In resize.c
, the image created in my resized image is a tiny image with a black blotch in the middle, regardless of whether I use small.bmp or smiley.bmp as input.
When I run xxd
, the header in the bmp file I created is extremely long (it scrolls so far in a rapid fashion that I can't see the beginning after it's done). It seems that one of my for loops is causing fwrite
to perform far too many times. The walkthrough wasn't very helpful IMO...I think I may need to do a malloc() somewhere, but i'm not sure if it would be in this portion or not.
*n
is the factor I am using to resize.
Code snippet:
// n is declared and given a value
char *n = argv[1];
// iterate over infile's scanlines
// which for loop is running too many times?
// fwrites too many times (shows when xxd is run)
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
for (int y = 0; y < *n; y++)
{
// 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 z = 0; z < *n; z++)
{
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 < padding; k++)
{
fputc(0x00, outptr);
}
}
}