0

Working on resize (more version) problem set from Week 4.

Having reviewed other solutions, and using debug50, peek, and diff, I'm having trouble identifying what in my code is leading to this error.

When I run ./resize f infile outfile, where, for example values are ./resize 4 smiley.bmp test.bmp, the outfile, or in this case test.bmp is corrupted. I try to open it and get an error invalid or unsuported file.

Trying to run debug50 just returns 1; peek returns error Could not recognize test.bmp, and diff returns binary files smiley.bmp and test.bmp differ.

Code is here: https://www.pastiebin.com/5903c9a7aa684

0

unsupported tells me that your header values are wrong. Looking at your code:

new_bi.biWidth = ((bi.biWidth * f) * sizeof(RGBTRIPLE)) + new_padding;
new_bi.biHeight = bi.biHeight * f;

bi.biWidth is the number of pixels per scanline, and bi.biHeight is the number of scanlines. So small.bmp would have a width of 3 since it is a 3x3 bitmap. Your code appears to calculating the size of the entire scanline.

Your new width should be the old width * the resize factor, such that if you resize by 5, your width would be 15.

You must log in to answer this question.

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