001/*
002 * $RCSfile: TIFFImageReadParam.java,v $
003 *
004 * 
005 * Copyright (c) 2005 Sun Microsystems, Inc. All  Rights Reserved.
006 * 
007 * Redistribution and use in source and binary forms, with or without
008 * modification, are permitted provided that the following conditions
009 * are met: 
010 * 
011 * - Redistribution of source code must retain the above copyright 
012 *   notice, this  list of conditions and the following disclaimer.
013 * 
014 * - Redistribution in binary form must reproduce the above copyright
015 *   notice, this list of conditions and the following disclaimer in 
016 *   the documentation and/or other materials provided with the
017 *   distribution.
018 * 
019 * Neither the name of Sun Microsystems, Inc. or the names of 
020 * contributors may be used to endorse or promote products derived 
021 * from this software without specific prior written permission.
022 * 
023 * This software is provided "AS IS," without a warranty of any 
024 * kind. ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND 
025 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, 
026 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY
027 * EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL 
028 * NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF 
029 * USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
030 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR 
031 * ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL,
032 * CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND
033 * REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF OR
034 * INABILITY TO USE THIS SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
035 * POSSIBILITY OF SUCH DAMAGES. 
036 * 
037 * You acknowledge that this software is not designed or intended for 
038 * use in the design, construction, operation or maintenance of any 
039 * nuclear facility. 
040 *
041 * $Revision: 1.1 $
042 * $Date: 2005/02/11 05:01:18 $
043 * $State: Exp $
044 */
045package com.github.jaiimageio.plugins.tiff;
046
047import java.util.ArrayList;
048import java.util.List;
049import javax.imageio.ImageReadParam;
050
051/**
052 * A subclass of {@link ImageReadParam} allowing control over
053 * the TIFF reading process.
054 *
055 * <p> Because TIFF is an extensible format, the reader requires
056 * information about any tags used by TIFF extensions in order to emit
057 * meaningful metadata.  Also, TIFF extensions may define new
058 * compression types.  Both types of information about extensions may
059 * be provided by this interface.
060 *
061 * <p> Additional TIFF tags must be organized into
062 * <code>TIFFTagSet</code>s.  A <code>TIFFTagSet</code> may be
063 * provided to the reader by means of the
064 * <code>addAllowedTagSet</code> method.  By default, the tag sets
065 * <code>BaselineTIFFTagSet</code>, <code>FaxTIFFTagSet</code>,
066 * <code>EXIFParentTIFFTagSet</code>, and <code>GeoTIFFTagSet</code>
067 * are included.
068 *
069 * <p> New TIFF decompressors are handled in a simple fashion.  If a
070 * non-<code>null</code> <code>TIFFDecompressor</code> is provided by
071 * means of the setTIFFDecompressor method, it will override the
072 * reader's usual choice of decompressor.  Thus, to read an image with
073 * a non-standard compression type, the application should first
074 * attempt to read the image's metadata and extract the compression
075 * type.  The application may then use its own logic to choose a
076 * suitable <code>TIFFDecompressor</code>, instantiate it, and pass it
077 * to the <code>ImageReadParam</code> being used.  The reader's
078 * <code>read</code> method may be called with the
079 * <code>ImageReadParam</code> set.
080 */
081public class TIFFImageReadParam extends ImageReadParam {
082
083    List allowedTagSets = new ArrayList(4);
084
085    TIFFDecompressor decompressor = null;
086
087    TIFFColorConverter colorConverter = null;
088
089    /**
090     * Constructs a <code>TIFFImageReadParam</code>.  Tags defined by
091     * the <code>TIFFTagSet</code>s <code>BaselineTIFFTagSet</code>,
092     * <code>FaxTIFFTagSet</code>, <code>EXIFParentTIFFTagSet</code>, and
093     * <code>GeoTIFFTagSet</code> will be supported.
094     *
095     * @see BaselineTIFFTagSet
096     * @see FaxTIFFTagSet
097     * @see EXIFParentTIFFTagSet
098     * @see GeoTIFFTagSet
099     */
100    public TIFFImageReadParam() {
101        addAllowedTagSet(BaselineTIFFTagSet.getInstance());
102        addAllowedTagSet(FaxTIFFTagSet.getInstance());
103        addAllowedTagSet(EXIFParentTIFFTagSet.getInstance());
104        addAllowedTagSet(GeoTIFFTagSet.getInstance());
105    }
106
107    /**
108     * Adds a <code>TIFFTagSet</code> object to the list of allowed
109     * tag sets.
110     *
111     * @param tagSet a <code>TIFFTagSet</code>.
112     *
113     * @throws IllegalArgumentException if <code>tagSet</code> is
114     * <code>null</code>.
115     */
116    public void addAllowedTagSet(TIFFTagSet tagSet) {
117        if (tagSet == null) {
118            throw new IllegalArgumentException("tagSet == null!");
119        }
120        allowedTagSets.add(tagSet);
121    }
122
123    /**
124     * Removes a <code>TIFFTagSet</code> object from the list of
125     * allowed tag sets.  Removal is based on the <code>equals</code>
126     * method of the <code>TIFFTagSet</code>, which is normally
127     * defined as reference equality.
128     *
129     * @param tagSet a <code>TIFFTagSet</code>.
130     *
131     * @throws IllegalArgumentException if <code>tagSet</code> is
132     * <code>null</code>.
133     */
134    public void removeAllowedTagSet(TIFFTagSet tagSet) {
135        if (tagSet == null) {
136            throw new IllegalArgumentException("tagSet == null!");
137        }
138        allowedTagSets.remove(tagSet);
139    }
140
141    /**
142     * Returns a <code>List</code> containing the allowed
143     * <code>TIFFTagSet</code> objects.
144     *
145     * @return a <code>List</code> of <code>TIFFTagSet</code>s.
146     */
147    public List getAllowedTagSets() {
148        return allowedTagSets;
149    }
150
151    /**
152     * Sets the <code>TIFFDecompressor</code> object to be used by the
153     * <code>ImageReader</code> to decode each image strip or tile.
154     * A value of <code>null</code> allows the reader to choose its
155     * own TIFFDecompressor.
156     *
157     * @param decompressor the <code>TIFFDecompressor</code> to be
158     * used for decoding, or <code>null</code> to allow the reader to
159     * choose its own.
160     *
161     * @see #getTIFFDecompressor
162     */
163    public void setTIFFDecompressor(TIFFDecompressor decompressor) {
164        this.decompressor = decompressor;
165    }
166
167    /**
168     * Returns the <code>TIFFDecompressor</code> that is currently set
169     * to be used by the <code>ImageReader</code> to decode each image
170     * strip or tile, or <code>null</code> if none has been set.
171     *
172     * @return decompressor the <code>TIFFDecompressor</code> to be
173     * used for decoding, or <code>null</code> if none has been set
174     * (allowing the reader to choose its own).
175     *
176     * @see #setTIFFDecompressor(TIFFDecompressor)
177     */
178    public TIFFDecompressor getTIFFDecompressor() {
179        return this.decompressor;
180    }
181
182    /**
183     * Sets the <code>TIFFColorConverter</code> object for the pixel data
184     * being read.  The data will be converted from the given color
185     * space to a standard RGB space as it is being read.  A value of
186     * <code>null</code> disables conversion.
187     *
188     * @param colorConverter a <code>TIFFColorConverter</code> object
189     * to be used for final color conversion, or <code>null</code>.
190     *
191     * @see #getColorConverter
192     */
193    public void setColorConverter(TIFFColorConverter colorConverter) {
194        this.colorConverter = colorConverter;
195    }
196
197    /**
198     * Returns the currently set <code>TIFFColorConverter</code> object,
199     * or <code>null</code> if none is set.
200     *
201     * @return the current <code>TIFFColorConverter</code> object.
202     *
203     * @see #setColorConverter(TIFFColorConverter)
204     */
205    public TIFFColorConverter getColorConverter() {
206        return this.colorConverter;
207    }
208}