Project 1 / Programming Practice

Update 2/7/2010: If you are really stuck on the practice assignment a sample solution is posted here

On this page...

  1. 1. Programming Practice Assignment
  2. 2. What your program must do
  3. 3. Getting LibTarga
  4. 4. A few hints
    1. 4.1 A note on De-Saturation
  5. 5. Turning things in
    1. 5.1 Specific for this Assignment
    2. 5.2 General Handin Instructions

1.  Programming Practice Assignment

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.

2.  What your program must do

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

Where

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
input.tga outfile.tga

3.  Getting LibTarga

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 _CRT_SECURE_NO_WARNINGS to the end of the list.

4.  A few hints

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.

4.1  A note on De-Saturation

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).

5.  Turning things in

Part of this assignment is to learn about the mechanisms we have for turning things in for this class.

5.1  Specific for this Assignment

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).

5.2  General Handin Instructions

Each student has a "handin" directory in /p/course/cs559-lizhang/handin (thats 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:

  1. A "readme.txt" file explaining what you are turning in, what features your program has, any thing we should know about how to build it, any attributions for code that you have taken from somewhere, etc.
  2. All of the files required to build the program. This includes a Visual Studio ".sln" and ".vcproj" file, and all source and header files. Any code that you are using (like the targa library files) needs to be included, but the libraries (FlTk and OpenGL - for future assignments) do not.
  3. Any required sample input/output pairs.

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).