use of java.awt.AlphaComposite in project jdk8u_jdk by JetBrains.
the class D3DSurfaceData method validatePipe.
public void validatePipe(SunGraphics2D sg2d) {
TextPipe textpipe;
boolean validated = false;
// for the surface which had any XOR rendering done to.
if (sg2d.compositeState >= sg2d.COMP_XOR) {
super.validatePipe(sg2d);
sg2d.imagepipe = d3dImagePipe;
disableAccelerationForSurface();
return;
}
if (/* CompositeType.SrcNoEa (any color) */
(sg2d.compositeState <= sg2d.COMP_ISCOPY && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) || /* CompositeType.SrcOver (any color) */
(sg2d.compositeState == sg2d.COMP_ALPHA && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR && (((AlphaComposite) sg2d.composite).getRule() == AlphaComposite.SRC_OVER)) || /* CompositeType.Xor (any color) */
(sg2d.compositeState == sg2d.COMP_XOR && sg2d.paintState <= sg2d.PAINT_ALPHACOLOR)) {
textpipe = d3dTextPipe;
} else {
// do this to initialize textpipe correctly; we will attempt
// to override the non-text pipes below
super.validatePipe(sg2d);
textpipe = sg2d.textpipe;
validated = true;
}
PixelToParallelogramConverter txPipe = null;
D3DRenderer nonTxPipe = null;
if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON) {
if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
if (sg2d.compositeState <= sg2d.COMP_XOR) {
txPipe = d3dTxRenderPipe;
nonTxPipe = d3dRenderPipe;
}
} else if (sg2d.compositeState <= sg2d.COMP_ALPHA) {
if (D3DPaints.isValid(sg2d)) {
txPipe = d3dTxRenderPipe;
nonTxPipe = d3dRenderPipe;
}
// custom paints handled by super.validatePipe() below
}
} else {
if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR) {
if (graphicsDevice.isCapPresent(CAPS_AA_SHADER) && (sg2d.imageComp == CompositeType.SrcOverNoEa || sg2d.imageComp == CompositeType.SrcOver)) {
if (!validated) {
super.validatePipe(sg2d);
validated = true;
}
PixelToParallelogramConverter aaConverter = new PixelToParallelogramConverter(sg2d.shapepipe, d3dAAPgramPipe, 1.0 / 8.0, 0.499, false);
sg2d.drawpipe = aaConverter;
sg2d.fillpipe = aaConverter;
sg2d.shapepipe = aaConverter;
} else if (sg2d.compositeState == sg2d.COMP_XOR) {
// install the solid pipes when AA and XOR are both enabled
txPipe = d3dTxRenderPipe;
nonTxPipe = d3dRenderPipe;
}
}
// other cases handled by super.validatePipe() below
}
if (txPipe != null) {
if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) {
sg2d.drawpipe = txPipe;
sg2d.fillpipe = txPipe;
} else if (sg2d.strokeState != sg2d.STROKE_THIN) {
sg2d.drawpipe = txPipe;
sg2d.fillpipe = nonTxPipe;
} else {
sg2d.drawpipe = nonTxPipe;
sg2d.fillpipe = nonTxPipe;
}
// Note that we use the transforming pipe here because it
// will examine the shape and possibly perform an optimized
// operation if it can be simplified. The simplifications
// will be valid for all STROKE and TRANSFORM types.
sg2d.shapepipe = txPipe;
} else {
if (!validated) {
super.validatePipe(sg2d);
}
}
// install the text pipe based on our earlier decision
sg2d.textpipe = textpipe;
// always override the image pipe with the specialized D3D pipe
sg2d.imagepipe = d3dImagePipe;
}
use of java.awt.AlphaComposite in project dbeaver by dbeaver.
the class GraphicsToGraphics2DAdaptor method setAlpha.
@Override
public void setAlpha(int alpha) {
swtGraphics.setAlpha(alpha);
currentState.alpha = alpha;
Composite composite = getGraphics2D().getComposite();
if (composite instanceof AlphaComposite) {
AlphaComposite newComposite = AlphaComposite.getInstance(((AlphaComposite) composite).getRule(), (float) alpha / (float) 255);
getGraphics2D().setComposite(newComposite);
}
}
use of java.awt.AlphaComposite in project Lucee by lucee.
the class Image method setTranparency.
public void setTranparency(float percent) throws ExpressionException {
if (percent == -1)
return;
tranparency = percent;
AlphaComposite rule = AlphaComposite.getInstance(3, 1.0F - (percent / 100.0F));
getGraphics().setComposite(rule);
}
use of java.awt.AlphaComposite in project litiengine by gurkenlabs.
the class OrthogonalMapRenderer method getLayerImage.
/**
* Gets the layer image.
*
* @param layer
* the layer
* @param map
* the map
* @return the layer image
*/
private synchronized BufferedImage getLayerImage(final ITileLayer layer, final IMap map, boolean includeAnimationTiles) {
// if we have already retrived the image, use the one from the cache to
// draw the layer
final String cacheKey = MessageFormat.format("{0}_{1}", getCacheKey(map), layer.getName());
if (ImageCache.MAPS.containsKey(cacheKey)) {
return ImageCache.MAPS.get(cacheKey);
}
final BufferedImage bufferedImage = ImageProcessing.getCompatibleImage(layer.getSizeInTiles().width * map.getTileSize().width, layer.getSizeInTiles().height * map.getTileSize().height);
// we need a graphics 2D object to work with transparency
final Graphics2D imageGraphics = bufferedImage.createGraphics();
// set alpha value of the tiles by the layers value
final AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity());
imageGraphics.setComposite(ac);
layer.getTiles().parallelStream().forEach(tile -> {
// get the tile from the tileset image
final int index = layer.getTiles().indexOf(tile);
if (tile.getGridId() == 0) {
return;
}
if (!includeAnimationTiles && MapUtilities.hasAnimation(map, tile)) {
return;
}
final Image tileTexture = getTileImage(map, tile);
// draw the tile on the layer image
final int x = index % layer.getSizeInTiles().width * map.getTileSize().width;
final int y = index / layer.getSizeInTiles().width * map.getTileSize().height;
RenderEngine.renderImage(imageGraphics, tileTexture, x, y);
});
ImageCache.MAPS.put(cacheKey, bufferedImage);
return bufferedImage;
}
use of java.awt.AlphaComposite in project litiengine by gurkenlabs.
the class OrthogonalMapRenderer method renderTileLayerImage.
/**
* Renders the tiles from the specified layer that lie within the bounds of
* the viewport. This rendering of static tiles is cached when when the
* related graphics setting is enabled, which tremendously improves the
* rendering performance.
*
* @param g
* @param layer
* @param map
* @param viewport
*/
private void renderTileLayerImage(final Graphics2D g, final ITileLayer layer, final IMap map, final Rectangle2D viewport) {
final Point startTile = MapUtilities.getTile(map, new Point2D.Double(viewport.getX(), viewport.getY()));
final Point endTile = MapUtilities.getTile(map, new Point2D.Double(viewport.getMaxX(), viewport.getMaxY()));
final double viewportOffsetX = -(viewport.getX() - startTile.x * map.getTileSize().width) + layer.getPosition().x;
final double viewportOffsetY = -(viewport.getY() - startTile.y * map.getTileSize().height) + layer.getPosition().y;
// set alpha value of the tiles by the layers value
final Composite oldComp = g.getComposite();
final AlphaComposite ac = java.awt.AlphaComposite.getInstance(AlphaComposite.SRC_OVER, layer.getOpacity());
g.setComposite(ac);
final int startX = MathUtilities.clamp(startTile.x, 0, layer.getSizeInTiles().width);
final int endX = MathUtilities.clamp(endTile.x, 0, layer.getSizeInTiles().width);
final int startY = MathUtilities.clamp(startTile.y, 0, layer.getSizeInTiles().height);
final int endY = MathUtilities.clamp(endTile.y, 0, layer.getSizeInTiles().height);
final double offsetX = viewportOffsetX + (startX - startTile.x) * map.getTileSize().width;
final double offsetY = viewportOffsetY + (startY - startTile.y) * map.getTileSize().height;
for (int x = startX; x <= endX; x++) {
for (int y = startY; y <= endY; y++) {
ITile tile = layer.getTile(x, y);
if (tile == null) {
continue;
}
final Image tileTexture = getTileImage(map, tile);
RenderEngine.renderImage(g, tileTexture, offsetX + (x - startX) * map.getTileSize().width, offsetY + (y - startY) * map.getTileSize().height);
}
}
g.setComposite(oldComp);
}
Aggregations