0

My code passes the simple scale-by-1 test, but when trying to scale-by-2 the size doubles properly but the image is wonky. Here is what my code is doing to the large.bmp image from the pset:

enter image description here

I suspect something is off with the writing-to-outfile iterations, I've tried switching up nested loops, like moving the padding outside of the first //iterate m times for loop...nothing seems to work, and it looks like I have the correct iterations to scale the file vertically and horizontally, but the scaled image is funky.

Any ideas?

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

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

        } 

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

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

// close outfile
fclose(outptr);

// that's all folks
return 0;
0

It looks like you're processing each horizontal line m times (correct thing to do), but you are forgetting to reset the input file pointer to the beginning of each line before reprocessing it after the first time.

If this answers your question, please click on the check to accept. Let's keep up on forum housekeeping. ;-)

1
  • Yes, that solved my wonky image issues, and thank you!! – Tony Burroughs Oct 8 '15 at 4:41

You must log in to answer this question.

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