Working with DIB sections, which is the fastest : 16, 24 or 32 bit color depth DIB?
Posted on 2004-04-04 07:58:02 by Vaxon
I have always assumed that 32 bit DIB sections are fastest, since the colour bits are aligned on a natural DWORD boundary. I have not tested this theory but it makes sense so I always use 32 bit. It also makes it easier to modify it directly in memory, bypassing the GDI, as claculating the offset to a particular pixel requires less calculation.
Posted on 2004-04-04 14:09:57 by donkey
32bpp is also one of the easiest formats to work with. 24bpp is yucky because it's not aligned, 15/16bpp requires messing around with bitmasks, and 8bpp involves palette stuff.

There's also memory comsumption (and bus bandwidth) to consider, and possible color conversion.

I personally like 32bpp myself, because it's very easy to work with :)
Posted on 2004-04-04 16:57:34 by f0dder
I always work with 16bpp... You can work with 2 pixels at once and its aligned too when you do that. Though 32-bit is most popular, you can also use MMX on it
Posted on 2004-04-04 17:53:06 by comrade
I have used 1bpp planes and palletised 8bpp maps, too. It all depends on what you are doing. If you mean fastest in how the OS/hardware deal with the data then that too depends on many factors!
Posted on 2004-04-04 22:24:02 by bitRAKE
Thanx, guys. Does anyone know why the color format for an RGB DIB section is really Blue-Green-Red instead of Red-Green-Blue? What's the catch? Or was it made to confuse everyone?
Posted on 2004-04-05 03:17:53 by Vaxon
Because Intel stores numbers in reverse byte order so RGBA is actually stored as the DWORD ABGR.
Posted on 2004-04-05 06:33:21 by donkey
The COLORREF values are stored as 0xaabbggrr, i.e. the least significant byte is rr (red), but values in a 32-bit DIB section are stored as 0x00rrggbb, which means that (bb) blue is the least significant byte. So Intel architecture has nothing to do with that, because only red and blue bytes are swapped.
Posted on 2004-04-05 07:10:43 by Vaxon
COLORREF does not use the Alpha channel it is 0BGR not ABGR, the bits are just shifted.


The low-order byte contains a value for the relative intensity of red; the second byte contains a value for green; and the third byte contains a value for blue. The high-order byte must be zero. The maximum value for a single byte is 0xFF.

Anyway, a DIB does not use COLORREF, it uses RGBQUAD structures:

RGBQUAD struct

rgbBlue db ?
rgbGreen db ?
rgbRed db ?
rgbReserved db ?
Posted on 2004-04-05 08:37:17 by donkey
I just wanted to say that swapping rgbRed and rgbBlue members of RGBQUAD would make it easier to map COLORREF to RGBQUAD structure. So I can't understand why grbBlue in RGBQUAD structure goes first.
Posted on 2004-04-06 03:27:43 by Vaxon
Oh well, I have stopped questioning why MS chose to do things a certain way, why for example is GRPICONDIRENTRY 2 bytes shorter than ICONDIRENTRY ? Just compensating for those 2 bytes adds extra code to icon extraction as you have to keep separate counters when doing it, they could just as easily have added 2 bytes of padding to the resource section entry. There are any number of examples, the standards came at different times for different reasons.
Posted on 2004-04-06 04:41:28 by donkey