Search in sources :

Example 6 with Region

use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method validateCompClip.

protected void validateCompClip() {
    int origClipState = clipState;
    if (usrClip == null) {
        clipState = CLIP_DEVICE;
        clipRegion = devClip;
    } else if (usrClip instanceof Rectangle2D) {
        clipState = CLIP_RECTANGULAR;
        if (usrClip instanceof Rectangle) {
            clipRegion = devClip.getIntersection((Rectangle) usrClip);
        } else {
            clipRegion = devClip.getIntersection(usrClip.getBounds());
        }
    } else {
        PathIterator cpi = usrClip.getPathIterator(null);
        int[] box = new int[4];
        ShapeSpanIterator sr = LoopPipe.getFillSSI(this);
        try {
            sr.setOutputArea(devClip);
            sr.appendPath(cpi);
            sr.getPathBox(box);
            Region r = Region.getInstance(box);
            r.appendSpans(sr);
            clipRegion = r;
            clipState = r.isRectangular() ? CLIP_RECTANGULAR : CLIP_SHAPE;
        } finally {
            sr.dispose();
        }
    }
    if (origClipState != clipState && (clipState == CLIP_SHAPE || origClipState == CLIP_SHAPE)) {
        validFontInfo = false;
        invalidatePipe();
    }
}
Also used : ShapeSpanIterator(sun.java2d.pipe.ShapeSpanIterator) PathIterator(java.awt.geom.PathIterator) Rectangle2D(java.awt.geom.Rectangle2D) Rectangle(java.awt.Rectangle) Region(sun.java2d.pipe.Region) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 7 with Region

use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method drawRenderedImage.

/**
     * Draws an image, applying a transform from image space into user space
     * before drawing.
     * The transformation from user space into device space is done with
     * the current transform in the Graphics2D.
     * The given transformation is applied to the image before the
     * transform attribute in the Graphics2D state is applied.
     * The rendering attributes applied include the clip, transform,
     * and composite attributes. Note that the result is
     * undefined, if the given transform is noninvertible.
     * @param img The image to be drawn. Does nothing if img is null.
     * @param xform The transformation from image space into user space.
     * @see #transform
     * @see #setTransform
     * @see #setComposite
     * @see #clip
     * @see #setClip
     */
public void drawRenderedImage(RenderedImage img, AffineTransform xform) {
    if (img == null) {
        return;
    }
    // BufferedImage case: use a simple drawImage call
    if (img instanceof BufferedImage) {
        BufferedImage bufImg = (BufferedImage) img;
        drawImage(bufImg, xform, null);
        return;
    }
    // transformState tracks the state of transform and
    // transX, transY contain the integer casts of the
    // translation factors
    boolean isIntegerTranslate = (transformState <= TRANSFORM_INT_TRANSLATE) && isIntegerTranslation(xform);
    // Include padding for interpolation/antialiasing if necessary
    int pad = isIntegerTranslate ? 0 : 3;
    Region clip;
    try {
        clip = getCompClip();
    } catch (InvalidPipeException e) {
        return;
    }
    // Determine the region of the image that may contribute to
    // the clipped drawing area
    Rectangle region = getImageRegion(img, clip, transform, xform, pad, pad);
    if (region.width <= 0 || region.height <= 0) {
        return;
    }
    // where both are integer translations.
    if (isIntegerTranslate) {
        // Use optimized code
        // Note that drawTranslatedRenderedImage calls copyImage
        // which takes the user space to device space transform into
        // account, but we need to provide the image space to user space
        // translations.
        drawTranslatedRenderedImage(img, region, (int) xform.getTranslateX(), (int) xform.getTranslateY());
        return;
    }
    // General case: cobble the necessary region into a single Raster
    Raster raster = img.getData(region);
    // Make a new Raster with the same contents as raster
    // but starting at (0, 0).  This raster is thus in the same
    // coordinate system as the SampleModel of the original raster.
    WritableRaster wRaster = Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null);
    // If the original raster was in a different coordinate
    // system than its SampleModel, we need to perform an
    // additional translation in order to get the (minX, minY)
    // pixel of raster to be pixel (0, 0) of wRaster.  We also
    // have to have the correct width and height.
    int minX = raster.getMinX();
    int minY = raster.getMinY();
    int width = raster.getWidth();
    int height = raster.getHeight();
    int px = minX - raster.getSampleModelTranslateX();
    int py = minY - raster.getSampleModelTranslateY();
    if (px != 0 || py != 0 || width != wRaster.getWidth() || height != wRaster.getHeight()) {
        wRaster = wRaster.createWritableChild(px, py, width, height, 0, 0, null);
    }
    // Now we have a BufferedImage starting at (0, 0)
    // with the same contents that started at (minX, minY)
    // in raster.  So we must draw the BufferedImage with a
    // translation of (minX, minY).
    AffineTransform transXform = (AffineTransform) xform.clone();
    transXform.translate(minX, minY);
    ColorModel cm = img.getColorModel();
    BufferedImage bufImg = new BufferedImage(cm, wRaster, cm.isAlphaPremultiplied(), null);
    drawImage(bufImg, transXform, null);
}
Also used : WritableRaster(java.awt.image.WritableRaster) ColorModel(java.awt.image.ColorModel) Raster(java.awt.image.Raster) WritableRaster(java.awt.image.WritableRaster) Rectangle(java.awt.Rectangle) Region(sun.java2d.pipe.Region) AffineTransform(java.awt.geom.AffineTransform) BufferedImage(java.awt.image.BufferedImage) RadialGradientPaint(java.awt.RadialGradientPaint) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) LinearGradientPaint(java.awt.LinearGradientPaint) GradientPaint(java.awt.GradientPaint)

