0

can someone point me in the right direction, when I resize small.bmp it works in all instances but check50 doesn't like it when it resizes smaller bmp's. I think maybe it has something to do with my vertical resizing method and fseek but I just don't see it. thanks!

BITMAPFILEHEADER bfNEW = bf;
BITMAPINFOHEADER biNEW = bi;



biNEW.biHeight = n * abs(bi.biHeight);
biNEW.biWidth = n * bi.biWidth;

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


biNEW.biSizeImage = (biNEW.biWidth * sizeof(RGBTRIPLE) + paddingNEW)  * abs(biNEW.biHeight);
bfNEW.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + biNEW.biSizeImage;


// write outfile's BITMAPFILEHEADER
fwrite(&bfNEW, sizeof(BITMAPFILEHEADER), 1, outptr);

// write outfile's BITMAPINFOHEADER
fwrite(&biNEW, sizeof(BITMAPINFOHEADER), 1, outptr);



// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
        // vertical resizing
        for (int r = 0; r < n; r++)
        {
            // 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
                for (int p = 0; p < n; p++)
                {
                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 < paddingNEW; k++)
            {
                fputc(0x00, outptr);
            }

            // reset inptr to start of line for next interation of vert resizing
            fseek(inptr, -(padding + sizeof(RGBTRIPLE) * bi.biWidth), SEEK_CUR);
        }

        //set inptr back to the end of the current scanline for next iteration
        fseek(inptr, (padding + sizeof(RGBTRIPLE) * bi.biWidth), SEEK_CUR);

}

// close infile
fclose(inptr);

// close outfile
fclose(outptr);

// that's all folks
return 0;

}

1
  • I just created a 1x1 pixel, blue bmp and tried testing it as to the specs that check50 tests and they seem to work. Is there something about my code that I'm doing wrong that check50 doesn't like? the first check50 fails are resizing a 1x1 pixel bmp when n = 1, 2 and 3 which it seems to do fine for my test image
    – John
    Jun 4 '16 at 4:19
1
            biNEW.biHeight = n * abs(bi.biHeight);

The sign of the biHeight parameter tells the computer whether to paint the image from top to bottom, or from bottom to top. By applying the abs() function, it changes any negative values to positive. That's breaking your code because the input files use a negative value.

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

You must log in to answer this question.

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