Palette-Based with Transparency
The PNG spec forbids the use of a full alpha channel
with palette-based images,
but it does allow ``cheap alpha'' via the transparency chunk, tRNS. As its
name implies--the first letter is lowercase--tRNS is an ancillary chunk,
which means the image is still viewable even if the decoder somehow fails to
recognize the chunk.
The structure of tRNS depends on the image type, but
for palette-based images it is exactly analogous to the PLTE chunk. It may
contain as many transparency entries as there are palette entries (more than
that would not make any sense) or as few as one, and it must come after PLTE
and before the first IDAT. In effect, it transforms the palette from an RGB
lookup table to an RGBA table, which implies a potential factor-of-four
savings in file size over a full 32-bit RGBA image. The icicle image used
as a basis for Figure C-1 in the color insert is
an RGBA-palette image; it is ``only'' 3.85 times smaller than the 32-bit
original due to dithering (which hurts compression).
By comparison, GIF supports only binary transparency, wherein a single
palette color is marked as completely transparent, while all others
are fully opaque. GIF has a tiny advantage in that the transparent
entry can live anywhere in the palette, whereas a single PNG
transparency entry should come first--all tRNS entries before the
transparent one must exist and must have the value 255 (fully opaque),
which would be redundant and therefore a waste of space. But the code
necessary to rearrange the palette so that all non-opaque entries come
before any opaque ones is simple to write, and the benefits of PNG's
more flexible transparency scheme far outweigh this minor drawback.
The TIFF format supports at least three kinds of transparency information,
two involving an interleaved alpha channel (extra samples) and the third
involving a completely separate subimage (or subfile) that is used as a
bilevel transparency mask. Baseline TIFF does not require support for any
of them, but libtiff supports the two interleaved flavors directly,
and could probably be manhandled into some level of support for the subfile
approach, although the transparency mask is ``typically at a higher
resolution than the main image if the main image is grayscale or color,''
according to the TIFF 6.0 specification.
On the other hand, with the possible exception of user-designed TIFF tags,
there is no support at all for ``cheap alpha,'' i.e., marking one or more
palette entries as partially or completely transparent.