I’ve started creating a program that is supposed to be able to read a range of different pixel formats. I tested this initially with a simple file in 32-bit RGBA format. I did this fairly simply by rearranging the bytes a bit (read from a BytesInput and write to a BytesOutput), then passing the result as a ByteArray into BitmapData.setPixels().
This works great, only it takes much too long. I mean, it is a fairly large file (2048x2048 pixels, that’s 16777216 bytes), but programs such as TextureFinder manage to do this much faster, switching between different formats quickly.
I’m sure that the issue is in the byte rearrangement, if I comment that out and just read it the data as ARGB directly, it obviously gives weird colours but loads much quicker, no more than a second wait. Rearranging the bytes takes at least 10 seconds, maybe even 20. Admittedly, my machine isn’t very high-end, but other programs still manage to do it much faster.
Here’s my byte handling code:
var out:BytesOutput = new BytesOutput();
out.bigEndian = true;
var input:BytesInput = new BytesInput(bytes);
input.bigEndian = true;
while ((input.position + 4) <= input.length)
{
var rgb:Int = input.readInt24();
var a:Int = input.readByte() << 24;
out.writeInt32(a + rgb);
}
trace("foo");
The variable bytes
is just a Bytes
object of the loaded file. I know that this is the code that takes time because if I comment out the loop then “foo” traces much quicker.
Any suggestions on how to speed this up would be appreciated!