Search in sources :

Example 1 with CompositeContext

use of java.awt.CompositeContext 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 2 with CompositeContext

use of java.awt.CompositeContext in project jdk8u_jdk by JetBrains.

the class GeneralCompositePipe method renderPathTile.

/**
    * GeneralCompositePipe.renderPathTile works with custom composite operator
    * provided by an application
    */
public void renderPathTile(Object ctx, byte[] atile, int offset, int tilesize, int x, int y, int w, int h) {
    TileContext context = (TileContext) ctx;
    PaintContext paintCtxt = context.paintCtxt;
    CompositeContext compCtxt = context.compCtxt;
    SunGraphics2D sg = context.sunG2D;
    Raster srcRaster = paintCtxt.getRaster(x, y, w, h);
    ColorModel paintModel = paintCtxt.getColorModel();
    Raster dstRaster;
    Raster dstIn;
    WritableRaster dstOut;
    SurfaceData sd = sg.getSurfaceData();
    dstRaster = sd.getRaster(x, y, w, h);
    if (dstRaster instanceof WritableRaster && atile == null) {
        dstOut = (WritableRaster) dstRaster;
        dstOut = dstOut.createWritableChild(x, y, w, h, 0, 0, null);
        dstIn = dstOut;
    } else {
        dstIn = dstRaster.createChild(x, y, w, h, 0, 0, null);
        dstOut = dstIn.createCompatibleWritableRaster();
    }
    compCtxt.compose(srcRaster, dstIn, dstOut);
    if (dstRaster != dstOut && dstOut.getParent() != dstRaster) {
        if (dstRaster instanceof WritableRaster && atile == null) {
            ((WritableRaster) dstRaster).setDataElements(x, y, dstOut);
        } else {
            ColorModel cm = sg.getDeviceColorModel();
            BufferedImage resImg = new BufferedImage(cm, dstOut, cm.isAlphaPremultiplied(), null);
            SurfaceData resData = BufImgSurfaceData.createData(resImg);
            if (atile == null) {
                Blit blit = Blit.getFromCache(resData.getSurfaceType(), CompositeType.SrcNoEa, sd.getSurfaceType());
                blit.Blit(resData, sd, AlphaComposite.Src, null, 0, 0, x, y, w, h);
            } else {
                MaskBlit blit = MaskBlit.getFromCache(resData.getSurfaceType(), CompositeType.SrcNoEa, sd.getSurfaceType());
                blit.MaskBlit(resData, sd, AlphaComposite.Src, null, 0, 0, x, y, w, h, atile, offset, tilesize);
            }
        }
    }
}
Also used : SurfaceData(sun.java2d.SurfaceData) BufImgSurfaceData(sun.awt.image.BufImgSurfaceData) CompositeContext(java.awt.CompositeContext) ColorModel(java.awt.image.ColorModel) WritableRaster(java.awt.image.WritableRaster) MaskBlit(sun.java2d.loops.MaskBlit) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) Blit(sun.java2d.loops.Blit) MaskBlit(sun.java2d.loops.MaskBlit) PaintContext(java.awt.PaintContext) SunGraphics2D(sun.java2d.SunGraphics2D) BufferedImage(java.awt.image.BufferedImage)

Example 3 with CompositeContext

use of java.awt.CompositeContext in project jdk8u_jdk by JetBrains.

the class GeneralCompositePipe method startSequence.

public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR, int[] abox) {
    RenderingHints hints = sg.getRenderingHints();
    ColorModel model = sg.getDeviceColorModel();
    PaintContext paintContext = sg.paint.createContext(model, devR, s.getBounds2D(), sg.cloneTransform(), hints);
    CompositeContext compositeContext = sg.composite.createContext(paintContext.getColorModel(), model, hints);
    return new TileContext(sg, paintContext, compositeContext, model);
}
Also used : CompositeContext(java.awt.CompositeContext) ColorModel(java.awt.image.ColorModel) PaintContext(java.awt.PaintContext) RenderingHints(java.awt.RenderingHints)

Aggregations

CompositeContext (java.awt.CompositeContext)3 ColorModel (java.awt.image.ColorModel)3 PaintContext (java.awt.PaintContext)2 RenderingHints (java.awt.RenderingHints)2 BufferedImage (java.awt.image.BufferedImage)2 Raster (java.awt.image.Raster)2 WritableRaster (java.awt.image.WritableRaster)2 Composite (java.awt.Composite)1 Graphics2D (java.awt.Graphics2D)1 Shape (java.awt.Shape)1 BufImgSurfaceData (sun.awt.image.BufImgSurfaceData)1 SunGraphics2D (sun.java2d.SunGraphics2D)1 SurfaceData (sun.java2d.SurfaceData)1 Blit (sun.java2d.loops.Blit)1 MaskBlit (sun.java2d.loops.MaskBlit)1