Path: blob/master/src/java.desktop/share/classes/javax/imageio/plugins/tiff/TIFFImageReadParam.java
41159 views
/*1* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package javax.imageio.plugins.tiff;2526import java.util.ArrayList;27import java.util.List;28import javax.imageio.ImageReadParam;2930/**31* A subclass of {@link ImageReadParam} allowing control over32* the TIFF reading process.33*34* <p> Because TIFF is an extensible format, the reader requires35* information about any tags used by TIFF extensions in order to emit36* meaningful metadata. Also, TIFF extensions may define new37* compression types. Both types of information about extensions may38* be provided by this interface.39*40* <p> Additional TIFF tags must be organized into41* {@code TIFFTagSet}s. A {@code TIFFTagSet} may be42* provided to the reader by means of the43* {@code addAllowedTagSet} method. By default, the tag sets44* {@code BaselineTIFFTagSet}, {@code FaxTIFFTagSet},45* {@code ExifParentTIFFTagSet}, and {@code GeoTIFFTagSet}46* are included.47*48* <p> Forcing reading of fields corresponding to {@code TIFFTag}s49* not in any of the allowed {@code TIFFTagSet}s may be effected via50* {@link #setReadUnknownTags setReadUnknownTags}.51*52* @since 953*/54public final class TIFFImageReadParam extends ImageReadParam {5556private final List<TIFFTagSet> allowedTagSets =57new ArrayList<TIFFTagSet>(4);5859private boolean readUnknownTags = false;6061/**62* Constructs a {@code TIFFImageReadParam}. Tags defined by63* the {@code TIFFTagSet}s {@code BaselineTIFFTagSet},64* {@code FaxTIFFTagSet}, {@code ExifParentTIFFTagSet}, and65* {@code GeoTIFFTagSet} will be supported.66*67* @see BaselineTIFFTagSet68* @see FaxTIFFTagSet69* @see ExifParentTIFFTagSet70* @see GeoTIFFTagSet71*/72public TIFFImageReadParam() {73addAllowedTagSet(BaselineTIFFTagSet.getInstance());74addAllowedTagSet(FaxTIFFTagSet.getInstance());75addAllowedTagSet(ExifParentTIFFTagSet.getInstance());76addAllowedTagSet(GeoTIFFTagSet.getInstance());77}7879/**80* Adds a {@code TIFFTagSet} object to the list of allowed81* tag sets. Attempting to add a duplicate object to the list82* has no effect.83*84* @param tagSet a {@code TIFFTagSet}.85*86* @throws IllegalArgumentException if {@code tagSet} is87* {@code null}.88*/89public void addAllowedTagSet(TIFFTagSet tagSet) {90if (tagSet == null) {91throw new IllegalArgumentException("tagSet == null!");92}93if (!allowedTagSets.contains(tagSet)) {94allowedTagSets.add(tagSet);95}96}9798/**99* Removes a {@code TIFFTagSet} object from the list of100* allowed tag sets. Removal is based on the {@code equals}101* method of the {@code TIFFTagSet}, which is normally102* defined as reference equality.103*104* @param tagSet a {@code TIFFTagSet}.105*106* @throws IllegalArgumentException if {@code tagSet} is107* {@code null}.108*/109public void removeAllowedTagSet(TIFFTagSet tagSet) {110if (tagSet == null) {111throw new IllegalArgumentException("tagSet == null!");112}113allowedTagSets.remove(tagSet);114}115116/**117* Returns a {@code List} containing the allowed118* {@code TIFFTagSet} objects.119*120* @return a {@code List} of {@code TIFFTagSet}s.121*/122public List<TIFFTagSet> getAllowedTagSets() {123return allowedTagSets;124}125126/**127* Set whether to read fields corresponding to {@code TIFFTag}s not in128* the allowed {@code TIFFTagSet}s. The default setting is {@code false}.129* If the TIFF {@code ImageReader} is ignoring metadata, then a setting130* of {@code true} is overridden as all metadata are ignored except those131* essential to reading the image itself.132*133* @param readUnknownTags Whether to read fields of unrecognized tags134*/135public void setReadUnknownTags(boolean readUnknownTags) {136this.readUnknownTags = readUnknownTags;137}138139/**140* Retrieve the setting of whether to read fields corresponding to unknown141* {@code TIFFTag}s.142*143* @return Whether to read fields of unrecognized tags144*/145public boolean getReadUnknownTags() {146return readUnknownTags;147}148}149150151