diff --git a/pngread.c b/pngread.c index b11f4db0f..ba56032e0 100644 --- a/pngread.c +++ b/pngread.c @@ -1286,24 +1286,26 @@ png_read_png(png_structp png_ptr, png_infop info_ptr, /* -------------- image transformations start here ------------------- */ -#ifdef PNG_READ_16_TO_8_SUPPORTED +#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED /* Tell libpng to strip 16-bit/color files down to 8 bits per color. */ -# ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED if (transforms & PNG_TRANSFORM_SCALE_16) - png_set_scale_16(png_ptr); -# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED - else - -# endif -# endif -# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + { /* Added at libpng-1.5.4. "strip_16" produces the same result that it * did in earlier versions, while "scale_16" is now more accurate. */ + png_set_scale_16(png_ptr); + } + +# ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED + else +# endif + +#endif + +#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED if (transforms & PNG_TRANSFORM_STRIP_16) png_set_strip_16(png_ptr); -# endif #endif #ifdef PNG_READ_STRIP_ALPHA_SUPPORTED diff --git a/pngrtran.c b/pngrtran.c index 0fca5dd51..e4ed0b996 100644 --- a/pngrtran.c +++ b/pngrtran.c @@ -1873,23 +1873,24 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr) #endif #ifdef PNG_READ_16_TO_8_SUPPORTED -#ifdef PNG_READ_16BIT_SUPPORTED +# ifdef PNG_READ_16BIT_SUPPORTED if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) && (info_ptr->bit_depth == 16)) info_ptr->bit_depth = 8; -#else +# else + /* Force chopping 16-bit input down to 8 */ if (info_ptr->bit_depth == 16) { - if (!(png_ptr->transformations & PNG_SCALE_16_TO_8)) -#if PNG_READ_STRIP_16_TO_8_SUPPORTED + if (!(png_ptr->transformations & PNG_16_TO_8)) +# if PNG_READ_STRIP_16_TO_8_SUPPORTED png_ptr->transformations |=PNG_16_TO_8; -#else +# else png_ptr->transformations |=PNG_SCALE_16_TO_8; -#endif +# endif info_ptr->bit_depth = 8; } -#endif +# endif #endif #ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED @@ -2151,7 +2152,7 @@ png_do_read_transformations(png_structp png_ptr) #endif #ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED - if (png_ptr->transformations & PNG_16_TO_8) + if (png_ptr->transformations & PNG_SCALE_16_TO_8) png_do_scale_16_to_8(&(png_ptr->row_info), png_ptr->row_buf + 1); #endif #ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED