ECE 1021

HOMEWORK #8

(Last Modified: 27 Nov 2010 )

PROGRAM A - Complex Math

Programming Problem #10.3 (p545).

PROGRAM B - Extend the BMP program

Create a structure called BMP that holds all of the data (or pointers to the data) associated with a Windows Bitmap File. Write primitive functions to manipulate this data. Just like the FILE structure, the goal is to have BMP be a black box that is passed to any function that needs to interact with the file.

For instance, some obvious functions might:

In general, for each data element in the BMP structure there should be a function that returns the value of that element (or some kind of information about it) and a function that sets the value of the element.

From a functionality standpoint, the code that you turn in does not need to do anything beyond what the program for the B&W image converter does. The difference is that you are to significantly clean up the code by using structures and function calls. You should also read the entire image into memory, convert the image in memory, and then write the image out to the new file.

As an example, your main() might end up looking something like:

int main(void)
{
    char *bmp_infilename;
    char *bmp_outfilename;

    BMP *bmp;

    int errcode;

    PrintHeader();

    printf("Enter the name of the color BMP file to read (w/ext): ");
    bmp_infilename = GetFileName();

    printf("Enter the name of the B&W BMP file to create (w/ext): ");
    bmp_outfilename = GetFileName();

    bmp = NewBMP(); // Create a new BMP structure for the data

    errcode = ImportBMP(bmp, bmp_infilename); // Import data from input file
    if(errcode)
    {
        printf("Error #%i detected reading %s\n", errcode, bmp_infilename);
        return(errcode);
    }

    DisplayBMP_STATS(bmp);
    ConvertToGray(bmp); // Convert Image to Grayscale

    errcode = ExportBMP(bmp, bmp_outfilename); // Export data to output file
    if(errcode)
    {
        printf("Error #%i detected writing %s\n", errcode, bmp_outfilename);
        return(errcode);
    }

    printf("Conversion Complete.\n");
    return(0);
}