1

My code seems to work but check50 fails with

~/workspace/git/CS50/pset04/resize/ (master) $ check50 2016.resize.more bmp.h resize.c
:) resize.c and bmp.h exist
:) resize.c compiles
:) doesn't resize 1x1-pixel BMP when f is 1.0
:) resizes 1x1-pixel BMP to 2x2 correctly when f is 2.0
:) resizes 1x1-pixel BMP to 3x3 correctly when f is 3.0
:) resizes 1x1-pixel BMP to 4x4 correctly when f is 4.0
:) resizes 1x1-pixel BMP to 5x5 correctly when f is 5.0
:) resizes 2x2-pixel BMP to 4x4 correctly when f is 2.0
:( resizes 2x2-pixel BMP to 1x1 correctly when f is 0.5
:( resizes 4x4-pixel BMP to 2x2 correctly when f is 0.5
:( resizes 6x6-pixel BMP to 3x3 correctly when f is 0.5

Since small.bmp is a 3x3-pixel image I produced a 1x1-pixel image with the staff solution: ~/workspace/git/CS50/pset04/resize/ (master) $ ~cs50/hacker4/resize .333333333 small.bmp 1x1.bmp and my solution ~/workspace/git/CS50/pset04/resize/ (master) $ ./resize .333333333 small.bmp student.bmp and compared it to my solution with ~/workspace/git/CS50/pset04/resize/ (master) $ ~cs50/hacker4/peek student.bmp 1x1.bmp:

offset  type   name              argv[1]   argv[2]
0       WORD   bfType               4d42      4d42
2       DWORD  bfSize           0000003a  0000003a
6       WORD   bfReserved1          0000      0000
8       WORD   bfReserved2          0000      0000
10      DWORD  bfOffBits        00000036  00000036
14      DWORD  biSize           00000028  00000028
18      LONG   biWidth          00000001  00000001
22      LONG   biHeight         ffffffff  ffffffff
26      WORD   biPlanes             0001      0001
28      WORD   biBitCount           0018      0018
30      DWORD  biCompression    00000000  00000000
34      DWORD  biSizeImage      00000004  00000004
38      LONG   biXPelsPerMeter  00000b12  00000b12
42      LONG   biYPelsPerMeter  00000b12  00000b12
46      DWORD  biClrUsed        00000000  00000000
50      DWORD  biClrImportant   00000000  00000000

~/workspace/git/CS50/pset04/resize/ (master) $ xxd -c 12 -g 3 -s 54 student.bmp 0000036: 00ff00 00

~/workspace/git/CS50/pset04/resize/ (master) $ xxd -c 12 -g 3 -s 54 1x1.bmp 0000036: 00ff00 00

I really don't know, what the problem is. Here are the interesting bits of my code:

The part that is different from copy.c:

// It works now, so I removed the code to not spoil anything. 
// I forgot to skip lines and pixels when downscaling.
1

Looks like you don't have any mechanism for skipping input pixels or input lines. One possible approach would be for every pixel you want to read, to calculate the absolute position inside the file, and use fseek with SEEK_SET.

You claimed your solution creates the same image as the staff's. To see differences, you could for example resize an image to 2x, and then back to 0.5x, and compare those (or any similar pair of factors). With most algorithms, the first and the third image should be at least similar, with your method even the same, if and only if you did your line skipping right.

| improve this answer | |
  • I believe you are right! I can't believe I did not realize this.Thank you – Nils Müller Feb 10 '17 at 16:13
  • I got it working now. Thank you! – Nils Müller Feb 13 '17 at 7:06
0

I barely looked at your code, but I'll tell you where to start and what I'm assuming.

This will allow you to figure out what's going wrong.

1) Get a hex editor (on Mac you can use ihex from the app store).

2) Take small.bmp and double it using your code and the staff's code.

3) Open up your bmp and staff's in the hex editor.

4) Compare them side by side

Edit: I just noticed your problems are on downsizing. They have not documented their downsizing algorithm well and it doesn't match any known algorithm I've been able to find. If you can't figure it out, and you can't get an answer from staff, I'd only do the (Less) option and move on.

| improve this answer | |
  • I got it working now with the algorithm min(biWidthOld, rint((j+0.25)/f-0.5)); and methods to skip to the appropriate scanlines and pixels. – Nils Müller Feb 13 '17 at 7:05
  • @NilsMüller i would love to take a look on your code, i basically gave up and worked only the less version. – Wilson Muñoz May 3 '17 at 1:38

You must log in to answer this question.

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