2

My resize for pset4 finally worked and I can resize the small.bmp (that green square) properly. however it doesn't work for all the check50 requirements(except for compiling and running) and i don't know why. Here is my "peek" data for n = 3. Can anyone help me please? There is the results for comparing to the staff solution. enter image description here

and here are my codes for padding

//resize header
    bi_big.biWidth = bi.biWidth * n;
    bi_big.biHeight = bi.biHeight * n;

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

    //resize header
    bi_big.biSizeImage = (bi_big.biWidth + padding) * abs(bi_big.biHeight); //image+padding   
    bf_big.bfSize = bi_big.biSizeImage + 54;//biSize + headers

//resizing processes, unrelavent codes.......

//at the end of each scanline
for (int k = 0; k < padding; k++)
            {    
                fputc(0x00, outptr);
            } 

            if ( vert < n - 1)
            {
                fseek(inptr, -bi.biWidth * sizeof(RGBTRIPLE), SEEK_CUR);
                //jump over old paddings without resizing
            }
        }

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

You are calculating the new bi.biSizeImage incorrectly.

bi.biSizeImage is the size in bytes of the raw bmp data, that means the size in bytes of the pixels information plus the padding.

So:

bi.biSizeImage = (width * height * sizeofpixel) + (padding * height * sizeofpadding)

Notice that the height can be a negative value, so you need to use it's absolute value, in this case the size of a pixel is 3 bytes or the same as sizeof(RGBTRIPLE), and the size of the padding is 1 byte.

And since you are using bi.biSizeImage to calculate bf.bfSize, this last one is incorrect too.

I think this should fix your header problem.

2
  • thank you so much! that indeed fixed the problem:) Feb 27 '15 at 14:42
  • Thank you. That fixed my problem, too. I doesn't realized that size of padding is 1 byte, so treated it as sizeof RGBTRIPLE Oct 8 '15 at 5:41

You must log in to answer this question.

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