0

I've tried many numbers, the code correctly resize the image, and the header info perfectly match. But it can't pass the check when the image is 1x1 pixel. I've spent two week on this pset and I am so exhausted and desperate. Someone please help me out. Thank you!

enter image description here

    // calculate old and new paddings and update biWidth, biHeight, biSizeImage, bfSize
    int old_padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;// determine old padding for scanlines
    bi.biWidth = n * bi.biWidth;
    bi.biHeight = n * bi.biHeight;
    int new_padding =  (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;// determine new padding for scanlines
    bi.biSizeImage = sizeof(RGBTRIPLE) * (bi.biWidth + new_padding) * abs(bi.biHeight);
    bf.bfSize = bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);// update bfSize
1

This is why it is important to test software with different test data to exercise each part of the code. Insufficient testing can leave a bug undiscovered.

My guess is that you've been using the same bmp file as input all this time. You should run your program with small.bmp as the input file witn n=1 and then check the header and image data of the output file against the original. They should be identical, but they aren't. The location of the problem should become obvious very quickly, but it might take a little while to recognize why there's a problem.

If you can't figure it out after a reasonable effort, leave a comment with any new questions and I'll point you in the right direction.

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

2
  • Thank you, Cliff! I've figured it out! I miscalculated the biSizeImage: every RGBTRIPLE is 3 bytes, but every padding is only 1 bytes! Thank you!!!
    – Kevin King
    Aug 29 '16 at 2:39
  • Yes, you did! Congratulations! I love it when someone does the work and the research!
    – Cliff B
    Aug 29 '16 at 2:41
0

With the help of Cliff, I finally figured it out. I miscalculated the biSizeImage: every RGBTRIPLE is 3 bytes, but every padding is only 1 bytes!

You must log in to answer this question.

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