mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
Fix rare issue where some PNGs were decoded with the wrong transparency (Thanks Goodly)
If the bitmap used a colour type of 2 (RGB) or 0 (GRAYSCALE), and had a tRNS chunk to indicate to treat one specific RGB colour as transparent, and that specific colour wasn't block, the decoder would still incorrectly treat black as the transparent colour instead of the actual colour specified
This commit is contained in:
parent
3e08cfc533
commit
03ccdbbc5c
10
src/Bitmap.c
10
src/Bitmap.c
@ -429,8 +429,9 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
|
||||
res = Stream_Read(stream, tmp, dataSize);
|
||||
if (res) return res;
|
||||
|
||||
/* RGB is 16 bits big endian, ignore least significant 8 bits */
|
||||
trnsCol = BitmapCol_Make(tmp[0], tmp[0], tmp[0], 0);
|
||||
/* RGB is always two bytes */
|
||||
/* TODO is this right for 16 bits per channel images? */
|
||||
trnsCol = BitmapCol_Make(tmp[1], tmp[1], tmp[1], 0);
|
||||
} else if (col == PNG_COLOR_INDEXED) {
|
||||
if (dataSize > PNG_PALETTE) return PNG_ERR_TRANS_COUNT;
|
||||
res = Stream_Read(stream, tmp, dataSize);
|
||||
@ -446,8 +447,9 @@ cc_result Png_Decode(struct Bitmap* bmp, struct Stream* stream) {
|
||||
res = Stream_Read(stream, tmp, dataSize);
|
||||
if (res) return res;
|
||||
|
||||
/* R,G,B is 16 bits big endian, ignore least significant 8 bits */
|
||||
trnsCol = BitmapCol_Make(tmp[0], tmp[2], tmp[4], 0);
|
||||
/* R,G,B are always two bytes */
|
||||
/* TODO is this right for 16 bits per channel images? */
|
||||
trnsCol = BitmapCol_Make(tmp[1], tmp[3], tmp[5], 0);
|
||||
} else {
|
||||
return PNG_ERR_TRANS_INVALID;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user