Grayscale with Alpha Channel
The second kind of transparency supported by grayscale images is an alpha
channel. This is a more expensive approach in terms of file size--for
grayscale, it doubles the number of image bytes--but it allows the user
much greater freedom in setting individual pixels to particular levels
of partial transparency. Only 8-bit and 16-bit grayscale images may have
an alpha channel, which must match the bit depth of the gray channel.
The full TIFF specification supports two kinds of interleaved ``extra samples''
for transparency: associated and unassociated alpha (though not at the
same time). Unlike PNG, TIFF's alpha channel may be of a different bit depth
from the main image data--in fact, every channel in a TIFF image may have an
arbitrary depth. TIFF also offers the explicit possibility of treating
a ``subfile,'' or secondary image within the file, as a transparency mask,
though such masks are only 1 bit deep, and therefore support only completely
opaque or completely transparent pixels.
Baseline TIFF does not require support for any of this, however. Current
versions of libtiff can read an interleaved alpha channel as generic
``extra samples,'' but it is up to the application to interpret the
samples correctly. The library does not support images with channels of
different depths, and although it could be manipulated into reading a
secondary grayscale subfile (which the application could interpret as a
full alpha channel), that would be a user-defined extension--i.e., specific
to the application and not supported by any other software.
As I just noted, standard JPEG (by which I mean the common JPEG File
Interchange Format, or JFIF files) has no provision for transparency. The
JPEG standard itself does allow extra channels, one of which could be treated
as an alpha channel, but this would be fairly pointless. Not only would it
require one to use a non-standard, unsupported file format for storage, there
would also tend to be visual artifacts, since lossy JPEG is not well suited to
the types of alpha masks one typically finds (unless the mask's quality
setting were boosted considerably, at a cost in file size). But see
Chapter 12, "Multiple-Image Network Graphics" for details on a MNG subformat called JNG that combines a
lossy JPEG image in JFIF format with a PNG-style, lossless alpha channel.