My resize program seems to work just like the staff version, the outputs being identical (checked with peek too). However, check50 still seems to detect some error: :) 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
https://sandbox.cs50.net/checks/b1b8b35e55d1494e8b1a72fd21772d7a
This is my code:
//copy file headers
BITMAPFILEHEADER of = bf;
BITMAPINFOHEADER oi = bi;
//alter height and width for output file
oi.biHeight = bi.biHeight *n;
oi.biWidth = bi.biWidth *n;
//determine padding
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int outpad = (4 - (oi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
//correcting size variables
oi.biSizeImage = ((oi.biWidth * abs(oi.biHeight)) * sizeof(RGBTRIPLE)) + (outpad * abs(oi.biHeight));
of.bfSize = bf.bfOffBits + oi.biSizeImage;
// write outfile's BITMAPFILEHEADER
fwrite(&of, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&oi, sizeof(BITMAPINFOHEADER), 1, outptr);
// determine padding for scanlines
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
for(int y = 0; y<n; y++){
// 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 z = 0; z<n; z++)
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
// skip over padding, if any
fseek(outptr, outpad, SEEK_CUR);
// then add it back (to demonstrate how)
for (int k = 0; k < outpad; k++)
{
fputc(0x00, outptr);
}
if(y != n-1){
fseek(inptr, -bi.biWidth*sizeof(RGBTRIPLE), SEEK_CUR);
}else{
fseek(inptr, padding, SEEK_CUR);
}
}
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
// that's all folks
return 0;
}
I've been having serious trouble with this assignment, so I likely went over a simple mistake. I just cannot understand what's wrong if the outputs are identical to the staff's. Thank you