summaryrefslogtreecommitdiff
path: root/src/lib/eet
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-03-17 08:50:26 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-17 09:58:19 +0100
commit182568f1032302756dda608156fdd6d29a2ffcd7 (patch)
tree21e62e0b025cb9997e48c0fab9b168dabbfc063d /src/lib/eet
parenta88f0074d7efc99f4eda5bd2159b22412d193ccc (diff)
eet: handle AGRY88 encoding for JPEG encoded image.
The alpha and the grey being encoded in two separated grey JPEG.
Diffstat (limited to 'src/lib/eet')
-rw-r--r--src/lib/eet/Eet.h2
-rw-r--r--src/lib/eet/eet_image.c234
2 files changed, 148 insertions, 88 deletions
diff --git a/src/lib/eet/Eet.h b/src/lib/eet/Eet.h
index 2a100ae93c..71b87cee55 100644
--- a/src/lib/eet/Eet.h
+++ b/src/lib/eet/Eet.h
@@ -495,6 +495,8 @@ typedef enum _Eet_Image_Encoding
495typedef Emile_Colorspace Eet_Colorspace; 495typedef Emile_Colorspace Eet_Colorspace;
496 496
497#define EET_COLORSPACE_ARGB8888 EMILE_COLORSPACE_ARGB8888 497#define EET_COLORSPACE_ARGB8888 EMILE_COLORSPACE_ARGB8888
498#define EET_COLORSPACE_GRY8 EMILE_COLORSPACE_GRY8
499#define EET_COLORSPACE_AGRY88 EMILE_COLORSPACE_AGRY88
498#define EET_COLORSPACE_ETC1 EMILE_COLORSPACE_ETC1 500#define EET_COLORSPACE_ETC1 EMILE_COLORSPACE_ETC1
499#define EET_COLORSPACE_RGB8_ETC2 EMILE_COLORSPACE_RGB8_ETC2 501#define EET_COLORSPACE_RGB8_ETC2 EMILE_COLORSPACE_RGB8_ETC2
500#define EET_COLORSPACE_RGBA8_ETC2_EAC EMILE_COLORSPACE_RGBA8_ETC2_EAC 502#define EET_COLORSPACE_RGBA8_ETC2_EAC EMILE_COLORSPACE_RGBA8_ETC2_EAC
diff --git a/src/lib/eet/eet_image.c b/src/lib/eet/eet_image.c
index a01f98c489..c8b1e290a1 100644
--- a/src/lib/eet/eet_image.c
+++ b/src/lib/eet/eet_image.c
@@ -177,7 +177,8 @@ static int
177eet_data_image_jpeg_header_decode(const void *data, 177eet_data_image_jpeg_header_decode(const void *data,
178 int size, 178 int size,
179 unsigned int *w, 179 unsigned int *w,
180 unsigned int *h); 180 unsigned int *h,
181 const Eet_Colorspace **cspaces);
181static int 182static int
182eet_data_image_jpeg_rgb_decode(const void *data, 183eet_data_image_jpeg_rgb_decode(const void *data,
183 int size, 184 int size,
@@ -186,16 +187,16 @@ eet_data_image_jpeg_rgb_decode(const void *data,
186 unsigned int *d, 187 unsigned int *d,
187 unsigned int w, 188 unsigned int w,
188 unsigned int h, 189 unsigned int h,
189 unsigned int row_stride); 190 Eet_Colorspace cspace);
190static int 191static int
191eet_data_image_jpeg_alpha_decode(const void *data, 192eet_data_image_jpeg_alpha_decode(const void *data,
192 int size, 193 int size,
193 unsigned int src_x, 194 unsigned int src_x,
194 unsigned int src_y, 195 unsigned int src_y,
195 unsigned int *d, 196 void *d,
196 unsigned int w, 197 unsigned int w,
197 unsigned int h, 198 unsigned int h,
198 unsigned int row_stride); 199 Eet_Colorspace cspace);
199static void * 200static void *
200eet_data_image_lossless_convert(int *size, 201eet_data_image_lossless_convert(int *size,
201 const void *data, 202 const void *data,
@@ -343,7 +344,8 @@ static int
343eet_data_image_jpeg_header_decode(const void *data, 344eet_data_image_jpeg_header_decode(const void *data,
344 int size, 345 int size,
345 unsigned int *w, 346 unsigned int *w,
346 unsigned int *h) 347 unsigned int *h,
348 const Eet_Colorspace **cspaces)
347{ 349{
348 Emile_Image_Load_Opts opts; 350 Emile_Image_Load_Opts opts;
349 Emile_Image_Property prop; 351 Emile_Image_Property prop;
@@ -368,13 +370,13 @@ eet_data_image_jpeg_header_decode(const void *data,
368 *w = prop.w; 370 *w = prop.w;
369 *h = prop.h; 371 *h = prop.h;
370 372
373 if (cspaces) *cspaces = prop.cspaces;
374
371 if (*w > 0 && *w <= 8192 && 375 if (*w > 0 && *w <= 8192 &&
372 *h > 0 && *h <= 8192) 376 *h > 0 && *h <= 8192)
373 r = 1; 377 r = 1;
374 378
375 on_error: 379 on_error:
376 fprintf(stderr, "eet_data_image_jpeg_header_decode: %i [%i, %i]\n", r, *w, *h);
377
378 emile_image_close(image); 380 emile_image_close(image);
379 eina_binbuf_free(bin); 381 eina_binbuf_free(bin);
380 382
@@ -389,7 +391,7 @@ eet_data_image_jpeg_rgb_decode(const void *data,
389 unsigned int *d, 391 unsigned int *d,
390 unsigned int w, 392 unsigned int w,
391 unsigned int h, 393 unsigned int h,
392 unsigned int row_stride) 394 Eet_Colorspace cspace)
393{ 395{
394 Emile_Image_Load_Opts opts; 396 Emile_Image_Load_Opts opts;
395 Emile_Image_Property prop; 397 Emile_Image_Property prop;
@@ -398,12 +400,12 @@ eet_data_image_jpeg_rgb_decode(const void *data,
398 Emile_Image_Load_Error error; 400 Emile_Image_Load_Error error;
399 int r = 0; 401 int r = 0;
400 402
401 /* FIXME: handle src_x, src_y and row_stride correctly */ 403 /* FIXME: handle src_x, src_y correctly */
402 if (!d) 404 if (!d)
403 return 0; 405 return 0;
404 406
405 // Fix for ABI incompatibility between 1.10 and 1.11 407 // Fix for ABI incompatibility between 1.10 and 1.11
406 /* if (cspace == 8) cspace = 9; */ 408 if (cspace == 8) cspace = 9;
407 409
408 bin = eina_binbuf_manage_read_only_new_length(data, size); 410 bin = eina_binbuf_manage_read_only_new_length(data, size);
409 if (!bin) return 0; 411 if (!bin) return 0;
@@ -422,7 +424,8 @@ eet_data_image_jpeg_rgb_decode(const void *data,
422 if (!emile_image_head(image, &prop, sizeof (Emile_Image_Property), &error)) 424 if (!emile_image_head(image, &prop, sizeof (Emile_Image_Property), &error))
423 goto on_error; 425 goto on_error;
424 426
425 // FIXME: Change prototype to handle color space and destination region (w, h) 427 prop.cspace = cspace;
428
426 if (!emile_image_data(image, &prop, sizeof (Emile_Image_Property), d, &error)) 429 if (!emile_image_data(image, &prop, sizeof (Emile_Image_Property), d, &error))
427 goto on_error; 430 goto on_error;
428 431
@@ -440,10 +443,10 @@ eet_data_image_jpeg_alpha_decode(const void *data,
440 int size, 443 int size,
441 unsigned int src_x, 444 unsigned int src_x,
442 unsigned int src_y, 445 unsigned int src_y,
443 unsigned int *d, 446 void *pixels,
444 unsigned int w, 447 unsigned int w,
445 unsigned int h, 448 unsigned int h,
446 unsigned int row_stride) 449 Eet_Colorspace cspace)
447{ 450{
448 Emile_Image_Load_Opts opts; 451 Emile_Image_Load_Opts opts;
449 Emile_Image_Property prop; 452 Emile_Image_Property prop;
@@ -455,7 +458,7 @@ eet_data_image_jpeg_alpha_decode(const void *data,
455 unsigned int i; 458 unsigned int i;
456 459
457 /* FIXME: handle src_x, src_y and row_stride correctly */ 460 /* FIXME: handle src_x, src_y and row_stride correctly */
458 if (!d) 461 if (!pixels)
459 return 0; 462 return 0;
460 463
461 bin = eina_binbuf_manage_read_only_new_length(data, size); 464 bin = eina_binbuf_manage_read_only_new_length(data, size);
@@ -484,12 +487,29 @@ eet_data_image_jpeg_alpha_decode(const void *data,
484 if (!emile_image_data(image, &prop, sizeof (Emile_Image_Property), tmp, &error)) 487 if (!emile_image_data(image, &prop, sizeof (Emile_Image_Property), tmp, &error))
485 goto on_error; 488 goto on_error;
486 489
487 for (i = 0; i < w * h; i++) 490 if (cspace == EMILE_COLORSPACE_AGRY88)
488 { 491 {
489 *d = ((*d) & 0x00ffffff) | 492 unsigned short *d = pixels;
490 ((*tmp) << 24); 493
491 tmp++; 494 for (i = 0; i < w * h; i++)
492 d++; 495 {
496 *d = ((*d) & 0x00ff) |
497 ((*tmp) << 8);
498 tmp++;
499 d++;
500 }
501 }
502 else if (cspace == EMILE_COLORSPACE_ARGB8888)
503 {
504 unsigned int *d = pixels;
505
506 for (i = 0; i < w * h; i++)
507 {
508 *d = ((*d) & 0x00ffffff) |
509 ((*tmp) << 24);
510 tmp++;
511 d++;
512 }
493 } 513 }
494 514
495 r = 1; 515 r = 1;
@@ -768,7 +788,6 @@ eet_data_image_etc1_compressed_convert(int *size,
768 Eet_Image_Encoding lossy) 788 Eet_Image_Encoding lossy)
769{ 789{
770 rg_etc1_pack_params param; 790 rg_etc1_pack_params param;
771 uint8_t *comp = NULL;
772 uint8_t *buffer; 791 uint8_t *buffer;
773 uint32_t *data; 792 uint32_t *data;
774 uint32_t nl_width, nl_height; 793 uint32_t nl_width, nl_height;
@@ -890,7 +909,6 @@ eet_data_image_etc1_compressed_convert(int *size,
890 { 909 {
891 uint32_t *input, *last_col, *last_row, *last_pix; 910 uint32_t *input, *last_col, *last_row, *last_pix;
892 int real_y; 911 int real_y;
893 int wlen;
894 912
895 if (y == 0) real_y = 0; 913 if (y == 0) real_y = 0;
896 else if (y < image_height + 1) real_y = y - 1; 914 else if (y < image_height + 1) real_y = y - 1;
@@ -1587,16 +1605,42 @@ eet_data_image_encode(const void *data,
1587 comp, quality, lossy, size_ret); 1605 comp, quality, lossy, size_ret);
1588} 1606}
1589 1607
1590EAPI int 1608static const Eet_Colorspace _eet_etc1_colorspace[] = {
1591eet_data_image_header_decode_cipher(const void *data, 1609 EET_COLORSPACE_ETC1,
1592 const char *cipher_key, 1610 EET_COLORSPACE_ARGB8888
1593 int size, 1611};
1594 unsigned int *w, 1612
1595 unsigned int *h, 1613static const Eet_Colorspace _eet_etc1_alpha_colorspace[] = {
1596 int *alpha, 1614 EET_COLORSPACE_ETC1_ALPHA,
1597 int *comp, 1615 EET_COLORSPACE_ARGB8888
1598 int *quality, 1616};
1599 Eet_Image_Encoding *lossy) 1617
1618static const Eet_Colorspace _eet_etc2_rgb_colorspace[] = {
1619 EET_COLORSPACE_RGB8_ETC2,
1620 EET_COLORSPACE_ARGB8888
1621};
1622
1623static const Eet_Colorspace _eet_etc2_rgba_colorspace[] = {
1624 EET_COLORSPACE_RGBA8_ETC2_EAC,
1625 EET_COLORSPACE_ARGB8888
1626};
1627
1628static const Eet_Colorspace _eet_gry8_alpha_colorspace[] = {
1629 EET_COLORSPACE_AGRY88,
1630 EET_COLORSPACE_ARGB8888
1631};
1632
1633static int
1634eet_data_image_header_advance_decode_cipher(const void *data,
1635 const char *cipher_key,
1636 int size,
1637 unsigned int *w,
1638 unsigned int *h,
1639 int *alpha,
1640 int *comp,
1641 int *quality,
1642 Eet_Image_Encoding *lossy,
1643 const Eet_Colorspace **cspaces)
1600{ 1644{
1601 int header[8]; 1645 int header[8];
1602 void *deciphered_d = NULL; 1646 void *deciphered_d = NULL;
@@ -1672,7 +1716,7 @@ eet_data_image_header_decode_cipher(const void *data,
1672 goto on_error; 1716 goto on_error;
1673 dt = data; 1717 dt = data;
1674 dt += 12; 1718 dt += 12;
1675 ok = eet_data_image_jpeg_header_decode(dt, sz1, &iw, &ih); 1719 ok = eet_data_image_jpeg_header_decode(dt, sz1, &iw, &ih, cspaces);
1676 if (ok) 1720 if (ok)
1677 { 1721 {
1678 if (w) 1722 if (w)
@@ -1709,18 +1753,22 @@ eet_data_image_header_decode_cipher(const void *data,
1709 case 0: 1753 case 0:
1710 if (lossy) *lossy = EET_IMAGE_ETC1; 1754 if (lossy) *lossy = EET_IMAGE_ETC1;
1711 if (alpha) *alpha = EINA_FALSE; 1755 if (alpha) *alpha = EINA_FALSE;
1756 if (cspaces) *cspaces = _eet_etc1_colorspace;
1712 break; 1757 break;
1713 case 1: 1758 case 1:
1714 if (lossy) *lossy = EET_IMAGE_ETC2_RGB; 1759 if (lossy) *lossy = EET_IMAGE_ETC2_RGB;
1715 if (alpha) *alpha = EINA_FALSE; 1760 if (alpha) *alpha = EINA_FALSE;
1761 if (cspaces) *cspaces = _eet_etc2_rgb_colorspace;
1716 break; 1762 break;
1717 case 2: 1763 case 2:
1718 if (alpha) *alpha = EINA_TRUE; 1764 if (alpha) *alpha = EINA_TRUE;
1719 if (lossy) *lossy = EET_IMAGE_ETC2_RGBA; 1765 if (lossy) *lossy = EET_IMAGE_ETC2_RGBA;
1766 if (cspaces) *cspaces = _eet_etc2_rgba_colorspace;
1720 break; 1767 break;
1721 case 3: 1768 case 3:
1722 if (alpha) *alpha = EINA_TRUE; 1769 if (alpha) *alpha = EINA_TRUE;
1723 if (lossy) *lossy = EET_IMAGE_ETC1_ALPHA; 1770 if (lossy) *lossy = EET_IMAGE_ETC1_ALPHA;
1771 if (cspaces) *cspaces = _eet_etc1_alpha_colorspace;
1724 break; 1772 break;
1725 default: 1773 default:
1726 goto on_error; 1774 goto on_error;
@@ -1734,7 +1782,7 @@ eet_data_image_header_decode_cipher(const void *data,
1734 unsigned int iw = 0, ih = 0; 1782 unsigned int iw = 0, ih = 0;
1735 int ok; 1783 int ok;
1736 1784
1737 ok = eet_data_image_jpeg_header_decode(data, size, &iw, &ih); 1785 ok = eet_data_image_jpeg_header_decode(data, size, &iw, &ih, cspaces);
1738 if (ok) 1786 if (ok)
1739 { 1787 {
1740 if (w) 1788 if (w)
@@ -1755,6 +1803,12 @@ eet_data_image_header_decode_cipher(const void *data,
1755 if (quality) 1803 if (quality)
1756 *quality = 75; 1804 *quality = 75;
1757 1805
1806 if (cspaces)
1807 {
1808 if ((*cspaces)[0] == EMILE_COLORSPACE_GRY8)
1809 *cspaces = _eet_gry8_alpha_colorspace;
1810 }
1811
1758 r = 1; 1812 r = 1;
1759 } 1813 }
1760 } 1814 }
@@ -1764,25 +1818,22 @@ eet_data_image_header_decode_cipher(const void *data,
1764 return r; 1818 return r;
1765} 1819}
1766 1820
1767static const Eet_Colorspace _eet_etc1_colorspace[] = { 1821EAPI int
1768 EET_COLORSPACE_ETC1, 1822eet_data_image_header_decode_cipher(const void *data,
1769 EET_COLORSPACE_ARGB8888 1823 const char *cipher_key,
1770}; 1824 int size,
1771 1825 unsigned int *w,
1772static const Eet_Colorspace _eet_etc1_alpha_colorspace[] = { 1826 unsigned int *h,
1773 EET_COLORSPACE_ETC1_ALPHA, 1827 int *alpha,
1774 EET_COLORSPACE_ARGB8888 1828 int *comp,
1775}; 1829 int *quality,
1776 1830 Eet_Image_Encoding *lossy)
1777static const Eet_Colorspace _eet_etc2_rgb_colorspace[] = { 1831{
1778 EET_COLORSPACE_RGB8_ETC2, 1832 return eet_data_image_header_advance_decode_cipher(data, cipher_key, size,
1779 EET_COLORSPACE_ARGB8888 1833 w, h,
1780}; 1834 alpha, comp, quality, lossy,
1781 1835 NULL);
1782static const Eet_Colorspace _eet_etc2_rgba_colorspace[] = { 1836}
1783 EET_COLORSPACE_RGBA8_ETC2_EAC,
1784 EET_COLORSPACE_ARGB8888
1785};
1786 1837
1787EAPI int 1838EAPI int
1788eet_data_image_colorspace_get(Eet_File *ef, 1839eet_data_image_colorspace_get(Eet_File *ef,
@@ -1790,25 +1841,29 @@ eet_data_image_colorspace_get(Eet_File *ef,
1790 const char *cipher_key, 1841 const char *cipher_key,
1791 const Eet_Colorspace **cspaces) 1842 const Eet_Colorspace **cspaces)
1792{ 1843{
1793 Eet_Image_Encoding lossy; 1844 void *data = NULL;
1794 int r; 1845 int size = 0;
1846 int free_data = 0;
1847 int d;
1795 1848
1796 r = eet_data_image_header_read_cipher(ef, name, cipher_key, NULL, NULL, NULL, NULL, NULL, &lossy); 1849 if (!cipher_key)
1797 if (!r) return r; 1850 data = (void *)eet_read_direct(ef, name, &size);
1798 1851
1799 if (cspaces) 1852 if (!data)
1800 { 1853 {
1801 if (lossy == EET_IMAGE_ETC1) 1854 data = eet_read_cipher(ef, name, &size, cipher_key);
1802 *cspaces = _eet_etc1_colorspace; 1855 free_data = 1;
1803 else if (lossy == EET_IMAGE_ETC2_RGB) 1856 if (!data)
1804 *cspaces = _eet_etc2_rgb_colorspace; 1857 return 0;
1805 else if (lossy == EET_IMAGE_ETC2_RGBA)
1806 *cspaces = _eet_etc2_rgba_colorspace;
1807 else if (lossy == EET_IMAGE_ETC1_ALPHA)
1808 *cspaces = _eet_etc1_alpha_colorspace;
1809 } 1858 }
1810 1859
1811 return r; 1860 d = eet_data_image_header_advance_decode_cipher(data, NULL, size, NULL, NULL,
1861 NULL, NULL, NULL, NULL,
1862 cspaces);
1863 if (free_data)
1864 free(data);
1865
1866 return d;
1812} 1867}
1813 1868
1814EAPI int 1869EAPI int
@@ -1945,16 +2000,16 @@ _eet_data_image_decode_inside(const void *data,
1945 dt += 12; 2000 dt += 12;
1946 2001
1947 if (eet_data_image_jpeg_rgb_decode(dt, sz1, src_x, src_y, d, w, h, 2002 if (eet_data_image_jpeg_rgb_decode(dt, sz1, src_x, src_y, d, w, h,
1948 row_stride)) 2003 cspace))
1949 { 2004 {
1950 dt += sz1; 2005 dt += sz1;
1951 if (!eet_data_image_jpeg_alpha_decode(dt, sz2, src_x, src_y, 2006 if (!eet_data_image_jpeg_alpha_decode(dt, sz2, src_x, src_y,
1952 d, w, h, row_stride)) 2007 d, w, h, cspace))
1953 return 0; 2008 return 0;
1954 } 2009 }
1955 } 2010 }
1956 else if (!eet_data_image_jpeg_rgb_decode(data, size, src_x, src_y, d, w, 2011 else if (!eet_data_image_jpeg_rgb_decode(data, size, src_x, src_y, d, w,
1957 h, row_stride)) 2012 h, cspace))
1958 return 0; 2013 return 0;
1959 } 2014 }
1960 else if ((lossy == EET_IMAGE_ETC1) || 2015 else if ((lossy == EET_IMAGE_ETC1) ||
@@ -2074,6 +2129,7 @@ eet_data_image_decode_to_cspace_surface_cipher(const void *data,
2074 unsigned int iw, ih; 2129 unsigned int iw, ih;
2075 int ialpha, icompress, iquality; 2130 int ialpha, icompress, iquality;
2076 Eet_Image_Encoding ilossy; 2131 Eet_Image_Encoding ilossy;
2132 const Eet_Colorspace *cspaces = NULL;
2077 void *deciphered_d = NULL; 2133 void *deciphered_d = NULL;
2078 unsigned int deciphered_sz = 0; 2134 unsigned int deciphered_sz = 0;
2079 2135
@@ -2091,32 +2147,34 @@ eet_data_image_decode_to_cspace_surface_cipher(const void *data,
2091 } 2147 }
2092 2148
2093 /* All check are done during header decode, this simplify the code a lot. */ 2149 /* All check are done during header decode, this simplify the code a lot. */
2094 if (!eet_data_image_header_decode(data, size, &iw, &ih, &ialpha, &icompress, 2150 if (!eet_data_image_header_advance_decode_cipher(data, NULL, size,
2095 &iquality, &ilossy)) 2151 &iw, &ih,
2152 &ialpha, &icompress, &iquality,
2153 &ilossy,
2154 &cspaces))
2096 return 0; 2155 return 0;
2097 2156
2098 if (!d) 2157 if (!d)
2099 return 0; 2158 return 0;
2100 2159
2101 if (cspace == EET_COLORSPACE_ETC1 && 2160 if (cspaces)
2102 ilossy != EET_IMAGE_ETC1) 2161 {
2103 return 0; 2162 unsigned int i;
2104
2105 if (cspace == EET_COLORSPACE_RGB8_ETC2 &&
2106 ilossy != EET_IMAGE_ETC2_RGB)
2107 return 0;
2108
2109 if (cspace == EET_COLORSPACE_RGBA8_ETC2_EAC &&
2110 ilossy != EET_IMAGE_ETC2_RGBA)
2111 return 0;
2112 2163
2113 if (cspace == EET_COLORSPACE_ETC1_ALPHA && 2164 for (i = 0; cspaces[i] != EET_COLORSPACE_ARGB8888; i++)
2114 ilossy != EET_IMAGE_ETC1_ALPHA) 2165 if (cspaces[i] == cspace)
2115 return 0; 2166 break ;
2116 2167
2117 if (cspace == EET_COLORSPACE_ARGB8888 && 2168 if (cspaces[i] != cspace)
2118 w * 4 > row_stride) 2169 return 0;
2119 return 0; 2170 }
2171 else
2172 {
2173 if ((cspaces != EET_COLORSPACE_ARGB8888) ||
2174 (cspace == EET_COLORSPACE_ARGB8888 &&
2175 w * 4 > row_stride))
2176 return 0;
2177 }
2120 2178
2121 if (w > iw || h > ih) 2179 if (w > iw || h > ih)
2122 return 0; 2180 return 0;