Handled tRNS color palette for PNG images (was crashing before)
Created by: siebenkopf
I have been stepping on weired types of PNG images lately. One of them is stored in an 8 bit palette format containing an alpha channel. This color type si called "tRNS" and it is documented here: http://www.libpng.org/pub/png/libpng-1.2.5-manual.html#section-3.7 where I have also found the solution to the problem.
For this type of images, the current version of png's im_load
crashes with some weired error message (double free) the python interpreter. After some debugging I have found out, why: we rely on estimating alpha based on the PNG_COLOR_MASK_ALPHA
, which is simply not set for these type of image (the color type is simply PNG_COLOR_TYPE_PALETTE
.
When setting has_alpha
to true in this case, we are sure to read (and actually skip) the alpha channel in im_load_color
.
The test cases pass -- meaning that the old way of reading PNGs was not influenced, but I am not sure if we test all cases of all different PNG color channels. I would like to add a test image with the tRNS color palette, but I have no idea, how to create such an image. I have read that ImageMagick does not write pngs with this palette. The current test image that I have is protected and cannot be published.