Remember to create a new directory in your repository for this lab. (Refer to previous labs for how if you have forgotten)
You have two tasks to complete before your lab. First, read about images and #define. Then answer the questions in lab4questions.html.
Second, copy over the header file and skeleton implementation file for the functions you will implement in the warmup during lab. More detailed directions follow.For the warmup and homework, you will be using png, a standard image format for storing pictures (png stands for "portable network graphics"). The png format exists independent of C programming; it is a complex compressed image format that you can produce (or consume) with programs written in any language. It is fairly efficient representation, and compresses images without any loss in quality (also known as lossless compression). This fact will be very useful in our upcoming assignment. Learning the PNG format is beyond the scope of this assignment; we will provide the functions that enable you to read and write PNG files. However, you still have to understand how images can be represented digitally.
An image can be represented as an array of pixels. Each pixel has an associated color. Colors in programs are stored as a series of three values: rgb - red, green, and blue. In our png format, we will allow the values to range from no color (0) to full saturated (255). Any color can be created using these three numbers. As you would expected, red is (255,0,0), green is (0,255,0), and blue is (0,0,255). When combining colors, though, you need to remember that these are light palettes, not paint palettes. Therefore, white is the saturation of all colors of light (255,255,255), and black is the absence of light (0,0,0). To get the values for red, orange, yellow, green, blue, and purple, you can look at this website.
In this assignment, you will be working with arrays of these red, green and blue values. We will provide functions that can read and write PNG files. These functions are defined in hw4_provided.h and hw4_provided.c), namely the provided_read_png and provided_write_png functions. For this assignment, you can simply invoke these functions in your code, and do not need to understand how they work. In order to compile your code, you will need a library called libpng installed on your system. If you are having trouble setting up the environment, it is suggested that you use the linux.cs.uchicago.edu machines, which already have this library installed.
If you are running MacOS which has Homebrew installed you can probably run:
brew install libpng
On Linux or Bash for Windows you can run this:
sudo apt install libpng-dev
If you are running Cygwin, it might be a bit harder, but i suggest installing apt-cyg and running:
apt-cyg install libpng-devel
To compile the provided functions, you can simply call:
clang -c -Wall -o hw4_provided.o hw4_provided.c
To link this function correctly using the png library with your own solutions, we add the -lpng flag to clang:
clang -Wall -lpng -o hw4 hw4_provided.o warmup4.c warmup4_main.c
These operations should be added to your Makefile.
The functions are designed to only read certain types of PNG files for this assignment. For those who are interested in the details, the files must be:
Here are a set of PNG files that have been tested to work with these functions. You may use them for your warmup and hw4. If you would like to use your own images, you may do so by editing them in an image editor (Photoshop, GIMP, etc.) to comply with the specifications above, at your own peril!
You read about #define last assignment. We are going to use #define to set the rows and columns that we support for pictures. It will look something like this:
#define HOWDY 9
This command tells the pre-processor to go through all of the files (after it reads #define) and replace every string "HOWDY" with the number 5. The reason we use all caps is that we don't want to accidentally have "HOWDY" in something else. For example, if we did the following:
#define a 5If we had the following code:
char my_function(char x, char y)
The pre-processor would replace all fo the 'a''s with 5. This would break all of our code. Therefore, pre-processor commands are both powerful and very, very stupid. They are only to be used in particular circumstances.
During the warmup, you are going to implement several functions that exercise arrays and pointers.
In order to spend your time efficiently in lab, you need to start with a
skeleton that compiles. Copy and paste them into your own files and
verify that you can compile. Remember the special flag. If you can't
compile, the TAs will help you in lab.
You will need
warmup4_main.c,
warmup4.h,
warmup4.c.
,
hw4_provided.h and
hw4_provided.c
Skim over the lab so you know what you will be doing.
Count the number of vowels (a,e,i,o,u) in the string. str is an in parameter. You may NOT use any library calls within count_vowels.
Modify the string so that all capital letters ('A'-'Z') are changed to their corresponding lower-case letters. str is both an in parameter and an out parameter. You may NOT use any library calls within make_lowercase.
In this problem, the red, green, and blue arrays are out parameters. They will contain the pixels for a width x height striped image. It will contain horizontal stripes, in which every stripe has width stripe_height. The color of the top stripe is (stripe_red, stripe_green, stripe_blue). The color of the next stripe is black. They alternate from there.
If stripe_height is 0, then the entire picture is black.
If width > COLS or height > ROWS, then print out an error.
The result of make_horizontal_stripes(r, g, b, 1, 30, 144, 255, 12, 12) is at horiz_stripes.html. This corresponds to horiz_stripes.png.
In this problem, you will fill in a picture with dimensions widthxheight. The red, green, and blue arrays are again out parameters. They will contain the pixels for a width x height checkerboard image. In the checkboard pattern, each square has width and height square_width. The color of one square is (square_red, square_green, square_blue). The color of the other square is white.
If square_width is 0, then the entire picture is white.
If width > COLS or height > ROWS, then print out an error.
The result of make_checker_board(r,g,b,4,30,144,255, 12, 12) is at checkerboard.html. This corresponds to checkerboard.png.