private final Texture2D getTexture(Image base, boolean border, Color col, float alpha, boolean tile) {
if (base == null) return null;
Texture2D tex = textureCache.get(new ImageAlpha(base, alpha));
if (tex == null) {
MediaTracker tracker = new MediaTracker(comp);
// Fully load image before continuing
tracker.addImage(base, 0);
do {
try { tracker.waitForID(0); } catch (InterruptedException e) { continue; }
} while (false);
tracker.removeImage(base);
final int w = base.getWidth(null), h = base.getHeight(null);
BufferedImage tmp = new BufferedImage(w*2, h*2, BufferedImage.TYPE_INT_ARGB);
Graphics2D tgr = tmp.createGraphics();
if (col != null) {
tgr.setColor(col);
tgr.fillRect(0, 0, w*2, h*2);
}
tgr.translate(w/2, h/2);
tgr.drawImage(base, null, null);
if (tile) {
// create an image of a hex with all 6 surrounding hexes to get
// better interpolation at the borders
tgr.translate(0, -h);
tgr.drawImage(base, null, null);
tgr.translate(0, 2*h);
tgr.drawImage(base, null, null);
tgr.translate(-3*w/4, -h/2);
tgr.drawImage(base, null, null);
tgr.translate(0, -h);
tgr.drawImage(base, null, null);
tgr.translate(3*w/2, 0);
tgr.drawImage(base, null, null);
tgr.translate(0, h);
tgr.drawImage(base, null, null);
}
tracker.addImage(tmp, 1);
do {
try { tracker.waitForID(1); } catch (InterruptedException e) { continue; }
} while (false);
tracker.removeImage(tmp);
// TODO: Make this configurable.
// Cut outer pixel border? This removes the distinct tile border present in most tiles.
int border_cut = 1;
// Add our own pixel border? Higher quality (resolution) than the image's tile border.