src/demo/share/java2d/J2DBench/src/j2dbench/tests/ImageTests.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
@@ -51,10 +51,11 @@
import java.awt.Image;
import java.awt.Canvas;
import java.awt.AlphaComposite;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
+import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ByteLookupTable;
import java.awt.image.ConvolveOp;
import java.awt.image.DataBuffer;
@@ -75,10 +76,11 @@
import java.util.ArrayList;
import javax.swing.JComponent;
public abstract class ImageTests extends GraphicsTests {
public static boolean hasVolatileImage;
+ public static boolean hasTransparentVolatileImage;
public static boolean hasCompatImage;
static {
try {
hasVolatileImage = (VolatileImage.class != null);
@@ -87,27 +89,34 @@
try {
new Canvas().getGraphicsConfiguration();
hasCompatImage = true;
} catch (NoSuchMethodError e) {
}
+ try {
+ new Canvas().getMousePosition();
+ hasTransparentVolatileImage = true;
+ } catch (NoSuchMethodError e) {
+ }
}
static Group imageroot;
static Group.EnableSet imgsrcroot;
static Group.EnableSet bufimgsrcroot;
+ static Group imgbenchroot;
static Group imgtestroot;
- static Group imgoptionsroot;
+ static Group imgtestOptRoot;
static Group imageOpRoot;
static Group imageOpOptRoot;
static Group imageOpTestRoot;
static Group graphicsTestRoot;
static Group bufImgOpTestRoot;
static Group rasterOpTestRoot;
static Option opList;
static Option doTouchSrc;
+ static Option interpolation;
static String transNodeNames[] = {
null, "opaque", "bitmask", "translucent",
};
@@ -120,47 +129,46 @@
"Imaging Benchmarks");
imageroot.setTabbed();
imgsrcroot = new Group.EnableSet(imageroot, "src",
"Image Rendering Sources");
- imgsrcroot.setBordered(true);
-
- imgoptionsroot = new Group(imgsrcroot, "options",
- "Image Source Options");
- imgoptionsroot.setBordered(true);
- doTouchSrc =
- new Option.Toggle(imgoptionsroot, "touchsrc",
- "Touch src image before every operation",
- Option.Toggle.Off);
-
- imgtestroot = new Group(imageroot, "tests",
- "Image Rendering Tests");
- imgtestroot.setBordered(true);
+ imgbenchroot = new Group(imageroot, "benchmarks",
+ "Image Rendering Benchmarks");
+ imgtestOptRoot = new Group(imgbenchroot, "opts", "Options");
new OffScreen();
if (hasGraphics2D) {
if (hasCompatImage) {
new CompatImg(Transparency.OPAQUE);
new CompatImg(Transparency.BITMASK);
new CompatImg(Transparency.TRANSLUCENT);
}
-
if (hasVolatileImage) {
+ if (hasTransparentVolatileImage) {
+ new VolatileImg(Transparency.OPAQUE);
+ new VolatileImg(Transparency.BITMASK);
+ new VolatileImg(Transparency.TRANSLUCENT);
+ } else {
new VolatileImg();
}
+ }
bufimgsrcroot =
new Group.EnableSet(imgsrcroot, "bufimg",
"BufferedImage Rendering Sources");
new BufImg(BufferedImage.TYPE_INT_RGB);
new BufImg(BufferedImage.TYPE_INT_ARGB);
+ new BufImg(BufferedImage.TYPE_INT_ARGB_PRE);
new BufImg(BufferedImage.TYPE_BYTE_GRAY);
new BufImg(BufferedImage.TYPE_3BYTE_BGR);
+ new BufImg(BufferedImage.TYPE_4BYTE_ABGR);
+ new BufImg(BufferedImage.TYPE_4BYTE_ABGR_PRE);
new BmByteIndexBufImg();
new BufImg(BufferedImage.TYPE_INT_RGB, true);
new BufImg(BufferedImage.TYPE_INT_ARGB, true);
+ new BufImg(BufferedImage.TYPE_INT_ARGB_PRE, true);
new BufImg(BufferedImage.TYPE_3BYTE_BGR, true);
imageOpRoot = new Group(imageroot, "imageops",
"Image Op Benchmarks");
imageOpOptRoot = new Group(imageOpRoot, "opts", "Options");
@@ -209,16 +217,35 @@
new DrawImageOp();
new BufImgOpFilter(false);
new BufImgOpFilter(true);
new RasterOpFilter(false);
new RasterOpFilter(true);
+
+ String interpolationnames[] = {"Nearest neighbor", "Bilinear",
+ "Bicubic",};
+ interpolation =
+ new ObjectList(imgtestOptRoot, "interpolation",
+ "Interpolation",
+ interpolationnames, new Object[] {
+ RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,
+ RenderingHints.VALUE_INTERPOLATION_BILINEAR,
+ RenderingHints.VALUE_INTERPOLATION_BICUBIC,
+ }, interpolationnames, interpolationnames, 1);
}
+ doTouchSrc =
+ new Option.Toggle(imgtestOptRoot, "touchsrc",
+ "Touch source image before every operation",
+ Option.Toggle.Off);
+
+ imgtestroot = new Group(imgbenchroot, "tests", "Image Rendering Tests");
+
new DrawImage();
new DrawImageBg();
new DrawImageScale("up", 1.5f);
new DrawImageScale("down", .75f);
+ new DrawImageScale("split", .5f);
new DrawImageTransform();
}
public static class Context extends GraphicsTests.Context {
boolean touchSrc;
@@ -234,10 +261,11 @@
Modifier.Filter srcFilter)
{
super(parent, nodeName, description);
addDependency(imgsrcroot, srcFilter);
addDependency(doTouchSrc);
+ addDependency(interpolation);
}
public GraphicsTests.Context createContext() {
return new ImageTests.Context();
}
@@ -246,10 +274,15 @@
super.initContext(env, ctx);
ImageTests.Context ictx = (ImageTests.Context) ctx;
ictx.src = env.getSrcImage();
ictx.touchSrc = env.isEnabled(doTouchSrc);
+ if (hasGraphics2D) {
+ Graphics2D g2d = (Graphics2D) ctx.graphics;
+ final Object modifier = env.getModifier(interpolation);
+ g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, modifier);
+ }
}
public abstract static class TriStateImageType extends Group {
Image theImage;
@@ -288,17 +321,31 @@
return c.createImage(w, h);
}
}
public static class VolatileImg extends TriStateImageType {
+ private final int transparency;
+
public VolatileImg() {
- super(imgsrcroot, "volimg", "Volatile Image", Transparency.OPAQUE);
+ this(0);
+ }
+
+ public VolatileImg(int transparency) {
+ super(imgsrcroot, Destinations.VolatileImg.ShortNames[transparency],
+ Destinations.VolatileImg.LongDescriptions[transparency],
+ transparency);
+ this.transparency = transparency;
}
public Image makeImage(TestEnvironment env, int w, int h) {
Canvas c = env.getCanvas();
- return c.createVolatileImage(w, h);
+ GraphicsConfiguration gc = c.getGraphicsConfiguration();
+ if (transparency == 0) {
+ return gc.createCompatibleVolatileImage(w, h);
+ } else {
+ return gc.createCompatibleVolatileImage(w, h, transparency);
+ }
}
}
public static class CompatImg extends TriStateImageType {
int transparency;