From 53e537439fbb818f8c47bc1ffa97d6d2391d475e Mon Sep 17 00:00:00 2001 From: John Bowler Date: Fri, 25 Sep 2015 16:22:17 -0700 Subject: [PATCH 1/2] Fix png_set_tRNS_to_alpha for low-bit-depth gray Signed-off-by: John Bowler --- pngrtran.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pngrtran.c b/pngrtran.c index ea05709fd..5e33d6d6d 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -776,7 +776,7 @@ fill_transparent_pixel(png_const_structrp png_ptr, png_byte *trans) #ifdef PNG_READ_EXPAND_SUPPORTED /* Flags for png_init_expand */ #define PNG_EXPAND_PALETTE 1U /* palette images only, includes tRNS */ -#define PNG_EXPAND_LBP_GRAY 2U /* grayscale low-bit depth only */ +#define PNG_EXPAND_LBD_GRAY 2U /* grayscale low-bit depth only */ #define PNG_EXPAND_tRNS 4U /* non-palette images only */ /* This struct is only required for tRNS matching, but it is convenient to @@ -1053,7 +1053,7 @@ png_init_expand(png_transformp *transform, png_transform_controlp tc) debug(tc->init); if (bit_depth >= 8U) - args &= PNG_BIC_MASK(PNG_EXPAND_LBP_GRAY); + args &= PNG_BIC_MASK(PNG_EXPAND_LBD_GRAY); # ifdef PNG_READ_tRNS_SUPPORTED if (png_ptr->num_trans == 0U || @@ -1066,7 +1066,7 @@ png_init_expand(png_transformp *transform, png_transform_controlp tc) switch (args) { - case PNG_EXPAND_LBP_GRAY: + case PNG_EXPAND_LBD_GRAY: tc->bit_depth = 8U; tc->invalid_info |= PNG_INFO_tRNS; @@ -1075,7 +1075,7 @@ png_init_expand(png_transformp *transform, png_transform_controlp tc) break; # ifdef PNG_READ_tRNS_SUPPORTED - case PNG_EXPAND_LBP_GRAY + PNG_EXPAND_tRNS: + case PNG_EXPAND_LBD_GRAY + PNG_EXPAND_tRNS: tc->bit_depth = 8U; tc->format |= PNG_FORMAT_FLAG_ALPHA; tc->invalid_info |= PNG_INFO_tRNS; @@ -1131,7 +1131,7 @@ png_set_expand_gray_1_2_4_to_8(png_structrp png_ptr) { if (png_ptr != NULL) png_add_transform(png_ptr, sizeof (png_expand), png_init_expand, - PNG_TR_EXPAND)->args |= PNG_EXPAND_LBP_GRAY; + PNG_TR_EXPAND)->args |= PNG_EXPAND_LBD_GRAY; } /* Expand paletted images to 8-bit RGB or, if there is a tRNS chunk, RGBA. @@ -1189,9 +1189,12 @@ png_init_alpha(png_transformp *transform, png_transform_controlp tc) required = 1; tc->expand_tRNS = 1U; + /* This happens as a result of an explicit API call to + * png_set_tRNS_to_alpha, so expand low-bit-depth gray too: + */ if (tc->init == PNG_TC_INIT_FORMAT) png_add_transform(png_ptr, sizeof (png_expand), png_init_expand, - PNG_TR_EXPAND)->args |= PNG_EXPAND_tRNS; + PNG_TR_EXPAND)->args |= PNG_EXPAND_tRNS + PNG_EXPAND_LBD_GRAY; } else @@ -2221,7 +2224,7 @@ push_gamma_expand(png_transformp *transform, png_transform_controlp tc, affirm(tc->init == PNG_TC_INIT_FINAL); if (tc->bit_depth < 8U) /* low bit gray: expand to 8 bits */ - expand = PNG_EXPAND_LBP_GRAY; + expand = PNG_EXPAND_LBD_GRAY; /* Gamma correction invalidates tRNS, so if it is being expanded and * alpha is not being stripped expand it now. From a5b993aaed73cd4e37b09f63f15abe9ced5535ba Mon Sep 17 00:00:00 2001 From: John Bowler Date: Fri, 25 Sep 2015 16:22:59 -0700 Subject: [PATCH 2/2] Enable low-bit-depth gray tests in pngvalid --- contrib/libtests/pngvalid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/libtests/pngvalid.c b/contrib/libtests/pngvalid.c index a5bdfca48..35ded08fe 100644 --- a/contrib/libtests/pngvalid.c +++ b/contrib/libtests/pngvalid.c @@ -11115,7 +11115,7 @@ int main(int argc, char **argv) # ifdef PNG_WRITE_tRNS_SUPPORTED pm.test_tRNS = 1; # endif - pm.test_lbg = 0; + pm.test_lbg = PNG_LIBPNG_VER >= 10600; pm.test_lbg_gamma_threshold = 1; pm.test_lbg_gamma_transform = PNG_LIBPNG_VER >= 10600; pm.test_lbg_gamma_sbit = 1;