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
46 * corresponds to an IFD Entry in the IFD.
47 *
48 * <p>When reading, a {@code TIFFDirectory} may be created by passing
49 * the value returned by {@link javax.imageio.ImageReader#getImageMetadata
50 * ImageReader.getImageMetadata()} to {@link #createFromMetadata
51 * createFromMetadata()}. The {@link TIFFField}s in the directory may then
52 * be obtained using the accessor methods provided in this class.</p>
53 *
54 * <p>When writing, an {@link IIOMetadata} object for use by one of the
55 * {@code write()} methods of {@link javax.imageio.ImageWriter} may be
56 * created from a {@code TIFFDirectory} by {@link #getAsMetadata()}.
57 * The {@code TIFFDirectory} itself may be created by construction or
58 * from the {@code IIOMetadata} object returned by
59 * {@link javax.imageio.ImageWriter#getDefaultImageMetadata
60 * ImageWriter.getDefaultImageMetadata()}. The {@code TIFFField}s in the
61 * directory may be set using the mutator methods provided in this class.</p>
62 *
63 * <p>A {@code TIFFDirectory} is aware of the tag numbers in the
64 * group of {@link TIFFTagSet}s associated with it. When
65 * a {@code TIFFDirectory} is created from a native image metadata
66 * object, these tag sets are derived from the <tt>tagSets</tt> attribute
67 * of the <tt>TIFFIFD</tt> node.</p>
68 *
69 * <p>A {@code TIFFDirectory} might also have a parent {@link TIFFTag}.
70 * This will occur if the directory represents an IFD other than the root
71 * IFD of the image. The parent tag is the tag of the IFD Entry which is a
72 * pointer to the IFD represented by this {@code TIFFDirectory}. The
73 * {@link TIFFTag#isIFDPointer} method of this parent {@code TIFFTag}
74 * must return {@code true}. When a {@code TIFFDirectory} is
75 * created from a native image metadata object, the parent tag set is set
76 * from the <tt>parentTagName</tt> attribute of the corresponding
77 * <tt>TIFFIFD</tt> node. Note that a {@code TIFFDirectory} instance
78 * which has a non-{@code null} parent tag will be contained in the
79 * data field of a {@code TIFFField} instance which has a tag field
80 * equal to the contained directory's parent tag.</p>
81 *
82 * <p>As an example consider an Exif image. The {@code TIFFDirectory}
83 * instance corresponding to the Exif IFD in the Exif stream would have parent
84 * tag {@link ExifParentTIFFTagSet#TAG_EXIF_IFD_POINTER TAG_EXIF_IFD_POINTER}
85 * and would include {@link ExifTIFFTagSet} in its group of known tag sets.
86 * The {@code TIFFDirectory} corresponding to this Exif IFD will be
87 * contained in the data field of a {@code TIFFField} which will in turn
88 * be contained in the {@code TIFFDirectory} corresponding to the primary
89 * IFD of the Exif image which will itself have a {@code null}-valued
90 * parent tag.</p>
91 *
92 * <p><b>Note that this implementation is not synchronized. </b>If multiple
93 * threads use a {@code TIFFDirectory} instance concurrently, and at
94 * least one of the threads modifies the directory, for example, by adding
95 * or removing {@code TIFFField}s or {@code TIFFTagSet}s, it
96 * <i>must</i> be synchronized externally.</p>
97 *
116 /**
117 * The fields in this directory which have a low tag number. These are
118 * managed as an array for efficiency as they are the most common fields.
119 */
120 private TIFFField[] lowFields = new TIFFField[MAX_LOW_FIELD_TAG_NUM + 1];
121
122 /** The number of low tag numbered fields in the directory. */
123 private int numLowFields = 0;
124
125 /**
126 * A mapping of {@code Integer} tag numbers to {@code TIFFField}s
127 * for fields which are not low tag numbered.
128 */
129 private Map<Integer,TIFFField> highFields = new TreeMap<Integer,TIFFField>();
130
131 /**
132 * Creates a {@code TIFFDirectory} instance from the contents of
133 * an image metadata object. The supplied object must support an image
134 * metadata format supported by the TIFF {@link javax.imageio.ImageWriter}
135 * plug-in. This will usually be either the TIFF native image metadata
136 * format <tt>javax_imageio_tiff_image_1.0</tt> or the Java
137 * Image I/O standard metadata format <tt>javax_imageio_1.0</tt>.
138 *
139 * @param tiffImageMetadata A metadata object which supports a compatible
140 * image metadata format.
141 *
142 * @return A {@code TIFFDirectory} populated from the contents of
143 * the supplied metadata object.
144 *
145 * @throws NullPointerException if {@code tiffImageMetadata}
146 * is {@code null}.
147 * @throws IllegalArgumentException if {@code tiffImageMetadata}
148 * does not support a compatible image metadata format.
149 * @throws IIOInvalidTreeException if the supplied metadata object
150 * cannot be parsed.
151 */
152 public static TIFFDirectory
153 createFromMetadata(IIOMetadata tiffImageMetadata)
154 throws IIOInvalidTreeException {
155
156 if(tiffImageMetadata == null) {
157 throw new NullPointerException("tiffImageMetadata == null");
|
1 /*
2 * Copyright (c) 2005, 2017, 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
46 * corresponds to an IFD Entry in the IFD.
47 *
48 * <p>When reading, a {@code TIFFDirectory} may be created by passing
49 * the value returned by {@link javax.imageio.ImageReader#getImageMetadata
50 * ImageReader.getImageMetadata()} to {@link #createFromMetadata
51 * createFromMetadata()}. The {@link TIFFField}s in the directory may then
52 * be obtained using the accessor methods provided in this class.</p>
53 *
54 * <p>When writing, an {@link IIOMetadata} object for use by one of the
55 * {@code write()} methods of {@link javax.imageio.ImageWriter} may be
56 * created from a {@code TIFFDirectory} by {@link #getAsMetadata()}.
57 * The {@code TIFFDirectory} itself may be created by construction or
58 * from the {@code IIOMetadata} object returned by
59 * {@link javax.imageio.ImageWriter#getDefaultImageMetadata
60 * ImageWriter.getDefaultImageMetadata()}. The {@code TIFFField}s in the
61 * directory may be set using the mutator methods provided in this class.</p>
62 *
63 * <p>A {@code TIFFDirectory} is aware of the tag numbers in the
64 * group of {@link TIFFTagSet}s associated with it. When
65 * a {@code TIFFDirectory} is created from a native image metadata
66 * object, these tag sets are derived from the {@code tagSets} attribute
67 * of the {@code TIFFIFD} node.</p>
68 *
69 * <p>A {@code TIFFDirectory} might also have a parent {@link TIFFTag}.
70 * This will occur if the directory represents an IFD other than the root
71 * IFD of the image. The parent tag is the tag of the IFD Entry which is a
72 * pointer to the IFD represented by this {@code TIFFDirectory}. The
73 * {@link TIFFTag#isIFDPointer} method of this parent {@code TIFFTag}
74 * must return {@code true}. When a {@code TIFFDirectory} is
75 * created from a native image metadata object, the parent tag set is set
76 * from the {@code parentTagName} attribute of the corresponding
77 * {@code TIFFIFD} node. Note that a {@code TIFFDirectory} instance
78 * which has a non-{@code null} parent tag will be contained in the
79 * data field of a {@code TIFFField} instance which has a tag field
80 * equal to the contained directory's parent tag.</p>
81 *
82 * <p>As an example consider an Exif image. The {@code TIFFDirectory}
83 * instance corresponding to the Exif IFD in the Exif stream would have parent
84 * tag {@link ExifParentTIFFTagSet#TAG_EXIF_IFD_POINTER TAG_EXIF_IFD_POINTER}
85 * and would include {@link ExifTIFFTagSet} in its group of known tag sets.
86 * The {@code TIFFDirectory} corresponding to this Exif IFD will be
87 * contained in the data field of a {@code TIFFField} which will in turn
88 * be contained in the {@code TIFFDirectory} corresponding to the primary
89 * IFD of the Exif image which will itself have a {@code null}-valued
90 * parent tag.</p>
91 *
92 * <p><b>Note that this implementation is not synchronized. </b>If multiple
93 * threads use a {@code TIFFDirectory} instance concurrently, and at
94 * least one of the threads modifies the directory, for example, by adding
95 * or removing {@code TIFFField}s or {@code TIFFTagSet}s, it
96 * <i>must</i> be synchronized externally.</p>
97 *
116 /**
117 * The fields in this directory which have a low tag number. These are
118 * managed as an array for efficiency as they are the most common fields.
119 */
120 private TIFFField[] lowFields = new TIFFField[MAX_LOW_FIELD_TAG_NUM + 1];
121
122 /** The number of low tag numbered fields in the directory. */
123 private int numLowFields = 0;
124
125 /**
126 * A mapping of {@code Integer} tag numbers to {@code TIFFField}s
127 * for fields which are not low tag numbered.
128 */
129 private Map<Integer,TIFFField> highFields = new TreeMap<Integer,TIFFField>();
130
131 /**
132 * Creates a {@code TIFFDirectory} instance from the contents of
133 * an image metadata object. The supplied object must support an image
134 * metadata format supported by the TIFF {@link javax.imageio.ImageWriter}
135 * plug-in. This will usually be either the TIFF native image metadata
136 * format {@code javax_imageio_tiff_image_1.0} or the Java
137 * Image I/O standard metadata format {@code javax_imageio_1.0}.
138 *
139 * @param tiffImageMetadata A metadata object which supports a compatible
140 * image metadata format.
141 *
142 * @return A {@code TIFFDirectory} populated from the contents of
143 * the supplied metadata object.
144 *
145 * @throws NullPointerException if {@code tiffImageMetadata}
146 * is {@code null}.
147 * @throws IllegalArgumentException if {@code tiffImageMetadata}
148 * does not support a compatible image metadata format.
149 * @throws IIOInvalidTreeException if the supplied metadata object
150 * cannot be parsed.
151 */
152 public static TIFFDirectory
153 createFromMetadata(IIOMetadata tiffImageMetadata)
154 throws IIOInvalidTreeException {
155
156 if(tiffImageMetadata == null) {
157 throw new NullPointerException("tiffImageMetadata == null");
|