aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/eet
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2015-03-17 08:50:28 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-17 09:58:19 +0100
commit0e7452a9e12483f29829461fd68a6f1eab6995e5 (patch)
tree5a472e29b52498fd56267f95d771a665a64a7646 /src/lib/eet
parenteet: refactoring jpeg encoding. (diff)
downloadefl-0e7452a9e12483f29829461fd68a6f1eab6995e5.tar.gz
eet: encode lossy image with AGRY88 or GRY8 whenever possible.
Diffstat (limited to 'src/lib/eet')
-rw-r--r--src/lib/eet/eet_image.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/lib/eet/eet_image.c b/src/lib/eet/eet_image.c
index 1e06cf66a4..f94bc5918c 100644
--- a/src/lib/eet/eet_image.c
+++ b/src/lib/eet/eet_image.c
@@ -1160,8 +1160,43 @@ _eet_data_image_rgb_encode(const void *data,
void *d = NULL;
size_t sz = 0;
JSAMPROW *jbuf;
+ unsigned int *grey;
unsigned char *buf;
+ /* Try to encode this buffer as GRY8 or AGRY88.
+ It is difficult to know if a different approach
+ would have payed of, but for now I do walk and
+ copy the pixels as long as they are grey. If I
+ manage to copy them up to the end, I will be
+ able to encode them as a GRY8 texture.
+ */
+ grey = malloc(sizeof (int) * w * h);
+ if (grey)
+ {
+ const unsigned int *pixels = data;
+ unsigned int i;
+
+ for (i = 0; i < w * h; i++)
+ {
+ uint8_t r, g, b;
+
+ r = R_VAL(&pixels[i]);
+ g = G_VAL(&pixels[i]);
+ b = B_VAL(&pixels[i]);
+ if (!(r == g && g == b))
+ break ;
+ grey[i] = r << 24;
+ }
+
+ if (i == w * h)
+ {
+ d = _eet_data_image_grey_encode(grey, w, h, quality, size);
+ free(grey);
+ return d;
+ }
+ free(grey);
+ }
+
buf = alloca(3 * w);
memset(&cinfo, 0, sizeof (struct jpeg_compress_struct));