-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPicture.java
More file actions
executable file
·215 lines (195 loc) · 6.64 KB
/
Picture.java
File metadata and controls
executable file
·215 lines (195 loc) · 6.64 KB
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
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
*/
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;
}
/** Method to set the blue to 0 */
public void zeroBlue()
{
Pixel[][] pixels = this.getPixels2D();
for (Pixel[] rowArray : pixels)
{
for (Pixel pixelObj : rowArray)
{
pixelObj.setBlue(0);
}
}
}
/** Method that mirrors the picture around a
* vertical mirror in the center of the picture
* from left to right */
public void mirrorVertical()
{
Pixel[][] pixels = this.getPixels2D();
Pixel leftPixel = null;
Pixel rightPixel = null;
int width = pixels[0].length;
for (int row = 0; row < pixels.length; row++)
{
for (int col = 0; col < width / 2; col++)
{
leftPixel = pixels[row][col];
rightPixel = pixels[row][width - 1 - col];
rightPixel.setColor(leftPixel.getColor());
}
}
}
/** Mirror just part of a picture of a temple */
public void mirrorTemple()
{
int mirrorPoint = 276;
Pixel leftPixel = null;
Pixel rightPixel = null;
int count = 0;
Pixel[][] pixels = this.getPixels2D();
// loop through the rows
for (int row = 27; row < 97; row++)
{
// loop from 13 to just before the mirror point
for (int col = 13; col < mirrorPoint; col++)
{
leftPixel = pixels[row][col];
rightPixel = pixels[row][mirrorPoint - col + mirrorPoint];
rightPixel.setColor(leftPixel.getColor());
}
}
}
/** Method to show large changes in color
* @param edgeDist the distance for finding edges
*/
public void edgeDetection(int edgeDist)
{
Pixel leftPixel = null;
Pixel rightPixel = null;
Pixel[][] pixels = this.getPixels2D();
Color rightColor = null;
for (int row = 0; row < pixels.length; row++)
{
for (int col = 0;
col < pixels[0].length-1; col++)
{
leftPixel = pixels[row][col];
rightPixel = pixels[row][col+1];
rightColor = rightPixel.getColor();
if (leftPixel.colorDistance(rightColor) >
edgeDist)
leftPixel.setColor(Color.BLACK);
else
leftPixel.setColor(Color.WHITE);
}
}
}
/**
* Sets each pixel in this picture to the average of the corresponding pixels in the specified
* list of pictures.
*
* @param pictures the specifies list of pictures to average
*
* precondition: this picture and all pictures in the list have the same number of rows and cols
*/
public void averagePics(ArrayList<Picture> pictures)
{
}
/**
* Method to copy a region of the specified source Picture object into this Picture object
* at the specified location.
*
* @param sourcePicture the picture from which to copy
* @param startSourceRow the row in the source picture from which to start copying (inclusive)
* @param endSourceRow the row in the source picture at which to stop copying (exclusive)
* @param startSourceCol the column in the source picture from which to start copying (inclusive)
* @param endSourceCol the column in the source picture at which to stop copying (exclusive)
* @param startDestRow the row in the destination picture (this picture) into which to start
* copying (inclusive)
* @param startDestCol the column in the destination picture (this picture) into which to start
* copying (inclusive)
*
* @precondition The destination Picture object must be large enough to fit the copied Picture.
*/
public void cropAndCopy( Picture sourcePicture, int startSourceRow, int endSourceRow,
int startSourceCol, int endSourceCol, int startDestRow, int startDestCol )
{
}
/* Main method for testing - each class in Java can have a main
* method
*/
public static void main(String[] args)
{
Picture beach = new Picture("beach.jpg");
beach.explore();
beach.zeroBlue();
beach.explore();
}
} // this } is the end of class Picture, put all new methods before this