Jump to content

RGBA color model

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 83.119.136.130 (talk) at 00:12, 29 February 2012 (RGBAX Notation). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Example of a RGBA image with translucent and transparent portions, displayed on a checker background

RGBA stands for red green blue alpha. While it is sometimes described as a color space, it is actually simply a use of the RGB color model, with extra information. The color is RGB, and may belong to any RGB color space, but an integral alpha value as invented by Catmull and Smith between 1971 and 1972 enables alpha blending and alpha compositing. The inventors named alpha after the Greek letter in the classic linear interpolation formula αA + (1-α)B.

The alpha channel is normally used as an opacity channel. If a pixel has a value of 0% in its alpha channel, it is fully transparent (and, thus, invisible), whereas a value of 100% in the alpha channel gives a fully opaque pixel (traditional digital images). Values between 0% and 100% make it possible for pixels to show through a background like a glass (translucency), an effect not possible with simple binary (transparent or opaque) transparency. It allows easy image compositing. Alpha channel values can be expressed as a percentage, integer, or real number between 0 and 1 like RGB parameters.

PNG is an image format that uses RGBA. The terms ARGB, ARGB32, or ARGB8888 are often used, for example, in Macromedia products terminology or the Silverlight framework. The term BGRA may also be seen. This represents the order that the bytes for each channel are actually in memory when ARGB32 data is stored by a little-endian CPU (such as Intel processors).

RGBA pixel formats

In computer graphics, pixels encoding the RGBA Color Space information must be stored in computer memory (or in files on disk), in well defined formats.
In most 32-bit per pixel formats (32bpp), the intensity of each channel sample is defined by 8 bits, and the samples are arranged in memory in such manner that a single 32-bit unsigned integer has the Alpha sample in the highest 8 bits, followed by the Red sample, Green sample and the Blue sample in the lowest 8 bits.
See the diagram below:

Sample layout in a typical 32bpp pixel
Sample layout in a typical 32bpp pixel

Fig.1 – An example of the most common 32bpp pixel layout

ARGB values are typically expressed using 8 hexadecimal digits, with each pair of the hexadecimal digits representing the sample values of the Alpha, Red, Green and Blue channel, respectively. For example, 0x80FFFF00 represents 50.2% opaque (non-premultiplied) yellow. The "0x" prefix is used to identify a number as hexadecimal in C notation. 0x80 represents a 50.2% alpha value, because it is 50.2% of 0xFF (in decimal 128 is 50.2% of 255), the first 0xFF represents the maximum value a red sample can have; the second 0xFF is like the previous but for green; 0x00 represents the minimum value a blue sample can have (effectively – no blue). Consequently red + green yields yellow.

RGBAX Notation

In practice, the samples of Alpha, Red, Green and Blue channels do not have to be arranged as in Fig. 1, nor does the pixel need to consist of 32 bits. Many image file formats allow for arbitrary layout of samples in a pixel and the pixel can consist of various number of bits[1] as long as the Red, Green, Blue and Alpha samples are contiguous and do not overlap. (The unused bits in a pixel can be discontiguous.)

Additionally, not all of the bits in a pixel need to contain samples, which can lead to unused bits in a pixel. The RGBAX notation (a.k.a. Sample Length Notation) is used to describe those pixel formats, including any unused bits.

GUIDELINES

  • The letters R.G.B.A.X signify Red, Green, Blue, Alpha and Unused sample bit lengths, respectively.
  • 5 decimal numbers correspond to the number of bits defining the Red, Green, Blue and Alpha samples as well as any unused bits and these 5 numbers are separated by periods.
  • The sum of the 5 numbers is equal to the total amount of bits needed for pixel storage, a.k.a. Bits per Pixel (bpp).
  • The Red, Green, Blue and Alpha samples must be contiguous and non-overlaping.
  • The unused bits in a pixel can be discontiguous, and their total number is denoted by the 5th number.

A typical RGBA image usually uses all channels to the fullest, so it would be noted as having used 8.8.8.8.0 as RGBAX channels. However, when only 6 of the normal 8 bits are used the sample length would be 6.6.6.6.8 in RGBAX notation. Similarly, when an image uses only half the number of bits of the alpha channel and 10 bits of the blue channel, one would write the sample length as 8.8.10.4.2 in RGBAX notation.[2]

The diagrams below depict some examples of RGBAX notation:

Sample Length Notation (RGBAX) of the most common 32bpp pixel layout
Sample Length Notation (RGBAX) of the most common 32bpp pixel layout

Fig. 2 - An example of the most common 32bpp pixel layout in RGBAX Notation


Sample Length Notation (RGBAX) of a 32bpp pixel layout
Sample Length Notation (RGBAX) of a 32bpp pixel layout

Fig. 3 - An example of a 32bpp pixel layout in RGBAX Notation, with unused bits and uncommon order of the RGB samples


Sample Length Notation (RGBAX) of a 32bpp pixel layout
Sample Length Notation (RGBAX) of a 32bpp pixel layout

Fig. 4 - An unusual example of a 32bpp pixel layout in RGBAX Notation, with unused bits and uncommon order of the RGBA samples


Sample Length Notation (RGBAX) of a 32bpp pixel layout
Sample Length Notation (RGBAX) of a 32bpp pixel layout

Fig. 5 - An example of a 16bpp pixel layout in RGBAX Notation, with unused bits

Note that the RGBAX notation does not differentiate between different orders of samples. So, while the notation does show the unused bits, it doesn't denote anything about way the bits are stored in the file.

In order to differentiate between different sample orders, a numeric subscript can be added to each of the 4 numbers representing the sample bit lengths. This subscript denotes the starting bit number of each sample field, e.g. for Fig. 5 this yields: 36.33.30.49.3
The subscript is not added to the 5th number denoting the total amount of unused bits, since unused bits can be discontiguous. Usually bitmap files are saved with the X channel first, then the alpha channel and so on (XABGR), but this can differ between implementations.

See also

References