01: /*
02: * $RCSfile: RampOpImage.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.2 $
09: * $Date: 2005/02/24 02:07:44 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.test;
13:
14: import java.awt.Point;
15: import java.awt.Rectangle;
16: import java.awt.image.Raster;
17: import java.awt.image.SampleModel;
18: import java.awt.image.WritableRaster;
19: import java.util.Map;
20: import javax.media.jai.ImageLayout;
21: import javax.media.jai.RasterFactory;
22: import javax.media.jai.SourcelessOpImage;
23:
24: /** Defines a ramp image for testing purpose. */
25: final class RampOpImage extends SourcelessOpImage {
26:
27: public RampOpImage(int minX, int minY, int width, int height,
28: SampleModel sampleModel, Map configuration,
29: ImageLayout layout) {
30: super (layout, configuration, sampleModel, minX, minY, width,
31: height);
32: }
33:
34: public Raster computeTile(int tileX, int tileY) {
35: int orgX = tileXToX(tileX);
36: int orgY = tileYToY(tileY);
37:
38: WritableRaster dst = RasterFactory.createWritableRaster(
39: sampleModel, new Point(orgX, orgY));
40:
41: Rectangle rect = new Rectangle(orgX, orgY, sampleModel
42: .getWidth(), sampleModel.getHeight());
43: rect = rect.intersection(getBounds());
44:
45: int numBands = sampleModel.getNumBands();
46: int p[] = new int[numBands];
47:
48: for (int y = rect.y; y < (rect.y + rect.height); y++) {
49: for (int x = rect.x; x < (rect.x + rect.width); x++) {
50: int value = Math.max(x & 0xFF, y & 0xFF);
51: for (int i = 0; i < numBands; i++) {
52: p[i] = value;
53: }
54: dst.setPixel(x, y, p);
55: }
56: }
57: return dst;
58: }
59: }
|