1 /* 2 * Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package javax.imageio.plugins.tiff; 26 27 import java.util.ArrayList; 28 import java.util.List; 29 import javax.imageio.ImageReadParam; 30 31 /** 32 * A subclass of {@link ImageReadParam} allowing control over 33 * the TIFF reading process. 34 * 35 * <p> Because TIFF is an extensible format, the reader requires 36 * information about any tags used by TIFF extensions in order to emit 37 * meaningful metadata. Also, TIFF extensions may define new 38 * compression types. Both types of information about extensions may 39 * be provided by this interface. 40 * 41 * <p> Additional TIFF tags must be organized into 42 * {@code TIFFTagSet}s. A {@code TIFFTagSet} may be 43 * provided to the reader by means of the 44 * {@code addAllowedTagSet} method. By default, the tag sets 45 * {@code BaselineTIFFTagSet}, {@code FaxTIFFTagSet}, 46 * {@code ExifParentTIFFTagSet}, and {@code GeoTIFFTagSet} 47 * are included. 48 * 49 * <p> Forcing reading of fields corresponding to {@code TIFFTag}s 50 * not in any of the allowed {@code TIFFTagSet}s may be effected via 51 * {@link #setReadUnknownTags setReadUnknownTags}. 52 * 53 * @since 9 54 */ 55 public final class TIFFImageReadParam extends ImageReadParam { 56 57 private final List<TIFFTagSet> allowedTagSets = 58 new ArrayList<TIFFTagSet>(4); 59 60 private boolean readUnknownTags = false; 61 62 /** 63 * Constructs a {@code TIFFImageReadParam}. Tags defined by 64 * the {@code TIFFTagSet}s {@code BaselineTIFFTagSet}, 65 * {@code FaxTIFFTagSet}, {@code ExifParentTIFFTagSet}, and 66 * {@code GeoTIFFTagSet} will be supported. 67 * 68 * @see BaselineTIFFTagSet 69 * @see FaxTIFFTagSet 70 * @see ExifParentTIFFTagSet 71 * @see GeoTIFFTagSet 72 */ 73 public TIFFImageReadParam() { 74 addAllowedTagSet(BaselineTIFFTagSet.getInstance()); 75 addAllowedTagSet(FaxTIFFTagSet.getInstance()); 76 addAllowedTagSet(ExifParentTIFFTagSet.getInstance()); 77 addAllowedTagSet(GeoTIFFTagSet.getInstance()); 78 } 79 80 /** 81 * Adds a {@code TIFFTagSet} object to the list of allowed 82 * tag sets. Attempting to add a duplicate object to the list 83 * has no effect. 84 * 85 * @param tagSet a {@code TIFFTagSet}. 86 * 87 * @throws IllegalArgumentException if {@code tagSet} is 88 * {@code null}. 89 */ 90 public void addAllowedTagSet(TIFFTagSet tagSet) { 91 if (tagSet == null) { 92 throw new IllegalArgumentException("tagSet == null!"); 93 } 94 if (!allowedTagSets.contains(tagSet)) { 95 allowedTagSets.add(tagSet); 96 } 97 } 98 99 /** 100 * Removes a {@code TIFFTagSet} object from the list of 101 * allowed tag sets. Removal is based on the {@code equals} 102 * method of the {@code TIFFTagSet}, which is normally 103 * defined as reference equality. 104 * 105 * @param tagSet a {@code TIFFTagSet}. 106 * 107 * @throws IllegalArgumentException if {@code tagSet} is 108 * {@code null}. 109 */ 110 public void removeAllowedTagSet(TIFFTagSet tagSet) { 111 if (tagSet == null) { 112 throw new IllegalArgumentException("tagSet == null!"); 113 } 114 allowedTagSets.remove(tagSet); 115 } 116 117 /** 118 * Returns a {@code List} containing the allowed 119 * {@code TIFFTagSet} objects. 120 * 121 * @return a {@code List} of {@code TIFFTagSet}s. 122 */ 123 public List<TIFFTagSet> getAllowedTagSets() { 124 return allowedTagSets; 125 } 126 127 /** 128 * Set whether to read fields corresponding to {@code TIFFTag}s not in 129 * the allowed {@code TIFFTagSet}s. The default setting is {@code false}. 130 * If the TIFF {@code ImageReader} is ignoring metadata, then a setting 131 * of {@code true} is overridden as all metadata are ignored except those 132 * essential to reading the image itself. 133 * 134 * @param readUnknownTags Whether to read fields of unrecognized tags 135 */ 136 public void setReadUnknownTags(boolean readUnknownTags) { 137 this.readUnknownTags = readUnknownTags; 138 } 139 140 /** 141 * Retrieve the setting of whether to read fields corresponding to unknown 142 * {@code TIFFTag}s. 143 * 144 * @return Whether to read fields of unrecognized tags 145 */ 146 public boolean getReadUnknownTags() { 147 return readUnknownTags; 148 } 149 }