001: /*
002: * $RCSfile: RookIterFactory.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:27 $
010: * $State: Exp $
011: */
012: package javax.media.jai.iterator;
013:
014: import java.awt.Rectangle;
015: import java.awt.image.ComponentSampleModel;
016: import java.awt.image.DataBuffer;
017: import java.awt.image.Raster;
018: import java.awt.image.WritableRaster;
019: import java.awt.image.RenderedImage;
020: import java.awt.image.SampleModel;
021: import java.awt.image.WritableRenderedImage; // import com.sun.media.jai.iterator.RookIterCSMByte;
022: // import com.sun.media.jai.iterator.RookIterCSMShort;
023: // import com.sun.media.jai.iterator.RookIterCSMUShort;
024: // import com.sun.media.jai.iterator.RookIterCSMInt;
025: // import com.sun.media.jai.iterator.RookIterCSMFloat;
026: // import com.sun.media.jai.iterator.RookIterCSMDouble;
027: import com.sun.media.jai.iterator.RookIterFallback;
028: import com.sun.media.jai.iterator.WrapperRI;
029: import com.sun.media.jai.iterator.WrapperWRI; // import com.sun.media.jai.iterator.WritableRookIterCSMByte;
030: // import com.sun.media.jai.iterator.WritableRookIterCSMShort;
031: // import com.sun.media.jai.iterator.WritableRookIterCSMUShort;
032: // import com.sun.media.jai.iterator.WritableRookIterCSMInt;
033: // import com.sun.media.jai.iterator.WritableRookIterCSMFloat;
034: // import com.sun.media.jai.iterator.WritableRookIterCSMDouble;
035: import com.sun.media.jai.iterator.WritableRookIterFallback;
036:
037: /**
038: * A factory class to instantiate instances of the RookIter and
039: * WritableRookIter interfaces on sources of type Raster,
040: * RenderedImage, and WritableRenderedImage.
041: *
042: * @see RookIter
043: * @see WritableRookIter
044: */
045: public class RookIterFactory {
046:
047: /** Prevent this class from ever being instantiated. */
048: private RookIterFactory() {
049: }
050:
051: /**
052: * Constructs and returns an instance of RookIter suitable
053: * for iterating over the given bounding rectangle within the
054: * given RenderedImage source. If the bounds parameter is null,
055: * the entire image will be used.
056: *
057: * @param im a read-only RenderedImage source.
058: * @param bounds the bounding Rectangle for the iterator, or null.
059: * @return a RookIter allowing read-only access to the source.
060: */
061: public static RookIter create(RenderedImage im, Rectangle bounds) {
062: if (bounds == null) {
063: bounds = new Rectangle(im.getMinX(), im.getMinY(), im
064: .getWidth(), im.getHeight());
065: }
066:
067: SampleModel sm = im.getSampleModel();
068: if (sm instanceof ComponentSampleModel) {
069: switch (sm.getDataType()) {
070: case DataBuffer.TYPE_BYTE:
071: // return new RookIterCSMByte(im, bounds);
072: case DataBuffer.TYPE_SHORT:
073: // return new RookIterCSMShort(im, bounds);
074: case DataBuffer.TYPE_USHORT:
075: // return new RookIterCSMUShort(im, bounds);
076: case DataBuffer.TYPE_INT:
077: // return new RookIterCSMInt(im, bounds);
078: case DataBuffer.TYPE_FLOAT:
079: // return new RookIterCSMFloat(im, bounds);
080: case DataBuffer.TYPE_DOUBLE:
081: // return new RookIterCSMDouble(im, bounds);
082: }
083: }
084:
085: return new RookIterFallback(im, bounds);
086: }
087:
088: /**
089: * Constructs and returns an instance of RookIter suitable
090: * for iterating over the given bounding rectangle within the
091: * given Raster source. If the bounds parameter is null,
092: * the entire Raster will be used.
093: *
094: * @param ras a read-only Raster source.
095: * @param bounds the bounding Rectangle for the iterator, or null.
096: * @return a RookIter allowing read-only access to the source.
097: */
098: public static RookIter create(Raster ras, Rectangle bounds) {
099: RenderedImage im = new WrapperRI(ras);
100: return create(im, bounds);
101: }
102:
103: /**
104: * Constructs and returns an instance of WritableRookIter suitable for
105: * iterating over the given bounding rectangle within the given
106: * WritableRenderedImage source. If the bounds parameter is null,
107: * the entire image will be used.
108: *
109: * @param im a WritableRenderedImage source.
110: * @param bounds the bounding Rectangle for the iterator, or null.
111: * @return a WritableRookIter allowing read/write access to the source.
112: */
113: public static WritableRookIter createWritable(
114: WritableRenderedImage im, Rectangle bounds) {
115: if (bounds == null) {
116: bounds = new Rectangle(im.getMinX(), im.getMinY(), im
117: .getWidth(), im.getHeight());
118: }
119:
120: SampleModel sm = im.getSampleModel();
121: if (sm instanceof ComponentSampleModel) {
122: switch (sm.getDataType()) {
123: case DataBuffer.TYPE_BYTE:
124: // return new WritableRookIterCSMByte(im, bounds);
125: case DataBuffer.TYPE_SHORT:
126: // return new WritableRookIterCSMShort(im, bounds);
127: case DataBuffer.TYPE_USHORT:
128: // return new WritableRookIterCSMUShort(im, bounds);
129: case DataBuffer.TYPE_INT:
130: // return new WritableRookIterCSMInt(im, bounds);
131: case DataBuffer.TYPE_FLOAT:
132: // return new WritableRookIterCSMFloat(im, bounds);
133: case DataBuffer.TYPE_DOUBLE:
134: // return new WritableRookIterCSMDouble(im, bounds);
135: }
136: }
137:
138: return new WritableRookIterFallback(im, bounds);
139: }
140:
141: /**
142: * Constructs and returns an instance of WritableRookIter suitable for
143: * iterating over the given bounding rectangle within the given
144: * WritableRaster source. If the bounds parameter is null,
145: * the entire Raster will be used.
146: *
147: * @param ras a WritableRaster source.
148: * @param bounds the bounding Rectangle for the iterator, or null.
149: * @return a WritableRookIter allowing read/write access to the source.
150: */
151: public static WritableRookIter createWritable(WritableRaster ras,
152: Rectangle bounds) {
153: WritableRenderedImage im = new WrapperWRI(ras);
154: return createWritable(im, bounds);
155: }
156: }
|