From 2cbb4489df0a2a31907769956f217d4b9d982bd0 Mon Sep 17 00:00:00 2001 From: glennrp Date: Wed, 2 Jun 2010 04:37:24 +0000 Subject: [PATCH] Correct the bKGD chunk reading (scaling was incorrect) --- ChangeLog | 17 ++++++++++------- coders/png.c | 41 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 628440aa1..6a423c003 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,15 +1,18 @@ +2010-06-01 6.6.2-2 Glenn Randers-Pehrson + * Properly scale color components of the PNG bKGD chunk. + * Prevent MNG divide by zero in calculation of frame_timeout. Set + both frame_delay and frame_timeout to infinite when ticks_per_second + is zero, as required by the MNG spec. + 2010-05-31 6.6.2-2 Cristy * Add x:silent option to prevent beeps when reading the X image format. * Recognize TTF for GetMagicInfo(). * Ensure the +set option deletes the image artifact. - * Prevent MNG divide by zero in calculation of frame_timeout. Set - both frame_delay and frame_timeout to infinite when ticks_per_second - is zero, as required by the MNG spec. -2010-05-28 6.6.2.1 Glenn Randers-Pehrson +2010-05-28 6.6.2-1 Glenn Randers-Pehrson * Prevent coders/png.c from attempting to write an empty tRNS chunk. -2010-05-25 6.6.2.1 Anthony Thyssen +2010-05-25 6.6.2-1 Anthony Thyssen * Finish for Square Array Rotates (off center origin rotate) * Added HitAndMiss kernel Ridges2 to find 2 pixel thick ridges * Added FreiChen:0,{angle} FreiChen:{angle} and FreiChen:-1 variations @@ -26,7 +29,7 @@ * Prevent MNG divide by zero in calculation of frame_delay (reference http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=16320). -2010-05-23 6.6.2.0 Anthony Thyssen +2010-05-23 6.6.2-0 Anthony Thyssen * Third Re-write of MorphologyApply() to better handle compound methods. * Implemented -set option:morphology:compose for merging results of multiple kernels. "None" means re-iterate results with next kernel. @@ -40,7 +43,7 @@ * ExpandKernelInfo() (rotation expand) now groks symmetrical kernels. So the above will only produce a list of 2 kernels, not 4 kernels -2010-05-18 6.6.2.0 Anthony Thyssen +2010-05-18 6.6.2-0 Anthony Thyssen * Separation of internal function MorphologyAppy() from MorphologyImageChannel() to calls to convolve without user settings. * Rewrite of MorphologyApply() to output better 'verbose' messages diff --git a/coders/png.c b/coders/png.c index a7bd06dbb..613fc8269 100644 --- a/coders/png.c +++ b/coders/png.c @@ -2132,20 +2132,57 @@ static Image *ReadOnePNGImage(MngInfo *mng_info, if (logging != MagickFalse) (void) LogMagickEvent(CoderEvent,GetMagickModule(), " Reading PNG bKGD chunk."); - if (ping_bit_depth <= MAGICKCORE_QUANTUM_DEPTH) + if (ping_bit_depth == MAGICKCORE_QUANTUM_DEPTH) { image->background_color.red=ping_background->red; image->background_color.green=ping_background->green; image->background_color.blue=ping_background->blue; } - else + else /* Scale background components to 16-bit */ { + unsigned int + bkgd_scale; + + if (logging != MagickFalse) + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " raw ping_background=(%d,%d,%d).",ping_background->red, + ping_background->green,ping_background->blue); + + bkgd_scale = 1; + if (ping_bit_depth == 1) + bkgd_scale = 255; + else if (ping_bit_depth == 2) + bkgd_scale = 85; + else if (ping_bit_depth == 4) + bkgd_scale = 17; + if (ping_bit_depth <= 8) + bkgd_scale *= 257; + + ping_background->red *= bkgd_scale; + ping_background->green *= bkgd_scale; + ping_background->blue *= bkgd_scale; + + if (logging != MagickFalse) + { + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " bkgd_scale=%d.",bkgd_scale); + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " ping_background=(%d,%d,%d).",ping_background->red, + ping_background->green,ping_background->blue); + } + image->background_color.red= ScaleShortToQuantum(ping_background->red); image->background_color.green= ScaleShortToQuantum(ping_background->green); image->background_color.blue= ScaleShortToQuantum(ping_background->blue); + + if (logging != MagickFalse) + (void) LogMagickEvent(CoderEvent,GetMagickModule(), + " image->background_color=(%d,%d,%d).", + image->background_color.red, + image->background_color.green,image->background_color.blue); } } #endif -- 2.50.1