CreateDIBSection under the hood

1.3k Views Asked by At

I've been using WINAPI CreateDIBSection() to draw pixel by pixel then I bitblt to DC. I'm curious. What is going on with CreateDIBSection's underlying data structures? The BITMAPINFO struct stores the width height of the screen/client. Then the VOID **ppvBits, handles the 24 bit colors. So could this all be looked at as a 3D array? Similar to this

int pixels[height][width][color]?

The reason I ask is this CreateDIBSection() function is very very fast, yet if I create a similar array of (900*1800*(246*256*256)) it is really really slow.

How does Microsoft get this method so fast and efficient? I've tried everything. Int*** pointers to pointer to pointer, int*** malloc, tried NEW etc, they are all very slow on large arrays. I'm just curious how I can construct a 3D array that performs as well. Any thoughts?

I need an array about 20000x1800x100000. CreateDIBSection() stores this swiftly with no problems. But how about a standard C/C++ dynmaic array?

I need to store what's in the CreateDIBSection() and BITMAPINFO in a 2nd array.

1

There are 1 best solutions below

0
On

It doesn't use a 3 dimensional array. It only needs a one dimensional array for colors. You can get X and Y coordinates from the index and knowing the width of the bitmap.

row = index / width;
column = index % width;

For 24 bit color, size of the dib is width * height * 3 bytes (one byte for each color). When it's loaded in memory, it gets padded to 4 bytes (size of integer).

You can use GetDibBits to access bits directly

See also: bitmap format