0

I'm really struggling with resize on pset4. My loop is adding too much padding, I think by a factor of the scale. I'm still working on the horizontal stretch portion of the program. I'm pretty sure my calculated values for old and new padding are correct, based on print debug lines and what I've examined from the staff solutions.

Here's the troublesome loop. Does anybody see a problem with this code?

BTW, headers match great when I used peek on them.

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
    // 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);

        for(int m=0; m<scale; m++)
        {
            // write RGB triple to outfile
            fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);   
        }
    }

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

    // then add it back (to demonstrate how)
    for (int k = 0; k < padding; k++)
    {
        fputc(0x00, outptr);
    }
}

1 Answer 1

0

You currently resize horizontally only.

You need another loop between the first and the second, also executing scale times, in total once per output line (input lines times scale), totalling to four nested loops. You might need to either buffer the content of the input line, or read it multiple times, in which case you need to reset the file cursor to the beginning of the line. You'll need to make sure you write output padding once per output line, and skip padding once per input line (that heavily depends on how you handle resets if you read lines multiple times).

You must log in to answer this question.

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