main-programmingpractice

Update 9/12/2009 - broken link to the sample solution is fixed

1.@ Programming Practice Assignment

This assignment is due on Wednesday, September 16th.

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

  • INFILE is the input file name (e.g. picture.tga)
  • OUTFILE is the output file name (e.g. output.tga)
  • SAT is a floating point number specifying the amount of desaturation (so 0 is no desaturation, 1 is fully desaturated)
  • X Y are integers specifying where the center of a green box should go.

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 BAD LINK.

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.tgaoutfile.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 http://www.cs.wisc.edu/graphics/Courses/559-f2008/Main/LibTargaWrapperDocumentation

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.

If you’re really stuck, you can download a sample solution (here). But make sure you figure things out yourself.

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

A sample solution - completely handed in in a handin directory is in the handin directory for “gleicher”. You can copy it if you want (remember to give proper attribution), but I encourage you to figure things out yourself.

5.2@ General Handin Instructions

Each student has a “handin” directory in p/course/cs559-gleicher/handin (thats p:/course/cs559-gleicher/handin on a windows machine. We will create the directories by Monday, September 14th. 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 “Practice1”.

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

6.@ How will this be graded

We will give you a simple check/no check for completing this assignment. We will probably only look to see if things seem reasonable - we may not test your program extensively. However, the point of this assignment is to make sure you’re ready for the first programming project (coming soon!).

Page last modified on September 12, 2009, at 01:02 PM