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;
049
050import javax.imageio.ImageReadParam;
051
052/**
053 * A subclass of {@link ImageReadParam} allowing control over
054 * the TIFF reading process.
055 *
056 * <p> Because TIFF is an extensible format, the reader requires
057 * information about any tags used by TIFF extensions in order to emit
058 * meaningful metadata.  Also, TIFF extensions may define new
059 * compression types.  Both types of information about extensions may
060 * be provided by this interface.
061 *
062 * <p> Additional TIFF tags must be organized into
063 * <code>TIFFTagSet</code>s.  A <code>TIFFTagSet</code> may be
064 * provided to the reader by means of the
065 * <code>addAllowedTagSet</code> method.  By default, the tag sets
066 * <code>BaselineTIFFTagSet</code>, <code>FaxTIFFTagSet</code>,
067 * <code>EXIFParentTIFFTagSet</code>, and <code>GeoTIFFTagSet</code>
068 * are included.
069 *
070 * <p> New TIFF decompressors are handled in a simple fashion.  If a
071 * non-<code>null</code> <code>TIFFDecompressor</code> is provided by
072 * means of the setTIFFDecompressor method, it will override the
073 * reader's usual choice of decompressor.  Thus, to read an image with
074 * a non-standard compression type, the application should first
075 * attempt to read the image's metadata and extract the compression
076 * type.  The application may then use its own logic to choose a
077 * suitable <code>TIFFDecompressor</code>, instantiate it, and pass it
078 * to the <code>ImageReadParam</code> being used.  The reader's
079 * <code>read</code> method may be called with the
080 * <code>ImageReadParam</code> set.
081 */
082public class TIFFImageReadParam extends ImageReadParam {
083
084    List allowedTagSets = new ArrayList(4);
085
086    TIFFDecompressor decompressor = null;
087
088    TIFFColorConverter colorConverter = null;
089
090    /**
091     * Constructs a <code>TIFFImageReadParam</code>.  Tags defined by
092     * the <code>TIFFTagSet</code>s <code>BaselineTIFFTagSet</code>,
093     * <code>FaxTIFFTagSet</code>, <code>EXIFParentTIFFTagSet</code>, and
094     * <code>GeoTIFFTagSet</code> will be supported.
095     *
096     * @see BaselineTIFFTagSet
097     * @see FaxTIFFTagSet
098     * @see EXIFParentTIFFTagSet
099     * @see GeoTIFFTagSet
100     */
101    public TIFFImageReadParam() {
102        addAllowedTagSet(BaselineTIFFTagSet.getInstance());
103        addAllowedTagSet(FaxTIFFTagSet.getInstance());
104        addAllowedTagSet(EXIFParentTIFFTagSet.getInstance());
105        addAllowedTagSet(GeoTIFFTagSet.getInstance());
106    }
107
108    /**
109     * Adds a <code>TIFFTagSet</code> object to the list of allowed
110     * tag sets.
111     *
112     * @param tagSet a <code>TIFFTagSet</code>.
113     *
114     * @throws IllegalArgumentException if <code>tagSet</code> is
115     * <code>null</code>.
116     */
117    public void addAllowedTagSet(TIFFTagSet tagSet) {
118        if (tagSet == null) {
119            throw new IllegalArgumentException("tagSet == null!");
120        }
121        allowedTagSets.add(tagSet);
122    }
123
124    /**
125     * Removes a <code>TIFFTagSet</code> object from the list of
126     * allowed tag sets.  Removal is based on the <code>equals</code>
127     * method of the <code>TIFFTagSet</code>, which is normally
128     * defined as reference equality.
129     *
130     * @param tagSet a <code>TIFFTagSet</code>.
131     *
132     * @throws IllegalArgumentException if <code>tagSet</code> is
133     * <code>null</code>.
134     */
135    public void removeAllowedTagSet(TIFFTagSet tagSet) {
136        if (tagSet == null) {
137            throw new IllegalArgumentException("tagSet == null!");
138        }
139        allowedTagSets.remove(tagSet);
140    }
141
142    /**
143     * Returns a <code>List</code> containing the allowed
144     * <code>TIFFTagSet</code> objects.
145     *
146     * @return a <code>List</code> of <code>TIFFTagSet</code>s.
147     */
148    public List getAllowedTagSets() {
149        return allowedTagSets;
150    }
151
152    /**
153     * Sets the <code>TIFFDecompressor</code> object to be used by the
154     * <code>ImageReader</code> to decode each image strip or tile.
155     * A value of <code>null</code> allows the reader to choose its
156     * own TIFFDecompressor.
157     *
158     * @param decompressor the <code>TIFFDecompressor</code> to be
159     * used for decoding, or <code>null</code> to allow the reader to
160     * choose its own.
161     *
162     * @see #getTIFFDecompressor
163     */
164    public void setTIFFDecompressor(TIFFDecompressor decompressor) {
165        this.decompressor = decompressor;
166    }
167
168    /**
169     * Returns the <code>TIFFDecompressor</code> that is currently set
170     * to be used by the <code>ImageReader</code> to decode each image
171     * strip or tile, or <code>null</code> if none has been set.
172     *
173     * @return decompressor the <code>TIFFDecompressor</code> to be
174     * used for decoding, or <code>null</code> if none has been set
175     * (allowing the reader to choose its own).
176     *
177     * @see #setTIFFDecompressor(TIFFDecompressor)
178     */
179    public TIFFDecompressor getTIFFDecompressor() {
180        return this.decompressor;
181    }
182
183    /**
184     * Sets the <code>TIFFColorConverter</code> object for the pixel data
185     * being read.  The data will be converted from the given color
186     * space to a standard RGB space as it is being read.  A value of
187     * <code>null</code> disables conversion.
188     *
189     * @param colorConverter a <code>TIFFColorConverter</code> object
190     * to be used for final color conversion, or <code>null</code>.
191     *
192     * @see #getColorConverter
193     */
194    public void setColorConverter(TIFFColorConverter colorConverter) {
195        this.colorConverter = colorConverter;
196    }
197
198    /**
199     * Returns the currently set <code>TIFFColorConverter</code> object,
200     * or <code>null</code> if none is set.
201     *
202     * @return the current <code>TIFFColorConverter</code> object.
203     *
204     * @see #setColorConverter(TIFFColorConverter)
205     */
206    public TIFFColorConverter getColorConverter() {
207        return this.colorConverter;
208    }
209}