Skip to content

Commit a066ea9

Browse files
committed
directly init closestColor
1 parent 734634c commit a066ea9

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/main/java/bwapi/Color.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,16 @@ public class Color {
5454
RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, RGBRESERVE, new RGBQUAD(255, 255, 255)
5555
};
5656

57-
private static boolean rgbInitialized;
5857
private static final byte[][][] closestColor = new byte[64][64][64];
58+
static {
59+
for (int r = 0; r < 64; ++r) {
60+
for (int g = 0; g < 64; ++g) {
61+
for (int b = 0; b < 64; ++b) {
62+
closestColor[r][g][b] = (byte) getBestIdFor(r << 2, g << 2, b << 2);
63+
}
64+
}
65+
}
66+
}
5967
public final int id;
6068

6169
public Color(final int r, final int g, final int b) {
@@ -92,16 +100,6 @@ private static int getBestIdFor(final int red, final int green, final int blue)
92100
}
93101

94102
private static int getRGBIndex(final int red, final int green, final int blue) {
95-
if (!rgbInitialized) {
96-
rgbInitialized = true;
97-
for (int r = 0; r < 64; ++r) {
98-
for (int g = 0; g < 64; ++g) {
99-
for (int b = 0; b < 64; ++b) {
100-
closestColor[r][g][b] = (byte) getBestIdFor(r << 2, g << 2, b << 2);
101-
}
102-
}
103-
}
104-
}
105103
return closestColor[(byte) (red >> 2)][(byte) (green >> 2)][(byte) (blue >> 2)];
106104
}
107105

0 commit comments

Comments
 (0)