Search in sources :

Example 36 with VolatileImage

use of java.awt.image.VolatileImage in project javatari by ppeccin.

the class SwingHelper method asCompatibleVolatileImage.

public static VolatileImage asCompatibleVolatileImage(Image img) {
    VolatileImage ret = defaultScreenDeviceConfiguration().createCompatibleVolatileImage(img.getWidth(null), img.getHeight(null));
    Graphics2D gc = ret.createGraphics();
    gc.drawImage(img, 0, 0, null);
    gc.dispose();
    return ret;
}
Also used : VolatileImage(java.awt.image.VolatileImage) Graphics2D(java.awt.Graphics2D)

Example 37 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class PixelTests method initTest.

public Object initTest(TestEnvironment env, Result result) {
    Context ctx = new Context();
    ctx.bimg = ((BufImg) env.getModifier(bufimgsrcroot)).getImage();
    if (env.isEnabled(doRenderTo)) {
        Graphics2D g2d = ctx.bimg.createGraphics();
        g2d.setColor(Color.white);
        g2d.fillRect(3, 0, 1, 1);
        g2d.dispose();
    }
    if (env.isEnabled(doRenderFrom)) {
        GraphicsConfiguration cfg = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        VolatileImage vimg = cfg.createCompatibleVolatileImage(8, 1);
        vimg.validate(cfg);
        Graphics2D g2d = vimg.createGraphics();
        for (int i = 0; i < 100; i++) {
            g2d.drawImage(ctx.bimg, 0, 0, null);
        }
        g2d.dispose();
        vimg.flush();
    }
    result.setUnits(1);
    result.setUnitName(getUnitName());
    return ctx;
}
Also used : VolatileImage(java.awt.image.VolatileImage) Graphics2D(java.awt.Graphics2D) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 38 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class TextRenderingTest method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setColor(Color.white);
        g2d.fillRect(0, 0, width, height);
        g2d.setPaint(new GradientPaint(new Point2D.Float(0, height / 2), Color.white, new Point2D.Float(width, height / 2), Color.black));
        g2d.fillRect(0, 0, width, height);
        String fnt = g2d.getFont().getFamily();
        g2d.setFont(new Font(fnt, Font.PLAIN, 100));
        // draw text with offset
        g2d.drawString("IIIIIIIIII", 100, 100);
        g2d.dispose();
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            continue;
        }
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            continue;
        }
        break;
    }
    BufferedImage bi = vi.getSnapshot();
    // the text shifted shouldn't be visible onto a painted rectangle!
    // so the check: color component (blue) must decrease monotonously
    int prev = Integer.MAX_VALUE;
    for (int x = 0; x < width; ++x) {
        int color = bi.getRGB(x, height / 2);
        int b = color & 0xFF;
        if (b > prev) {
            throw new RuntimeException("test failed: can see the text rendered!");
        }
        prev = b;
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GradientPaint(java.awt.GradientPaint) GraphicsEnvironment(java.awt.GraphicsEnvironment) Font(java.awt.Font) BufferedImage(java.awt.image.BufferedImage) GradientPaint(java.awt.GradientPaint) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 39 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class IncorrectClipSurface2SW method getVolatileImage.

private static VolatileImage getVolatileImage(GraphicsConfiguration gc, int size) {
    VolatileImage vi = gc.createCompatibleVolatileImage(size, size);
    Graphics2D g2d = vi.createGraphics();
    g2d.setColor(Color.GREEN);
    g2d.fillRect(0, 0, size, size);
    return vi;
}
Also used : VolatileImage(java.awt.image.VolatileImage) Graphics2D(java.awt.Graphics2D)

Example 40 with VolatileImage

use of java.awt.image.VolatileImage in project jdk8u_jdk by JetBrains.

the class IncorrectAlphaSurface2SW method main.

public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    BufferedImage destVI;
    BufferedImage destBI;
    BufferedImage sourceBI;
    VolatileImage sourceVI;
    for (final int s : SIZES) {
        for (final int srcType : srcTypes) {
            for (final int dstType : dstTypes) {
                for (final int scale : SCALES) {
                    int sw = s * scale;
                    destVI = new BufferedImage(sw, sw, dstType);
                    destBI = new BufferedImage(sw, sw, dstType);
                    sourceBI = gc.createCompatibleImage(sw, sw, srcType);
                    sourceVI = gc.createCompatibleVolatileImage(s, s, srcType);
                    // draw to dest BI using compatible image
                    fill(sourceBI, s);
                    Graphics2D big = destBI.createGraphics();
                    big.setComposite(AlphaComposite.Src);
                    big.drawImage(sourceBI, 0, 0, sw, sw, null);
                    big.dispose();
                    // draw to dest BI using compatible image
                    fill(sourceVI, s);
                    drawVItoBI(gc, destVI, sourceVI);
                    validate(destVI, destBI);
                    sourceVI.flush();
                }
            }
        }
    }
    System.out.println("Test PASSED");
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Aggregations

VolatileImage (java.awt.image.VolatileImage)53 GraphicsConfiguration (java.awt.GraphicsConfiguration)30 BufferedImage (java.awt.image.BufferedImage)29 Graphics2D (java.awt.Graphics2D)24 GraphicsEnvironment (java.awt.GraphicsEnvironment)21 Graphics (java.awt.Graphics)6 AffineTransform (java.awt.geom.AffineTransform)6 Rectangle (java.awt.Rectangle)5 File (java.io.File)5 GraphicsDevice (java.awt.GraphicsDevice)3 Shape (java.awt.Shape)3 IOException (java.io.IOException)3 DestSurfaceProvider (sun.java2d.DestSurfaceProvider)3 Surface (sun.java2d.Surface)3 AWTException (java.awt.AWTException)2 Font (java.awt.Font)2 GradientPaint (java.awt.GradientPaint)2 Image (java.awt.Image)2 ImageCapabilities (java.awt.ImageCapabilities)2 Paint (java.awt.Paint)2