use of java.awt.Composite in project jdk8u_jdk by JetBrains.
the class Bug7049339 method main.
public static void main(String[] argv) {
int x = 100, y = 100;
BufferedImage src = new BufferedImage(x, y, BufferedImage.TYPE_INT_ARGB);
BufferedImage dst = new BufferedImage(x, y, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D dstg2d = dst.createGraphics();
dstg2d.setComposite(new Composite() {
@Override
public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) {
return new CompositeContext() {
@Override
public void compose(Raster src, Raster dstIn, WritableRaster dstOut) {
// do nothing
}
@Override
public void dispose() {
}
};
}
});
Shape clip = new Ellipse2D.Double(x / 4, y / 4, x / 2, y / 2);
dstg2d.setClip(clip);
// This will throw a RasterFormatException if the bug is present.
dstg2d.drawImage(src, 0, 0, null);
}
use of java.awt.Composite in project android_frameworks_base by AOSPA.
the class GcSnapshot method setComposite.
private void setComposite(Graphics2D g, Paint_Delegate paint, boolean usePaintAlpha, int forceMode) {
// the alpha for the composite. Always opaque if the normal paint color is used since
// it contains the alpha
int alpha = usePaintAlpha ? paint.getAlpha() : 0xFF;
if (forceMode != 0) {
g.setComposite(AlphaComposite.getInstance(forceMode, (float) alpha / 255.f));
return;
}
Xfermode_Delegate xfermodeDelegate = paint.getXfermode();
if (xfermodeDelegate != null) {
if (xfermodeDelegate.isSupported()) {
Composite composite = xfermodeDelegate.getComposite(alpha);
assert composite != null;
if (composite != null) {
g.setComposite(composite);
return;
}
} else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_XFERMODE, xfermodeDelegate.getSupportMessage(), null, /*throwable*/
null);
}
}
// that will handle the alpha.
if (alpha != 0xFF) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha / 255.f));
}
}
use of java.awt.Composite in project android_frameworks_base by ResurrectionRemix.
the class GcSnapshot method setComposite.
private void setComposite(Graphics2D g, Paint_Delegate paint, boolean usePaintAlpha, int forceMode) {
// the alpha for the composite. Always opaque if the normal paint color is used since
// it contains the alpha
int alpha = usePaintAlpha ? paint.getAlpha() : 0xFF;
if (forceMode != 0) {
g.setComposite(AlphaComposite.getInstance(forceMode, (float) alpha / 255.f));
return;
}
Xfermode_Delegate xfermodeDelegate = paint.getXfermode();
if (xfermodeDelegate != null) {
if (xfermodeDelegate.isSupported()) {
Composite composite = xfermodeDelegate.getComposite(alpha);
assert composite != null;
if (composite != null) {
g.setComposite(composite);
return;
}
} else {
Bridge.getLog().fidelityWarning(LayoutLog.TAG_XFERMODE, xfermodeDelegate.getSupportMessage(), null, /*throwable*/
null);
}
}
// that will handle the alpha.
if (alpha != 0xFF) {
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) alpha / 255.f));
}
}
use of java.awt.Composite in project EnrichmentMapApp by BaderLab.
the class AbstractChartLayer method draw.
@Override
public void draw(final Graphics2D g, final Shape shape, final CyNetworkView networkView, final View<? extends CyIdentifiable> view) {
// Give JFreeChart a larger area to draw into, so the proportions of the chart elements looks better
final double scale = 2.0;
Rectangle2D newBounds = new Rectangle2D.Double(bounds.getX() * scale, bounds.getY() * scale, bounds.getWidth() * scale, bounds.getHeight() * scale);
// Of course, we also have to ask Graphics2D to apply the inverse transformation
final double invScale = 1.0 / scale;
final AffineTransform at = new AffineTransform();
at.scale(invScale, invScale);
g.transform(at);
// Check to see if we have a current alpha composite
Composite comp = g.getComposite();
if (comp instanceof AlphaComposite) {
float alpha = ((AlphaComposite) comp).getAlpha();
JFreeChart fc = getChart();
Plot plot = fc.getPlot();
plot.setForegroundAlpha(alpha);
fc.draw(g, newBounds);
} else {
getChart().draw(g, newBounds);
}
// Make sure Graphics2D is "back to normal" before returning
try {
at.invert();
} catch (NoninvertibleTransformException e) {
e.printStackTrace();
}
g.transform(at);
}
use of java.awt.Composite in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method doCopyArea.
private void doCopyArea(int x, int y, int w, int h, int dx, int dy) {
if (w <= 0 || h <= 0) {
return;
}
SurfaceData theData = surfaceData;
if (theData.copyArea(this, x, y, w, h, dx, dy)) {
return;
}
if (transformState > TRANSFORM_TRANSLATESCALE) {
throw new InternalError("transformed copyArea not implemented yet");
}
// REMIND: This method does not deal with missing data from the
// source object (i.e. it does not send exposure events...)
Region clip = getCompClip();
Composite comp = composite;
if (lastCAcomp != comp) {
SurfaceType dsttype = theData.getSurfaceType();
CompositeType comptype = imageComp;
if (CompositeType.SrcOverNoEa.equals(comptype) && theData.getTransparency() == Transparency.OPAQUE) {
comptype = CompositeType.SrcNoEa;
}
lastCAblit = Blit.locate(dsttype, comptype, dsttype);
lastCAcomp = comp;
}
double[] coords = { x, y, x + w, y + h, x + dx, y + dy };
transform.transform(coords, 0, coords, 0, 3);
x = (int) Math.ceil(coords[0] - 0.5);
y = (int) Math.ceil(coords[1] - 0.5);
w = ((int) Math.ceil(coords[2] - 0.5)) - x;
h = ((int) Math.ceil(coords[3] - 0.5)) - y;
dx = ((int) Math.ceil(coords[4] - 0.5)) - x;
dy = ((int) Math.ceil(coords[5] - 0.5)) - y;
// In case of negative scale transform, reflect the rect coords.
if (w < 0) {
w *= -1;
x -= w;
}
if (h < 0) {
h *= -1;
y -= h;
}
Blit ob = lastCAblit;
if (dy == 0 && dx > 0 && dx < w) {
while (w > 0) {
int partW = Math.min(w, dx);
w -= partW;
int sx = x + w;
ob.Blit(theData, theData, comp, clip, sx, y, sx + dx, y + dy, partW, h);
}
return;
}
if (dy > 0 && dy < h && dx > -w && dx < w) {
while (h > 0) {
int partH = Math.min(h, dy);
h -= partH;
int sy = y + h;
ob.Blit(theData, theData, comp, clip, x, sy, x + dx, sy + dy, w, partH);
}
return;
}
ob.Blit(theData, theData, comp, clip, x, y, x + dx, y + dy, w, h);
}
Aggregations