Today I am going to give a quick tutorial on the Whodunit portion of Problem Set 4. Next week I will go over Resize, and the following week I will cover Recover. As I said this will be a quick tutorial, as I am flying out to Virginia Beach today to learn all about Industry 4.0, including machine learning and automation. So, let’s dig right in.

The biggest learning potential you will have from this problem will be the ability to read and understand the source code that is provided. Implementing the code changes will be fairly short, once we understand what the rest of the code is doing. The beginning of this file should look fairly similar to ones that we have done in the past. We are just making sure that the user has provided us with the correct amount of command line arguments. Then the program sets a pointer to the file that we will be loading and another one for the file that we will produce after some manipulation. Next, the program opens the file provided as read only. If the file is empty the program throws an error. The same is done for the output file, except the file is opened as write only.

Next, the program reads the given files BITMAPFILEHEADER and BITMAPINFOHEADER. The information in the previous links will tell you what these two items are and why they are in the file. The next few lines of code examines items in the file header and info header to make sure we are working with a 24 bit compressed bitmap. It then writes the file header and info header for the output file, making it equal to the input file. The function to determine the padding is given to us next. You can take for granted that this works, and we will reuse this in subsequent exercises.  The next portion is where the program will iterate over the scanlines and write each line to the output file. The original version of copy.c simply copies the file. But, we need to do a little more in this section if we want to find out Whodunit.

The program will read each RGBTRIPLE in the input file and them write them into the output file. In between is where our code will go, because we want to manipulate the triple before it is written to the output file.  My implementation is very simple. First I change any triple that is red to white. Next, I change all the white pixels to black. This gives us the image that is at the start of this blog. Now, I encourage you to mess around with some other colors and see if you can get your image even more clear than the one I have. The last step in the program is where it iterates over the padding and then closes both files. It is very important to make sure we close files after we have opened them and this will be shown in subsequent exercises where we will implement more of the program ourselves.

So, go give Whodunit a shot and let men know how your implementation turns out. Remember to share this post if you found it helpful, by clicking on your favorite social media below. Go out there and figure out Whodunit and as always…Happy Programming!

One comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s