Generic cleanup of warnings, whitespace and style.

By: Erik Broes <erikbroes@grum.nl>
This commit is contained in:
Bukkit/Spigot
2011-12-25 16:02:30 +01:00
parent 98960fd73e
commit aaab1cba23
257 changed files with 1408 additions and 1152 deletions

View File

@ -9,15 +9,14 @@ import java.awt.image.BufferedImage;
* Represents the palette that map items use.
*/
public final class MapPalette {
// Internal mechanisms
private MapPalette() {}
private static Color c(int r, int g, int b) {
return new Color(r, g, b);
}
private static double getDistance(Color c1, Color c2) {
double rmean = (c1.getRed() + c2.getRed()) / 2.0;
double r = c1.getRed() - c2.getRed();
@ -28,7 +27,7 @@ public final class MapPalette {
double weightB = 2 + (255 - rmean) / 256.0;
return weightR * r * r + weightG * g * g + weightB * b * b;
}
private static final Color[] colors = {
new Color(0, 0, 0, 0), new Color(0, 0, 0, 0),
new Color(0, 0, 0, 0), new Color(0, 0, 0, 0),
@ -46,9 +45,8 @@ public final class MapPalette {
c(45,45,180), c(55,55,220), c(64,64,255), c(55,55,220),
c(73,58,35), c(89,71,43), c(104,83,50), c(89,71,43)
};
// Interface
/**
* The base color ranges. Each entry corresponds to four colors of varying
* shades with values entry to entry + 3.
@ -67,8 +65,10 @@ public final class MapPalette {
public static final byte DARK_GRAY = 44;
public static final byte BLUE = 48;
public static final byte DARK_BROWN = 52;
/**
* Resize an image to 128x128.
*
* @param image The image to resize.
* @return The resized image.
*/
@ -82,6 +82,7 @@ public final class MapPalette {
/**
* Convert an Image to a byte[] using the palette.
*
* @param image The image to convert.
* @return A byte[] containing the pixels of the image.
*/
@ -90,10 +91,10 @@ public final class MapPalette {
Graphics2D graphics = temp.createGraphics();
graphics.drawImage(image, 0, 0, null);
graphics.dispose();
int[] pixels = new int[temp.getWidth() * temp.getHeight()];
temp.getRGB(0, 0, temp.getWidth(), temp.getHeight(), pixels, 0, temp.getWidth());
byte[] result = new byte[temp.getWidth() * temp.getHeight()];
for (int i = 0; i < pixels.length; i++) {
result[i] = matchColor(new Color(pixels[i]));
@ -103,6 +104,7 @@ public final class MapPalette {
/**
* Get the index of the closest matching color in the palette to the given color.
*
* @param r The red component of the color.
* @param b The blue component of the color.
* @param g The green component of the color.
@ -111,18 +113,19 @@ public final class MapPalette {
public static byte matchColor(int r, int g, int b) {
return matchColor(new Color(r, g, b));
}
/**
* Get the index of the closest matching color in the palette to the given color.
*
* @param color The Color to match.
* @return The index in the palette.
*/
public static byte matchColor(Color color) {
if (color.getAlpha() < 128) return 0;
int index = 0;
double best = -1;
for (int i = 4; i < colors.length; i++) {
double distance = getDistance(color, colors[i]);
if (distance < best || best == -1) {
@ -133,9 +136,10 @@ public final class MapPalette {
return (byte) index;
}
/**
* Get the value of the given color in the palette.
*
* @param index The index in the palette.
* @return The Color of the palette entry.
*/
@ -146,5 +150,5 @@ public final class MapPalette {
return colors[index];
}
}
}