From 17a1485544c62993fc7a94e343c87fed5f3e6407 Mon Sep 17 00:00:00 2001 From: glennrp Date: Mon, 10 May 2010 03:01:59 +0000 Subject: [PATCH] Fix background.index PNG bug. --- coders/png.c | 41 ++++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/coders/png.c b/coders/png.c index 87836e962..737d78f09 100644 --- a/coders/png.c +++ b/coders/png.c @@ -7062,12 +7062,13 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, else if (mng_info->IsPalette) { + unsigned long + number_colors; + + number_colors=image_colors; + if (image_depth <= 8) { - unsigned long - number_colors; - - number_colors=image_colors; /* Set image palette. */ @@ -7211,13 +7212,6 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, } } - /* - Identify which colormap entry is the background color. - */ - for (i=0; i < (long) MagickMax(1L*number_colors-1L,1L); i++) - if (IsPNGColorEqual(ping_background,image->colormap[i])) - break; - ping_background.index=(png_byte) i; } } else @@ -7259,6 +7253,31 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info, ping_trans_color.gray=(png_uint_16) (QuantumScale*(maxval* ping_trans_color.gray)); } + + if ((int) ping_color_type == PNG_COLOR_TYPE_PALETTE) + { + /* + Identify which colormap entry is the background color. + */ + + unsigned long + number_colors; + + number_colors=image_colors; + + for (i=0; i < (long) MagickMax(1L*number_colors-1L,1L); i++) + if (IsPNGColorEqual(ping_background,image->colormap[i])) + break; + + ping_background.index=(png_byte) i; + + if (logging) + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " Setting up bKGD chunk with index=%d",(int) i); + + png_set_bKGD(ping,ping_info,&ping_background); + } + if (logging != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(), " PNG color type: %d",ping_color_type); -- 2.40.0