I am having trouble to make my file resize vertically. My code is below
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
//for each resize factor
for (int b = 0; b < n ; b++)
{
// when b is 0, it means the file is writing the line for 1st time.
// we want to avoid rewriting the first line again
if (b != 0)
{
fseek(inptr, -(long int)(sizeof(RGBTRIPLE)*bi.biWidth*b+ new_padding), SEEK_CUR);
}
// for each 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
// write extra pixel n times
for (int a = 0; a < n; a++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
//skip over padding, if any
//notice that, we are skipping over infile's padding
fseek(inptr, old_padding, SEEK_CUR);
//then add to the padding new padding
for (int k = 0; k < new_padding; k++)
{
fputc(0x00, outptr);
}
}
}
Please point out any flaws in my logic, in the comments in my code. Also, anything wrong with my fseek() offset?