-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxMin.java
238 lines (237 loc) · 6.17 KB
/
MaxMin.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
* Stores the Max RGB for a set, stored in an array
* in P4CStarter, used to combine the sets.
*
*/
public class MaxMin {
/** Variable for min red part of pixel. */
private int redmin = -1;
/** Variable for min green part of pixel. */
private int greenmin = -1;
/** Variable for min blue part of pixel. */
private int bluemin = -1;
/** Variable for max red part of pixel. */
private int redmax = -1;
/** Variable for max green part of pixel. */
private int greenmax = -1;
/** Variable for max blue part of pixel. */
private int bluemax = -1;
/** Count for keeping track of combines.*/
private int count = 1;
/**
* Default constructor.
*/
public MaxMin() {
}
/**
* Constructor that takes in a vertex.
* @param v generic vertex to take in.
*/
public MaxMin(GVertex<Pixel> v) { // init
this.redmin = v.data().getred();
this.greenmin = v.data().getgreen();
this.bluemin = v.data().getblue();
this.redmax = v.data().getred();
this.greenmax = v.data().getgreen();
this.bluemax = v.data().getblue();
}
/**
* Get min red part.
* @return min red part
*/
public int getrmin() {
return this.redmin;
}
/**
* Get min green part.
* @return min green part
*/
public int getgmin() {
return this.greenmin;
}
/**
* Get min blue part.
* @return min blue part
*/
public int getbmin() {
return this.bluemin;
}
/**
* Get max red part.
* @return max red part
*/
public int getrmax() {
return this.redmax;
}
/**
* Get max green part.
* @return max green part
*/
public int getgmax() {
return this.greenmax;
}
/**
* Get max blue part.
* @return max blue part
*/
public int getbmax() {
return this.bluemax;
}
/**
* Set min red part.
* @param r red component
*/
public void setrmin(int r) {
this.redmin = r;
}
/**
* Set min green part.
* @param r green component
*/
public void setgmin(int r) {
this.greenmin = r;
}
/**
* Set min blue part.
* @param r blue component
*/
public void setbmin(int r) {
this.bluemin = r;
}
/**
* Set max red part.
* @param r red component
*/
public void setrmax(int r) {
this.redmax = r;
}
/**
* Set max green part.
* @param r grenn component
*/
public void setgmax(int r) {
this.greenmax = r;
}
/**
* Set max blue part.
* @param r blue component
*/
public void setbmax(int r) {
this.bluemax = r;
}
/**
* Get pixels in sets.
* @return int of count
*/
public int getCount() {
return this.count;
}
/**
* Set pixels in sets.
* @param r
*/
public void setCount(int r) {
this.count = r;
}
/**
* If greater/equal, add all to it and increase count.
* @param j a MaxMin to combine.
*/
public void combine(MaxMin j) {
if (this.count >= j.getCount()) {
this.redmin = Math.min(this.redmin, j.getrmin());
this.greenmin = Math.min(this.greenmin, j.getgmin());
this.bluemin = Math.min(this.bluemin, j.getbmin());
this.redmax = Math.max(this.redmax, j.getrmax());
this.greenmax = Math.max(this.greenmax, j.getgmax());
this.bluemax = Math.max(this.bluemax, j.getbmax());
this.count = this.count + j.getCount();
} else {
j.setrmin(Math.min(this.redmin, j.getrmin())); // edit j
j.setgmin(Math.min(this.greenmin, j.getgmin()));
j.setbmin(Math.min(this.bluemin, j.getbmin()));
j.setrmax(Math.max(this.redmax, j.getrmax()));
j.setgmax(Math.max(this.greenmax, j.getgmax()));
j.setbmax(Math.max(this.bluemax, j.getbmax()));
j.setCount(j.getCount() + this.count);
}
}
/**
* Diff in max and min components of red.
* @return the difference
*/
public int diffr() {
int red = this.redmax - this.redmin;
return red;
}
/**
* Diff in max and min components of green.
* @return the difference
*/
public int diffg() {
int green = this.greenmax - this.greenmin;
return green;
}
/**
* Diff in max and min components of blue.
* @return the difference
*/
public int diffb() {
int blue = this.bluemax - this.bluemin;
return blue;
}
/**
* Calculate the diff for each color if they
* would be combined with something else for red.
* @param j diff to calculate for color
* @return the difference.
*/
public int diffrc(MaxMin j) {
int temprmax = this.redmax;
int temprmin = this.redmin;
if (temprmax < j.getrmax()) {
temprmax = j.getrmax();
}
if (temprmin > j.getrmin()) {
temprmin = j.getrmin();
}
int red = temprmax - temprmin;
return red;
}
/**
* Calculate the diff for each color if they
* would be combined with something else for green.
* @param j diff to calculate for color
* @return the difference.
*/
public int diffgc(MaxMin j) {
int tempgmax = this.greenmax;
int tempgmin = this.greenmin;
if (tempgmax < j.getgmax()) {
tempgmax = j.getgmax();
}
if (tempgmin > j.getgmin()) {
tempgmin = j.getgmin();
}
int green = tempgmax - tempgmin;
return green;
}
/**
* Calculate the diff for each color if they
* would be combined with something else for blue.
* @param j diff to calculate for color
* @return the difference.
*/
public int diffbc(MaxMin j) {
int tempbmax = this.bluemax;
int tempbmin = this.bluemin;
if (tempbmax < j.getbmax()) {
tempbmax = j.getbmax();
}
if (tempbmin > j.getbmin()) {
tempbmin = j.getbmin();
}
int blue = tempbmax - tempbmin;
return blue;
}
}