My resize program isn't working. I have narrowed it down to the padding, but cannot find what is incorrect.
It resizes images that don't need padding perfectly (multiples of 4), and the header information is all correct (checked by peek) but in other cases it creates images with displaced pixels/odd colors, etc.
check50: https://sandbox.cs50.net/checks/b50c42ee0c884758939d16116a6bb5f4
I omitted all of the unnecessary code, and left all the logic.
[some code was hidden per academic honesty]
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
// Store an array in order to repeat each line 3x
RGBTRIPLE tarray[bi.biWidth];
// iterate over pixels in scanline
for (int j = 0; j < bi.biWidth; j++)
{
// read RGB triple from infile
RGBTRIPLE triple;
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
tarray[j] = triple;
// write RGB triple to outfile w/ magnification
for(int k = 0; k < magn; k++){
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// skip over padding, then add it back
fseek(inptr, inpadding, SEEK_CUR);
for (int pad = 0; pad < padding; pad++)
{
fputc(0x00, outptr);
}
// write each row more than once!
for(int j = 0; j < magn-1; j++){
for (int k = 0; k < bi.biWidth; k++)
{
// write RGB triple to outfile w/ magnification
for(int l = 0; l < magn; l++){
fwrite(&tarray[k], sizeof(RGBTRIPLE), 1, outptr);
}
}
// skip over padding, then add it back
fseek(inptr, inpadding, SEEK_CUR);
for (int pad2 = 0; pad2 < padding; pad2++)
{
fputc(0x00, outptr);
}
}
}