I have been working with resize for a couple weeks on and off. My pseudo code makes sense, but when I put it into action, it is not working. I only pass a portion of check50. I think it has to do with padding, but cannot figure it out. Here is my code. It would be great to get some insight... thanks in advance!!!
// create a copy of the infile headers, making new outfile headers BITMAPFILEHEADER new_bf; BITMAPINFOHEADER new_bi; new_bf = bf; new_bi = bi;
// identify existing data in bitmap
int crntWidth = bi.biWidth;
int crntHeight = bi.biHeight;
// update bitmap information for outfile with resize data
new_bi.biWidth = crntWidth * resize;
new_bi.biHeight = crntHeight * resize;
// calculating padding for scanlines
int crntPadding = (4 - (crntWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int newPadding = (4 - (new_bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
// update image size for outfile
new_bi.biSizeImage = (new_bi.biWidth * sizeof(RGBTRIPLE) + newPadding) * abs(new_bi.biHeight);
// update file size for outfile
new_bf.bfSize = 54 + new_bi.biSizeImage;
// write outfile's BITMAPFILEHEADER
fwrite(&new_bf, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&new_bi, sizeof(BITMAPINFOHEADER), 1, outptr);
// read and itierate over infile's scanlines
for (int i = 0, new_biHeight = abs(crntHeight); i < new_biHeight; i++)
{
// itierate over pixels in scanline
for (int j = 0; j < resize; j++)
{
if (j % resize != 0)
{
fseek(inptr, -(crntWidth * sizeof(RGBTRIPLE) + newPadding), SEEK_CUR);
}
// resize horizontally
for (int k = 0; k < crntWidth; k++)
{
// issue temporary storage
RGBTRIPLE triple;
// read RGB pixels (triple) from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// write RGB triple to outfile, multiplied by factor
for (int k = 0; k < resize; k++)
{
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
}
// skip over infile padding, if any
fseek(inptr, crntPadding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int crntPadding = 0; crntPadding < newPadding; crntPadding++)
{
fputc(0x00, outptr);
}
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
return 0;
}