I'm on the verge of giving up. I've been stuck on this problem for weeks. I managed the headers, and I think I set up the loops right to write the pixels correctly. I just can't wrap my head around fseek however. I read the man page, and read stack exchange, but I just don't get it.
Can anyone help me, why my code is failing to resize, and what direction should I progress? I'm super frustrated with it.
// Saving original width and height int oriwidth = bi.biWidth; int oriheight = bi.biHeight; // Modifying to new width and height bi.biWidth = bi.biWidth * n; bi.biHeight = bi.biHeight * n; // determine padding for scanlines int oripadding = (4 - (oriwidth * sizeof(RGBTRIPLE)) % 4) % 4; int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4; // Modifying sizes bi.biSizeImage = ((bi.biWidth * abs(bi.biHeight)) * sizeof(RGBTRIPLE)) + (padding * abs(bi.biHeight)); bf.bfSize = bi.biSizeImage + 54; // write outfile's BITMAPFILEHEADER fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr); // write outfile's BITMAPINFOHEADER fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr); // iterate over infile's scanlines for (int i = 0; i < abs(oriheight); i++) { // temporary storage RGBTRIPLE triple; for (int s = 0; s < n; s++) { fseek(inptr, 54 + ((i + 1) * oriwidth * (sizeof(triple) + oripadding)), SEEK_SET); // iterate over pixels in scanline for (int j = 0; j < oriwidth; j++) { // read RGB triple from infile fread(&triple, sizeof(RGBTRIPLE), 1, inptr); // write RGB triple to outfile for (int k = 0; k < n; k++) { fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr); } } } // 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); } }