0

My resize does the work pretty well with the smiley.bmp and small.bmp. Although it fails to pass check50. I've checked my program so many times, the headers are the same as the stuff implementation, so there is no bug.

:) resize.c and bmp.h exist
:) resize.c compiles
:) doesn't resize 1x1-pixel BMP when n is 1
:( resizes 1x1-pixel BMP to 2x2 correctly when n is 2
:( resizes 1x1-pixel BMP to 3x3 correctly when n is 3
:( resizes 1x1-pixel BMP to 4x4 correctly when n is 4
:( resizes 1x1-pixel BMP to 5x5 correctly when n is 5
:( resizes 2x2-pixel BMP to 4x4 correctly when n is 2

I know it was asked so many times, but I still couldn't find the right answer. Getting desperate :(

My code: (I've read the headers also in the biOutput and bfOutput, modified the relevant properties for the new file's header)

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

// iterate over infile's scanlines
for (int i = 0, biHeight = abs(biOutput.biHeight); i < biHeight; i++)
{

    // loop for vertical stretching
    for (int n = 0; n < size; n++)
    {

        // 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 n times
            for (int m = 0; m < size; m++)
            {
                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 < paddingOutput; k++)
        {
            fputc(0x00, outptr);
        }

        // resetting position for vertical resizing
        fseek(inptr, -(bi.biWidth * sizeof(RGBTRIPLE)  + padding), SEEK_CUR);
    }
    fseek(inptr, bi.biWidth * sizeof(RGBTRIPLE) + padding, SEEK_CUR);
}

So, here are the header calculations:

// read infile's BITMAPFILEHEADER in two variables BITMAPFILEHEADER bf;

// bfOutput = the resized file's heade
BITMAPFILEHEADER bfOutput;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);

// setting the cursor to the beginning of inputr, to read the same stuff
fseek(inptr, 0, SEEK_SET);
fread(&bfOutput, sizeof(BITMAPFILEHEADER), 1, inptr);

// read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;

// same as above
BITMAPINFOHEADER biOutput;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);

// setting the cursor after the fileheader
fseek(inptr, sizeof(BITMAPFILEHEADER), SEEK_SET);
fread(&biOutput, sizeof(BITMAPINFOHEADER), 1, inptr);

biOutput.biWidth = biOutput.biWidth * size;
biOutput.biHeight = biOutput.biHeight * size;


// determining the paddign for the large bmp
int paddingOutput =  (4 - (biOutput.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;  

//updating the file and image size info
biOutput.biSizeImage = (biOutput.biWidth * abs(biOutput.biHeight) * sizeof(RGBTRIPLE)) + (paddingOutput * abs(biOutput.biHeight));
bfOutput.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + biOutput.biSizeImage;



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

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

// determine padding for scanlines
int padding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
4
  • Without seeing your actual code I don't think anyone could help you. Consider editing your question and adding the relevant parts.
    – ChrisG
    Commented Sep 25, 2015 at 8:52
  • Yeah, but I don't know which part should I add...
    – Manowar
    Commented Sep 25, 2015 at 8:55
  • That part looks fine...what about your header calculation?
    – Sam Gerber
    Commented Sep 25, 2015 at 9:04
  • Okay, here are the headers:
    – Manowar
    Commented Sep 25, 2015 at 9:07

1 Answer 1

2
for (int i = 0, biHeight = abs(biOutput.biHeight); i < biHeight; i++)

should be

for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
2
  • Thx for the tip, I check it as I get home, this will be my first action :) Stay tuned
    – Manowar
    Commented Sep 25, 2015 at 9:47
  • That was the problem, I just got my eyes over it about 100 times. Thx Sam Gerber
    – Manowar
    Commented Sep 25, 2015 at 21:28

You must log in to answer this question.

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