public byte[] getImageData(String pathInfo) throws IOException, FormatException { byte[] imageData = null; // We're assuming that all queries are coming in with the name in front, // along with a slash if (name != null) { int index = pathInfo.indexOf(name, 1); pathInfo = pathInfo.substring(index + name.length()); } String filePath = rootDir + pathInfo; if (logger.isLoggable(Level.FINE)) { logger.fine("looking for " + filePath); } try { BinaryBufferedFile file = new BinaryBufferedFile(filePath); imageData = file.readBytes(100000, true); file.close(); } catch (IOException ioe) { logger.fine("Problem fetching the file"); // The file wasn't found. if (emptyTileHandler != null) { if (logger.isLoggable(Level.FINE)) { logger.fine("Creating " + filePath + " since it wasn't found from the server."); } TileInfo ti = new TileInfo(filePath); // FPBT: used to be // pathInfo ti.setMtcTransform(getMtcTransform()); BufferedImage bufferedImage = ti.getBufferedImage(emptyTileHandler); if (bufferedImage != null) { imageData = new PNGImageIOFormatter().formatImage(bufferedImage); logger.fine("buffered image created, writing file to disk too"); File newFile = new File(filePath); newFile.getParentFile().mkdirs(); // Write the image data to the local cache location FileOutputStream fos = new FileOutputStream(newFile); fos.write(imageData); fos.flush(); fos.close(); } else { logger.fine("null buffered image back from EmptyTileHandler"); } } else { logger.fine("no empty file handler"); } } return imageData; }
/** Add model to TileMap */ public final void addModel(final TileMapModel model) { int mapTileWidth = (int) model.getTileSize().x; int mapTileHeight = (int) model.getTileSize().y; for (int i = 0; i < model.getLayersCount(); i++) { final TileMapLayer layer = model.getLayer(i); int width = (int) Math.min(layer.mWidth, model.getMapSize().x); int height = (int) Math.min(layer.mHeight, model.getMapSize().y); LayerInfo layerInfo = addLayerInfo(new Vector2(width, height)); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { final int tileId = layer.mData[x + y * width]; if (tileId == 0) continue; final TileInfo tileInfo = model.getTileInfo(tileId); // Prepare Buffer layerInfo.prepareBuffer(tileInfo); // Get Buffer LayerInfo.Buffer buff = layerInfo.getBuffer(tileInfo); // Get Rect Area RectF textureArea = tileInfo.getTextureArea(); RectF textureAreaU = GeneralUtils.divideRect(textureArea, tileInfo.getTexture().getSize()); Vector2 tileSize = tileInfo.getSize(); final int tileWidth = (int) tileSize.x; final int tileHeight = (int) tileSize.y; // Put Element buffer buff.mElementsVertex.put(x * mapTileWidth); buff.mElementsVertex.put(y * mapTileHeight); buff.mElementsVertex.put(x * mapTileWidth + tileWidth); buff.mElementsVertex.put(y * mapTileHeight); buff.mElementsVertex.put(x * mapTileWidth + tileWidth); buff.mElementsVertex.put(y * mapTileHeight + tileHeight); buff.mElementsVertex.put(x * mapTileWidth); buff.mElementsVertex.put(y * mapTileHeight); buff.mElementsVertex.put(x * mapTileWidth); buff.mElementsVertex.put(y * mapTileHeight + tileHeight); buff.mElementsVertex.put(x * mapTileWidth + tileWidth); buff.mElementsVertex.put(y * mapTileHeight + tileHeight); // Put Texture Buffer buff.mTextureVertex.put(textureAreaU.left); buff.mTextureVertex.put(textureAreaU.top); buff.mTextureVertex.put(textureAreaU.right); buff.mTextureVertex.put(textureAreaU.top); buff.mTextureVertex.put(textureAreaU.right); buff.mTextureVertex.put(textureAreaU.bottom); buff.mTextureVertex.put(textureAreaU.left); buff.mTextureVertex.put(textureAreaU.top); buff.mTextureVertex.put(textureAreaU.left); buff.mTextureVertex.put(textureAreaU.bottom); buff.mTextureVertex.put(textureAreaU.right); buff.mTextureVertex.put(textureAreaU.bottom); } } layerInfo.pack(); } }