Multiplexing bitplanes into bytes
This may be more appropriate in the Game Programming forum, but anyway...
I've written some code that reads in bits from 4 seperate bitplanes and multiplexes them into bytes, i.e. the upper half of the first byte contains the first bits from the bitplanes, the lower half the second bits, etc.
The thing is, it's not terribly fast. Running this on a 2 GHz Pentium 4, CPU usage of up to 98% is observed when bmpBitmap describes a set of 640x480 bitplanes and the code is executed 60 times a second.
// inputs: unsigned char *lpBuffer, bitmap_t *bmpBitmap
int i, j, iMaskShift = 7, iShift = 4, iSize;
unsigned char *lpPointers, ucColour, ucSourceMask = 0x80, ucDestMask = 0xF;
// setup pointers
lpPointers[i] = bmpBitmap->lpPlanes[i];
iSize = bmpBitmap->sWidth * bmpBitmap->sHeight;
ucColour = 0;
ucColour |= ((*lpPointers[j] & ucSourceMask) >> iMaskShift) << (j + iShift);
*lpBuffer = (*lpBuffer & ucDestMask) | ucColour;
ucDestMask = ~ucDestMask;
iShift = 0;
iShift = 4;
ucSourceMask >>= 1;
iMaskShift = 7;
ucSourceMask = 0x80;
Could anyone suggest some performance enhancements?