The Forum is up for sale: XeNTaX Forum looking for new owner

Converting argb1555 to RGBA32

Get your graphics formats figures out here! Got details for others? Post here!
Post Reply
finale00
M-M-M-Monster veteran
M-M-M-Monster veteran
Posts: 2382
Joined: Sat Apr 09, 2011 1:22 am
Has thanked: 170 times
Been thanked: 307 times

Converting argb1555 to RGBA32

Post by finale00 »

I have some idea what the format is: 5 bits per pixel, with 1 bit for alpha.
I have to extract the RGBA values from each byte accordingly.

Assuming two bytes B1 and B2 side by side, assuming the following pattern

Code: Select all

A R R R R R G G G G G  B B B B B
So I'd just do some bitmasking

A: B1 & 0b10000000
R: B1 & 0b01111100
G: B1 & 0b00000011 | B2 & 0b11100000
B: B2 & 0b00011111

Or basically

R = B1 & 0x7C
G = B1 & 0x03 | B2 & 0xE0
B = B2 & 0x1F

But then how should I be shifting the bits to get the correct value?

Here is an example of a 640x480 image encoded in ARGB1555
You do not have the required permissions to view the files attached to this post.
MrAdults
Moderator
Posts: 1007
Joined: Mon Mar 23, 2009 2:57 am
Has thanked: 44 times
Been thanked: 505 times

Re: Converting argb1555 to RGBA32

Post by MrAdults »

rgba = rapi.imageDecodeRaw(sourceData, width, height, "a1r5g5b5")
MrAdults
Moderator
Posts: 1007
Joined: Mon Mar 23, 2009 2:57 am
Has thanked: 44 times
Been thanked: 505 times

Re: Converting argb1555 to RGBA32

Post by MrAdults »

Here is a lovely right-click context tool script that will let you decode images from a simple format string:

http://code.google.com/p/noesis-plugins ... wdecode.py

It looks like your image is actually b5g5r5p1, by the way. The p is pad, because that alpha bit is otherwise always 0 in that image, so you just throw it away.
Post Reply