Once again I find myself stumped by CS50. In the below code I have done my best to try to mathematically edit the Bitmap Headers using a variable I named "scalefactor" which is determined by the user, as well as use that same variable to influence the writing of the pixels, and feel that I am quite close to the solution, but as always missing some obvious and simple part to the program that is resulting in mostly black images. I doubt it's anything to do with the way I determine the header information, but to be sure I've placed that below as well. As always, thank you for the help.
// determine padding for scanlines
int padding = (4 - ((bi.biWidth * scalefactor) * sizeof(RGBTRIPLE)) % 4) % 4;
if (scalefactor != 1)
{
// make necessary changes to BITMAPFILEHEADER
bf.bfSize = (bf.bfSize - bi.biSize) + (((bi.biWidth + padding) * scalefactor) * (bi.biHeight * scalefactor));
// make necessary changes to BITMAPINFOHEADER
bi.biWidth = bi.biWidth * scalefactor;
bi.biHeight = bi.biHeight * scalefactor;
bi.biSizeImage = bi.biWidth * bi.biHeight;
}
// write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
for (int k = 1; k <= scalefactor; k++)
{
// 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
fwrite(&triple, sizeof(RGBTRIPLE), scalefactor, outptr);
}
}
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int k = 0; k < padding; k++)
{
fputc(0x00, outptr);
}
}