Edje: Fix ETC1 encoding with EET and Edje
authorJean-Philippe Andre <jp.andre@samsung.com>
Fri, 18 Apr 2014 04:12:03 +0000 (13:12 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Fri, 18 Apr 2014 06:43:07 +0000 (15:43 +0900)
There were a few critical issues:
- Invalid pointer arithmetics on the input data (char vs. int)
- Invalid logic in the pixel duplication code

All of these due to bad copy and paste :(

Also, use LZ4HC instead of LZ4 when compression is enabled.
ETC1 encoding is so damn slow you won't see the difference between
LZ4 and LZ4HC compression times.

src/bin/edje/edje_cc_out.c
src/lib/eet/eet_image.c

index 3302fa6..7691bab 100644 (file)
@@ -704,6 +704,7 @@ error_and_abort_image_load_error(Eet_File *ef, const char *file, int error)
          "bmp",
          "ico",
          "tga",
+         "tgv",
          NULL
        };
 
@@ -754,7 +755,7 @@ data_thread_image(void *data, Ecore_Thread *thread EINA_UNUSED)
    if ((iw->data) && (iw->w > 0) && (iw->h > 0))
      {
         Eet_Image_Encoding lossy = EET_IMAGE_LOSSLESS;
-        int mode, qual;
+        int mode, qual, comp = 0;
 
         snprintf(buf, sizeof(buf), "edje/images/%i", iw->img->id);
         qual = 80;
@@ -787,7 +788,11 @@ data_thread_image(void *data, Ecore_Thread *thread EINA_UNUSED)
              if (qual < min_quality) qual = min_quality;
              if (qual > max_quality) qual = max_quality;
              if (!allow_etc1 || (iw->alpha)) lossy = EET_IMAGE_JPEG;
-             else lossy = EET_IMAGE_ETC1;
+             else
+               {
+                  lossy = EET_IMAGE_ETC1;
+                  comp = !no_comp;
+               }
           }
         if (iw->alpha)
           {
@@ -819,7 +824,7 @@ data_thread_image(void *data, Ecore_Thread *thread EINA_UNUSED)
           bytes = eet_data_image_write(iw->ef, buf,
                                        iw->data, iw->w, iw->h,
                                        iw->alpha,
-                                       0, qual, lossy);
+                                       comp, qual, lossy);
         if (bytes <= 0)
           {
              snprintf(buf2, sizeof(buf2),
index d5bda22..58e7df5 100644 (file)
@@ -995,7 +995,7 @@ eet_data_image_lossless_compressed_convert(int         *size,
 
 static void *
 eet_data_image_etc1_compressed_convert(int         *size,
-                                       const unsigned char *data,
+                                       const unsigned char *data8,
                                        unsigned int w,
                                        unsigned int h,
                                        int          quality,
@@ -1009,6 +1009,7 @@ eet_data_image_etc1_compressed_convert(int         *size,
    unsigned int x, y;
    unsigned int compress_length;
    unsigned int real_x, real_y;
+   unsigned int *data = (unsigned int *) data8;
    char *comp;
    char *buffer;
    void *result;
@@ -1106,7 +1107,7 @@ eet_data_image_etc1_compressed_convert(int         *size,
 
                        if (lmax > 0)
                          {
-                            for (k = duplicate_h[0]; k < kmax; k++)
+                            for (k = 0; k < kmax; k++)
                               memcpy(&todo[(k + duplicate_h[0]) * 16 + duplicate_w[0] * 4],
                                      &data[(real_y + i + k) * w + real_x + j],
                                      4 * lmax);
@@ -1147,7 +1148,7 @@ eet_data_image_etc1_compressed_convert(int         *size,
 
              if (compression)
                {
-                  wlen = LZ4_compress(buffer, comp, block_count * 8);
+                  wlen = LZ4_compressHC(buffer, comp, block_count * 8);
                }
              else
                {