I keep getting an error from the IDE saying "Invalid or Unsupported Image Format" and I haven't been able to figure out why. I have looked at other questions but none seem to help.
bi_new.biWidth = bi.biWidth * n;
bi_new.biHeight = bi.biHeight * n;
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int new_padding = (4 - (bi_new.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
bf_new.bfSize = (bi_new.biWidth * abs(bi_new.biHeight )) * sizeof(RGBTRIPLE) + new_padding * abs(bi_new.biHeight) + 54;
bi_new.biSizeImage = bf_new.bfSize - 54;
// write outfile's BITMAPFILEHEADER
fwrite(&bf_new, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bi_new, sizeof(BITMAPINFOHEADER), 1, outptr);
// determine padding for scanlines
padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
int current_pos = ftell(inptr);
// iterate over pixels in scanline
for (int j = 0; j < bi.biWidth; j++)
{
fseek(inptr, current_pos, SEEK_SET);
//bi.biHeight = bi.biHeight *= n;
//bi.biWidth = bi.biWidth *= n;
// temporary storage
RGBTRIPLE triple;
//long int pos = ftell(inptr);
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
for(int m = 0; m <= n; m++){
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
//fseek(inptr, pos, SEEK_SET);
}
fwrite(outptr, new_padding, SEEK_CUR);
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int k = 0; k < new_padding; k++)
{
fputc(0x00, outptr);
}
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
// success
return 0;
}