I need to build on our PBM image creator from (code shown below) to create a fully functional image editor, using 2D arrays to store our changes. We’ll also make it a little 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. 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. You should be able to copy and paste the output into a file and load it in the same way as you did with the PBM file (shown below) – the only difference is that the extension should be .pgm. Quit

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Hi, can you help mw with this question?  Thanks!

Art Program.

I need to build on our PBM image creator from (code shown below) to create a fully functional image editor, using 2D arrays to store our changes. We’ll also make it a little 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. 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. You should be able to copy and paste the output into a file and load it in the same way as you did with the PBM file (shown below) – the only difference is that the extension should be .pgm.

  • 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
steps

Step by step

Solved in 2 steps with 9 images

Blurred answer
Knowledge Booster
Image Element
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education