MakeTiles: use BufferedImage, to be the same as gui

This commit is contained in:
Jason Long 2014-08-13 20:11:09 -04:00
parent 7592117306
commit 28be533163
2 changed files with 21 additions and 24 deletions

View file

@ -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}");

View file

@ -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;