Palette (computing)

Last updated
RGB 24bits palette sample image.jpg
Sample image
Sample Image RGB Cube.gif
The palette used in the image, shown rotating about the RGB color space.

In computer graphics, a palette is the set of available colors from which an image can be made. In some systems, the palette is fixed by the hardware design, and in others it is dynamic, typically implemented via a color lookup table (CLUT), a correspondence table in which selected colors from a certain color space's color reproduction range are assigned an index, by which they can be referenced. By referencing the colors via an index, which takes less information than needed to describe the actual colors in the color space, this technique aims to reduce data usage, including processing, transfer bandwidth, RAM usage, and storage. Images in which colors are indicated by references to a CLUT are called indexed color images.

Contents

Description

As of 2019, the most common image colorspace in graphics cards is the RGB color model with 8 bits per pixel color depth. Using this technique, 8 bits per pixel are used to describe the luminance level in each of the RGB channels, therefore 24 bits fully describe the color of each pixel. The full system palette for such hardware therefore has 224 colors. The objective of the usage of smaller palettes via CLUTs is to lower the number of bits per pixel by reducing the set of possible colors that are to be handled at once (often using adaptive methods). Each possible color is assigned an index, which allows each color to be referenced using less information than needed to fully describe the color. An example is the 256-color palette commonly used in the GIF file format, in which 256 colors to be used to represent an image are selected from the whole 24 bit color space, each being assigned an 8 bit index. This way, while the system can potentially reproduce any color in the RGB color space (as long as the 256 color restriction allows), the storage requirement per pixel is lowered from 24 to 8 bits per pixel.

Master palette

An adaptive color palette expanding from 2 colors to 256 colors, demonstrating how the image changes (click to see animation).

In an application showing many different image thumbnails in a mosaic on screen, the program may not be able to load all the adaptive palettes of every displayed image thumbnail at the same time in the hardware color registers. A solution is to use a unique, common master palette or universal palette, which can be used to display with reasonable accuracy any kind of image.

This is done by selecting colors in such way that the master palette comprises a full RGB color space "in miniature", limiting the possible levels that the red, green and blue components may have. This kind of arrangement is sometimes referred as a uniform palette. [1] The normal human eye has sensibility to the three primary colors in different degrees: the more to the green, the less to the blue. So RGB arrangements can take advantage of this by assigning more levels for the green component and fewer to the blue.

A master palette built this way can be filled with up to 8R×8G×4B = 256 colors , but this does not leave space in the palette for reserved colors, color indices that the program could use for special purposes. It is more general to use only 6R×6G×6B = 216 (as in the Web colors case), 6R×8G×5B = 240 or 6R×7G×6B = 252 , which leaves room for some reserved colors.

Then, when loading the mosaic of image thumbnails (or other heterogeneous images), the program simply maps every original indexed color pixel to its most approximated in the master palette (after dumping this into the hardware color registers), and writes the result in the video buffer. Here is a sample of a simple mosaic of the four image thumbnails using a master palette of 240 RGB arranged colors plus 16 additional intermediate shades of gray; all images are put together without a significant loss of color accuracy:

IndexedColorSample (Mosaic).png

Adaptive palette

When using indexed color techniques, real life images are represented with better fidelity to the truecolor original one by using adaptive palettes (sometimes termed adaptative palettes), in which the colors are selected or quantized through some algorithm directly from the original image (by picking the most frequent colors). This way, and with further dithering, the indexed color image can nearly match the original.

But this creates a heavy dependence between the image pixels and its adaptive palette. Assuming a limited 8-bit depth graphic display, it is necessary to load a given image's adaptive palette into the color hardware registers prior to loading the image surface itself into the frame buffer. To display different images with different adaptive palettes, they must be loaded one by one, as in a slideshow. Here are samples of four different indexed color images with color patches to show their respective (and largely incompatible) adaptive palettes:

IndexedColorSample (Strawberries picked).png IndexedColorSample (Caerulea3 crop).png IndexedColorSample (Lapis.elephant.800pix.060203).png IndexedColorSample (Lemon).png

Transparency in palettes

A single palette entry in an indexed color image can be designated as a transparent color, in order to perform a simple video overlay: superimposing a given image over a background in such way that some part of the overlapped image obscures the background and the remaining not. Superimposing film/TV titles and credits is a typical application of video overlay.

