将RGBA转换为ARGB像素形式

2024-05-12 17:25:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将图像转换为以下DDS格式:

| Resource Format | dwFlags  | dwRGBBitCount | dwRBitMask | dwGBitMask | dwBBitMask | dwABitMask |
+-----------------+----------+---------------+------------+------------+------------+------------+
| D3DFMT_A4R4G4B4 | DDS_RGBA | 16            | 0xf00      | 0xf0       | 0xf        | 0xf000     |

D3DFMT_A4R4G4B4 16-bit ARGB pixel format with 4 bits for each channel.

我有以下python代码(使用Wand lib):

^{pr2}$

{{1}期望的是

问题:

  • 我的RGBA到ARGB的转换错误吗?在
  • 为什么我没有得到预期的结果?在

代码的预期输出(左)与实际输出(右): enter image description hereenter image description here


Tags: 代码图像format格式resourceddsrgbaargb
1条回答
网友
1楼 · 发布于 2024-05-12 17:25:44

根据@MartinBeckett关于scaling down的评论,源像素从8位到4位。我试着寻找如何做到这一点,最后找到了解决办法。在

只需右移4位so8-4=4。最终代码是:

r = blob[x]     >> 4
g = blob[x + 1] >> 4
b = blob[x + 2] >> 4
a = blob[x + 3] >> 4

pixel = (a << 12 | r << 8 | g << 4 | b) & 0xffff

尽管产出与预期产出之间仍有很小的差异。(差额部分)

输出:enter image description here
应输入:enter image description here
来源:enter image description here

相关问题 更多 >