I cant seem to get my enlarge code to work. I am trying to make it go back and do the pixel n number of times but my code is faulty but I cant figure out why. I have only included my padding and enlarge code Can anyone tell me what is wrong with my code?
int oldpadding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int newpadding = (4 - (newinfo.biWidth * n * sizeof(RGBTRIPLE)) % 4) % 4;
BITMAPINFOHEADER newinfo;
// write outfile's BITMAPFILEHEADER
BITMAPFILEHEADER newfile;
newfile = bf;
newinfo = bi;
newinfo.biWidth = bi.biWidth * n;
int oldpadding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
int newpadding = (4 - (newinfo.biWidth * n * sizeof(RGBTRIPLE)) % 4) % 4;
newinfo.biHeight = bi.biHeight * n;
newinfo.biSizeImage = (bi.biWidth * n * sizeof(RGBTRIPLE) + newpadding) * abs(newinfo.biHeight);
newfile.bfSize = newinfo.biSizeImage + sizeof(newfile)+ sizeof(newinfo);
fwrite(&newfile, sizeof(newfile), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&newinfo, sizeof(newinfo), 1, outptr);
// determine padding for scanlines
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
//enlarge vertically
for (int hi = 0; hi < n; hi++)
{
if(hi > 0)
{
fseek(inptr, -(bi.biWidth * sizeof(RGBTRIPLE)), SEEK_CUR);
}
// 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);
// write RGB triple to outfile and enlarge horizontally
for (int jn = 0; jn < n; jn++)
{
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 < newpadding; k++)
{
fputc(0x00, outptr);
}
}
}