In the image to be superimposed (indexed color is assumed), a given palette entry plays the role of the transparent color. Usually the index number 0, but other may be chosen if the overlay is performed by software. At design time, the transparent color palette entry is assigned to an arbitrary (usually distinctive) color. In the example below, a typical arrow pointer for a pointing device is designed over an orange background, so here the orange areas denoted the transparent areas (left). At runtime, the overlapped image is placed anywhere over the background image, and it is blended in such way that if the pixel color index is the transparent color, the background pixel is kept, otherwise it is replaced.

This technique is used for pointers, in typical 2-D videogames for characters, bullets and so on (the sprites), video titling and other image mixing applications.

Some early computers, as Commodore 64, MSX and Amiga supports sprites and/or full screen video overlay by hardware. In these cases, the transparent palette entry number is defined by the hardware, and it used to be the number 0.

Some indexed color image file formats as GIF natively support the designation of a given palette entry as transparent, freely selectable among any of the palette entries used for a given image.
The BMP file format reserves space for Alpha channel values in its Color Table, [2] however currently this space is not being used to hold any translucency data and is set to zero. By contrast, PNG supports alpha channels in palette entries, enabling semi-transparency in paletted images.

When dealing with truecolor images, some video mixing equipment can employ the RGB triplet (0,0,0) (no red, no green, no blue: the darkest shade of black, sometimes referred as superblack in this context) as the transparent color. At design time, it is replaced by the so-called magic pink. The same way, typical desktop publishing software can assume pure white, RGB triplet (255,255,255) from photos and illustrations to be excluded in order to let the text paragraphs to invade the image's bounding box for irregular text arrangement around the image's subjects.

2-D painting programs, like Microsoft Paint and Deluxe Paint, can employ the user designated background color as the transparent color when performing cut, copy, and paste operations.

Although related (due to they are used for the same purposes), image bit masks and alpha channels are techniques which do not involve the use of palettes nor transparent color at all, but off-image added extra binary data layers.

Software palettes

Microsoft Windows

Microsoft Windows applications manage the palette of 4-bit or 8-bit indexed color display devices through specialized functions of the Win32 API. The applicability of palettes in Highcolor and Truecolor display modes becomes questionable. These APIs deals with the so-called "system palette" and with many "logical palettes".

The "system palette" is a copy in RAM of the color display's hardware registers, primarily a physical palette, and it is a unique, shared common resource of the system. At boot, it is loaded with the default system palette (mainly a "master palette" which works well enough with most programs).

When a given application intends to output colorized graphics and/or images, it can set their own "logical palette", that is, its own private selection of colors (up to 256). It is supposed that every graphic element that the application tries to show on screen employs the colors of its logical palette. Every program can manage freely one or more logical palettes without further expected interference (in advance).

Before the output is effectively made, the program must realize its logical palette: The system tries to match the "logical" colors with "physical" ones. If an intended color is already present in the system palette, the system internally maps the logical to the system palette indexes (because they rarely coincide). If the intended color is not present yet, the system applies an internal algorithm to discard the least-used color in the system palette (generally, one used by another window in the background) and substitutes it with the new color. Due to there being limited room for colors in the system palette, the algorithm also tries to remap similar colors together and will always avoid creating redundant colors.

The final result depends on how many applications are trying to show their colors on screen at the same time. The foreground window is always favored, so background windows may behave in different ways: from become corrupted to quickly redraw themselves. When the system palette changes, the system triggers a specific event to inform every application. When received, a window can quickly redraw itself using a single Win32 API function. But this must be done explicitly in the program code; hence the fact that many programs fail to handle this event, and their windows will become corrupt in this situation.

An application can force the system palette to be loaded with specific colors (even in a specific order), "tricking" the system by telling it they are color entries intended for animation (quick color changes of the colors in the physical palette at specific entries). The system will then assume that those hardware palette entries no longer are free for its palette color management algorithm. The final result depends on the skills of the color-forcing program and the behavior of the other programs (although this problem is the same as in the regular case), and that of the operating system itself.

See also

Notes

Related Research Articles

<span class="mw-page-title-main">GIF</span> Bitmap image file format family

The Graphics Interchange Format is a bitmap image format that was developed by a team at the online services provider CompuServe led by American computer scientist Steve Wilhite and released on June 15, 1987.

<span class="mw-page-title-main">PNG</span> Family of lossless compression file formats for image files

Portable Network Graphics is a raster-graphics file format that supports lossless data compression. PNG was developed as an improved, non-patented replacement for Graphics Interchange Format (GIF)—unofficially, the initials PNG stood for the recursive acronym "PNG's not GIF".

