Question
USING C++ IF YOU COULD HELP ME WITH PART OF THE CODE (you don't have to complete) Case 8 - Picture This Background Pictures that
USING C++ IF YOU COULD HELP ME WITH PART OF THE CODE (you don't have to complete)
Case 8 - Picture This
Background
Pictures that you take with your phone or download from the Internet are essentially a large number of fields that make up what are known as pixels. Pixels are the small dots on your TV or monitor that can display a blending of three colors: red, green, and blue. You've probably heard of a resolution such as 1920x1080. That means there are 1920 dots spanning the width and 1080 dots spanning the height of your monitor. Essentially, higher the resolution, the more dots and the more "resolute" the picture on your monitor becomes.
Problem
In this lab, you will be reading a file called a portable pixel map (PPM). A portable pixel map is a color picture that has a text format, making it easy to use input file streams to read from. You will be reading from this file, making a series of adjustments, and then outputting the transformed picture to an output file.
Portable Pixel Map File
A portable pixel map (PPM) file has a specific text format:
Clara Van Nguyen has put together a great reference for PPM files and their associated format.
Also, see Wikipedia as another resource.
Pixel Structure (Class)
Prototype a new structure that stores information about a pixel and contains the following members:
Three public integers: red, green, and blue
A public 3-argument constructor that takes three integers: red, green, and blue. This constructor will set the red, green, and blue member variables to the red, green, and blue parameters.
A public 0-argument constructor. This constructor will call the 3-argument constructor and pass 0 for red, green, and blue.
Picture Class
Prototype a new class that stores pixel information in a "vector of vectors" given the following declaration:
vector
The Picture class will contain the following members:
A private vector of vector of pixels (declaration shown above).
private variables for intensity, number of rows, and number of columns
A public function that takes an input file stream and reads a given PPM file into the private vector. This function will return true if the file was able to be fully read, or false otherwise.
A public function that takes an output file stream and writes to a PPM file. This function will return false if the number of rows to write is 0, or true otherwise.
A public function that flips the PPM vector around the Y axis. The resulting PPM file will be "backwards".
A public function that flips the PPM vector around the X axis. The resulting PPM file will be "upside-down".
A public function that will set the red value to zero. This is flattening the red.
A public function that changes the picture into a grey scale image. This is done by averaging the values of all three color numbers for a pixel, the red, green and blue, and then replacing them all by that average. So if the three colors were 25, 75 and 250, the average would be 116, and all three numbers would become 116.
Inputs
Inputs for this program come from command line arguments. There will be either two or three arguments: inputFilename outputFilename optionalModificationCode
You will be reading a PPM file specified by the user in the first user-supplied command line argument (the input file name).
You will be making some sort of modification to the PPM file, which will be provided in a possible third user-supplied argument (modification code) as either Y, X, F or G.
If the user specifies Y, then you will flip the PPM file around the Y axis
If the user specifies X, then you will flip the PPM file around the X axis.
If the user specifies F (for flatten), you will flatten the red value to 0 in all pixels of the PPM file.
If the user specifies G, then you will convert the picture to grey scale.
Finally, if the user doesn't specify anything, you will make no modifications to the PPM file.
You will then write to a separate PPM file specified by the user in the second user-supplied command line argument.
Use the following error messages for the given conditions:
If the user doesn't specify enough arguments output the following error message and return an error code: Note: there could be either 2 or 3 user supplied command line arguments.
Usage: inputfile outputfile [XYFG]
If the user specifies a third command argument, but it is not an X, Y, F or G, output the following message (replace Z with whatever command the user specified), and return an error code:
Error: Z is an invalid command. Use either X, Y, F, or G.
If the result of reading the input file is false (either the file could not be opened or is not valid), output the following error message, and return an error code:
Error: unable to read PPM file 'given input file'
If the output file could not be opened for writing, output the following error message, and return an error code:
Error: unable to write PPM file 'given output file'
If the result of your output member function is false (meaning that the number of rows is 0), output the following error message, and return an error code:
Error: unable to output uninitialized PPM picture
Output
The PPM file that you output will have the following format:
P3
width height
intensity
pixel_row0_col0_red pixel_row0_col0_green pixel_row0_col0_blue
pixel_row0_col1_red pixel_row0_col1_green pixel_row0_col1_blue
...
In other words, you will output the red, green, and blue values of each pixel on a single line. You will output an entire row first (meaning output each column of one row before moving to the next row).
Problem Solving
Determine what your code should do in certain circumstances.
Sample .ppm file: bee.ppm
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started