Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.map.MapPalette Class Reference

Static Public Member Functions

static BufferedImage resizeImage (Image image)
 
static byte[] imageToBytes (Image image)
 
static byte matchColor (int r, int g, int b)
 
static byte matchColor (Color color)
 
static Color getColor (byte index)
 

Static Public Attributes

static final byte TRANSPARENT = 0
 
static final byte LIGHT_GREEN = 4
 
static final byte LIGHT_BROWN = 8
 
static final byte GRAY_1 = 12
 
static final byte RED = 16
 
static final byte PALE_BLUE = 20
 
static final byte GRAY_2 = 24
 
static final byte DARK_GREEN = 28
 
static final byte WHITE = 32
 
static final byte LIGHT_GRAY = 36
 
static final byte BROWN = 40
 
static final byte DARK_GRAY = 44
 
static final byte BLUE = 48
 
static final byte DARK_BROWN = 52
 

Detailed Description

Represents the palette that map items use.

These fields are hee base color ranges. Each entry corresponds to four colors of varying shades with values entry to entry + 3.

Definition at line 14 of file MapPalette.java.

Member Function Documentation

static Color org.bukkit.map.MapPalette.getColor ( byte  index)
static

Get the value of the given color in the palette.

Parameters
indexThe index in the palette.
Returns
The Color of the palette entry.
Deprecated:
Magic value

Definition at line 233 of file MapPalette.java.

233  {
234  if ((index > -113 && index < 0) || index > 127) {
235  throw new IndexOutOfBoundsException();
236  } else {
237  // Minecraft has 143 colors, some of which have negative byte representations
238  return colors[index >= 0 ? index : index + 256];
239  }
240  }
static byte [] org.bukkit.map.MapPalette.imageToBytes ( Image  image)
static

Convert an Image to a byte[] using the palette.

Parameters
imageThe image to convert.
Returns
A byte[] containing the pixels of the image.
Deprecated:
Magic value

Definition at line 167 of file MapPalette.java.

References org.bukkit.map.MapPalette.matchColor().

167  {
168  BufferedImage temp = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
169  Graphics2D graphics = temp.createGraphics();
170  graphics.drawImage(image, 0, 0, null);
171  graphics.dispose();
172 
173  int[] pixels = new int[temp.getWidth() * temp.getHeight()];
174  temp.getRGB(0, 0, temp.getWidth(), temp.getHeight(), pixels, 0, temp.getWidth());
175 
176  byte[] result = new byte[temp.getWidth() * temp.getHeight()];
177  for (int i = 0; i < pixels.length; i++) {
178  result[i] = matchColor(new Color(pixels[i], true));
179  }
180  return result;
181  }
static byte matchColor(int r, int g, int b)
static byte org.bukkit.map.MapPalette.matchColor ( int  r,
int  g,
int  b 
)
static

Get the index of the closest matching color in the palette to the given color.

Parameters
rThe red component of the color.
bThe blue component of the color.
gThe green component of the color.
Returns
The index in the palette.
Deprecated:
Magic value

Definition at line 194 of file MapPalette.java.

Referenced by org.bukkit.map.MapPalette.imageToBytes().

194  {
195  return matchColor(new Color(r, g, b));
196  }
static byte matchColor(int r, int g, int b)
static byte org.bukkit.map.MapPalette.matchColor ( Color  color)
static

Get the index of the closest matching color in the palette to the given color.

Parameters
colorThe Color to match.
Returns
The index in the palette.
Deprecated:
Magic value

Definition at line 207 of file MapPalette.java.

207  {
208  if (color.getAlpha() < 128) return 0;
209 
210  int index = 0;
211  double best = -1;
212 
213  for (int i = 4; i < colors.length; i++) {
214  double distance = getDistance(color, colors[i]);
215  if (distance < best || best == -1) {
216  best = distance;
217  index = i;
218  }
219  }
220 
221  // Minecraft has 143 colors, some of which have negative byte representations
222  return (byte) (index < 128 ? index : -129 + (index - 127));
223  }
static BufferedImage org.bukkit.map.MapPalette.resizeImage ( Image  image)
static

Resize an image to 128x128.

Parameters
imageThe image to resize.
Returns
The resized image.

Definition at line 151 of file MapPalette.java.

151  {
152  BufferedImage result = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB);
153  Graphics2D graphics = result.createGraphics();
154  graphics.drawImage(image, 0, 0, 128, 128, null);
155  graphics.dispose();
156  return result;
157  }

Member Data Documentation

final byte org.bukkit.map.MapPalette.BLUE = 48
static
Deprecated:
Magic value

Definition at line 138 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.BROWN = 40
static
Deprecated:
Magic value

Definition at line 128 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.DARK_BROWN = 52
static
Deprecated:
Magic value

Definition at line 143 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.DARK_GRAY = 44
static
Deprecated:
Magic value

Definition at line 133 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.DARK_GREEN = 28
static
Deprecated:
Magic value

Definition at line 113 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.GRAY_1 = 12
static
Deprecated:
Magic value

Definition at line 93 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.GRAY_2 = 24
static
Deprecated:
Magic value

Definition at line 108 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.LIGHT_BROWN = 8
static
Deprecated:
Magic value

Definition at line 88 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.LIGHT_GRAY = 36
static
Deprecated:
Magic value

Definition at line 123 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.LIGHT_GREEN = 4
static
Deprecated:
Magic value

Definition at line 83 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.PALE_BLUE = 20
static
Deprecated:
Magic value

Definition at line 103 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.RED = 16
static
Deprecated:
Magic value

Definition at line 98 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.TRANSPARENT = 0
static
Deprecated:
Magic value

Definition at line 78 of file MapPalette.java.

final byte org.bukkit.map.MapPalette.WHITE = 32
static
Deprecated:
Magic value

Definition at line 118 of file MapPalette.java.


The documentation for this class was generated from the following file: