This article has multiple issues. Please helpimprove it or discuss these issues on thetalk page.(Learn how and when to remove these messages) (Learn how and when to remove this message)
|

| Color depth |
|---|
| Related |
In computing,indexed color is a technique to managedigital images' colors in a limited fashion, in order to savecomputer storage, while speeding up display refresh and file transfers. It is a form ofvector quantization compression.
When an image isencoded in this way, color information is not directly carried by the imagepixel data, but is stored in a separate piece of data called acolor lookup table (CLUT) orpalette: an array of color specifications. Every element in the array represents a color, indexed by its position within the array. For color information, each image pixel then specifies only its index into thepalette.
This technique is sometimes referred aspseudocolor[1] orindirect color,[2] as colors are addressed indirectly.
Early graphics display systems that used 8-bit indexed color withframe buffers and CLUTs include Shoup'sSuperPaint (1973) and the video frame buffer described in 1975 by Kajiya, Sutherland, and Cheadle.[3][4] These supported a palette of 256 RGB colors. SuperPaint used ashift-register frame buffer, while the Kajiya et al. system used arandom-access frame buffer.
A few earlier systems used 3-bit color, but typically treated the bits as independent red, green, and blue on/off bits rather than jointly as an index into a CLUT.
The palette itself stores a limited number of distinct colors; 4, 16 or 256 are the most common cases. These limits are often imposed by the target architecture'sdisplay adapter hardware, so it is not a coincidence that those numbers are exactpowers of two: 22 = 4, 24 = 16 and 28 = 256. While 256 values can fit into a single 8-bitbyte (and then a single indexed color pixel also occupies a single byte), multiple pixel indices with 16 (4-bit, anibble) or fewer colors can be packed together into a single byte (two nibbles per byte, if 16 colors are employed, or four 2-bit pixels per byte if using 4 colors). Sometimes, 1-bit (2-color) values can be used, and then up to eight pixels can be packed into a single byte; such images are consideredbinary images (sometimes referred as abitmap orbilevel image) and not an indexed color image.
If simplevideo overlay is intended through atransparent color, one palette entry is specifically reserved for this purpose, and it is discounted as an available color. Some machines, such as theMSX series, had the transparent color reserved by hardware.[5]
Indexed color images with palette sizes beyond 256 entries are rare. The practical limit is around 12 bits per pixel, 4,096 different indices. Useful direct RGBhigh color modes can be used from 15 bpp and up.
If an image has many subtle color shades, it is necessary to select a limited repertoire of colors to approximate the image usingcolor quantization. Such a palette is frequently insufficient to represent the image accurately; difficult-to-reproduce features such asgradients will appear blocky or as strips (color banding). In those cases, it is usual to employdithering, which mixes different-colored pixels in patterns, exploiting the tendency of human vision to blur nearby pixels together, giving a result visually closer to the original one.
Here is a typical indexed 256-color image and its own palette (shown as a rectangle of swatches):
How the colors are encoded within the color palette map of a given indexed color image depends on the target platform.
Many earlypersonal andhome computers had very limitedhardware palettes that could produce a very small set of colors. In these cases, each pixel's value is mapped directly onto one of these colors. Well-known examples include theApple II,Commodore 64 andIBM PC CGA, all of which include hardware that can produce a fixed set of 16 colors. In these cases, an image can encode each pixel with 4 bits, directly selecting the color to use. In most cases, however, the display hardware supports additional modes where only a subset of those colors can be used in a single image, a useful technique to save memory. For instance, the CGA's320 × 200 resolution mode can show only four of the 16 colors at one time. As the palettes are entirely proprietary, an image generated on one platform cannot be directly viewed properly on another.
Other machines of this era had the ability to generate a larger set of colors, but generally only allowed a subset of those to be used in any one image. Examples include the 256-color palette onAtari 8-bit machines or the 4,096 colors of theVT241 terminal inReGIS graphics mode. In these cases it was common for the image to only allow a small subset of the total number of colors to be displayed at one time, up to 16 at once on the Atari and VT241. Generally, these systems worked identically to their less-colorful brethren, but a key difference was that there were too many colors in the palette to directly encode in the pixel data given the limited amount ofvideo memory. Instead, they used acolour look-up table (CLUT) where each pixel's data pointed to an entry in the CLUT, and the CLUT was set up under program control. This meant that the image CLUT data had to be stored along with the raw image data in order to be able to re-produce the image correctly.
Hardware palettes based oncomponent video colors such asYPbPr or the like were generally replaced in the mid 1980s by the more flexibleRGB color model, in which a given color can be obtained by mixing different amounts of the threeprimary colors red, green, and blue. Although the total number of different colors depends on the number of levels per primary, and on a given hardware implementation (a9-bit RGB provides 512 combinations, a12-bit RGB provides 4,096, and so on), in this modeldigital-to-analog converters (DAC) can generate the colors — simplifying the hardware design — while the software can treat the number per levels used abstractly and manage the RGB colors in a device-independent fashion. With colors stored in RGB format within the palettes of indexed image files, any image can be displayed (through appropriate transformations) on any such system, regardless of the color depth used in the hardware implementation.
Today, display hardware andimage file formats that deal with indexed color images almost exclusively manage colors in RGB format, the de facto standard encoding being the so-calledtruecolor or24-bit RGB, with16,777,216 different possible colors. However, indexed color images are not genuinely constrained to a 24-bit RGB color encoding; image palettes can hold any type of color encoding. For example, thePDF file format does support indexed color in other colorspaces, notablyCMYK, andAdobe Distiller by default will convert images to indexed color whenever the total number of colors in an image is equal to or less than 256. When using RGB, theTIFF andPNG file formats can optionally store the RGB triplets with a precision of 16-bit (65,536 levels per component) yielding a total of 48 bits per pixel. A proposed extension to the TIFF Standard allows[6] non-RGB color palettes, but this was never implemented in software due to technical reasons. The color map table of theBMP file format indexed color mode stores its entries in BGR order rather than RGB, and has (in the current version) an additional unused byte for padding to conform to32-bitword alignment during processing, but it is essentially still a 24-bit RGB color encoding. (An earlier version of the BMP format used three bytes per 24-bit color map table entry, and many files in that format are still in circulation, so many modern programs that read BMP files support both variations.)
Except for very low resolution graphic modes, early home and personal computers rarely implemented an "all-pixels-addressable" design - that is, the ability to change a single pixel to any of the available colors independently. Their limitations came from employing separatecolor attribute orcolor RAM areas, leading toattribute clash effects. Also, the pixel bits and/or the scan lines of the video memory were commonly arranged in odd ways convenient for the video generator hardware (thus saving hardware costs in a cost-competitive market), but sometimes creating difficulty for the people writing graphics programs. A pixel's bits in indexed-color, all-pixel-addressable images are not always contiguous in video memory or image files (i.e.,chunky organization is not always used.) Some video hardware, such as the 16-color graphic modes of theEnhanced Graphics Adapter (EGA) andVideo Graphics Array (VGA) forIBM PC compatibles[7]or theAmiga video buffer[8]are arranged as a series ofbit planes (in a configuration calledplanar), in which the related bits of a single pixel are split among several independentbitmaps. Thus, the pixel bits are conceptually aligned along the 3D Z-axis. (The "depth" concept here is not the same as that of pixeldepth.)
Early image file formats, such asPIC, stored little more than a barememory dump of the video buffer of a given machine.
Some indexed-color image file formats such asGraphics Interchange Format (GIF) allow the image's scan lines to be arranged ininterleaved fashion (not linear order), which allows a low resolution version of the image to appear on screen while it is still downloading, so that the computer user can gain an idea of its contents during the seconds before the whole image arrives. Here is an example of a typical vertically interleaved download in four steps:

