将两位颜色转换为八位颜色

发布于 2024-11-06 21:20:59 字数 772 浏览 5 评论 0原文

我的颜色值有六位,其中红色、绿色和蓝色各占两位。因此黑色将表示为二进制 000000、红色 110000、蓝色 000011、黄色 111100 等等。

我必须将此颜色转换为 24 位 RGB 值才能将其传递到图形层 (DirectFB)。由于3(二进制11)要变成255(0xFF),所以我使用了以下公式,其中85(=255/3)作为转换因子。

r = (color_6bit >> 4) * FACTOR;
g = ((color_6bit >> 2) & 0x3) * FACTOR;
b = (color_6bit & 0x3) * FACTOR;

color_32bit = (r << 16)| (g << 8) | b;

这可以正确转换颜色(白色 [0x3F -> 0xFFFFFF]、红色 [0x30 -> 0xFF0000] 等)。

现在,这些颜色是要在电视上显示的字幕的文本和背景颜色,我们的测试流在视频中嵌入了参考调色板。当我将使用此公式获得的八位颜色绘制到屏幕上时,它与视频中存在的参考颜色并不完全匹配 - 它相当接近,但存在差异。

我是否正确进行了转换,或者是否有任何标准算法可以将两位 RGB 颜色值转换为八位 RGB 值? DirectFB 是否可以在内部使用一些不同的表示形式(例如 RGB565)?

无论如何,当因子 85 替换为 48(通过反复试验找到的值)时,颜色几乎完美匹配。

I've color values coming in six bits, with two bits each for red, green and blue. So black would be represented as binary 000000, red 110000, blue 000011, yellow 111100 and so on.

I have to convert this color into to 24 bit rgb value to pass it to the graphics layer (DirectFB). Since three (binary 11) is to become 255 (0xFF), I used the following formula with 85 (=255/3) as the conversion factor.

r = (color_6bit >> 4) * FACTOR;
g = ((color_6bit >> 2) & 0x3) * FACTOR;
b = (color_6bit & 0x3) * FACTOR;

color_32bit = (r << 16)| (g << 8) | b;

This correctly converts the colors (white [0x3F -> 0xFFFFFF], red [0x30 -> 0xFF0000] and so on).

Now, these colors are text and background colors of captions to be displayed on TV and we have test streams that have reference color palette embedded in the video. When I draw the eight bit colors obtained using this formula on to the screen, it is not exactly matching with the reference color present in the video - it is fairly close, but there is a difference.

Am I doing the conversion correctly or is there any standard algorithm for converting two bit rgb color values to eight bit rgb values? Could DirectFB be using some different representation (like RGB565) internally?

For what it is worth, when the factor 85 is replaced with 48 (value found by trial and error), the colors are matching almost perfectly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

追我者格杀勿论 2024-11-13 21:20:59

我知道的唯一标准是 EGA - wikipedia 上有一个参考。

就其价值而言,6 位空间非常小——只有 64 个值。在 cpu 时间和内存方面进行转换的最快方法几乎肯定只是在大小为 64 的数组中查找值。特别是如果您有测试数据,这非常简单 - 只需从测试数组中的数据。这样您就不必担心它是否是一个标准 - 该标准正是适用于该系统的任何标准。

The only standard I know of is EGA - there's a reference on wikipedia.

For what it's worth, 6 bits is a very small space - only 64 values. The quickest way of doing the conversion in terms of both cpu time and memory is almost certainly just looking up the value in an array of size 64. Especially if you have test data, this is really easy - just put the correct 64 values from the test data in the array. That way you don't need to worry if it is a standard - the standard is exactly whatever works for this system.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文