From cd3b0cc4d9be95dd647d6a0a272b37f1d4c1ebff Mon Sep 17 00:00:00 2001 From: John Bowler Date: Tue, 14 Jun 2011 23:01:07 -0500 Subject: [PATCH] [devel] Fixed a problem in png_do_expand_palette() exposed by optimization in 1.5.3beta06 Also removed a spurious (totally unused and confusing) member from png_info. The palette expand optimization prevented expansion to an intermediate RGBA form if tRNS was present but alpha was marked to be stripped; this exposed a check for tRNS in png_do_expand_palette() which is inconsistent with the code elsewhere in libpng. --- ANNOUNCE | 11 +++++++++-- CHANGES | 9 ++++++++- pnginfo.h | 1 - pngrtran.c | 28 ++++++++++++++-------------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index cd52e8853..66c01b47f 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.5.4beta03 - June 14, 2011 +Libpng 1.5.4beta03 - June 15, 2011 This is not intended to be a public release. It will be replaced within a few weeks by a public version or by another test version. @@ -202,7 +202,14 @@ Version 1.5.4beta02 [June 14, 2011] called. Made png_set_chop_16() API removeable by disabling PNG_CHOP_16_TO_8_SUPPORTED -Version 1.5.4beta03 [June 14, 2011] +Version 1.5.4beta03 [June 15, 2011] + Fixed a problem in png_do_expand_palette() exposed by optimization in + 1.5.3beta06 + Also removed a spurious (totally unused and confusing) member from png_info. + The palette expand optimization prevented expansion to an intermediate RGBA + form if tRNS was present but alpha was marked to be stripped; this exposed + a check for tRNS in png_do_expand_palette() which is inconsistent with the + code elsewhere in libpng. Send comments/corrections/commendations to png-mng-implement at lists.sf.net: (subscription required; visit diff --git a/CHANGES b/CHANGES index 7610d8220..240f76278 100644 --- a/CHANGES +++ b/CHANGES @@ -3465,7 +3465,14 @@ Version 1.5.4beta02 [June 14, 2011] called. Made png_set_chop_16() API removeable by disabling PNG_CHOP_16_TO_8_SUPPORTED -Version 1.5.4beta03 [June 14, 2011] +Version 1.5.4beta03 [June 15, 2011] + Fixed a problem in png_do_expand_palette() exposed by optimization in + 1.5.3beta06 + Also removed a spurious (totally unused and confusing) member from png_info. + The palette expand optimization prevented expansion to an intermediate RGBA + form if tRNS was present but alpha was marked to be stripped; this exposed + a check for tRNS in png_do_expand_palette() which is inconsistent with the + code elsewhere in libpng. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/pnginfo.h b/pnginfo.h index fa19f85e7..a33bfab06 100644 --- a/pnginfo.h +++ b/pnginfo.h @@ -138,7 +138,6 @@ defined(PNG_READ_BACKGROUND_SUPPORTED) * single color specified that should be treated as fully transparent. * Data is valid if (valid & PNG_INFO_tRNS) is non-zero. */ - png_bytep trans; /* alpha values for paletted image */ png_bytep trans_alpha; /* alpha values for paletted image */ png_color_16 trans_color; /* transparent color for non-palette image */ #endif diff --git a/pngrtran.c b/pngrtran.c index 53b271369..ada35a913 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -4464,7 +4464,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, if (row_info->bit_depth == 8) { { - if (trans_alpha != NULL) + if (num_trans > 0) { sp = row + (png_size_t)row_width - 1; dp = row + (png_size_t)(row_width << 2) - 1; @@ -4518,7 +4518,7 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row, */ void /* PRIVATE */ png_do_expand(png_row_infop row_info, png_bytep row, - png_const_color_16p trans_value) + png_const_color_16p trans_color) { int shift, value; png_bytep sp, dp; @@ -4530,7 +4530,7 @@ png_do_expand(png_row_infop row_info, png_bytep row, { if (row_info->color_type == PNG_COLOR_TYPE_GRAY) { - png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0); + png_uint_16 gray = (png_uint_16)(trans_color ? trans_color->gray : 0); if (row_info->bit_depth < 8) { @@ -4622,7 +4622,7 @@ png_do_expand(png_row_infop row_info, png_bytep row, row_info->rowbytes = row_width; } - if (trans_value != NULL) + if (trans_color != NULL) { if (row_info->bit_depth == 8) { @@ -4674,13 +4674,13 @@ png_do_expand(png_row_infop row_info, png_bytep row, row_width); } } - else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value) + else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_color) { if (row_info->bit_depth == 8) { - png_byte red = (png_byte)(trans_value->red & 0xff); - png_byte green = (png_byte)(trans_value->green & 0xff); - png_byte blue = (png_byte)(trans_value->blue & 0xff); + png_byte red = (png_byte)(trans_color->red & 0xff); + png_byte green = (png_byte)(trans_color->green & 0xff); + png_byte blue = (png_byte)(trans_color->blue & 0xff); sp = row + (png_size_t)row_info->rowbytes - 1; dp = row + (png_size_t)(row_width << 2) - 1; for (i = 0; i < row_width; i++) @@ -4698,12 +4698,12 @@ png_do_expand(png_row_infop row_info, png_bytep row, } else if (row_info->bit_depth == 16) { - png_byte red_high = (png_byte)((trans_value->red >> 8) & 0xff); - png_byte green_high = (png_byte)((trans_value->green >> 8) & 0xff); - png_byte blue_high = (png_byte)((trans_value->blue >> 8) & 0xff); - png_byte red_low = (png_byte)(trans_value->red & 0xff); - png_byte green_low = (png_byte)(trans_value->green & 0xff); - png_byte blue_low = (png_byte)(trans_value->blue & 0xff); + png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff); + png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff); + png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff); + png_byte red_low = (png_byte)(trans_color->red & 0xff); + png_byte green_low = (png_byte)(trans_color->green & 0xff); + png_byte blue_low = (png_byte)(trans_color->blue & 0xff); sp = row + row_info->rowbytes - 1; dp = row + (png_size_t)(row_width << 3) - 1; for (i = 0; i < row_width; i++)