unsigned long rgb16_to_rgb32(unsigned short a) {
/* 1. Extract the red, green and blue values */
/* from rrrr rggg gggb bbbb */
unsigned long r = (a & 0xF800) >11;
unsigned long g = (a & 0x07E0) >5;
unsigned long b = (a & 0x001F);
/* 2. Convert them to 0-255 range: There is more than one way. You can just shift them left: to 00000000 rrrrr000 gggggg00 bbbbb000
r <<= 3;
g <<= 2;
b <<= 3;
But that means your image will be slightly dark and off-colour as white 0xFFFF
will convert to F8,FC,F8 So instead you can scale by multiply and divide:
*/
r = r * 255 / 31;
g = g * 255 / 63;
b = b * 255 / 31;
/* This ensures 31/31 converts to 255/255 */
/* 3. Construct your 32-bit format (this is 0RGB):*/
return (r << 16) | (g << 8) | b;
/* Or for BGR0: return (r << 8) | (g << 16) | (b << 24); */
}
RGB16 转换Rgb32
最新推荐文章于 2025-04-15 17:12:31 发布
这篇博客详细介绍了如何将16位RGB颜色值转换为32位格式,涉及颜色通道的提取、范围转换以及构造32位颜色值的过程。通过位运算和比例计算确保了颜色的准确转换,适用于图像处理和显示领域的应用。
1万+

被折叠的 条评论
为什么被折叠?



