Search in sources :

Example 91 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class AcceleratedScaleTest method main.

public static void main(String[] args) {
    Frame f = new Frame();
    f.pack();
    GraphicsConfiguration gc = f.getGraphicsConfiguration();
    if (gc.getColorModel().getPixelSize() < 16) {
        System.out.printf("Bit depth: %d . Test considered passed.", gc.getColorModel().getPixelSize());
        f.dispose();
        return;
    }
    BufferedImage bi = new BufferedImage(IMAGE_SIZE / 4, IMAGE_SIZE / 4, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = (Graphics2D) bi.getGraphics();
    g.setColor(Color.red);
    g.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    BufferedImage snapshot;
    do {
        initVI(gc);
        g = (Graphics2D) destVI.getGraphics();
        // "accelerate" BufferedImage
        for (int i = 0; i < 5; i++) {
            g.drawImage(bi, 0, 0, null);
        }
        g.setColor(Color.white);
        g.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
        // this will force the use of Transform primitive instead of
        // Scale (the latter doesn't do bilinear filtering required by
        // VALUE_RENDER_QUALITY, which triggers the bug in D3D pipeline
        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.drawImage(bi, 0, 0, destVI.getWidth(), destVI.getHeight(), null);
        g.fillRect(0, 0, destVI.getWidth(), destVI.getHeight());
        g.drawImage(bi, 0, 0, destVI.getWidth(), destVI.getHeight(), null);
        snapshot = destVI.getSnapshot();
    } while (destVI.contentsLost());
    f.dispose();
    int whitePixel = Color.white.getRGB();
    for (int y = 0; y < snapshot.getHeight(); y++) {
        for (int x = 0; x < snapshot.getWidth(); x++) {
            if (snapshot.getRGB(x, y) == whitePixel) {
                System.out.printf("Found untouched pixel at %dx%d\n", x, y);
                System.out.println("Dumping the dest. image to " + "AcceleratedScaleTest_dst.png");
                try {
                    ImageIO.write(snapshot, "png", new File("AcceleratedScaleTest_dst.png"));
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
                throw new RuntimeException("Test failed.");
            }
        }
    }
    System.out.println("Test Passed.");
}
Also used : Frame(java.awt.Frame) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 92 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class MutableColorTest method main.

public static void main(String[] args) {
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    bmImage = gc.createCompatibleImage(64, 64, Transparency.BITMASK);
    argbImage = gc.createCompatibleImage(64, 64, Transparency.TRANSLUCENT);
    if (gc.getColorModel().getPixelSize() > 8) {
        VolatileImage vi = gc.createCompatibleVolatileImage(64, 64, Transparency.OPAQUE);
        do {
            if (vi.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
                vi = gc.createCompatibleVolatileImage(64, 64, Transparency.OPAQUE);
                vi.validate(gc);
            }
            int color = testImage(vi, false, false);
            testResult("vi_noclip_notx", vi.getSnapshot(), color);
            color = testImage(vi, true, true);
            testResult("vi_clip_tx", vi.getSnapshot(), color);
            color = testImage(vi, true, false);
            testResult("vi_clip_notx", vi.getSnapshot(), color);
            color = testImage(vi, false, true);
            testResult("vi_noclip_tx", vi.getSnapshot(), color);
        } while (vi.contentsLost());
    }
    BufferedImage bi = new BufferedImage(64, 64, BufferedImage.TYPE_INT_RGB);
    int color = testImage(bi, false, false);
    testResult("bi_noclip_notx", bi, color);
    color = testImage(bi, true, true);
    testResult("bi_clip_tx", bi, color);
    color = testImage(bi, true, false);
    testResult("bi_clip_notx", bi, color);
    color = testImage(bi, false, true);
    testResult("bi_noclip_tx", bi, color);
    System.err.println("Test passed.");
}
Also used : VolatileImage(java.awt.image.VolatileImage) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 93 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class IncorrectSourceOffset method main.

public static void main(final String[] args) throws IOException {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(511, 255);
    BufferedImage bi = new BufferedImage(511, 255, BufferedImage.TYPE_INT_ARGB);
    BufferedImage gold = new BufferedImage(511, 255, BufferedImage.TYPE_INT_ARGB);
    fill(gold);
    while (true) {
        vi.validate(gc);
        fill(vi);
        if (vi.validate(gc) != VolatileImage.IMAGE_OK) {
            try {
                Thread.sleep(100);
            } catch (final InterruptedException ignored) {
            }
            continue;
        }
        Graphics2D big = bi.createGraphics();
        big.drawImage(vi, 7, 11, 127, 111, 7, 11, 127, 111, null);
        big.dispose();
        if (vi.contentsLost()) {
            try {
                Thread.sleep(100);
            } catch (final InterruptedException ignored) {
            }
            continue;
        }
        break;
    }
    for (int x = 7; x < 127; ++x) {
        for (int y = 11; y < 111; ++y) {
            if (gold.getRGB(x, y) != bi.getRGB(x, y)) {
                ImageIO.write(gold, "png", new File("gold.png"));
                ImageIO.write(bi, "png", new File("bi.png"));
                throw new RuntimeException("Test failed.");
            }
        }
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) GraphicsEnvironment(java.awt.GraphicsEnvironment) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) Graphics2D(java.awt.Graphics2D)

Example 94 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class bug8071705 method checkConfigs.

private static GraphicsDevice checkConfigs(GraphicsDevice[] devices) {
    GraphicsDevice correctDevice = null;
    if (devices.length < 2) {
        return correctDevice;
    }
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Rectangle screenBounds = new Rectangle(toolkit.getScreenSize());
    int halfScreen = screenBounds.height / 2;
    for (int i = 0; i < devices.length; i++) {
        if (devices[i].getType() == GraphicsDevice.TYPE_RASTER_SCREEN) {
            GraphicsConfiguration conf = devices[i].getDefaultConfiguration();
            Rectangle bounds = conf.getBounds();
            if (bounds.y >= halfScreen) {
                // found
                correctDevice = devices[i];
                break;
            }
        }
    }
    return correctDevice;
}
Also used : GraphicsDevice(java.awt.GraphicsDevice) Rectangle(java.awt.Rectangle) Toolkit(java.awt.Toolkit) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Example 95 with GraphicsConfiguration

use of java.awt.GraphicsConfiguration in project jdk8u_jdk by JetBrains.

the class bug8071705 method setLocation.

private static Rectangle setLocation(JFrame frame, GraphicsDevice device) {
    GraphicsConfiguration conf = device.getDefaultConfiguration();
    Rectangle bounds = conf.getBounds();
    // put just below half screen
    int x = bounds.x + bounds.width / 2;
    int y = bounds.y + bounds.height / 2;
    frame.setLocation(x, y);
    return bounds;
}
Also used : Rectangle(java.awt.Rectangle) Point(java.awt.Point) GraphicsConfiguration(java.awt.GraphicsConfiguration)

Aggregations

GraphicsConfiguration (java.awt.GraphicsConfiguration)134 GraphicsEnvironment (java.awt.GraphicsEnvironment)55 BufferedImage (java.awt.image.BufferedImage)46 Rectangle (java.awt.Rectangle)43 GraphicsDevice (java.awt.GraphicsDevice)38 Graphics2D (java.awt.Graphics2D)33 VolatileImage (java.awt.image.VolatileImage)31 Point (java.awt.Point)29 Dimension (java.awt.Dimension)21 Insets (java.awt.Insets)16 File (java.io.File)16 Graphics (java.awt.Graphics)13 IOException (java.io.IOException)13 Frame (java.awt.Frame)11 JFrame (javax.swing.JFrame)8 HeadlessException (java.awt.HeadlessException)7 Window (java.awt.Window)7 ImageIcon (javax.swing.ImageIcon)7 Color (java.awt.Color)6 AffineTransform (java.awt.geom.AffineTransform)6