1 | /*
|
---|
2 | * Copyright 2002-2016 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 | */
|
---|
21 | package com.drew.metadata.exif.makernotes;
|
---|
22 |
|
---|
23 | import com.drew.lang.Rational;
|
---|
24 | import com.drew.lang.annotations.NotNull;
|
---|
25 | import com.drew.lang.annotations.Nullable;
|
---|
26 | import com.drew.metadata.TagDescriptor;
|
---|
27 |
|
---|
28 | import java.text.DecimalFormat;
|
---|
29 |
|
---|
30 | import static com.drew.metadata.exif.makernotes.NikonType2MakernoteDirectory.*;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Provides human-readable string representations of tag values stored in a {@link NikonType2MakernoteDirectory}.
|
---|
34 | *
|
---|
35 | * Type-2 applies to the E990 and D-series cameras such as the D1, D70 and D100.
|
---|
36 | *
|
---|
37 | * @author Drew Noakes https://drewnoakes.com
|
---|
38 | */
|
---|
39 | public class NikonType2MakernoteDescriptor extends TagDescriptor<NikonType2MakernoteDirectory>
|
---|
40 | {
|
---|
41 | public NikonType2MakernoteDescriptor(@NotNull NikonType2MakernoteDirectory directory)
|
---|
42 | {
|
---|
43 | super(directory);
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | @Nullable
|
---|
48 | public String getDescription(int tagType)
|
---|
49 | {
|
---|
50 | switch (tagType)
|
---|
51 | {
|
---|
52 | case TAG_PROGRAM_SHIFT:
|
---|
53 | return getProgramShiftDescription();
|
---|
54 | case TAG_EXPOSURE_DIFFERENCE:
|
---|
55 | return getExposureDifferenceDescription();
|
---|
56 | case TAG_LENS:
|
---|
57 | return getLensDescription();
|
---|
58 | case TAG_CAMERA_HUE_ADJUSTMENT:
|
---|
59 | return getHueAdjustmentDescription();
|
---|
60 | case TAG_CAMERA_COLOR_MODE:
|
---|
61 | return getColorModeDescription();
|
---|
62 | case TAG_AUTO_FLASH_COMPENSATION:
|
---|
63 | return getAutoFlashCompensationDescription();
|
---|
64 | case TAG_FLASH_EXPOSURE_COMPENSATION:
|
---|
65 | return getFlashExposureCompensationDescription();
|
---|
66 | case TAG_FLASH_BRACKET_COMPENSATION:
|
---|
67 | return getFlashBracketCompensationDescription();
|
---|
68 | case TAG_EXPOSURE_TUNING:
|
---|
69 | return getExposureTuningDescription();
|
---|
70 | case TAG_LENS_STOPS:
|
---|
71 | return getLensStopsDescription();
|
---|
72 | case TAG_COLOR_SPACE:
|
---|
73 | return getColorSpaceDescription();
|
---|
74 | case TAG_ACTIVE_D_LIGHTING:
|
---|
75 | return getActiveDLightingDescription();
|
---|
76 | case TAG_VIGNETTE_CONTROL:
|
---|
77 | return getVignetteControlDescription();
|
---|
78 | case TAG_ISO_1:
|
---|
79 | return getIsoSettingDescription();
|
---|
80 | case TAG_DIGITAL_ZOOM:
|
---|
81 | return getDigitalZoomDescription();
|
---|
82 | case TAG_FLASH_USED:
|
---|
83 | return getFlashUsedDescription();
|
---|
84 | case TAG_AF_FOCUS_POSITION:
|
---|
85 | return getAutoFocusPositionDescription();
|
---|
86 | case TAG_FIRMWARE_VERSION:
|
---|
87 | return getFirmwareVersionDescription();
|
---|
88 | case TAG_LENS_TYPE:
|
---|
89 | return getLensTypeDescription();
|
---|
90 | case TAG_SHOOTING_MODE:
|
---|
91 | return getShootingModeDescription();
|
---|
92 | case TAG_NEF_COMPRESSION:
|
---|
93 | return getNEFCompressionDescription();
|
---|
94 | case TAG_HIGH_ISO_NOISE_REDUCTION:
|
---|
95 | return getHighISONoiseReductionDescription();
|
---|
96 | case TAG_POWER_UP_TIME:
|
---|
97 | return getPowerUpTimeDescription();
|
---|
98 | default:
|
---|
99 | return super.getDescription(tagType);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | @Nullable
|
---|
104 | public String getPowerUpTimeDescription()
|
---|
105 | {
|
---|
106 | return getEpochTimeDescription(TAG_POWER_UP_TIME);
|
---|
107 | }
|
---|
108 |
|
---|
109 | @Nullable
|
---|
110 | public String getHighISONoiseReductionDescription()
|
---|
111 | {
|
---|
112 | return getIndexedDescription(TAG_HIGH_ISO_NOISE_REDUCTION,
|
---|
113 | "Off",
|
---|
114 | "Minimal",
|
---|
115 | "Low",
|
---|
116 | null,
|
---|
117 | "Normal",
|
---|
118 | null,
|
---|
119 | "High"
|
---|
120 | );
|
---|
121 | }
|
---|
122 |
|
---|
123 | @Nullable
|
---|
124 | public String getFlashUsedDescription()
|
---|
125 | {
|
---|
126 | return getIndexedDescription(TAG_FLASH_USED,
|
---|
127 | "Flash Not Used",
|
---|
128 | "Manual Flash",
|
---|
129 | null,
|
---|
130 | "Flash Not Ready",
|
---|
131 | null,
|
---|
132 | null,
|
---|
133 | null,
|
---|
134 | "External Flash",
|
---|
135 | "Fired, Commander Mode",
|
---|
136 | "Fired, TTL Mode"
|
---|
137 | );
|
---|
138 | }
|
---|
139 |
|
---|
140 | @Nullable
|
---|
141 | public String getNEFCompressionDescription()
|
---|
142 | {
|
---|
143 | return getIndexedDescription(TAG_NEF_COMPRESSION,
|
---|
144 | 1,
|
---|
145 | "Lossy (Type 1)",
|
---|
146 | null,
|
---|
147 | "Uncompressed",
|
---|
148 | null,
|
---|
149 | null,
|
---|
150 | null,
|
---|
151 | "Lossless",
|
---|
152 | "Lossy (Type 2)"
|
---|
153 | );
|
---|
154 | }
|
---|
155 |
|
---|
156 | @Nullable
|
---|
157 | public String getShootingModeDescription()
|
---|
158 | {
|
---|
159 | return getBitFlagDescription(TAG_SHOOTING_MODE,
|
---|
160 | // LSB [low label, high label]
|
---|
161 | new String[]{"Single Frame", "Continuous"},
|
---|
162 | "Delay",
|
---|
163 | null,
|
---|
164 | "PC Control",
|
---|
165 | "Exposure Bracketing",
|
---|
166 | "Auto ISO",
|
---|
167 | "White-Balance Bracketing",
|
---|
168 | "IR Control"
|
---|
169 | );
|
---|
170 | }
|
---|
171 |
|
---|
172 | @Nullable
|
---|
173 | public String getLensTypeDescription()
|
---|
174 | {
|
---|
175 | return getBitFlagDescription(TAG_LENS_TYPE,
|
---|
176 | // LSB [low label, high label]
|
---|
177 | new String[]{"AF", "MF"},
|
---|
178 | "D",
|
---|
179 | "G",
|
---|
180 | "VR"
|
---|
181 | );
|
---|
182 | }
|
---|
183 |
|
---|
184 | @Nullable
|
---|
185 | public String getColorSpaceDescription()
|
---|
186 | {
|
---|
187 | return getIndexedDescription(TAG_COLOR_SPACE,
|
---|
188 | 1,
|
---|
189 | "sRGB",
|
---|
190 | "Adobe RGB"
|
---|
191 | );
|
---|
192 | }
|
---|
193 |
|
---|
194 | @Nullable
|
---|
195 | public String getActiveDLightingDescription()
|
---|
196 | {
|
---|
197 | Integer value = _directory.getInteger(TAG_ACTIVE_D_LIGHTING);
|
---|
198 | if (value==null)
|
---|
199 | return null;
|
---|
200 | switch (value) {
|
---|
201 | case 0: return "Off";
|
---|
202 | case 1: return "Light";
|
---|
203 | case 3: return "Normal";
|
---|
204 | case 5: return "High";
|
---|
205 | case 7: return "Extra High";
|
---|
206 | case 65535: return "Auto";
|
---|
207 | default: return "Unknown (" + value + ")";
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | @Nullable
|
---|
212 | public String getVignetteControlDescription()
|
---|
213 | {
|
---|
214 | Integer value = _directory.getInteger(TAG_VIGNETTE_CONTROL);
|
---|
215 | if (value==null)
|
---|
216 | return null;
|
---|
217 | switch (value) {
|
---|
218 | case 0: return "Off";
|
---|
219 | case 1: return "Low";
|
---|
220 | case 3: return "Normal";
|
---|
221 | case 5: return "High";
|
---|
222 | default: return "Unknown (" + value + ")";
|
---|
223 | }
|
---|
224 | }
|
---|
225 |
|
---|
226 | @Nullable
|
---|
227 | public String getAutoFocusPositionDescription()
|
---|
228 | {
|
---|
229 | int[] values = _directory.getIntArray(TAG_AF_FOCUS_POSITION);
|
---|
230 | if (values==null)
|
---|
231 | return null;
|
---|
232 | if (values.length != 4 || values[0] != 0 || values[2] != 0 || values[3] != 0) {
|
---|
233 | return "Unknown (" + _directory.getString(TAG_AF_FOCUS_POSITION) + ")";
|
---|
234 | }
|
---|
235 | switch (values[1]) {
|
---|
236 | case 0:
|
---|
237 | return "Centre";
|
---|
238 | case 1:
|
---|
239 | return "Top";
|
---|
240 | case 2:
|
---|
241 | return "Bottom";
|
---|
242 | case 3:
|
---|
243 | return "Left";
|
---|
244 | case 4:
|
---|
245 | return "Right";
|
---|
246 | default:
|
---|
247 | return "Unknown (" + values[1] + ")";
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | @Nullable
|
---|
252 | public String getDigitalZoomDescription()
|
---|
253 | {
|
---|
254 | Rational value = _directory.getRational(TAG_DIGITAL_ZOOM);
|
---|
255 | if (value==null)
|
---|
256 | return null;
|
---|
257 | return value.intValue() == 1
|
---|
258 | ? "No digital zoom"
|
---|
259 | : value.toSimpleString(true) + "x digital zoom";
|
---|
260 | }
|
---|
261 |
|
---|
262 | @Nullable
|
---|
263 | public String getProgramShiftDescription()
|
---|
264 | {
|
---|
265 | return getEVDescription(TAG_PROGRAM_SHIFT);
|
---|
266 | }
|
---|
267 |
|
---|
268 | @Nullable
|
---|
269 | public String getExposureDifferenceDescription()
|
---|
270 | {
|
---|
271 | return getEVDescription(TAG_EXPOSURE_DIFFERENCE);
|
---|
272 | }
|
---|
273 |
|
---|
274 | @Nullable
|
---|
275 | public String getAutoFlashCompensationDescription()
|
---|
276 | {
|
---|
277 | return getEVDescription(TAG_AUTO_FLASH_COMPENSATION);
|
---|
278 | }
|
---|
279 |
|
---|
280 | @Nullable
|
---|
281 | public String getFlashExposureCompensationDescription()
|
---|
282 | {
|
---|
283 | return getEVDescription(TAG_FLASH_EXPOSURE_COMPENSATION);
|
---|
284 | }
|
---|
285 |
|
---|
286 | @Nullable
|
---|
287 | public String getFlashBracketCompensationDescription()
|
---|
288 | {
|
---|
289 | return getEVDescription(TAG_FLASH_BRACKET_COMPENSATION);
|
---|
290 | }
|
---|
291 |
|
---|
292 | @Nullable
|
---|
293 | public String getExposureTuningDescription()
|
---|
294 | {
|
---|
295 | return getEVDescription(TAG_EXPOSURE_TUNING);
|
---|
296 | }
|
---|
297 |
|
---|
298 | @Nullable
|
---|
299 | public String getLensStopsDescription()
|
---|
300 | {
|
---|
301 | return getEVDescription(TAG_LENS_STOPS);
|
---|
302 | }
|
---|
303 |
|
---|
304 | @Nullable
|
---|
305 | private String getEVDescription(int tagType)
|
---|
306 | {
|
---|
307 | int[] values = _directory.getIntArray(tagType);
|
---|
308 | if (values == null || values.length < 2)
|
---|
309 | return null;
|
---|
310 | if (values.length < 3 || values[2] == 0)
|
---|
311 | return null;
|
---|
312 | final DecimalFormat decimalFormat = new DecimalFormat("0.##");
|
---|
313 | double ev = values[0] * values[1] / (double)values[2];
|
---|
314 | return decimalFormat.format(ev) + " EV";
|
---|
315 | }
|
---|
316 |
|
---|
317 | @Nullable
|
---|
318 | public String getIsoSettingDescription()
|
---|
319 | {
|
---|
320 | int[] values = _directory.getIntArray(TAG_ISO_1);
|
---|
321 | if (values == null)
|
---|
322 | return null;
|
---|
323 | if (values[0] != 0 || values[1] == 0)
|
---|
324 | return "Unknown (" + _directory.getString(TAG_ISO_1) + ")";
|
---|
325 | return "ISO " + values[1];
|
---|
326 | }
|
---|
327 |
|
---|
328 | @Nullable
|
---|
329 | public String getLensDescription()
|
---|
330 | {
|
---|
331 | return getLensSpecificationDescription(TAG_LENS);
|
---|
332 | }
|
---|
333 |
|
---|
334 | @Nullable
|
---|
335 | public String getHueAdjustmentDescription()
|
---|
336 | {
|
---|
337 | return getFormattedString(TAG_CAMERA_HUE_ADJUSTMENT, "%s degrees");
|
---|
338 | }
|
---|
339 |
|
---|
340 | @Nullable
|
---|
341 | public String getColorModeDescription()
|
---|
342 | {
|
---|
343 | String value = _directory.getString(TAG_CAMERA_COLOR_MODE);
|
---|
344 | return value == null ? null : value.startsWith("MODE1") ? "Mode I (sRGB)" : value;
|
---|
345 | }
|
---|
346 |
|
---|
347 | @Nullable
|
---|
348 | public String getFirmwareVersionDescription()
|
---|
349 | {
|
---|
350 | return getVersionBytesDescription(TAG_FIRMWARE_VERSION, 2);
|
---|
351 | }
|
---|
352 | }
|
---|