The correct step formula for bitmap

Surface pitch calculation

In an uncompressed bitmap, the step is the number of bytes needed to go from the beginning of one row of pixels to the beginning of the next row.

Above from the structure is BITMAPINFOHEADER and it makes perfect sense.

The same site provides the following formula for calculating the step:

For uncompressed RGB formats, the minimum step is always the image width in bytes, rounded to the nearest DWORD. You can use the following formula to calculate the step:

stride = ((((biWidth * biBitCount) + 31) and ~ 31) → 3)

Assume an image with a width of 600, a height of 800, and 1bpp

I expect the step to be 600/8 = 75 ... But the above formula gives me 76!

I used (w + 7) / 8and got the expected 75 ...

, Microsoft, - ?

+2
1

75 DWORD. DWORDs - 4 . 76 4.

( DWORD , ). , , , .

+2

All Articles