0

I'm one of the less comfortable and this problem set is giving me fits. I finally got my code to resize the image small.bmp but the output is really distorted multi colored lines where the original was an all green square... Any help is appreciated. check50 passes all but the factor of 4 checks! code to follow:

[code hidden. please do not post code publicly per the academic honesty policy]

0

are you sure this line is correct?

fseek(inptr, (width + padding_infile) * sizeof(RGBTRIPLE), SEEK_CUR);

are you sure you wanna seek forward (width + padding_infile) * sizeof(RGBTRIBLE)?

also are you sure you're calculating the padding of the output file correctly? 'cause it looks like if bi_new.biWidth is a multiple of 4, then

(4 - (bi_new.biWidth * sizeof(RGBTRIPLE) % 4) % 4);

is gonna be evaluated to 4 where it should be evaluated to 0.

5
  • I thought I had the outfile padding formula adjusted correclty. am I wrong that by creating bi_new.biWidth I am accounting for the adjustment in size already?
    – George
    Dec 6 '15 at 8:14
  • Also, I might not understand fseek the way I thought I did. If at the end of the for loop for writing each pixel I am located at the end of the width (prior to the padding) and then fseek back to the beginning of the line, then I am now essentially at the beginning of the origninal line. I now iterate through the loop and want to move on to the next line so it would seem that I need to skip the line I already wrote (which I am now at the beginning of due to the last fseek) in order to write the next line. am I all kinds of confused?
    – George
    Dec 6 '15 at 8:19
  • @George the reason we need a padding is to pad each scanline so that its size is a multiple of 4. if the size of a scanline is a multiple of 4 already without padding, the padding should be 0 in this case.
    – kzidane
    Dec 6 '15 at 9:03
  • @George you do seem to understand fseek and use it correctly where you should! the problem is that you are not seeking forward the correct amount of bytes in the line shown in the answer. are you sure you want padding_infile to be multiplied by sizeof(RGBTRIBLE)?
    – kzidane
    Dec 6 '15 at 9:07
  • Kareem, thanks for the help. I'm still a little messed up on the padding but the fseek function makes more sense now. I'm now resizing small.bmp correctly with several different values for n, but I'm not passing check50. hopefully I can figure it out this afternoon when my daughter is napping... baby plus math = no bueno
    – George
    Dec 6 '15 at 13:57

You must log in to answer this question.

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