Search in sources :

Example 1 with VolatileImage

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

the class FillTexturePaint method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(size, size);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.setPaint(shape);
        g2d.fill(new Rectangle(0, 0, size, size));
        g2d.dispose();
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        BufferedImage bi = vi.getSnapshot();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        for (int x = 0; x < size; ++x) {
            for (int y = 0; y < size; ++y) {
                if (bi.getRGB(x, y) != Color.GREEN.getRGB()) {
                    throw new RuntimeException("Test failed.");
                }
            }
        }
        break;
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) Rectangle(java.awt.Rectangle) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) TexturePaint(java.awt.TexturePaint) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 2 with VolatileImage

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

the class FlipDrawImage method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(width, height);
    final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setColor(Color.red);
        g2d.fillRect(0, 0, width, height);
        g2d.setColor(Color.green);
        g2d.fillRect(0, 0, width / 2, height / 2);
        g2d.dispose();
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        Graphics2D g = bi.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.setColor(Color.BLUE);
        g.fillRect(0, 0, width, height);
        // destination width and height are flipped and scale is used.
        g.drawImage(vi, width / 2, height / 2, -width / 2, -height / 2, null, null);
        g.dispose();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                if (x < width / 2 && y < height / 2) {
                    if (x >= width / 4 && y >= height / 4) {
                        if (bi.getRGB(x, y) != Color.green.getRGB()) {
                            throw new RuntimeException("Test failed.");
                        }
                    } else if (bi.getRGB(x, y) != Color.red.getRGB()) {
                        throw new RuntimeException("Test failed.");
                    }
                } else {
                    if (bi.getRGB(x, y) != Color.BLUE.getRGB()) {
                        throw new RuntimeException("Test failed.");
                    }
                }
            }
        }
        break;
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 3 with VolatileImage

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

the class TransformSetGet method main.

public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    final VolatileImage vi = gc.createCompatibleVolatileImage(200, 200);
    final SunGraphics2D sg2d = (SunGraphics2D) vi.createGraphics();
    sg2d.constrain(0, 61, 100, 100);
    final AffineTransform expected = sg2d.cloneTransform();
    sg2d.setTransform(sg2d.getTransform());
    final AffineTransform actual = sg2d.cloneTransform();
    sg2d.dispose();
    vi.flush();
    if (!expected.equals(actual)) {
        System.out.println("Expected = " + expected);
        System.out.println("Actual = " + actual);
        throw new RuntimeException("Wrong transform");
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) AffineTransform(java.awt.geom.AffineTransform) SunGraphics2D(sun.java2d.SunGraphics2D) GraphicsEnvironment(java.awt.GraphicsEnvironment) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 4 with VolatileImage

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

the class IncorrectAlphaConversionBicubic method main.

public static void main(final String[] args) {
    final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    final GraphicsDevice gd = ge.getDefaultScreenDevice();
    final GraphicsConfiguration gc = gd.getDefaultConfiguration();
    final VolatileImage vi = gc.createCompatibleVolatileImage(SIZE, SIZE, TRANSLUCENT);
    final BufferedImage bi = makeUnmanagedBI(gc, TRANSLUCENT);
    final int expected = bi.getRGB(2, 2);
    int attempt = 0;
    BufferedImage snapshot;
    while (true) {
        if (++attempt > 10) {
            throw new RuntimeException("Too many attempts: " + attempt);
        }
        vi.validate(gc);
        final Graphics2D g2d = vi.createGraphics();
        g2d.setComposite(AlphaComposite.Src);
        g2d.scale(2, 2);
        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g2d.drawImage(bi, 0, 0, null);
        g2d.dispose();
        snapshot = vi.getSnapshot();
        if (vi.contentsLost()) {
            continue;
        }
        break;
    }
    final int actual = snapshot.getRGB(2, 2);
    if (actual != expected) {
        System.err.println("Actual: " + Integer.toHexString(actual));
        System.err.println("Expected: " + Integer.toHexString(expected));
        throw new RuntimeException("Test failed");
    }
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 5 with VolatileImage

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

the class IncorrectBounds method main.

public static void main(final String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(width / 4, height / 4);
    final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    while (true) {
        vi.validate(gc);
        Graphics2D g2d = vi.createGraphics();
        g2d.setColor(Color.green);
        g2d.fillRect(0, 0, width / 4, height / 4);
        g2d.dispose();
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        Graphics2D g = bi.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.setColor(Color.red);
        g.fillRect(0, 0, width, height);
        // Use sx and sy outside of VI bounds.
        g.drawImage(vi, 0, 0, width / 2, height / 2, 0, 0, width * 2, height * 2, null);
        g.dispose();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException ignored) {
            }
            continue;
        }
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                if (x < width / 16 && y < height / 16) {
                    if (bi.getRGB(x, y) != Color.green.getRGB()) {
                        throw new RuntimeException("Test failed.");
                    }
                } else {
                    if (bi.getRGB(x, y) != Color.red.getRGB()) {
                        throw new RuntimeException("Test failed.");
                    }
                }
            }
        }
        break;
    }
}
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