The code I wrote (using the pseudo-code of Zamyla's video on resize) make the image proper for some cases while not for others. I really need help in finding the flaw in the code.
pseudo-code
1. for each row
2. for n-1 times
3. write pixels, padding to the file
4. send infile cursor back
5. write pixels, padding to outfile
6. skip over infile padding
for (int i = 0, biHeight = abs(iHeight); i < biHeight; i++)
{
int j;
// temporary storage
RGBTRIPLE triple;
for (int k = 0; k < n - 1; k++)
{
/*--------write pixels, padding to the file------------*/
for (j = 0; j < iWidth; j++)
{
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile
for (int l = 0; l < n; l++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// write padding to the outfile
for (int l = 0; l < paddingNew; l++)
{
fputc(0x00, outptr);
}
/*------------send infile cursor back-------------*/
fseek(inptr, -1 * sizeof(RGBTRIPLE) * j, SEEK_CUR);
}
/*-----------------------write pixels, padding to outfile--------------*/
for (j = 0; j < iWidth; j++)
{
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
/*--------write pixels, padding to the file------------*/
// write RGB triple to outfile
for (int l = 0; l < n; l++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// write padding to the outfile
for (int l = 0; l < paddingNew; l++)
{
fputc(0x00, outptr);
}
/*-----------------------skip over infile padding------------------*/
fseek(inptr, padding, SEEK_CUR);
}