1

So in copy.c the formula for padding is:

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

which I don't quite understand. For example (to my understanding) if the image is 3x3 the padding should be 1 as per the formula but instead I get the following: padding = (4 - (3 * 3) % 4) % 4 = (4 - (9) % 4) % 4 = (4 - 1) % 4 = 3 % 4 = 3 If someone could explain this to me I would greatly appreciate it

2

Remember, each RGB triple is 3 bytes.

If the image is 3 pixels wide, it takes 9 bytes per row. The padding is therefore 3 bytes per row, bringing it to 12.

If you look further down you'll see they write the padding one byte at a time.

| improve this answer | |
  • Thanks for the explanation. – Kim Nov 25 '14 at 13:50
  • How do I know RGB triple is 3 bytes? Is it a fixed value or variable according to the bmp's type? Sorry I can't understand clearly. – Cindy.G Sep 14 '15 at 14:36
  • Cindy-- I know it's a few months late, but I answered your question here: cs50.stackexchange.com/questions/16678/… – Dr.Queso Mar 31 '16 at 6:07

You must log in to answer this question.

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