Skip to main content
GameDev.net gamedev.net
🔒 Locked

16 bit color conversion

Started by square2 Apr 12, 2001 at 4:28 AM 4 replies 750+ views
Original Post
square2
square2
how can i convert my r,g,b,a values in an 16 bit A4R4G4B4 format?
JOL
JOL
What exactly do you mean by convert ?!? to what ?

you can get the r,g,b,a separated like this...
int16 = rgba; // this is the initial value

a = (rgba >> 12);
r = (rgba >> 8) & 0xF;
g = (rgba >> 4) & 0xF;
b = rgba & 0xF;

you now have the values separated, now you need to scale it to whatever you want (4 bit or 32 bit or whatever)....

maybe I didn't get your question right ?


Edited by - JOL on April 12, 2001 6:21:08 AM
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work
square2
square2
ive got the seperated rgba values but i need an
int16 to draw them in the surface
lakibuk
lakibuk
i wrote a short c/c++ function which solves this 16bit color problem, it is very common. email me if you want me to send it to you. but i can''t answer before saturday.
square2
square2
pleaaaaaaassssssseeeeeee heeeeeeeelllllppppppp
JOL
JOL
this is how you could make a single 16 bit int from 4 4bit values...

int16 makeARGB16(uint16 a, int16 r, int16 g, int16 b)
{
return a<<12 | r<<8 | g<<4 | b;
}

this will work - if your values are alredy of 4bit magnitude - meaning they are not greater than 15

if you need them in some other order, just exchange the variable names in the return row ...



Edited by - JOL on April 12, 2001 5:08:47 PM
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~I'm looking for work

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.