一个人怎么转换16位RGB565 24位RGB888?个人

2023-09-11 01:44:09 作者:ζ滥情空心

我有一个16位的RGB565图像(具体地讲,一个Android的framebuffer转储)我的手,我想将其转换为24位RGB888观看普通显示器上。

I’ve got my hands on a 16-bit rgb565 image (specifically, an Android framebuffer dump), and I would like to convert it to 24-bit rgb888 for viewing on a normal monitor.

的问题是,一个人如何转换的5或6位信道,以8位?答案显然是来接班。我开始写这样的:

The question is, how does one convert a 5- or 6-bit channel to 8 bits? The obvious answer is to shift it. I started out by writing this:

puts("P6 320 480 255");
uint16_t buf;
while (read(0, &buf, sizeof buf)) {
    unsigned char red = (buf & 0xf800) >> 11;
    unsigned char green = (buf & 0x07e0) >> 5;
    unsigned char blue = buf & 0x001f;
    putchar(red << 3);
    putchar(green << 2);
    putchar(blue << 3);
}

不过,这并不有一个属性,我想,这是 0xFFFF的映射到 0XFFFFFF 而不是 0xf8fcf8 。我需要扩大在某些​​方面的价值,但我不知道怎么说应该工作。

However, this doesn’t have one property I would like, which is for 0xffff to map to 0xffffff, instead of 0xf8fcf8. I need to expand the value in some way, but I’m not sure how that should work.

Android SDK中自带的工具称为DDMS(Dalvik的调试监视器),它的屏幕捕获。据我可以告诉reading在code ,它实现了同样的逻辑;但是它的屏幕截图现身不同,而白色则映射为白色。

The Android SDK comes with a tool called ddms (Dalvik Debug Monitor) that takes screen captures. As far as I can tell from reading the code, it implements the same logic; yet its screenshots are coming out different, and white is mapping to white.

这里是原始帧缓冲的的由DDMS智能转换和哑转换 。需要注意的是,后者是稍暗,更环保。

Here’s the raw framebuffer, the smart conversion by ddms, and the dumb conversion by the above algorithm. Note that the latter is slightly darker and greener.

(顺便说一句,这种转换在ffmpeg的,但它只是执行上面列出的哑转换,使最低有效位都为零。)

(By the way, this conversion is implemented in ffmpeg, but it’s just performing the dumb conversion listed above, leaving the LSBs at all zero.)

我想我有两个问题:

什么是最明智的方式转换成RGB565到RGB888? 如何DDMS将其截图?

推荐答案

您可能会改变,然后或用最显著位;即。

You could shift and then or with the most significant bits; i.e.

Red 10101 becomes 10101000 | 101 => 10101101
    12345         12345---   123    12345123

这有你所寻求的属性,但它不是值从一个空间到另一个最线性映射。它速度快,虽然。 :)

This has the property you seek, but it's not the most linear mapping of values from one space to the other. It's fast, though. :)

克莱图斯的回答是更完整,可能会更好。 :)

Cletus' answer is more complete and probably better. :)

 
精彩推荐
图片推荐