more commit....

SVN revision: 26237
This commit is contained in:
Carsten Haitzler 2006-09-30 10:21:23 +00:00
parent 8c93e825a8
commit 2190ed562a
4 changed files with 46 additions and 23 deletions

View File

@ -97,11 +97,11 @@ raster(TIFFRGBAImage_Extra * img, uint32 * rast,
r = TIFFGetR(pixel_value); r = TIFFGetR(pixel_value);
g = TIFFGetG(pixel_value); g = TIFFGetG(pixel_value);
b = TIFFGetB(pixel_value); b = TIFFGetB(pixel_value);
if ((a > 0) && (a < 255) && (alpha_premult)) if (!alpha_premult && (a < 255))
{ {
r = (r * 255) / a; r = (r * (a + 1)) >> 8;
g = (g * 255) / a; g = (g * (a + 1)) >> 8;
b = (b * 255) / a; b = (b * (a + 1)) >> 8;
} }
(*(buffer_pixel++)) = (a << 24) | (r << 16) | (g << 8) | b; (*(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); TIFFClose(tif);
evas_common_image_set_alpha_sparse(im);
return 1; return 1;
} }

View File

@ -16,6 +16,7 @@ evas_image_save_file_eet(RGBA_Image *im, const char *file, const char *key, int
{ {
Eet_File *ef; Eet_File *ef;
int alpha = 0, lossy = 0, ok = 0; int alpha = 0, lossy = 0, ok = 0;
DATA32 *data;
if (!im || !im->image || !im->image->data || !file) if (!im || !im->image || !im->image->data || !file)
return 0; 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 (!ef) return 0;
if ((quality <= 100) || (compress < 0)) lossy = 1; if ((quality <= 100) || (compress < 0)) lossy = 1;
if (im->flags & RGBA_IMAGE_HAS_ALPHA) alpha = 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, im->image->w, im->image->h, alpha, compress,
quality, lossy); quality, lossy);
if (alpha)
free(data);
eet_close(ef); eet_close(ef);
return ok; return ok;
} }

View File

@ -18,9 +18,9 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace)
FILE *f; FILE *f;
png_structp png_ptr; png_structp png_ptr;
png_infop info_ptr; png_infop info_ptr;
DATA32 *ptr; DATA32 *ptr, *data;
int x, y, j; int x, y, j;
png_bytep row_ptr, data = NULL; png_bytep row_ptr, png_data = NULL;
png_color_8 sig_bit; png_color_8 sig_bit;
int num_passes = 1, pass; int num_passes = 1, pass;
@ -59,10 +59,19 @@ save_image_png(RGBA_Image *im, const char *file, int compress, int interlace)
#endif #endif
} }
png_init_io(png_ptr, f);
if (im->flags & RGBA_IMAGE_HAS_ALPHA) 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_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced, PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); 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 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_set_IHDR(png_ptr, info_ptr, im->image->w, im->image->h, 8,
PNG_COLOR_TYPE_RGB, png_ptr->interlaced, PNG_COLOR_TYPE_RGB, png_ptr->interlaced,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); 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.red = 8;
sig_bit.green = 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++) for (pass = 0; pass < num_passes; pass++)
{ {
ptr = im->image->data; ptr = data;
for (y = 0; y < im->image->h; y++) 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++) for (j = 0, x = 0; x < im->image->w; x++)
{ {
data[j++] = (ptr[x] >> 16) & 0xff; png_data[j++] = (ptr[x] >> 16) & 0xff;
data[j++] = (ptr[x] >> 8) & 0xff; png_data[j++] = (ptr[x] >> 8) & 0xff;
data[j++] = (ptr[x]) & 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); png_write_rows(png_ptr, &row_ptr, 1);
ptr += im->image->w; 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_write_struct(&png_ptr, (png_infopp) & info_ptr);
png_destroy_info_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); fclose(f);
return 1; return 1;
} }

View File

@ -79,14 +79,7 @@ save_image_tiff(RGBA_Image *im, const char *file, int compress, int interlace)
g = (pixel >> 8) & 0xff; g = (pixel >> 8) & 0xff;
b = pixel & 0xff; b = pixel & 0xff;
if (has_alpha) if (has_alpha)
{ a = (pixel >> 24) & 0xff;
/* 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;
}
/* This might be endian dependent */ /* This might be endian dependent */
buf[i++] = r; buf[i++] = r;