I would like to know if someone can think about a better solution for doing this stuff.

I have an array of raw bitmap data in 32bit format (RGBA). I need to transform and transpose this array into a 24bit format by eliminating the alpha component.

Additionally I need to transform the data by aligning the red component in the first part of the result array, the green in after the first 1/3 and the blue after the 2/3 because I'm doing a RLE compression after.

By doing this alignment, I have a better compression because there is more chance to have red, green and blue component alignment between pixels.

I'm using unsafe and fixed pointer to do that. I'm getting something like 11ms to process for a 8.3M array length. It seems to be low but I'm doing a realtime screengrabbing and every ms is counting.

(I bypass unsafe and fixed byte* stuff):

byte* actualpointeur = actual == (IntPtr)pd1 ? pd1 : pd2; // it s the pointer on my source 32bit array
// pd24b is a pointeur to my reception array at the right size...
byte* redindexp = pd24b;
byte* greenindexp = pd24b+(datain24format.Length / 3);
byte* blueindexp = pd24b+((datain24format.Length / 3) * 2);
for (int i = 0; i < datalenght; i += 4, actualpointeur+=4, redindexp++, greenindexp++, blueindexp++)
    *redindexp= *(actualpointeur);
    *greenindexp = *(actualpointeur+1);
    *blueindexp = *(actualpointeur+2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.