I uploaded the assignment
Assignment 1: ImageMaker Portable Pix Map Image Format Specification The portable pix map image format (ppm) is one of the simplest methods of creating an image file. This format is encoded as readable ascii text or viewed as an image with an image viewing program such as gimp. In this assignment, you will make a class that create a ppm image using basic drawing methods. In addition, you will make a driver that can be used to help test the functionality of the class. BE SURE TO READ THE DELIVERABLES! RGB Format P3 4 4 255 0 0 0 200 0 0 0 0 0 155 0 155 0 0 0 0 155 175 0 0 0 0 0 0 0 0 0 0 0 0 0 100 175 0 0 0 255 255 255 0 0 0 0 0 0 155 155 155 The first three lines defines the image header. P3 indicates that the image will use RGB color. The second line indicates width and height. The 255 indicates the maximum value for the color. In the example above colors are between 0-255. Read the following wiki-link for additional details: https://en.wikipedia.org/wiki/Netpbm_format Coordinate System Unlike in math, the standard coordinate system for images starts in the upper left hand corner. https://en.wikipedia.org/wiki/Netpbm_format Class Definition The following is the class definition: const int MAX_WIDTH = 640; const int MAX_HEIGHT = 480; const int MAX_COLOR = 255; enum COLOR {RED, GREEN, BLUE}; using namespace std; class ImageMaker { public: ImageMaker(); ImageMaker(string filename); // Opens image with filename and stores information into void LoadImage(string filename); void SaveImage(string filename); // Size functions int GetWidth(); int GetHeight(); void SetWidth(int width); void SetHeight(int height); // Color functions int GetPenRed(); int GetPenGreen(); int GetPenBlue(); int SetPenRed(int newR); int SetPenGreen(int newG); int SetPenBlue(int newB); // Drawing methods // These methods will use the current red, green, blue values of the pen void DrawPixel(int x, int y); void DrawRectangle(int x1, int y1, int x2, int y2); void DrawLine(int x1, int y1, int x2, int y2); private: int width; int height; int pen_red; // Used by draw functions int pen_green; // Used by draw functions int pen_blue; // Used by draw functions short image[MAX_WIDTH][MAX_HEIGHT][3]; }; Before you start looking at how to implement this class, you must determine and document the appropriate preconditions and postconditions for each operation (See page 139 for examples or preconditions and postconditions). Constructor There are two constructors. The default constructor should create an image with 0 width and 0 height, and set the initial pen color to black (255, 255, 255). The second constructor should load a ppm image into the image matrix and set the width and height accordingly; the default color should be set to black. Draw Functions All draw functions should throw an error if out of bounds values are given. All draw functions use the current pen_red, pen_green and pen_blue values as the “pen” color when drawing. DrawPixel colors the coordinate (x, y) using the current values of the pen_red, pen_green, and pen_blue. DrawRectangle draws a rectangle using the current values of pen_red, pen_green, and pen_blue. (x1, y1) (x2, y2) DrawLine draws a rectangle using the current values of the red, green, and blue. Suppose (x1, y1) (3, 2) (x2, y2) (6, 4) (3,2) (6,4) To figure out the values for y, you will need to figure out the line y = mx + b. In this case, it would be m = (4 – 2)/(6 – 3) = 2/3= 0.6666667 b = y1 – m*x1 = 2 – 0.66667*3 = 0 y = 0.666667x + 0 With this formula, you can figure out the y values for x = 2 … 6. Note that for x = 4 y = 0.66667*4 + 0 = 2.666667 Since there is no pixel for (4, 2.666667), we can just round the y coordinate and use the coordinate (4, 3) instead. DrawRectangle(2, 3, 6, 4) and DrawRectangle(6, 4, 2, 3) should both produce the same line. Test Driver Before this class can become a permanent part of your program library, it must be thoroughly tested. The test driver should support the following test commands: DrawPixel x y Draw a pixel at x, y DrawRectangle x1 y1 x2 y2 Draw a rectangle using the points x1, y1 to x2, y2 DrawLine x1 y1 x2 y2 Draw a line from x1, y1 to x2, y2 SetColor r/g/b value Sets the r, g, or b to value PrintRGB Prints out the values of red, green and blue to the screen SetSize width height Sets the width and height PrintSize Prints out the size Load imagename Loads a ppm image with name imagename Save imagename Saves the image using the name imagename Quit Notes 1. The Load function should throw an error if file is not formatted correctly. The test driver must be able to catch these errors and continue. Be sure to refer to examples given in class. 2. Be sure to refer to the other test driver examples 3. The ImageMaker class must throw an error if bad input is given. The test driver must be able to catch these errors and continue. Be sure to refer to examples given in class. 4. Clarity and formatting will be counted as part of the grade. 5. Pre and post conditions should be included for each method. Deliverables • Your ImageMaker class • Your test driver class • Your test plan as input to the test driver (See page 125 for an example) (THE TEST PLAN IS NOT TRIVIAL AND A SUBSTATIAL PART OF THE GRADE) • The input files used with your test driver • The output files from the test driver Extra Credit Opportunities Extra credit is generally available for all my projects. More difficult extensions receive more points. The following are some ideas for extensions that can be done for extra credit. Points are additive (more features, more points). Additional drawing methods/features (1-10%) Extra credit awarded depending how difficult the drawing method or feature is. For example, a DrawTriangle would have a relatively low extra credit. A filled rectangle would get slightly more points. Additional Notes and Questions Stack overflow error for Visual Studio If you encounter a stack over flow error, it means you need to increase the size of the stack memory used for the program. The following increases the size of the stack to 4mb, which should be large enough to handle most situations for this class. PROJECT Properties Configuration Properties Linker System Stack Reserve Size=4194304 Portable Pix Map Image Format Specification RGB Format Coordinate System Class Definition Constructor Draw Functions Test Driver Notes Deliverables Extra Credit Opportunities Stack overflow error for Visual Studio