int oldHeight = bi.biHeight;
int oldWidth = bi.biWidth;
bi.biWidth *= n;
bi.biHeight *= n;
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
bi.biSizeImage = ((sizeof(RGBTRIPLE) * bi.biWidth) + padding) * abs(bi.biHeight);
bf.bfSize = bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
// write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
// determine padding for scanlines
int oldPadding = (4 - (oldWidth * sizeof(RGBTRIPLE)) % 4) % 4;
RGBTRIPLE scanlines[bi.biWidth][abs(bi.biHeight)];
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(oldHeight); i < biHeight; i++)
{
// increase row by n factor
for(int w = 0; w < n; w++)
{
if( w > 0 )
{
fseek(inptr, oldHeight * sizeof(RGBTRIPLE), SEEK_CUR);
}
// iterate over pixels in scanline
for (int j = 0; j < oldWidth; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
// increase pixels in scanline by n factor
for(int z = 0; z < n; z++)
{
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
}
// skip over padding, if any
fseek(inptr, oldPadding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int k = 0; k < padding; k++)
{
fputc(0x00, outptr);
}
}
As the title says, my resize less program is correct in check50, except when n=2, 3 and 5 and the image is small.bmp, after some testing, i suspect the issue has something to do with the padding, therefor the problem only appears when it's dealing with an image that is not a multiple of 4 or is not an exact copy of the original (n=1). The error results in a multicolor rectangle, with only 5 rows instead of 4 and only the first row is green. I posted a part of the code above, any help is appreciated.
EDIT: I solved the problem, it was the simple fact i left the padding output for loop inside the loop over the infile scanlines and not the one which will create the outfile, therefore i was only making the padding times the original number of rows and not the original * n factor like it was supposed to.