-
Notifications
You must be signed in to change notification settings - Fork 0
/
Picture.java
218 lines (180 loc) · 6.15 KB
/
Picture.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.text.*;
import java.util.*;
import java.util.List; // resolves problem with java.awt.List and java.util.List
/**
* A class that represents a picture. This class inherits from
* SimplePicture and allows the student to add functionality to
* the Picture class.
*
* @author Barbara Ericson ericson@cc.gatech.edu
*
* 02-27-15 altered by Leon Schram
* This file is made shorter to focus on the Lab15b assignment.
*
*/
//////////////////////////////////////////////////////////////////////////
//
// This is the student starting file of the Lab15b assignment.
//
// This is the only file that students use to write their methods.
//
//////////////////////////////////////////////////////////////////////////
public class Picture extends SimplePicture
{
///////////////////// constructors //////////////////////////////////
/**
* Constructor that takes no arguments
*/
public Picture ()
{
/* not needed but use it to show students the implicit call to super()
* child constructors always call a parent constructor
*/
super();
}
/**
* Constructor that takes a file name and creates the picture
* @param fileName the name of the file to create the picture from
*/
public Picture(String fileName)
{
// let the parent class handle this fileName
super(fileName);
}
/**
* Constructor that takes the width and height
* @param height the height of the desired picture
* @param width the width of the desired picture
*/
public Picture(int height, int width)
{
// let the parent class handle this width and height
super(width,height);
}
/**
* Constructor that takes a picture and creates a
* copy of that picture
* @param copyPicture the picture to copy
*/
public Picture(Picture copyPicture)
{
// let the parent class do the copy
super(copyPicture);
}
/**
* Constructor that takes a buffered image
* @param image the buffered image to use
*/
public Picture(BufferedImage image)
{
super(image);
}
////////////////////// methods ///////////////////////////////////////
/**
* Method to return a string with information about this picture.
* @return a string with information about the picture such as fileName,
* height and width.
*/
public String toString()
{
String output = "Picture, filename " + getFileName() +
" height " + getHeight()
+ " width " + getWidth();
return output;
}
////////////////////////////////////////////////////////////////////////
// REQUIRED FOR 80-POINTS
public void grayScale()
{
Pixel[][] arr = getPixels2D();
for(int i = 0; i < arr.length; ++i) {
for(int j = 0; j < arr[i].length; ++j) {
Pixel p = arr[i][j];
int sum = (int)(0.299 *p.getRed() + 0.587* p.getGreen() + 0.114 * p.getBlue()) ;
p.setColor(new Color(sum,sum,sum));
}
}
}
//////////////////////////////////////////////////////////////////////////
// REQUIRED FOR 80-POINTS
public void mirror()
{
Pixel[][] arr = getPixels2D();
for(int i = 0; i < arr.length; ++i){
for(int j = 0; j < arr[i].length / 2; ++j) {
Color c = arr[i][j].getColor();
Color c2 = arr[i][arr[j].length - j - 1 ].getColor();
arr[i][j].setColor(c2);
arr[i][arr[j].length - j - 1].setColor(c);
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
// REQUIRED FOR 80-POINTS
public void upsideDown()
{
Pixel[][] arr = getPixels2D();
for(int i = 0; i < arr.length / 2; ++i){
for(int j = 0; j < arr[i].length; ++j) {
Color c = arr[i][j].getColor();
Color c2 = arr[arr.length - i - 1][j].getColor();
arr[i][j].setColor(c2);
arr[arr.length - i - 1][j].setColor(c);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////
// REQUIRED FOR 90-POINTS
public void mirrorVertical()
{
Pixel[][] arr = getPixels2D();
for(int i = 0; i < arr.length; ++i){
for(int j = 0; j < arr[i].length / 2; ++j) {
Color c = arr[i][j].getColor();
arr[i][arr[j].length - j - 1].setColor(c);
}
}
}
//////////////////////////////////////////////////////////////////////////////////
// REQUIRED FOR 90-POINTS
public void mirrorHorizontal()
{
Pixel[][] arr = getPixels2D();
for(int i = 0; i < arr.length / 2; ++i){
for(int j = 0; j < arr[i].length; ++j) {
Color c = arr[i][j].getColor();
arr[arr.length - i - 1][j].setColor(c);
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////
// REQUIRED FOR 90-POINTS
public void mirrorDiagonal()
{
Pixel[][] arr = getPixels2D();
for(int i = 0; i < arr.length ; ++i){
for(int j = 0; j < arr.length ; ++j) {
if(i >= arr[j].length )
break;
Color c = arr[j][i].getColor();
arr[i][j].setColor(c);
}
}
}
/////////////////////////////////////////////////////////////////////////////////////
// REQUIRED FOR 100-POINTS
public void mirrorTemple()
{
Pixel[][] arr = getPixels2D();
for(int i = 0; i < (int)(arr.length / 4.5); ++i){
for(int j = 0; j < arr[i].length / 2; ++j) {
Color c = arr[i][j].getColor();
arr[i][arr[j].length - j - 1].setColor(c);
}
}
}
}