views:

101

answers:

2

I'm porting a DOS game to AS3. I need a way to specifically format my sprite files.

I need to know how to take a 256-colour paletted PNG, and save a (presumably) 32-bit PNG, where all three colour channels are summed to the blue channel only - so all colour information is contained only on the blue channel.

I plan on modifying an AS3 PNG encoder to do this, but I don't know how to specifically calculate the value of each pixel. any help please?

Much appreciated!

+1  A: 

to extract the color info from a pixel

//24bit
var color:uint = 0x336699;
var r:uint = color >> 16;
var g:uint = color >> 8 & 0xFF;
var b:uint = color & 0xFF;

//32bit
var color:uint = 0xff336699;
var a:uint = color >>> 24;
var r:uint = color >>> 16 & 0xFF;
var g:uint = color >>>  8 & 0xFF;
var b:uint = color & 0xFF;

to put it back in a pixel

//24bit
var r:uint = 0x33;
var g:uint = 0x66;
var b:uint = 0x99;
var color:uint = r << 16 | g << 8 | b;

//32bit
var a:uint = 0xff;
var r:uint = 0x33;
var g:uint = 0x66;
var b:uint = 0x99;
var color:uint = a << 24 | r << 16 | g << 8 | b;
TheBrain
A: 

That's brilliant! How do I extract the data from an 8bit image and sum it all to the blue channel of a 24bit image? Nearly there!

Chris
Instead of creating a new answer, can you leave your post as a comment to the other one? It's just as StackOverflow is not a forum, posts are "answers." This does not answer your question. Furthermore, there is random ordering for answers with the same number of votes, and as both answers here *were* 0, this appeared above the actual answer. Don't mean to seem harsh :). Thanks, and welcome to StackOverflow.
Lucas Jones
Thanks, I couldn't find a way to comment on the only answer I got, but I found the comment button to reply to you! I didn't want to 'answer' myself but didn't know how else to respond. I can only see 'link | flag' options.OK, I have a colour uint for an 8bit pixel. how can I modify and save this information as a 24 bit pixel, where the 8 bits of colour information are all saved onto the blue channel only? Thanks, and I didn't think you were harsh at all!
Chris