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:
parent
2e3e80c1ee
commit
8decf20d4f
1 changed files with 3 additions and 2 deletions
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue