Java Code Examples for sun.java2d.pipe.Region#clipRound()

The following examples show how to use sun.java2d.pipe.Region#clipRound() . 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 check out the related API usage on the sidebar.
Example 1
Source File: SunGraphicsEnvironment.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Converts coordinates from the user's space to the device space using
 * appropriate device transformation.
 *
 * @param  x coordinate in the user space
 * @param  y coordinate in the user space
 * @return the point which uses device space(pixels)
 */
public static Point convertToDeviceSpace(double x, double y) {
    GraphicsConfiguration gc = getLocalGraphicsEnvironment()
                    .getDefaultScreenDevice().getDefaultConfiguration();
    gc = getGraphicsConfigurationAtPoint(gc, x, y);

    AffineTransform tx = gc.getDefaultTransform();
    x = Region.clipRound(x * tx.getScaleX());
    y = Region.clipRound(y * tx.getScaleY());

    return new Point((int) x, (int) y);
}
 
Example 2
Source File: SunVolatileImage.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * This method creates a BufferedImage intended for use as a "snapshot"
 * or a backup surface with the given horizontal and vertical scale factors.
 */
public BufferedImage getBackupImage(double scaleX, double scaleY) {
    int w = Region.clipRound(getWidth() * scaleX);
    int h = Region.clipRound(getHeight() * scaleY);
    return graphicsConfig.createCompatibleImage(w, h, getTransparency());
}
 
Example 3
Source File: RepaintManager.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
private void paintDoubleBufferedFPScales(JComponent c, Image image,
                                         Graphics g, int clipX, int clipY,
                                         int clipW, int clipH) {
    Graphics osg = image.getGraphics();
    Graphics2D g2d = (Graphics2D) g;
    Graphics2D osg2d = (Graphics2D) osg;

    AffineTransform identity = new AffineTransform();
    int bw = Math.min(clipW, image.getWidth(null));
    int bh = Math.min(clipH, image.getHeight(null));
    int x, y, maxx, maxy;

    AffineTransform tx = g2d.getTransform();
    double scaleX = tx.getScaleX();
    double scaleY = tx.getScaleY();
    double trX = tx.getTranslateX();
    double trY = tx.getTranslateY();

    boolean translucent = volatileBufferType != Transparency.OPAQUE;
    Composite oldComposite = g2d.getComposite();

    try {
        for (x = clipX, maxx = clipX + clipW; x < maxx; x += bw) {
            for (y = clipY, maxy = clipY + clipH; y < maxy; y += bh) {

                // draw x, y, bw, bh
                int pixelx1 = Region.clipRound(x * scaleX + trX);
                int pixely1 = Region.clipRound(y * scaleY + trY);
                int pixelx2 = Region.clipRound((x + bw) * scaleX + trX);
                int pixely2 = Region.clipRound((y + bh) * scaleY + trY);
                int pixelw = pixelx2 - pixelx1;
                int pixelh = pixely2 - pixely1;

                osg2d.setTransform(identity);
                if (translucent) {
                    final Color oldBg = g2d.getBackground();
                    g2d.setBackground(c.getBackground());
                    g2d.clearRect(pixelx1, pixely1, pixelw, pixelh);
                    g2d.setBackground(oldBg);
                }

                osg2d.setClip(0, 0, pixelw, pixelh);
                osg2d.translate(trX - pixelx1, trY - pixely1);
                osg2d.scale(scaleX, scaleY);
                c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);

                g2d.setTransform(identity);
                g2d.setClip(pixelx1, pixely1, pixelw, pixelh);
                AffineTransform stx = new AffineTransform();
                stx.translate(pixelx1, pixely1);
                stx.scale(scaleX, scaleY);
                g2d.setTransform(stx);

                if (translucent) {
                    g2d.setComposite(AlphaComposite.Src);
                }

                g2d.drawImage(image, 0, 0, c);

                if (translucent) {
                    g2d.setComposite(oldComposite);
                }
                g2d.setTransform(tx);
            }
        }
    } finally {
        osg.dispose();
    }
}
 
