001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2007, Geotools Project Managment Committee (PMC)
005: * (C) 2007, Geomatys
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.image.io;
018:
019: import java.util.Locale;
020: import java.io.IOException;
021: import java.awt.image.BufferedImage;
022: import javax.imageio.ImageReadParam;
023: import javax.imageio.ImageReader;
024: import javax.imageio.metadata.IIOMetadata;
025: import javax.imageio.spi.ImageReaderSpi;
026:
027: import org.geotools.image.io.metadata.Band;
028: import org.geotools.image.io.metadata.GeographicMetadata;
029:
030: /**
031: * A null implementation of {@link GeographicImageReader} for testing purpose.
032: *
033: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/test/java/org/geotools/image/io/NullImageReader.java $
034: * @version $Id: NullImageReader.java 26775 2007-08-30 15:58:26Z desruisseaux $
035: * @author Martin Desruisseaux
036: */
037: final class NullImageReader extends GeographicImageReader {
038: /**
039: * The data type to be returned by {@link #getRawDataType}.
040: */
041: private final int dataType;
042:
043: /**
044: * The metadata to be returned by {@link #getImageMetadata}.
045: */
046: private final double minimum, maximum, padValue;
047:
048: /**
049: * Creates a reader with a dummy provider.
050: */
051: public NullImageReader(final int dataType, final double minimum,
052: final double maximum, final double padValue) {
053: super (new Spi());
054: this .dataType = dataType;
055: this .minimum = minimum;
056: this .maximum = maximum;
057: this .padValue = padValue;
058: setInput("Dummy");
059: }
060:
061: /**
062: * Returns a dummy width.
063: */
064: public int getWidth(final int imageIndex) throws IOException {
065: checkImageIndex(imageIndex);
066: return 200;
067: }
068:
069: /**
070: * Returns a dummy height.
071: */
072: public int getHeight(final int imageIndex) throws IOException {
073: checkImageIndex(imageIndex);
074: return 100;
075: }
076:
077: /**
078: * Returns the metadata specified at construction time.
079: */
080: //@Override
081: public IIOMetadata getImageMetadata(final int imageIndex)
082: throws IOException {
083: final GeographicMetadata metadata = new GeographicMetadata(this );
084: final Band band = metadata.addBand("Dummy");
085: band.setValidRange(minimum, maximum);
086: band.setNoDataValues(new double[] { padValue });
087: return metadata;
088: }
089:
090: /**
091: * Returns the data type specified at construction time.
092: */
093: //@Override
094: protected int getRawDataType(final int imageIndex)
095: throws IOException {
096: super .getRawDataType(imageIndex);
097: return dataType;
098: }
099:
100: /**
101: * Returns a dummy image.
102: */
103: public BufferedImage read(final int imageIndex,
104: final ImageReadParam param) throws IOException {
105: checkImageIndex(imageIndex);
106: final BufferedImage image = getDestination(imageIndex, param,
107: 200, 100, null);
108: return image;
109: }
110:
111: /**
112: * A dummy provider for the dummy reader.
113: */
114: private static final class Spi extends ImageReaderSpi {
115: public Spi() {
116: inputTypes = new Class[] { String.class };
117: }
118:
119: public ImageReader createReaderInstance(final Object extension)
120: throws IOException {
121: throw new UnsupportedOperationException();
122: }
123:
124: public boolean canDecodeInput(final Object source)
125: throws IOException {
126: return false;
127: }
128:
129: public String getDescription(final Locale locale) {
130: return "Dummy";
131: }
132: }
133: }
|