Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C language program where you must manipulate an image from a 24-bit uncompressed bmp file. (The format of bmp files is given in

Write a C language program where you must manipulate an image from a 24-bit uncompressed bmp file. (The format of bmp files is given in http://en.wikipedia.org/wiki/BMP_file_format). To help with reading and writing the image file. You are asked to implement the enlarge() and rotate() functions: the former is used to enlarge the image by an integer scale factor; the latter is to rotate the image either clockwise or counter-clockwise by a certain degree (which must be a multiple of 90) depending whether the rotation degree is positive or negative.

The program should take the follow command-line options:

% bmptool [-s scale | -r degree | -f ] [-o output_file] [input_file]

Where -s means to scale the image by the given 'scale' (a positive integer: 1, 2, 3, ...), -r means to rotate the image by 'degree' (which must be a multiple of 90, clockwise if positive, counter-clockwise if negative), and -f means to flip the image horizontally. You can assume for each type (-s, -r, or -f), the command line has at most one option. That is, the user is not supposed to do something like "./bmptool -s 2 -s 4". If that happens, you can either prompt error, or take either 2 or 4 as the scale. However, the user may present a combination, say, './bmptool -r 90 -s 4'. If multiple option types are present, the order for processing the image is that you do scale first, then rotate, and then flip.

You are required to use getopt() to process the command-line. If '-o output_file' is missing, use standard output. If 'input_file' is missing, use standard input. The options to use standard input or standard output will only be used when chaining commands.

Make sure the program returns 0 on success. In that case, one can 'chain' the commands using pipes, like:

% bmptool -s 4 1.bmp | bmptool -r -90 | bmptool -f -o 2.bmp

Your program needs to provide necessary sanity-check for command line arguments and handle various error conditions and prompt the user with helpful information. You need to use getopt() to process the command line arguments. Test your program with various combinations to make sure it works as expected. You must use dynamic memory to store the content of the new image before writing out to file. You need to reclaim memory afterwards to prevent from memory leaks.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago