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.
This commit is contained in:
Jean-Philippe Andre 2016-12-22 19:00:41 +09:00
parent 3be0e7b63b
commit 2f1d666a06
3 changed files with 39 additions and 1 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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,