I'm trying to convert an image to this following DDS format:
| 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.
I have this python code (using Wand lib):
# 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
The first pixel I get is 64328
but I was expecting 62868
.
Question:
- Is my RGBA to ARGB conversion wrong?
- Why am I not getting the desired result?
The expected output (left) vs the actual output (right) of my code: