Comp 116 Programming Assignment 02:
PPM Filter

Due 11:59pm Friday, March 12 2019

This is an individual assignment. You must complete this lab on your own, although you may discuss lab concepts with other students. Please keep the Academic Integrity Policy in mind---do not show your code to anyone outside of the professors and tutors, and do not look at anyone else's code for this lab.

The goal of this lab is to introduce you to common concepts in the C++ program language. Concepts you will be familiar with after this lab include:

Description

Download the .zip file that contains the starter code for the third programming assignment. The file you need depends on whether you are using a Windows or Mac, so make sure you download the right one. When submitting your assignment on onCourse, you should submit a .zip file of the entire folder for the project.

In this lab, you will write a program that modifies images stored in the .ppm (portable pixel map) format. Your program should ask the user for the name of an input file, the name of an output file and the name of the filter to apply. It will then read the input file, apply the transformation requested, write the modified picture to the output file and terminate. I will go over the details of the .ppm format, and you can click here for more information.

Interacting with your program should look something like this:

Welcome to the Portable Pixmap (PPM) Image Editor

Enter name of input file:  MachuPicchu.ppm 
Enter name of output file:  output.ppm 
Enter filter command:  grayscale 

Image converted.  Goodbye!
The original and resulting image should be:

MachuPicchu.ppm MachuPicchu-gray.ppm

Reading and Writing PPMs

Reading and writing .ppm files will be done using two functions:

While doing the first phase of the assignment, you can use the compiled versions of these functions that I have provided. Writing the code for these two functions will be the second phase of the assignment.

The array of pixels may be larger than you'd expect; it will actually be three times the size of the number of pixels in the image. For instance, a 100x100 PPM image would produce an array of size 30,000. This is because each pixel is represented by three numbers: the amount of red, green, and blue light to show for the pixel. Each number ranges from 0 (no light) to 255 (all the light). Here are some example pixel values:


Transforming PPMs

Your file should accept the following keywords for the transformations:

For each of these transformations, your code should be similar to the template for the removeRed function provided in the file filters.cpp.

Phase 1 (Submit by 11:59pm on Friday March 5th)

In the first phase of this assignment, you will implement all the transformations to be applied to the array, except for the flips. To do this, for each transformation, you should add the name of the transformation function in filters.h, implement it in filters.cpp, then modify the code in main.cpp so that the transformation is recognized by the program. Here are a few additional requirements and recommendations on how to proceed for this phase:

  1. Do not write the code for the assignment all at once. Implement the transformation one at a time, and test each transformation as you go along. As part of the starter package, you have the correct solution for each of the transformations applied to one of the pictures. Compare your result with the pictures to test if your program is working correctly.
  2. Do follow the template we gave you in the function maxRed, it will make your code much more elegant and much easier to write and follow (and you will lose style points if you don't).
  3. Each function declared in the .h file should be preceded by a comment that explains what the function does, what each parameter should be and, when application, what the return value is. If you use a function in the .cpp file that is not declared in the .h file, you should put a comment above that function as well.
  4. flipHorizontally and flipVertically are significantly harder than the other transformations. We recommend that you work out the math on paper before attempting to write the code (but note: those transformations are not required for this submission).
Phase 2

By the end of the first week of the assignment, we should have covered in class how to do file input and output. In the second phase of this assignment, you will add a file ppmio.cpp to your project, replace ppmio.o by ppmio.cpp in CMakeLists.txt and implement the functions readFile and writeFile. You should make sure of the following:

The function readFile should make sure that these are truly the case. If not, the function should return nullptr. The function writeFile should write these values at the top of the file, then proceed to write all the values for the pixels, one number per line.

Acknowledgement

This lab write up is based off of Joshua Guerin and Debby Keen's NIFTY 2012 submission titled PPM Image Editor.