如何在诺基亚 6100 上显示 24 位 RGB 十六进制,而不是 12 位十六进制

发布于 12-17 06:25 字数 224 浏览 7 评论 0原文

我正在使用 Arduino Uno 为诺基亚 6100 LCD 供电。在我的程序中,我采用 RGB 8 位输入,可以使用任何可用的在线转换工具将其转换为 24 位十六进制,我可以处理该转换。然而,我使用的 LCD 库只允许 12 位十六进制。我怎样才能让 LCD 接受 24 位十六进制值而不是 12 位,并在屏幕上获得正确的颜色。或者在这种情况下有没有办法从 24 位十六进制更改为 12 位十六进制?

谢谢, 费兹

I am using Arduino Uno to power a Nokia 6100 LCD. In my program, i take RGB 8 bit input which can be converted to 24 bit Hex using any available online conversion tools, that conversion i can take care of. However, the LCD library i am using only allows 12 bit Hex. how can i get the LCD to accept 24 bit Hex values instead of 12 and get the right colour on the screen. Or is there a way to change from 24 bit Hex to 12 bit hex in this case?

Thanks,
Faiz

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

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

发布评论

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

评论(1

只是我以为2024-12-24 06:25:49

也许 LCD 只能识别 4 位通道?无论如何,这听起来像是库的限制:)

要从 24 位值(3 通道 x 8 位/通道)转换为 12 位值(3 通道 x 4 位/通道),只需缩放将每个通道降低 24 倍——即将每个 8 位通道值 [0-255] 除以 16,以获得 4 中的近似值-少量频道 [0-15]。

现在,考虑一下:对于无符号 2 的补码整数,“除以 16”和“右移 4”(非符号扩展)实际上是相同的。也就是说,底部 4 位只是被“丢弃”。

想象一下这个 24 位值,以位为单位(用 32 位整数填充):

00000000RRRRrrrrGGGGggggBBBBbbbb 

这是目标值(用 16 位整数填充):

0000RRRRGGGGBBBB  // just get rid of the "small letter" bits :)

请注意,这可以通过一系列按位运算来获得:

r12 = (hex24 >> 20) & 0xF
g12 = (hex24 >> 12) & 0xF
b12 = (hex24 >> 4) & 0xF
hex12 = (r12 << 8) | (g12 << 4) | b12

Happy编码。

Perhaps the LCD only understands 4bit channels? In any case, it sounds like that's the limit of the library :)

To convert to a 12-bit value (3 channels x 4 bits/channel) from a 24-bit value (3 channels x 8 bits/channel), just scale down each channel by a factor of 24 -- that is, divide each 8-bit channel value [0-255] by 16 to obtain the approximate value in a 4-bit channel [0-15].

Now, consider this: "dividing by 16" and "shifting right by 4" (non sign-extending) is effectively the same for unsigned 2's complement integers. That is, the bottom 4 bits are just "thrown out".

Imagine this 24-bit value, in bits (padded in 32-bit integer):

00000000RRRRrrrrGGGGggggBBBBbbbb 

And this is the target value (padded in 16-bit integer):

0000RRRRGGGGBBBB  // just get rid of the "small letter" bits :)

And note that this can be obtained with a series of bit-wise operations:

r12 = (hex24 >> 20) & 0xF
g12 = (hex24 >> 12) & 0xF
b12 = (hex24 >> 4) & 0xF
hex12 = (r12 << 8) | (g12 << 4) | b12

Happy coding.

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