0

I have resized horizontally successfully but am having trouble with vertical resizing. I have done a header check against the staff headers and they are the same so I don't think the problem is there. I've been running my code on smiley because it's a bit easier to see what is going wrong. It seems like my code is printing the entire smiley in each row. I have looked at this so many times and moved the fseek around and I think I am going in circles. It took so much effort to get to this point I feel like I can't see the forest for the trees anymore. Any guidance on what to focus on would be appreciated.

// for each row (iterate over infile's scanlines)
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    // for n-1 times
    for (int copyrows = 0; copyrows <= n; copyrows++)
    {
        // for each pixel in row (iterate over pixels in scanline)
        for (int j = 0; j < bi.biWidth; j++)
        {
            // temporary storage
            RGBTRIPLE triple;

            // read RGB triple from infile
            fread(&triple, sizeof(RGBTRIPLE), 1, inptr);

            // copy pixels along each row
            for (int l = 0; l < n; l++)
            {
                // write pixel to outfile n times
                fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
            }
        }
        // write outfile's padding
        for (int k = 0; k < paddingresize; k++)
        {
            fputc(0x00, outptr);
        }

        // send infile cursor back to the beginning of the scanline
        if (copyrows < (n - 1))
        {
            fseek(inptr, - ((bi.biWidth * sizeof(RGBTRIPLE)) + padding), SEEK_CUR);
        }
    }

// skip over infile padding, if any
fseek(inptr, padding, SEEK_CUR);
}

2 Answers 2

1

Oh my god those fixes did it. Actually thought about the width and height issue right after I posted this question. Thank you so much! This pset has been a real bear for me and I've been going back and forth on all of the components (whodunit, resize and recover) for about three weeks now. So glad to be done with this! Hopefully I can finish recover and move on.

0

I hope bi.biHeight and bi.biWidth represent dimensions of input image, not resized image?

Remove the + padding from the first fseek, you never skipped it, so you don't have to rewind it.

Also, < n instead of <= n.

1
  • Thank you! Trying all of these things now.
    – CM23
    Mar 30, 2018 at 15:01

You must log in to answer this question.

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