Java Code Examples for java.awt.Composite

The following examples show how to use java.awt.Composite. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: jdk8u-jdk   Source File: MaskFill.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void MaskFill(SunGraphics2D sg2d,
                     SurfaceData sData,
                     Composite comp,
                     int x, int y, int w, int h,
                     byte mask[], int offset, int scan)
{
    BufferedImage dstBI =
        new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
    SurfaceData tmpData = BufImgSurfaceData.createData(dstBI);

    // REMIND: This is not pretty.  It would be nicer if we
    // passed a "FillData" object to the Pixel loops, instead
    // of a SunGraphics2D parameter...
    Region clip = sg2d.clipRegion;
    sg2d.clipRegion = null;
    int pixel = sg2d.pixel;
    sg2d.pixel = tmpData.pixelFor(sg2d.getColor());
    fillop.FillRect(sg2d, tmpData, 0, 0, w, h);
    sg2d.pixel = pixel;
    sg2d.clipRegion = clip;

    maskop.MaskBlit(tmpData, sData, comp, null,
                    0, 0, x, y, w, h,
                    mask, offset, scan);
}
 
Example 2
@Override
protected void paint (Graphics2D g,
                      Params params,
                      Point location,
                      Alignment alignment)
{
    Point loc = alignment.translatedPoint(
            AREA_CENTER,
            params.rect,
            location);

    if (decorated) {
        // Draw a note head (using composite)
        Composite oldComposite = g.getComposite();
        g.setComposite(decoComposite);
        MusicFont.paint(g, params.layout, loc, AREA_CENTER);
        g.setComposite(oldComposite);
    }

    // Ledger
    g.drawLine(
            loc.x - (params.rect.width / 2),
            loc.y,
            loc.x + (params.rect.width / 2),
            loc.y);
}
 
Example 3
Source Project: TencentKona-8   Source File: XRMaskBlit.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void MaskBlit(SurfaceData src, SurfaceData dst, Composite comp,
        Region clip, int srcx, int srcy, int dstx, int dsty, int width,
        int height, byte[] mask, int maskoff, int maskscan) {
    if (width <= 0 || height <= 0) {
        return;
    }

    try {
        SunToolkit.awtLock();

        XRSurfaceData x11sd = (XRSurfaceData) src;
        x11sd.validateAsSource(null, XRUtils.RepeatNone, XRUtils.FAST);

        XRCompositeManager maskBuffer = x11sd.maskBuffer;
        XRSurfaceData x11dst = (XRSurfaceData) dst;
        x11dst.validateAsDestination(null, clip);

        int maskPict = maskBuffer.getMaskBuffer().
                     uploadMask(width, height, maskscan, maskoff, mask);
        maskBuffer.XRComposite(x11sd.getPicture(), maskPict, x11dst.getPicture(),
                              srcx, srcy, 0, 0, dstx, dsty, width, height);
        maskBuffer.getMaskBuffer().clearUploadMask(maskPict, width, height);
    } finally {
        SunToolkit.awtUnlock();
    }
}
 
Example 4
Source Project: jdk8u-jdk   Source File: PeekMetrics.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Record information about drawing done
 * with the supplied <code>Composite</code>.
 */
private void checkAlpha(Composite composite) {

    if (composite instanceof AlphaComposite) {
        AlphaComposite alphaComposite = (AlphaComposite) composite;
        float alpha = alphaComposite.getAlpha();
        int rule = alphaComposite.getRule();

        if (alpha != 1.0
                || (rule != AlphaComposite.SRC
                    && rule != AlphaComposite.SRC_OVER)) {

            mHasCompositing = true;
        }

    } else {
        mHasCompositing = true;
    }

}
 
Example 5
Source Project: ECG-Viewer   Source File: Plot.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the background image (if there is one) aligned within the
 * specified area.
 *
 * @param g2  the graphics device.
 * @param area  the area.
 *
 * @see #getBackgroundImage()
 * @see #getBackgroundImageAlignment()
 * @see #getBackgroundImageAlpha()
 */
public void drawBackgroundImage(Graphics2D g2, Rectangle2D area) {
    if (this.backgroundImage == null) {
        return;  // nothing to do
    }
    Composite savedComposite = g2.getComposite();
    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            this.backgroundImageAlpha));
    Rectangle2D dest = new Rectangle2D.Double(0.0, 0.0,
            this.backgroundImage.getWidth(null),
            this.backgroundImage.getHeight(null));
    Align.align(dest, area, this.backgroundImageAlignment);
    Shape savedClip = g2.getClip();
    g2.clip(area);
    g2.drawImage(this.backgroundImage, (int) dest.getX(),
            (int) dest.getY(), (int) dest.getWidth() + 1,
            (int) dest.getHeight() + 1, null);
    g2.setClip(savedClip);
    g2.setComposite(savedComposite);
}
 