PCX, standing for PiCture eXchange, is an image file format developed by the now-defunct ZSoft Corporation of Marietta, Georgia, United States. It was the native file format for PC Paintbrush and became one of the first widely accepted DOS imaging standards, although it has since been succeeded by more sophisticated image formats, such as BMP, JPEG, and PNG. PCX files commonly store palette-indexed images ranging from 2 or 4 colors to 16 and 256 colors, although the format has been extended to record true-color (24-bit) images as well.

<span class="mw-page-title-main">RGB color model</span> Color model based on red, green, and blue

The RGB color model is an additive color model in which the red, green and blue primary colors of light are added together in various ways to reproduce a broad array of colors. The name of the model comes from the initials of the three additive primary colors, red, green, and blue.

High color graphics is a method of storing image information in a computer's memory such that each pixel is represented by two bytes. Usually the color is represented by all 16 bits, but some devices also support 15-bit high color.

The BMP file format or bitmap, is a raster graphics image file format used to store bitmap digital images, independently of the display device, especially on Microsoft Windows and OS/2 operating systems.

Color depth or colour depth, also known as bit depth, is either the number of bits used to indicate the color of a single pixel, or the number of bits used for each color component of a single pixel. When referring to a pixel, the concept can be defined as bits per pixel (bpp). When referring to a color component, the concept can be defined as bits per component, bits per channel, bits per color, and also bits per pixel component, bits per color channel or bits per sample (bps). Modern standards tend to use bits per component, but historical lower-depth systems used bits per pixel more often.

<span class="mw-page-title-main">RAMDAC</span> Color to analog voltage table

A random-access memory digital-to-analog converter (RAMDAC) is a combination of three fast digital-to-analog converters (DACs) with a small static random-access memory (SRAM) used in computer graphics display controllers or video cards to store the color palette and to generate the analog signals to drive a color monitor. The logical color number from the display memory is fed into the address inputs of the SRAM to select a palette entry to appear on the data output of the SRAM. This entry is composed of three separate values corresponding to the three components of the desired physical color. Each component value is fed to a separate DAC, whose analog output goes to the monitor, and ultimately to one of its three electron guns.

<span class="mw-page-title-main">Transparency (graphic)</span> Capability of a computer graphic to allow whatever is "behind" it to be visible

Transparency in computer graphics is possible in a number of file formats. The term "transparency" is used in various ways by different people, but at its simplest there is "full transparency" i.e. something that is completely invisible. Only part of a graphic should be fully transparent, or there would be nothing to see. More complex is "partial transparency" or "translucency" where the effect is achieved that a graphic is partially transparent in the same way as colored glass. Since ultimately a printed page or computer or television screen can only be one color at a point, partial transparency is always simulated at some level by mixing colors. There are many different ways to mix colors, so in some cases transparency is ambiguous.

<span class="mw-page-title-main">Hold-And-Modify</span> Display mode used in Commodore Amiga computers

Hold-And-Modify, usually abbreviated as HAM, is a display mode of the Commodore Amiga computer. It uses a highly unusual technique to express the color of pixels, allowing many more colors to appear on screen than would otherwise be possible. HAM mode was commonly used to display digitized photographs or video frames, bitmap art and occasionally animation. At the time of the Amiga's launch in 1985, this near-photorealistic display was unprecedented for a home computer and it was widely used to demonstrate the Amiga's graphical capability. However, HAM has significant technical limitations which prevent it from being used as a general purpose display mode.

8-bit color graphics are a method of storing image information in a computer's memory or in an image file, so that each pixel is represented by 8 bits (1 byte). The maximum number of colors that can be displayed at any one time is 256 per pixel or 28.

In computing, indexed color is a technique to manage digital images' colors in a limited fashion, in order to save computer memory and file storage, while speeding up display refresh and file transfers. It is a form of vector quantization compression.

<span class="mw-page-title-main">Color quantization</span>

In computer graphics, color quantization or color image quantization is quantization applied to color spaces; it is a process that reduces the number of distinct colors used in an image, usually with the intention that the new image should be as visually similar as possible to the original image. Computer algorithms to perform color quantization on bitmaps have been studied since the 1970s. Color quantization is critical for displaying images with many colors on devices that can only display a limited number of colors, usually due to memory limitations, and enables efficient compression of certain types of images.

<span class="mw-page-title-main">Tandy Graphics Adapter</span> Computer display standard for the Tandy 1000 series

Tandy Graphics Adapter is a computer display standard for the Tandy 1000 series of IBM PC compatibles, which has compatibility with the video subsystem of the IBM PCjr but became a standard in its own right.

References