Assignment 3: memory locality

Hand-in requirements

Functional requirements

Build a program which will take in the filename of a PPM image file and output the co-ordinates of the image after being "auto-cropped". You should not output the actual image file after being auto-cropped, only the co-ordinates of where to do the cropping.

You may make the following assumptions about any PPM loaded into your program:

Your program must print out the co-ordinates to do auto-cropping. Consider this example picture. The original image is without the yellow lines or red text. Your program must find the largest borders possible which can be cropped without destroying any of the "foreground" image. For your purposes, you will assume that the pixel in the extreme top-left corner (x=0, y=0) is the background colour and that any pixels with the same red, green and blue values can be considered part of the background; all other pixels are considired the foreground.

Co-ordinates in the image are read from the top down and from left to right, starting at 0. The top-left pixel is (0, 0). The pixel immediately to the right of it is (1, 0). The pixel immediately below the top-left pixel is (0, 1).

After finding the largest possible borders which can be cropped without removing any of the foreground, your program must print to stdout those co-ordinates (x1, x2, y1 and y2 from the example picture).

To gain full marks for the assignment, your program must not only be correct, but be very fast. You will use your knowledge of virtual memory and data caching to make it as fast as possible.

The following strategies are disallowed for assignment 3:

Example usage

bash$ ./autocrop giant-picture.ppm
(402, 17) - (10382, 17893)

Marks

Your base mark will be based on how quickly your program can autocrop the testing data. In the ~mburrel/3305/asn3 directory on GAUL you can find a number of large PPM files and sample output.

Your program will be compiled (with your Makefile) and run and timed on obelix. The amount of time it takes your program to determine a correct answer will decide your base mark. Note that your program may be run multiple times to get an average time (due to experimental error in the results). The PPM file will be in the operating system cache (i.e., we'll run it once first to get the file cached) before timing.

The exact PPM file used to test your program will be asteroids.ppm.

Marks will be given as follows:

BehaviourBase markTotal running time (wall clock time) for asteroids.ppm on obelix
Very little submitted0/20
Nothing compiles2/20
Compiles but has little functionality5/20
Produces incorrect results due to bug but otherwise complete7/20
Correct: very slow9/20≥30.000 seconds
Correct: slow13/2020.000–29.999 seconds
Correct: moderate speed15/209.500–19.999 seconds
Correct: fast17/207.500–9.499 seconds
Correct: very fast20/205.800–7.499 seconds
Faster than my solution21/20<5.800 seconds
Mark adjustments
Something's fishy with the Makefile, making it annoying for the TAs to build-2/20
Bad directory structure-1/20
Code is hard to read-1/20 to -4/20, depending on severity
An unnecessary use of a magic number-1/20
Something really awesome that goes beyond the requirements of this assignment (stick in a README so we know to look for it!)+1/20 to +3/20, depending on level of awesomeness
Proper C coding techniques have been followed (checking for errors, using errno, printing out error messages, dependencies in Makefiles are correct, etc.)+1/20

Hints