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

1 Answer 1

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.

3
  • Thanks for the explanation. Commented Nov 25, 2014 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. Commented Sep 14, 2015 at 14:36
  • Cindy-- I know it's a few months late, but I answered your question here: cs50.stackexchange.com/questions/16678/… Commented Mar 31, 2016 at 6:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.