Java Code Examples for java.awt.GraphicsConfiguration#getColorModel()

The following examples show how to use java.awt.GraphicsConfiguration#getColorModel() . 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: CachedHiDPIIcon.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static CachedImageKey create(Graphics2D g) {
    final AffineTransform tx = g.getTransform();
    final int txType = tx.getType();
    final double scale;
    if (txType == AffineTransform.TYPE_UNIFORM_SCALE ||
        txType == (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION))
    {
        scale = tx.getScaleX();
    } else {
        scale = 1.0;
    }
    GraphicsConfiguration gconf = g.getDeviceConfiguration();
    /* Always use the same transparency mode for the cached images, so we don't end up with
    one set of cached images for each encountered mode. The TRANSLUCENT mode is the most
    generic one; presumably it should paint OK onto less capable surfaces. */
    ColorModel colorModel = gconf.getColorModel(Transparency.TRANSLUCENT);
    return new CachedImageKey(colorModel, scale);
}
 
Example 2
Source File: IsToolkitUseTheMainScreen.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static void testHeadful() {
    GraphicsEnvironment ge
            = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsConfiguration gc
            = ge.getDefaultScreenDevice().getDefaultConfiguration();
    Dimension gcSize = gc.getBounds().getSize();
    ColorModel gcCM = gc.getColorModel();

    Dimension toolkitSize = Toolkit.getDefaultToolkit().getScreenSize();
    ColorModel toolkitCM = Toolkit.getDefaultToolkit().getColorModel();

    if (!gcSize.equals(toolkitSize)) {
        System.err.println("Toolkit size = " + toolkitSize);
        System.err.println("GraphicsConfiguration size = " + gcSize);
        throw new RuntimeException("Incorrect size");
    }
    if (!gcCM.equals(toolkitCM)) {
        System.err.println("Toolkit color model = " + toolkitCM);
        System.err.println("GraphicsConfiguration color model = " + gcCM);
        throw new RuntimeException("Incorrect color model");
    }
}
 
Example 3
Source File: PreviewPanel.java    From swingsane with Apache License 2.0 5 votes vote down vote up
public final void renderImagePreview(Graphics2D g) {

    if (sourceImage != null) {

      if (convertedImage == null) {

        GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment()
            .getDefaultScreenDevice();
        GraphicsConfiguration gc = gd.getDefaultConfiguration();

        if (sourceImage.getColorModel() != gc.getColorModel()) {
          convertedImage = gc.createCompatibleImage(sourceImage.getWidth(),
              sourceImage.getHeight(), Transparency.OPAQUE);
          Graphics2D g2d = convertedImage.createGraphics();
          g2d.drawImage(sourceImage, 0, 0, sourceImage.getWidth(), sourceImage.getHeight(), null);
          convertedImage.flush();
          g2d.dispose();
        } else {
          convertedImage = sourceImage;
        }

      }

      g.setColor(Color.darkGray);
      g.fill(new Rectangle2D.Double(0, 0, imagePreviewLabel.getWidth(), imagePreviewLabel
          .getHeight()));

      g.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
          RenderingHints.VALUE_FRACTIONALMETRICS_ON);
      g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);

      double x = (imagePreviewLabel.getWidth() / 2) - ((sourceImage.getWidth() * realZoom) / 2);
      double y = (imagePreviewLabel.getHeight() / 2) - ((sourceImage.getHeight() * realZoom) / 2);
      AffineTransform at = AffineTransform.getTranslateInstance(x, y);
      at.scale(realZoom, realZoom);
      g.drawRenderedImage(convertedImage, at);

    }

  }
 
Example 4
Source File: DrawImageBilinear.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 5
Source File: DrawImageBilinear.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 6
Source File: DrawImageBilinear.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 7
Source File: DrawImageBilinear.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 8
Source File: DrawImageBilinear.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 9
Source File: DrawImageBilinear.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 10
Source File: DrawImageBilinear.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 11
Source File: DrawImageBilinear.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 12
Source File: DrawImageBilinear.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 13
Source File: DrawImageBilinear.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 14
Source File: DrawImageBilinear.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 15
Source File: DrawImageBilinear.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 16
Source File: DrawImageBilinear.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    boolean show = false;
    for (String arg : args) {
        if ("-show".equals(arg)) {
            show = true;
        }
    }

    String arch = System.getProperty("os.arch");
    boolean isOglEnabled = Boolean.getBoolean("sun.java2d.opengl");
    skipOglTextureTest = isOglEnabled && ("sparc".equals(arch));
    System.out.println("Skip OpenGL texture test: " + skipOglTextureTest);

    DrawImageBilinear test = new DrawImageBilinear();
    Frame frame = new Frame();
    frame.add(test);
    frame.pack();
    frame.setVisible(true);

    // Wait until the component's been painted
    synchronized (test) {
        while (!done) {
            try {
                test.wait();
            } catch (InterruptedException e) {
                throw new RuntimeException("Failed: Interrupted");
            }
        }
    }

    GraphicsConfiguration gc = frame.getGraphicsConfiguration();
    if (gc.getColorModel() instanceof IndexColorModel) {
        System.out.println("IndexColorModel detected: " +
                           "test considered PASSED");
        frame.dispose();
        return;
    }

    if (!show) {
        frame.dispose();
    }
    if (capture == null) {
        throw new RuntimeException("Failed: capture is null");
    }

    // Test background color
    int pixel = capture.getRGB(5, 5);
    if (pixel != 0xffffffff) {
        throw new RuntimeException("Failed: Incorrect color for " +
                                   "background");
    }

    // Test pixels
    testRegion(capture, new Rectangle(10, 10, 40, 40));
    testRegion(capture, new Rectangle(80, 10, 40, 40));
    testRegion(capture, new Rectangle(150, 10, 40, 40));
}
 
Example 17
Source File: Img.java    From gcs with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * @param gc           The {@link GraphicsConfiguration} to make the image compatible with.
 * @param width        The width to create.
 * @param height       The height to create.
 * @param transparency A constant from {@link Transparency}.
 * @return A new {@link Img} of the given size.
 */
public static Img create(GraphicsConfiguration gc, int width, int height, int transparency) {
    return new Img(gc.getColorModel(transparency), width, height);
}