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:
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 .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:
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
.
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:
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.
This lab write up is based off of Joshua Guerin and Debby Keen's NIFTY 2012 submission titled PPM Image Editor.