Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 (Links to an external site.)Links to an external site. 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> 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 seconduser-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

...

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_2

Step: 3

blur-text-image_3

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions

Question

Describe the Indian constitution and political system.

Answered: 1 week ago

Question

Explain in detail the developing and developed economy of India

Answered: 1 week ago

Question

Problem: Evaluate the integral: I = X 52+7 - 1)(x+2) dx

Answered: 1 week ago

Question

What is gravity?

Answered: 1 week ago

Question

What is the Big Bang Theory?

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago