0
我試圖將圖像轉換爲這個以下DDS格式:針對每個信道的4位轉換RGBA到ARGB像素格式
| Resource Format | dwFlags | dwRGBBitCount | dwRBitMask | dwGBitMask | dwBBitMask | dwABitMask |
+-----------------+----------+---------------+------------+------------+------------+------------+
| D3DFMT_A4R4G4B4 | DDS_RGBA | 16 | 0xf00 | 0xf0 | 0xf | 0xf000 |
D3DFMT_A4R4G4B4 16位ARGB像素格式。
我有(使用法杖LIB)這個Python代碼:
# source is jpeg converted to RGBA format (wand only supports RGBA not ARGB)
blob = img.make_blob(format="RGBA")
for x in range(0, img.width * img.height * 4, 4):
r = blob[x]
g = blob[x + 1]
b = blob[x + 2]
a = blob[x + 3]
# a=255 r=91 g=144 b=72
pixel = (a << 12 | r << 8 | g << 4 | b) & 0xffff
第一像素我得到的是64328
但我期待62868
。
問:
- 是我的RGBA到ARGB轉換錯了嗎?
- 爲什麼我沒有得到想要的結果?
將R,G,B值是在字節(8位),則需要按比例下來,4位(0-16 )在重新組裝像素之前。 –
ps如果你這樣做是爲了與圖像一起工作,而不僅僅是作業練習使用opencv(import cv2)它更快更容易 –
@MartinBeckett謝謝,最後想通了。雖然似乎有一點區別,但在產出和預期產出方面存在非常細微的差異。 – majidarif