📄 bitmap_convert.c
字号:
#include "bitmap_convert.h"/* [RGB565] * 0x00??+1 RRRRRGGG * 0x00??+0 GGGBBBBB * R 5 0xf8 * G 6 0xe0 0x07 * B 5 0x1f *//* [RGB24] * R G B * addr:1 2 3 *//* [RGB32] * 0x00??+3 reserve * 0x00??+2 R * 0x00??+1 G * 0x00??+0 B */// source convertvoid RGB24_to_RGB32(unsigned char *source,unsigned char *convert,int width) { //width:source pic width (pixel) int i; for (i=0 ; i<width ;i++) { *convert++=*(source+2); *convert++=*(source+1); *convert =*source; convert +=2; source +=3; }}void RGB24_to_RGB565(unsigned char *source,unsigned char *convert,int width){/*STEP1(第二个字节) R 取得前5bit & 0xf8 * G 取得前3bit & 0xe0 并右移5bit 并入R;|STEP2(第一个字节) 取得第4-6bit & 0x1c 并左移3bit 并入B * B 取得前5bit & 0xf8 并右移3bit 与G中间3位合并 */ /* R4 R3 R2 R1 R0 G5 G4 G3 G2 G1 G0 B4 B3 B2 B1 B0 * A[] 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 */ int i; for (i=0 ;i<width ;i++) { *(convert+1) = (*source & 0xf8) | ((*(source+1) & 0xe0)>>5); * convert = ((*(source+1) & 0x1c)<<3) | ((*(source+2) & 0xf8)>>3); source +=3; convert +=2; }}void RGB565_to_RGB32(unsigned char *source,unsigned char *convert,int width){/*RGB565 * STEP1(第二个字节) R 取得前5bit & 0xf8 * G 取得前3bit & 0xe0 并右移5bit 并入R;|STEP2(第一个字节) 取得第4-6bit & 0x1c 并左移3bit 并入B * B 取得前5bit & 0xf8 并右移3bit 与G中间3位合并 */ /* R4 R3 R2 R1 R0 G5 G4 G3 | G2 G1 G0 B4 B3 B2 B1 B0 * A[] 15 14 13 12 11 10 9 8 | 7 6 5 4 3 2 1 0 *//* [RGB32] * 0x00??+3 reserve * 0x00??+2 R * 0x00??+1 G * 0x00??+0 B */ int i; for (i=0 ;i<width ;i++) { * convert++ = (*source)<<3; /* B */ * convert++ = (*(source+1) & 0x07)<<5 | (*source & 0xe0)>>3; /* G */ * convert++ = *(source+1); /* R */ convert++; source +=2; }}void RGB565_to_RGB24(unsigned char *source,unsigned char *convert,int width){/*RGB565 * STEP1(第二个字节) R 取得前5bit & 0xf8 * G 取得前3bit & 0xe0 并右移5bit 并入R;|STEP2(第一个字节) 取得第4-6bit & 0x1c 并左移3bit 并入B * B 取得前5bit & 0xf8 并右移3bit 与G中间3位合并 */ /* R4 R3 R2 R1 R0 G5 G4 G3 | G2 G1 G0 B4 B3 B2 B1 B0 * A[] 15 14 13 12 11 10 9 8 | 7 6 5 4 3 2 1 0 *//* [RGB32] * 0x00??+2 R * 0x00??+1 G * 0x00??+0 B */ int i; for (i=0 ;i<width ;i++) { * convert++ = (*source)<<3; /* B */ * convert++ = (*(source+1) & 0x07)<<5 | (*source & 0xe0)>>3; /* G */ * convert++ = *(source+1); /* R */ source +=2; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -