FSCJ BMP Image Processing Programming Code Script
Assignment #2 Instructions: BMP Image Processing
Through this programming assignment, the students will learn to do the following:
- Learn to read and write binary files.
- Gain more experience with using pointers.
- Gain more experience with dynamic memory allocation and deallocation.
In this assignment, you are asked to 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 given library functions and an example that deal with the bmp file (in a zip file). In the example, the image is flipped horizontally. You are asked to implement some additional functions including the verticalflip(), enlarge() and rotate() functions: the first flips the image vertically, the second is used to enlarge the image by an integer scale factor of 2 or 3; the last one is used to rotate the image either clockwise by 90 degrees or counter-clockwise by 90 degrees.
The program should take the follow command-line options:
% bmptool [-f | -r | -l | -s scale| -v ] [-o output_file] [input_file]
Where -s means to scale the image by a scale factor of 2 or 3 as indicated on the command line with a 2 or a 3, -r means to rotate the image by 90 degrees clockwise, -l means to rotate the image by 90 degrees counter-clockwise, -v means to flip the image vertically and -f means to flip the image horizontally. You can assume for each type (-s, -r, – l, -f, or -v), the command line has at most one option, but that should not affect your code. Only implement each one one time no matter how many times it is included. However, the user may present a combination, say, ‘bmptool -r -s -l -f -v’. If multiple option types are present, the order for processing the image is that you do scale first, then any rotate options, and then flip vertically and finally flip horizontally.
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 2 1.bmp | bmptool -r | 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 memory leaks. Please submit your work through Canvas as one zip file called FirstnameLastnameA2.zip. Follow the instructions below carefully (to avoid unnecessary loss of grade). Include your source code, your Makefile, the bmplib files that I have provided, and the example.bmp file in the zip file. I should be able to create the executable by typing ‘make’. The Makefile should also contain a ‘clean’ target for cleaning up the directory (removing all object files). Make sure you don’t include intermediate files: *.o, executables, *~, etc., in your submission. (There’ll be a penalty for including unnecessary intermediate files).
If the program does not compile and do something useful on ocelot when it runs it will not earn any credit.
Example bmp:
main.c
#include
#include “bmplib.h”
/*
* This method enlarges a 24-bit, uncompressed .bmp file
* that has been read in using readFile()
*
* original – an array containing the original PIXELs, 3 bytes per each
* rows – the original number of rows
* cols – the original number of columns
*
* scale – the multiplier applied to EACH OF the rows and columns, e.g.
*
if scale=2, then 2* rows and 2*cols
*
* new
– the new array containing the PIXELs, allocated within
* newrows – the new number of rows (scale*rows)
* newcols – the new number of cols (scale*cols)
*/
int enlarge(PIXEL* original, int rows, int cols, int scale,
PIXEL** new, int* newrows, int* newcols)
{
/* THIS IS THE METHOD THAT YOU SHOULD WRITE */
return 0;
}
/*
* This method rotates a 24-bit, uncompressed .bmp file that has been read
* in using readFile(). The rotation is expressed in degrees and can be
* positive, negative, or 0 — but it must be a multiple of 90 degrees
*
* original – an array containing the original PIXELs, 3 bytes per each
* rows – the number of rows
* cols – the number of columns
* rotation – a positive or negative rotation,
*
* new
– the new array containing the PIXELs, allocated within
* newrows – the new number of rows
* newcols – the new number of cols
*/
int rotate(PIXEL* original, int rows, int cols, int rotation,
PIXEL** new, int* newrows, int* newcols)
{
/* THIS IS THE METHOD THAT YOU SHOULD WRITE */
return 0;
}
/*
* This method Vertically flips a 24-bit, uncompressed bmp file
* that has been read in using readFile().
*
* original – an array containing the original PIXELs, 3 bytes per each
* rows – the number of rows
* cols – the number of columns
*
* new
– the new array containing the PIXELs, allocated within
*/
int verticalflip (PIXEL *original, PIXEL **new, int rows, int cols)
{
/* THIS IS THE METHOD THAT YOU SHOULD WRITE */
return 0;
}
/*
* This method horizontally flips a 24-bit, uncompressed bmp file
* that has been read in using readFile().
*
* THIS IS GIVEN TO YOU SOLELY TO LOOK AT AS AN EXAMPLE
* TRY TO UNDERSTAND HOW IT WORKS
*
* original – an array containing the original PIXELs, 3 bytes per each
* rows – the number of rows
* cols – the number of columns
*
* new
– the new array containing the PIXELs, allocated within
*/
int flip (PIXEL *original, PIXEL **new, int rows, int cols)
{
int row, col;
if ((rows 0) {
if(mywrite(fd, padding, padAmount) < 0) {
perror("Can't write bitmap");
return -8;
}
}
}
return 0;
}
Top-quality papers guaranteed
100% original papers
We sell only unique pieces of writing completed according to your demands.
Confidential service
We use security encryption to keep your personal data protected.
Money-back guarantee
We can give your money back if something goes wrong with your order.
Enjoy the free features we offer to everyone
-
Title page
Get a free title page formatted according to the specifics of your particular style.
-
Custom formatting
Request us to use APA, MLA, Harvard, Chicago, or any other style for your essay.
-
Bibliography page
Don’t pay extra for a list of references that perfectly fits your academic needs.
-
24/7 support assistance
Ask us a question anytime you need to—we don’t charge extra for supporting you!
Calculate how much your essay costs
What we are popular for
- English 101
- History
- Business Studies
- Management
- Literature
- Composition
- Psychology
- Philosophy
- Marketing
- Economics