Statistics

Problem Statement for "PhotoQuick"

Problem Statement

PROBLEM STATEMENT

Inept Imaging needs your help to develop photo editing software with a
programmatic interface.  Fortunately, their images are very rudimentary and
only consist of white, grey, and black pixels.
Let '.' represent a white pixel, 'x' represent a grey pixel, and '#' represent
a black pixel.  Below is a sample image.


..#####...
..xxxxx...
..x...x...
..x...x...
..xxxxx...
..#####...
..........
..###.xxx.
..#.#.x.x.
..###.xxx.


To be consistent with most graphics programming, the top left corner is (0,0).
Assuming (x,y) coordinates, x increases as the pixels go farther to the right,
and y increases as the pixels go farther down.

Common operations on images include the following:

FILLTOOL - like the paint-bucket tool in many other programs, it fills the
selected region with a given color

ROTATECW - rotates the image 90 degrees clock-wise

ROTATECCW - rotates the image 90 degrees counter clock-wise

DRAWAT - changes a single pixel to the specified color

DRAWRECT - changes all the pixels within the given rectangle to the specified
color

UNDO - reverts the image back to the previous state


DEFINITION

You are to write a class PhotoQuick with method render that takes as parameters
a String[] image, representing the default image buffer, and a String[]
operations, which represents a sequence of commands to perform on the image.
The method returns the resulting image buffer after the sequence of operations.

Class: PhotoQuick
Parameters: String[], String[]
Returns: String[]
Method Signature: String[] render (String[] image, String[] operations)
Be sure to declare your method public.

Below are the possible operations, their formats, and their semantics.

FILLTOOL

format:  "FILLTOOL,c,xxx,yyy"
c must be a single char, either '.', 'x', or '#'
xxx and yyy correspond to x and y coordinates, which must be in bounds.

semantics:
The current region containing the pixel at coordinate (x,y) will be entirely
converted to pixels represented by c.
A region is a set of same-color pixels such that, for any two pixels A and B,
there is a path from A to B where:
1.) Every pixel traversed in the path is the same color as A and B.
2.) The path only moves in the four cardinal directions, up, down, left , or
right (no diagonals).  

DRAWAT

format: "DRAWAT,c,xxx,yyy"
c must be a single char, either '.', 'x', or '#'
xxx and yyy correspond to x and y coordinates, which must be in bounds.

semantics:
The pixel at coordinate (x,y) will be converted into the pixel represented by c

ROTATECW

format: "ROTATECW"

semantics:
The resulting image has a width equal to the original height, and a height
equal to the original width.  Each pixel of the old image belongs in the pixel
of the resulting image as if the buffer were rotated clock-wise by 90 degree.
For example, the upper left-hand corner of the original image becomes the upper
right-hand corner of the resulting image and so on.  The rotation occurs about
the center of the the image buffer.

ROTATECCW

format: "ROTATECCW"

semantics:
The resulting image has a width equal to the original height, and a height
equal to the original width.  Each pixel of the old image belongs in the pixel
of the resulting image as if the buffer were rotated counter clock-wise by 90
degree.  For example, the upper right-hand corner of the original image becomes
the upper left-hand corner of the resulting image and so on.  The rotation
occurs about the center of the the image buffer.

DRAWRECT

format: "DRAWRECT,c,xxx,yyy,aaa,bbb"
c must be a single char, either '.', 'x', or '#'
xxx and yyy correspond to x1 and y1 coordinates, which must be in bounds.
aaa and bbb also correspond to x2 and y2 coordinates, which must be in bounds.

x1 <= x2,
y1 <= y2

semantics:
All the pixels within the closed bounds of the rectangle with (x1,y1) as the
top left corner and (x2,y2) at bottom right corner will be converted into the
pixel represented by c

UNDO

format: "UNDO"

semantics:
UNDO undoes the most previously executed function which was not an UNDO command
and which was not already undone. An UNDO command called on the initial state
of the image does nothing. In other words, for each undo in the sequence of
operations, conceptually remove the first non-undo command previously found in
the sequence. A-B-C-UNDO-D-UNDO-UNDO would cause us to revert to the image just
after operation A. Also, A-B-UNDO-UNDO-UNDO-UNDO-C would result in command C
executed on the initial image. See example 4. 

TopCoder will check the validity of the inputs.  Inputs are valid if all of the
following criteria are met:
-image contains between 1 and 12 elements inclusive
-Each String in image must be the same length, and the length must be between
1-12 inclusive
-Each character of each String in image must be one of the following: '.' 'x' '#'
-commands contains between 1 and 20 elements inclusive
-Each element of commands is one of the formats described above
-Each string in commands can not contain an out of bounds pixel reference




EXAMPLES:

Example 1

image:
.....
.....
..x..
.x.x.
..x..

commands:
DRAWAT,#,0,0
DRAWAT,#,1,1
DRAWAT,#,0,2
FILLTOOL,x,0,1
FILLTOOL,x,2,3

solution should be:

#....
x#...
#.x..
.xxx.
..x..

Example 2

image:
.....
.....
..x..
.x.x.
..x..

ROTATECW
FILLTOOL,#,1,2
ROTATECCW

solution:
.....
.....
..x..
.x#x.
..x..

Example 3

image:
.....
.....
..x..
.x.x.
..x..

ROTATECCW
FILLTOOL,#,1,2
ROTATECW

solution:
#####
#####
##x##
#x.x#
##x##

Example 4

image:
...
...
...

FILLTOOL,x,1,1
FILLTOOL,#,1,1
UNDO
UNDO
UNDO
DRAWRECT,x,0,0,1,1
FILLTOOL,#,0,0
UNDO

solution:
xx.
xx.
...

Definition

Class:
PhotoQuick
Method:
render
Parameters:
String[], String[]
Returns:
String[]
Method signature:
String[] render(String[] param0, String[] param1)
(be sure your method is public)

Constraints

    Examples


      This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
      This problem was used for: