diff --git a/src/micropolisj/build_tool/MakeTiles.java b/src/micropolisj/build_tool/MakeTiles.java index b4f1d9b..cd30195 100644 --- a/src/micropolisj/build_tool/MakeTiles.java +++ b/src/micropolisj/build_tool/MakeTiles.java @@ -441,13 +441,23 @@ public class MakeTiles if (!loadedImages.containsKey(fileName)) { loadedImages.put(fileName, - loadImageReal(fileName)); + loadImageNoCache(fileName)); } return loadedImages.get(fileName); } - static SourceImage loadImageReal(String fileName) + static SourceImage loadImageReal(File pngFile, int basisSize) + throws IOException + { + BufferedImage bi = ImageIO.read(pngFile); + return new SourceImage( + bi, + basisSize, + TILE_SIZE); + } + + static SourceImage loadImageNoCache(String fileName) throws IOException { File svgFile, pngFile = null; @@ -465,40 +475,24 @@ public class MakeTiles } if (pngFile != null && pngFile.exists()) { - ImageIcon ii = new ImageIcon(pngFile.toString()); - return new SourceImage( - ii.getImage(), - TILE_SIZE, - TILE_SIZE); + return loadImageReal(pngFile, TILE_SIZE); } pngFile = new File(fileName+"_"+TILE_SIZE+"x"+TILE_SIZE+".png"); if (pngFile.exists()) { - ImageIcon ii = new ImageIcon(pngFile.toString()); - return new SourceImage( - ii.getImage(), - TILE_SIZE, - TILE_SIZE); + return loadImageReal(pngFile, TILE_SIZE); } if (TILE_SIZE < 128) { pngFile = new File(fileName+"_128x128.png"); if (pngFile.exists()) { - ImageIcon ii = new ImageIcon(pngFile.toString()); - return new SourceImage( - ii.getImage(), - 128, - TILE_SIZE); + return loadImageReal(pngFile, 128); } } pngFile = new File(fileName+".png"); if (pngFile.exists()) { - ImageIcon ii = new ImageIcon(pngFile.toString()); - return new SourceImage( - ii.getImage(), - STD_SIZE, - TILE_SIZE); + return loadImageReal(pngFile, STD_SIZE); } throw new IOException("File not found: "+fileName+".{svg,png}"); diff --git a/src/micropolisj/graphics/TileImage.java b/src/micropolisj/graphics/TileImage.java index 799cc36..e6e1dbb 100644 --- a/src/micropolisj/graphics/TileImage.java +++ b/src/micropolisj/graphics/TileImage.java @@ -48,13 +48,16 @@ public abstract class TileImage } } + /** + * Supports rescaling of tile images. + */ public static class SourceImage extends TileImage { - public final Image image; + public final BufferedImage image; public final int basisSize; public final int targetSize; - public SourceImage(Image image, int basisSize, int targetSize) + public SourceImage(BufferedImage image, int basisSize, int targetSize) { this.image = image; this.basisSize = basisSize;