0

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.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
  • What exactly are you saying is "really really slow"? The allocation? Using the memory in some way? Except in some specialised cases (like with DirectX copying from video to system RAM), memory is generally memory - whether allocated by `CreateDIBSection` or by `malloc`. – Jonathan Potter Jul 07 '15 at 21:38
  • You're allocating too much memory. A similar array would be 900*1800*3, since for each pixel you have 3 bytes (4 if you have alpha, plus some bytes at the end of each row for alignment). It's not a 3D array, it's a 2D array of color values. – Fabio Ceconello Jul 07 '15 at 23:27

1 Answers1

1

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

Community
  • 1
  • 1
Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77