4

I'm stuck since a while in the 'resize' task. Don't fully get my head around the padding.

// read scanline pixel/pixel from infile

// write pixels to outfile

// skip padding

// add padding back

1) My understanding is that lines are executed in order. Why would I position 'skip padding' only after the reading and writing commands as it happens in copy.c?

2) given '00ff00 ffff 00ff00 0000 00ff00 ffff 00ff00 0000': fseek skipps over every 0000 and continue from the following 00ff00 ?

3) Is the skipped padding stored somehow or is it necessary that fputc() follows immediately after the fseek() command?

Hope my questions make sense.

Best Wishes

1 Answer 1

2

1) My understanding is that lines are executed in order. Why would I position 'skip padding' only after the reading and writing commands as it happens in copy.c?

you could also position it after add padding but it doesnt matter point is ultimately you want to skip padding so you dont read the padding and hence write it in your new file because your old padding does not have be the same as your new one

2) given '00ff00 ffff 00ff00 0000 00ff00 ffff 00ff00 0000': fseek skipps over every 0000 and continue from the following 00ff00 ?

yes from what I understood fseek only skips the padding. I hope you knew that it doesnt really know that 0000 is padding. It actually calculated what the padding was previously and calculated let say 2 bytes and skips 2 bytes

3) Is the skipped padding stored somehow or is it necessary that fputc() follows immediately after the fseek() command?

It has always existed in the old file. So it was always stored. And again as I said you could have fputc before and then skip padding it doesnt matter so as long as you dont make the mistake of reading the old padding

4
  • I didn't fully understand answer 2. So in other words it could also skip ffff in certain cases. As this happened to me when checking with xxd.
    – gado007
    Commented Sep 5, 2015 at 18:34
  • exactly if your formula for calculating padding is wrong. It doesnt know if 0000 is padding. You calculated the padding and told it padding is x bytes if your formula is wrong and your padding is larger than it needs to be it will skip your real image as well Commented Sep 6, 2015 at 2:06
  • What I did to calculate the new Padding, was switching bi.biWidth with bi_new.biWidth in the formula provided in copy.c. Thanks for your explanation!
    – gado007
    Commented Sep 6, 2015 at 6:28
  • no problem happy to help Commented Sep 6, 2015 at 10:16

You must log in to answer this question.

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