ECE 1021
HOMEWORK #7
(Last Modified: 27 Nov 2010 )
The primary portion of this assignment is to write the functions needed to perform very basic manipulations of Windows Bitmap Files. Your program needs to open a suitable BMP file, read image data from the file, perform a very basic manipulation of that data, and write that data back out to the file. The manipulation is very simple - for each pixel, get the red-blue-green values (an RGB triplet) and replace each with the RMS value of the triplet. This will convert the image from a color image to a black and white image.
Information about the structure of a BMP file can be found in the reference material for the course.
It turns out that the function malloc(), in Turbo C/C++ v4.5, is only capable of allocating a block of memory that is 65535 - (64K - 1) - bytes long. What is the maximum width of a 4:3 aspect ratio image that you can store in an array if it is represented in 24-bit color?
What if we want to work with an image larger than that? The key to doing so is to note that while a given call to malloc() can only allocate 65535 bytes of memory, multiple calls to malloc() can allocate multiple blocks as long as the operating system has sufficient memory to meet the request. So to store an 1024x768 24-bit image, which requires about 2.4MB of memory, you would need to call malloc() a minimum of 37 times.
However, each call to malloc() gets a different block of memory and these blocks may not be contiguous. So you need a means of breaking up your image into appropriately sized chunks and storing each chunk in it's own block. At the same time, you would like the bulk of your code to be written in such a way as to hide the fact that this is being done.
Think of how you might like your basic graphics functions to be used. If you wanted to set the red component of the pixel in row 653 and column 289 to a value of 145, you might want to have a function call that looks like:
image = ??? ; // A pointer to the memory that the image is stored in
row = 653;
col = 289;
component = RED; // RED is a #define constant
intensity = 145;
SetPixel(image, row, col, component, value);
You don't need to worry about what "image" is at this point. Your task is to devise a means to map a given row, column, and component value to a specific location in one of these blocks of memory.
Your submission for this should include the code needed to demonstrate that your approach works. A simple way to do this is to create an ASCII image of 20x20 where each character is stored in an array but where the maximum dimension of a single character array is 63 characters. One way to demonstrate that your approach really does work is to randomly generate characters to be stored into the image and print them on the left side of the screen based on their row and column number and then store them into the image data based on those same numbers. Then, after the data has been generated and stored, use the image data to plot the same display of characters on the right hand side of the screen.
Note: This is something you are going to need to be able to do for the Koch Snowflake programs, so why not get a head start and claim some extra credit at the same time?