Example 6
Source Project: jdk8u_jdk   Source File: X11PMBlitLoops.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy,
                 int dx, int dy,
                 int w, int h)
{
    SunToolkit.awtLock();
    try {
        X11SurfaceData x11sd = (X11SurfaceData)dst;
        // pass null clip region here since we clip manually in native code
        // also use false for needExposures since we clip to the pixmap
        long xgc = x11sd.getBlitGC(null, false);
        nativeBlit(src.getNativeOps(), dst.getNativeOps(), xgc, clip,
                   sx, sy, dx, dy, w, h);
    } finally {
        SunToolkit.awtUnlock();
    }
}
 
Example 7
Source Project: dragonwell8_jdk   Source File: GDIRenderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
void doDrawLine(GDIWindowSurfaceData sData,
                Region clip, Composite comp, int color,
                int x1, int y1, int x2, int y2)
{
    GraphicsPrimitive.tracePrimitive("GDIDrawLine");
    super.doDrawLine(sData, clip, comp, color, x1, y1, x2, y2);
}
 
Example 8
Source Project: dragonwell8_jdk   Source File: GDIRenderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
void doFillOval(GDIWindowSurfaceData sData,
                Region clip, Composite comp, int color,
                int x, int y, int w, int h)
{
    GraphicsPrimitive.tracePrimitive("GDIFillOval");
    super.doFillOval(sData, clip, comp, color, x, y, w, h);
}
 
Example 9
Source Project: jdk8u-jdk   Source File: GDIRenderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
void doFillPoly(GDIWindowSurfaceData sData,
                Region clip, Composite comp, int color,
                int transx, int transy,
                int[] xpoints, int[] ypoints,
                int npoints)
{
    GraphicsPrimitive.tracePrimitive("GDIFillPoly");
    super.doFillPoly(sData, clip, comp, color, transx, transy,
                     xpoints, ypoints, npoints);
}
 
Example 10
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy,
                 int w, int h)
{
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        // make sure the RenderQueue keeps a hard reference to the
        // destination (sysmem) SurfaceData to prevent it from being
        // disposed while the operation is processed on the QFT
        rq.addReference(dst);

        RenderBuffer buf = rq.getBuffer();
        D3DContext.setScratchSurface(((D3DSurfaceData)src).getContext());

        rq.ensureCapacityAndAlignment(48, 32);
        buf.putInt(SURFACE_TO_SW_BLIT);
        buf.putInt(sx).putInt(sy);
        buf.putInt(dx).putInt(dy);
        buf.putInt(w).putInt(h);
        buf.putInt(typeval);
        buf.putLong(src.getNativeOps());
        buf.putLong(dst.getNativeOps());

        // always flush immediately
        rq.flushNow();
    } finally {
        rq.unlock();
    }
}
 
Example 11
Source Project: hottub   Source File: GDIRenderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
void doFillRect(GDIWindowSurfaceData sData,
                Region clip, Composite comp, int color,
                int x, int y, int w, int h)
{
    GraphicsPrimitive.tracePrimitive("GDIFillRect");
    super.doFillRect(sData, clip, comp, color, x, y, w, h);
}
 
Example 12
Source Project: jdk8u60   Source File: GDIRenderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
void doDrawPoly(GDIWindowSurfaceData sData,
                Region clip, Composite comp, int color,
                int transx, int transy,
                int[] xpoints, int[] ypoints,
                int npoints, boolean isclosed)
{
    GraphicsPrimitive.tracePrimitive("GDIDrawPoly");
    super.doDrawPoly(sData, clip, comp, color, transx, transy,
                     xpoints, ypoints, npoints, isclosed);
}
 
Example 13
@Override
protected void validateContext(SunGraphics2D sg2d, Composite comp) {
    // assert rq.lock.isHeldByCurrentThread();
    OGLSurfaceData oglDst = (OGLSurfaceData)sg2d.surfaceData;
    OGLContext.validateContext(oglDst, oglDst,
                               sg2d.getCompClip(), comp,
                               null, sg2d.paint, sg2d,
                               OGLContext.NO_CONTEXT_FLAGS);
}
 
Example 14
Source Project: openjdk-jdk9   Source File: D3DBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Scale(SurfaceData src, SurfaceData dst,
                  Composite comp, Region clip,
                  int sx1, int sy1,
                  int sx2, int sy2,
                  double dx1, double dy1,
                  double dx2, double dy2)
{
    D3DBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx1, sy1, sx2, sy2,
                         dx1, dy1, dx2, dy2,
                         true);
}
 
