Possible Duplicate:
How to represent 18bit color depth to 16bit color depth?
I'm porting a software that build from 16-bit color depth device to 18-bit color depth device? How can I represent the 18-bit color depth? Thanks.
Possible Duplicate:
How to represent 18bit color depth to 16bit color depth?
I'm porting a software that build from 16-bit color depth device to 18-bit color depth device? How can I represent the 18-bit color depth? Thanks.
NOTE: This is just an edit of my answer to your previous question, since the two are so similar - you just have to reverse the process.
You will first of all have to access each of the colour components (i.e. extract the R value, the G value, and the B value). The way to do this will depend totally on the way that the colour is stored in memory. If it is stored as RGB, with 5-6-5 bits for the components, you could use something like this:
blueComponent = (colour & 0x3F);
greenComponent = (colour >> 6) & 0x3F;
redComponent = (colour >> 12) & 0x3F;
This will extract the colour components for you, then you can use the method outlined above to convert each of the components (I presume 18-bit will use 6 bits per component):
blueComponent = (blueComponent / 64.0) * 32;
//greenComponent = (greenComponent / 64.0) * 64; //not needed
redComponent = (redComponent / 64.0) * 32;
Note that with the above code, it is important that you use 64.0, or some other method that will ensure that your program represents the number as a floating point number. Then to combine the components into your 18-bit colour, use:
colour = (redComponent << 11) | (greenComponent << 5) | blueComponent;