source: josm/trunk/src/com/drew/metadata/exif/NikonType2MakernoteDirectory.java@ 4258

Last change on this file since 4258 was 4258, checked in by stoecker, 13 years ago

fix #6597 - update NikonType2MakernoteDirectory.java to revision r16 - fixing wrong encoding

File size: 17.3 KB
Line 
1/*
2 * This is public domain software - that is, you can do whatever you want
3 * with it, and include it software that is licensed under the GNU or the
4 * BSD license, or whatever other licence you choose, including proprietary
5 * closed source licenses. I do ask that you leave this header in tact.
6 *
7 * If you make modifications to this code that you think would benefit the
8 * wider community, please send me a copy and I'll post it on my site.
9 *
10 * If you make use of this code, I'd appreciate hearing about it.
11 * metadata_extractor [at] drewnoakes [dot] com
12 * Latest version of this software kept at
13 * http://drewnoakes.com/
14 *
15 * Created by dnoakes on 3-Oct-2002 10:10:47 using IntelliJ IDEA.
16 */
17package com.drew.metadata.exif;
18
19import com.drew.lang.Rational;
20import com.drew.metadata.Directory;
21import com.drew.metadata.MetadataException;
22
23import java.util.HashMap;
24
25/**
26 * Describes tags specific to Nikon (type 2) cameras. Type-2 applies to the E990 and D-series cameras such as the E990, D1,
27 * D70 and D100.
28 *
29 * Thanks to Fabrizio Giudici for publishing his reverse-engineering of the D100 makernote data.
30 * http://www.timelesswanderings.net/equipment/D100/NEF.html
31 *
32 * Note that the camera implements image protection (locking images) via the file's 'readonly' attribute. Similarly
33 * image hiding uses the 'hidden' attribute (observed on the D70). Consequently, these values are not available here.
34 *
35 * Additional sample images have been observed, and their tag values recorded in javadoc comments for each tag's field.
36 * New tags have subsequently been added since Fabrizio's observations.
37 *
38 * In earlier models (such as the E990 and D1), this directory begins at the first byte of the makernote IFD. In
39 * later models, the IFD was given the standard prefix to indicate the camera models (most other manufacturers also
40 * provide this prefix to aid in software decoding).
41 */
42public class NikonType2MakernoteDirectory extends Directory
43{
44 /**
45 * Values observed
46 * - 0200 (D70)
47 * - 0200 (D1X)
48 */
49 public static final int TAG_NIKON_TYPE2_FIRMWARE_VERSION = 0x0001;
50
51 /**
52 * Values observed
53 * - 0 250
54 * - 0 400
55 */
56 public static final int TAG_NIKON_TYPE2_ISO_1 = 0x0002;
57
58 /**
59 * Values observed
60 * - COLOR (seen in the D1X)
61 */
62 public static final int TAG_NIKON_TYPE2_COLOR_MODE = 0x0003;
63
64 /**
65 * Values observed
66 * - FILE
67 * - RAW
68 * - NORMAL
69 * - FINE
70 */
71 public static final int TAG_NIKON_TYPE2_QUALITY_AND_FILE_FORMAT = 0x0004;
72
73 /**
74 * The white balance as set in the camera.
75 *
76 * Values observed
77 * - AUTO
78 * - SUNNY (D70)
79 * - FLASH (D1X)
80 * (presumably also SHADOW / INCANDESCENT / FLUORESCENT / CLOUDY)
81 */
82 public static final int TAG_NIKON_TYPE2_CAMERA_WHITE_BALANCE = 0x0005;
83
84 /**
85 * The sharpening as set in the camera.
86 *
87 * Values observed
88 * - AUTO
89 * - NORMAL (D70)
90 * - NONE (D1X)
91 */
92 public static final int TAG_NIKON_TYPE2_CAMERA_SHARPENING = 0x0006;
93
94 /**
95 * The auto-focus type used by the camera.
96 *
97 * Values observed
98 * - AF-S
99 * - AF-C
100 * - MANUAL
101 */
102 public static final int TAG_NIKON_TYPE2_AF_TYPE = 0x0007;
103
104 /**
105 * Values observed
106 * - NORMAL
107 * - RED-EYE
108 *
109 * Note: when TAG_NIKON_TYPE2_AUTO_FLASH_MODE is blank, Nikon Browser displays "Flash Sync Mode: Not Attached"
110 */
111 public static final int TAG_NIKON_TYPE2_FLASH_SYNC_MODE = 0x0008;
112
113 /**
114 * Values observed
115 * - Built-in,TTL
116 * - Optional,TTL (with speedlight SB800, flash sync mode as NORMAL. NikonBrowser reports Auto Flash Comp: 0 EV -- which tag is that?) (D70)
117 * - NEW_TTL (Nikon Browser interprets as "D-TTL")
118 * - (blank -- accompanied FlashSyncMode of NORMAL) (D70)
119 */
120 public static final int TAG_NIKON_TYPE2_AUTO_FLASH_MODE = 0x0009;
121
122 /**
123 * Added during merge of Type2 & Type3. May apply to earlier models, such as E990 and D1.
124 */
125 public static final int TAG_NIKON_TYPE2_UNKNOWN_34 = 0x000A;
126
127 /**
128 * Values observed
129 * - 0
130 */
131 public static final int TAG_NIKON_TYPE2_CAMERA_WHITE_BALANCE_FINE = 0x000B;
132
133 /**
134 * The first two numbers are coefficients to multiply red and blue channels according to white balance as set in the
135 * camera. The meaning of the third and the fourth numbers is unknown.
136 *
137 * Values observed
138 * - 2.25882352 1.76078431 0.0 0.0
139 * - 10242/1 34305/1 0/1 0/1
140 * - 234765625/100000000 1140625/1000000 1/1 1/1
141 */
142 public static final int TAG_NIKON_TYPE2_CAMERA_WHITE_BALANCE_RB_COEFF = 0x000C;
143
144 /**
145 * Values observed
146 * - 0,1,6,0 (hex)
147 */
148 public static final int TAG_NIKON_TYPE2_UNKNOWN_1 = 0x000D;
149
150 /**
151 * Values observed
152 * - 0,1,c,0 (hex)
153 */
154 public static final int TAG_NIKON_TYPE2_UNKNOWN_2 = 0x000E;
155
156 /**
157 * Added during merge of Type2 & Type3. May apply to earlier models, such as E990 and D1.
158 */
159 public static final int TAG_NIKON_TYPE2_ISO_SELECTION = 0x000F;
160
161 /**
162 * Added during merge of Type2 & Type3. May apply to earlier models, such as E990 and D1.
163 */
164 public static final int TAG_NIKON_TYPE2_DATA_DUMP = 0x0010;
165
166 /**
167 * Values observed
168 * - 914
169 * - 1379 (D70)
170 * - 2781 (D1X)
171 * - 6942 (D100)
172 */
173 public static final int TAG_NIKON_TYPE2_UNKNOWN_3 = 0x0011;
174
175 /**
176 * Values observed
177 * - (no value -- blank)
178 */
179 public static final int TAG_NIKON_TYPE2_AUTO_FLASH_COMPENSATION = 0x0012;
180
181 /**
182 * Values observed
183 * - 0 250
184 * - 0 400
185 */
186 public static final int TAG_NIKON_TYPE2_ISO_2 = 0x0013;
187
188 /**
189 * Values observed
190 * - 0 0 49163 53255
191 * - 0 0 3008 2000 (the image dimensions were 3008x2000) (D70)
192 */
193 public static final int TAG_NIKON_TYPE2_UNKNOWN_21 = 0x0016;
194
195 /**
196 * Values observed
197 * - (blank)
198 */
199 public static final int TAG_NIKON_TYPE2_UNKNOWN_22 = 0x0017;
200
201 /**
202 * Values observed
203 * - (blank)
204 */
205 public static final int TAG_NIKON_TYPE2_UNKNOWN_23 = 0x0018;
206
207 /**
208 * Values observed
209 * - 0
210 */
211 public static final int TAG_NIKON_TYPE2_UNKNOWN_24 = 0x0019;
212
213 /**
214 * Added during merge of Type2 & Type3. May apply to earlier models, such as E990 and D1.
215 */
216 public static final int TAG_NIKON_TYPE2_IMAGE_ADJUSTMENT = 0x0080;
217
218 /**
219 * The tone compensation as set in the camera.
220 *
221 * Values observed
222 * - AUTO
223 * - NORMAL (D1X, D100)
224 */
225 public static final int TAG_NIKON_TYPE2_CAMERA_TONE_COMPENSATION = 0x0081;
226
227 /**
228 * Added during merge of Type2 & Type3. May apply to earlier models, such as E990 and D1.
229 */
230 public static final int TAG_NIKON_TYPE2_ADAPTER = 0x0082;
231
232 /**
233 * Values observed
234 * - 6
235 * - 6 (D70)
236 * - 2 (D1X)
237 */
238 public static final int TAG_NIKON_TYPE2_UNKNOWN_4 = 0x0083;
239
240 /**
241 * A pair of focal/max-fstop values that describe the lens used.
242 *
243 * Values observed
244 * - 180.0,180.0,2.8,2.8 (D100)
245 * - 240/10 850/10 35/10 45/10
246 * - 18-70mm f/3.5-4.5 (D70)
247 * - 17-35mm f/2.8-2.8 (D1X)
248 * - 70-200mm f/2.8-2.8 (D70)
249 *
250 * Nikon Browser identifies the lens as "18-70mm F/3.5-4.5 G" which
251 * is identical to metadata extractor, except for the "G". This must
252 * be coming from another tag...
253 */
254 public static final int TAG_NIKON_TYPE2_LENS = 0x0084;
255
256 /**
257 * Added during merge of Type2 & Type3. May apply to earlier models, such as E990 and D1.
258 */
259 public static final int TAG_NIKON_TYPE2_MANUAL_FOCUS_DISTANCE = 0x0085;
260
261 /**
262 * Added during merge of Type2 & Type3. May apply to earlier models, such as E990 and D1.
263 */
264 public static final int TAG_NIKON_TYPE2_DIGITAL_ZOOM = 0x0086;
265
266 /**
267 * Values observed
268 * - 0
269 * - 9
270 * - 3 (D1X)
271 */
272 public static final int TAG_NIKON_TYPE2_UNKNOWN_5 = 0x0087;
273
274 /**
275 * Values observed
276 * -
277 */
278 public static final int TAG_NIKON_TYPE2_AF_FOCUS_POSITION = 0x0088;
279
280 /**
281 * Values observed
282 * - 0
283 * - 1
284 */
285 public static final int TAG_NIKON_TYPE2_UNKNOWN_7 = 0x0089;
286
287 /**
288 * Values observed
289 * - 0
290 * - 0
291 */
292 public static final int TAG_NIKON_TYPE2_UNKNOWN_20 = 0x008A;
293
294 /**
295 * Values observed
296 * - 48,1,c,0 (hex) (D100)
297 * - @ <hex>
298 */
299 public static final int TAG_NIKON_TYPE2_UNKNOWN_8 = 0x008B;
300
301 /**
302 * Unknown. Fabrizio believes this may be a lookup table for the user-defined curve.
303 *
304 * Values observed
305 * - (blank) (D1X)
306 */
307 public static final int TAG_NIKON_TYPE2_UNKNOWN_9 = 0x008C;
308
309 /**
310 * The color space as set in the camera.
311 *
312 * Values observed
313 * - MODE1
314 * - Mode I (sRGB) (D70)
315 * - MODE2 (D1X, D100)
316 */
317 public static final int TAG_NIKON_TYPE2_CAMERA_COLOR_MODE = 0x008D;
318
319 /**
320 * Values observed
321 * - NATURAL
322 * - SPEEDLIGHT (D70, D1X)
323 */
324 public static final int TAG_NIKON_TYPE2_LIGHT_SOURCE = 0x0090;
325
326 /**
327 * Values observed
328 * - 0100 <hex>
329 * - 0103 (D70)
330 * - 0100 (D1X)
331 */
332 public static final int TAG_NIKON_TYPE2_UNKNOWN_11 = 0x0091;
333
334 /**
335 * The hue adjustment as set in the camera.
336 *
337 * Values observed
338 * - 0
339 */
340 public static final int TAG_NIKON_TYPE2_CAMERA_HUE_ADJUSTMENT = 0x0092;
341
342 /**
343 * Values observed
344 * - OFF
345 */
346 public static final int TAG_NIKON_TYPE2_NOISE_REDUCTION = 0x0095;
347
348 /**
349 * Values observed
350 * - 0100 <hex>
351 * - 0103 <hex>
352 */
353 public static final int TAG_NIKON_TYPE2_UNKNOWN_12 = 0x0097;
354
355 /**
356 * Values observed
357 * - 0100 <hex>
358 * - 0101 <hex>
359 * - 0100 <hex> (D1X)
360 * - 30,31,30,30,0,0,b,48,7c,7c,24,24,5,15,24,0,0,0,0,0 (hex) (D100)
361 */
362 public static final int TAG_NIKON_TYPE2_UNKNOWN_13 = 0x0098;
363
364 /**
365 * Values observed
366 * - 2014 662 (D1X)
367 * - 1517,1012 (D100)
368 */
369 public static final int TAG_NIKON_TYPE2_UNKNOWN_14 = 0x0099;
370
371 /**
372 * Values observed
373 * - 78/10 78/10
374 * - 78/10 78/10 (D70)
375 * - 59/10 59/5 (D1X)
376 * - 7.8,7.8 (D100)
377 */
378 public static final int TAG_NIKON_TYPE2_UNKNOWN_15 = 0x009A;
379
380 /**
381 * Values observed
382 * - NO= 00002539
383 */
384 public static final int TAG_NIKON_TYPE2_UNKNOWN_25 = 0x00A0;
385
386 /**
387 * Values observed
388 * - 1564851
389 */
390 public static final int TAG_NIKON_TYPE2_UNKNOWN_26 = 0x00A2;
391
392 /**
393 * Values observed
394 * - 0
395 */
396 public static final int TAG_NIKON_TYPE2_UNKNOWN_27 = 0x00A3;
397
398 /**
399 * This appears to be a sequence number to indentify the exposure. This value seems to increment
400 * for consecutive exposures (observed on D70).
401 *
402 * Values observed
403 * - 5062
404 */
405 public static final int TAG_NIKON_TYPE2_EXPOSURE_SEQUENCE_NUMBER = 0x00A7;
406
407 /**
408 * Values observed
409 * - 0100 (D70)
410 */
411 public static final int TAG_NIKON_TYPE2_UNKNOWN_32 = 0x00A8;
412
413 /**
414 * Values observed
415 * - NORMAL (D70)
416 */
417 public static final int TAG_NIKON_TYPE2_UNKNOWN_33 = 0x00A9;
418
419 /**
420 * Nikon Browser suggests this value represents Saturation...
421 * Values observed
422 * - NORMAL (D70)
423 */
424 public static final int TAG_NIKON_TYPE2_UNKNOWN_29 = 0x00AA;
425
426 /**
427 * Values observed
428 * - AUTO (D70)
429 * - (blank) (D70)
430 */
431 public static final int TAG_NIKON_TYPE2_UNKNOWN_30 = 0x00AB;
432
433 /**
434 * Data about changes set by Nikon Capture Editor.
435 *
436 * Values observed
437 */
438 public static final int TAG_NIKON_TYPE2_CAPTURE_EDITOR_DATA = 0x0E01;
439
440 /**
441 * Values observed
442 * - 1473
443 * - 7036 (D100)
444 */
445 public static final int TAG_NIKON_TYPE2_UNKNOWN_16 = 0x0E10;
446
447 protected static final HashMap _tagNameMap = new HashMap();
448
449 static
450 {
451 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_FIRMWARE_VERSION), "Firmware Version");
452 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_ISO_1), "ISO");
453 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_QUALITY_AND_FILE_FORMAT), "Quality & File Format");
454 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_CAMERA_WHITE_BALANCE), "White Balance");
455 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_CAMERA_SHARPENING), "Sharpening");
456 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_AF_TYPE), "AF Type");
457 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_CAMERA_WHITE_BALANCE_FINE), "White Balance Fine");
458 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_CAMERA_WHITE_BALANCE_RB_COEFF), "White Balance RB Coefficients");
459 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_ISO_2), "ISO");
460 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_ISO_SELECTION), "ISO Selection");
461 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_DATA_DUMP), "Data Dump");
462 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_IMAGE_ADJUSTMENT), "Image Adjustment");
463 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_CAMERA_TONE_COMPENSATION), "Tone Compensation");
464 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_ADAPTER), "Adapter");
465 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_LENS), "Lens");
466 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_MANUAL_FOCUS_DISTANCE), "Manual Focus Distance");
467 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_DIGITAL_ZOOM), "Digital Zoom");
468 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_CAMERA_COLOR_MODE), "Colour Mode");
469 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_CAMERA_HUE_ADJUSTMENT), "Camera Hue Adjustment");
470 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_NOISE_REDUCTION), "Noise Reduction");
471 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_CAPTURE_EDITOR_DATA), "Capture Editor Data");
472
473 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_1), "Unknown 01");
474 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_2), "Unknown 02");
475 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_3), "Unknown 03");
476 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_4), "Unknown 04");
477 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_5), "Unknown 05");
478 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_AF_FOCUS_POSITION), "AF Focus Position");
479 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_7), "Unknown 07");
480 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_8), "Unknown 08");
481 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_9), "Unknown 09");
482 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_LIGHT_SOURCE), "Light source");
483 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_11), "Unknown 11");
484 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_12), "Unknown 12");
485 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_13), "Unknown 13");
486 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_14), "Unknown 14");
487 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_15), "Unknown 15");
488 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_16), "Unknown 16");
489 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_FLASH_SYNC_MODE), "Flash Sync Mode");
490 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_AUTO_FLASH_MODE), "Auto Flash Mode");
491 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_AUTO_FLASH_COMPENSATION), "Auto Flash Compensation");
492 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_EXPOSURE_SEQUENCE_NUMBER), "Exposure Sequence Number");
493 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_COLOR_MODE), "Color Mode");
494
495 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_20), "Unknown 20");
496 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_21), "Unknown 21");
497 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_22), "Unknown 22");
498 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_23), "Unknown 23");
499 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_24), "Unknown 24");
500 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_25), "Unknown 25");
501 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_26), "Unknown 26");
502 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_27), "Unknown 27");
503 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_29), "Unknown 29");
504 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_30), "Unknown 30");
505 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_32), "Unknown 32");
506 _tagNameMap.put(new Integer(TAG_NIKON_TYPE2_UNKNOWN_33), "Unknown 33");
507 }
508
509 public NikonType2MakernoteDirectory()
510 {
511 this.setDescriptor(new NikonType2MakernoteDescriptor(this));
512 }
513
514 public Rational getAutoFlashCompensation() throws MetadataException
515 {
516 if (!containsTag(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_AUTO_FLASH_COMPENSATION))
517 return null;
518
519 byte[] bytes = getByteArray(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_AUTO_FLASH_COMPENSATION);
520 return CalculateFlashCompensationFromBytes(bytes);
521 }
522
523 public static Rational CalculateFlashCompensationFromBytes(byte[] bytes)
524 {
525 if (bytes.length==3)
526 {
527 byte denominator = bytes[2];
528 int numerator = (int)bytes[0] * bytes[1];
529 return new Rational(numerator, denominator);
530 }
531 return null;
532 }
533
534 public String getName()
535 {
536 return "Nikon Makernote";
537 }
538
539 protected HashMap getTagNameMap()
540 {
541 return _tagNameMap;
542 }
543}
Note: See TracBrowser for help on using the repository browser.