public void Blit(SurfaceData srcData, SurfaceData dstData, Composite comp, Region clip, int srcx, int srcy, int dstx, int dsty, int width, int height) { ColorModel srcCM = srcData.getColorModel(); ColorModel dstCM = dstData.getColorModel(); // REMIND: Should get RenderingHints from sg2d CompositeContext ctx = comp.createContext(srcCM, dstCM, new RenderingHints(null)); Raster srcRas = srcData.getRaster(srcx, srcy, width, height); WritableRaster dstRas = (WritableRaster) dstData.getRaster(dstx, dsty, width, height); if (clip == null) { clip = Region.getInstanceXYWH(dstx, dsty, width, height); } int span[] = {dstx, dsty, dstx+width, dsty+height}; SpanIterator si = clip.getSpanIterator(span); srcx -= dstx; srcy -= dsty; while (si.nextSpan(span)) { int w = span[2] - span[0]; int h = span[3] - span[1]; Raster tmpSrcRas = srcRas.createChild(srcx + span[0], srcy + span[1], w, h, 0, 0, null); WritableRaster tmpDstRas = dstRas.createWritableChild(span[0], span[1], w, h, 0, 0, null); ctx.compose(tmpSrcRas, tmpDstRas, tmpDstRas); } ctx.dispose(); }
@Override public final CompositeContext createContext(final ColorModel srcColorModel, final ColorModel dstColorModel, final RenderingHints hints) { return new CompositeContext() { @Override public final void dispose() { // NOP } @Override public final void compose(final Raster src, final Raster dstIn, final WritableRaster dstOut) { final Rectangle inBounds = dstIn.getBounds(); final Rectangle outBounds = dstOut.getBounds(); for (int yIn = inBounds.y, yOut = outBounds.y; yIn < inBounds.y + inBounds.height; ++yIn, ++yOut) { for (int xIn = inBounds.x, xOut = outBounds.x; xIn < inBounds.x + inBounds.width; ++xIn, ++xOut) { final int[] datum = (int[]) dstIn.getDataElements(xIn, yIn, null); datum[0] = (datum[0] & 0xFF000000) | (~datum[0] & 0x00FFFFFF); dstOut.setDataElements(xOut, yOut, datum); } } } }; }
@Override public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints arg2) { switch (mode) { case MULTIPLY: return new MultiplyContext(); // Modes with significant creation overhead (lookup tables). Cache those case SOFT_LIGHT: CompositeContext ctx = cache.get(Mode.SOFT_LIGHT); if (ctx == null) { ctx = new BlendContext(mode, color); cache.put(Mode.SOFT_LIGHT, ctx); } return ctx; default: return new BlendContext(mode, color); } }
@Override public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR, int[] abox) { // warning: clone map: 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); // BlendComposite matcher: classpath independent so use String.equals() boolean blendComposite = "sun.java2d.pipe.BlendComposite".equals(sg.composite.getClass().getName()); // use ThreadLocal (to reduce memory footprint): final TileContext tc = tileContextThreadLocal.get(); tc.init(sg, paintContext, compositeContext, model, blendComposite); return tc; }
/** * ( begin auto-generated from blendMode.xml ) This is a new reference entry for Processing 2.0. * It will be updated shortly. ( end auto-generated ) * * @webref Rendering * @param mode * the blending mode to use */ @Override public void blendMode(final int mode) { if (mode == PConstants.BLEND) { g2.setComposite(defaultComposite); } else { g2.setComposite(new Composite() { @Override public CompositeContext createContext(final ColorModel srcColorModel, final ColorModel dstColorModel, final RenderingHints hints) { return new BlendingContext(mode); } }); } }
public TileContext(SunGraphics2D sg, PaintContext pCtx, CompositeContext cCtx, ColorModel cModel) { sunG2D = sg; paintCtxt = pCtx; compCtxt = cCtx; compModel = cModel; }
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); }
@Override public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) { return new CustomCompositeContext(); }
/** * {@inheritDoc} */ public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) { if (isRgbColorModel(srcColorModel) && isRgbColorModel(dstColorModel)) { return new BlendingRgbContext(this); } else if (isBgrColorModel(srcColorModel) && isBgrColorModel(dstColorModel)) { return new BlendingBgrContext(this); } throw new RasterFormatException("Incompatible color models"); }
/** * Creates a context object for performing the compositing * operation. Several contexts may co-exist for one composite; each * context may simultaneously be called from concurrent threads. * * @param srcColorModel the color model of the source. * @param dstColorModel the color model of the destination. * @param hints hints for choosing between rendering alternatives. */ public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) { if (IntContext.isSupported(srcColorModel, dstColorModel, hints)) return new IntContext(srcColorModel, xorColor); return new GeneralContext(srcColorModel, dstColorModel, xorColor); }
public FilterContext(ColorModel dstModel, CompositeContext ctx, BufferedImageOp filter) { Contract.asNotNull(dstModel, "dstModel cannot be null"); Contract.asNotNull(ctx, "context cannot be null"); this.dstModel = dstModel; this.ctx = ctx; this.filter = filter; }
/** * {@inheritDoc} */ @Override public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) { if (isRgbColorModel(srcColorModel) && isRgbColorModel(dstColorModel)) { return new BlendingRgbContext(this); } else if (isBgrColorModel(srcColorModel) && isBgrColorModel(dstColorModel)) { return new BlendingBgrContext(this); } throw new RasterFormatException("Incompatible color models:\n " + srcColorModel + "\n " + dstColorModel); }
void init(SunGraphics2D sg, PaintContext pCtx, CompositeContext cCtx, ColorModel cModel, boolean blendComposite, boolean extraAlpha) { sunG2D = sg; paintCtxt = pCtx; compCtxt = cCtx; compModel = cModel; isBlendComposite = blendComposite; hasExtraAlpha = extraAlpha; }
@Override public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) { // use ThreadLocal (to reduce memory footprint): final BlendingContext bc = blendContextThreadLocal.get(); bc.init(this); return bc; }
/** * {@inheritDoc} */ public CompositeContext createContext(ColorModel srcColorModel, ColorModel dstColorModel, RenderingHints hints) { if (!checkComponentsOrder(srcColorModel) || !checkComponentsOrder(dstColorModel)) { throw new RasterFormatException("Incompatible color models"); } return new BlendingContext(this); }