Update 2/7/2010: If you are really stuck on the practice assignment a sample solution is posted here
This assignment is due on Monday, February 8th by 2.30pm
The main objective of this assignment is to make sure that you have figured out the mechanics of doing programming assignments in this class: how to write C++ programs using the supported tools, and to turn things in correctly. Also, to make sure that you can read and write images using the TargaImage library. What your program does with these images doesn't need to be that interesting.
The idea here is to make sure you're ready for the first programming project by getting the mechanics issues out of the way.
Your program must take a set of command line arguments (explained below), read in a TGA image, do something to it (desaturate it and add a green box), and write it back out.
You should use the libtarga library created for this class. We strongly recommend using the TargaImage wrapper for LibTarga. As far as we're concerned in this class, the definition of a targa file is "the files that can be read and written using libtarga." We won't test your program with targa files that libtarga cannot handle.
Your program should take the following arguments (to make sure that you can handle command line arguments):
main INFILE OUTFILE SAT X Y
Your program will read in the image, desaturate it some amount, draw a green box, and write it back out.
Desaturation means removing color - so if SAT=1, the image will be grayscale (R=G=B). If you really can't figure it out, there's a note on saturation below.
We don't really care how big the green box is - but make is big enough that we can see.
Your program should be robust against bad inputs.
Here is an example of running the program on this input image, with the parameters
practice1 input.tga outfile.tga .75 120 100
You can download the header and c file for libtarga from http://www.cs.wisc.edu/graphics/Gallery/LibTarga/
You can download a C++ wrapped for libtarga (recommended to make things easier to use) from LibTarga documentation
Note: these pages are from old versions of the course web. Beware.
You should simply place the 4 files (TargaImage.cpp, TargaImage.h, libtarga.c libtarga.h) in your project.
Libtarga was written back in the old days, before visual studio complained about using the standard C library. If you compile it, you will get warnings like:
1>c:\users\gleicher\559\practice1\libtarga.c(272) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(237) : see declaration of 'fopen'
Good programming practice is to make your programs compile with no errors and no
warnings, so you should probably get rid of these warnings. The easiest way to do
that is to put the macro
_CRT_SECURE_NO_WARNINGS into the project settings
(under "Configuration Properties" "C/C++" "Preprocessor" - add
to the end of the list.
If you need a way to convert between some image format you have (jpg, png) and tga, you can use IrfanView - a free program that is installed on the CSL computers, or one of many other programs.
In the future, you might want to create test images with specific content, so learning about Photoshop, GIMP, or some other image editing program might be a good idea.
For testing your program, you will need to set the command line options within visual studio (e.g. what command line options are passed to the program when you hit "run" or "run with debugger"). Being able to run your program from the command line is nice, but sometimes you'll want the debugger.
To make an image grayscale, set the color channels to be equal.
R = G = B = L
Of course, there's a choice in how to compute L. For the purpose of this assignment, the simplest thing is OK:
L = (R+G+B)/3
Because our eyes are more sensitive to green, an equally bright green, blue, and red will not appear equally bright. This means that if you are converting between color and grayscale, the color red (255,0,0) should not turn into the same brightness as the color green (0,255,0).
The exact ratios vary. One simple one is to say that green is twice as sensitive as red is twice as sensitive as blue, which gives the rations for
R,G,B as 2/7, 4/7, 1/7, or .28, .57, .14. I have also seen systems that
use r = 0.212671, g = 0.715160, b = 0.072169.
The closest thing to an "official" standard is what is used in NTSC (the North American video standard) to compute brightness from colors. That's: Y = 0.30R + 0.59G + 0.11B.
Once you have L, you compute can compute desaturation by interpolating between the original color (SAT=0) and the gray value (SAT=1).
Part of this assignment is to learn about the mechanisms we have for turning things in for this class.
While writing a readme.txt file and giving sample I/O files may seem like overkill for the practice assignment, its meant to make sure everyone can do the mechanics.
You should include an input/output pair of what your program 1 does. Call these input.tga and output.tga. Input.tga should be no bigger than 200 pixels on a side (TGA files are not compressed, so they get to be quite big).
Each student has a "handin" directory in
p:/course/cs559-lizhang/handin on a windows
machine. We have created the directories with your login name. If you do not
have a directory after that date, contact the TA.
Within the handin directories, there will be seperate sub directories for each assignment to turn in. For this assignment, it is "Project1/Practice".
You simply need to put the required files into the appropriate sub-directory. We will use the timestamp of the last file put into this directory as the time things are handed in.
For programming assignments, you must turn in the following:
Important: do not turn in any "binaries" - executables, object files, debugger files, etc. These get pretty big.
To test to make sure things work out OK, you should copy the directory onto the local disk, double click on the solution file, and hit F7 (which is "compile" in visual studio).
For the programming practice, I would expect a directory to have the following files: a readme.txt file, a .sln file, a .vcproj file, your program file (probably just one for the practice assignment), the libtarga files (two source files and two header files), and two targa files (the input/output pair).