I'm currently trying to figure out what am I doing wrong while resizing the pixels, the weird location of the pixels suggests me that something is wrong with the padding, but I'm not sure. And it seems that I'm not resizing horizontally at all. I'm currently stuck, I've tried fixing it and reading current entries of why it might be wrong, but not a clue. Thank you in advance for your help.
/* update headers file */
//update width
bi.biWidth *= n;
// update padding for scanlines
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
//update height
bi.biHeight *= n;
//update image size
bi.biSizeImage = ((sizeof(RGBTRIPLE) * bi.biWidth) + padding) * abs(bi.biHeight);
// write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
//update file size
bf.bfSize = bi.biSizeImage + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
// iterate over infile's scanlines
for (int i = 0, biHeight = abs(bi.biHeight); i < biHeight; i++)
{
// resize vertically
for (int x = 0; x < n; x++)
{
// 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 n times (aka resize horizontally)
fwrite(&triple, sizeof(RGBTRIPLE), n, outptr);
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
}
}
// skip over padding, if any
fseek(inptr, padding, SEEK_CUR);
//then add it back (to demonstrate how)
for (int k = 0; k < padding; k++)
fputc(0x00, outptr);
}