Strip alpha channel from PNG images with tRNS chunk

When PNG transformations are set up, tRNS chunk is converted to alpha channel
early in the process.  Later the decision whether to strip alpha channel or not
is made upon checking (color_type & PNG_COLOR_MASK_ALPHA).  Thus alpha channel
created by tRNS chunk conversion does not get stripped.
This commit is contained in:
Dmitrij D. Czarkoff 2016-08-15 15:39:18 +02:00
parent 2e3e80c1ee
commit 8decf20d4f

View file

@ -192,6 +192,7 @@ out:
int load_png(struct quirc *q, const char *filename) int load_png(struct quirc *q, const char *filename)
{ {
int width, height, rowbytes, interlace_type, number_passes = 1; int width, height, rowbytes, interlace_type, number_passes = 1;
png_uint_32 trns;
png_byte color_type, bit_depth; png_byte color_type, bit_depth;
png_structp png_ptr = NULL; png_structp png_ptr = NULL;
png_infop info_ptr = NULL; png_infop info_ptr = NULL;
@ -229,13 +230,13 @@ int load_png(struct quirc *q, const char *filename)
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand_gray_1_2_4_to_8(png_ptr); png_set_expand_gray_1_2_4_to_8(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) if ((trns = png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
png_set_tRNS_to_alpha(png_ptr); png_set_tRNS_to_alpha(png_ptr);
if (bit_depth == 16) if (bit_depth == 16)
png_set_scale_16(png_ptr); png_set_scale_16(png_ptr);
if (color_type & PNG_COLOR_MASK_ALPHA) if ((trns) || color_type & PNG_COLOR_MASK_ALPHA)
png_set_strip_alpha(png_ptr); png_set_strip_alpha(png_ptr);
if (color_type == PNG_COLOR_TYPE_PALETTE) if (color_type == PNG_COLOR_TYPE_PALETTE)