I am on pset4 and working on resize, less comfortable. I chose to follow the "rewrite" method but it seems that I am going wrong somewhere and I have no idea what to do. Any advice?
// determine padding for scanlines
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
bi.biWidth *= n;
bi.biHeight *= n;
int newPadding = (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);
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
RGBTRIPLE number[n];
// iterate over 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);
for (int p = 0, s= 0; p < n; p++)
{
number[s] = triple;
s++;
}
}
for (int l = 0; l < n; l++)
{
// write RGB triple to outfile
fwrite(&number[l], sizeof(RGBTRIPLE), 1, outptr);
// then add it back (to demonstrate how)
for (int k = 0; k < newPadding; k++)
{
fputc(0x00, outptr);
}
}
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
// success
return 0;
}