1

This code here:

// determine padding for scanlines

int padding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

is the second %4 necessary? wouldn't

int padding =  4 - bi.biWidth * sizeof(RGBTRIPLE) % 4;

give the same result?

2

Yes, it is necessary, and no, the second formula wouldn't produce the correct result.

The reason for the second %4 is to cover a corner case. If (bi.biWidth * sizeof(RGBTRIPLE) ) %4 = 0, then 4-0 = 4. But you can't have padding of 4. Applying the second %4 does nothing to 1, 2, or 3, but will change 4 to 0. (BTW, you'll never have 0 before applying the second %4.)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .