summaryrefslogtreecommitdiff
path: root/src/lib/emile
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-03-17 08:50:25 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-17 09:58:19 +0100
commita88f0074d7efc99f4eda5bd2159b22412d193ccc (patch)
tree5fe3ec6e0838f627b13e1938853c1993f5d2787f /src/lib/emile
parentce340ce2fb9f9af459bd57a965b864c3b0afe2c9 (diff)
emile: handle AGRY88 for JPEG image.
Diffstat (limited to 'src/lib/emile')
-rw-r--r--src/lib/emile/emile_image.c136
1 files changed, 131 insertions, 5 deletions
diff --git a/src/lib/emile/emile_image.c b/src/lib/emile/emile_image.c
index 9c43e385a4..6f8261eaf7 100644
--- a/src/lib/emile/emile_image.c
+++ b/src/lib/emile/emile_image.c
@@ -201,8 +201,9 @@ static const Emile_Colorspace cspaces_etc1_alpha[2] = {
201 EMILE_COLORSPACE_ARGB8888 201 EMILE_COLORSPACE_ARGB8888
202}; 202};
203 203
204static const Emile_Colorspace cspaces_gry[2] = { 204static const Emile_Colorspace cspaces_agry[2] = {
205 EMILE_COLORSPACE_GRY8, 205 EMILE_COLORSPACE_GRY8,
206 EMILE_COLORSPACE_AGRY88,
206 EMILE_COLORSPACE_ARGB8888 207 EMILE_COLORSPACE_ARGB8888
207}; 208};
208 209
@@ -1159,6 +1160,88 @@ _rotate_change_wh8(uint8_t *to, uint8_t *from,
1159 } 1160 }
1160} 1161}
1161 1162
1163static void
1164_rotate16_180(uint16_t *data, int w, int h)
1165{
1166 uint16_t *p1, *p2;
1167 uint16_t pt;
1168 int x;
1169
1170 p1 = data;
1171 p2 = data + (h * w) - 1;
1172 for (x = (w * h) / 2; --x >= 0;)
1173 {
1174 pt = *p1;
1175 *p1 = *p2;
1176 *p2 = pt;
1177 p1++;
1178 p2--;
1179 }
1180}
1181
1182static void
1183_flip_horizontal16(uint16_t *data, int w, int h)
1184{
1185 uint16_t *p1, *p2;
1186 uint16_t pt;
1187 int x, y;
1188
1189 for (y = 0; y < h; y++)
1190 {
1191 p1 = data + (y * w);
1192 p2 = data + ((y + 1) * w) - 1;
1193 for (x = 0; x < (w >> 1); x++)
1194 {
1195 pt = *p1;
1196 *p1 = *p2;
1197 *p2 = pt;
1198 p1++;
1199 p2--;
1200 }
1201 }
1202}
1203
1204static void
1205_flip_vertical16(uint16_t *data, int w, int h)
1206{
1207 uint16_t *p1, *p2;
1208 uint16_t pt;
1209 int x, y;
1210
1211 for (y = 0; y < (h >> 1); y++)
1212 {
1213 p1 = data + (y * w);
1214 p2 = data + ((h - 1 - y) * w);
1215 for (x = 0; x < w; x++)
1216 {
1217 pt = *p1;
1218 *p1 = *p2;
1219 *p2 = pt;
1220 p1++;
1221 p2++;
1222 }
1223 }
1224}
1225
1226static void
1227_rotate_change_wh16(uint16_t *to, uint16_t *from,
1228 int w, int h,
1229 int dx, int dy)
1230{
1231 int x, y;
1232
1233 for (x = h; --x >= 0;)
1234 {
1235 for (y = w; --y >= 0;)
1236 {
1237 *to = *from;
1238 from++;
1239 to += dy;
1240 }
1241 to += dx;
1242 }
1243}
1244
1162static Eina_Bool 1245static Eina_Bool
1163_emile_jpeg_bind(Emile_Image *image EINA_UNUSED, 1246_emile_jpeg_bind(Emile_Image *image EINA_UNUSED,
1164 Emile_Image_Load_Opts *opts EINA_UNUSED, 1247 Emile_Image_Load_Opts *opts EINA_UNUSED,
@@ -1231,8 +1314,8 @@ _emile_jpeg_head(Emile_Image *image,
1231 1314
1232 if (cinfo.jpeg_color_space == JCS_GRAYSCALE) 1315 if (cinfo.jpeg_color_space == JCS_GRAYSCALE)
1233 { 1316 {
1234 // We do handle GRY8 colorspace as an output for JPEG 1317 // We do handle GRY8 and AGRY88 (with FF for alpha) colorspace as an output for JPEG
1235 prop->cspaces = cspaces_gry; 1318 prop->cspaces = cspaces_agry;
1236 } 1319 }
1237 1320
1238 /* rotation decoding */ 1321 /* rotation decoding */
@@ -1406,7 +1489,7 @@ _emile_jpeg_data(Emile_Image *image,
1406 void *pixels, 1489 void *pixels,
1407 Emile_Image_Load_Error *error) 1490 Emile_Image_Load_Error *error)
1408{ 1491{
1409 // Handle RGB, ARGB and GRY 1492 // Handle RGB, ARGB, GRY and AGRY
1410 Emile_Image_Load_Opts *opts = NULL; 1493 Emile_Image_Load_Opts *opts = NULL;
1411 unsigned int w, h; 1494 unsigned int w, h;
1412 struct jpeg_decompress_struct cinfo; 1495 struct jpeg_decompress_struct cinfo;
@@ -1414,6 +1497,7 @@ _emile_jpeg_data(Emile_Image *image,
1414 const unsigned char *m = NULL; 1497 const unsigned char *m = NULL;
1415 uint8_t *ptr, *line[16], *data; 1498 uint8_t *ptr, *line[16], *data;
1416 uint32_t *ptr2, *ptr_rotate = NULL; 1499 uint32_t *ptr2, *ptr_rotate = NULL;
1500 uint16_t *ptrag, *ptrag_rotate = NULL;
1417 uint8_t *ptrg, *ptrg_rotate = NULL; 1501 uint8_t *ptrg, *ptrg_rotate = NULL;
1418 unsigned int x, y, l, i, scans; 1502 unsigned int x, y, l, i, scans;
1419 int region = 0; 1503 int region = 0;
@@ -1481,7 +1565,8 @@ _emile_jpeg_data(Emile_Image *image,
1481 case JCS_UNKNOWN: 1565 case JCS_UNKNOWN:
1482 break; 1566 break;
1483 case JCS_GRAYSCALE: 1567 case JCS_GRAYSCALE:
1484 if (prop->cspace == EMILE_COLORSPACE_GRY8) 1568 if (prop->cspace == EMILE_COLORSPACE_GRY8 ||
1569 prop->cspace == EMILE_COLORSPACE_AGRY88)
1485 { 1570 {
1486 cinfo.out_color_space = JCS_GRAYSCALE; 1571 cinfo.out_color_space = JCS_GRAYSCALE;
1487 break; 1572 break;
@@ -1576,6 +1661,7 @@ _emile_jpeg_data(Emile_Image *image,
1576 switch (prop->cspace) 1661 switch (prop->cspace)
1577 { 1662 {
1578 case EMILE_COLORSPACE_GRY8: 1663 case EMILE_COLORSPACE_GRY8:
1664 case EMILE_COLORSPACE_AGRY88:
1579 if (!(cinfo.out_color_space == JCS_GRAYSCALE && 1665 if (!(cinfo.out_color_space == JCS_GRAYSCALE &&
1580 cinfo.output_components == 1)) 1666 cinfo.output_components == 1))
1581 { 1667 {
@@ -1611,6 +1697,11 @@ _emile_jpeg_data(Emile_Image *image,
1611 ptrg = malloc(w * h * sizeof(uint8_t)); 1697 ptrg = malloc(w * h * sizeof(uint8_t));
1612 ptrg_rotate = ptrg; 1698 ptrg_rotate = ptrg;
1613 } 1699 }
1700 else if (prop->cspace == EMILE_COLORSPACE_AGRY88)
1701 {
1702 ptrag = malloc(w * h * sizeof(uint16_t));
1703 ptrag_rotate = ptrag;
1704 }
1614 else 1705 else
1615 { 1706 {
1616 ptr2 = malloc(w * h * sizeof(uint32_t)); 1707 ptr2 = malloc(w * h * sizeof(uint32_t));
@@ -1861,6 +1952,11 @@ _emile_jpeg_data(Emile_Image *image,
1861 *ptrg = ptr[0]; 1952 *ptrg = ptr[0];
1862 ptrg++; 1953 ptrg++;
1863 } 1954 }
1955 else if (prop->cspace == EMILE_COLORSPACE_AGRY88)
1956 {
1957 *ptrag = 0xFF | ptr[0];
1958 ptrag++;
1959 }
1864 else 1960 else
1865 { 1961 {
1866 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]); 1962 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]);
@@ -1900,6 +1996,11 @@ _emile_jpeg_data(Emile_Image *image,
1900 *ptrg = ptr[0]; 1996 *ptrg = ptr[0];
1901 ptrg++; 1997 ptrg++;
1902 } 1998 }
1999 else if (prop->cspace == EMILE_COLORSPACE_AGRY88)
2000 {
2001 *ptrag = 0xFF00 | ptr[0];
2002 ptrag++;
2003 }
1903 else 2004 else
1904 { 2005 {
1905 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]); 2006 *ptr2 = ARGB_JOIN(0xff, ptr[0], ptr[0], ptr[0]);
@@ -1923,11 +2024,13 @@ done:
1923 { 2024 {
1924 uint32_t *to; 2025 uint32_t *to;
1925 uint8_t *to8; 2026 uint8_t *to8;
2027 uint16_t *to16;
1926 int hw; 2028 int hw;
1927 2029
1928 hw = w * h; 2030 hw = w * h;
1929 to = pixels; 2031 to = pixels;
1930 to8 = pixels; 2032 to8 = pixels;
2033 to16 = pixels;
1931 2034
1932 switch (degree) 2035 switch (degree)
1933 { 2036 {
@@ -1939,6 +2042,13 @@ done:
1939 else 2042 else
1940 _rotate_change_wh8(to8 + h - 1, ptrg_rotate, w, h, -hw - 1, h); 2043 _rotate_change_wh8(to8 + h - 1, ptrg_rotate, w, h, -hw - 1, h);
1941 } 2044 }
2045 else if (prop->cspace == EMILE_COLORSPACE_AGRY88)
2046 {
2047 if (prop->flipped)
2048 _rotate_change_wh16(to16 + hw - 1, ptrag_rotate, w, h, hw - 1, -h);
2049 else
2050 _rotate_change_wh16(to16 + h - 1, ptrag_rotate, w, h, -hw - 1, h);
2051 }
1942 else 2052 else
1943 { 2053 {
1944 if (prop->flipped) 2054 if (prop->flipped)
@@ -1955,6 +2065,13 @@ done:
1955 else 2065 else
1956 _rotate8_180(to8, w, h); 2066 _rotate8_180(to8, w, h);
1957 } 2067 }
2068 else if (prop->cspace == EMILE_COLORSPACE_AGRY88)
2069 {
2070 if (prop->flipped)
2071 _flip_vertical16(to16, w, h);
2072 else
2073 _rotate16_180(to16, w, h);
2074 }
1958 else 2075 else
1959 { 2076 {
1960 if (prop->flipped) 2077 if (prop->flipped)
@@ -1971,6 +2088,13 @@ done:
1971 else 2088 else
1972 _rotate_change_wh8(to8 + hw - h, ptrg_rotate, w, h, hw + 1, -h); 2089 _rotate_change_wh8(to8 + hw - h, ptrg_rotate, w, h, hw + 1, -h);
1973 } 2090 }
2091 else if (prop->cspace == EMILE_COLORSPACE_AGRY88)
2092 {
2093 if (prop->flipped)
2094 _rotate_change_wh16(to16, ptrag_rotate, w, h, -hw + 1, h);
2095 else
2096 _rotate_change_wh16(to16 + hw - h, ptrag_rotate, w, h, hw + 1, -h);
2097 }
1974 else 2098 else
1975 { 2099 {
1976 if (prop->flipped) 2100 if (prop->flipped)
@@ -1984,6 +2108,8 @@ done:
1984 { 2108 {
1985 if (prop->cspace == EMILE_COLORSPACE_GRY8) 2109 if (prop->cspace == EMILE_COLORSPACE_GRY8)
1986 _flip_horizontal8(to8, w, h); 2110 _flip_horizontal8(to8, w, h);
2111 else if (prop->cspace == EMILE_COLORSPACE_AGRY88)
2112 _flip_horizontal16(to16, w, h);
1987 else 2113 else
1988 _flip_horizontal(to, w, h); 2114 _flip_horizontal(to, w, h);
1989 } 2115 }