4
votes

I would like to confirm my interpretation of the PNG file format description is correct with color type 0x02 and with tRNS chunk present. It says on PNG website that:

For colour types 0 or 2, two bytes per sample are used regardless of the image bit depth (see 7.1: Integers and byte order). Pixels of the specified grey sample value or RGB sample values are treated as transparent (equivalent to alpha value 0); all other pixels are to be treated as fully opaque (alpha value 2bitdepth-1). If the image bit depth is less than 16, the least significant bits are used and the others are 0.

Give this same tRNS Chunk:

Length: 6
Type: tRNS
Data: 00 ff 00 ff 00 ff 
CRC: 37581b7d

Does this mean for RRGGGBBB: 0xFFFFFF or the white color is treated as transparent and all other colors are as is? If so, for the general case, I need to construct an array of such color (say array of int) and during the decoding of the IDAT chunk, I need to look up if the color is one of the transparent color, if so, it is treated as (RRGGBBAA) 0xRRGGBB00, or fully transparent? What would be a good LUT for such case?

Thanks!

1

1 Answers

5
votes

Your interpretation is correct.

I need to look up if the color is one of the transparent color,

Actually not "one of" but the transparent colour: in the truecolor+TRNS scenario all colors are opaque except one.

What would be a good LUT for such case?

I don't think that scenario has to do with LUTs. Think of this format as an efficient way to store a true color image with "hard" (yes/no) transparency. The decoder will typically either decode the image adding an alpha channel (and then the colour would be factually ignored), (for example you can see lineToARGB32 method here) or either by ignoring the TRNS.

Notice that this truecolour+TRNS case is not very usual, there are not many PNG images with that format, and many readers just ignore the TRNS in that case.