Made zoomed-rendering make use of existing tile-files instead of keeping those tiles in memory.
This commit is contained in:
parent
38ee8657e8
commit
fb1b5df3d0
5 changed files with 84 additions and 75 deletions
|
|
@ -93,8 +93,8 @@ public class DefaultTileRenderer implements MapTileRenderer {
|
|||
|
||||
/* save the generated tile */
|
||||
saveTile(tile, im, path);
|
||||
|
||||
((KzedMap) tile.getMap()).invalidateTile(new KzedZoomedMapTile((KzedMap) tile.getMap(), im, tile));
|
||||
im.flush();
|
||||
((KzedMap) tile.getMap()).invalidateTile(new KzedZoomedMapTile((KzedMap) tile.getMap(), tile));
|
||||
|
||||
return !isempty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,12 +10,10 @@ public class KzedZoomedMapTile extends MapTile {
|
|||
return "z" + originalTile.renderer.getName() + "_" + getTileX() + "_" + getTileY();
|
||||
}
|
||||
|
||||
public BufferedImage unzoomedImage;
|
||||
public KzedMapTile originalTile;
|
||||
|
||||
public KzedZoomedMapTile(KzedMap map, BufferedImage unzoomedImage, KzedMapTile original) {
|
||||
public KzedZoomedMapTile(KzedMap map, KzedMapTile original) {
|
||||
super(map);
|
||||
this.unzoomedImage = unzoomedImage;
|
||||
this.originalTile = original;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,26 +19,38 @@ public class ZoomedTileRenderer {
|
|||
}
|
||||
|
||||
public void render(KzedZoomedMapTile zt, String outputPath) {
|
||||
KzedMapTile t = zt.originalTile;
|
||||
String zoomPath = new File(new File(outputPath), zt.getName() + ".png").getPath();
|
||||
render(t.px, t.py, zt.getTileX(), zt.getTileY(), zt.unzoomedImage, zoomPath);
|
||||
}
|
||||
|
||||
public void render(int px, int py, int zpx, int zpy, BufferedImage image, String zoomPath) {
|
||||
BufferedImage zIm = null;
|
||||
debugger.debug("Trying to load zoom-out tile: " + zoomPath);
|
||||
KzedMapTile originalTile = zt.originalTile;
|
||||
int px = originalTile.px;
|
||||
int py = originalTile.py;
|
||||
int zpx = zt.getTileX();
|
||||
int zpy = zt.getTileY();
|
||||
|
||||
BufferedImage image = null;
|
||||
try {
|
||||
File file = new File(zoomPath);
|
||||
zIm = ImageIO.read(file);
|
||||
image = ImageIO.read(new File(new File(outputPath), originalTile.getName() + ".png"));
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (image == null) {
|
||||
debugger.debug("Could not load original tile, won't render zoom-out tile.");
|
||||
return;
|
||||
}
|
||||
|
||||
BufferedImage zIm = null;
|
||||
File zoomFile = new File(new File(outputPath), zt.getName() + ".png");
|
||||
try {
|
||||
zIm = ImageIO.read(zoomFile);
|
||||
} catch (IOException e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (zIm == null) {
|
||||
/* create new one */
|
||||
zIm = new BufferedImage(KzedMap.tileWidth, KzedMap.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||
debugger.debug("New zoom-out tile created " + zoomPath);
|
||||
debugger.debug("New zoom-out tile created " + zt.getName());
|
||||
} else {
|
||||
debugger.debug("Loaded zoom-out tile from " + zoomPath);
|
||||
debugger.debug("Loaded zoom-out tile from " + zt.getName());
|
||||
}
|
||||
|
||||
/* update zoom-out tile */
|
||||
|
|
@ -66,13 +78,12 @@ public class ZoomedTileRenderer {
|
|||
|
||||
/* save zoom-out tile */
|
||||
try {
|
||||
File file = new File(zoomPath);
|
||||
ImageIO.write(zIm, "png", file);
|
||||
debugger.debug("Saved zoom-out tile at " + zoomPath);
|
||||
ImageIO.write(zIm, "png", zoomFile);
|
||||
debugger.debug("Saved zoom-out tile at " + zoomFile.getName());
|
||||
} catch (IOException e) {
|
||||
debugger.error("Failed to save zoom-out tile: " + zoomPath, e);
|
||||
debugger.error("Failed to save zoom-out tile: " + zoomFile.getName(), e);
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
debugger.error("Failed to save zoom-out tile (NullPointerException): " + zoomPath, e);
|
||||
debugger.error("Failed to save zoom-out tile (NullPointerException): " + zoomFile.getName(), e);
|
||||
}
|
||||
zIm.flush();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue