Having some growing pains with this pset. I think I have the horizontal resizing figured out with my for loop. My problem is iterating over the same line x number of times (where x is the scale entered). Each time I try something I run into issues with the padding or it doesn't iterate over that same line.
// read infile's BITMAPFILEHEADER
BITMAPFILEHEADER bf;
fread(&bf, sizeof(BITMAPFILEHEADER), 1, inptr);
// read infile's BITMAPINFOHEADER
BITMAPINFOHEADER bi;
fread(&bi, sizeof(BITMAPINFOHEADER), 1, inptr);
int originalPadding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
//printf("%i", originalPadding);
// ensure infile is (likely) a 24-bit uncompressed BMP 4.0
if (bf.bfType != 0x4d42 || bf.bfOffBits != 54 || bi.biSize != 40 ||
bi.biBitCount != 24 || bi.biCompression != 0)
{
fclose(outptr);
fclose(inptr);
fprintf(stderr, "Unsupported file format.\n");
return 4;
}
int oldHeight = bi.biHeight;
int oldWidth = bi.biWidth;
//printf("%i%i", oldHeight, oldWidth);
bi.biWidth = (bi.biWidth * resizeBy);
bi.biHeight = bi.biHeight * resizeBy;
// determine padding for scanlines
//this is padding for adjusted width of outfile
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
//printf("%i", padding);
//vvvvvv We need to add the padding vvvvvv
bi.biSizeImage = (bi.biWidth * sizeof(RGBTRIPLE) + padding) * abs(bi.biHeight);
bf.bfSize = bi.biSizeImage + 54;
//printf("%i%i", oldHeight, oldWidth);
// 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, oldHeight1 = abs(oldHeight); i < oldHeight1; i++)
{
for ( int r = 0; r < resizeBy; r++)
{
// 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);
for (int k= 0; k < resizeBy; k++)
{
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
// skip over padding, if any
fseek(inptr, originalPadding, SEEK_CUR);
// then add it back (to demonstrate how)
for (int p = 0; p < padding; p++)
{
fputc(0x00, outptr);
}
if (r % resizeBy != resizeBy - 1)
{
fseek (inptr, -1 * (oldWidth * (int)sizeof(RGBTRIPLE)) + originalPadding , SEEK_CUR);
}
}
}
//move back to same line??
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
// success
return 0;
}
}