Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need some help with c++ here are the instructions. here is the code i have so far. the one part i need the most

i need some help with c++

here are the instructions.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedhere is the code i have so far.

image text in transcribedimage text in transcribed

the one part i need the most help with is the function

  • void stripedDiagonalPattern( std::istream& is, std::ostream& os, PPM& p );
Portable Pixmap Format The Portable Pixmap Format (PPM) is an open definition digital image file format. It defines how to store data in a file such that another program can read the file and correctly display the image that was stored. PPM Image File Format A PPM image has a width, a height, and a maximum color value. The width is the number of pixels in a row. The height is the number of rows in the image. The maximum color value is the highest number that can be stored in one channel of a pixel. Each PPM image is allowed to have a different maximum color value. This allows the image file to decide what number represents 100% brightness. In our implementation, the maximum color value will need to be at least 1 but no more than 255. As you work on this assignment, it will be useful to know the way a PPM image is stored in a file. The file header information is text (ASCII) words, separated by white space. After the newline character that follows the maximum color value, the rest of the data in the file is binary (not-ASCII), with one byte per color channel, or three bytes per pixel. There are no newlines or other white space characters in the pixel data. P6 WIDTH HEIGHT MAX_COLOR_VALUE BINARY REPRESENTATION OF COLORS FOR EACH PIXEL IN THE SAME ORDER AS THE COLOR FILE Assignment In this assignment, you will update the project from the previous assignment. You will add code to be able to store the additional information needed for a PPM image, in addition to the Image information. You will also create a program to create a PPM image using an algorithm to set the pixel values, using an image size specified by the user. Finally, the program will save the image to a PPM format file, using the name specified by the user. Potential Session $ ./image_file Image height? 350 Image width? 250 Output filename? assignment3.ppm $ ls -l assignment3.ppm -rw-rw-r-- 1 cgl cgl 262515 Sep 17 19:03 assignment3.ppm This image appears this: This image appears like this: W Download the ppm file Programming Requirements Create PPM.h This file must include the declaration of the PPM class. The PPM class must inherit from the Image class that already exists, so you don't have to recreate all of the data storage code. The PPM class must have an integer data member to store the maximum color value. Your PPM class must have the following methods. PPM(); The default constructor. A default PPM has max color value of 1, and a default constructed Image portion. PPM( const int& height, const int& width ); The max color value should be set to 1. The Image portion should be initialized with the height and width parameters. int getMaxColorvalue () const; Returns the maximum color value of the PPM. bool valuevalid( const int& value ) const; Checks if value is a legal color value for this image. Legal means at least 0 and no more than the maximum color value. Returns true if it is legal, false otherwise. void setMaxColorvalue( const int& max_color_value ); Change the maximum color value of the PPM. Only values 1 to 255, inclusive should be accepted. If the value is not accepted, make no changes. void setChannel ( const int& row, const int& column, const int& channel, const int & value ); If value is valid (use the valuevalid method), then call Image::setChannel() passing in the parameters. If value is not valid, do nothing. void setPixel ( const int& row, const int& column, const int& red, const int& green, const int& blue ); Set all three channels for the specified pixel. Should use setChannel to do the work. void writestream (std::ostream& os) const; Writes the PPM data to the output stream os. Uses the format mentioned above. The first line of data is ASCII text, and the rest is binary data. Create PPM.cpp This file must implement all of the methods of the PPM class declared in PPM.h. Update image_menu.h Add the following function declarations to the file. void writeUserImage ( std::istream& is, std::ostream& os, const PPM& p ); void stripedDiagonalPattern( std::istream& is, std::ostream& os, PPM& p); int assignment3( std::istream& is, std::ostream& os ); Update image_output.cpp This file must include the implementations for these functions: void writeUserImage ( std::istream& is, std::ostream& os, const PPM& p); Uses getString to ask the user for the Output filename?, opens the output file in binary mode, writes the PPM object to the stream (using writeStream), and closes the file stream Update image_drawing.cpp Implement the following functions: void stripedDiagonalPattern( std::istream& is, std::ostream& os, PPM& p ); Description of the stripedDiagonalPattern () Function This function will use getInteger to ask the user for the height of an image and again for the width of an image. The questions must be asked in the order demonstrated in the potential session with identical prompts. Sets the height and width of the PPM parameter using the height and width specified by the user Sets the maximum color value of the Sets the height and width of the PPM parameter, using the height and width specified by the user. Sets the maximum color value of the object to the sum of the height and the width, divided by 3. If this value is larger than 255, sets the maximum color value to 255 instead. For examples: if the height and width are 300 and 200, then the maximum color value will be (300 + 200)/3 = 166. However, if the height and width are 500 and 400, then the maximum color will be 255, because (500 + 400)/3 = 300 which is greater than 255. If a pixel is in the top half of the image, sets the red channel of the pixel to 0. If a pixel is in the bottom half of the image and the row number is a multiple of 3, sets the red channel of the pixel to 0. If a pixel is in the bottom half of the image, and the row number is not a multiple of 3, sets the red channel to the maximum color value. column 1) divided by one more than the maximum color value. Sets the green channel of a pixel to the remainder of (row + width Read that sentence carefully to get the math correct. Sets the blue channel of a pixel to 0 if the column number is less than the row. Otherwise, sets the blue channel to the maximum color value. When determining top half vs bottom half or left half vs right half, consider that x/2 results in an integer, when x is an integer. The top half of the image includes all rows who are strictly less than half of the height. The left half of the image includes all columns who are strictly less than half of the width. (Note: if the user gives nonsense values for height, width or filename, the image saved will not make sense, and it's their fault, not yours.) Update controllers.cpp Implement the following functions: int assignment3( std::istream& is, std::ostream& os ); Creates a default constructed PPM object. Calls stripedDiagonalPattern and writeUserImage. Returns 0. Create image_file.cpp This file must include the implementations of the following functions: int main(); This function should call assignment3, passing in std::cin and std::cout as the input and output streams to use. This function should return what assignment3 returns. Update Makefile This file must now also include the rules to build the program image_file. The following commands should work correctly. make hello - builds the hello program make questions_3 - builds the questions_3 program malee Benimace builds the ascii image program File Edit Selection View Go Run Terminal Help PPM. -Src - Visual Studio Code EXPLORER M Makelile C PPM.h X L CPPM.cpp Cimace menu Image.cpp image output.cpp C PPM.h> 6 class PPM: public Image { public: 8 PPM(); 9 PPM( const int& height, const int& width ); 10 int get MaxColorvalue() const; 11 bool valuevalidt const int& value ) const; 12 void selMaxcolorValue( const int& max_color_value ); 13 void setChannel( const int& row, const int& column, const int& channel, const int& value); 14 void setPixel( const int& row, const int& column, const int& red, const int& green, const int& blue ); 15 void writestrean(std::ostream& os) const; 16 private: 17 int mMaxcolor; 18 19 20 21 #ridif V OPEN EDITORS 2 UNSAVED M Makefile X C PPMH 2 . PPM.cpp 2 4 C image_menuh 2 Image.cpp 2 image_output.cpp 3 V SRC V vscode Esci_image ascii_image.cpp E asci_imagco controllers.cpp controllers.o hello chello.cpp hello image drawing app image_drawing.o Cimage_menuh 4 image_cubulepp 3 image_outputo Imagespp 2 C Image.h Image.o M Makefile C PPM.CPP 2 CPPM. 2 question 3.cpp questions 2 questions_3.cpp questions_3.0 22 23 > OUTLINE Tab Moves Focus In 3, Col 19 Spaces: 4 UTF-8 CRLF C++ Win32 RO File Edit Selection View Go Run Terminal Help - PPM.cpp - SIC - Visual Studio Code EXPLORER M Makelile pp.h G PPM.cpp Cimace menu L Image.cpp image output.cpp PPM.cpp). 1 #include "PPM.h" 2 Hinclude "Image.h" 3 4 5 7 8 PPM::PPMO; : Image(), maxcolor - 1 10 11 12 13 } PPM::PPM( const int& height, const int& width ) : Tmage(width, height), maxColor = 10 14 15 16 17 V OPEN EDITORS 2 UNSAVED M Makefile CPPMH 2 CPPM.cpp 2 C image_menuh 4 image.cpp 2 image_output.cpp 3 V SRC V vscode Esci_image ascii_image.cpp E asci_imageo controllers.cpp controllers.o hello chello.cpp hello image drawing.cpp image_drawing.o C image_menuh 4 4 image_cutulepp 3 image_outputo Imagespp 2 C Image.h Image.o M Makefile CPPM.CPP 2 CPPM. / 2 question 3.cpp questions? questions_3.cpp questions_3.0 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 } int PPM::getMaxcolorvalue() const{ return maxcolor: } bool PPM::valuevalid( const int& value ) const ( if (value >-&& value - 1 && max_color_value OUTLINE Tab Moves Focus In 43, Col1 Spaces: 4 UTF-8 CRLF C++ Win32 RO Portable Pixmap Format The Portable Pixmap Format (PPM) is an open definition digital image file format. It defines how to store data in a file such that another program can read the file and correctly display the image that was stored. PPM Image File Format A PPM image has a width, a height, and a maximum color value. The width is the number of pixels in a row. The height is the number of rows in the image. The maximum color value is the highest number that can be stored in one channel of a pixel. Each PPM image is allowed to have a different maximum color value. This allows the image file to decide what number represents 100% brightness. In our implementation, the maximum color value will need to be at least 1 but no more than 255. As you work on this assignment, it will be useful to know the way a PPM image is stored in a file. The file header information is text (ASCII) words, separated by white space. After the newline character that follows the maximum color value, the rest of the data in the file is binary (not-ASCII), with one byte per color channel, or three bytes per pixel. There are no newlines or other white space characters in the pixel data. P6 WIDTH HEIGHT MAX_COLOR_VALUE BINARY REPRESENTATION OF COLORS FOR EACH PIXEL IN THE SAME ORDER AS THE COLOR FILE Assignment In this assignment, you will update the project from the previous assignment. You will add code to be able to store the additional information needed for a PPM image, in addition to the Image information. You will also create a program to create a PPM image using an algorithm to set the pixel values, using an image size specified by the user. Finally, the program will save the image to a PPM format file, using the name specified by the user. Potential Session $ ./image_file Image height? 350 Image width? 250 Output filename? assignment3.ppm $ ls -l assignment3.ppm -rw-rw-r-- 1 cgl cgl 262515 Sep 17 19:03 assignment3.ppm This image appears this: This image appears like this: W Download the ppm file Programming Requirements Create PPM.h This file must include the declaration of the PPM class. The PPM class must inherit from the Image class that already exists, so you don't have to recreate all of the data storage code. The PPM class must have an integer data member to store the maximum color value. Your PPM class must have the following methods. PPM(); The default constructor. A default PPM has max color value of 1, and a default constructed Image portion. PPM( const int& height, const int& width ); The max color value should be set to 1. The Image portion should be initialized with the height and width parameters. int getMaxColorvalue () const; Returns the maximum color value of the PPM. bool valuevalid( const int& value ) const; Checks if value is a legal color value for this image. Legal means at least 0 and no more than the maximum color value. Returns true if it is legal, false otherwise. void setMaxColorvalue( const int& max_color_value ); Change the maximum color value of the PPM. Only values 1 to 255, inclusive should be accepted. If the value is not accepted, make no changes. void setChannel ( const int& row, const int& column, const int& channel, const int & value ); If value is valid (use the valuevalid method), then call Image::setChannel() passing in the parameters. If value is not valid, do nothing. void setPixel ( const int& row, const int& column, const int& red, const int& green, const int& blue ); Set all three channels for the specified pixel. Should use setChannel to do the work. void writestream (std::ostream& os) const; Writes the PPM data to the output stream os. Uses the format mentioned above. The first line of data is ASCII text, and the rest is binary data. Create PPM.cpp This file must implement all of the methods of the PPM class declared in PPM.h. Update image_menu.h Add the following function declarations to the file. void writeUserImage ( std::istream& is, std::ostream& os, const PPM& p ); void stripedDiagonalPattern( std::istream& is, std::ostream& os, PPM& p); int assignment3( std::istream& is, std::ostream& os ); Update image_output.cpp This file must include the implementations for these functions: void writeUserImage ( std::istream& is, std::ostream& os, const PPM& p); Uses getString to ask the user for the Output filename?, opens the output file in binary mode, writes the PPM object to the stream (using writeStream), and closes the file stream Update image_drawing.cpp Implement the following functions: void stripedDiagonalPattern( std::istream& is, std::ostream& os, PPM& p ); Description of the stripedDiagonalPattern () Function This function will use getInteger to ask the user for the height of an image and again for the width of an image. The questions must be asked in the order demonstrated in the potential session with identical prompts. Sets the height and width of the PPM parameter using the height and width specified by the user Sets the maximum color value of the Sets the height and width of the PPM parameter, using the height and width specified by the user. Sets the maximum color value of the object to the sum of the height and the width, divided by 3. If this value is larger than 255, sets the maximum color value to 255 instead. For examples: if the height and width are 300 and 200, then the maximum color value will be (300 + 200)/3 = 166. However, if the height and width are 500 and 400, then the maximum color will be 255, because (500 + 400)/3 = 300 which is greater than 255. If a pixel is in the top half of the image, sets the red channel of the pixel to 0. If a pixel is in the bottom half of the image and the row number is a multiple of 3, sets the red channel of the pixel to 0. If a pixel is in the bottom half of the image, and the row number is not a multiple of 3, sets the red channel to the maximum color value. column 1) divided by one more than the maximum color value. Sets the green channel of a pixel to the remainder of (row + width Read that sentence carefully to get the math correct. Sets the blue channel of a pixel to 0 if the column number is less than the row. Otherwise, sets the blue channel to the maximum color value. When determining top half vs bottom half or left half vs right half, consider that x/2 results in an integer, when x is an integer. The top half of the image includes all rows who are strictly less than half of the height. The left half of the image includes all columns who are strictly less than half of the width. (Note: if the user gives nonsense values for height, width or filename, the image saved will not make sense, and it's their fault, not yours.) Update controllers.cpp Implement the following functions: int assignment3( std::istream& is, std::ostream& os ); Creates a default constructed PPM object. Calls stripedDiagonalPattern and writeUserImage. Returns 0. Create image_file.cpp This file must include the implementations of the following functions: int main(); This function should call assignment3, passing in std::cin and std::cout as the input and output streams to use. This function should return what assignment3 returns. Update Makefile This file must now also include the rules to build the program image_file. The following commands should work correctly. make hello - builds the hello program make questions_3 - builds the questions_3 program malee Benimace builds the ascii image program File Edit Selection View Go Run Terminal Help PPM. -Src - Visual Studio Code EXPLORER M Makelile C PPM.h X L CPPM.cpp Cimace menu Image.cpp image output.cpp C PPM.h> 6 class PPM: public Image { public: 8 PPM(); 9 PPM( const int& height, const int& width ); 10 int get MaxColorvalue() const; 11 bool valuevalidt const int& value ) const; 12 void selMaxcolorValue( const int& max_color_value ); 13 void setChannel( const int& row, const int& column, const int& channel, const int& value); 14 void setPixel( const int& row, const int& column, const int& red, const int& green, const int& blue ); 15 void writestrean(std::ostream& os) const; 16 private: 17 int mMaxcolor; 18 19 20 21 #ridif V OPEN EDITORS 2 UNSAVED M Makefile X C PPMH 2 . PPM.cpp 2 4 C image_menuh 2 Image.cpp 2 image_output.cpp 3 V SRC V vscode Esci_image ascii_image.cpp E asci_imagco controllers.cpp controllers.o hello chello.cpp hello image drawing app image_drawing.o Cimage_menuh 4 image_cubulepp 3 image_outputo Imagespp 2 C Image.h Image.o M Makefile C PPM.CPP 2 CPPM. 2 question 3.cpp questions 2 questions_3.cpp questions_3.0 22 23 > OUTLINE Tab Moves Focus In 3, Col 19 Spaces: 4 UTF-8 CRLF C++ Win32 RO File Edit Selection View Go Run Terminal Help - PPM.cpp - SIC - Visual Studio Code EXPLORER M Makelile pp.h G PPM.cpp Cimace menu L Image.cpp image output.cpp PPM.cpp). 1 #include "PPM.h" 2 Hinclude "Image.h" 3 4 5 7 8 PPM::PPMO; : Image(), maxcolor - 1 10 11 12 13 } PPM::PPM( const int& height, const int& width ) : Tmage(width, height), maxColor = 10 14 15 16 17 V OPEN EDITORS 2 UNSAVED M Makefile CPPMH 2 CPPM.cpp 2 C image_menuh 4 image.cpp 2 image_output.cpp 3 V SRC V vscode Esci_image ascii_image.cpp E asci_imageo controllers.cpp controllers.o hello chello.cpp hello image drawing.cpp image_drawing.o C image_menuh 4 4 image_cutulepp 3 image_outputo Imagespp 2 C Image.h Image.o M Makefile CPPM.CPP 2 CPPM. / 2 question 3.cpp questions? questions_3.cpp questions_3.0 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 } int PPM::getMaxcolorvalue() const{ return maxcolor: } bool PPM::valuevalid( const int& value ) const ( if (value >-&& value - 1 && max_color_value OUTLINE Tab Moves Focus In 43, Col1 Spaces: 4 UTF-8 CRLF C++ Win32 RO

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

The Ages Of The Investor A Critical Look At Life Cycle Investing

Authors: William J Bernstein

1st Edition

1478227133, 978-1478227137

Students also viewed these Databases questions