在调整 bmp 图像大小的程序中,{fseek (inptr, - ( bi.biWidth * 3 + padding), SEEK_CUR);} 是什么意思?

what does this mean {fseek (inptr, - ( bi.biWidth * 3 + padding), SEEK_CUR);} in the program that resizes a bmp image?

我不太明白这段代码的必要性。

// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);

// then add it back (to demonstrate how)
for (int k = 0; k < new_padding; k++)
{
    fputc(0x00, outptr);
}

if (repeat < n - 1)
{
    fseek(inptr, - (bi.biWidth * 3 + padding), SEEK_CUR);
}

如果没有完整的上下文,很难确认这段代码的正确性,甚至是相关性。

fseek 将输入流的指针向前移动 padding 字节。

程序然后将 new_padding 个空字节输出到输出流,可能与 padding 的数量不同。 Microsoft 的 BMP 文件格式需要在不同的地方进行一些填充,以便于读取到内存中。

最后,再次使用 fseek 将输入流指针向后设置到像素行的开头(每个像素 3 个字节)加上它跳过的填充,但前提是 (repeat < n - 1) .