001: /*
002: * $RCSfile: RandomIterFactory.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:26 $
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;
022: import com.sun.media.jai.iterator.RandomIterCSMByte;
023: import com.sun.media.jai.iterator.RandomIterCSMShort;
024: import com.sun.media.jai.iterator.RandomIterCSMUShort;
025: import com.sun.media.jai.iterator.RandomIterCSMInt;
026: import com.sun.media.jai.iterator.RandomIterCSMFloat;
027: import com.sun.media.jai.iterator.RandomIterCSMDouble;
028: import com.sun.media.jai.iterator.RandomIterFallback;
029: import com.sun.media.jai.iterator.WrapperRI;
030: import com.sun.media.jai.iterator.WrapperWRI;
031: import com.sun.media.jai.iterator.WritableRandomIterCSMByte;
032: import com.sun.media.jai.iterator.WritableRandomIterCSMShort;
033: import com.sun.media.jai.iterator.WritableRandomIterCSMUShort;
034: import com.sun.media.jai.iterator.WritableRandomIterCSMInt;
035: import com.sun.media.jai.iterator.WritableRandomIterCSMFloat;
036: import com.sun.media.jai.iterator.WritableRandomIterCSMDouble;
037: import com.sun.media.jai.iterator.WritableRandomIterFallback;
038:
039: /**
040: * A factory class to instantiate instances of the RandomIter and
041: * WritableRandomIter interfaces on sources of type Raster,
042: * RenderedImage, and WritableRenderedImage.
043: *
044: * @see RandomIter
045: * @see WritableRandomIter
046: */
047: public class RandomIterFactory {
048:
049: /** Prevent this class from ever being instantiated. */
050: private RandomIterFactory() {
051: }
052:
053: /**
054: * Constructs and returns an instance of RandomIter suitable for
055: * iterating over the given bounding rectangle within the given
056: * RenderedImage source. If the bounds parameter is null, the
057: * entire image will be used.
058: *
059: * @param im a read-only RenderedImage source.
060: * @param bounds the bounding Rectangle for the iterator, or null.
061: * @return a RandomIter allowing read-only access to the source.
062: */
063: public static RandomIter create(RenderedImage im, Rectangle bounds) {
064: if (bounds == null) {
065: bounds = new Rectangle(im.getMinX(), im.getMinY(), im
066: .getWidth(), im.getHeight());
067: }
068:
069: SampleModel sm = im.getSampleModel();
070: if (sm instanceof ComponentSampleModel) {
071: switch (sm.getDataType()) {
072: case DataBuffer.TYPE_BYTE:
073: // return new RandomIterCSMByte(im, bounds);
074: case DataBuffer.TYPE_SHORT:
075: // return new RandomIterCSMShort(im, bounds);
076: case DataBuffer.TYPE_USHORT:
077: // return new RandomIterCSMUShort(im, bounds);
078: case DataBuffer.TYPE_INT:
079: // return new RandomIterCSMInt(im, bounds);
080: case DataBuffer.TYPE_FLOAT:
081: // return new RandomIterCSMFloat(im, bounds);
082: case DataBuffer.TYPE_DOUBLE:
083: // return new RandomIterCSMDouble(im, bounds);
084: }
085: }
086:
087: return new RandomIterFallback(im, bounds);
088: }
089:
090: /**
091: * Constructs and returns an instance of RandomIter suitable for
092: * iterating over the given bounding rectangle within the given
093: * Raster source. If the bounds parameter is null, the entire
094: * Raster will be used.
095: *
096: * @param ras a read-only Raster source.
097: * @param bounds the bounding Rectangle for the iterator, or null.
098: * @return a RandomIter allowing read-only access to the source.
099: */
100: public static RandomIter create(Raster ras, Rectangle bounds) {
101: RenderedImage im = new WrapperRI(ras);
102: return create(im, bounds);
103: }
104:
105: /**
106: * Constructs and returns an instance of WritableRandomIter
107: * suitable for iterating over the given bounding rectangle within
108: * the given WritableRenderedImage source. If the bounds
109: * parameter is null, the entire image will be used.
110: *
111: * @param im a WritableRenderedImage source.
112: * @param bounds the bounding Rectangle for the iterator, or null.
113: * @return a WritableRandomIter allowing read/write access to the source.
114: */
115: public static WritableRandomIter createWritable(
116: WritableRenderedImage im, Rectangle bounds) {
117: if (bounds == null) {
118: bounds = new Rectangle(im.getMinX(), im.getMinY(), im
119: .getWidth(), im.getHeight());
120: }
121:
122: SampleModel sm = im.getSampleModel();
123: if (sm instanceof ComponentSampleModel) {
124: switch (sm.getDataType()) {
125: case DataBuffer.TYPE_BYTE:
126: // return new WritableRandomIterCSMByte(im, bounds);
127: case DataBuffer.TYPE_SHORT:
128: // return new WritableRandomIterCSMShort(im, bounds);
129: case DataBuffer.TYPE_USHORT:
130: // return new WritableRandomIterCSMUShort(im, bounds);
131: case DataBuffer.TYPE_INT:
132: // return new WritableRandomIterCSMInt(im, bounds);
133: case DataBuffer.TYPE_FLOAT:
134: // return new WritableRandomIterCSMFloat(im, bounds);
135: case DataBuffer.TYPE_DOUBLE:
136: // return new WritableRandomIterCSMDouble(im, bounds);
137: }
138: }
139:
140: return new WritableRandomIterFallback(im, bounds);
141: }
142:
143: /**
144: * Constructs and returns an instance of WritableRandomIter
145: * suitable for iterating over the given bounding rectangle within
146: * the given WritableRaster source. If the bounds parameter is
147: * null, the entire Raster will be used.
148: *
149: * @param ras a WritableRaster source.
150: * @param bounds the bounding Rectangle for the iterator, or null.
151: * @return a WritableRandomIter allowing read/write access to the source.
152: */
153: public static WritableRandomIter createWritable(WritableRaster ras,
154: Rectangle bounds) {
155: WritableRenderedImage im = new WrapperWRI(ras);
156: return createWritable(im, bounds);
157: }
158: }
|