As seen here, the image has been divided into four groups of lines: group A contains every fourth line, group B contains lines immediately following ones in group A, group C likewise contains the lines immediately following those in group B, and group D contains the remaining lines, which are between group C lines (immediately above) and group A lines (immediately below). These are stored into the file in the order A, C, B, D, so that when the file is transmitted the second received group (C) of lines lie centered between the lines of the first group, yielding the most spatially uniform and recognizable image possible, composed of only two of the groups of lines. The same technique can be applied with more groups (e.g. eight), in which case at each step the next group to be sent contains lines lying at or near the centers of remaining bands that are not yet filled with image data. This method, with four or eight groups of lines, was commonly used on the early World Wide Web during the second half of the 1990s. Rather than leaving the background (black) showing as in the illustration above, the partial image was often presented on screen by duplicating each line to fill the space below it down to the next received image line. The end result was a continuous image with decreased vertical resolution that would increase to full resolution over a few seconds as the later parts of the image data arrived.
Indexed color saves a lot of memory, storage space, and transmission time: usingtruecolor, each pixel needs 24 bits, or 3 bytes. A typical 640×480VGA resolution truecolor uncompressed image needs 640×480×3 = 921,600 bytes (900 KiB). Limiting the image colors to 256, every pixel needs only 8 bits, or 1 byte each, so the example image now needs only 640×480×1 = 307,200 bytes (300 KiB), plus 256×3 = 768 additional bytes to store the palette map in itself (assuming RGB), approximately one third of the original size. Smaller palettes (4-bit 16 colors, 2-bit 4 colors) can pack the pixels even more (to one sixth or one twelfth), obviously at cost of color accuracy.
Indexed color was widely used in earlypersonal computers and display adapters' hardware to reduce costs (mainly by requiring fewer of the then-expensiveRAMchips) but also for convenient image management with limited-powerCPUs (of the order of 4 to 8MHz), file storage (cassette tapes and low densityfloppy disks). Notable computer graphics systems extensively (or even exclusively) using pseudocolor palettes in the 1980s includeCGA,EGA, and VGA (forIBM PC compatibles), theAtari ST, andAmiga'sOCS andAGA.
Image files exchanged over theCompuServe net in the early 1990s were encapsulated in theGIF format. Later, theHTML web pages used the GIF along with other indexed color-supporting file formats such asPNG, to exchange limited-color images quickly and store them in limited storage space.
Mostimage file formats that support indexed color images also commonly support somecompression scheme, enhancing their ability to store the images in smaller files.
Interestingcolorized and artistic effects can be easily achieved by altering the color palette of indexed color images, for example to produce colorizedsepia tone images. Due to the separate nature of the associated palette element of the indexed color images, they are ideal to remapgrayscale images intofalse color ones through the use offalse color palettes.
Simplevideo overlay can be achieved easily through thetransparent color technique.
By manipulating the color hardware registers (Color look-up table or CLUT) of the display adapter in the indexed color graphic modes, full-screen color-animation effects can be achieved without redrawing the image - that is, at low CPU time cost; a single change of the register values affects the whole screen at once. Color-map animation, also known asColor cycling, is extensively used in thedemoscene. The Microsoft Windows boot logo screen in Windows 95, 98, ME, and 2000 Professional (which uses VGA 320x200x256 color display mode because it is the greatest common denominator on all PCs) employs this technique for the scrolling gradient bar across the bottom of the screen; the picture is a static image with no pixels rewritten after it is initially displayed. Custom boot screen images could tap the cycled colors to animate other parts of the images.
The main disadvantage of using indexed color is the limited set of simultaneous colors per image. Small 4- or 16-color palettes are still acceptable for little images (icons) or very simple graphics, but to reproduce real life images they become nearly useless. Some techniques, such ascolor quantization,anti-aliasing anddithering combined together can create indexed 256-color images comparable to the original up to an acceptable level.
Indexed color images are heavily dependent on their own color palettes. Except for a few well known fixed-color palettes (such as that of theColor Graphics Adapter—CGA), raw image data and/or color map tables cannot be reliably exchanged between different image files without some kind of intermediate mapping. Also, if the original color palette for a given indexed image is lost, it can be nearly impossible to restore it. Here is an example of what happens when an indexed color image (the previous parrot) has been associated with an incorrect color palette:
Indexed color graphic modes for display adapters have the 16- or 256-color limit imposed by hardware. Indexed color images with rich but incompatible palettes can only be accurately displayed one at a time, as in aslideshow. When it is necessary to show multiple images together, as in a mosaic ofthumbnails, a common ormaster palette is often used, which encompasses as many different hues as possible into a single set, thereby limiting the overall accurate color availability.
The following image is a mosaic of four different indexed color images rendered with a single sharedmaster palette of6-8-5 levels RGB plus 16 additional grays. Note the limited range of colors used for every image, and how many palette entries are left unused.
Many indexed color display devices do not reach the 24-bit limit for the full RGB palette. TheVGA for IBM PC compatibles, for example, only provides an18-bit RGB palette with 262,144 different possible colors in both 16- and 256- indexed color graphic modes.
Some image editing software allowsgamma correction to be applied to a palette for indexed color image files. In general, to apply a gamma correction directly to the color map is bad practice, due to the original RGB color values being lost. It is better to apply the gamma correction with the display hardware (most modern display adapters support this feature), or as an active intermediate step of the rendering software throughcolor management, which preserves the original color values. Only when the indexed color images are intended for systems that lack any kind ofcolor calibration, and they are not intended to be cross-platform, gamma correction may be applied to the color table itself.
These are some of the most representative image file formats that support indexed color modes. Some of these support other modes (e.g. truecolor), but only the indexed color modes are listed here.
| Acronym | Full name | Creator | DOS extension | 1-bit (2) | 2-bit (4) | 3-bit (8) | 4-bit (16) | 5-bit (32) | 6-bit (64) | 7-bit (128) | 8-bit (256) | Compression |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| PCX | PC Paintbrush Image File | ZSoft Corporation | .pcx | Yes | Yes | No | Yes | No | No | No | Yes | RLE |
| ILBM | InterLeaved BitMap | Electronic Arts | .lbm,.iff | Yes | Yes | Yes | Yes | Yes | Yes* (EHB mode, 64-color) | Yes* | Yes* | Uncompressed,RLE |
| GIF | Graphics Interchange Format | Compuserve | .gif | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | LZW |
| TGA | TARGA File format | Truevision | .tga, .vda,.icb, .vst | No | No | No | No | No | No | No | Yes | Uncompressed,RLE |
| TIFF | Tag(ged) Image File Format | Aldus | .tif | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Uncompressed,DEFLATE,LZW,PackBits,CCITT Group 3 fax,CCITT Group 4 fax,JPEG,others less common (**) |
| BMP | Device-independent Bitmap | Microsoft | .bmp,.dib,.rle | Yes | No | No | Yes | No | No | No | Yes | Uncompressed,RLE (***) |
| PSD | Photoshop Document | Adobe Systems | .psd | No | No | No | No | No | No | No | Yes | PackBits |
| PNG | Portable Network Graphics | PNG Development Group | .png | Yes | Yes | No | Yes | No | No | No | Yes | DEFLATE |