228 if (nbits == 0) {
229 bimg = new BufferedImage(8, 1, type);
230 } else {
231 IndexColorModel icm =
232 new IndexColorModel(nbits, (1 << nbits),
233 cmap, 0, (nbits > 1), -1,
234 DataBuffer.TYPE_BYTE);
235 // Note that this constructor has bugs pre 1.4...
236 // bimg = new BufferedImage(64/nbits, 1, type, icm);
237 WritableRaster wr =
238 icm.createCompatibleWritableRaster(64/nbits, 1);
239 bimg = new BufferedImage(icm, wr, false, null);
240 }
241 for (int i = 0; i < bimg.getWidth(); i++) {
242 bimg.setRGB(i, 0, rgbvals[i&3]);
243 }
244 return bimg;
245 }
246 }
247
248 public static abstract class BufImgTest extends PixelTests {
249 public BufImgTest(String nodeName, String description) {
250 super(bufimgtestroot, nodeName, description);
251 }
252
253 public String getUnitName() {
254 return "pixel";
255 }
256
257 public static class GetRGB extends BufImgTest {
258 public GetRGB() {
259 super("getrgb", "BufferedImage.getRGB(x, y)");
260 }
261
262 public void runTest(Object context, int numReps) {
263 BufferedImage bimg = ((Context) context).bimg;
264 do {
265 bimg.getRGB(numReps&7, 0);
266 } while (--numReps > 0);
267 }
268 }
269
270 public static class SetRGB extends BufImgTest {
271 public SetRGB() {
272 super("setrgb", "BufferedImage.setRGB(x, y, rgb)");
273 }
274
275 public void runTest(Object context, int numReps) {
276 BufferedImage bimg = ((Context) context).bimg;
277 do {
278 bimg.setRGB(numReps&7, 0, BufImg.rgbvals[numReps&3]);
279 } while (--numReps > 0);
280 }
281 }
282 }
283
284 public static abstract class RasTest extends PixelTests {
285 public RasTest(String nodeName, String description) {
286 super(rastertestroot, nodeName, description);
287 }
288
289 public String getUnitName() {
290 return "pixel";
291 }
292
293 public Object initTest(TestEnvironment env, Result result) {
294 Context ctx = (Context) super.initTest(env, result);
295 ctx.ras = ctx.bimg.getRaster();
296 ctx.pixeldata = ctx.ras.getPixel(0, 0, (int[]) null);
297 ctx.elemdata = ctx.ras.getDataElements(0, 0, null);
298 return ctx;
299 }
300
301 public static class GetDataElements extends RasTest {
302 public GetDataElements() {
303 super("getdataelem", "Raster.getDataElements(x, y, o)");
304 }
338 ras.getPixel(numReps&7, 0, pixeldata);
339 } while (--numReps > 0);
340 }
341 }
342
343 public static class SetPixel extends RasTest {
344 public SetPixel() {
345 super("setpixel", "WritableRaster.setPixel(x, y, v[])");
346 }
347
348 public void runTest(Object context, int numReps) {
349 WritableRaster ras = ((Context) context).ras;
350 int pixeldata[] = ((Context) context).pixeldata;
351 do {
352 ras.setPixel(numReps&7, 0, pixeldata);
353 } while (--numReps > 0);
354 }
355 }
356 }
357
358 public static abstract class DataBufTest extends PixelTests {
359 public DataBufTest(String nodeName, String description) {
360 super(dbtestroot, nodeName, description);
361 }
362
363 public String getUnitName() {
364 return "element";
365 }
366
367 public Object initTest(TestEnvironment env, Result result) {
368 Context ctx = (Context) super.initTest(env, result);
369 ctx.db = ctx.bimg.getRaster().getDataBuffer();
370 return ctx;
371 }
372
373 public static class GetElem extends DataBufTest {
374 public GetElem() {
375 super("getelem", "DataBuffer.getElem(i)");
376 }
377
378 public void runTest(Object context, int numReps) {
|
228 if (nbits == 0) {
229 bimg = new BufferedImage(8, 1, type);
230 } else {
231 IndexColorModel icm =
232 new IndexColorModel(nbits, (1 << nbits),
233 cmap, 0, (nbits > 1), -1,
234 DataBuffer.TYPE_BYTE);
235 // Note that this constructor has bugs pre 1.4...
236 // bimg = new BufferedImage(64/nbits, 1, type, icm);
237 WritableRaster wr =
238 icm.createCompatibleWritableRaster(64/nbits, 1);
239 bimg = new BufferedImage(icm, wr, false, null);
240 }
241 for (int i = 0; i < bimg.getWidth(); i++) {
242 bimg.setRGB(i, 0, rgbvals[i&3]);
243 }
244 return bimg;
245 }
246 }
247
248 public abstract static class BufImgTest extends PixelTests {
249 public BufImgTest(String nodeName, String description) {
250 super(bufimgtestroot, nodeName, description);
251 }
252
253 public String getUnitName() {
254 return "pixel";
255 }
256
257 public static class GetRGB extends BufImgTest {
258 public GetRGB() {
259 super("getrgb", "BufferedImage.getRGB(x, y)");
260 }
261
262 public void runTest(Object context, int numReps) {
263 BufferedImage bimg = ((Context) context).bimg;
264 do {
265 bimg.getRGB(numReps&7, 0);
266 } while (--numReps > 0);
267 }
268 }
269
270 public static class SetRGB extends BufImgTest {
271 public SetRGB() {
272 super("setrgb", "BufferedImage.setRGB(x, y, rgb)");
273 }
274
275 public void runTest(Object context, int numReps) {
276 BufferedImage bimg = ((Context) context).bimg;
277 do {
278 bimg.setRGB(numReps&7, 0, BufImg.rgbvals[numReps&3]);
279 } while (--numReps > 0);
280 }
281 }
282 }
283
284 public abstract static class RasTest extends PixelTests {
285 public RasTest(String nodeName, String description) {
286 super(rastertestroot, nodeName, description);
287 }
288
289 public String getUnitName() {
290 return "pixel";
291 }
292
293 public Object initTest(TestEnvironment env, Result result) {
294 Context ctx = (Context) super.initTest(env, result);
295 ctx.ras = ctx.bimg.getRaster();
296 ctx.pixeldata = ctx.ras.getPixel(0, 0, (int[]) null);
297 ctx.elemdata = ctx.ras.getDataElements(0, 0, null);
298 return ctx;
299 }
300
301 public static class GetDataElements extends RasTest {
302 public GetDataElements() {
303 super("getdataelem", "Raster.getDataElements(x, y, o)");
304 }
338 ras.getPixel(numReps&7, 0, pixeldata);
339 } while (--numReps > 0);
340 }
341 }
342
343 public static class SetPixel extends RasTest {
344 public SetPixel() {
345 super("setpixel", "WritableRaster.setPixel(x, y, v[])");
346 }
347
348 public void runTest(Object context, int numReps) {
349 WritableRaster ras = ((Context) context).ras;
350 int pixeldata[] = ((Context) context).pixeldata;
351 do {
352 ras.setPixel(numReps&7, 0, pixeldata);
353 } while (--numReps > 0);
354 }
355 }
356 }
357
358 public abstract static class DataBufTest extends PixelTests {
359 public DataBufTest(String nodeName, String description) {
360 super(dbtestroot, nodeName, description);
361 }
362
363 public String getUnitName() {
364 return "element";
365 }
366
367 public Object initTest(TestEnvironment env, Result result) {
368 Context ctx = (Context) super.initTest(env, result);
369 ctx.db = ctx.bimg.getRaster().getDataBuffer();
370 return ctx;
371 }
372
373 public static class GetElem extends DataBufTest {
374 public GetElem() {
375 super("getelem", "DataBuffer.getElem(i)");
376 }
377
378 public void runTest(Object context, int numReps) {
|