I am pretty certain that my problem in this problem is my fseek in my vertical resizing for loop. Basically my idea is to print out horizontally resized code once per scan line always, then depending on factor size repeat the line by going back with that first fseek line. I don't think I would have to add the padding to the offset of fseek (fputc wouldn't move the fseek cursor right?), but I tried it anyways and it didn't work. I want to try to debug this with gdb or debug50, but I don't really know how to approach it in this program. Any thoughts?
// creates offset that is size of infile that vertical scaling wants to go back by
long offset = bi.biWidth * sizeof(RGBTRIPLE);
// iterate over infile's scanlines (rows)
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
// write pixels (columns)
for (int j = 0; j < bi.biWidth; j++)
{
RGBTRIPLE triple;
// read RGBTRIPLE from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write triple to outfile n times for horizontal scaling
for( int n = 0; n < factor; n++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// put outpadding value to outfile (diff from inpadding remember)
for (int k = 0; k < outPadding; k++)
{
fputc(0x00, outptr);
}
// if factor is greater than 1, need to repeat scan line factor - 1 times
// remember this whole for loop is optional and simply repeats row any time
// that it needs to scale up, if factor is 10 this loop will execute 9 times
// because the outermost for loop makes sure to write it once if factor is 1
for (int t = 0; t < factor - 1; t++)
{
fseek(inptr, -offset, SEEK_CUR);
// iterate over pixels in scanline (columns)
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
// scale horizontally by writing each pixel factor times across
for (int n = 0; n < factor; n++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// add padding to outfile
for (int k = 0; k < outPadding; k++)
{
fputc(0x00, outptr);
}
// remember that fseek is to change the cursor for the inFile
// here I want to go back
//if (t != bi.biWidth - 1)
// {
// fseek(inptr, -offset, SEEK_CUR);
// }
}
// skipp inPadding which sets up cursor for next part in file
fseek(inptr, inPadding, SEEK_CUR);
}