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 * @since 9 50 */ 51 public final class TIFFImageReadParam extends ImageReadParam { 52 53 private final List<TIFFTagSet> allowedTagSets = 54 new ArrayList<TIFFTagSet>(4); 55 56 /** 57 * Constructs a {@code TIFFImageReadParam}. Tags defined by 58 * the {@code TIFFTagSet}s {@code BaselineTIFFTagSet}, 59 * {@code FaxTIFFTagSet}, {@code ExifParentTIFFTagSet}, and 60 * {@code GeoTIFFTagSet} will be supported. 61 * 62 * @see BaselineTIFFTagSet 63 * @see FaxTIFFTagSet 64 * @see ExifParentTIFFTagSet 65 * @see GeoTIFFTagSet 66 */ 67 public TIFFImageReadParam() { 68 addAllowedTagSet(BaselineTIFFTagSet.getInstance()); 69 addAllowedTagSet(FaxTIFFTagSet.getInstance()); 70 addAllowedTagSet(ExifParentTIFFTagSet.getInstance()); 71 addAllowedTagSet(GeoTIFFTagSet.getInstance()); 72 } 73 74 /** 75 * Adds a {@code TIFFTagSet} object to the list of allowed 76 * tag sets. Attempting to add a duplicate object to the list 77 * has no effect. 78 * 79 * @param tagSet a {@code TIFFTagSet}. 80 * 81 * @throws IllegalArgumentException if {@code tagSet} is 82 * {@code null}. 83 */ 84 public void addAllowedTagSet(TIFFTagSet tagSet) { 85 if (tagSet == null) { 86 throw new IllegalArgumentException("tagSet == null!"); 87 } 88 if (!allowedTagSets.contains(tagSet)) { 89 allowedTagSets.add(tagSet); 90 } 91 } 92 93 /** 94 * Removes a {@code TIFFTagSet} object from the list of 95 * allowed tag sets. Removal is based on the {@code equals} 96 * method of the {@code TIFFTagSet}, which is normally 97 * defined as reference equality. 98 * 99 * @param tagSet a {@code TIFFTagSet}. 100 * 101 * @throws IllegalArgumentException if {@code tagSet} is 102 * {@code null}. 103 */ 104 public void removeAllowedTagSet(TIFFTagSet tagSet) { 105 if (tagSet == null) { 106 throw new IllegalArgumentException("tagSet == null!"); 107 } 108 allowedTagSets.remove(tagSet); 109 } 110 111 /** 112 * Returns a {@code List} containing the allowed 113 * {@code TIFFTagSet} objects. 114 * 115 * @return a {@code List} of {@code TIFFTagSet}s. 116 */ 117 public List<TIFFTagSet> getAllowedTagSets() { 118 return allowedTagSets; 119 } 120 }