Programming assignment #1,
Due: January 11
CSS 342 - Data Structures, Algorithms, and
Discrete Math I – Winter 2018
Programming with images in C++
program is an introduction to programming with images and ensures that you have
some of the programming background necessary to succeed in this course. The
programming aspects of this assignment shouldn’t be difficult. If you find
yourself spending several hours on it, you should consider taking another
programming class to brush up on your skills. Even though this is a short
program, you should still make the program modular and use fail-safe
We will be using Visual
Studio 2017. It is available in the Windows Lab (UW1-310) and the Community
Edition can be freely downloaded from: https://www.visualstudio.com/downloads/
- Post an introduction on the
Introductions thread on the message board.
- Create a new C++ project in
MS Visual Studio called “Program1”.
project should be a Visual C++ - General - Empty Project. Remember where
you save the project. If your project has stdafx.cpp or stdafx.h or
targetver.h, then you did this incorrectly. Your code should compile without
these files and you should not turn them in.
- Download the following
files from the web and place them in …/Program1/Program1/
not change the contents of these files in order to complete this assignment.
- Examine ImageLib.h
to understand the interface for reading and writing GIF images. You should
not be able to access the implementation details of ImageLib.lib. Note
that images are not first-class objects. For example, there are no
constructors or assignment operators that will handle them correctly.
Functions are provided in the library for these purposes.
- Add ImageLib.h and
ImageLib.lib to your project (Project – Add Existing Item).
- Create a new source file in
Program 1 called main.cpp (Project – Add New Item). We are
now ready to start coding.
- Edit main.cpp to
accomplish the following in order:
- Read the image test.gif.
- For every pixel of this
Subtract green mod 15 from the
blue component of the pixel, where green is the green component of the
pixel. The mod operator uses the % symbol.
Add col mod 13 to the red
component of the pixel, col is the column of the pixel.
Do not change the green component of the
for overflow and underflow, since bytes are unable to store values below 0 or
above 255! If you find overflow, set the byte to 255. If you find underflow,
set the byte to 0.
- Create a new image that is
the image from the previous step rotated by 90 degrees counter-clockwise.
The number of rows in the new image will be the number of columns in the
previous image (and vice versa).
- Save the new image to a
file called output.gif.
- Read output.gif into
a new image variable.
- Compare each pixel in the
newly read image to the one that you saved in step d (not the original).
Are there any differences?
- Count and output to the
console the number of pixels that have different values for red, green,
or blue. (If a pixel has a difference in any of the three, then it counts
as one difference.)
- Submit your completed code
(only new code that you wrote, as few as one file) using Catalyst at:
For additional fun
- Apply your code to other
GIF images. Any file with a “.gif” extension should work. What changes
would you make to the images to make them brighter or to have more
- Experiment with different
changes to the input image pixels. Which ones cause the image to be
different after saving and then rereading image?
- After reading an image,
count the frequency of each pixel color (red, green, blue) in the image.
How many different colors are represented? Repeat this after modifying the
image as above and after saving and rereading the modified image. Does
this tell you anything?
- Write a program to
determine whether there is a cat in the image.
This program is worth 10% of
the programming score for the course. See the grading rubric for a breakdown on
how each program is scored.