0

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 ......

0

Shouldn't you be copying from the &out_bf and &out_bi

// write outfile's BITMAPFILEHEADER
fwrite(&bf, sizeof(BITMAPFILEHEADER), 1, outptr);

// write outfile's BITMAPINFOHEADER
fwrite(&bi, sizeof(BITMAPINFOHEADER), 1, outptr);

You are writing from the original values bf and bi

6
  • I have tried &out_bf and &out_bi in the fwrite function before. But then "bmp image has unsupported header size" appeared in large.bmp, so I change back to &bf and &bi...and the above problem results.... – Hang Man Jan 25 '15 at 9:19
  • what does large.bmp have to do with this? Aren't you saving your resized as student.bmp? – curiouskiwi Jan 25 '15 at 9:22
  • I have tried again peeking student.bmp and compared with staff.bmp, however, the "Could not recognize student.bmp" result. And in the bmp folder, student.bmp shows "bmp image has unsupported header size... – Hang Man Jan 25 '15 at 9:57
  • can you please run your resize with the corrected fwrites ./resize 2 small.bmp student2.bmp and then run this: xxd -c 18 -g 3 student2.bmp and paste what you get as an edit to your question. – curiouskiwi Jan 25 '15 at 10:07
  • (it's quite late here, so I will check again in the morning.) – curiouskiwi Jan 25 '15 at 10:18
0

The problem is most likely about 'n', how are you storing n?

Hint, right after you get n, write the following and try to compile

printf( "scale           %d", n )
printf( "scale times two %d", n*2 )

you will probably see the problem.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .