0

So I'm struggling a bit with pset4. My resize program results in an outfile that is the correct size with an n of 4 (I used the xxd command to compare with large.bmp) so I don't think it's a header issue. But instead of having white pixels in the middle it's just completely green. I believe I am doing something wrong with the padding but I can't figure out why!

Here's the relevant parts of my code:

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

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

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

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

        // adding outfile padding
        for (int m = 0; m < newPadding; m++)
        {
            fputc(0x00, outptr);
        } 

        fseek(inptr, abs(bi.biWidth) * sizeof(RGBTRIPLE) + padding, SEEK_CUR); 

    } 

}
2
  • You left out the most important lines of code. How do you calculate the input padding size and the output padding size? Next, is the final fseek above supposed to rewind back to the start of the current line so you can reprocess it for vertical expansion? If so, it looks like it's moving forward and not backward like it should.
    – Cliff B
    Jul 31 '15 at 5:02
  • Hey, thanks for the response! Indeed, my fseek was moving forward instead of backward. I tweaked that a bit and now my program works :)
    – lrzhou
    Jul 31 '15 at 5:09
0

So, let's close out the question:

The final fseek above is supposed to rewind back to the start of the current line so you can reprocess it for vertical expansion? If so, it looks like it's moving forward and not backward like it should.

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)

You must log in to answer this question.

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