use of games.strategy.triplea.image.BlendComposite.BlendingMode in project triplea by triplea-game.
the class TileImageFactory method loadBlendedImage.
private Image loadBlendedImage(final String fileName, final boolean cache, final boolean scaled) {
BufferedImage reliefFile = null;
BufferedImage baseFile = null;
// The relief tile
final String reliefFileName = fileName.replace("baseTiles", "reliefTiles");
final URL urlrelief = resourceLoader.getResource(reliefFileName);
// The base tile
final String baseFileName = fileName.replace("reliefTiles", "baseTiles");
final URL urlBase = resourceLoader.getResource(baseFileName);
// blank relief tile
final String blankReliefFileName = "reliefTiles/blank_relief.png";
final URL urlBlankRelief = resourceLoader.getResource(blankReliefFileName);
// Get buffered images
try {
final Stopwatch loadingImages = new Stopwatch(logger, Level.FINE, "Loading images:" + urlrelief + " and " + urlBase);
if (urlrelief != null) {
reliefFile = loadCompatibleImage(urlrelief);
}
if (urlBase != null) {
baseFile = loadCompatibleImage(urlBase);
}
loadingImages.done();
} catch (final IOException e) {
ClientLogger.logQuietly("Failed to load one or more images: " + urlrelief + ", " + urlBase, e);
}
// This does the blend
final float alpha = getShowMapBlendAlpha();
if (reliefFile == null) {
try {
reliefFile = loadCompatibleImage(urlBlankRelief);
} catch (final IOException e) {
ClientLogger.logQuietly("Failed to load image: " + urlBlankRelief, e);
}
}
// This fixes the blank land territories
if (baseFile == null) {
baseFile = makeMissingBaseTile(reliefFile);
}
/* reversing the to/from files leaves white underlays visible */
if (reliefFile != null) {
final BufferedImage blendedImage = new BufferedImage(reliefFile.getWidth(null), reliefFile.getHeight(null), BufferedImage.TYPE_INT_ARGB);
final Graphics2D g2 = blendedImage.createGraphics();
if (scaled && scale != 1.0) {
final AffineTransform transform = new AffineTransform();
transform.scale(scale, scale);
g2.setTransform(transform);
}
g2.drawImage(reliefFile, 0, 0, null);
final BlendingMode blendMode = BlendComposite.BlendingMode.valueOf(getShowMapBlendMode());
final BlendComposite blendComposite = BlendComposite.getInstance(blendMode).derive(alpha);
g2.setComposite(blendComposite);
g2.drawImage(baseFile, 0, 0, null);
final ImageRef ref = new ImageRef(blendedImage);
if (cache) {
imageCache.put(fileName, ref);
}
return blendedImage;
}
final ImageRef ref = new ImageRef(baseFile);
if (cache) {
imageCache.put(fileName, ref);
}
return baseFile;
}
Aggregations