diff --git a/legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c b/legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c index f8744374b7..e944395674 100644 --- a/legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c +++ b/legacy/evas/src/modules/loaders/tiff/evas_image_load_tiff.c @@ -97,11 +97,11 @@ raster(TIFFRGBAImage_Extra * img, uint32 * rast, r = TIFFGetR(pixel_value); g = TIFFGetG(pixel_value); b = TIFFGetB(pixel_value); - if ((a > 0) && (a < 255) && (alpha_premult)) + if (!alpha_premult && (a < 255)) { - r = (r * 255) / a; - g = (g * 255) / a; - b = (b * 255) / a; + r = (r * (a + 1)) >> 8; + g = (g * (a + 1)) >> 8; + b = (b * (a + 1)) >> 8; } (*(buffer_pixel++)) = (a << 24) | (r << 16) | (g << 8) | b; } @@ -313,6 +313,7 @@ evas_image_load_file_data_tiff(RGBA_Image *im, const char *file, const char *key TIFFClose(tif); + evas_common_image_set_alpha_sparse(im); return 1; } diff --git a/legacy/evas/src/modules/savers/eet/evas_image_save_eet.c b/legacy/evas/src/modules/savers/eet/evas_image_save_eet.c index 8f2166025a..2f5130dec1 100644 --- a/legacy/evas/src/modules/savers/eet/evas_image_save_eet.c +++ b/legacy/evas/src/modules/savers/eet/evas_image_save_eet.c @@ -16,6 +16,7 @@ evas_image_save_file_eet(RGBA_Image *im, const char *file, const char *key, int { Eet_File *ef; int alpha = 0, lossy = 0, ok = 0; + DATA32 *data; if (!im || !im->image || !im->image->data || !file) return 0; @@ -25,9 +26,24 @@ evas_image_save_file_eet(RGBA_Image *im, const char *file, const char *key, int if (!ef) return 0; if ((quality <= 100) || (compress < 0)) lossy = 1; if (im->flags & RGBA_IMAGE_HAS_ALPHA) alpha = 1; - ok = eet_data_image_write(ef, (char *)key, im->image->data, + if (alpha) + { + data = malloc(im->image->w * im->image->h * sizeof(DATA32)); + if (!data) + { + eet_close(ef); + return 0; + } + memcpy(data, im->image->data, im->image->w * im->image->h * sizeof(DATA32)); + evas_common_convert_argb_unpremul(data, im->image->w * im->image->h); + } + else + data = im->image->data; + ok = eet_data_image_write(ef, (char *)key, data, im->image->w, im->image->h, alpha, compress, quality, lossy); + if (alpha) + free(data); eet_close(ef); return ok; } diff --git a/legacy/evas/src/modules/savers/png/evas_image_save_png.c b/legacy/evas/src/modules/savers/png/evas_image_save_png.c index c5fb2dbc5a..6c5ad5795e 100644 --- a/legacy/evas/src/modules/savers/png/evas_image_save_png.c +++ b/legacy/evas/src/modules/savers/png/evas_image_save_png.c @@ -18,9 +18,9 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace) FILE *f; png_structp png_ptr; png_infop info_ptr; - DATA32 *ptr; + DATA32 *ptr, *data; int x, y, j; - png_bytep row_ptr, data = NULL; + png_bytep row_ptr, png_data = NULL; png_color_8 sig_bit; int num_passes = 1, pass; @@ -59,10 +59,19 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace) #endif } - png_init_io(png_ptr, f); - if (im->flags & RGBA_IMAGE_HAS_ALPHA) { + data = malloc(im->image->w * im->image->h * sizeof(DATA32)); + if (!data) + { + fclose(f); + png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr); + png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr); + return 0; + } + memcpy(data, im->image->data, im->image->w * im->image->h * sizeof(DATA32)); + evas_common_convert_argb_unpremul(data, im->image->w * im->image->h); + png_init_io(png_ptr, f); png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8, PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); @@ -74,10 +83,12 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace) } else { + data = im->image->data; + png_init_io(png_ptr, f); png_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8, PNG_COLOR_TYPE_RGB, png_ptr->interlaced, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - data = alloca(im->image->w * 3 * sizeof(char)); + png_data = alloca(im->image->w * 3 * sizeof(char)); } sig_bit.red = 8; sig_bit.green = 8; @@ -92,7 +103,7 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace) for (pass = 0; pass < num_passes; pass++) { - ptr = im->image->data; + ptr = data; for (y = 0; y < im->image->h; y++) { @@ -102,11 +113,11 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace) { for (j = 0, x = 0; x < im->image->w; x++) { - data[j++] = (ptr[x] >> 16) & 0xff; - data[j++] = (ptr[x] >> 8) & 0xff; - data[j++] = (ptr[x]) & 0xff; + png_data[j++] = (ptr[x] >> 16) & 0xff; + png_data[j++] = (ptr[x] >> 8) & 0xff; + png_data[j++] = (ptr[x]) & 0xff; } - row_ptr = (png_bytep) data; + row_ptr = (png_bytep) png_data; } png_write_rows(png_ptr, &row_ptr, 1); ptr += im->image->w; @@ -116,6 +127,8 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace) png_destroy_write_struct(&png_ptr, (png_infopp) & info_ptr); png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr); + if (im->flags & RGBA_IMAGE_HAS_ALPHA) + free(data); fclose(f); return 1; } diff --git a/legacy/evas/src/modules/savers/tiff/evas_image_save_tiff.c b/legacy/evas/src/modules/savers/tiff/evas_image_save_tiff.c index 9af8ee2f31..dd05091220 100644 --- a/legacy/evas/src/modules/savers/tiff/evas_image_save_tiff.c +++ b/legacy/evas/src/modules/savers/tiff/evas_image_save_tiff.c @@ -79,14 +79,7 @@ save_image_tiff(RGBA_Image *im, const char *file, int compress, int interlace) g = (pixel >> 8) & 0xff; b = pixel & 0xff; if (has_alpha) - { - /* TIFF makes you pre-mutiply the rgb components by alpha */ - a = (pixel >> 24) & 0xff; - alpha_factor = ((double)a / 255.0); - r *= alpha_factor; - g *= alpha_factor; - b *= alpha_factor; - } + a = (pixel >> 24) & 0xff; /* This might be endian dependent */ buf[i++] = r;