The PNG Guide is an eBook based on Greg Roelofs' book, originally published by O'Reilly. |
Home An Introduction to PNG What Is PNG Good For Alpha Channels | |||
Alpha ChannelsAll three of the basic PNG image types--RGB, grayscale, and palette-based--can have alpha information, but currently it's most often used with truecolor images. Instead of storing three bytes for every pixel, now four are required: red, green, blue, and alpha, or RGBA. The variable transparency allows one to create special effects that will look good on any background, whether light, dark, or patterned. For example, a photo-vignette effect can be created for a portrait by making a central oval region fully opaque (i.e., for the face and shoulders of the subject), the outer regions fully transparent, and a transition region that varies smoothly between the two extremes. When viewed with a web browser such as Acorn Browse or Arena, the portrait would fade smoothly to white when viewed against a white background or smoothly to black if against a black background. Both cases are shown in Figure 1-2.
This feature is especially important for the small web graphics that are
typically used on web pages, such as colored (circular) bullets and fancy
text. To avoid the jagged artifacts that really stand out on such images,
Alpha blending, on the other hand, effectively uses transparency as a placeholder for the background color. Fully transparent regions will inherit the background color as is; fully opaque regions will show up as the foreground images. This is no different from the usual case, exemplified by transparent GIFs. But the anti-aliased regions in between the fully transparent and fully opaque areas are no longer pre-mixed with an assumed background color; instead, they are partially transparent and can be mixed with whatever background on which the image happens to be placed. Of course, effective replacements for GIF buttons and icons must not only be
more useful but also of comparable or smaller size, and that mostly rules out
truecolor RGBA images. Fortunately, PNG supports alpha information with
palette images as well; it's just harder to implement in a smart way. A PNG
alpha-palette image is just that: an image whose palette also has alpha
information associated with it, not a palette image with a full alpha mask.
In other words, each pixel corresponds to an entry in the palette with red,
green, blue, and alpha components. So if you want to have bright red
pixels with four different levels of transparency, you must use four separate
palette entries to accommodate them--all four entries will have identical
RGB components, but the alpha values will differ. If you want all of
your colors to have four levels of transparency, you've effectively reduced
your total number of available colors from 256 to 64. In general, though,
only some of the colors need more than one level of transparency, and
recognizing which ones do is where things get tricky for the programmer.[2]
|
|||
Home An Introduction to PNG What Is PNG Good For Alpha Channels |