Fix Grayscale depth reduction with tRNS #470
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for #426. The tRNS chunk was not being accounted for when reducing the bit depth of a grayscale image.
There are two possibilities we need to account for here:
I've added two tests for both of these cases.
The example images in #426 are in grayscale-8 with a tRNS value of 1 (near-black). This colour does not appear in the image and when the depth is reduced to 1-bit, the tRNS value of 1 now refers to white, making the image black and transparent instead of black and white.
Closes #426.
[edit]
Would be good if you could double-check my logic for validating the tRNS value. Or see if you have any ideas for achieving the same thing without a loop. I note the current grayscale reduction only supports reducing from 8-bit (not from 4 or 2), but the tRNS reduction/validation should continue to work even if that limitation is removed in future (it would be a bit of work though, so not inclined to do it right now).