source: josm/trunk/src/com/drew/metadata/tiff/DirectoryTiffHandler.java@ 8132

Last change on this file since 8132 was 8132, checked in by Don-vip, 9 years ago

fix #11162 - update to metadata-extractor 2.7.2

File size: 5.3 KB
Line 
1/*
2 * Copyright 2002-2015 Drew Noakes
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * More information about this project is available at:
17 *
18 * https://drewnoakes.com/code/exif/
19 * https://github.com/drewnoakes/metadata-extractor
20 */
21package com.drew.metadata.tiff;
22
23import com.drew.imaging.tiff.TiffHandler;
24import com.drew.lang.Rational;
25import com.drew.lang.annotations.NotNull;
26import com.drew.metadata.Directory;
27import com.drew.metadata.Metadata;
28
29import java.util.Stack;
30
31/**
32 * Adapter between the {@link TiffHandler} interface and the {@link Metadata}/{@link Directory} object model.
33 *
34 * @author Drew Noakes https://drewnoakes.com
35 */
36public abstract class DirectoryTiffHandler implements TiffHandler
37{
38 private final Stack<Directory> _directoryStack = new Stack<Directory>();
39
40 protected Directory _currentDirectory;
41 protected final Metadata _metadata;
42
43 protected DirectoryTiffHandler(Metadata metadata, Class<? extends Directory> initialDirectory)
44 {
45 _metadata = metadata;
46 _currentDirectory = _metadata.getOrCreateDirectory(initialDirectory);
47 }
48
49 public void endingIFD()
50 {
51 _currentDirectory = _directoryStack.empty() ? null : _directoryStack.pop();
52 }
53
54 protected void pushDirectory(@NotNull Class<? extends Directory> directoryClass)
55 {
56 assert(directoryClass != _currentDirectory.getClass());
57 _directoryStack.push(_currentDirectory);
58 _currentDirectory = _metadata.getOrCreateDirectory(directoryClass);
59 }
60
61 public void warn(@NotNull String message)
62 {
63 _currentDirectory.addError(message);
64 }
65
66 public void error(@NotNull String message)
67 {
68 _currentDirectory.addError(message);
69 }
70
71 public void setByteArray(int tagId, @NotNull byte[] bytes)
72 {
73 _currentDirectory.setByteArray(tagId, bytes);
74 }
75
76 public void setString(int tagId, @NotNull String string)
77 {
78 _currentDirectory.setString(tagId, string);
79 }
80
81 public void setRational(int tagId, @NotNull Rational rational)
82 {
83 _currentDirectory.setRational(tagId, rational);
84 }
85
86 public void setRationalArray(int tagId, @NotNull Rational[] array)
87 {
88 _currentDirectory.setRationalArray(tagId, array);
89 }
90
91 public void setFloat(int tagId, float float32)
92 {
93 _currentDirectory.setFloat(tagId, float32);
94 }
95
96 public void setFloatArray(int tagId, @NotNull float[] array)
97 {
98 _currentDirectory.setFloatArray(tagId, array);
99 }
100
101 public void setDouble(int tagId, double double64)
102 {
103 _currentDirectory.setDouble(tagId, double64);
104 }
105
106 public void setDoubleArray(int tagId, @NotNull double[] array)
107 {
108 _currentDirectory.setDoubleArray(tagId, array);
109 }
110
111 public void setInt8s(int tagId, byte int8s)
112 {
113 // NOTE Directory stores all integral types as int32s, except for int32u and long
114 _currentDirectory.setInt(tagId, int8s);
115 }
116
117 public void setInt8sArray(int tagId, @NotNull byte[] array)
118 {
119 // NOTE Directory stores all integral types as int32s, except for int32u and long
120 _currentDirectory.setByteArray(tagId, array);
121 }
122
123 public void setInt8u(int tagId, short int8u)
124 {
125 // NOTE Directory stores all integral types as int32s, except for int32u and long
126 _currentDirectory.setInt(tagId, int8u);
127 }
128
129 public void setInt8uArray(int tagId, @NotNull short[] array)
130 {
131 // TODO create and use a proper setter for short[]
132 _currentDirectory.setObjectArray(tagId, array);
133 }
134
135 public void setInt16s(int tagId, int int16s)
136 {
137 // TODO create and use a proper setter for int16u?
138 _currentDirectory.setInt(tagId, int16s);
139 }
140
141 public void setInt16sArray(int tagId, @NotNull short[] array)
142 {
143 // TODO create and use a proper setter for short[]
144 _currentDirectory.setObjectArray(tagId, array);
145 }
146
147 public void setInt16u(int tagId, int int16u)
148 {
149 // TODO create and use a proper setter for
150 _currentDirectory.setInt(tagId, int16u);
151 }
152
153 public void setInt16uArray(int tagId, @NotNull int[] array)
154 {
155 // TODO create and use a proper setter for short[]
156 _currentDirectory.setObjectArray(tagId, array);
157 }
158
159 public void setInt32s(int tagId, int int32s)
160 {
161 _currentDirectory.setInt(tagId, int32s);
162 }
163
164 public void setInt32sArray(int tagId, @NotNull int[] array)
165 {
166 _currentDirectory.setIntArray(tagId, array);
167 }
168
169 public void setInt32u(int tagId, long int32u)
170 {
171 _currentDirectory.setLong(tagId, int32u);
172 }
173
174 public void setInt32uArray(int tagId, @NotNull long[] array)
175 {
176 // TODO create and use a proper setter for short[]
177 _currentDirectory.setObjectArray(tagId, array);
178 }
179}
Note: See TracBrowser for help on using the repository browser.