1 | /*
|
---|
2 | * Copyright 2002-2012 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 | * http://drewnoakes.com/code/exif/
|
---|
19 | * http://code.google.com/p/metadata-extractor/
|
---|
20 | */
|
---|
21 |
|
---|
22 | package com.drew.metadata.exif;
|
---|
23 |
|
---|
24 | import com.drew.lang.Rational;
|
---|
25 | import com.drew.lang.annotations.NotNull;
|
---|
26 | import com.drew.lang.annotations.Nullable;
|
---|
27 | import com.drew.metadata.TagDescriptor;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Provides human-readable string representations of tag values stored in a <code>ExifThumbnailDirectory</code>.
|
---|
31 | *
|
---|
32 | * @author Drew Noakes http://drewnoakes.com
|
---|
33 | */
|
---|
34 | public class ExifThumbnailDescriptor extends TagDescriptor<ExifThumbnailDirectory>
|
---|
35 | {
|
---|
36 | /**
|
---|
37 | * Dictates whether rational values will be represented in decimal format in instances
|
---|
38 | * where decimal notation is elegant (such as 1/2 -> 0.5, but not 1/3).
|
---|
39 | */
|
---|
40 | private final boolean _allowDecimalRepresentationOfRationals = true;
|
---|
41 |
|
---|
42 | public ExifThumbnailDescriptor(@NotNull ExifThumbnailDirectory directory)
|
---|
43 | {
|
---|
44 | super(directory);
|
---|
45 | }
|
---|
46 |
|
---|
47 | // Note for the potential addition of brightness presentation in eV:
|
---|
48 | // Brightness of taken subject. To calculate Exposure(Ev) from BrightnessValue(Bv),
|
---|
49 | // you must add SensitivityValue(Sv).
|
---|
50 | // Ev=BV+Sv Sv=log2(ISOSpeedRating/3.125)
|
---|
51 | // ISO100:Sv=5, ISO200:Sv=6, ISO400:Sv=7, ISO125:Sv=5.32.
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Returns a descriptive value of the the specified tag for this image.
|
---|
55 | * Where possible, known values will be substituted here in place of the raw
|
---|
56 | * tokens actually kept in the Exif segment. If no substitution is
|
---|
57 | * available, the value provided by getString(int) will be returned.
|
---|
58 | * @param tagType the tag to find a description for
|
---|
59 | * @return a description of the image's value for the specified tag, or
|
---|
60 | * <code>null</code> if the tag hasn't been defined.
|
---|
61 | */
|
---|
62 | @Nullable
|
---|
63 | public String getDescription(int tagType)
|
---|
64 | {
|
---|
65 | switch (tagType) {
|
---|
66 | case ExifThumbnailDirectory.TAG_ORIENTATION:
|
---|
67 | return getOrientationDescription();
|
---|
68 | case ExifThumbnailDirectory.TAG_RESOLUTION_UNIT:
|
---|
69 | return getResolutionDescription();
|
---|
70 | case ExifThumbnailDirectory.TAG_YCBCR_POSITIONING:
|
---|
71 | return getYCbCrPositioningDescription();
|
---|
72 | case ExifThumbnailDirectory.TAG_X_RESOLUTION:
|
---|
73 | return getXResolutionDescription();
|
---|
74 | case ExifThumbnailDirectory.TAG_Y_RESOLUTION:
|
---|
75 | return getYResolutionDescription();
|
---|
76 | case ExifThumbnailDirectory.TAG_THUMBNAIL_OFFSET:
|
---|
77 | return getThumbnailOffsetDescription();
|
---|
78 | case ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH:
|
---|
79 | return getThumbnailLengthDescription();
|
---|
80 | case ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_WIDTH:
|
---|
81 | return getThumbnailImageWidthDescription();
|
---|
82 | case ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT:
|
---|
83 | return getThumbnailImageHeightDescription();
|
---|
84 | case ExifThumbnailDirectory.TAG_BITS_PER_SAMPLE:
|
---|
85 | return getBitsPerSampleDescription();
|
---|
86 | case ExifThumbnailDirectory.TAG_THUMBNAIL_COMPRESSION:
|
---|
87 | return getCompressionDescription();
|
---|
88 | case ExifThumbnailDirectory.TAG_PHOTOMETRIC_INTERPRETATION:
|
---|
89 | return getPhotometricInterpretationDescription();
|
---|
90 | case ExifThumbnailDirectory.TAG_ROWS_PER_STRIP:
|
---|
91 | return getRowsPerStripDescription();
|
---|
92 | case ExifThumbnailDirectory.TAG_STRIP_BYTE_COUNTS:
|
---|
93 | return getStripByteCountsDescription();
|
---|
94 | case ExifThumbnailDirectory.TAG_SAMPLES_PER_PIXEL:
|
---|
95 | return getSamplesPerPixelDescription();
|
---|
96 | case ExifThumbnailDirectory.TAG_PLANAR_CONFIGURATION:
|
---|
97 | return getPlanarConfigurationDescription();
|
---|
98 | case ExifThumbnailDirectory.TAG_YCBCR_SUBSAMPLING:
|
---|
99 | return getYCbCrSubsamplingDescription();
|
---|
100 | case ExifThumbnailDirectory.TAG_REFERENCE_BLACK_WHITE:
|
---|
101 | return getReferenceBlackWhiteDescription();
|
---|
102 | default:
|
---|
103 | return super.getDescription(tagType);
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | @Nullable
|
---|
108 | public String getReferenceBlackWhiteDescription()
|
---|
109 | {
|
---|
110 | int[] ints = _directory.getIntArray(ExifThumbnailDirectory.TAG_REFERENCE_BLACK_WHITE);
|
---|
111 | if (ints==null)
|
---|
112 | return null;
|
---|
113 | int blackR = ints[0];
|
---|
114 | int whiteR = ints[1];
|
---|
115 | int blackG = ints[2];
|
---|
116 | int whiteG = ints[3];
|
---|
117 | int blackB = ints[4];
|
---|
118 | int whiteB = ints[5];
|
---|
119 | return "[" + blackR + "," + blackG + "," + blackB + "] " +
|
---|
120 | "[" + whiteR + "," + whiteG + "," + whiteB + "]";
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Nullable
|
---|
124 | public String getYCbCrSubsamplingDescription()
|
---|
125 | {
|
---|
126 | int[] positions = _directory.getIntArray(ExifThumbnailDirectory.TAG_YCBCR_SUBSAMPLING);
|
---|
127 | if (positions==null || positions.length < 2)
|
---|
128 | return null;
|
---|
129 | if (positions[0] == 2 && positions[1] == 1) {
|
---|
130 | return "YCbCr4:2:2";
|
---|
131 | } else if (positions[0] == 2 && positions[1] == 2) {
|
---|
132 | return "YCbCr4:2:0";
|
---|
133 | } else {
|
---|
134 | return "(Unknown)";
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | @Nullable
|
---|
139 | public String getPlanarConfigurationDescription()
|
---|
140 | {
|
---|
141 | // When image format is no compression YCbCr, this value shows byte aligns of YCbCr
|
---|
142 | // data. If value is '1', Y/Cb/Cr value is chunky format, contiguous for each subsampling
|
---|
143 | // pixel. If value is '2', Y/Cb/Cr value is separated and stored to Y plane/Cb plane/Cr
|
---|
144 | // plane format.
|
---|
145 | Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_PLANAR_CONFIGURATION);
|
---|
146 | if (value==null)
|
---|
147 | return null;
|
---|
148 | switch (value) {
|
---|
149 | case 1: return "Chunky (contiguous for each subsampling pixel)";
|
---|
150 | case 2: return "Separate (Y-plane/Cb-plane/Cr-plane format)";
|
---|
151 | default:
|
---|
152 | return "Unknown configuration";
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Nullable
|
---|
157 | public String getSamplesPerPixelDescription()
|
---|
158 | {
|
---|
159 | String value = _directory.getString(ExifThumbnailDirectory.TAG_SAMPLES_PER_PIXEL);
|
---|
160 | return value==null ? null : value + " samples/pixel";
|
---|
161 | }
|
---|
162 |
|
---|
163 | @Nullable
|
---|
164 | public String getRowsPerStripDescription()
|
---|
165 | {
|
---|
166 | final String value = _directory.getString(ExifThumbnailDirectory.TAG_ROWS_PER_STRIP);
|
---|
167 | return value==null ? null : value + " rows/strip";
|
---|
168 | }
|
---|
169 |
|
---|
170 | @Nullable
|
---|
171 | public String getStripByteCountsDescription()
|
---|
172 | {
|
---|
173 | final String value = _directory.getString(ExifThumbnailDirectory.TAG_STRIP_BYTE_COUNTS);
|
---|
174 | return value==null ? null : value + " bytes";
|
---|
175 | }
|
---|
176 |
|
---|
177 | @Nullable
|
---|
178 | public String getPhotometricInterpretationDescription()
|
---|
179 | {
|
---|
180 | // Shows the color space of the image data components
|
---|
181 | Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_PHOTOMETRIC_INTERPRETATION);
|
---|
182 | if (value==null)
|
---|
183 | return null;
|
---|
184 | switch (value) {
|
---|
185 | case 0: return "WhiteIsZero";
|
---|
186 | case 1: return "BlackIsZero";
|
---|
187 | case 2: return "RGB";
|
---|
188 | case 3: return "RGB Palette";
|
---|
189 | case 4: return "Transparency Mask";
|
---|
190 | case 5: return "CMYK";
|
---|
191 | case 6: return "YCbCr";
|
---|
192 | case 8: return "CIELab";
|
---|
193 | case 9: return "ICCLab";
|
---|
194 | case 10: return "ITULab";
|
---|
195 | case 32803: return "Color Filter Array";
|
---|
196 | case 32844: return "Pixar LogL";
|
---|
197 | case 32845: return "Pixar LogLuv";
|
---|
198 | case 32892: return "Linear Raw";
|
---|
199 | default:
|
---|
200 | return "Unknown colour space";
|
---|
201 | }
|
---|
202 | }
|
---|
203 |
|
---|
204 | @Nullable
|
---|
205 | public String getCompressionDescription()
|
---|
206 | {
|
---|
207 | Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_THUMBNAIL_COMPRESSION);
|
---|
208 | if (value==null)
|
---|
209 | return null;
|
---|
210 | switch (value) {
|
---|
211 | case 1: return "Uncompressed";
|
---|
212 | case 2: return "CCITT 1D";
|
---|
213 | case 3: return "T4/Group 3 Fax";
|
---|
214 | case 4: return "T6/Group 4 Fax";
|
---|
215 | case 5: return "LZW";
|
---|
216 | case 6: return "JPEG (old-style)";
|
---|
217 | case 7: return "JPEG";
|
---|
218 | case 8: return "Adobe Deflate";
|
---|
219 | case 9: return "JBIG B&W";
|
---|
220 | case 10: return "JBIG Color";
|
---|
221 | case 32766: return "Next";
|
---|
222 | case 32771: return "CCIRLEW";
|
---|
223 | case 32773: return "PackBits";
|
---|
224 | case 32809: return "Thunderscan";
|
---|
225 | case 32895: return "IT8CTPAD";
|
---|
226 | case 32896: return "IT8LW";
|
---|
227 | case 32897: return "IT8MP";
|
---|
228 | case 32898: return "IT8BL";
|
---|
229 | case 32908: return "PixarFilm";
|
---|
230 | case 32909: return "PixarLog";
|
---|
231 | case 32946: return "Deflate";
|
---|
232 | case 32947: return "DCS";
|
---|
233 | case 32661: return "JBIG";
|
---|
234 | case 32676: return "SGILog";
|
---|
235 | case 32677: return "SGILog24";
|
---|
236 | case 32712: return "JPEG 2000";
|
---|
237 | case 32713: return "Nikon NEF Compressed";
|
---|
238 | default:
|
---|
239 | return "Unknown compression";
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | @Nullable
|
---|
244 | public String getBitsPerSampleDescription()
|
---|
245 | {
|
---|
246 | String value = _directory.getString(ExifThumbnailDirectory.TAG_BITS_PER_SAMPLE);
|
---|
247 | return value==null ? null : value + " bits/component/pixel";
|
---|
248 | }
|
---|
249 |
|
---|
250 | @Nullable
|
---|
251 | public String getThumbnailImageWidthDescription()
|
---|
252 | {
|
---|
253 | String value = _directory.getString(ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_WIDTH);
|
---|
254 | return value==null ? null : value + " pixels";
|
---|
255 | }
|
---|
256 |
|
---|
257 | @Nullable
|
---|
258 | public String getThumbnailImageHeightDescription()
|
---|
259 | {
|
---|
260 | String value = _directory.getString(ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT);
|
---|
261 | return value==null ? null : value + " pixels";
|
---|
262 | }
|
---|
263 |
|
---|
264 | @Nullable
|
---|
265 | public String getThumbnailLengthDescription()
|
---|
266 | {
|
---|
267 | String value = _directory.getString(ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH);
|
---|
268 | return value==null ? null : value + " bytes";
|
---|
269 | }
|
---|
270 |
|
---|
271 | @Nullable
|
---|
272 | public String getThumbnailOffsetDescription()
|
---|
273 | {
|
---|
274 | String value = _directory.getString(ExifThumbnailDirectory.TAG_THUMBNAIL_OFFSET);
|
---|
275 | return value==null ? null : value + " bytes";
|
---|
276 | }
|
---|
277 |
|
---|
278 | @Nullable
|
---|
279 | public String getYResolutionDescription()
|
---|
280 | {
|
---|
281 | Rational value = _directory.getRational(ExifThumbnailDirectory.TAG_Y_RESOLUTION);
|
---|
282 | if (value==null)
|
---|
283 | return null;
|
---|
284 | final String unit = getResolutionDescription();
|
---|
285 | return value.toSimpleString(_allowDecimalRepresentationOfRationals) +
|
---|
286 | " dots per " +
|
---|
287 | (unit==null ? "unit" : unit.toLowerCase());
|
---|
288 | }
|
---|
289 |
|
---|
290 | @Nullable
|
---|
291 | public String getXResolutionDescription()
|
---|
292 | {
|
---|
293 | Rational value = _directory.getRational(ExifThumbnailDirectory.TAG_X_RESOLUTION);
|
---|
294 | if (value==null)
|
---|
295 | return null;
|
---|
296 | final String unit = getResolutionDescription();
|
---|
297 | return value.toSimpleString(_allowDecimalRepresentationOfRationals) +
|
---|
298 | " dots per " +
|
---|
299 | (unit==null ? "unit" : unit.toLowerCase());
|
---|
300 | }
|
---|
301 |
|
---|
302 | @Nullable
|
---|
303 | public String getYCbCrPositioningDescription()
|
---|
304 | {
|
---|
305 | Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_YCBCR_POSITIONING);
|
---|
306 | if (value==null)
|
---|
307 | return null;
|
---|
308 | switch (value) {
|
---|
309 | case 1: return "Center of pixel array";
|
---|
310 | case 2: return "Datum point";
|
---|
311 | default:
|
---|
312 | return String.valueOf(value);
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | @Nullable
|
---|
317 | public String getOrientationDescription()
|
---|
318 | {
|
---|
319 | Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_ORIENTATION);
|
---|
320 | if (value==null)
|
---|
321 | return null;
|
---|
322 | switch (value) {
|
---|
323 | case 1: return "Top, left side (Horizontal / normal)";
|
---|
324 | case 2: return "Top, right side (Mirror horizontal)";
|
---|
325 | case 3: return "Bottom, right side (Rotate 180)";
|
---|
326 | case 4: return "Bottom, left side (Mirror vertical)";
|
---|
327 | case 5: return "Left side, top (Mirror horizontal and rotate 270 CW)";
|
---|
328 | case 6: return "Right side, top (Rotate 90 CW)";
|
---|
329 | case 7: return "Right side, bottom (Mirror horizontal and rotate 90 CW)";
|
---|
330 | case 8: return "Left side, bottom (Rotate 270 CW)";
|
---|
331 | default:
|
---|
332 | return String.valueOf(value);
|
---|
333 | }
|
---|
334 | }
|
---|
335 |
|
---|
336 | @Nullable
|
---|
337 | public String getResolutionDescription()
|
---|
338 | {
|
---|
339 | // '1' means no-unit, '2' means inch, '3' means centimeter. Default value is '2'(inch)
|
---|
340 | Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_RESOLUTION_UNIT);
|
---|
341 | if (value==null)
|
---|
342 | return null;
|
---|
343 | switch (value) {
|
---|
344 | case 1: return "(No unit)";
|
---|
345 | case 2: return "Inch";
|
---|
346 | case 3: return "cm";
|
---|
347 | default:
|
---|
348 | return "";
|
---|
349 | }
|
---|
350 | }
|
---|
351 | }
|
---|