代码片段随摘
RGB888转RGB565
#include <stdio.h>
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;
typedef unsigned int uint32_t;
int main(void) {
uint32_t hex888 = 0x0f378e;
uint8_t r8 = (uint8_t)((hex888 >> 16) & 0xFF);
uint8_t g8 = (uint8_t)((hex888 >> 8) & 0xFF);
uint8_t b8 = (uint8_t)(hex888 & 0xFF);
uint16_t rgb565 = ((uint16_t)((r8 >> 3) & 0x1FU) << 11) | ((uint16_t)((g8 >> 2) & 0x3FU) << 5) | (uint16_t)((b8 >> 3) & 0x1FU);
printf("test:0x%04X", rgb565);
// printf("test:%d",1);
return 0;
}