summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@samsung.com>2014-03-18 18:11:49 +0900
committerCedric BAIL <cedric.bail@free.fr>2014-04-01 22:00:15 +0900
commitb1e576081175835cfef1626b85c3bf99fc3d8d13 (patch)
tree9572b0e52c01bbe99e6f960f14e481599a6b430c
parente47dbc02ea75f5976aa08c137c2cd92491c5dc8f (diff)
eet: add internal encoding to ETC1 as an alternate solution to Jpeg.
-rw-r--r--src/Makefile_Eet.am5
-rw-r--r--src/lib/eet/Eet.h51
-rw-r--r--src/lib/eet/eet_image.c472
-rw-r--r--src/modules/evas/loaders/eet/evas_image_load_eet.c12
-rw-r--r--src/tests/eet/eet_suite.c4
5 files changed, 479 insertions, 65 deletions
diff --git a/src/Makefile_Eet.am b/src/Makefile_Eet.am
index b8540f511e..a6055f15fd 100644
--- a/src/Makefile_Eet.am
+++ b/src/Makefile_Eet.am
@@ -20,10 +20,13 @@ lib/eet/eet_utils.c \
20static_libs/lz4/lz4.c \ 20static_libs/lz4/lz4.c \
21static_libs/lz4/lz4.h \ 21static_libs/lz4/lz4.h \
22static_libs/lz4/lz4hc.c \ 22static_libs/lz4/lz4hc.c \
23static_libs/lz4/lz4hc.h 23static_libs/lz4/lz4hc.h \
24static_libs/rg_etc/rg_etc1.c \
25static_libs/rg_etc/rg_etc1.h
24 26
25lib_eet_libeet_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \ 27lib_eet_libeet_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl \
26-I$(top_srcdir)/src/static_libs/lz4 \ 28-I$(top_srcdir)/src/static_libs/lz4 \
29-I$(top_srcdir)/src/static_libs/rg_etc \
27-DPACKAGE_BIN_DIR=\"$(bindir)\" \ 30-DPACKAGE_BIN_DIR=\"$(bindir)\" \
28-DPACKAGE_LIB_DIR=\"$(libdir)\" \ 31-DPACKAGE_LIB_DIR=\"$(libdir)\" \
29-DPACKAGE_DATA_DIR=\"$(datadir)/eet\" \ 32-DPACKAGE_DATA_DIR=\"$(datadir)/eet\" \
diff --git a/src/lib/eet/Eet.h b/src/lib/eet/Eet.h
index 60e58d4541..e3a01fc096 100644
--- a/src/lib/eet/Eet.h
+++ b/src/lib/eet/Eet.h
@@ -469,6 +469,25 @@ typedef enum _Eet_File_Mode
469} Eet_File_Mode; /**< Modes that a file can be opened. */ 469} Eet_File_Mode; /**< Modes that a file can be opened. */
470 470
471/** 471/**
472 * @enum _Eet_Image_Encoding
473 * Specify lossy encoding for image
474 * @since 1.10
475 */
476typedef enum _Eet_Image_Encoding
477{
478 EET_IMAGE_LOSSLESS = 0,
479 EET_IMAGE_JPEG = 1,
480 EET_IMAGE_ETC1 = 2
481} Eet_Image_Encoding;
482
483typedef enum _Eet_Colorspace
484{
485 EET_COLORSPACE_ARGB8888 = 0,
486 /* The number between are reserved to preserve compatibility with evas */
487 EET_COLORSPACE_ETC1 = 8
488} Eet_Colorspace;
489
490/**
472 * @typedef Eet_File 491 * @typedef Eet_File
473 * Opaque handle that defines an Eet file (or memory). 492 * Opaque handle that defines an Eet file (or memory).
474 * 493 *
@@ -1054,7 +1073,7 @@ eet_data_image_header_read(Eet_File *ef,
1054 int *alpha, 1073 int *alpha,
1055 int *compress, 1074 int *compress,
1056 int *quality, 1075 int *quality,
1057 int *lossy); 1076 Eet_Image_Encoding *lossy);
1058 1077
1059/** 1078/**
1060 * Read image data from the named key in the eet file. 1079 * Read image data from the named key in the eet file.
@@ -1099,7 +1118,7 @@ eet_data_image_read(Eet_File *ef,
1099 int *alpha, 1118 int *alpha,
1100 int *compress, 1119 int *compress,
1101 int *quality, 1120 int *quality,
1102 int *lossy); 1121 Eet_Image_Encoding *lossy);
1103 1122
1104/** 1123/**
1105 * Read image data from the named key in the eet file and store it in the given buffer. 1124 * Read image data from the named key in the eet file and store it in the given buffer.
@@ -1160,7 +1179,7 @@ eet_data_image_read_to_surface(Eet_File *ef,
1160 int *alpha, 1179 int *alpha,
1161 int *compress, 1180 int *compress,
1162 int *quality, 1181 int *quality,
1163 int *lossy); 1182 Eet_Image_Encoding *lossy);
1164 1183
1165/** 1184/**
1166 * Write image data to the named key in an eet file. 1185 * Write image data to the named key in an eet file.
@@ -1208,7 +1227,7 @@ eet_data_image_write(Eet_File *ef,
1208 int alpha, 1227 int alpha,
1209 int compress, 1228 int compress,
1210 int quality, 1229 int quality,
1211 int lossy); 1230 Eet_Image_Encoding lossy);
1212 1231
1213/** 1232/**
1214 * Decode Image data header only to get information. 1233 * Decode Image data header only to get information.
@@ -1243,7 +1262,7 @@ eet_data_image_header_decode(const void *data,
1243 int *alpha, 1262 int *alpha,
1244 int *compress, 1263 int *compress,
1245 int *quality, 1264 int *quality,
1246 int *lossy); 1265 Eet_Image_Encoding *lossy);
1247 1266
1248/** 1267/**
1249 * Decode Image data into pixel data. 1268 * Decode Image data into pixel data.
@@ -1283,7 +1302,7 @@ eet_data_image_decode(const void *data,
1283 int *alpha, 1302 int *alpha,
1284 int *compress, 1303 int *compress,
1285 int *quality, 1304 int *quality,
1286 int *lossy); 1305 Eet_Image_Encoding *lossy);
1287 1306
1288/** 1307/**
1289 * Decode Image data into pixel data and stores in the given buffer. 1308 * Decode Image data into pixel data and stores in the given buffer.
@@ -1325,7 +1344,7 @@ eet_data_image_decode_to_surface(const void *data,
1325 int *alpha, 1344 int *alpha,
1326 int *compress, 1345 int *compress,
1327 int *quality, 1346 int *quality,
1328 int *lossy); 1347 Eet_Image_Encoding *lossy);
1329 1348
1330/** 1349/**
1331 * Encode image data for storage or transmission. 1350 * Encode image data for storage or transmission.
@@ -1365,7 +1384,7 @@ eet_data_image_encode(const void *data,
1365 int alpha, 1384 int alpha,
1366 int compress, 1385 int compress,
1367 int quality, 1386 int quality,
1368 int lossy); 1387 Eet_Image_Encoding lossy);
1369 1388
1370/** 1389/**
1371 * @defgroup Eet_File_Image_Cipher_Group Image Store and Load using a Cipher 1390 * @defgroup Eet_File_Image_Cipher_Group Image Store and Load using a Cipher
@@ -1424,7 +1443,7 @@ eet_data_image_header_read_cipher(Eet_File *ef,
1424 int *alpha, 1443 int *alpha,
1425 int *compress, 1444 int *compress,
1426 int *quality, 1445 int *quality,
1427 int *lossy); 1446 Eet_Image_Encoding *lossy);
1428 1447
1429/** 1448/**
1430 * Read image data from the named key in the eet file using a cipher. 1449 * Read image data from the named key in the eet file using a cipher.
@@ -1474,7 +1493,7 @@ eet_data_image_read_cipher(Eet_File *ef,
1474 int *alpha, 1493 int *alpha,
1475 int *compress, 1494 int *compress,
1476 int *quality, 1495 int *quality,
1477 int *lossy); 1496 Eet_Image_Encoding *lossy);
1478 1497
1479/** 1498/**
1480 * Read image data from the named key in the eet file using a cipher. 1499 * Read image data from the named key in the eet file using a cipher.
@@ -1530,7 +1549,7 @@ eet_data_image_read_to_surface_cipher(Eet_File *ef,
1530 int *alpha, 1549 int *alpha,
1531 int *compress, 1550 int *compress,
1532 int *quality, 1551 int *quality,
1533 int *lossy); 1552 Eet_Image_Encoding *lossy);
1534 1553
1535/** 1554/**
1536 * Write image data to the named key in an eet file using a cipher. 1555 * Write image data to the named key in an eet file using a cipher.
@@ -1578,7 +1597,7 @@ eet_data_image_write_cipher(Eet_File *ef,
1578 int alpha, 1597 int alpha,
1579 int compress, 1598 int compress,
1580 int quality, 1599 int quality,
1581 int lossy); 1600 Eet_Image_Encoding lossy);
1582 1601
1583/** 1602/**
1584 * Decode Image data header only to get information using a cipher. 1603 * Decode Image data header only to get information using a cipher.
@@ -1626,7 +1645,7 @@ eet_data_image_header_decode_cipher(const void *data,
1626 int *alpha, 1645 int *alpha,
1627 int *compress, 1646 int *compress,
1628 int *quality, 1647 int *quality,
1629 int *lossy); 1648 Eet_Image_Encoding *lossy);
1630 1649
1631/** 1650/**
1632 * Decode Image data into pixel data using a cipher. 1651 * Decode Image data into pixel data using a cipher.
@@ -1676,7 +1695,7 @@ eet_data_image_decode_cipher(const void *data,
1676 int *alpha, 1695 int *alpha,
1677 int *compress, 1696 int *compress,
1678 int *quality, 1697 int *quality,
1679 int *lossy); 1698 Eet_Image_Encoding *lossy);
1680 1699
1681/** 1700/**
1682 * Decode Image data into pixel data using a cipher. 1701 * Decode Image data into pixel data using a cipher.
@@ -1732,7 +1751,7 @@ eet_data_image_decode_to_surface_cipher(const void *data,
1732 int *alpha, 1751 int *alpha,
1733 int *compress, 1752 int *compress,
1734 int *quality, 1753 int *quality,
1735 int *lossy); 1754 Eet_Image_Encoding *lossy);
1736 1755
1737/** 1756/**
1738 * Encode image data for storage or transmission using a cipher. 1757 * Encode image data for storage or transmission using a cipher.
@@ -1777,7 +1796,7 @@ eet_data_image_encode_cipher(const void *data,
1777 int alpha, 1796 int alpha,
1778 int compress, 1797 int compress,
1779 int quality, 1798 int quality,
1780 int lossy, 1799 Eet_Image_Encoding lossy,
1781 int *size_ret); 1800 int *size_ret);
1782 1801
1783/** 1802/**
diff --git a/src/lib/eet/eet_image.c b/src/lib/eet/eet_image.c
index f8719443f5..eebed301e7 100644
--- a/src/lib/eet/eet_image.c
+++ b/src/lib/eet/eet_image.c
@@ -28,6 +28,16 @@
28#include "lz4.h" 28#include "lz4.h"
29#include "lz4hc.h" 29#include "lz4hc.h"
30 30
31#include "rg_etc1.h"
32
33#define OFFSET_BLOCK_SIZE 4
34#define OFFSET_ALGORITHN 5
35#define OFFSET_OPTIONS 6
36#define OFFSET_WIDTH 8
37#define OFFSET_HEIGHT 12
38#define OFFSET_BLOCKS 16
39
40
31/*---*/ 41/*---*/
32 42
33typedef struct _JPEG_error_mgr *emptr; 43typedef struct _JPEG_error_mgr *emptr;
@@ -662,6 +672,172 @@ eet_data_image_jpeg_alpha_decode(const void *data,
662 return 1; 672 return 1;
663} 673}
664 674
675static inline unsigned int
676_tgv_length_get(const char *m, unsigned int length, unsigned int *offset)
677{
678 unsigned int r = 0;
679 unsigned int shift = 0;
680
681 while (*offset < length && ((*m) & 0x80))
682 {
683 r = r | (((*m) & 0x7F) << shift);
684 shift += 7;
685 m++;
686 (*offset)++;
687 }
688 if (*offset < length)
689 {
690 r = r | (((*m) & 0x7F) << shift);
691 (*offset)++;
692 }
693
694 return r;
695}
696
697static int
698eet_data_image_etc1_decode(const void *data,
699 unsigned int length,
700 unsigned int *p,
701 unsigned int dst_x,
702 unsigned int dst_y,
703 unsigned int dst_w,
704 unsigned int dst_h,
705 unsigned int cspace)
706{
707 Eina_Rectangle master;
708 Eina_Rectangle current;
709 const char *m = data;
710 char *buffer;
711 unsigned int block_width, block_height;
712 unsigned int compress;
713 unsigned int width, height;
714 unsigned int block_count;
715 unsigned int etc1_width = 0;
716 unsigned int offset;
717 unsigned int x, y;
718
719 block_width = 4 << (m[OFFSET_BLOCK_SIZE] & 0x0f);
720 block_height = 4 << ((m[OFFSET_BLOCK_SIZE] & 0xf0) >> 4);
721
722 if (m[OFFSET_ALGORITHN] != 0) return 0;
723
724 compress = m[OFFSET_OPTIONS] & 0x1;
725
726 width = ntohl(*((unsigned int*) &(m[OFFSET_WIDTH])));
727 height = ntohl(*((unsigned int*) &(m[OFFSET_HEIGHT])));
728
729 EINA_RECTANGLE_SET(&master, 0, 0, width, height);
730 EINA_RECTANGLE_SET(&current, dst_x, dst_y, dst_w, dst_h);
731
732 if (!eina_rectangle_intersection(&master, &current))
733 return 0;
734
735 if (cspace == EET_COLORSPACE_ETC1)
736 {
737 if (master.x % 4 ||
738 master.y % 4)
739 abort ();
740
741 etc1_width = ((dst_w + 2) / 4 + ((dst_w + 2) % 4 ? 1 : 0)) * 8;
742 }
743 else
744 {
745 // Account for duplicated border pixels
746 master.x += 1;
747 master.y += 1;
748 }
749
750 // Allocate space for each ETC1 block (64bytes per 4 * 4 pixels group)
751 block_count = block_width * block_height / (4 * 4);
752 if (compress)
753 buffer = alloca(8 * block_count);
754 else
755 buffer = NULL;
756
757 offset = OFFSET_BLOCKS;
758
759 for (y = 0; y < height + 2; y += block_height)
760 for (x = 0; x < width + 2; x += block_width)
761 {
762 const char *data_start;
763 const char *it;
764 unsigned int block_length;
765 unsigned int expand_length;
766 unsigned int i, j;
767
768 block_length = _tgv_length_get(m + offset, length, &offset);
769 if (block_length == 0) return 0;
770
771 data_start = m + offset;
772 offset += block_length;
773
774 EINA_RECTANGLE_SET(&current, x, y,
775 block_width, block_height);
776 if (!eina_rectangle_intersection(&current, &master))
777 continue ;
778
779 if (compress)
780 {
781 expand_length = LZ4_uncompress(data_start,
782 buffer, block_count * 8);
783 // That's an overhead for now, need to be fixed
784 if (expand_length != block_length)
785 return 0;
786 }
787 else
788 {
789 buffer = (void*) data_start;
790 if (block_count * 8 != block_length)
791 return 0;
792 }
793 it = buffer;
794
795 for (i = 0; i < block_height; i += 4)
796 for (j = 0; j < block_width; j += 4, it += 8)
797 {
798 Eina_Rectangle current_etc;
799 unsigned int temporary[4 * 4] = { 0 };
800 unsigned int offset_x, offset_y;
801 int k;
802
803 EINA_RECTANGLE_SET(&current_etc, x + j, y + i, 4, 4);
804
805 if (!eina_rectangle_intersection(&current_etc, &current))
806 continue ;
807
808 switch (cspace)
809 {
810 case EET_COLORSPACE_ARGB8888:
811 if (!rg_etc1_unpack_block(it, temporary, 0))
812 {
813 fprintf(stderr, "HOUSTON WE HAVE A PROBLEM ! Block starting at {%i, %i} is corrupted !\n", x + j, y + i);
814 continue ;
815 }
816
817 offset_x = current_etc.x - x - j;
818 offset_y = current_etc.y - y - i;
819 for (k = 0; k < current_etc.h; k++)
820 {
821 memcpy(&p[current_etc.x - 1 +
822 (current_etc.y - 1 + k) * master.w],
823 &temporary[offset_x + (offset_y + k) * 4],
824 current_etc.w * sizeof (unsigned int));
825 }
826 break;
827 case EET_COLORSPACE_ETC1:
828 memcpy(&p[current_etc.x +
829 current_etc.y * etc1_width],
830 it, 8);
831 break;
832 default:
833 abort();
834 }
835 }
836 }
837
838 return 1;
839}
840
665static void * 841static void *
666eet_data_image_lossless_convert(int *size, 842eet_data_image_lossless_convert(int *size,
667 const void *data, 843 const void *data,
@@ -818,6 +994,191 @@ eet_data_image_lossless_compressed_convert(int *size,
818} 994}
819 995
820static void * 996static void *
997eet_data_image_etc1_compressed_convert(int *size,
998 const unsigned char *data,
999 unsigned int w,
1000 unsigned int h,
1001 int quality,
1002 int compression)
1003{
1004 Eina_Binbuf *r;
1005 rg_etc1_pack_params param;
1006 unsigned char header[8] = "TGV1";
1007 unsigned int nw, nh;
1008 unsigned int block, block_count;
1009 unsigned int x, y;
1010 unsigned int compress_length;
1011 unsigned int real_x, real_y;
1012 char *comp;
1013 char *buffer;
1014 void *result;
1015
1016 r = eina_binbuf_new();
1017 if (!r) return NULL;
1018
1019 nw = htonl(w);
1020 nh = htonl(h);
1021 param.m_dithering = 1;
1022 if (quality > 70)
1023 {
1024 param.m_quality = rg_etc1_high_quality;
1025 block = 7;
1026 }
1027 else if (quality < 30)
1028 {
1029 param.m_quality = rg_etc1_medium_quality;
1030 block = 6;
1031 }
1032 else
1033 {
1034 param.m_quality = rg_etc1_low_quality;
1035 block = 5;
1036 }
1037
1038 header[4] = (block << 4) | block;
1039 header[5] = 0;
1040 header[6] = (!!compression & 0x1); // For now only LZ4 compression
1041 header[7] = 0;
1042
1043 eina_binbuf_append_length(r, header, sizeof (header));
1044 eina_binbuf_append_length(r, (unsigned char*) &nw, sizeof (nw));
1045 eina_binbuf_append_length(r, (unsigned char*) &nh, sizeof (nh));
1046
1047 block = 4 << block;
1048 block_count = (block * block) / (4 * 4);
1049 buffer = alloca(block_count * 8);
1050
1051 if (compression)
1052 {
1053 compress_length = LZ4_compressBound(block_count * 8);
1054 comp = alloca(compress_length);
1055 }
1056 else
1057 {
1058 comp = NULL;
1059 }
1060
1061 // Write block
1062 for (y = 0; y < h + 2; y += block)
1063 {
1064 real_y = y > 0 ? y - 1 : 0;
1065
1066 for (x = 0; x < w + 2; x += block)
1067 {
1068 unsigned int i, j;
1069 unsigned char duplicate_w[2], duplicate_h[2];
1070 int wlen;
1071 char *offset = buffer;
1072
1073 real_x = x > 0 ? x - 1 : 0;
1074
1075 for (i = 0; i < block; i += 4)
1076 {
1077 unsigned char block_h;
1078 int kmax;
1079
1080 duplicate_h[0] = !!((real_y + i) == 0);
1081 duplicate_h[1] = !!((real_y + i + (4 - duplicate_h[0])) >= h);
1082 block_h = 4 - duplicate_h[0] - duplicate_h[1];
1083
1084 kmax = real_y + i + block_h < h ?
1085 block_h : h - real_y - i - 1;
1086
1087 for (j = 0; j < block; j += 4)
1088 {
1089 unsigned char todo[64] = { 0 };
1090 unsigned char block_w;
1091 int block_length;
1092 int k, lmax;
1093
1094
1095 duplicate_w[0] = !!((real_x + j) == 0);
1096 duplicate_w[1] = !!(((real_x + j + (4 - duplicate_w[0]))) >= w);
1097 block_w = 4 - duplicate_w[0] - duplicate_w[1];
1098
1099 lmax = real_x + j + block_w < w ?
1100 block_w : w - real_x - j - 1;
1101 block_length = real_x + j + 4 < w ?
1102 4 : w - real_x - j - 1;
1103
1104 if (lmax > 0)
1105 {
1106 for (k = duplicate_h[0]; k < kmax; k++)
1107 memcpy(&todo[(k + duplicate_h[0]) * 16 + duplicate_w[0] * 4],
1108 &data[(real_y + i + k) * w + real_x + j],
1109 4 * lmax);
1110 }
1111
1112
1113 if (duplicate_h[0] && block_length > 0) // Duplicate first line
1114 memcpy(&todo[0],
1115 &data[(real_y + i) * w + real_x + j],
1116 block_length * 4);
1117
1118 if (duplicate_h[1] && block_length > 0 && kmax >= 0) // Duplicate last line
1119 memcpy(&todo[kmax * 16],
1120 &data[(real_y + i + kmax) * w + real_x + j],
1121 block_length * 4);
1122
1123 if (duplicate_w[0]) // Duplicate first row
1124 {
1125 for (k = 0; k < kmax; k++)
1126 memcpy(&todo[(k + duplicate_h[0]) * 16],
1127 &data[(real_y + i + k) * w + real_x + j],
1128 4); // Copy a pixel at a time
1129 }
1130
1131 if (duplicate_w[1] && lmax >= 0) // Duplicate last row
1132 {
1133 for (k = 0; k < kmax; k++)
1134 memcpy(&todo[(k + duplicate_h[0]) * 16 + (duplicate_w[0] + lmax) * 4],
1135 &data[(real_y + i + k) * w + real_x + j + lmax],
1136 4); // Copy a pixel at a time
1137 }
1138
1139
1140 rg_etc1_pack_block(offset, (unsigned int*) todo, &param);
1141 offset += 8;
1142 }
1143 }
1144
1145 if (compression)
1146 {
1147 wlen = LZ4_compress(buffer, comp, block_count * 8);
1148 }
1149 else
1150 {
1151 comp = buffer;
1152 wlen = block_count * 8;
1153 }
1154
1155 if (wlen > 0)
1156 {
1157 unsigned int blen = wlen;
1158
1159 while (blen)
1160 {
1161 unsigned char plen;
1162
1163 plen = blen & 0x7F;
1164 blen = blen >> 7;
1165
1166 if (blen) plen = 0x80 | plen;
1167 eina_binbuf_append_length(r, &plen, 1);
1168 }
1169 eina_binbuf_append_length(r, (unsigned char *) comp, wlen);
1170 }
1171 }
1172 }
1173
1174 *size = eina_binbuf_length_get(r);
1175 result = eina_binbuf_string_steal(r);
1176 eina_binbuf_free(r);
1177
1178 return result;
1179}
1180
1181static void *
821eet_data_image_jpeg_convert(int *size, 1182eet_data_image_jpeg_convert(int *size,
822 const void *data, 1183 const void *data,
823 unsigned int w, 1184 unsigned int w,
@@ -1101,7 +1462,7 @@ eet_data_image_write_cipher(Eet_File *ef,
1101 int alpha, 1462 int alpha,
1102 int comp, 1463 int comp,
1103 int quality, 1464 int quality,
1104 int lossy) 1465 Eet_Image_Encoding lossy)
1105{ 1466{
1106 void *d = NULL; 1467 void *d = NULL;
1107 int size = 0; 1468 int size = 0;
@@ -1128,7 +1489,7 @@ eet_data_image_write(Eet_File *ef,
1128 int alpha, 1489 int alpha,
1129 int comp, 1490 int comp,
1130 int quality, 1491 int quality,
1131 int lossy) 1492 Eet_Image_Encoding lossy)
1132{ 1493{
1133 return eet_data_image_write_cipher(ef, 1494 return eet_data_image_write_cipher(ef,
1134 name, 1495 name,
@@ -1151,7 +1512,7 @@ eet_data_image_read_cipher(Eet_File *ef,
1151 int *alpha, 1512 int *alpha,
1152 int *comp, 1513 int *comp,
1153 int *quality, 1514 int *quality,
1154 int *lossy) 1515 Eet_Image_Encoding *lossy)
1155{ 1516{
1156 unsigned int *d = NULL; 1517 unsigned int *d = NULL;
1157 void *data = NULL; 1518 void *data = NULL;
@@ -1185,7 +1546,7 @@ eet_data_image_read(Eet_File *ef,
1185 int *alpha, 1546 int *alpha,
1186 int *comp, 1547 int *comp,
1187 int *quality, 1548 int *quality,
1188 int *lossy) 1549 Eet_Image_Encoding *lossy)
1189{ 1550{
1190 return eet_data_image_read_cipher(ef, name, NULL, w, h, alpha, 1551 return eet_data_image_read_cipher(ef, name, NULL, w, h, alpha,
1191 comp, quality, lossy); 1552 comp, quality, lossy);
@@ -1204,7 +1565,7 @@ eet_data_image_read_to_surface_cipher(Eet_File *ef,
1204 int *alpha, 1565 int *alpha,
1205 int *comp, 1566 int *comp,
1206 int *quality, 1567 int *quality,
1207 int *lossy) 1568 Eet_Image_Encoding *lossy)
1208{ 1569{
1209 void *data = NULL; 1570 void *data = NULL;
1210 int free_data = 0; 1571 int free_data = 0;
@@ -1244,7 +1605,7 @@ eet_data_image_read_to_surface(Eet_File *ef,
1244 int *alpha, 1605 int *alpha,
1245 int *comp, 1606 int *comp,
1246 int *quality, 1607 int *quality,
1247 int *lossy) 1608 Eet_Image_Encoding *lossy)
1248{ 1609{
1249 return eet_data_image_read_to_surface_cipher(ef, name, NULL, 1610 return eet_data_image_read_to_surface_cipher(ef, name, NULL,
1250 src_x, src_y, d, 1611 src_x, src_y, d,
@@ -1262,7 +1623,7 @@ eet_data_image_header_read_cipher(Eet_File *ef,
1262 int *alpha, 1623 int *alpha,
1263 int *comp, 1624 int *comp,
1264 int *quality, 1625 int *quality,
1265 int *lossy) 1626 Eet_Image_Encoding *lossy)
1266{ 1627{
1267 void *data = NULL; 1628 void *data = NULL;
1268 int size = 0; 1629 int size = 0;
@@ -1296,7 +1657,7 @@ eet_data_image_header_read(Eet_File *ef,
1296 int *alpha, 1657 int *alpha,
1297 int *comp, 1658 int *comp,
1298 int *quality, 1659 int *quality,
1299 int *lossy) 1660 Eet_Image_Encoding *lossy)
1300{ 1661{
1301 return eet_data_image_header_read_cipher(ef, name, NULL, 1662 return eet_data_image_header_read_cipher(ef, name, NULL,
1302 w, h, alpha, 1663 w, h, alpha,
@@ -1311,7 +1672,7 @@ eet_data_image_encode_cipher(const void *data,
1311 int alpha, 1672 int alpha,
1312 int comp, 1673 int comp,
1313 int quality, 1674 int quality,
1314 int lossy, 1675 Eet_Image_Encoding lossy,
1315 int *size_ret) 1676 int *size_ret)
1316{ 1677{
1317 void *d = NULL; 1678 void *d = NULL;
@@ -1319,24 +1680,32 @@ eet_data_image_encode_cipher(const void *data,
1319 unsigned int ciphered_sz = 0; 1680 unsigned int ciphered_sz = 0;
1320 int size = 0; 1681 int size = 0;
1321 1682
1322 if (lossy == 0) 1683 switch (lossy)
1323 { 1684 {
1324 if (comp > 0) 1685 case EET_IMAGE_LOSSLESS:
1325 d = eet_data_image_lossless_compressed_convert(&size, data, 1686 if (comp > 0)
1326 w, h, alpha, comp); 1687 d = eet_data_image_lossless_compressed_convert(&size, data,
1327 1688 w, h, alpha, comp);
1328 /* eet_data_image_lossless_compressed_convert will refuse to compress something 1689
1329 if the result is bigger than the entry. */ 1690 /* eet_data_image_lossless_compressed_convert will refuse to compress something
1330 if (comp <= 0 || !d) 1691 if the result is bigger than the entry. */
1331 d = eet_data_image_lossless_convert(&size, data, w, h, alpha); 1692 if (comp <= 0 || !d)
1332 } 1693 d = eet_data_image_lossless_convert(&size, data, w, h, alpha);
1333 else 1694 break;
1334 { 1695 case EET_IMAGE_JPEG:
1335 if (!alpha) 1696 if (!alpha)
1336 d = eet_data_image_jpeg_convert(&size, data, w, h, alpha, quality); 1697 d = eet_data_image_jpeg_convert(&size, data, w, h, alpha, quality);
1337 else 1698 else
1338 d = eet_data_image_jpeg_alpha_convert(&size, data, 1699 d = eet_data_image_jpeg_alpha_convert(&size, data,
1339 w, h, alpha, quality); 1700 w, h, alpha, quality);
1701 break;
1702 case EET_IMAGE_ETC1:
1703 if (alpha) abort();
1704 d = eet_data_image_etc1_compressed_convert(&size, data, w, h,
1705 quality, comp);
1706 break;
1707 default:
1708 abort();
1340 } 1709 }
1341 1710
1342 if (cipher_key) 1711 if (cipher_key)
@@ -1369,7 +1738,7 @@ eet_data_image_encode(const void *data,
1369 int alpha, 1738 int alpha,
1370 int comp, 1739 int comp,
1371 int quality, 1740 int quality,
1372 int lossy) 1741 Eet_Image_Encoding lossy)
1373{ 1742{
1374 return eet_data_image_encode_cipher(data, NULL, w, h, alpha, 1743 return eet_data_image_encode_cipher(data, NULL, w, h, alpha,
1375 comp, quality, lossy, size_ret); 1744 comp, quality, lossy, size_ret);
@@ -1384,7 +1753,7 @@ eet_data_image_header_decode_cipher(const void *data,
1384 int *alpha, 1753 int *alpha,
1385 int *comp, 1754 int *comp,
1386 int *quality, 1755 int *quality,
1387 int *lossy) 1756 Eet_Image_Encoding *lossy)
1388{ 1757{
1389 int header[8]; 1758 int header[8];
1390 void *deciphered_d = NULL; 1759 void *deciphered_d = NULL;
@@ -1463,7 +1832,7 @@ eet_data_image_header_decode_cipher(const void *data,
1463 *comp = cp; 1832 *comp = cp;
1464 1833
1465 if (lossy) 1834 if (lossy)
1466 *lossy = 0; 1835 *lossy = EET_IMAGE_LOSSLESS;
1467 1836
1468 if (quality) 1837 if (quality)
1469 *quality = 100; 1838 *quality = 100;
@@ -1497,7 +1866,7 @@ eet_data_image_header_decode_cipher(const void *data,
1497 *comp = 0; 1866 *comp = 0;
1498 1867
1499 if (lossy) 1868 if (lossy)
1500 *lossy = 1; 1869 *lossy = EET_IMAGE_JPEG;
1501 1870
1502 if (quality) 1871 if (quality)
1503 *quality = 75; 1872 *quality = 75;
@@ -1505,6 +1874,19 @@ eet_data_image_header_decode_cipher(const void *data,
1505 return 1; 1874 return 1;
1506 } 1875 }
1507 } 1876 }
1877 else if (!strncmp(data, "TGV1", 4))
1878 {
1879 const char *m = data;
1880
1881 if (w) *w = ntohl(*((unsigned int*) &(m[OFFSET_WIDTH])));
1882 if (h) *h = ntohl(*((unsigned int*) &(m[OFFSET_HEIGHT])));
1883 if (alpha) *alpha = 0; // ETC1 only for now
1884 if (comp) *comp = m[OFFSET_OPTIONS] & 0x1;
1885 if (lossy) *lossy = EET_IMAGE_ETC1;
1886 if (quality) *quality = 50;
1887
1888 return 1;
1889 }
1508 else 1890 else
1509 { 1891 {
1510 unsigned int iw = 0, ih = 0; 1892 unsigned int iw = 0, ih = 0;
@@ -1526,7 +1908,7 @@ eet_data_image_header_decode_cipher(const void *data,
1526 *comp = 0; 1908 *comp = 0;
1527 1909
1528 if (lossy) 1910 if (lossy)
1529 *lossy = 1; 1911 *lossy = EET_IMAGE_JPEG;
1530 1912
1531 if (quality) 1913 if (quality)
1532 *quality = 75; 1914 *quality = 75;
@@ -1547,7 +1929,7 @@ eet_data_image_header_decode(const void *data,
1547 int *alpha, 1929 int *alpha,
1548 int *comp, 1930 int *comp,
1549 int *quality, 1931 int *quality,
1550 int *lossy) 1932 Eet_Image_Encoding *lossy)
1551{ 1933{
1552 return eet_data_image_header_decode_cipher(data, 1934 return eet_data_image_header_decode_cipher(data,
1553 NULL, 1935 NULL,
@@ -1598,9 +1980,9 @@ _eet_data_image_decode_inside(const void *data,
1598 int alpha, 1980 int alpha,
1599 int comp, 1981 int comp,
1600 int quality, 1982 int quality,
1601 int lossy) 1983 Eet_Image_Encoding lossy)
1602{ 1984{
1603 if (lossy == 0 && quality == 100) 1985 if (lossy == EET_IMAGE_LOSSLESS && quality == 100)
1604 { 1986 {
1605 unsigned int *body; 1987 unsigned int *body;
1606 1988
@@ -1687,7 +2069,7 @@ _eet_data_image_decode_inside(const void *data,
1687 for (x = 0; x < (w * h); x++) SWAP32(d[x]); 2069 for (x = 0; x < (w * h); x++) SWAP32(d[x]);
1688 } 2070 }
1689 } 2071 }
1690 else if (comp == 0 && lossy == 1) 2072 else if (comp == 0 && lossy == EET_IMAGE_JPEG)
1691 { 2073 {
1692 if (alpha) 2074 if (alpha)
1693 { 2075 {
@@ -1721,6 +2103,12 @@ _eet_data_image_decode_inside(const void *data,
1721 h, row_stride)) 2103 h, row_stride))
1722 return 0; 2104 return 0;
1723 } 2105 }
2106 else if (lossy == EET_IMAGE_ETC1)
2107 {
2108 return eet_data_image_etc1_decode(data, size, d,
2109 src_x, src_y, src_w, src_h,
2110 EET_COLORSPACE_ARGB8888);
2111 }
1724 else 2112 else
1725 abort(); 2113 abort();
1726 2114
@@ -1736,11 +2124,12 @@ eet_data_image_decode_cipher(const void *data,
1736 int *alpha, 2124 int *alpha,
1737 int *comp, 2125 int *comp,
1738 int *quality, 2126 int *quality,
1739 int *lossy) 2127 Eet_Image_Encoding *lossy)
1740{ 2128{
1741 unsigned int *d = NULL; 2129 unsigned int *d = NULL;
1742 unsigned int iw, ih; 2130 unsigned int iw, ih;
1743 int ialpha, icompress, iquality, ilossy; 2131 int ialpha, icompress, iquality;
2132 Eet_Image_Encoding ilossy;
1744 void *deciphered_d = NULL; 2133 void *deciphered_d = NULL;
1745 unsigned int deciphered_sz = 0; 2134 unsigned int deciphered_sz = 0;
1746 2135
@@ -1802,7 +2191,7 @@ eet_data_image_decode(const void *data,
1802 int *alpha, 2191 int *alpha,
1803 int *comp, 2192 int *comp,
1804 int *quality, 2193 int *quality,
1805 int *lossy) 2194 Eet_Image_Encoding *lossy)
1806{ 2195{
1807 return eet_data_image_decode_cipher(data, NULL, size, w, h, 2196 return eet_data_image_decode_cipher(data, NULL, size, w, h,
1808 alpha, comp, quality, lossy); 2197 alpha, comp, quality, lossy);
@@ -1821,10 +2210,11 @@ eet_data_image_decode_to_surface_cipher(const void *data,
1821 int *alpha, 2210 int *alpha,
1822 int *comp, 2211 int *comp,
1823 int *quality, 2212 int *quality,
1824 int *lossy) 2213 Eet_Image_Encoding *lossy)
1825{ 2214{
1826 unsigned int iw, ih; 2215 unsigned int iw, ih;
1827 int ialpha, icompress, iquality, ilossy; 2216 int ialpha, icompress, iquality;
2217 Eet_Image_Encoding ilossy;
1828 void *deciphered_d = NULL; 2218 void *deciphered_d = NULL;
1829 unsigned int deciphered_sz = 0; 2219 unsigned int deciphered_sz = 0;
1830 2220
@@ -1887,7 +2277,7 @@ eet_data_image_decode_to_surface(const void *data,
1887 int *alpha, 2277 int *alpha,
1888 int *comp, 2278 int *comp,
1889 int *quality, 2279 int *quality,
1890 int *lossy) 2280 Eet_Image_Encoding *lossy)
1891{ 2281{
1892 return eet_data_image_decode_to_surface_cipher(data, NULL, size, 2282 return eet_data_image_decode_to_surface_cipher(data, NULL, size,
1893 src_x, src_y, d, 2283 src_x, src_y, d,
diff --git a/src/modules/evas/loaders/eet/evas_image_load_eet.c b/src/modules/evas/loaders/eet/evas_image_load_eet.c
index 3df93249a7..83d5c4106b 100644
--- a/src/modules/evas/loaders/eet/evas_image_load_eet.c
+++ b/src/modules/evas/loaders/eet/evas_image_load_eet.c
@@ -70,11 +70,12 @@ evas_image_load_file_head_eet(void *loader_data,
70 int *error) 70 int *error)
71{ 71{
72 Evas_Loader_Internal *loader = loader_data; 72 Evas_Loader_Internal *loader = loader_data;
73 int a, compression, quality, lossy; 73 int a, compression, quality;
74 Eet_Image_Encoding lossy;
74 int ok; 75 int ok;
75 76
76 ok = eet_data_image_header_read(loader->ef, loader->key, 77 ok = eet_data_image_header_read(loader->ef, loader->key,
77 &prop->w, &prop->h, &a, &compression, &quality, &lossy); 78 &prop->w, &prop->h, &a, &compression, &quality, &lossy);
78 if (!ok) 79 if (!ok)
79 return _evas_image_load_return_error(EVAS_LOAD_ERROR_DOES_NOT_EXIST, error); 80 return _evas_image_load_return_error(EVAS_LOAD_ERROR_DOES_NOT_EXIST, error);
80 if (IMG_TOO_BIG(prop->w, prop->h)) 81 if (IMG_TOO_BIG(prop->w, prop->h))
@@ -93,13 +94,14 @@ evas_image_load_file_data_eet(void *loader_data,
93 int *error) 94 int *error)
94{ 95{
95 Evas_Loader_Internal *loader = loader_data; 96 Evas_Loader_Internal *loader = loader_data;
96 int alpha, compression, quality, lossy, ok; 97 int alpha, compression, quality, ok;
98 Eet_Image_Encoding lossy;
97 DATA32 *body, *p, *end; 99 DATA32 *body, *p, *end;
98 DATA32 nas = 0; 100 DATA32 nas = 0;
99 101
100 ok = eet_data_image_read_to_surface(loader->ef, loader->key, 0, 0, 102 ok = eet_data_image_read_to_surface(loader->ef, loader->key, 0, 0,
101 pixels, prop->w, prop->h, prop->w * 4, 103 pixels, prop->w, prop->h, prop->w * 4,
102 &alpha, &compression, &quality, &lossy); 104 &alpha, &compression, &quality, &lossy);
103 if (!ok) 105 if (!ok)
104 return _evas_image_load_return_error(EVAS_LOAD_ERROR_GENERIC, error); 106 return _evas_image_load_return_error(EVAS_LOAD_ERROR_GENERIC, error);
105 107
diff --git a/src/tests/eet/eet_suite.c b/src/tests/eet/eet_suite.c
index 5b56cf95fd..43b9fdec7f 100644
--- a/src/tests/eet/eet_suite.c
+++ b/src/tests/eet/eet_suite.c
@@ -1290,7 +1290,7 @@ START_TEST(eet_image)
1290 int compress; 1290 int compress;
1291 int quality; 1291 int quality;
1292 int result; 1292 int result;
1293 int lossy; 1293 Eet_Image_Encoding lossy;
1294 int alpha; 1294 int alpha;
1295 unsigned int w; 1295 unsigned int w;
1296 unsigned int h; 1296 unsigned int h;
@@ -1658,7 +1658,7 @@ START_TEST(eet_small_image)
1658 int alpha; 1658 int alpha;
1659 int compression; 1659 int compression;
1660 int quality; 1660 int quality;
1661 int lossy; 1661 Eet_Image_Encoding lossy;
1662 int result; 1662 int result;
1663 1663
1664 image[0] = IM0; 1664 image[0] = IM0;