Example 4
Source File: RepaintManager.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private void paintDoubleBufferedFPScales(JComponent c, Image image,
                                         Graphics g, int clipX, int clipY,
                                         int clipW, int clipH) {
    Graphics osg = image.getGraphics();
    Graphics2D g2d = (Graphics2D) g;
    Graphics2D osg2d = (Graphics2D) osg;

    AffineTransform identity = new AffineTransform();
    int bw = Math.min(clipW, image.getWidth(null));
    int bh = Math.min(clipH, image.getHeight(null));
    int x, y, maxx, maxy;

    AffineTransform tx = g2d.getTransform();
    double scaleX = tx.getScaleX();
    double scaleY = tx.getScaleY();
    double trX = tx.getTranslateX();
    double trY = tx.getTranslateY();

    boolean translucent = volatileBufferType != Transparency.OPAQUE;
    Composite oldComposite = g2d.getComposite();

    try {
        for (x = clipX, maxx = clipX + clipW; x < maxx; x += bw) {
            for (y = clipY, maxy = clipY + clipH; y < maxy; y += bh) {

                // draw x, y, bw, bh
                int pixelx1 = Region.clipRound(x * scaleX + trX);
                int pixely1 = Region.clipRound(y * scaleY + trY);
                int pixelx2 = Region.clipRound((x + bw) * scaleX + trX);
                int pixely2 = Region.clipRound((y + bh) * scaleY + trY);
                int pixelw = pixelx2 - pixelx1;
                int pixelh = pixely2 - pixely1;

                osg2d.setTransform(identity);
                if (translucent) {
                    final Color oldBg = g2d.getBackground();
                    g2d.setBackground(c.getBackground());
                    g2d.clearRect(pixelx1, pixely1, pixelw, pixelh);
                    g2d.setBackground(oldBg);
                }

                osg2d.setClip(0, 0, pixelw, pixelh);
                osg2d.translate(trX - pixelx1, trY - pixely1);
                osg2d.scale(scaleX, scaleY);
                c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);

                g2d.setTransform(identity);
                g2d.setClip(pixelx1, pixely1, pixelw, pixelh);
                AffineTransform stx = new AffineTransform();
                stx.translate(pixelx1, pixely1);
                stx.scale(scaleX, scaleY);
                g2d.setTransform(stx);

                if (translucent) {
                    g2d.setComposite(AlphaComposite.Src);
                }

                g2d.drawImage(image, 0, 0, c);

                if (translucent) {
                    g2d.setComposite(oldComposite);
                }
                g2d.setTransform(tx);
            }
        }
    } finally {
        osg.dispose();
    }
}
 
Example 5
Source File: RepaintManager.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private void paintDoubleBufferedFPScales(JComponent c, Image image,
                                         Graphics g, int clipX, int clipY,
                                         int clipW, int clipH) {
    Graphics osg = image.getGraphics();
    Graphics2D g2d = (Graphics2D) g;
    Graphics2D osg2d = (Graphics2D) osg;

    AffineTransform identity = new AffineTransform();
    int bw = Math.min(clipW, image.getWidth(null));
    int bh = Math.min(clipH, image.getHeight(null));
    int x, y, maxx, maxy;

    AffineTransform tx = g2d.getTransform();
    double scaleX = tx.getScaleX();
    double scaleY = tx.getScaleY();
    double trX = tx.getTranslateX();
    double trY = tx.getTranslateY();

    boolean translucent = volatileBufferType != Transparency.OPAQUE;
    Composite oldComposite = g2d.getComposite();

    try {
        for (x = clipX, maxx = clipX + clipW; x < maxx; x += bw) {
            for (y = clipY, maxy = clipY + clipH; y < maxy; y += bh) {

                // draw x, y, bw, bh
                int pixelx1 = Region.clipRound(x * scaleX + trX);
                int pixely1 = Region.clipRound(y * scaleY + trY);
                int pixelx2 = Region.clipRound((x + bw) * scaleX + trX);
                int pixely2 = Region.clipRound((y + bh) * scaleY + trY);
                int pixelw = pixelx2 - pixelx1;
                int pixelh = pixely2 - pixely1;

                osg2d.setTransform(identity);
                if (translucent) {
                    final Color oldBg = g2d.getBackground();
                    g2d.setBackground(c.getBackground());
                    g2d.clearRect(pixelx1, pixely1, pixelw, pixelh);
                    g2d.setBackground(oldBg);
                }

                osg2d.setClip(0, 0, pixelw, pixelh);
                osg2d.translate(trX - pixelx1, trY - pixely1);
                osg2d.scale(scaleX, scaleY);
                c.paintToOffscreen(osg, x, y, bw, bh, maxx, maxy);

                g2d.setTransform(identity);
                g2d.setClip(pixelx1, pixely1, pixelw, pixelh);
                AffineTransform stx = new AffineTransform();
                stx.translate(pixelx1, pixely1);
                stx.scale(scaleX, scaleY);
                g2d.setTransform(stx);

                if (translucent) {
                    g2d.setComposite(AlphaComposite.Src);
                }

                g2d.drawImage(image, 0, 0, c);

                if (translucent) {
                    g2d.setComposite(oldComposite);
                }
                g2d.setTransform(tx);
            }
        }
    } finally {
        osg.dispose();
    }
}