source: josm/trunk/src/com/drew/metadata/exif/NikonType2MakernoteDescriptor.java@ 4231

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

add signpost and metadata extractor code to repository directly

File size: 6.6 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 * drew@drewnoakes.com
12 * Latest version of this software kept at
13 * http://drewnoakes.com/
14 */
15package com.drew.metadata.exif;
16
17import com.drew.lang.Rational;
18import com.drew.metadata.Directory;
19import com.drew.metadata.MetadataException;
20import com.drew.metadata.TagDescriptor;
21
22import java.text.DecimalFormat;
23
24/**
25 * Provides human-readable string versions of the tags stored in a NikonType2MakernoteDirectory.
26 * Type-2 applies to the E990 and D-series cameras such as the D1, D70 and D100.
27 */
28public class NikonType2MakernoteDescriptor extends TagDescriptor
29{
30 public NikonType2MakernoteDescriptor(Directory directory)
31 {
32 super(directory);
33 }
34
35 private NikonType2MakernoteDirectory getMakernoteDirectory()
36 {
37 return (NikonType2MakernoteDirectory)_directory;
38 }
39
40 public String getDescription(int tagType) throws MetadataException
41 {
42 switch (tagType)
43 {
44 case NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_LENS:
45 return getLensDescription();
46 case NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_CAMERA_HUE_ADJUSTMENT:
47 return getHueAdjustmentDescription();
48 case NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_CAMERA_COLOR_MODE:
49 return getColorModeDescription();
50 case NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_AUTO_FLASH_COMPENSATION:
51 return getAutoFlashCompensationDescription();
52 case NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_ISO_1:
53 return getIsoSettingDescription();
54 case NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_DIGITAL_ZOOM:
55 return getDigitalZoomDescription();
56 case NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_AF_FOCUS_POSITION:
57 return getAutoFocusPositionDescription();
58 case NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_FIRMWARE_VERSION:
59 return getAutoFirmwareVersionDescription();
60 default:
61 return _directory.getString(tagType);
62 }
63 }
64
65 public String getAutoFocusPositionDescription() throws MetadataException
66 {
67 if (!_directory.containsTag(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_AF_FOCUS_POSITION)) return null;
68 int[] values = _directory.getIntArray(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_AF_FOCUS_POSITION);
69 if (values.length != 4 || values[0] != 0 || values[2] != 0 || values[3] != 0) {
70 return "Unknown (" + _directory.getString(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_AF_FOCUS_POSITION) + ")";
71 }
72 switch (values[1]) {
73 case 0:
74 return "Centre";
75 case 1:
76 return "Top";
77 case 2:
78 return "Bottom";
79 case 3:
80 return "Left";
81 case 4:
82 return "Right";
83 default:
84 return "Unknown (" + values[1] + ")";
85 }
86 }
87
88 public String getDigitalZoomDescription() throws MetadataException
89 {
90 if (!_directory.containsTag(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_DIGITAL_ZOOM)) return null;
91 Rational rational = _directory.getRational(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_DIGITAL_ZOOM);
92 if (rational.intValue() == 1) {
93 return "No digital zoom";
94 }
95 return rational.toSimpleString(true) + "x digital zoom";
96 }
97
98 public String getIsoSettingDescription() throws MetadataException
99 {
100 if (!_directory.containsTag(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_ISO_1)) return null;
101 int[] values = _directory.getIntArray(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_ISO_1);
102 if (values[0] != 0 || values[1] == 0) {
103 return "Unknown (" + _directory.getString(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_ISO_1) + ")";
104 }
105 return "ISO " + values[1];
106 }
107
108 public String getAutoFlashCompensationDescription() throws MetadataException
109 {
110 Rational ev = getMakernoteDirectory().getAutoFlashCompensation();
111
112 if (ev==null)
113 return "Unknown";
114
115 DecimalFormat decimalFormat = new DecimalFormat("0.##");
116 return decimalFormat.format(ev.floatValue()) + " EV";
117 }
118
119 public String getLensDescription() throws MetadataException
120 {
121 if (!_directory.containsTag(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_LENS))
122 return null;
123
124 Rational[] lensValues = _directory.getRationalArray(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_LENS);
125
126 if (lensValues.length!=4)
127 return _directory.getString(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_LENS);
128
129 StringBuffer description = new StringBuffer();
130 description.append(lensValues[0].intValue());
131 description.append('-');
132 description.append(lensValues[1].intValue());
133 description.append("mm f/");
134 description.append(lensValues[2].floatValue());
135 description.append('-');
136 description.append(lensValues[3].floatValue());
137
138 return description.toString();
139 }
140
141 public String getHueAdjustmentDescription()
142 {
143 if (!_directory.containsTag(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_CAMERA_HUE_ADJUSTMENT))
144 return null;
145
146 return _directory.getString(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_CAMERA_HUE_ADJUSTMENT) + " degrees";
147 }
148
149 public String getColorModeDescription()
150 {
151 if (!_directory.containsTag(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_CAMERA_COLOR_MODE))
152 return null;
153
154 String raw = _directory.getString(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_CAMERA_COLOR_MODE);
155 if (raw.startsWith("MODE1"))
156 return "Mode I (sRGB)";
157
158 return raw;
159 }
160
161 public String getAutoFirmwareVersionDescription() throws MetadataException
162 {
163 if (!_directory.containsTag(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_FIRMWARE_VERSION))
164 return null;
165
166 int[] ints = _directory.getIntArray(NikonType2MakernoteDirectory.TAG_NIKON_TYPE2_FIRMWARE_VERSION);
167 return ExifDescriptor.convertBytesToVersionString(ints);
168 }
169}
Note: See TracBrowser for help on using the repository browser.