How to calculate bitmap stride?

Using IWICBitmap->CopyPixels() I must specify the bitmap stride. It's supposed to be (width * (bitsperpixel / 8)) + padding. Is it safe to assume there is no padding ever, or how do I know how many bytes of padding there are?
Is it safe to assume there is no padding ever,


No.

The padding must push the pixels up to a DWORD boundary (1 DWORD = 4 bytes).

Calculation:
1
2
3
4
5
6
7
8
9
// width = width in pixels
// bpp = BITS per pixel.  Ex:  bpp=24 would be 3 bytes per pixel

int stride = width*bpp;  // bits per row
stride += 31;            // round up to next 32-bit boundary
stride /= 32;            // DWORDs per row
stride *= 4;             // bytes per row

// done 
Topic archived. No new replies allowed.