RGB565 Color Picker
Red ⏐ Green ⏐ Blue 1 1 1 1 1 ⏐ 1 1 1 1 1 0 ⏐ 0 0 0 0 0 = 31 ⏐ = 62 ⏐ = 0
((31 << 11) | (62 << 5) | 0) = 65472 = 0xffc0
See also: our RGB565 Color Codes Table.
What is RGB565?
RGB565 (also known as 16-bit RGB) is a color format that uses 16 bits to represent a color, with 5 bits for the red channel, 6 bits for the green channel, and 5 bits for the blue channel. It is used in many display devices, such as LCD screens and computer monitors, to represent a wide range of colors with a limited number of bits. This format is characterized by a smaller color depth than other formats like RGB888, but it is more memory-efficient.
The 5 bits for the red channel can represent 32 different shades of red (2^5 = 32), the 6 bits for the green channel can represent 64 different shades of green (2^6 = 64), and the 5 bits for the blue channel can represent 32 different shades of blue (2^5 = 32). This allows for 32 x 64 x 32 = 65,536 different colors to be represented, which is considerably less than the number of colors that can be represented with other formats like RGB888, which uses 24 bits per pixel and can represent 256 x 256 x 256 = 16,777,216 different colors.
What are the advantages and disadvantages of the RGB565 color format?
The main advantage of RGB565 is that it uses less memory than other RGB color formats like RGB888. For example, a 320 x 240 pixel image in RGB565 would use 320 x 240 x 2 = 153,600 bytes of memory, whereas the same image in RGB888 would use 320 x 240 x 3 = 230,400 bytes of memory. This means that RGB565 images can be stored in less memory (33% less to be precise), which can be beneficial in memory-constrained environments like embedded systems and mobile devices.
A consequence of using less memory is that RGB565 data can be faster to process as there is less data to read and write. This can lead to better performance in real-time applications, such as video games or image processing tasks. Devices using the RGB565 color format may consume less power when rendering and displaying images, as they need to process fewer bits per pixel.
The main disadvantage of RGB565 is that it has a lower color depth than RGB888: RGB565 supports a maximum of 65,536 colors, compared to the 16.7 million colors available in RGB888. This can result in color banding and reduced image quality, especially in images with smooth gradients or subtle color differences.
Why does RGB565 use 6 bits for the green channel but 5 for red and blue?
Splitting 16 bits into 3 parts leaves one extra bit for one channel. RGB565 uses this extra bit for the green channel (for a total of 6 bits) and 5 bits each for the red and blue channels because the human eye is more sensitive to variations in the green channel than in the red or blue channels. This is due to the way the cones in the human eye that detect color are distributed: there are more cones that are sensitive to green light than to red or blue light. By allocating more bits to the green channel, RGB565 can represent more variations in the green color, which results in a more accurate representation of images.
Can I use transparency with RGB565 colors?
No, transparency is not supported in RGB565 since it does not have an alpha channel. If you need to use transparency, you have to use a different color format that has an alpha channel, such as standard RGBA or RGBA 0-1.
How can I convert 24-bit RGB (RGB888) to 16-bit RGB (RGB565)?
- First, extract the red, green, and blue components of the 24-bit RGB888 color value. Each component is an integer between 0 and 255.
- Next, convert each component to a 5 or 6-bit value, depending on whether it corresponds to the red or blue channel (5-bit) or the green channel (6-bit). To do this, divide each component by the maximum possible value in the source format (255) and then multiply the result by the maximum value for that channel in the target format (31 for red and blue, 63 for green).
- Shift the 5-bit red value to the left by 11 bits to make room for the green and blue values, which will be 6 + 5 = 11 bits. The red value will occupy the upper 5 bits of the 16-bit RGB565 value.
- Shift the 6-bit green value to the left by 5 bits to make room for the blue value, which will be 5 bits. The green value will occupy bits 6 to 11 of the 16-bit RGB565 value.
- The blue value does not need to be shifted t the left as it will occupy the lower 5 bits of the RGB565 value.
- Finally, concatenate the red, green, and blue values to create the 16-bit RGB565 color value.
Here's how this can be done in Python 3:
def rgb888_to_rgb565(red8, green8, blue8):
# Convert 8-bit red to 5-bit red.
red5 = round(red8 / 255 * 31)
# Convert 8-bit green to 6-bit green.
green6 = round(green8 / 255 * 63)
# Convert 8-bit blue to 5-bit blue.
blue5 = round(blue8 / 255 * 31)
# Shift the red value to the left by 11 bits.
red5_shifted = red5 << 11
# Shift the green value to the left by 5 bits.
green6_shifted = green6 << 5
# Combine the red, green, and blue values.
rgb565 = red5_shifted | green6_shifted | blue5
return rgb565
print(rgb888_to_rgb565(10, 20, 30)) # => 2212 or 0x8a4
How can I convert 16-bit RGB (RGB565) to 24-bit RGB (RGB888)?
- First, extract the red, green, and blue components of the 16-bit RGB565 color value. Each component is an integer between 0 and 31 for the red and blue channels and between 0 and 63 for the green channel.
- To extract the red component, shift the 16-bit RGB565 value to the right by 11 bits to remove the green and blue values.
- To extract the green component, shift the 16-bit RGB565 value to the right by 5 bits to remove the blue value and then mask the result with 0b111111 (63) to remove the red value by keeping only the lower 6 bits.
- To extract the blue component, mask the 16-bit RGB565 value with 0b11111 (31) to remove the red and green values by keeping only the lower 5 bits.
- Finally, convert each component to an 8-bit value, depending on whether it corresponds to the red, green, or blue channel. To do this, divide each component by the maximum possible value in the source format (31 for red and blue, 63 for green) and then multiply the result by the maximum value for that channel in the target format (255).
Here's how this can be done in Python 3:
def rgb565_to_rgb888(rgb565):
# Shift the red value to the right by 11 bits.
red5 = rgb565 >> 11
# Shift the green value to the right by 5 bits and extract the lower 6 bits.
green6 = (rgb565 >> 5) & 0b111111
# Extract the lower 5 bits.
blue5 = rgb565 & 0b11111
# Convert 5-bit red to 8-bit red.
red8 = round(red5 / 31 * 255)
# Convert 6-bit green to 8-bit green.
green8 = round(green6 / 63 * 255)
# Convert 5-bit blue to 8-bit blue.
blue8 = round(blue5 / 31 * 255)
return red8, green8, blue8
print(rgb565_to_rgb888(3000)) # => (8, 117, 197)