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;
}
}
}