Fix background.index PNG bug.
diff --git a/coders/png.c b/coders/png.c
index 87836e9..737d78f 100644
--- a/coders/png.c
+++ b/coders/png.c
@@ -7062,12 +7062,13 @@
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 @@
}
}
- /*
- 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 @@
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);