Search in sources :

Example 6 with Composite

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);
}
Also used : Shape(java.awt.Shape) Composite(java.awt.Composite) CompositeContext(java.awt.CompositeContext) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) BufferedImage(java.awt.image.BufferedImage) RenderingHints(java.awt.RenderingHints) Graphics2D(java.awt.Graphics2D)

Example 7 with Composite

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));
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Xfermode_Delegate(android.graphics.Xfermode_Delegate) Paint(android.graphics.Paint)

Example 8 with Composite

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));
    }
}
Also used : AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) Xfermode_Delegate(android.graphics.Xfermode_Delegate) Paint(android.graphics.Paint)

Example 9 with Composite

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);
}
Also used : NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) AlphaComposite(java.awt.AlphaComposite) Composite(java.awt.Composite) AlphaComposite(java.awt.AlphaComposite) Plot(org.jfree.chart.plot.Plot) Rectangle2D(java.awt.geom.Rectangle2D) AffineTransform(java.awt.geom.AffineTransform) JFreeChart(org.jfree.chart.JFreeChart)

Example 10 with Composite

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);
}
Also used : Composite(java.awt.Composite) XORComposite(sun.java2d.loops.XORComposite) AlphaComposite(java.awt.AlphaComposite) Region(sun.java2d.pipe.Region) Blit(sun.java2d.loops.Blit) SurfaceType(sun.java2d.loops.SurfaceType) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint) CompositeType(sun.java2d.loops.CompositeType)

Aggregations

Composite (java.awt.Composite)21 AlphaComposite (java.awt.AlphaComposite)18 Paint (android.graphics.Paint)6 Xfermode_Delegate (android.graphics.Xfermode_Delegate)6 Shape (java.awt.Shape)6 Color (java.awt.Color)5 Graphics2D (java.awt.Graphics2D)4 Paint (java.awt.Paint)4 TexturePaint (java.awt.TexturePaint)4 AffineTransform (java.awt.geom.AffineTransform)4 BasicStroke (java.awt.BasicStroke)2 GradientPaint (java.awt.GradientPaint)2 LinearGradientPaint (java.awt.LinearGradientPaint)2 RadialGradientPaint (java.awt.RadialGradientPaint)2 Rectangle (java.awt.Rectangle)2 NoninvertibleTransformException (java.awt.geom.NoninvertibleTransformException)2 Rectangle2D (java.awt.geom.Rectangle2D)2 BufferedImage (java.awt.image.BufferedImage)2 RectangleInsets (org.jfree.ui.RectangleInsets)2 Shader_Delegate (android.graphics.Shader_Delegate)1