I'm stuck with resize.c :( I managed to update headers and resized image horizontally, but I cannot resize vertically - my code either stretches images in width or produces some weird images like from old TV monitors.
Here is my code:
int scanlinelength = biWidthOrg * (int)sizeof(RGBTRIPLE) * -1;
// iterate over infile's scanlines
for (int i = 0, counter = 1, biHeightRsz = abs(bi.biHeight); i < biHeightRsz; i++)
{
// iterate over pixels in scanline
for (int j = 0; j < biWidthOrg; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile and store the value in &triple
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// resize horizontally
for (int k = 0; k < nfactor; k++)
{
// write RGB triple to outfile nfactor times
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
// add padding to outfile, if any
for (int l = 0; l < paddingRsz; l++)
fputc(0x00, outptr);
}
if (counter >= nfactor)
{
counter = 1;
// skip over padding in infile, if any
fseek(inptr, paddingOrg, SEEK_CUR);
}
else
{
// go backward from current position to resize vertically
fseek(inptr, scanlinelength, SEEK_CUR);
counter++;
}
}
What I'm trying to do: after fwrite writes the scanline into outfile, I want to come back in infile to the beginning of the original scanline using fseek and read and write this scanline into outfile again. But it isn't working and I receive resized images which looks like this https://monosnap.com/file/h1ynTiEZKuA1LRjmhJmnPBR6QF5apV
Please, help! Many thanks in advance!