I think I have the headers correct except for the new bf.Size not to sure on that one. I am having real problems with resizing the bitmap and I can't figure out what it is, any hints or pointers in the right direction would be very appreciated.
// read infile's BITMAPFILEHEADER
BITMAPFILEHEADER bf;
BITMAPFILEHEADER bfc;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
// read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;
BITMAPINFOHEADER bic;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
// 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;
}
bfc = bf;
bic = bi;
// determine padding for scanlines
int padding = (4 - (bi.biWidth) * sizeof(RGBTRIPLE) % 4) % 4;
int newpadding = (4 - (bi.biWidth * n) * sizeof(RGBTRIPLE) % 4) % 4;
bic.biSizeImage = ((bi.biWidth * n) * sizeof(RGBTRIPLE) + newpadding ) * (abs(bi.biHeight * n));
bfc.bfSize = bic.biSizeImage + 54;
bic.biHeight = (bi.biHeight * n);
bic.biWidth = (bi.biWidth * n);
// write outfile's BITMAPINFOHEADER
fwrite(&bic, sizeof(BITMAPINFOHEADER), n, outptr);
// write outfile's BITMAPFILEHEADER
fwrite(&bfc, sizeof(BITMAPFILEHEADER), n, outptr);
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
// 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 l = 0; l < n; l++)
{
if (l > 0)
{
fseek(outptr, sizeof(RGBTRIPLE)* l, SEEK_CUR);
}
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int k = 0; k < newpadding; k++)
{
fputc(0x00, outptr);
}
}
`