The output image appears to be correct, but only passes tests when resizing by 1. I tried to use peek and xxd to compare with staff implementation, my output appears to be equal.
// read infile's BITMAPFILEHEADER
BITMAPFILEHEADER bf;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
// read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
//store old header values
int width = bi.biWidth;
int height = bi.biHeight;
//update headers for the resized image
bi.biWidth *= n;
bi.biHeight *= n;
bi.biSizeImage *= n * n;
bf.bfSize = bi.biSizeImage + 54;
// ensure infile is (likely) a 24-bit uncompressed BMP 4.0
if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 ||
bi.biBitCount != 24 || bi.biCompression != 0)
{
fclose(outptr);
fclose(inptr);
fprintf(stderr, "Unsupported file format.\n");
return 4;
}
// write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
// determine padding for scanlines
int padding = (4 - (width * sizeof(RGBTRIPLE)) % 4) % 4;
int outPadding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
//size of output line in bytes
int size = bi.biWidth * sizeof(RGBTRIPLE);
// iterate over infile's scanlines
height = abs(height);
for (int i = 0; i < height; i++)
{
// iterate over pixels in scanline
for (int j = 0; j < width; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// stores position of output to go back later to prepare for next iteration
int back = ftell(outptr);
for(int k = 0; k < n; k++){
for(int l = 0; l < n; l++){
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
// jumps line
fseek(outptr, size + outPadding - n * sizeof(RGBTRIPLE), SEEK_CUR);
}
// backs to first unfilled pixel
fseek(outptr, back + n*sizeof(RGBTRIPLE), SEEK_SET);
}
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int k = 0; k < outPadding; k++)
{
fputc(0x00, outptr);
}
for(int k = 0; k < n - 1; k++){
// skip lines in output
fseek(outptr, size, SEEK_CUR);
for (int l = 0; l < outPadding; l++)
{
fputc(0x00, outptr);
}
}
}
}