summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2016-12-22 19:00:41 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2016-12-22 19:23:01 +0900
commit2f1d666a06d374d1930cf69cf72f21c9700caf46 (patch)
tree523b35cf7e0b2b2569b7b885cfeb52f51c56b7c7
parent3be0e7b63b7f9df2241e854eabd8ef924978783a (diff)
downloadefl-2f1d666a06d374d1930cf69cf72f21c9700caf46.tar.gz
evas: PNG save of ARGY88 needs unpremul
PNG saves unpremultiplied values, so we need to do that for the newly supported ARGY88 colorspace as well. Fixes the previous commit.
-rw-r--r--src/lib/evas/common/evas_convert_color.c28
-rw-r--r--src/lib/evas/common/evas_convert_color.h1
-rw-r--r--src/modules/evas/image_savers/png/evas_image_save_png.c11
3 files changed, 39 insertions, 1 deletions
diff --git a/src/lib/evas/common/evas_convert_color.c b/src/lib/evas/common/evas_convert_color.c
index 421f425221..3558b341e0 100644
--- a/src/lib/evas/common/evas_convert_color.c
+++ b/src/lib/evas/common/evas_convert_color.c
@@ -26,6 +26,34 @@ evas_common_convert_ag_premul(DATA16 *data, unsigned int len)
return nas;
}
+EAPI void
+evas_common_convert_ag_unpremul(DATA16 *data, unsigned int len)
+{
+ DATA16 *de = data + len;
+ DATA16 p_val = 0x0000, p_res = 0x0000;
+
+ while (data < de)
+ {
+ if (p_val == *data) *data = p_res;
+ else
+ {
+ DATA16 a = (*data >> 8);
+
+ p_val = *data;
+ if ((a > 0) && (a < 255))
+ {
+ *data = ((a << 8) | (((*data & 0xff) * 0xff) / a));
+ }
+ else if (a == 0)
+ {
+ *data = 0x0000;
+ }
+ p_res = *data;
+ }
+ data++;
+ }
+}
+
EAPI DATA32
evas_common_convert_argb_premul(DATA32 *data, unsigned int len)
{
diff --git a/src/lib/evas/common/evas_convert_color.h b/src/lib/evas/common/evas_convert_color.h
index c3c07a3ca9..54bd59e138 100644
--- a/src/lib/evas/common/evas_convert_color.h
+++ b/src/lib/evas/common/evas_convert_color.h
@@ -3,6 +3,7 @@
EAPI DATA32 evas_common_convert_ag_premul (DATA16 *data, unsigned int len);
+EAPI void evas_common_convert_ag_unpremul (DATA16 *data, unsigned int len);
EAPI DATA32 evas_common_convert_argb_premul (DATA32 *src, unsigned int len);
EAPI void evas_common_convert_argb_unpremul (DATA32 *src, unsigned int len);
EAPI void evas_common_convert_color_argb_premul (int a, int *r, int *g, int *b);
diff --git a/src/modules/evas/image_savers/png/evas_image_save_png.c b/src/modules/evas/image_savers/png/evas_image_save_png.c
index 6eef2fe221..eca98f8ab7 100644
--- a/src/modules/evas/image_savers/png/evas_image_save_png.c
+++ b/src/modules/evas/image_savers/png/evas_image_save_png.c
@@ -88,7 +88,16 @@ save_image_png(RGBA_Image *im, const char *file, int do_compress, int interlace)
{
agry88 = EINA_TRUE;
pixel_size = 2;
- data = im->image.data8;
+ data = malloc(im->cache_entry.w * im->cache_entry.h * pixel_size);
+ if (!data)
+ {
+ png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr);
+ png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
+ goto close_file;
+ }
+ free_data = EINA_TRUE;
+ memcpy(data, im->image.data, im->cache_entry.w * im->cache_entry.h * pixel_size);
+ evas_common_convert_ag_unpremul((DATA16 *) data, im->cache_entry.w * im->cache_entry.h);
png_init_io(png_ptr, f);
png_set_IHDR(png_ptr, info_ptr, im->cache_entry.w, im->cache_entry.h, 8,
PNG_COLOR_TYPE_GRAY_ALPHA, interlace,