… | |
… | |
1624 | RUINT32T mask_r, mask_g, mask_b; |
1624 | RUINT32T mask_r, mask_g, mask_b; |
1625 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1625 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1626 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1626 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1627 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1627 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1628 | int i; |
1628 | int i; |
|
|
1629 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1629 | |
1630 | |
1630 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1631 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1631 | |
1632 | |
1632 | /* for convenience */ |
1633 | /* for convenience */ |
1633 | mask_r = visual->red_mask; |
1634 | mask_r = visual->red_mask; |
1634 | mask_g = visual->green_mask; |
1635 | mask_g = visual->green_mask; |
1635 | mask_b = visual->blue_mask; |
1636 | mask_b = visual->blue_mask; |
1636 | |
1637 | |
1637 | /* boring lookup table pre-initialization */ |
1638 | /* boring lookup table pre-initialization */ |
1638 | switch (srcImage->bits_per_pixel) |
1639 | switch (srcImage->depth) |
1639 | { |
1640 | { |
1640 | case 15: |
1641 | case 15: |
1641 | if ((mask_r != 0x7c00) || |
1642 | if ((mask_r != 0x7c00) || |
1642 | (mask_g != 0x03e0) || |
1643 | (mask_g != 0x03e0) || |
1643 | (mask_b != 0x001f)) |
1644 | (mask_b != 0x001f)) |
… | |
… | |
1716 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1717 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1717 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
1718 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
1718 | upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
1719 | upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
1719 | } |
1720 | } |
1720 | |
1721 | |
1721 | /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ |
|
|
1722 | if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000)) |
|
|
1723 | { |
|
|
1724 | unsigned int tmp; |
|
|
1725 | |
|
|
1726 | tmp = lower_lim_r; |
|
|
1727 | lower_lim_r = lower_lim_b; |
|
|
1728 | lower_lim_b = tmp; |
|
|
1729 | |
|
|
1730 | tmp = upper_lim_r; |
|
|
1731 | upper_lim_r = upper_lim_b; |
|
|
1732 | upper_lim_b = tmp; |
|
|
1733 | } |
|
|
1734 | |
|
|
1735 | /* fill our lookup tables */ |
1722 | /* fill our lookup tables */ |
1736 | for (i = 0; i <= mask_r>>sh_r; i++) |
1723 | for (i = 0; i <= mask_r>>sh_r; i++) |
1737 | { |
1724 | { |
1738 | RUINT32T tmp; |
1725 | RUINT32T tmp; |
1739 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
1726 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
… | |
… | |
1754 | tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
1741 | tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
1755 | lookup_b[i] = (tmp/65535)<<sh_b; |
1742 | lookup_b[i] = (tmp/65535)<<sh_b; |
1756 | } |
1743 | } |
1757 | |
1744 | |
1758 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1745 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1759 | switch (srcImage->bits_per_pixel) |
1746 | if (srcImage->bits_per_pixel == 32 |
|
|
1747 | && (srcImage->depth == 24 || srcImage->depth == 32) |
|
|
1748 | && srcImage->byte_order == host_byte_order) |
1760 | { |
1749 | { |
1761 | case 15: |
|
|
1762 | { |
|
|
1763 | unsigned short *p1, *pf, *p, *pl; |
|
|
1764 | p1 = (unsigned short *) srcImage->data; |
|
|
1765 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1766 | while (p1 < pf) |
|
|
1767 | { |
|
|
1768 | p = p1; |
|
|
1769 | pl = p1 + srcImage->width; |
|
|
1770 | for (; p < pl; p++) |
|
|
1771 | { |
|
|
1772 | *p = lookup_r[(*p & 0x7c00)>>10] | |
|
|
1773 | lookup_g[(*p & 0x03e0)>> 5] | |
|
|
1774 | lookup_b[(*p & 0x001f)]; |
|
|
1775 | } |
|
|
1776 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1777 | } |
|
|
1778 | break; |
|
|
1779 | } |
|
|
1780 | case 16: |
|
|
1781 | { |
|
|
1782 | unsigned short *p1, *pf, *p, *pl; |
|
|
1783 | p1 = (unsigned short *) srcImage->data; |
|
|
1784 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1785 | while (p1 < pf) |
|
|
1786 | { |
|
|
1787 | p = p1; |
|
|
1788 | pl = p1 + srcImage->width; |
|
|
1789 | for (; p < pl; p++) |
|
|
1790 | { |
|
|
1791 | *p = lookup_r[(*p & 0xf800)>>11] | |
|
|
1792 | lookup_g[(*p & 0x07e0)>> 5] | |
|
|
1793 | lookup_b[(*p & 0x001f)]; |
|
|
1794 | } |
|
|
1795 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1796 | } |
|
|
1797 | break; |
|
|
1798 | } |
|
|
1799 | case 24: |
|
|
1800 | { |
|
|
1801 | unsigned char *p1, *pf, *p, *pl; |
|
|
1802 | p1 = (unsigned char *) srcImage->data; |
|
|
1803 | pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1804 | while (p1 < pf) |
|
|
1805 | { |
|
|
1806 | p = p1; |
|
|
1807 | pl = p1 + srcImage->width * 3; |
|
|
1808 | for (; p < pl; p += 3) |
|
|
1809 | { |
|
|
1810 | p[0] = lookup_r[(p[0] & 0xff0000)>>16]; |
|
|
1811 | p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; |
|
|
1812 | p[2] = lookup_r[(p[2] & 0x0000ff)]; |
|
|
1813 | } |
|
|
1814 | p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1815 | } |
|
|
1816 | break; |
|
|
1817 | } |
|
|
1818 | case 32: |
|
|
1819 | { |
|
|
1820 | RUINT32T *p1, *pf, *p, *pl; |
1750 | RUINT32T *p1, *pf, *p, *pl; |
1821 | p1 = (RUINT32T *) srcImage->data; |
1751 | p1 = (RUINT32T *) srcImage->data; |
1822 | pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1752 | pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1823 | |
1753 | |
1824 | while (p1 < pf) |
1754 | while (p1 < pf) |
1825 | { |
1755 | { |
1826 | p = p1; |
1756 | p = p1; |
1827 | pl = p1 + srcImage->width; |
1757 | pl = p1 + srcImage->width; |
1828 | for (; p < pl; p++) |
1758 | for (; p < pl; p++) |
1829 | { |
1759 | { |
1830 | *p = lookup_r[(*p & 0xff0000)>>16] | |
1760 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1831 | lookup_g[(*p & 0x00ff00)>> 8] | |
1761 | lookup_g[(*p & 0x00ff00) >> 8] | |
1832 | lookup_b[(*p & 0x0000ff)] | |
1762 | lookup_b[(*p & 0x0000ff)] | |
1833 | (*p & ~0xffffff); |
1763 | (*p & 0xff000000); |
1834 | } |
1764 | } |
1835 | p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
1765 | p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1766 | } |
|
|
1767 | } |
|
|
1768 | else |
|
|
1769 | { |
|
|
1770 | for (int y = 0; y < srcImage->height; y++) |
|
|
1771 | for (int x = 0; x < srcImage->width; x++) |
|
|
1772 | { |
|
|
1773 | unsigned long pixel = XGetPixel (srcImage, x, y); |
|
|
1774 | pixel = lookup_r[(pixel & mask_r) >> sh_r] | |
|
|
1775 | lookup_g[(pixel & mask_g) >> sh_g] | |
|
|
1776 | lookup_b[(pixel & mask_b) >> sh_b]; |
|
|
1777 | XPutPixel (srcImage, x, y, pixel); |
1836 | } |
1778 | } |
1837 | break; |
|
|
1838 | } |
|
|
1839 | } |
1779 | } |
1840 | |
1780 | |
1841 | free (lookup); |
1781 | free (lookup); |
1842 | } |
1782 | } |
1843 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |
1783 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |