Search in sources :

Example 46 with VolatileImage

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

the class JPEGsNotAcceleratedTest method runTestOnImage.

public void runTestOnImage(String desc, BufferedImage bi, Rectangle srcROI) {
    if (srcROI == null) {
        srcROI = new Rectangle(0, 0, TEST_W, TEST_H);
    }
    VolatileImage testVI = accelerateImage(bi);
    ImageCapabilities ic = bi.getCapabilities(f.getGraphicsConfiguration());
    boolean accelerated = ic.isAccelerated();
    System.err.println("Testing: " + desc + " -- bi.isAccelerated(): " + accelerated);
    BufferedImage snapshot = testVI.getSnapshot();
    if (showRes) {
        showRes(desc, snapshot);
    }
    for (int y = 0; y < srcROI.height; y++) {
        for (int x = 0; x < srcROI.width; x++) {
            int destRGB = snapshot.getRGB(x, y);
            if (destRGB != testRGB && destRGB != 0xfffe0000) {
                failed = true;
                System.err.printf("Test failed at %dx%d pixel=%x\n", x, y, snapshot.getRGB(x, y));
                if (!showRes) {
                    showRes(desc, snapshot);
                }
                break;
            }
        }
    }
}
Also used : VolatileImage(java.awt.image.VolatileImage) Rectangle(java.awt.Rectangle) ImageCapabilities(java.awt.ImageCapabilities) BufferedImage(java.awt.image.BufferedImage)

Example 47 with VolatileImage

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

the class JPEGsNotAcceleratedTest method accelerateImage.

public VolatileImage accelerateImage(BufferedImage bi) {
    VolatileImage testVI = f.createVolatileImage(TEST_W, TEST_H);
    do {
        if (testVI.validate(f.getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) {
            testVI = f.createVolatileImage(TEST_W, TEST_H);
        }
        Graphics2D g = testVI.createGraphics();
        g.setComposite(AlphaComposite.Src);
        g.setColor(Color.green);
        g.fillRect(0, 0, TEST_W, TEST_H);
        g.drawImage(bi, 0, 0, null);
        g.drawImage(bi, 0, 0, null);
        g.drawImage(bi, 0, 0, null);
        g.dispose();
    } while (testVI.contentsLost());
    return testVI;
}
Also used : VolatileImage(java.awt.image.VolatileImage) Graphics2D(java.awt.Graphics2D)

Example 48 with VolatileImage

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

the class DrawImageBgTest method main.

public static void main(String[] args) {
    GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
    if (gc.getColorModel().getPixelSize() <= 8) {
        System.out.println("8-bit color model, test considered passed");
        return;
    }
    /*
         * Set up images:
         * 1.) VolatileImge for rendering to,
         * 2.) BufferedImage for reading back the contents of the VI
         * 3.) The image triggering the problem
         */
    VolatileImage vImg = null;
    BufferedImage readBackBImg;
    // create a BITMASK ICM such that the transparent color is
    // tr. black (and it's the first in the color map so a buffered image
    // created with this ICM is transparent
    byte[] r = { 0x00, (byte) 0xff };
    byte[] g = { 0x00, (byte) 0xff };
    byte[] b = { 0x00, (byte) 0xff };
    IndexColorModel icm = new IndexColorModel(8, 2, r, g, b, 0);
    WritableRaster wr = icm.createCompatibleWritableRaster(25, 25);
    BufferedImage tImg = new BufferedImage(icm, wr, false, null);
    do {
        if (vImg == null || vImg.validate(gc) == VolatileImage.IMAGE_INCOMPATIBLE) {
            vImg = gc.createCompatibleVolatileImage(tImg.getWidth(), tImg.getHeight());
        }
        Graphics viG = vImg.getGraphics();
        viG.setColor(Color.red);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());
        viG.drawImage(tImg, 0, 0, Color.green, null);
        viG.fillRect(0, 0, vImg.getWidth(), vImg.getHeight());
        viG.drawImage(tImg, 0, 0, Color.white, null);
        readBackBImg = vImg.getSnapshot();
    } while (vImg.contentsLost());
    for (int x = 0; x < readBackBImg.getWidth(); x++) {
        for (int y = 0; y < readBackBImg.getHeight(); y++) {
            int currPixel = readBackBImg.getRGB(x, y);
            if (currPixel != Color.white.getRGB()) {
                String fileName = "DrawImageBgTest.png";
                try {
                    ImageIO.write(readBackBImg, "png", new File(fileName));
                    System.err.println("Dumped image to " + fileName);
                } catch (IOException ex) {
                }
                throw new RuntimeException("Test Failed: found wrong color: 0x" + Integer.toHexString(currPixel));
            }
        }
    }
    System.out.println("Test Passed.");
}
Also used : Graphics(java.awt.Graphics) VolatileImage(java.awt.image.VolatileImage) WritableRaster(java.awt.image.WritableRaster) IOException(java.io.IOException) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) GraphicsConfiguration(java.awt.GraphicsConfiguration) IndexColorModel(java.awt.image.IndexColorModel)

Example 49 with VolatileImage

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

the class bug7181438 method main.

public static void main(final String[] args) {
    final BufferedImage bi = createBufferedImage();
    final VolatileImage vi = createVolatileImage();
    final Graphics s2dVi = vi.getGraphics();
    //sw->texture->surface blit
    s2dVi.drawImage(bi, 0, 0, null);
    final BufferedImage results = vi.getSnapshot();
    for (int i = 0; i < SIZE; ++i) {
        for (int j = 0; j < SIZE; ++j) {
            //Image should be opaque: (black color and alpha = 255)
            if (results.getRGB(i, j) != 0xFF000000) {
                throw new RuntimeException("Failed: Wrong alpha");
            }
        }
    }
    System.out.println("Passed");
}
Also used : Graphics(java.awt.Graphics) VolatileImage(java.awt.image.VolatileImage) BufferedImage(java.awt.image.BufferedImage)

Example 50 with VolatileImage

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

the class DrawCachedImageAndTransform method main.

public static void main(String[] args) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc = ge.getDefaultScreenDevice().getDefaultConfiguration();
    VolatileImage vi = gc.createCompatibleVolatileImage(100, 100);
    Graphics2D g2d = vi.createGraphics();
    g2d.scale(2, 2);
    BufferedImage img = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);
    g2d.drawImage(img, 10, 25, Color.blue, null);
    g2d.dispose();
}
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)52 GraphicsConfiguration (java.awt.GraphicsConfiguration)30 BufferedImage (java.awt.image.BufferedImage)28 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 Point (java.awt.Point)2