Part 2 - Lab Assignment

Writing your first class: HSLAPixel

Create a class called HSLAPixel whose functionality is described in the Doxygen documentation for HSLAPixel. A few important things to remember:

Understanding HSL Color Space

HSL – hue, saturation, and luminance – is a representation of color that tries to be intuitive and perceptually relevant. HSL can represent all of the colors that can be represented by RGB.

Hue

The hue of a color is the color component – red, green, blue, yellow, etc. Hues are represented on a circle in terms of degrees [0, 360]. For example:

The full hue spectrum can be seen in this image from Wikipedia:

Saturation

The saturation is the intensity of a color, on a scale of [0, 1]. A saturation value of 0 is gray, without color.

Luminance

The luminance is brightness applied to the color, on a scale of [0, 1]. A luminance value of 0 is black and a luminance value of 1 is white. A higher luminance value results in a lighter/whiter version of the same color.

Compile it!

A Makefile has been provided for you for this lab (you’ll make your own soon!). To compile your program, run:

make

If make fails, you will see error messages. We use clang, which aims to provides descriptive error messages that try to help you not only spot the error but also will provide a suggestion on how to fix the bug.

If make runs successfully, you will see three warning messages:

lab_intro.cpp:57:36: warning: unused parameter 'centerX' [-Wunused-parameter]
PNG createSpotlight(PNG image, int centerX, int centerY) {
                                   ^
lab_intro.cpp:57:49: warning: unused parameter 'centerY' [-Wunused-parameter]
PNG createSpotlight(PNG image, int centerX, int centerY) {
                                                ^
lab_intro.cpp:91:35: warning: unused parameter 'secondImage'
[-Wunused-parameter]
PNG watermark(PNG firstImage, PNG secondImage) {
                                  ^

This is expected – you have not written these functions yet.

Writing the PNG manipulation functions

The rest of this lab assignment uses the HSLAPixel class to manipulate an image. A small program has been written in main.cpp that loads alma.png, calls various manipulation functions, and writes out the images as out-_____.png.

All of these manipulation functions are in lab_intro.cpp. The first one, grayscale, has been written for you already and transforms alma.png to grayscale:


alma.png

out-grayscale.png

You should view these files for yourself from your own program to verify they look the same! Continue working through lab_intro.cpp to complete the remaining functions.

Helpful Functions
image.resize(1024, 768);    // Changes the size of the PNG named image to be 1024 (width) by 768 (height) pixels.
image.height();             // Returns the height of the PNG named image.
image.width();              // Returns the width of the PNG named image.
HSLAPixel *pixel = image.getPixel(x, y);  // Gets a pointer to the memory storing the pixel at (x, y)

Compiling the Code

To compile your code, run the following:

make

Testing the Code

After compiling your code, an executable named lab_intro should be located in your working directory. To test your code, run lab_intro:

./lab_intro

This will make several png images as out-*.png in your current directory, where * denotes the manipulation done to the image. You can view it by opening the image or, on the command line, by running:

xdg-open out-grayscale.png
xdg-open out-illinify.png
xdg-open out-spotlight.png
xdg-open out-watermark.png

Submitting Your Work

We’ll be grading all of the labs this semester, and all of the MPs. This part of the lab is critical. If you do not submit your lab or MP code correctly, it could cost you most or all of the points.

For labs, we allow you to work with a partner. Should you choose to work with someone else we require that you submit a text file called partners.txt that contains your and your partners NetID. This file should have one NetID per line and no additional content or whitespace. If you did not collaborate with anyone, the file should contain only your NetID. If we have to manually correct the format of your partners.txt file on a real lab submission, you may lose points. Failure to cite collaborators violates our academic integrity policy; we will be aggressively pursuing such violators.

At the beginning of class, you already checked out a working copy of the code from the class repository. To submit your work, you will need to commit the changes that you have made. First be sure that your working directory is the same that you had checked out from the repository (lab_intro/). You can view the status of the working copy by typing:

svn status

This command asks for the SVN status of all files and directories within the working directory. It returns a list of modified(M), unknown(?) , and added(A) files. If no output appears, then your repository is already up-to-date with your working copy. Any new files that you created and were not previously in the working copy are labeled unknown and may need to be added to it. partners.txt falls into this category and should be added by using the following command:

svn add partners.txt
svn add cs225/HSLAPixel.cpp
svn add cs225/HSLAPixel.h

You can confirm changes made to the working copy by again checking the status. Now that all the important files are either added, modified, or up-to-date, the changes are committed to the repository using the following command:

svn commit -m "lab_intro submission"

The -m flag tells SVN that the quoted message following it should be used as a description of the changes you made. If you forget this flag, you will see a strange message "Editor not set". The string may be empty (""), but it is a good practice to add comments to each revision of your code. In the event of needing to revert to previous revision, the comments will help you differentiate between the revisions. Your repository directory can be viewed from a web browser from the following URL: https://subversion.ews.illinois.edu/svn/fa17-cs225/NETID/, where NETID is your university NetID. It is important to check that the files you expect to be graded are present and up-to-date in your SVN copy.

Autograder Testing

We will be using an autograder to assist in grading your code. The autograder uses a widely used C++ testing library called catch. Some of these test cases are provided for you with the release of every MP and lab. To run the tests, run make test to compile your code with the test cases and then run test to run the tester.

make test
./test

This will run our test cases on your code. For more information on running tests with Catch and interpreting the results, see Testing with Catch.