Click to See Complete Forum and Search --> : BI_BITFIELDS masks


Mike Harnad
October 15th, 2004, 02:13 PM
Does anyone know how the three DWORD masks are used when a 16-bit color bitmap uses the BI_BITFIELDS flag? For example, when I look at the "raw" bitmap data, I see x'3806' for a cyan pixel in the bitmap. How do the masks convert this to x'c0c000'? Any takers?

DEmberton
October 19th, 2004, 11:13 AM
If it's 565 format, then it'll be 0xf800, 0x7e0, and 0x1f (r/g/b). If we look at green, in binary it's:

0000011111100000

The 1s are where the colour info is, so first you AND your value to that. Then as there's 5 0s to the right, shift it right 5. As in total there's 6 1s, that means the green value is out of 2^6 = 64 whereas you want it out of 256, so you shift left twice. And then you get the correct value for green.

Can't make it work for your values though, but you didn't say what the exact masks were.

Dave

Mike Harnad
October 19th, 2004, 11:18 AM
DEmberton: thanks for the reply. The masks are indeed as you've indicated. One more note. The bitmap is created by DirectX using D3DXSaveSurfaceToFileInMemory() with a D3DXIFF_BMP flag. If I use the green mask 0x7e0 and apply it to 0x638 (note: 3806 is raw data in bitmap file), I get 620 (or binary 11000100000). Right shifting 5 bits and left shifting 2 bits yields 11000100 which is 0xc4, not 0xc0.