Example 15
Source Project: jdk8u-jdk   Source File: Blit.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 16
Source Project: TencentKona-8   Source File: D3DBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Scale(SurfaceData src, SurfaceData dst,
                  Composite comp, Region clip,
                  int sx1, int sy1,
                  int sx2, int sy2,
                  double dx1, double dy1,
                  double dx2, double dy2)
{
    D3DBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx1, sy1, sx2, sy2,
                      dx1, dy1, dx2, dy2,
                      typeval, false);
}
 
Example 17
Source Project: jdk8u_jdk   Source File: GDIRenderer.java    License: GNU General Public License v2.0 5 votes vote down vote up
void doDrawRect(GDIWindowSurfaceData sData,
                Region clip, Composite comp, int color,
                int x, int y, int w, int h)
{
    GraphicsPrimitive.tracePrimitive("GDIDrawRect");
    super.doDrawRect(sData, clip, comp, color, x, y, w, h);
}
 
Example 18
Source Project: jdk8u60   Source File: D3DBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Scale(SurfaceData src, SurfaceData dst,
                  Composite comp, Region clip,
                  int sx1, int sy1,
                  int sx2, int sy2,
                  double dx1, double dy1,
                  double dx2, double dy2)
{
    D3DBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx1, sy1, sx2, sy2,
                      dx1, dy1, dx2, dy2,
                      typeval, false);
}
 
Example 19
Source Project: jdk8u60   Source File: Blit.java    License: GNU General Public License v2.0 5 votes vote down vote up
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();
}
 
Example 20
Source Project: hottub   Source File: D3DBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy,
                 int w, int h)
{
    D3DRenderQueue rq = D3DRenderQueue.getInstance();
    rq.lock();
    try {
        // make sure the RenderQueue keeps a hard reference to the
        // destination (sysmem) SurfaceData to prevent it from being
        // disposed while the operation is processed on the QFT
        rq.addReference(dst);

        RenderBuffer buf = rq.getBuffer();
        D3DContext.setScratchSurface(((D3DSurfaceData)src).getContext());

        rq.ensureCapacityAndAlignment(48, 32);
        buf.putInt(SURFACE_TO_SW_BLIT);
        buf.putInt(sx).putInt(sy);
        buf.putInt(dx).putInt(dy);
        buf.putInt(w).putInt(h);
        buf.putInt(typeval);
        buf.putLong(src.getNativeOps());
        buf.putLong(dst.getNativeOps());

        // always flush immediately
        rq.flushNow();
    } finally {
        rq.unlock();
    }
}
 
Example 21
Source Project: SIMVA-SoS   Source File: ClipPath.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Draws the clip path.
 *
 * @param g2  current graphics2D.
 * @param dataArea  the dataArea that the plot is being draw in.
 * @param horizontalAxis  the horizontal axis.
 * @param verticalAxis  the vertical axis.
 *
 * @return The GeneralPath defining the outline
 */
public GeneralPath draw(Graphics2D g2,
                        Rectangle2D dataArea,
                        ValueAxis horizontalAxis, ValueAxis verticalAxis) {

    GeneralPath generalPath = generateClipPath(
        dataArea, horizontalAxis, verticalAxis
    );
    if (this.fillPath || this.drawPath) {
        Composite saveComposite = g2.getComposite();
        Paint savePaint = g2.getPaint();
        Stroke saveStroke = g2.getStroke();

        if (this.fillPaint != null) {
            g2.setPaint(this.fillPaint);
        }
        if (this.composite != null) {
            g2.setComposite(this.composite);
        }
        if (this.fillPath) {
            g2.fill(generalPath);
        }

        if (this.drawStroke != null) {
            g2.setStroke(this.drawStroke);
        }
        if (this.drawPath) {
            g2.draw(generalPath);
        }
        g2.setPaint(savePaint);
        g2.setComposite(saveComposite);
        g2.setStroke(saveStroke);
    }
    return generalPath;

}
 
Example 22
Source Project: jdk8u-dev-jdk   Source File: D3DBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Scale(SurfaceData src, SurfaceData dst,
                  Composite comp, Region clip,
                  int sx1, int sy1,
                  int sx2, int sy2,
                  double dx1, double dy1,
                  double dx2, double dy2)
{
    D3DBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx1, sy1, sx2, sy2,
                         dx1, dy1, dx2, dy2,
                         false);
}
 
Example 23
Source Project: TencentKona-8   Source File: D3DBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void Transform(SurfaceData src, SurfaceData dst,
                      Composite comp, Region clip,
                      AffineTransform at, int hint,
                      int sx, int sy, int dx, int dy,
                      int w, int h)
{
    // see comment above
    D3DVolatileSurfaceManager.handleVItoScreenOp(src, dst);
}
 
