Build on our PBM image creator from (code shown below) to create a fully functional image editor (in C++), using 2D arrays to store our changes. To make it more interesting by switching to the Portable Gray Map standard. 8 bit PGM files have color values ranging from 0 (black) to 255 (white), with the values in-between being shades of gray. The header is very similar to PBM, and looks like this: P2 WIDTH HEIGHT 255 IMAGE_DATA The P2 tells image readers that it is a PGM file, and the 255 indicates the largest possible color value is 255. You will first prompt the user to enter a width, height, and initial color value to fill the image. You should then create a 2D array with those dimensions and initialize each cell with that color value. You will then use a loop to create a menu that repeatedly prompts the user to make one of the following choices: Fill in a pixel with a new color ◦ Prompt the user to enter a row and column value and a new color value. If the array has that row and column index AND the color value is between 0 – 255, change the color at the index. Otherwise, inform the user that it’s an invalid command. Fill in a line with a new color         ◦ Prompt the user to enter a starting row and column value, a new color value, a length value, and a direction          (left, right, up, or down, case sensitive). If all those values are valid, fill in each index in the line with those                values in the 2D array (you can open up a program like Excel if you need help visualizing this) If the row,                  column, color, and/or direction are not correct, inform the user that it’s an invalid command. If the length is correct but would go outside the array (e.g. a length of 20 but the array only has 10 columns), fill in values up to the edge of the array and then stop. Do not cause an ArrayOutOfBounds error. Print the PGM file           ◦ This should print out the contents of a valid PGM image.  Quit

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 5GZ
icon
Related questions
Question

Build on our PBM image creator from (code shown below) to create a fully functional image editor (in C++), using 2D arrays to store our changes. To make it more interesting by switching to the Portable Gray Map standard. 8 bit PGM files have color values ranging from 0 (black) to 255 (white), with the values in-between being shades of gray. The header is very similar to PBM, and looks like this:

P2

WIDTH HEIGHT

255 IMAGE_DATA

The P2 tells image readers that it is a PGM file, and the 255 indicates the largest possible color value is 255.

You will first prompt the user to enter a width, height, and initial color value to fill the image. You should then create a 2D array with those dimensions and initialize each cell with that color value.

You will then use a loop to create a menu that repeatedly prompts the user to make one of the following choices:

  • Fill in a pixel with a new color

◦ Prompt the user to enter a row and column value and a new color value. If the array has that row and column index AND the color value is between 0 – 255, change the color at the index.

Otherwise, inform the user that it’s an invalid command.

  • Fill in a line with a new color

        ◦ Prompt the user to enter a starting row and column value, a new color value, a length value, and a direction          (left, right, up, or down, case sensitive). If all those values are valid, fill in each index in the line with those                values in the 2D array (you can open up a program like Excel if you need help visualizing this) If the row,                  column, color, and/or direction are not correct, inform the user that it’s an invalid command.

If the length is correct but would go outside the array (e.g. a length of 20 but the array only has 10 columns), fill in values up to the edge of the array and then stop. Do not cause an ArrayOutOfBounds error.

  • Print the PGM file

          ◦ This should print out the contents of a valid PGM image. 

  • Quit
60
61
62
63
64
65
66
67
68
69
78172754557 78 79 88 81 82 88
70
73
76
80
83
84
85
86
87
00 00 00
780
88
89
90
91
92
નન
93
94
95
}
{
}
for (int j = 0; j < height_width; j++)
{
}
for (int i = 0; i < size_square; i++)
{
cout << color_border;
}cout << endl;
}
for (int j = 0; j < size_border; j++)
{
}
for (int k = 0; k < size_square; k++ )
cout << color_square;
(int j = 0; j < size_border; j++)
{
}
for
cout << color_border;
{
cout << color_border;
}cout << endl;
for (int i = 0; i < size_border; i++)
{
for (int j = 0; j < height_width; j++)|
{
cout << color_border;
}cout << endl;
cout << endl;
return 0;
Transcribed Image Text:60 61 62 63 64 65 66 67 68 69 78172754557 78 79 88 81 82 88 70 73 76 80 83 84 85 86 87 00 00 00 780 88 89 90 91 92 નન 93 94 95 } { } for (int j = 0; j < height_width; j++) { } for (int i = 0; i < size_square; i++) { cout << color_border; }cout << endl; } for (int j = 0; j < size_border; j++) { } for (int k = 0; k < size_square; k++ ) cout << color_square; (int j = 0; j < size_border; j++) { } for cout << color_border; { cout << color_border; }cout << endl; for (int i = 0; i < size_border; i++) { for (int j = 0; j < height_width; j++)| { cout << color_border; }cout << endl; cout << endl; return 0;
1
include <iostream>
2 using namespace std;
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
WNH NNNNNNNNNH
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
int main()
{
int size_square;
int size_border;
int color_square;
int color_border;
do{
cout << "Enter the size of the square:
cin >> size_square;
if (size_square < 0) {
}
cout << "Invalid input!" << endl;
}
while (size_square < 0);
do{
cout << "Enter the size of the border:
cin >> size_border;
if (size_border < 0) {
}
cout << "Invalid input!" << endl;
}
while (size_border < 0);
do{
cout << "Enter the color of the square:
cin >> color_square;
if (color_square < ℗ || color_square > 1){
"Invalid input!" << endl;
}
cout
}
while (color_square < ℗ || color_square > 1);
do{
cout
cin >> color_border;
if (color_border < 0 || color_border > 1){
"Invalid input!" << endl;
}
"Enter the color of the border:
cout
}
while (color_border < ℗ || color_border > 1);
cout << "PBM File Contents:" << endl;
cout
"P1" << endl;
int total_size;
total_size = size_square + 2
int height_width;
height_width = total_size;
size_border;
cout << total_size <<
for (int i = 0; i < size_border; i++)
<< total_size << endl;
Transcribed Image Text:1 include <iostream> 2 using namespace std; 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 WNH NNNNNNNNNH 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 int main() { int size_square; int size_border; int color_square; int color_border; do{ cout << "Enter the size of the square: cin >> size_square; if (size_square < 0) { } cout << "Invalid input!" << endl; } while (size_square < 0); do{ cout << "Enter the size of the border: cin >> size_border; if (size_border < 0) { } cout << "Invalid input!" << endl; } while (size_border < 0); do{ cout << "Enter the color of the square: cin >> color_square; if (color_square < ℗ || color_square > 1){ "Invalid input!" << endl; } cout } while (color_square < ℗ || color_square > 1); do{ cout cin >> color_border; if (color_border < 0 || color_border > 1){ "Invalid input!" << endl; } "Enter the color of the border: cout } while (color_border < ℗ || color_border > 1); cout << "PBM File Contents:" << endl; cout "P1" << endl; int total_size; total_size = size_square + 2 int height_width; height_width = total_size; size_border; cout << total_size << for (int i = 0; i < size_border; i++) << total_size << endl;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 9 images

Blurred answer
Knowledge Booster
Processes of 3D Graphics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage