Quote:
alfkil wrote:
What is the fastest or most convenient way to turn a bitwise 01-pattern into an alpha map or colored bitmap?
(sorry for all the lame questions)
Process it 4 pixels at a time using a 4-bit Look-Up-Table (LUT).
Something like:
uint32 lut[16] = {
0x00000000,
0x000000FF,
0x0000FF00,
0x0000FFFF,
0x00FF0000,
0x00FF00FF,
0x00FFFF00,
0x00FFFFFF,
0xFF000000,
0xFF0000FF,
0xFF00FF00,
0xFF00FFFF,
0xFFFF0000,
0xFFFF00FF,
0xFFFFFF00,
0xFFFFFFFF,
};
uint8* src = srcBase;
uint32* destRow = destBase;
for(y = 0; y < height; ++y)
{
uint32* dest = destRow;
for(x = 0; x < width/8; ++x)
{
dest[0] = lut[(*src >> 4)];
dest[1] = lut[*src & 0xF];
dest += 2;
++src;
}
destRow += destDWORDSPerRow;
}
NOTES:
- I made up this code just now, and it has NOT been tested
- I cannot remember in what order the pixels are within each byte of a bitplane; the code above may have to be modified to reverse the order if I got it wrong
- Likewise, this code is byte endian-dependent, and so you'd have to adjust the code again if you moved to a little-endian processor.
Hans
Edited by Hans on 2012/3/26 5:45:33
Edited by Hans on 2012/3/26 5:49:39