int pastwidth = bi.biWidth;
int pastHeight = bi.biHeight;
int padding = (4 - (SCALE * sizeof(RGBTRIPLE)) % 4) % 4;
bi.biWidth = SCALE;
bi.biHeight = SCALE;
bi.biSizeImage = ((SCALE+padding*SCALE+padding)*24);
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);
// determine padding for scanlines
bi.biWidth = pastwidth;
bi.biHeight = pastHeight;
// iterate over infile's scanlines
for (int i = 0; i < abs(newHeight); i++)
{
for(int o=0;o<SCALE;o++)
{
fseek(inptr, 54 + bi.biWidth * i, SEEK_SET);
// iterate over pixels in scanline
for (int j = 0; j < newWidth; j++)
{
// temporary storage
RGBTRIPLE triple;
// read RGB triple from infile
fread(&triple, sizeof(RGBTRIPLE), 1, inptr);
for(int a=0;a<SCALE;a++)
{
// write RGB triple to outfile
fwrite(&triple, sizeof(RGBTRIPLE), 1, outptr);
}
}
}
// skip over padding, if any
fseek(inptr, padding, SEEK_SET);
// then add it back (to demonstrate how)
for (int k = 0; k < padding; k++)
{
fputc(0x00, outptr);
}
}
}
// close infile
fclose(inptr);
// close outfile
fclose(outptr);
// that's all folks
return 0;
}
AlRIGHT ALMOST EVERYTHING IS CHANGED
Hello cs50 people. I'm pretty close to the real solution, I feel it. So It produces SOLID GREEN BOX(with no space in it). I believe it's about fseek but dont know how to correct it :[.