Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPicture.java
More file actions
Latest commit
executable file
·215 lines (195 loc) · 6.64 KB
/
Copy pathPicture.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
importjava.awt.*;
importjava.awt.font.*;
importjava.awt.geom.*;
importjava.awt.image.BufferedImage;
importjava.text.*;
importjava.util.*;
importjava.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
*/
publicclassPictureextendsSimplePicture
{
///////////////////// constructors //////////////////////////////////
/**
* Constructor that takes no arguments
*/
publicPicture ()
{
/* 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
*/
publicPicture(StringfileName)
{
// 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
*/
publicPicture(intheight, intwidth)
{
// 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
*/
publicPicture(PicturecopyPicture)
{
// let the parent class do the copy
super(copyPicture);
}
/**
* Constructor that takes a buffered image
* @param image the buffered image to use
*/
publicPicture(BufferedImageimage)
{
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.
*/
publicStringtoString()
{
Stringoutput = "Picture, filename " + getFileName() +
" height " + getHeight()
+ " width " + getWidth();
returnoutput;
}
/** Method to set the blue to 0 */
publicvoidzeroBlue()
{
Pixel[][] pixels = this.getPixels2D();
for (Pixel[] rowArray : pixels)
{
for (PixelpixelObj : rowArray)
{
pixelObj.setBlue(0);
}
}
}
/** Method that mirrors the picture around a
* vertical mirror in the center of the picture
* from left to right */
publicvoidmirrorVertical()
{
Pixel[][] pixels = this.getPixels2D();
PixelleftPixel = null;
PixelrightPixel = null;
intwidth = pixels[0].length;
for (introw = 0; row < pixels.length; row++)
{
for (intcol = 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 */
publicvoidmirrorTemple()
{
intmirrorPoint = 276;
PixelleftPixel = null;
PixelrightPixel = null;
intcount = 0;
Pixel[][] pixels = this.getPixels2D();
// loop through the rows
for (introw = 27; row < 97; row++)
{
// loop from 13 to just before the mirror point
for (intcol = 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
*/
publicvoidedgeDetection(intedgeDist)
{
PixelleftPixel = null;
PixelrightPixel = null;
Pixel[][] pixels = this.getPixels2D();
ColorrightColor = null;
for (introw = 0; row < pixels.length; row++)
{
for (intcol = 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
*/
publicvoidaveragePics(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.
*/
publicvoidcropAndCopy( PicturesourcePicture, intstartSourceRow, intendSourceRow,
intstartSourceCol, intendSourceCol, intstartDestRow, intstartDestCol )
{
}
/* Main method for testing - each class in Java can have a main
* method
*/
publicstaticvoidmain(String[] args)
{
Picturebeach = newPicture("beach.jpg");
beach.explore();
beach.zeroBlue();
beach.explore();
}
} // this } is the end of class Picture, put all new methods before this