1 /*
2 * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Oracle nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
36 * input validation and proper error handling, might not be present in
37 * this sample code.
38 */
39
40
41 package j2dbench.tests;
42
43 import j2dbench.Destinations;
44 import j2dbench.Group;
45 import j2dbench.Modifier;
46 import j2dbench.Option;
47 import j2dbench.TestEnvironment;
48 import java.awt.Graphics;
49 import java.awt.Graphics2D;
50 import java.awt.Color;
51 import java.awt.Image;
52 import java.awt.Canvas;
53 import java.awt.AlphaComposite;
54 import java.awt.Dimension;
55 import java.awt.GraphicsConfiguration;
56 import java.awt.image.BufferedImage;
57 import java.awt.image.BufferedImageOp;
58 import java.awt.image.ByteLookupTable;
59 import java.awt.image.ConvolveOp;
60 import java.awt.image.DataBuffer;
61 import java.awt.image.IndexColorModel;
62 import java.awt.image.Kernel;
63 import java.awt.image.LookupOp;
64 import java.awt.image.Raster;
65 import java.awt.image.RasterOp;
66 import java.awt.image.RescaleOp;
67 import java.awt.image.ShortLookupTable;
68 import java.awt.image.VolatileImage;
69 import java.awt.image.WritableRaster;
70 import java.awt.Transparency;
71 import java.awt.geom.AffineTransform;
72 import java.awt.image.DataBufferByte;
73 import java.awt.image.DataBufferInt;
74 import java.awt.image.DataBufferShort;
75 import java.util.ArrayList;
76 import javax.swing.JComponent;
77
78 public abstract class ImageTests extends GraphicsTests {
79 public static boolean hasVolatileImage;
80 public static boolean hasCompatImage;
81
82 static {
83 try {
84 hasVolatileImage = (VolatileImage.class != null);
85 } catch (NoClassDefFoundError e) {
86 }
87 try {
88 new Canvas().getGraphicsConfiguration();
89 hasCompatImage = true;
90 } catch (NoSuchMethodError e) {
91 }
92 }
93
94 static Group imageroot;
95 static Group.EnableSet imgsrcroot;
96 static Group.EnableSet bufimgsrcroot;
97
98 static Group imgtestroot;
99 static Group imgoptionsroot;
100
101 static Group imageOpRoot;
102 static Group imageOpOptRoot;
103 static Group imageOpTestRoot;
104 static Group graphicsTestRoot;
105 static Group bufImgOpTestRoot;
106 static Group rasterOpTestRoot;
107 static Option opList;
108 static Option doTouchSrc;
109
110 static String transNodeNames[] = {
111 null, "opaque", "bitmask", "translucent",
112 };
113
114 static String transDescriptions[] = {
115 null, "Opaque", "Bitmask", "Translucent",
116 };
117
118 public static void init() {
119 imageroot = new Group(graphicsroot, "imaging",
120 "Imaging Benchmarks");
121 imageroot.setTabbed();
122
123 imgsrcroot = new Group.EnableSet(imageroot, "src",
124 "Image Rendering Sources");
125 imgsrcroot.setBordered(true);
126
127 imgoptionsroot = new Group(imgsrcroot, "options",
128 "Image Source Options");
129 imgoptionsroot.setBordered(true);
130 doTouchSrc =
131 new Option.Toggle(imgoptionsroot, "touchsrc",
132 "Touch src image before every operation",
133 Option.Toggle.Off);
134
135 imgtestroot = new Group(imageroot, "tests",
136 "Image Rendering Tests");
137 imgtestroot.setBordered(true);
138
139 new OffScreen();
140
141 if (hasGraphics2D) {
142 if (hasCompatImage) {
143 new CompatImg(Transparency.OPAQUE);
144 new CompatImg(Transparency.BITMASK);
145 new CompatImg(Transparency.TRANSLUCENT);
146 }
147
148 if (hasVolatileImage) {
149 new VolatileImg();
150 }
151
152 bufimgsrcroot =
153 new Group.EnableSet(imgsrcroot, "bufimg",
154 "BufferedImage Rendering Sources");
155 new BufImg(BufferedImage.TYPE_INT_RGB);
156 new BufImg(BufferedImage.TYPE_INT_ARGB);
157 new BufImg(BufferedImage.TYPE_BYTE_GRAY);
158 new BufImg(BufferedImage.TYPE_3BYTE_BGR);
159 new BmByteIndexBufImg();
160 new BufImg(BufferedImage.TYPE_INT_RGB, true);
161 new BufImg(BufferedImage.TYPE_INT_ARGB, true);
162 new BufImg(BufferedImage.TYPE_3BYTE_BGR, true);
163
164 imageOpRoot = new Group(imageroot, "imageops",
165 "Image Op Benchmarks");
166 imageOpOptRoot = new Group(imageOpRoot, "opts", "Options");
167 imageOpTestRoot = new Group(imageOpRoot, "tests", "Tests");
168 graphicsTestRoot = new Group(imageOpTestRoot, "graphics2d",
169 "Graphics2D Tests");
170 bufImgOpTestRoot = new Group(imageOpTestRoot, "bufimgop",
171 "BufferedImageOp Tests");
172 rasterOpTestRoot = new Group(imageOpTestRoot, "rasterop",
173 "RasterOp Tests");
174
175 ArrayList opStrs = new ArrayList();
176 ArrayList opDescs = new ArrayList();
177 opStrs.add("convolve3x3zero");
178 opDescs.add("ConvolveOp (3x3 blur, zero)");
179 opStrs.add("convolve3x3noop");
180 opDescs.add("ConvolveOp (3x3 blur, noop)");
181 opStrs.add("convolve5x5zero");
194 opDescs.add("RescaleOp (1 band)");
195 opStrs.add("rescale3band");
196 opDescs.add("RescaleOp (3 band)");
197 String[] opStrArr = new String[opStrs.size()];
198 opStrArr = (String[])opStrs.toArray(opStrArr);
199 String[] opDescArr = new String[opDescs.size()];
200 opDescArr = (String[])opDescs.toArray(opDescArr);
201 opList =
202 new Option.ObjectList(imageOpOptRoot,
203 "op", "Operation",
204 opStrArr, opStrArr,
205 opStrArr, opDescArr,
206 0x1);
207 ((Option.ObjectList) opList).setNumRows(4);
208
209 new DrawImageOp();
210 new BufImgOpFilter(false);
211 new BufImgOpFilter(true);
212 new RasterOpFilter(false);
213 new RasterOpFilter(true);
214 }
215
216 new DrawImage();
217 new DrawImageBg();
218 new DrawImageScale("up", 1.5f);
219 new DrawImageScale("down", .75f);
220 new DrawImageTransform();
221 }
222
223 public static class Context extends GraphicsTests.Context {
224 boolean touchSrc;
225 Image src;
226 AffineTransform tx;
227 }
228
229 public ImageTests(Group parent, String nodeName, String description) {
230 this(parent, nodeName, description, null);
231 }
232
233 public ImageTests(Group parent, String nodeName, String description,
234 Modifier.Filter srcFilter)
235 {
236 super(parent, nodeName, description);
237 addDependency(imgsrcroot, srcFilter);
238 addDependency(doTouchSrc);
239 }
240
241 public GraphicsTests.Context createContext() {
242 return new ImageTests.Context();
243 }
244
245 public void initContext(TestEnvironment env, GraphicsTests.Context ctx) {
246 super.initContext(env, ctx);
247 ImageTests.Context ictx = (ImageTests.Context) ctx;
248
249 ictx.src = env.getSrcImage();
250 ictx.touchSrc = env.isEnabled(doTouchSrc);
251 }
252
253 public abstract static class TriStateImageType extends Group {
254 Image theImage;
255
256 public TriStateImageType(Group parent, String nodename, String desc,
257 int transparency)
258 {
259 super(parent, nodename, desc);
260 setHorizontal();
261 new DrawableImage(this, Transparency.OPAQUE, true);
262 new DrawableImage(this, Transparency.BITMASK,
263 (transparency != Transparency.OPAQUE));
264 new DrawableImage(this, Transparency.TRANSLUCENT,
265 (transparency == Transparency.TRANSLUCENT));
266 }
267
268 public Image getImage(TestEnvironment env, int w, int h) {
269 if (theImage == null ||
270 theImage.getWidth(null) != w ||
273 theImage = makeImage(env, w, h);
274 }
275 return theImage;
276 }
277
278 public abstract Image makeImage(TestEnvironment env, int w, int h);
279 }
280
281 public static class OffScreen extends TriStateImageType {
282 public OffScreen() {
283 super(imgsrcroot, "offscr", "Offscreen Image", Transparency.OPAQUE);
284 }
285
286 public Image makeImage(TestEnvironment env, int w, int h) {
287 Canvas c = env.getCanvas();
288 return c.createImage(w, h);
289 }
290 }
291
292 public static class VolatileImg extends TriStateImageType {
293 public VolatileImg() {
294 super(imgsrcroot, "volimg", "Volatile Image", Transparency.OPAQUE);
295 }
296
297 public Image makeImage(TestEnvironment env, int w, int h) {
298 Canvas c = env.getCanvas();
299 return c.createVolatileImage(w, h);
300 }
301 }
302
303 public static class CompatImg extends TriStateImageType {
304 int transparency;
305
306 public CompatImg(int transparency) {
307 super(imgsrcroot,
308 Destinations.CompatImg.ShortNames[transparency],
309 Destinations.CompatImg.LongDescriptions[transparency],
310 transparency);
311 this.transparency = transparency;
312 }
313
314 public Image makeImage(TestEnvironment env, int w, int h) {
315 Canvas c = env.getCanvas();
316 GraphicsConfiguration gc = c.getGraphicsConfiguration();
317 return gc.createCompatibleImage(w, h, transparency);
318 }
319 }
|
1 /*
2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * - Neither the name of Oracle nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
36 * input validation and proper error handling, might not be present in
37 * this sample code.
38 */
39
40
41 package j2dbench.tests;
42
43 import j2dbench.Destinations;
44 import j2dbench.Group;
45 import j2dbench.Modifier;
46 import j2dbench.Option;
47 import j2dbench.TestEnvironment;
48 import java.awt.Graphics;
49 import java.awt.Graphics2D;
50 import java.awt.Color;
51 import java.awt.Image;
52 import java.awt.Canvas;
53 import java.awt.AlphaComposite;
54 import java.awt.Dimension;
55 import java.awt.GraphicsConfiguration;
56 import java.awt.RenderingHints;
57 import java.awt.image.BufferedImage;
58 import java.awt.image.BufferedImageOp;
59 import java.awt.image.ByteLookupTable;
60 import java.awt.image.ConvolveOp;
61 import java.awt.image.DataBuffer;
62 import java.awt.image.IndexColorModel;
63 import java.awt.image.Kernel;
64 import java.awt.image.LookupOp;
65 import java.awt.image.Raster;
66 import java.awt.image.RasterOp;
67 import java.awt.image.RescaleOp;
68 import java.awt.image.ShortLookupTable;
69 import java.awt.image.VolatileImage;
70 import java.awt.image.WritableRaster;
71 import java.awt.Transparency;
72 import java.awt.geom.AffineTransform;
73 import java.awt.image.DataBufferByte;
74 import java.awt.image.DataBufferInt;
75 import java.awt.image.DataBufferShort;
76 import java.util.ArrayList;
77 import javax.swing.JComponent;
78
79 public abstract class ImageTests extends GraphicsTests {
80 public static boolean hasVolatileImage;
81 public static boolean hasTransparentVolatileImage;
82 public static boolean hasCompatImage;
83
84 static {
85 try {
86 hasVolatileImage = (VolatileImage.class != null);
87 } catch (NoClassDefFoundError e) {
88 }
89 try {
90 new Canvas().getGraphicsConfiguration();
91 hasCompatImage = true;
92 } catch (NoSuchMethodError e) {
93 }
94 try {
95 new Canvas().getMousePosition();
96 hasTransparentVolatileImage = true;
97 } catch (NoSuchMethodError e) {
98 }
99 }
100
101 static Group imageroot;
102 static Group.EnableSet imgsrcroot;
103 static Group.EnableSet bufimgsrcroot;
104
105 static Group imgbenchroot;
106 static Group imgtestroot;
107 static Group imgtestOptRoot;
108
109 static Group imageOpRoot;
110 static Group imageOpOptRoot;
111 static Group imageOpTestRoot;
112 static Group graphicsTestRoot;
113 static Group bufImgOpTestRoot;
114 static Group rasterOpTestRoot;
115 static Option opList;
116 static Option doTouchSrc;
117 static Option interpolation;
118
119 static String transNodeNames[] = {
120 null, "opaque", "bitmask", "translucent",
121 };
122
123 static String transDescriptions[] = {
124 null, "Opaque", "Bitmask", "Translucent",
125 };
126
127 public static void init() {
128 imageroot = new Group(graphicsroot, "imaging",
129 "Imaging Benchmarks");
130 imageroot.setTabbed();
131
132 imgsrcroot = new Group.EnableSet(imageroot, "src",
133 "Image Rendering Sources");
134 imgbenchroot = new Group(imageroot, "benchmarks",
135 "Image Rendering Benchmarks");
136 imgtestOptRoot = new Group(imgbenchroot, "opts", "Options");
137
138 new OffScreen();
139
140 if (hasGraphics2D) {
141 if (hasCompatImage) {
142 new CompatImg(Transparency.OPAQUE);
143 new CompatImg(Transparency.BITMASK);
144 new CompatImg(Transparency.TRANSLUCENT);
145 }
146 if (hasVolatileImage) {
147 if (hasTransparentVolatileImage) {
148 new VolatileImg(Transparency.OPAQUE);
149 new VolatileImg(Transparency.BITMASK);
150 new VolatileImg(Transparency.TRANSLUCENT);
151 } else {
152 new VolatileImg();
153 }
154 }
155
156 bufimgsrcroot =
157 new Group.EnableSet(imgsrcroot, "bufimg",
158 "BufferedImage Rendering Sources");
159 new BufImg(BufferedImage.TYPE_INT_RGB);
160 new BufImg(BufferedImage.TYPE_INT_ARGB);
161 new BufImg(BufferedImage.TYPE_INT_ARGB_PRE);
162 new BufImg(BufferedImage.TYPE_BYTE_GRAY);
163 new BufImg(BufferedImage.TYPE_3BYTE_BGR);
164 new BufImg(BufferedImage.TYPE_4BYTE_ABGR);
165 new BufImg(BufferedImage.TYPE_4BYTE_ABGR_PRE);
166 new BmByteIndexBufImg();
167 new BufImg(BufferedImage.TYPE_INT_RGB, true);
168 new BufImg(BufferedImage.TYPE_INT_ARGB, true);
169 new BufImg(BufferedImage.TYPE_INT_ARGB_PRE, true);
170 new BufImg(BufferedImage.TYPE_3BYTE_BGR, true);
171
172 imageOpRoot = new Group(imageroot, "imageops",
173 "Image Op Benchmarks");
174 imageOpOptRoot = new Group(imageOpRoot, "opts", "Options");
175 imageOpTestRoot = new Group(imageOpRoot, "tests", "Tests");
176 graphicsTestRoot = new Group(imageOpTestRoot, "graphics2d",
177 "Graphics2D Tests");
178 bufImgOpTestRoot = new Group(imageOpTestRoot, "bufimgop",
179 "BufferedImageOp Tests");
180 rasterOpTestRoot = new Group(imageOpTestRoot, "rasterop",
181 "RasterOp Tests");
182
183 ArrayList opStrs = new ArrayList();
184 ArrayList opDescs = new ArrayList();
185 opStrs.add("convolve3x3zero");
186 opDescs.add("ConvolveOp (3x3 blur, zero)");
187 opStrs.add("convolve3x3noop");
188 opDescs.add("ConvolveOp (3x3 blur, noop)");
189 opStrs.add("convolve5x5zero");
202 opDescs.add("RescaleOp (1 band)");
203 opStrs.add("rescale3band");
204 opDescs.add("RescaleOp (3 band)");
205 String[] opStrArr = new String[opStrs.size()];
206 opStrArr = (String[])opStrs.toArray(opStrArr);
207 String[] opDescArr = new String[opDescs.size()];
208 opDescArr = (String[])opDescs.toArray(opDescArr);
209 opList =
210 new Option.ObjectList(imageOpOptRoot,
211 "op", "Operation",
212 opStrArr, opStrArr,
213 opStrArr, opDescArr,
214 0x1);
215 ((Option.ObjectList) opList).setNumRows(4);
216
217 new DrawImageOp();
218 new BufImgOpFilter(false);
219 new BufImgOpFilter(true);
220 new RasterOpFilter(false);
221 new RasterOpFilter(true);
222
223 String interpolationnames[] = {"Nearest neighbor", "Bilinear",
224 "Bicubic",};
225 interpolation =
226 new ObjectList(imgtestOptRoot, "interpolation",
227 "Interpolation",
228 interpolationnames, new Object[] {
229 RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,
230 RenderingHints.VALUE_INTERPOLATION_BILINEAR,
231 RenderingHints.VALUE_INTERPOLATION_BICUBIC,
232 }, interpolationnames, interpolationnames, 1);
233 }
234
235 doTouchSrc =
236 new Option.Toggle(imgtestOptRoot, "touchsrc",
237 "Touch source image before every operation",
238 Option.Toggle.Off);
239
240 imgtestroot = new Group(imgbenchroot, "tests", "Image Rendering Tests");
241
242 new DrawImage();
243 new DrawImageBg();
244 new DrawImageScale("up", 1.5f);
245 new DrawImageScale("down", .75f);
246 new DrawImageScale("split", .5f);
247 new DrawImageTransform();
248 }
249
250 public static class Context extends GraphicsTests.Context {
251 boolean touchSrc;
252 Image src;
253 AffineTransform tx;
254 }
255
256 public ImageTests(Group parent, String nodeName, String description) {
257 this(parent, nodeName, description, null);
258 }
259
260 public ImageTests(Group parent, String nodeName, String description,
261 Modifier.Filter srcFilter)
262 {
263 super(parent, nodeName, description);
264 addDependency(imgsrcroot, srcFilter);
265 addDependency(doTouchSrc);
266 addDependency(interpolation);
267 }
268
269 public GraphicsTests.Context createContext() {
270 return new ImageTests.Context();
271 }
272
273 public void initContext(TestEnvironment env, GraphicsTests.Context ctx) {
274 super.initContext(env, ctx);
275 ImageTests.Context ictx = (ImageTests.Context) ctx;
276
277 ictx.src = env.getSrcImage();
278 ictx.touchSrc = env.isEnabled(doTouchSrc);
279 if (hasGraphics2D) {
280 Graphics2D g2d = (Graphics2D) ctx.graphics;
281 final Object modifier = env.getModifier(interpolation);
282 g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, modifier);
283 }
284 }
285
286 public abstract static class TriStateImageType extends Group {
287 Image theImage;
288
289 public TriStateImageType(Group parent, String nodename, String desc,
290 int transparency)
291 {
292 super(parent, nodename, desc);
293 setHorizontal();
294 new DrawableImage(this, Transparency.OPAQUE, true);
295 new DrawableImage(this, Transparency.BITMASK,
296 (transparency != Transparency.OPAQUE));
297 new DrawableImage(this, Transparency.TRANSLUCENT,
298 (transparency == Transparency.TRANSLUCENT));
299 }
300
301 public Image getImage(TestEnvironment env, int w, int h) {
302 if (theImage == null ||
303 theImage.getWidth(null) != w ||
306 theImage = makeImage(env, w, h);
307 }
308 return theImage;
309 }
310
311 public abstract Image makeImage(TestEnvironment env, int w, int h);
312 }
313
314 public static class OffScreen extends TriStateImageType {
315 public OffScreen() {
316 super(imgsrcroot, "offscr", "Offscreen Image", Transparency.OPAQUE);
317 }
318
319 public Image makeImage(TestEnvironment env, int w, int h) {
320 Canvas c = env.getCanvas();
321 return c.createImage(w, h);
322 }
323 }
324
325 public static class VolatileImg extends TriStateImageType {
326 private final int transparency;
327
328 public VolatileImg() {
329 this(0);
330 }
331
332 public VolatileImg(int transparency) {
333 super(imgsrcroot, Destinations.VolatileImg.ShortNames[transparency],
334 Destinations.VolatileImg.LongDescriptions[transparency],
335 transparency);
336 this.transparency = transparency;
337 }
338
339 public Image makeImage(TestEnvironment env, int w, int h) {
340 Canvas c = env.getCanvas();
341 GraphicsConfiguration gc = c.getGraphicsConfiguration();
342 if (transparency == 0) {
343 return gc.createCompatibleVolatileImage(w, h);
344 } else {
345 return gc.createCompatibleVolatileImage(w, h, transparency);
346 }
347 }
348 }
349
350 public static class CompatImg extends TriStateImageType {
351 int transparency;
352
353 public CompatImg(int transparency) {
354 super(imgsrcroot,
355 Destinations.CompatImg.ShortNames[transparency],
356 Destinations.CompatImg.LongDescriptions[transparency],
357 transparency);
358 this.transparency = transparency;
359 }
360
361 public Image makeImage(TestEnvironment env, int w, int h) {
362 Canvas c = env.getCanvas();
363 GraphicsConfiguration gc = c.getGraphicsConfiguration();
364 return gc.createCompatibleImage(w, h, transparency);
365 }
366 }
|