RGB24 Mutual Turn RGB565

Source: Internet
Author: User

RGB24 Mutual Turn RGB565

width and height are the height and width of the image

Conversion of 24bit RGB888-> 16bit RGB565

24IBT RGB888 R7 R6 R5 R4 R3 R2 R1 R0 G7 G6 G5 G4 G3 G2 G1 g0b7 B6 B5 B4 B3 B2 B1 B0

16bit RGB565 R7 R6 R5 R4 R3 G7 G6 G5 G4 G3 g2b7 B6 B5 B4 B3

Rgb24 = (unsignedchar*) malloc (width*3);
Rgb16 = (unsigned short*) malloc (width*height*2);
static void rgb24_to_rgb565 (__u8 *rgb24, __u8 *rgb16)
{
int i = 0, j = 0;
for (i = 0; i < width*height*3 i + + 3)
{
RGB16[J] = Rgb24[i] >> 3; B
RGB16[J] |= ((rgb24[i+1] & 0x1c) << 3); G
RGB16[J+1] = rgb24[i+2] & 0xf8;//R
Rgb16[j+1] |= (rgb24[i+1] >>5); G
J + + 2;
}
}

Conversion of 16bit RGB565-> 24bit RGB888

16bit RGB565 R4 R3 R2 R1 R0 G5 G4 G3 G2 G1 g0b4 B3 B2 B1 B0

24IBT RGB888 R4 R3 R2 R1 R0 R2 R1 R0 G5 G4 G3 G2 G1 G0 G1 g0b4 B3 B2 B1 B0 B2 B1 B0

Rgb24 = (unsignedchar*) malloc (width*3);
Rgb16 = (unsigned short*) malloc (width*height*2);
static void Rgb565_to_rgb24 (__u8 *rgb16, __u8 *rgb24)
{
int x = 0, y = 0;
/* RGB565-> RGB888, Compress * *
for (y = 0; y < height; y++)
{
for (x = 0; x < width/x + +)
{
* (rgb24 + x*3+0) = (* (rgb16 + y*width + x) & 0xf800) >> 8 & 0xFF;
* (rgb24 + x*3+1) = (* (rgb16 + y*width + x) & 0x07e0) >> 3 & 0xFF;
* (rgb24 + x*3+2) = (* (rgb16 + y*width + x) & 0x001f) << 3 & 0xFF;
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.