This program implements the basic functionalities of a simple image editing software (such as Microsoft Paint), for a PPM-style image format, including crop, resize, color region, blur, rotate and fill.
The image is represented through a matrix of pixels, where a pixel is represented by three bytes (ranging from 0 to 255) according to the RGB (Red, Green, Blue) model.
The equivalent PPM format is as follows:
P3
width height
255
byte matrix of size 3 * width x height
For example:
P3
2 3
255
0 0 255 0 255 0
255 0 0 128 0 128
255 255 255 0 0 0
Commands are given as their respective code (opCode) followed by the right parameters, as follows:
opCode [p1 p2 p3...]
1 width height
byte matrix of size 3 * width x height
2 3
0 0 255 0 255 0
255 0 0 128 0 128
255 255 255 0 0 0
- 1 ≤ height ≤ 1024
- 1 ≤ width ≤ 1024
- 0 ≤ r, g, b ≤ 255
The current image is overwritten by the image delimited by the rectangle between the given coordinates.
2 start_col start_line end_col end_line
(0, 0, 255) (0, 255, 0) (255, 0, 0)
(0, 128, 0) (0, 255, 0) (0, 128, 0)
2 0 0 1 0
(0, 0, 255) (0, 255, 0)
- 0 ≤ start_line ≤ end_line < current image height
- 0 ≤ start_col ≤ end_col < current image width
Modifies the dimensions of the image. If one dimension is larger than the original image, the new lines/columns will be filled by white pixels. If the dimensions are smaller, the operation is equivalent with a crop instruction.
3 width height
(0, 0, 255) (0, 255, 0) (255, 0, 0)
(0, 128, 0) (0, 255, 0) (0, 128, 0)
3 1 3
(0, 0, 255)
(0, 128, 0)
(255, 255, 255)
- 1 ≤ height ≤ 1024
- 1 ≤ width ≤ 1024
The rectangle delimited by the given coordinates will be colored with (r g b) pixels.
4 start_col start_line end_col end_line r g b
(0, 0, 255) (0, 255, 0) (255, 0, 0)
(0, 128, 0) (0, 255, 0) (0, 128, 0)
4 1 0 2 1 100 150 200
(0, 0, 255) (100, 150, 200) (100, 150, 200)
(0, 128, 0) (100, 150, 200) (100, 150, 200)
- 0 ≤ start_line ≤ end_line < Înaltimea curentă a imaginii
- 0 ≤ start_col ≤ end_col < Lățimea curentă a imaginii
- 0 ≤ r, g, b ≤ 255
The blur effect implies replacing each pixel with the average of its neighbors (up, down, left, right). This operation will be repeated num_iter times.
5 num_iter
(0, 0, 255) (0, 255, 0) (255, 0, 0)
(0, 128, 0) (0, 255, 0) (0, 128, 0)
5 1
(0, 191, 0) (85, 85, 85) (0, 191, 0)
(0, 127, 127) (0, 170, 0) (127, 127, 0)
- 0 ≤ num_iter ≤ 2000
The image is rotated num_rot times by 90 degrees.
6 num_rot
(0, 0, 255) (0, 255, 0) (255, 0, 0)
(0, 128, 0) (0, 255, 0) (0, 128, 0)
6 1
(0, 128, 0) (0, 0, 255)
(0, 255, 0) (0, 255, 0)
(0, 128, 0) (255, 0, 0)
- 0 ≤ num_iter ≤ 3
The pixel at (start_line, start_col) will be overwritten by (r, g, b) pixels. The operation is repeated recursively for all its neighbors that have the same color as the original pixel at (start_line, start_col).
7 start_col start_line r g b
(0, 0, 255) (10, 10, 10) (255, 0, 0) (10, 10, 10)
(10, 10, 10) (0, 255, 0) (10, 10, 10) (10, 10, 10)
(10, 10, 10) (10, 10, 10) (10, 10, 10) (10, 15, 10)
7 2 1 42 42 42
(0, 0, 255) (10, 10, 10) (255, 0, 0) (42, 42, 42)
(42, 42, 42) (0, 255, 0) (42, 42, 42) (42, 42, 42)
(42, 42, 42) (42, 42, 42) (42, 42, 42) (10, 15, 10)
- 0 ≤ start_line < current image height
- 0 ≤ start_col < current image width
- 0 ≤ r, g, b ≤ 255
The image is printed with the known format.
8
(0, 0, 255) (0, 255, 0) (255, 0, 0)
(0, 128, 0) (0, 255, 0) (0, 128, 0)
3 2
0 0 255 0 255 0 255 0 0
0 128 0 0 255 0 0 128 0
The program exits successfully.
0