Example 8 with Region

use of sun.java2d.pipe.Region 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)

Example 9 with Region

use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.

the class SunGraphics2D method setDevClip.

public void setDevClip(int x, int y, int w, int h) {
    Region c = constrainClip;
    if (c == null) {
        devClip = Region.getInstanceXYWH(x, y, w, h);
    } else {
        devClip = c.getIntersectionXYWH(x, y, w, h);
    }
    validateCompClip();
}
Also used : Region(sun.java2d.pipe.Region)

Example 10 with Region

use of sun.java2d.pipe.Region in project jdk8u_jdk by JetBrains.

the class LWComponentPeer method findPeerAt.

// ---- UTILITY METHODS ---- //
/**
     * Finds a top-most visible component for the given point. The location is
     * specified relative to the peer's parent.
     */
LWComponentPeer<?, ?> findPeerAt(final int x, final int y) {
    final Rectangle r = getBounds();
    final Region sh = getRegion();
    final boolean found = isVisible() && sh.contains(x - r.x, y - r.y);
    return found ? this : null;
}
Also used : Region(sun.java2d.pipe.Region)

Aggregations

Region (sun.java2d.pipe.Region)22 Rectangle (java.awt.Rectangle)5 GradientPaint (java.awt.GradientPaint)3 LinearGradientPaint (java.awt.LinearGradientPaint)3 Paint (java.awt.Paint)3 RadialGradientPaint (java.awt.RadialGradientPaint)3 TexturePaint (java.awt.TexturePaint)3 ShapeSpanIterator (sun.java2d.pipe.ShapeSpanIterator)3 Composite (java.awt.Composite)2 AffineTransform (java.awt.geom.AffineTransform)2 ColorModel (java.awt.image.ColorModel)2 Raster (java.awt.image.Raster)2 WritableRaster (java.awt.image.WritableRaster)2 CompositeType (sun.java2d.loops.CompositeType)2 AlphaComposite (java.awt.AlphaComposite)1 Polygon (java.awt.Polygon)1 PathIterator (java.awt.geom.PathIterator)1 Rectangle2D (java.awt.geom.Rectangle2D)1 BufferedImage (java.awt.image.BufferedImage)1 IntegerComponentRaster (sun.awt.image.IntegerComponentRaster)1