summaryrefslogtreecommitdiff
path: root/src/lib/emile
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2016-12-15 16:45:10 -0800
committerCedric BAIL <cedric@osg.samsung.com>2016-12-15 16:45:10 -0800
commit0ca1d0eef2ffc04c59fa194ad5c2e827614e95bc (patch)
tree9b970c91d93d13139c1db5d111ffa97f0b5cdb98 /src/lib/emile
parent3b354d6757437e27957d49381e125fb1f12ac2b8 (diff)
emile: refactor color convertion/copy logic in jpeg data decoder.
Diffstat (limited to 'src/lib/emile')
-rw-r--r--src/lib/emile/emile_image.c277
1 files changed, 148 insertions, 129 deletions
diff --git a/src/lib/emile/emile_image.c b/src/lib/emile/emile_image.c
index da17464396..4ea9cd224b 100644
--- a/src/lib/emile/emile_image.c
+++ b/src/lib/emile/emile_image.c
@@ -1618,6 +1618,129 @@ _emile_jpeg_head(Emile_Image *image,
1618 return EINA_TRUE; 1618 return EINA_TRUE;
1619} 1619}
1620 1620
1621static inline void
1622_jpeg_convert_copy(volatile uint32_t **dst, uint8_t **src, unsigned int w, Eina_Bool adobe_marker)
1623{
1624 uint32_t *ptr2 = (uint32_t*) *dst;
1625 uint8_t *ptr = *src;
1626 unsigned int x;
1627
1628 if (adobe_marker)
1629 {
1630 for (x = 0; x < w; x++)
1631 {
1632 /* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */
1633 /* that is C is replaces by 255 - C, etc... */
1634 /* See the comment below for the computation of RGB values from CMYK ones. */
1635 *ptr2 = (0xff000000) |
1636 ((ptr[0] * ptr[3] / 255) << 16) |
1637 ((ptr[1] * ptr[3] / 255) << 8) |
1638 ((ptr[2] * ptr[3] / 255));
1639 ptr += 4;
1640 ptr2++;
1641 }
1642 }
1643 else
1644 {
1645 for (x = 0; x < w; x++)
1646 {
1647 /* Conversion from CMYK to RGB is done in 2 steps: */
1648 /* CMYK => CMY => RGB (see http://www.easyrgb.com/index.php?X=MATH) */
1649 /* after computation, if C, M, Y and K are between 0 and 1, we have: */
1650 /* R = (1 - C) * (1 - K) * 255 */
1651 /* G = (1 - M) * (1 - K) * 255 */
1652 /* B = (1 - Y) * (1 - K) * 255 */
1653 /* libjpeg stores CMYK values between 0 and 255, */
1654 /* so we replace C by C * 255 / 255, etc... and we obtain: */
1655 /* R = (255 - C) * (255 - K) / 255 */
1656 /* G = (255 - M) * (255 - K) / 255 */
1657 /* B = (255 - Y) * (255 - K) / 255 */
1658 /* with C, M, Y and K between 0 and 255. */
1659 *ptr2 = (0xff000000) |
1660 (((255 - ptr[0]) * (255 - ptr[3]) / 255) << 16) |
1661 (((255 - ptr[1]) * (255 - ptr[3]) / 255) << 8) |
1662 (((255 - ptr[2]) * (255 - ptr[3]) / 255));
1663 ptr += 4;
1664 ptr2++;
1665 }
1666 }
1667
1668 *dst = ptr2;
1669 *src = ptr;
1670}
1671
1672static inline void
1673_jpeg_gry8_convert_copy(uint8_t **dst, uint8_t **src, unsigned int w)
1674{
1675 uint8_t *ptrg = (uint8_t*) *dst;
1676 uint8_t *ptr = *src;
1677 unsigned int x;
1678
1679 for (x = 0; x < w; x++)
1680 {
1681 *ptrg = ptr[0];
1682 ptrg++;
1683 ptr++;
1684 }
1685
1686 *dst = ptrg;
1687 *src = ptr;
1688}
1689
1690static inline void
1691_jpeg_agry88_convert_copy(uint16_t **dst, uint8_t **src, unsigned int w)
1692{
1693 uint16_t *ptrag = (uint16_t*) *dst;
1694 uint8_t *ptr = *src;
1695 unsigned int x;
1696
1697 for (x = 0; x < w; x++)
1698 {
1699 *ptrag = 0xFF00 | ptr[0];
1700 ptrag++;
1701 ptr++;
1702 }
1703
1704 *dst = ptrag;
1705 *src = ptr;
1706}
1707
1708static inline void
1709_jpeg_argb8888_convert_copy(volatile uint32_t **dst, uint8_t **src, unsigned int w)
1710{
1711 uint32_t *ptr2 = (uint32_t*) *dst;
1712 uint8_t *ptr = *src;
1713 unsigned int x;
1714
1715 for (x = 0; x < w; x++)
1716 {
1717 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]);
1718 ptr2++;
1719 ptr++;
1720 }
1721
1722 *dst = ptr2;
1723 *src = ptr;
1724}
1725
1726static inline void
1727_jpeg_copy(volatile uint32_t **dst, uint8_t **src, unsigned int w)
1728{
1729 uint32_t *ptr2 = (uint32_t*) *dst;
1730 uint8_t *ptr = *src;
1731 unsigned int x;
1732
1733 for (x = 0; x < w; x++)
1734 {
1735 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[1], ptr[2]);
1736 ptr += 3;
1737 ptr2++;
1738 }
1739
1740 *dst = ptr2;
1741 *src = ptr;
1742}
1743
1621static Eina_Bool 1744static Eina_Bool
1622_emile_jpeg_data(Emile_Image *image, 1745_emile_jpeg_data(Emile_Image *image,
1623 Emile_Image_Property *prop, 1746 Emile_Image_Property *prop,
@@ -1636,7 +1759,7 @@ _emile_jpeg_data(Emile_Image *image,
1636 uint32_t *ptr_rotate = NULL; 1759 uint32_t *ptr_rotate = NULL;
1637 uint16_t *ptrag = NULL, *ptrag_rotate = NULL; 1760 uint16_t *ptrag = NULL, *ptrag_rotate = NULL;
1638 uint8_t *ptrg = NULL, *ptrg_rotate = NULL; 1761 uint8_t *ptrg = NULL, *ptrg_rotate = NULL;
1639 unsigned int x, y, l, i, scans; 1762 unsigned int y, l, i, scans;
1640 volatile int region = 0; 1763 volatile int region = 0;
1641 /* rotation setting */ 1764 /* rotation setting */
1642 unsigned int ie_w = 0, ie_h = 0; 1765 unsigned int ie_w = 0, ie_h = 0;
@@ -1885,47 +2008,7 @@ _emile_jpeg_data(Emile_Image *image,
1885 { 2008 {
1886 for (y = 0; y < scans; y++) 2009 for (y = 0; y < scans; y++)
1887 { 2010 {
1888 if (cinfo.saw_Adobe_marker) 2011 _jpeg_convert_copy(&ptr2, &ptr, w, cinfo.saw_Adobe_marker);
1889 {
1890 for (x = 0; x < w; x++)
1891 {
1892 /* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */
1893 /* that is C is replaces by 255 - C, etc... */
1894 /* See the comment below for the computation of RGB values from CMYK ones. */
1895 *ptr2 =
1896 (0xff000000) |
1897 ((ptr[0] * ptr[3] / 255) << 16) |
1898 ((ptr[1] * ptr[3] / 255) << 8) |
1899 ((ptr[2] * ptr[3] / 255));
1900 ptr += 4;
1901 ptr2++;
1902 }
1903 }
1904 else
1905 {
1906 for (x = 0; x < w; x++)
1907 {
1908 /* Conversion from CMYK to RGB is done in 2 steps: */
1909 /* CMYK => CMY => RGB (see http://www.easyrgb.com/index.php?X=MATH) */
1910 /* after computation, if C, M, Y and K are between 0 and 1, we have: */
1911 /* R = (1 - C) * (1 - K) * 255 */
1912 /* G = (1 - M) * (1 - K) * 255 */
1913 /* B = (1 - Y) * (1 - K) * 255 */
1914 /* libjpeg stores CMYK values between 0 and 255, */
1915 /* so we replace C by C * 255 / 255, etc... and we obtain: */
1916 /* R = (255 - C) * (255 - K) / 255 */
1917 /* G = (255 - M) * (255 - K) / 255 */
1918 /* B = (255 - Y) * (255 - K) / 255 */
1919 /* with C, M, Y and K between 0 and 255. */
1920 *ptr2 =
1921 (0xff000000) |
1922 (((255 - ptr[0]) * (255 - ptr[3]) / 255) << 16) |
1923 (((255 - ptr[1]) * (255 - ptr[3]) / 255) << 8) |
1924 (((255 - ptr[2]) * (255 - ptr[3]) / 255));
1925 ptr += 4;
1926 ptr2++;
1927 }
1928 }
1929 } 2012 }
1930 } 2013 }
1931 else 2014 else
@@ -1949,47 +2032,7 @@ _emile_jpeg_data(Emile_Image *image,
1949 if (((y + l) >= opts_region.y) && ((y + l) < (opts_region.y + opts_region.h))) 2032 if (((y + l) >= opts_region.y) && ((y + l) < (opts_region.y + opts_region.h)))
1950 { 2033 {
1951 ptr += opts_region.x; 2034 ptr += opts_region.x;
1952 if (cinfo.saw_Adobe_marker) 2035 _jpeg_convert_copy(&ptr2, &ptr, opts_region.w, cinfo.saw_Adobe_marker);
1953 {
1954 for (x = 0; x < opts_region.w; x++)
1955 {
1956 /* According to libjpeg doc, Photoshop inverse the values of C, M, Y and K, */
1957 /* that is C is replaces by 255 - C, etc... */
1958 /* See the comment below for the computation of RGB values from CMYK ones. */
1959 *ptr2 =
1960 (0xff000000) |
1961 ((ptr[0] * ptr[3] / 255) << 16) |
1962 ((ptr[1] * ptr[3] / 255) << 8) |
1963 ((ptr[2] * ptr[3] / 255));
1964 ptr += 4;
1965 ptr2++;
1966 }
1967 }
1968 else
1969 {
1970 for (x = 0; x < opts_region.w; x++)
1971 {
1972 /* Conversion from CMYK to RGB is done in 2 steps: */
1973 /* CMYK => CMY => RGB (see http://www.easyrgb.com/index.php?X=MATH) */
1974 /* after computation, if C, M, Y and K are between 0 and 1, we have: */
1975 /* R = (1 - C) * (1 - K) * 255 */
1976 /* G = (1 - M) * (1 - K) * 255 */
1977 /* B = (1 - Y) * (1 - K) * 255 */
1978 /* libjpeg stores CMYK values between 0 and 255, */
1979 /* so we replace C by C * 255 / 255, etc... and we obtain: */
1980 /* R = (255 - C) * (255 - K) / 255 */
1981 /* G = (255 - M) * (255 - K) / 255 */
1982 /* B = (255 - Y) * (255 - K) / 255 */
1983 /* with C, M, Y and K between 0 and 255. */
1984 *ptr2 =
1985 (0xff000000) |
1986 (((255 - ptr[0]) * (255 - ptr[3]) / 255) << 16) |
1987 (((255 - ptr[1]) * (255 - ptr[3]) / 255) << 8) |
1988 (((255 - ptr[2]) * (255 - ptr[3]) / 255));
1989 ptr += 4;
1990 ptr2++;
1991 }
1992 }
1993 ptr += (4 * (w - (opts_region.x + opts_region.w))); 2036 ptr += (4 * (w - (opts_region.x + opts_region.w)));
1994 } 2037 }
1995 else 2038 else
@@ -2034,12 +2077,7 @@ _emile_jpeg_data(Emile_Image *image,
2034 { 2077 {
2035 for (y = 0; y < scans; y++) 2078 for (y = 0; y < scans; y++)
2036 { 2079 {
2037 for (x = 0; x < w; x++) 2080 _jpeg_copy(&ptr2, &ptr, w);
2038 {
2039 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[1], ptr[2]);
2040 ptr += 3;
2041 ptr2++;
2042 }
2043 } 2081 }
2044 } 2082 }
2045 else 2083 else
@@ -2061,12 +2099,7 @@ _emile_jpeg_data(Emile_Image *image,
2061 ((y + l) < (opts_region.y + opts_region.h))) 2099 ((y + l) < (opts_region.y + opts_region.h)))
2062 { 2100 {
2063 ptr += (3 * opts_region.x); 2101 ptr += (3 * opts_region.x);
2064 for (x = 0; x < opts_region.w; x++) 2102 _jpeg_copy(&ptr2, &ptr, opts_region.w);
2065 {
2066 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[1], ptr[2]);
2067 ptr += 3;
2068 ptr2++;
2069 }
2070 ptr += (3 * (w - (opts_region.x + opts_region.w))); 2103 ptr += (3 * (w - (opts_region.x + opts_region.w)));
2071 } 2104 }
2072 else 2105 else
@@ -2099,24 +2132,17 @@ _emile_jpeg_data(Emile_Image *image,
2099 { 2132 {
2100 for (y = 0; y < scans; y++) 2133 for (y = 0; y < scans; y++)
2101 { 2134 {
2102 for (x = 0; x < w; x++) 2135 switch (prop->cspace)
2103 { 2136 {
2104 if (prop->cspace == EMILE_COLORSPACE_GRY8) 2137 case EMILE_COLORSPACE_GRY8:
2105 { 2138 _jpeg_gry8_convert_copy(&ptrg, &ptr, w);
2106 *ptrg = ptr[0]; 2139 break;
2107 ptrg++; 2140 case EMILE_COLORSPACE_AGRY88:
2108 } 2141 _jpeg_agry88_convert_copy(&ptrag, &ptr, w);
2109 else if (prop->cspace == EMILE_COLORSPACE_AGRY88) 2142 break;
2110 { 2143 default:
2111 *ptrag = 0xFF00 | ptr[0]; 2144 _jpeg_argb8888_convert_copy(&ptr2, &ptr, w);
2112 ptrag++; 2145 break;
2113 }
2114 else
2115 {
2116 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]);
2117 ptr2++;
2118 }
2119 ptr++;
2120 } 2146 }
2121 } 2147 }
2122 } 2148 }
@@ -2142,24 +2168,17 @@ _emile_jpeg_data(Emile_Image *image,
2142 ((y + l) < (opts_region.y + opts_region.h))) 2168 ((y + l) < (opts_region.y + opts_region.h)))
2143 { 2169 {
2144 ptr += opts_region.x; 2170 ptr += opts_region.x;
2145 for (x = 0; x < opts_region.w; x++) 2171 switch (prop->cspace)
2146 { 2172 {
2147 if (prop->cspace == EMILE_COLORSPACE_GRY8) 2173 case EMILE_COLORSPACE_GRY8:
2148 { 2174 _jpeg_gry8_convert_copy(&ptrg, &ptr, opts_region.w);
2149 *ptrg = ptr[0]; 2175 break;
2150 ptrg++; 2176 case EMILE_COLORSPACE_AGRY88:
2151 } 2177 _jpeg_agry88_convert_copy(&ptrag, &ptr, opts_region.w);
2152 else if (prop->cspace == EMILE_COLORSPACE_AGRY88) 2178 break;
2153 { 2179 default:
2154 *ptrag = 0xFF00 | ptr[0]; 2180 _jpeg_argb8888_convert_copy(&ptr2, &ptr, opts_region.w);
2155 ptrag++; 2181 break;
2156 }
2157 else
2158 {
2159 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]);
2160 ptr2++;
2161 }
2162 ptr++;
2163 } 2182 }
2164 ptr += w - (opts_region.x + opts_region.w); 2183 ptr += w - (opts_region.x + opts_region.w);
2165 } 2184 }