I have been in resize for a month....Finally the program runs but when check50, still all :( except resize by 1, below is my code
// determine padding for scanlines
int padding = (4 - (bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
BITMAPFILEHEADER out_bf;
BITMAPINFOHEADER out_bi;
out_bf = bf;
out_bi = bi;
out_bi.biWidth = bi.biWidth * n;
out_bi.biHeight = bi.biHeight * n;
// new...to determine the padding for the output image scanlines
int out_padding = (4 - (out_bi.biWidth * sizeof(RGBTRIPLE)) % 4) % 4;
out_bi.biSize = (out_bi.biWidth * sizeof(RGBTRIPLE) + out_padding) * abs(out_bi.biHeight);
out_bf.bfSize = 54 + out_bi.biSize;
// write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);
// write outfile's BITMAPINFOHEADER
fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);
...hidden code that is not relevant to problem
...
After I peek using: ./resize 4 small.bmp student.bmp ~cs50/pset4/resize 4 small.bmp staff.bmp ~cs50/pset4/peek student.bmp staff.bmp
the following results
offset type name argv[1] argv[2]
0 WORD bfType 4d42 4d42
2 DWORD bfSize 0000005a 000001e6
6 WORD bfReserved1 0000 0000
8 WORD bfReserved2 0000 0000
10 DWORD bfOffBits 00000036 00000036
14 DWORD biSize 00000028 00000028
18 LONG biWidth 00000003 0000000c
22 LONG biHeight fffffffd fffffff4
26 WORD biPlanes 0001 0001
28 WORD biBitCount 0018 0018
30 DWORD biCompression 00000000 00000000
34 DWORD biSizeImage 00000024 000001b0
38 LONG biXPelsPerMeter 00000b12 00000b12
42 LONG biYPelsPerMeter 00000b12 00000b12
46 DWORD biClrUsed 00000000 00000000
50 DWORD biClrImportant 00000000 00000000
jharvard@ubuntu (~/Dropbox/pset4/bmp):
all width, height, size of file and image do not work :( Could somebody help?
After editing from fwrite's &bf and &bi to &out_bf and &out_bi respectively and run ./resize 2 small.bmp student2.bmp and then xxd - c 18 -g 3 student2.bmp, the below results
0000000: 424dae 000000 000000 003600 000078 000000 BM........6...x...
0000012: 060000 00faff ffff01 001800 000000 002400 ................$.
0000024: 000012 0b0000 120b00 000000 000000 000000 ..................
0000036: 00ff00 00ff00 00ff00 00ff00 00ff00 00ff00 ..................
0000048: 000000 000000 00ff00 00ff00 ffffff ffffff ..................
000005a: 000000 000000 000000 ff0000 ff0000 ff0000 ..................
000006c: ff0000 ff0000 ff0000 000000 000000 000000 ..................
000007e: 000000 000000 000000 000000 000000 000000 ..................
0000090: 000000 000000 000000 000000 000000 000000 ..................
00000a2: 000000 000000 ......