RGB

The RGB pixel formats are probably the best known pixel formats. In these formats, the representation follows the color model of light, which is why this model is usually also used on screens.

Published on 12/06/2015, updated on 03/25/2019

The RGB pixel formats are probably the best known pixel formats. In these formats, the representation follows the color model of light, which is why this model is usually also used on screens. The color is formed from the RGB color model, consisting of the components red, green and blue, which represent the color channels in this model.

The basic colour, i.e. the very first colour in the model, is black. Only by adding at least one of the 3 colors another color is created. If all 3 color channels are balanced (i.e. have the same value), the result is a gray tone of different brightness, up to white.

The RGB pixel format therefore uses additive color mixing.

For example, the following pixel formats result from the channels:

Pixel format red channel green channel blue channel resulting color depth
RGB161616 / RGB48 16 Bit
0 - 65535
16 Bit
0 - 65535
16 Bit
0 - 65535
48 Bit
281.474.976.710.656 Colors
RGB121212 / RGB36 12 Bit
0 - 4095
12 Bit
0 - 4095
12 Bit
0 - 4095
36 Bit
68.719.476.736 Colors
RGB888 / RGB24 8 Bit
0 - 255
8 Bit
0 - 255
8 Bit
0 - 255
24 Bit
16.777.216 Colors
RGB565 5 Bit
0 - 31
6 Bit
0 - 63
5 Bit
0 - 31
16 Bit
65.536 Colors
RGB555 5 Bit
0 - 31
5 Bit
0 - 31
5 Bit
0 - 31
15 Bit
32.768 Colors
RGB444 4 Bit
0 - 15
4 Bit
0 - 15
4 Bit
0 - 15
12 Bit
4.096 Colors
RGB222 2 Bit
0 - 3
2 Bit
0 - 3
2 Bit
0 - 3
6 Bit
64 Colors
BGR844 4 Bit
0 - 15
4 Bit
0 - 15
8 Bit
0 - 255
16 Bit
65.536 Colors

As you can see, pixel formats usually show the order of the color channels first - and then the depth of the color channels in bits.

ARGB / RGBA / BGRA / ABGR formats are also often seen. But the A is not a color in the actual sense:
With these an alpha channel is added, which does not represent an own color, but takes up the information about how transparent the appropriate position is to be drawn.
Accordingly, an ARGB1555 format contains 1-bit information about transparency as well as 5 bits per color channel.

In the real world, the RGB888, ARGB8888, RGB565, RGB555 and ARGB1555 formats are common.
Often the green channel gets a higher weighting, if space is available, because the eye can see finer nuances on this color channel.

For illustration, here are the 3 Mario colours in different RGB formats:

Color Pixel format red green blue hexadecimal representation
red RGB888 177
69.4%
52
20.3%
37
14.5%
B13425
RGB565 22
70.9%
13
20.6%
4
12.9%
160D04
RGB555 22
70.9%
6
19.3%
4
12.9%
160604
RGB444 10
66.6%
3
20.0%
2
13.3%
A32
yellow RGB888 228
89.4%
158
61.9%
37
14.5%
E39D25
RGB565 28
90.3%
39
61.9%
4
12.9%
1C2704
RGB555 28
90.3%
19
61.2%
4
12.9%
1C1304
RGB444 13
86.6%
9
60.0%
2
13.3%
D92
ochre RGB888 106
41.5%
107
41.9%
4
1.5%
6A6B04
RGB565 13
41.9%
26
41.2%
0
0.0%
0D1A00
RGB555 13
41.9%
13
41.9%
0
0.0%
0D0D00
RGB444 6
40.0%
6
40.0%
0
0.0%
660

The inclined observer may notice
HTML and CSS use either RGB888 (24 bit) or RGB444 (12 bit) in hexadecimal representation.

The percentages (which result from color value / channel circumference * 100) also show how color data can be converted in the individual color depths:

colorTarget = round(colorOriginal / channel sizeOriginal * channel sizeTarget)

Whereby the color range corresponds to the value (2depth of the color channel - 1). Please note this if it is not obvious:
A color can be converted without loss of quality into a color depth that corresponds to a multiple of the original color channel. If you deviate from this, information is inevitably lost.

Specifically: a 4-bit channel can be converted into an 8-bit channel without any problems. If you convert it into a 6-bit channel, there is a certain probability of losses because you have to use approximations. However, these losses do not necessarily have to be immediately visible. If the image were to be converted back, however, the exact same image would no longer be produced.
Similarly, losses occur when the 8-bit channel is converted into a 4-bit channel - but these are more noticeable here.

The rounding reduces the loss of quality. If you floor the value, i.e. cut / ignore the decimal digits - or calculate with integers - the quality loss would be drastic depending on the pixel format:

Therefore, always pay attention:
Even if it is expensive, it is definitely worth working with decimal places, i.e. fixed point / floating point, for the conversion. Since you usually don't have to convert color channels in real time, this should be a negligible problem.

Usually, the individual color channels are stored in combination.
This can be achieved as follows:

color value = (red << green color depth << blue color depth) & (green << blue color depth) && blue

for an RGB variant, or

color value = (blue << greenColor depth << redColor depth) & (green << blueColor depth) && red

for a BGR variant, where the xxxcolor depth variants correspond in any case to the channel depth in bits.
<< denotes an operator that shifts a data value to the left by a certain number of bits.

Please note:
The character Super Mario is in character and representation intellectual property of the company Nintendo and protected worldwide in many countries accordingly.
The graphic was used for illustrative and educational purposes in the sense of Fair Use.

comments

add a comment

Your comment may not be displayed immediately and will be moderated for spam prevention reasons.