Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++: Problem You will be reading a file called a portable pixel map (PPM). A portable pixel map is a color picture that has

IN C++:

Problem

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.

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> picture_data;

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).

Thanks in advance!

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

Database Security XI Status And Prospects

Authors: T.Y. Lin, Shelly Qian

1st Edition

0412820900, 978-0412820908

More Books

Students also viewed these Databases questions