So what I tried to do here is to copy every pixel in each of infile's scanlines as many times as the factor provided, then go back to the start of the scanline and do it again but on the next row, so it also resizes vertically. But when I run this, I get a file size exceeded (512mb) so I guess it gets stuck on some kind of infinite loop, but I can't really see where. Any help would be appreciated, thanks.
// 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++)
{
int rowDone = 0;
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile (factor)times
for (int k = 0; k < factor; k++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
// If on the end of scanline, go back to start of the scanline
// and repeat factor times, on next row of outfile
if (j == bi.biWidth - 1)
{
rowDone++;
if (rowDone != factor)
{
// Restarts for loop
j = 0;
// Seek to start of the scanline
fseek(inptr, i*(sizeof(RGBTRIPLE)*bi.biWidth)+1, SEEK_SET);
}
}
}
// skip over padding, if any
fseek(inptr, inpadding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int l = 0; l < outpadding; l++)
{
fputc(0x00, outptr);
}
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
// success
return 0;
}
EDIT: So I figured out that the infinite loop was happening because I defined the rowDone variable inside of the pixels loop instead of the scanline loop. But now when I run it, I get a weird image with tons of colors in it, which I don't even know where they are coming from since the original picture is only red and white (I'm testing it with smiley.bmp). What's wrong with my logic here? :(