Mercurial > hg > xemacs-beta
comparison src/glyphs-msw.c @ 290:c9fe270a4101 r21-0b43
Import from CVS: tag r21-0b43
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:36:47 +0200 |
parents | e11d67e05968 |
children | 70ad99077275 |
comparison
equal
deleted
inserted
replaced
289:6e6992ccc4b6 | 290:c9fe270a4101 |
---|---|
1528 from left to right, little-endian within a byte. 0 = white, 1 = | 1528 from left to right, little-endian within a byte. 0 = white, 1 = |
1529 black. It must be converted to the following format: Widths are | 1529 black. It must be converted to the following format: Widths are |
1530 padded to a multiple of 16. Scan lines are stored in increasing | 1530 padded to a multiple of 16. Scan lines are stored in increasing |
1531 byte order from left to right, big-endian within a byte. 0 = | 1531 byte order from left to right, big-endian within a byte. 0 = |
1532 black, 1 = white. */ | 1532 black, 1 = white. */ |
1533 static HBITMAP | 1533 HBITMAP |
1534 xbm_create_bitmap_from_data (char *data, | 1534 xbm_create_bitmap_from_data (HDC hdc, char *data, |
1535 unsigned int width, unsigned int height) | 1535 unsigned int width, unsigned int height, |
1536 int mask, COLORREF fg, COLORREF bg) | |
1536 { | 1537 { |
1537 int old_width = (width + 7)/8; | 1538 int old_width = (width + 7)/8; |
1538 int new_width = 2*((width + 15)/16); | 1539 int new_width = 2*((width + 15)/16); |
1539 unsigned char *offset; | 1540 unsigned char *offset; |
1541 void *bmp_buf = 0; | |
1540 unsigned char *new_data, *new_offset; | 1542 unsigned char *new_data, *new_offset; |
1541 unsigned int i; | 1543 int i, j; |
1542 int j; | 1544 BITMAPINFO* bmp_info = |
1543 HBITMAP hb; | 1545 xmalloc_and_zero (sizeof(BITMAPINFO) + sizeof(RGBQUAD)); |
1544 | 1546 HBITMAP bitmap; |
1545 new_data = (unsigned char *) xmalloc (height*new_width); | 1547 |
1548 if (!bmp_info) | |
1549 return NULL; | |
1550 | |
1551 new_data = (unsigned char *) xmalloc (height * new_width); | |
1552 | |
1553 if (!new_data) | |
1554 { | |
1555 xfree (bmp_info); | |
1556 return NULL; | |
1557 } | |
1558 | |
1546 for (i=0; i<height; i++) | 1559 for (i=0; i<height; i++) |
1547 { | 1560 { |
1548 offset = data + i*old_width; | 1561 offset = data + i*old_width; |
1549 new_offset = new_data + i*new_width; | 1562 new_offset = new_data + i*new_width; |
1563 | |
1550 new_offset[new_width - 1] = 0; /* there may be an extra byte | 1564 new_offset[new_width - 1] = 0; /* there may be an extra byte |
1551 that needs to be padded */ | 1565 that needs to be padded */ |
1552 for (j=0; j<old_width; j++) | 1566 for (j=0; j<old_width; j++) |
1553 { | 1567 { |
1554 int byte = offset[j]; | 1568 int byte = offset[j]; |
1555 new_offset[j] = ~ (unsigned char) | 1569 new_offset[j] = ~ (unsigned char) |
1556 ((flip_table[byte & 0xf] << 4) + flip_table[byte >> 4]); | 1570 ((flip_table[byte & 0xf] << 4) + flip_table[byte >> 4]); |
1557 } | 1571 } |
1558 } | 1572 } |
1559 hb = CreateBitmap (width, height, 1, 1, new_data); | 1573 |
1574 /* if we want a mask invert the bits */ | |
1575 if (!mask) | |
1576 { | |
1577 new_offset = &new_data[height * new_width]; | |
1578 while (new_offset-- != new_data) | |
1579 { | |
1580 *new_offset ^= 0xff; | |
1581 } | |
1582 } | |
1583 | |
1584 bmp_info->bmiHeader.biWidth=width; | |
1585 bmp_info->bmiHeader.biHeight=-height; | |
1586 bmp_info->bmiHeader.biPlanes=1; | |
1587 bmp_info->bmiHeader.biSize=sizeof(BITMAPINFOHEADER); | |
1588 bmp_info->bmiHeader.biBitCount=1; | |
1589 bmp_info->bmiHeader.biCompression=BI_RGB; | |
1590 bmp_info->bmiHeader.biClrUsed = 2; | |
1591 bmp_info->bmiHeader.biClrImportant = 2; | |
1592 bmp_info->bmiHeader.biSizeImage = height * new_width; | |
1593 bmp_info->bmiColors[0].rgbRed = GetRValue (fg); | |
1594 bmp_info->bmiColors[0].rgbGreen = GetGValue (fg); | |
1595 bmp_info->bmiColors[0].rgbBlue = GetBValue (fg); | |
1596 bmp_info->bmiColors[0].rgbReserved = 0; | |
1597 bmp_info->bmiColors[1].rgbRed = GetRValue (bg); | |
1598 bmp_info->bmiColors[1].rgbGreen = GetGValue (bg); | |
1599 bmp_info->bmiColors[1].rgbBlue = GetBValue (bg); | |
1600 bmp_info->bmiColors[1].rgbReserved = 0; | |
1601 | |
1602 bitmap = CreateDIBSection (hdc, | |
1603 bmp_info, | |
1604 DIB_RGB_COLORS, | |
1605 &bmp_buf, | |
1606 0,0); | |
1607 | |
1608 xfree (bmp_info); | |
1609 | |
1610 if (!bitmap || !bmp_buf) | |
1611 { | |
1612 xfree (new_data); | |
1613 return NULL; | |
1614 } | |
1615 | |
1616 /* copy in the actual bitmap */ | |
1617 memcpy (bmp_buf, new_data, height * new_width); | |
1560 xfree (new_data); | 1618 xfree (new_data); |
1561 | 1619 |
1562 return hb; | 1620 return bitmap; |
1563 } | 1621 } |
1564 | 1622 |
1565 /* Given inline data for a mono pixmap, initialize the given | 1623 /* Given inline data for a mono pixmap, initialize the given |
1566 image instance accordingly. */ | 1624 image instance accordingly. */ |
1567 | 1625 |
1576 int dest_mask, | 1634 int dest_mask, |
1577 HBITMAP mask, | 1635 HBITMAP mask, |
1578 Lisp_Object mask_filename) | 1636 Lisp_Object mask_filename) |
1579 { | 1637 { |
1580 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); | 1638 Lisp_Object device = IMAGE_INSTANCE_DEVICE (ii); |
1639 struct frame* f = XFRAME (DEVICE_SELECTED_FRAME (XDEVICE (device))); | |
1581 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground); | 1640 Lisp_Object foreground = find_keyword_in_vector (instantiator, Q_foreground); |
1582 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background); | 1641 Lisp_Object background = find_keyword_in_vector (instantiator, Q_background); |
1583 enum image_instance_type type; | 1642 enum image_instance_type type; |
1643 COLORREF black = PALETTERGB (0,0,0); | |
1644 COLORREF white = PALETTERGB (255,255,255); | |
1645 | |
1646 HDC hdc = FRAME_MSWINDOWS_CDC (f); | |
1584 | 1647 |
1585 if (!DEVICE_MSWINDOWS_P (XDEVICE (device))) | 1648 if (!DEVICE_MSWINDOWS_P (XDEVICE (device))) |
1586 signal_simple_error ("Not an MS-Windows device", device); | 1649 signal_simple_error ("Not an MS-Windows device", device); |
1587 | 1650 |
1588 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) && | 1651 if ((dest_mask & IMAGE_MONO_PIXMAP_MASK) && |
1603 incompatible_image_types (instantiator, dest_mask, | 1666 incompatible_image_types (instantiator, dest_mask, |
1604 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK | 1667 IMAGE_MONO_PIXMAP_MASK | IMAGE_COLOR_PIXMAP_MASK |
1605 | IMAGE_POINTER_MASK); | 1668 | IMAGE_POINTER_MASK); |
1606 | 1669 |
1607 mswindows_initialize_dibitmap_image_instance (ii, type); | 1670 mswindows_initialize_dibitmap_image_instance (ii, type); |
1671 | |
1672 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = | |
1673 find_keyword_in_vector (instantiator, Q_file); | |
1608 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width; | 1674 IMAGE_INSTANCE_PIXMAP_WIDTH (ii) = width; |
1609 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height; | 1675 IMAGE_INSTANCE_PIXMAP_HEIGHT (ii) = height; |
1610 IMAGE_INSTANCE_PIXMAP_FILENAME (ii) = | 1676 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1; |
1611 find_keyword_in_vector (instantiator, Q_file); | |
1612 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0); | 1677 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), 0); |
1613 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0); | 1678 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), 0); |
1614 IMAGE_INSTANCE_PIXMAP_DEPTH (ii) = 1; | 1679 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = mask ? mask : |
1615 IMAGE_INSTANCE_MSWINDOWS_MASK (ii) = mask; | 1680 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height, |
1616 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = | 1681 TRUE, black, white); |
1617 xbm_create_bitmap_from_data ((Extbyte *) bits, width, height); | |
1618 | 1682 |
1619 switch (type) | 1683 switch (type) |
1620 { | 1684 { |
1621 case IMAGE_MONO_PIXMAP: | 1685 case IMAGE_MONO_PIXMAP: |
1686 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = | |
1687 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height, | |
1688 FALSE, black, black); | |
1622 break; | 1689 break; |
1623 | 1690 |
1624 case IMAGE_COLOR_PIXMAP: | 1691 case IMAGE_COLOR_PIXMAP: |
1625 { | 1692 { |
1626 unsigned long fg = PALETTERGB (0,0,0); | 1693 COLORREF fg = black; |
1627 unsigned long bg = PALETTERGB (255,255,255); | 1694 COLORREF bg = white; |
1628 | 1695 |
1629 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground)) | 1696 if (!NILP (foreground) && !COLOR_INSTANCEP (foreground)) |
1630 foreground = | 1697 foreground = |
1631 Fmake_color_instance (foreground, device, | 1698 Fmake_color_instance (foreground, device, |
1632 encode_error_behavior_flag (ERROR_ME)); | 1699 encode_error_behavior_flag (ERROR_ME)); |
1642 if (COLOR_INSTANCEP (background)) | 1709 if (COLOR_INSTANCEP (background)) |
1643 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background)); | 1710 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background)); |
1644 | 1711 |
1645 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground; | 1712 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground; |
1646 IMAGE_INSTANCE_PIXMAP_BG (ii) = background; | 1713 IMAGE_INSTANCE_PIXMAP_BG (ii) = background; |
1714 | |
1715 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = | |
1716 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height, | |
1717 FALSE, fg, black); | |
1647 } | 1718 } |
1648 break; | 1719 break; |
1649 | 1720 |
1650 case IMAGE_POINTER: | 1721 case IMAGE_POINTER: |
1651 { | 1722 { |
1723 COLORREF fg = black; | |
1724 COLORREF bg = white; | |
1725 | |
1652 if (NILP (foreground)) | 1726 if (NILP (foreground)) |
1653 foreground = pointer_fg; | 1727 foreground = pointer_fg; |
1654 if (NILP (background)) | 1728 if (NILP (background)) |
1655 background = pointer_bg; | 1729 background = pointer_bg; |
1656 | 1730 |
1731 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii), | |
1732 find_keyword_in_vector (instantiator, Q_hotspot_x)); | |
1733 XSETINT (IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii), | |
1734 find_keyword_in_vector (instantiator, Q_hotspot_y)); | |
1657 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground; | 1735 IMAGE_INSTANCE_PIXMAP_FG (ii) = foreground; |
1658 IMAGE_INSTANCE_PIXMAP_BG (ii) = background; | 1736 IMAGE_INSTANCE_PIXMAP_BG (ii) = background; |
1659 IMAGE_INSTANCE_PIXMAP_HOTSPOT_X (ii) = | 1737 if (COLOR_INSTANCEP (foreground)) |
1660 find_keyword_in_vector (instantiator, Q_hotspot_x); | 1738 fg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (foreground)); |
1661 IMAGE_INSTANCE_PIXMAP_HOTSPOT_Y (ii) = | 1739 if (COLOR_INSTANCEP (background)) |
1662 find_keyword_in_vector (instantiator, Q_hotspot_y); | 1740 bg = COLOR_INSTANCE_MSWINDOWS_COLOR (XCOLOR_INSTANCE (background)); |
1741 | |
1742 IMAGE_INSTANCE_MSWINDOWS_BITMAP (ii) = | |
1743 xbm_create_bitmap_from_data (hdc, (Extbyte *) bits, width, height, | |
1744 TRUE, fg, black); | |
1745 mswindows_initialize_image_instance_icon (ii, TRUE); | |
1663 } | 1746 } |
1664 break; | 1747 break; |
1665 | 1748 |
1666 default: | 1749 default: |
1667 abort (); | 1750 abort (); |
1676 CONST char *bits) | 1759 CONST char *bits) |
1677 { | 1760 { |
1678 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data); | 1761 Lisp_Object mask_data = find_keyword_in_vector (instantiator, Q_mask_data); |
1679 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file); | 1762 Lisp_Object mask_file = find_keyword_in_vector (instantiator, Q_mask_file); |
1680 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); | 1763 struct Lisp_Image_Instance *ii = XIMAGE_INSTANCE (image_instance); |
1764 struct frame* f = XFRAME (DEVICE_SELECTED_FRAME | |
1765 (XDEVICE (IMAGE_INSTANCE_DEVICE (ii)))); | |
1766 HDC hdc = FRAME_MSWINDOWS_CDC (f); | |
1681 HBITMAP mask = 0; | 1767 HBITMAP mask = 0; |
1682 CONST char *gcc_may_you_rot_in_hell; | 1768 CONST char *gcc_may_you_rot_in_hell; |
1683 | 1769 |
1684 if (!NILP (mask_data)) | 1770 if (!NILP (mask_data)) |
1685 { | 1771 { |
1686 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))), | 1772 GET_C_STRING_BINARY_DATA_ALLOCA (XCAR (XCDR (XCDR (mask_data))), |
1687 gcc_may_you_rot_in_hell); | 1773 gcc_may_you_rot_in_hell); |
1688 mask = | 1774 mask = |
1689 xbm_create_bitmap_from_data ( (unsigned char *) | 1775 xbm_create_bitmap_from_data ( hdc, |
1776 (unsigned char *) | |
1690 gcc_may_you_rot_in_hell, | 1777 gcc_may_you_rot_in_hell, |
1691 XINT (XCAR (mask_data)), | 1778 XINT (XCAR (mask_data)), |
1692 XINT (XCAR (XCDR (mask_data)))); | 1779 XINT (XCAR (XCDR (mask_data))), FALSE, |
1780 PALETTERGB (0,0,0), | |
1781 PALETTERGB (255,255,255)); | |
1693 } | 1782 } |
1694 | 1783 |
1695 init_image_instance_from_xbm_inline (ii, width, height, bits, | 1784 init_image_instance_from_xbm_inline (ii, width, height, bits, |
1696 instantiator, pointer_fg, pointer_bg, | 1785 instantiator, pointer_fg, pointer_bg, |
1697 dest_mask, mask, mask_file); | 1786 dest_mask, mask, mask_file); |