Example 24
Source Project: jdk8u-jdk   Source File: OGLBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Scale(SurfaceData src, SurfaceData dst,
                  Composite comp, Region clip,
                  int sx1, int sy1,
                  int sx2, int sy2,
                  double dx1, double dy1,
                  double dx2, double dy2)
{
    OGLBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, null,
                         AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                         sx1, sy1, sx2, sy2,
                         dx1, dy1, dx2, dy2,
                         true);
}
 
Example 25
Source Project: dsworkbench   Source File: ChurchLayerRenderer.java    License: Apache License 2.0 5 votes vote down vote up
void renderTempChurch(Graphics2D g2d, KnownVillage tmpVillage, Rectangle r) {
    Composite cb = g2d.getComposite();
    Color cob = g2d.getColor();
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .3f));
    GeneralPath p = ChurchLayerRenderer.calculateChurchPath(tmpVillage, r.width, r.height);
    g2d.setColor(Constants.DS_BACK_LIGHT);
    g2d.fill(p);
    g2d.setComposite(cb);
    g2d.setColor(Constants.DS_BACK);
    g2d.draw(p);
    g2d.setColor(cob);
}
 
Example 26
Source Project: jdk8u-jdk   Source File: TransformHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Transform(MaskBlit output,
                      SurfaceData src, SurfaceData dst,
                      Composite comp, Region clip,
                      AffineTransform itx, int txtype,
                      int sx1, int sy1, int sx2, int sy2,
                      int dx1, int dy1, int dx2, int dy2,
                      int edges[], int dxoff, int dyoff)
{
    tracePrimitive(target);
    target.Transform(output, src, dst, comp, clip, itx, txtype,
                     sx1, sy1, sx2, sy2,
                     dx1, dy1, dx2, dy2,
                     edges, dxoff, dyoff);
}
 
Example 27
Source Project: jdk8u_jdk   Source File: OGLBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Blit(SurfaceData src, SurfaceData dst,
                 Composite comp, Region clip,
                 int sx, int sy, int dx, int dy, int w, int h)
{
    OGLBlitLoops.Blit(src, dst,
                      comp, clip, null,
                      AffineTransformOp.TYPE_NEAREST_NEIGHBOR,
                      sx, sy, sx+w, sy+h,
                      dx, dy, dx+w, dy+h,
                      typeval, false);
}
 
Example 28
Source Project: openjdk-8   Source File: OGLBlitLoops.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void Transform(SurfaceData src, SurfaceData dst,
                      Composite comp, Region clip,
                      AffineTransform at, int hint,
                      int sx, int sy, int dx, int dy, int w, int h)
{
    OGLBlitLoops.IsoBlit(src, dst,
                         null, null,
                         comp, clip, at, hint,
                         sx, sy, sx+w, sy+h,
                         dx, dy, dx+w, dy+h,
                         true);
}
 
Example 29
Source Project: audiveris   Source File: BeamSymbol.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void paint (Graphics2D g,
                      Params params,
                      Point location,
                      Alignment alignment)
{
    MyParams p = (MyParams) params;
    Point loc = alignment.translatedPoint(TOP_RIGHT, p.rect, location);

    // Beams
    Rectangle2D quarterRect = p.layout.getBounds();
    int beamHeight = (int) Math.rint(quarterRect.getHeight() * 0.12);
    int beamDelta = (int) Math.rint(quarterRect.getHeight() * 0.18);

    for (int i = 0; i < beamCount; i++) {
        Point left = new Point(loc.x - p.quarterDx, loc.y + (i * beamDelta) + p.quarterDy);
        Point right = new Point(loc.x, loc.y + (i * beamDelta));
        Polygon polygon = new Polygon();
        polygon.addPoint(left.x, left.y);
        polygon.addPoint(left.x, left.y + beamHeight);
        polygon.addPoint(right.x, right.y + beamHeight);
        polygon.addPoint(right.x, right.y);
        g.fill(polygon);
    }

    // Decorations (using composite)
    Composite oldComposite = g.getComposite();
    g.setComposite(decoComposite);

    MusicFont.paint(g, p.layout, loc, TOP_RIGHT);
    loc.translate(-p.quarterDx, p.quarterDy);
    MusicFont.paint(g, p.layout, loc, TOP_RIGHT);

    g.setComposite(oldComposite);
}
 
Example 30
Source Project: jdk8u-jdk   Source File: MaskFill.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void DrawAAPgram(SunGraphics2D sg2d, SurfaceData sData,
                        Composite comp,
                        double x, double y,
                        double dx1, double dy1,
                        double dx2, double dy2,
                        double lw1, double lw2)
{
    tracePrimitive(drawPgramTarget);
    target.DrawAAPgram(sg2d, sData, comp,
                       x, y, dx1, dy1, dx2, dy2, lw1, lw2);
}