I've been stuck on this problem for days now, my problems arrise from the following:

1- I have no idea how to implement padding

2- I have no idea where the vertical loop would go

3- I have no idea how to rewind the infile cursor ( I tried fseek using a start point and SEEK_SET)

I scratched my code to the bits that "work" and I was left with this

// determine padding for scanlines
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;

// Changing header info to match resize
bi.biWidth *= resize;
bi.biHeight *= resize;
int Newpadding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
bi.biSizeImage = ((sizeof(RGBTRIPLE) * bi.biWidth) + Newpadding) * abs(bi.biHeight);
bf.bfSize = bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);


 for (int i = 0, biHeight = abs(bi.biHeight)/resize; i < biHeight; i++)
    // iterate over pixels in scanline
    for (int j = 0; j < bi.biWidth/resize; j++)
        // temporary storage
        RGBTRIPLE triple;

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

        // write RGB triple to outfile
        for (int a = 0; a < resize; a++)
            fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);

I figured it out!

1- Padding depends on how you implement rows, the examples on copy.c should suffice

2- Vertical loop goes between i & j

3- You go back like this

fseek(inptr, -(bi.biWidth * sizeof(RGBTRIPLE)), SEEK_CUR);
  • I've been stuck on the vertical part of this problem for some time as well. I know that the vertical loop goes between i & j, but in the walkthrough's psuedocode it appears that even in the vertical loop there is stuff happening inside j, and when I try to implement this, it breaks what was working with the horizontal. I understand each individual step of the pseudocode (at least for 'rewrite', recopy is another matter entirely), but when I try to implement it it does work. Apr 18 '18 at 7:21

You must log in to answer this question.

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