From 83c2de583a59e41b57be8036d1cf7392c01d03d7 Mon Sep 17 00:00:00 2001 From: glennrp Date: Wed, 17 Nov 2010 14:40:15 +0000 Subject: [PATCH] Fixed various problems with the PNG encoder, mainly loss of transparency. --- ChangeLog | 7 +++-- coders/png.c | 84 +++++++++++++++++++++------------------------------- 2 files changed, 37 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a728e497..e88403624 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-11-17 6.6.5-9 Glenn Randers-Pehrson + * Many of the problems with the PNG encoder have been fixed (reference + http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=16487). + 2010-11-14 6.6.5-9 Cristy * The splice option no longer throws spurious "pixels are not authentic" exceptions. @@ -11,9 +15,6 @@ preservation of images which only vary horizontally (or vertically)" under no-op. New blur = 0.9812505644269356. -2010-10-29 6.6.5-9 Glenn Randers-Pehrson - * Revised PNG encoder to avoid emitting some spurious warnings. - 2010-11-08 6.6.5-8 Nicolas Robidoux * Missing logical operator in tiff.c. diff --git a/coders/png.c b/coders/png.c index 0dc80a192..c8e37e2c6 100644 --- a/coders/png.c +++ b/coders/png.c @@ -345,7 +345,6 @@ typedef struct _MngInfo need_fram, object_id, old_framing_mode, - optimize, saved_bkgd_index; int @@ -7054,6 +7053,39 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, if (image->colorspace != RGBColorspace) (void) TransformImageColorspace(image,RGBColorspace); + /* + Sometimes we get PseudoClass images whose RGB values don't match + the colors in the colormap. This code syncs the RGB values. + */ + if (image->taint && image->storage_class == PseudoClass) + (void) SyncImage(image); + +#ifdef PNG_BUILD_PALETTE + + if (((mng_info->write_png_colortype-1) == PNG_COLOR_TYPE_PALETTE) || + (mng_info->write_png_colortype == 0 && image->depth <= 8)) + { + /* + Sometimes we get DirectClass images that have 256 colors or fewer. + This code will convert them to PseudoClass and build a colormap. + */ + if (image->storage_class != PseudoClass) + { + image->colors=GetNumberColors(image,(FILE *) NULL,&image->exception); + if (image->colors <= 256) + { + image->colors=0; + + if (image->matte != MagickFalse) + (void) SetImageType(image,PaletteMatteType); + + else + (void) SetImageType(image,PaletteType); + } + } + } +#endif + mng_info->IsPalette=image->storage_class == PseudoClass && image_colors <= 256 && !IsOpaqueImage(image,&image->exception); @@ -9925,56 +9957,6 @@ static MagickBooleanType WriteMNGImage(const ImageInfo *image_info,Image *image) } } - /* - Sometimes we get PseudoClass images whose RGB values don't match - the colors in the colormap. This code syncs the RGB values. - */ - { - Image - *p; - - for (p=image; p != (Image *) NULL; p=GetNextImageInList(p)) - { - if (p->taint && p->storage_class == PseudoClass) - (void) SyncImage(p); - - if (mng_info->adjoin == MagickFalse) - break; - } - } - -#ifdef PNG_BUILD_PALETTE - if (!(mng_info->write_png24 || mng_info->write_png32)) - { - /* - Sometimes we get DirectClass images that have 256 colors or fewer. - This code will convert them to PseudoClass and build a colormap. - */ - Image - *p; - - for (p=image; p != (Image *) NULL; p=GetNextImageInList(p)) - { - if (p->storage_class != PseudoClass) - { - p->colors=GetNumberColors(p,(FILE *) NULL,&p->exception); - if (p->colors <= 256) - { - p->colors=0; - - if (p->matte != MagickFalse) - (void) SetImageType(p,PaletteMatteType); - - else - (void) SetImageType(p,PaletteType); - } - } - if (mng_info->adjoin == MagickFalse) - break; - } - } -#endif - use_global_plte=MagickFalse; all_images_are_gray=MagickFalse; #ifdef PNG_WRITE_EMPTY_PLTE_SUPPORTED -- 2.40.0