01: /*
02: * $RCSfile: PatternOpImage.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.1 $
09: * $Date: 2005/02/11 04:56:39 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.opimage;
13:
14: import java.awt.Rectangle;
15: import java.awt.image.ColorModel;
16: import java.awt.image.Raster;
17: import java.awt.image.RenderedImage;
18: import java.awt.Point;
19: import java.awt.image.SampleModel;
20: import java.awt.image.WritableRaster;
21: import javax.media.jai.ImageLayout;
22: import javax.media.jai.SourcelessOpImage;
23: import javax.media.jai.RasterFactory;
24:
25: /**
26: * An OpImage class to generate a repeating pattern of pixels.
27: *
28: * <p> PatternOpImage defines an image consisting of a repeated
29: * pattern. The pattern is stored internally as a Raster, and
30: * translated versions of the master tile (sharing the same
31: * DataBuffer) are returned by computeTile().
32: *
33: */
34: // public since ../test/OpImageTester.java uses it
35: public class PatternOpImage extends SourcelessOpImage {
36:
37: /** The master tile (0, 0) containing the pattern. */
38: protected Raster pattern;
39:
40: /** Set up image layout. */
41: private static ImageLayout layoutHelper(Raster pattern,
42: ColorModel colorModel) {
43: return new ImageLayout(pattern.getMinX(), pattern.getMinY(),
44: pattern.getWidth(), pattern.getHeight(), pattern
45: .getSampleModel(), colorModel);
46: }
47:
48: /**
49: * Constructs a PatternOpImage from a Raster.
50: *
51: * @param pattern The Raster pattern to be repeated.
52: * @param colorModel The output image ColorModel.
53: * @param width The output image width.
54: * @param height The output image height.
55: */
56: public PatternOpImage(Raster pattern, ColorModel colorModel,
57: int minX, int minY, int width, int height) {
58: super (layoutHelper(pattern, colorModel), null, pattern
59: .getSampleModel(), minX, minY, width, height);
60:
61: this .pattern = pattern;
62: }
63:
64: public Raster getTile(int tileX, int tileY) {
65: return computeTile(tileX, tileY);
66: }
67:
68: /**
69: * Returns a suitably translated version of the pattern tile
70: * for reading.
71: *
72: * @param tileX the X index of the tile
73: * @param tileY the Y index of the tile
74: */
75: public Raster computeTile(int tileX, int tileY) {
76: return pattern.createChild(tileGridXOffset, tileGridYOffset,
77: tileWidth, tileHeight, tileXToX(tileX),
78: tileYToY(tileY), null);
79: }
80: }
|