Im going through a tutorial and ive come across a variable thats declared called bytePerRow and i understand that it attempts to store the total bytes in the row if image data but i dont understand the calculation used.
The (( width * 3 + 3 ) / 4 ) * 4 is rounding up to the nearest word (32-bit) boundary.
Suppose you want to round an integer UP to the next 10. Ie, 17 becomes 20,
11 becomes 20, 10 becomes 10, etc.
The trick to doing this is to take the number and add 9, then divide by 10.
So for example, 17 + 9 = 26 / 10 = 2; 11 + 9 = 20 / 10 = 2; 10 + 9 = 19 / 10 = 1.
Since you divided by 10, you then have to multiply by 10.
That's what the first part of above code is doing: it is rounding UP to the next 4.
It takes advantage of integer division to drop the remainder.