/** * Initialize the map palette * * @return Map pallete */ private static IColorPalette getMapPalette() { List<Color> result = new ArrayList<Color>(); try { for (int i = 0; i < 256; i++) { Color c = MapPalette.getColor((byte)i); if (c.getAlpha()<128) { continue; } result.add(c); } } catch (Exception ex) { //Ignore exception } return new ColorPalette(result.toArray(new Color[0])); }
/** * Initialize new instance of the class * @param img The image to draw on the map */ public ImgRenderer(BufferedImage img) { super(false); int hh = Math.min(img.getHeight(), MAX_SIZE); int ww = Math.min(img.getWidth(), MAX_SIZE); BufferedImage lImg; if (hh != MAX_SIZE || ww != MAX_SIZE) { lImg = new BufferedImage(MAX_SIZE, MAX_SIZE, BufferedImage.TYPE_4BYTE_ABGR); Graphics g = lImg.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); } else { lImg = img; } m_isRendered = false; m_img = MapPalette.imageToBytes(lImg); }
public void drawImage(int x, int y, Image image) { byte[] bytes = MapPalette.imageToBytes(image); for (int x2 = 0; x2 < image.getWidth(null); ++x2) { for (int y2 = 0; y2 < image.getHeight(null); ++y2) { setPixel(x + x2, y + y2, bytes[y2 * image.getWidth(null) + x2]); } } }
public void drawText(int x, int y, MapFont font, String text) { int xStart = x; byte color = MapPalette.DARK_GRAY; if (!font.isValid(text)) { throw new IllegalArgumentException("text contains invalid characters"); } for (int i = 0; i < text.length(); ++i) { char ch = text.charAt(i); if (ch == '\n') { x = xStart; y += font.getHeight() + 1; continue; } else if (ch == '\u00A7') { int j = text.indexOf(';', i); if (j >= 0) { try { color = Byte.parseByte(text.substring(i + 1, j)); i = j; continue; } catch (NumberFormatException ex) {} } } CharacterSprite sprite = font.getChar(text.charAt(i)); for (int r = 0; r < font.getHeight(); ++r) { for (int c = 0; c < sprite.getWidth(); ++c) { if (sprite.get(r, c)) { setPixel(x + c, y + r, color); } } } x += sprite.getWidth() + 1; } }
/** * Create a new map from an image * * @param image Image * @return Map */ @SuppressWarnings("deprecation") public static CustomMap fromImage(Image image) { CustomMap customMap = new CustomMap(MapUtils.IDS--, image.getWidth(null), image.getHeight(null)); customMap.bytes = MapPalette.imageToBytes(image); return customMap; }
public BPMap(String name, GameType gameType, int minPlayers, int maxPlayers, double fallDamageMultiplier) { this.name = name; this.gameType = gameType; this.minPlayers = minPlayers; this.maxPlayers = maxPlayers; this.fallDamageMultiplier = fallDamageMultiplier; image = loadImage(); image = MapPalette.resizeImage(image); }
@SuppressWarnings("deprecation") private void renderMap(MapState state, int sectionX, int sectionZ, MapCanvas canvas) { MapSection section = state.getMapSection(sectionX, sectionZ); for (int x = 0; x < 128; x++) { for (int z = 0; z < 128; z++) { byte pixel = section.getPixel(x, z); if(pixel != Byte.MAX_VALUE && pixel != MapPalette.TRANSPARENT){ canvas.setPixel(x, z, pixel); } } } }
public MapSection(){ mapData = new byte[128][128]; byte min = MapPalette.TRANSPARENT; for(int index = 0; index < 128; index++){ for(int index2 = 0; index2 < 128; index2++){ mapData[index][index2] = min; } } }
public synchronized byte getPixel(int x, int z){ if((x > -1 && x < 128 && z > -1 && z < 128)){ return mapData[x][z]; } Bukkit.getLogger().warning("Invalid Map Get Cordinates: " + x + " " + z); return MapPalette.TRANSPARENT; }
public void setImage(Image image) { this.image = image; image = MapPalette.resizeImage(image); this.data = MapPalette.imageToBytes(image); this.width = image.getWidth(null); this.height = image.getHeight(null); this.redraw(); }
@SuppressWarnings("deprecation") public void setPixel(int x, int y, byte color) { if (x < 0 || y < 0 || x > CANVAS_WIDTH || y > CANVAS_HEIGHT) return; pixels[x + y * CANVAS_WIDTH] = color; // Map colors in advance. if (color != MapPalette.TRANSPARENT && !dyeColors.containsKey(color)) { java.awt.Color mapColor = MapPalette.getColor(color); Color targetColor = Color.fromRGB(mapColor.getRed(), mapColor.getGreen(), mapColor.getBlue()); // Find best dyeColor DyeColor bestDyeColor = null; Double bestDistance = null; for (DyeColor testDyeColor : DyeColor.values()) { Color testColor = testDyeColor.getColor(); double testDistance = ColorHD.getDistance(testColor, targetColor); if (bestDistance == null || testDistance < bestDistance) { bestDistance = testDistance; bestDyeColor = testDyeColor; if (testDistance == 0) break; } } dyeColors.put(color, bestDyeColor); } }
@SuppressWarnings("deprecation") public DyeColor getDyeColor(int x, int y) { byte color = getPixel(x, y); if (color == MapPalette.TRANSPARENT) return null; if (!dyeColors.containsKey(color)) return null; return dyeColors.get(color); }
@SuppressWarnings("deprecation") public void drawImage(int x, int y, Image image) { byte[] bytes = MapPalette.imageToBytes(image); for (int x2 = 0; x2 < image.getWidth(null); ++x2) { for (int y2 = 0; y2 < image.getHeight(null); ++y2) { setPixel(x + x2, y + y2, bytes[y2 * image.getWidth(null) + x2]); } } }
@SuppressWarnings("deprecation") public void drawText(int x, int y, MapFont font, String text) { int xStart = x; byte color = MapPalette.DARK_GRAY; if (!font.isValid(text)) { throw new IllegalArgumentException("text contains invalid characters"); } for (int i = 0; i < text.length(); ++i) { char ch = text.charAt(i); if (ch == '\n') { x = xStart; y += font.getHeight() + 1; continue; } else if (ch == '\u00A7') { int j = text.indexOf(';', i); if (j >= 0) { try { color = Byte.parseByte(text.substring(i + 1, j)); i = j; continue; } catch (NumberFormatException ex) {} } } CharacterSprite sprite = font.getChar(text.charAt(i)); for (int r = 0; r < font.getHeight(); ++r) { for (int c = 0; c < sprite.getWidth(); ++c) { if (sprite.get(r, c)) { setPixel(x + c, y + r, color); } } } x += sprite.getWidth() + 1; } }
private static Color[] stealColors(){ try{ Field field = MapPalette.class.getDeclaredField("colors"); field.setAccessible(true); return (Color[]) field.get(null); }catch (Throwable e){ e.printStackTrace(); return null; } }