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 | */
|
---|
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 static com.drew.metadata.exif.makernotes.OlympusFocusInfoMakernoteDirectory.*;
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Provides human-readable String representations of tag values stored in a {@link OlympusFocusInfoMakernoteDirectory}.
|
---|
32 | * <p>
|
---|
33 | * Some Description functions converted from Exiftool version 10.10 created by Phil Harvey
|
---|
34 | * http://www.sno.phy.queensu.ca/~phil/exiftool/
|
---|
35 | * lib\Image\ExifTool\Olympus.pm
|
---|
36 | *
|
---|
37 | * @author Kevin Mott https://github.com/kwhopper
|
---|
38 | * @author Drew Noakes https://drewnoakes.com
|
---|
39 | */
|
---|
40 | @SuppressWarnings("WeakerAccess")
|
---|
41 | public class OlympusFocusInfoMakernoteDescriptor extends TagDescriptor<OlympusFocusInfoMakernoteDirectory>
|
---|
42 | {
|
---|
43 | public OlympusFocusInfoMakernoteDescriptor(@NotNull OlympusFocusInfoMakernoteDirectory directory)
|
---|
44 | {
|
---|
45 | super(directory);
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | @Nullable
|
---|
50 | public String getDescription(int tagType)
|
---|
51 | {
|
---|
52 | switch (tagType) {
|
---|
53 | case TagFocusInfoVersion:
|
---|
54 | return getFocusInfoVersionDescription();
|
---|
55 | case TagAutoFocus:
|
---|
56 | return getAutoFocusDescription();
|
---|
57 | case TagFocusDistance:
|
---|
58 | return getFocusDistanceDescription();
|
---|
59 | case TagAfPoint:
|
---|
60 | return getAfPointDescription();
|
---|
61 | case TagExternalFlash:
|
---|
62 | return getExternalFlashDescription();
|
---|
63 | case TagExternalFlashBounce:
|
---|
64 | return getExternalFlashBounceDescription();
|
---|
65 | case TagExternalFlashZoom:
|
---|
66 | return getExternalFlashZoomDescription();
|
---|
67 | case TagManualFlash:
|
---|
68 | return getManualFlashDescription();
|
---|
69 | case TagMacroLed:
|
---|
70 | return getMacroLedDescription();
|
---|
71 | case TagSensorTemperature:
|
---|
72 | return getSensorTemperatureDescription();
|
---|
73 | case TagImageStabilization:
|
---|
74 | return getImageStabilizationDescription();
|
---|
75 | default:
|
---|
76 | return super.getDescription(tagType);
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Nullable
|
---|
81 | public String getFocusInfoVersionDescription()
|
---|
82 | {
|
---|
83 | return getVersionBytesDescription(TagFocusInfoVersion, 4);
|
---|
84 | }
|
---|
85 |
|
---|
86 | @Nullable
|
---|
87 | public String getAutoFocusDescription()
|
---|
88 | {
|
---|
89 | return getIndexedDescription(TagAutoFocus,
|
---|
90 | "Off", "On");
|
---|
91 | }
|
---|
92 |
|
---|
93 | @Nullable
|
---|
94 | public String getFocusDistanceDescription()
|
---|
95 | {
|
---|
96 | Rational value = _directory.getRational(TagFocusDistance);
|
---|
97 | if (value == null)
|
---|
98 | return "inf";
|
---|
99 | if (value.getNumerator() == 0xFFFFFFFFL || value.getNumerator() == 0x00000000L)
|
---|
100 | return "inf";
|
---|
101 |
|
---|
102 | return value.getNumerator() / 1000.0 + " m";
|
---|
103 | }
|
---|
104 |
|
---|
105 | @Nullable
|
---|
106 | public String getAfPointDescription()
|
---|
107 | {
|
---|
108 | Integer value = _directory.getInteger(TagAfPoint);
|
---|
109 | if (value == null)
|
---|
110 | return null;
|
---|
111 |
|
---|
112 | return value.toString();
|
---|
113 | }
|
---|
114 |
|
---|
115 | @Nullable
|
---|
116 | public String getExternalFlashDescription()
|
---|
117 | {
|
---|
118 | int[] values = _directory.getIntArray(TagExternalFlash);
|
---|
119 | if (values == null || values.length < 2)
|
---|
120 | return null;
|
---|
121 |
|
---|
122 | String join = String.format("%d %d", (short)values[0], (short)values[1]);
|
---|
123 |
|
---|
124 | if(join.equals("0 0"))
|
---|
125 | return "Off";
|
---|
126 | else if(join.equals("1 0"))
|
---|
127 | return "On";
|
---|
128 | else
|
---|
129 | return "Unknown (" + join + ")";
|
---|
130 | }
|
---|
131 |
|
---|
132 | @Nullable
|
---|
133 | public String getExternalFlashBounceDescription()
|
---|
134 | {
|
---|
135 | return getIndexedDescription(TagExternalFlashBounce,
|
---|
136 | "Bounce or Off", "Direct");
|
---|
137 | }
|
---|
138 |
|
---|
139 | @Nullable
|
---|
140 | public String getExternalFlashZoomDescription()
|
---|
141 | {
|
---|
142 | int[] values = _directory.getIntArray(TagExternalFlashZoom);
|
---|
143 | if (values == null)
|
---|
144 | {
|
---|
145 | // check if it's only one value long also
|
---|
146 | Integer value = _directory.getInteger(TagExternalFlashZoom);
|
---|
147 | if(value == null)
|
---|
148 | return null;
|
---|
149 |
|
---|
150 | values = new int[1];
|
---|
151 | values[0] = value;
|
---|
152 | }
|
---|
153 |
|
---|
154 | if (values.length == 0)
|
---|
155 | return null;
|
---|
156 |
|
---|
157 | String join = String.format("%d", (short)values[0]);
|
---|
158 | if(values.length > 1)
|
---|
159 | join += " " + String.format("%d", (short)values[1]);
|
---|
160 |
|
---|
161 | if(join.equals("0"))
|
---|
162 | return "Off";
|
---|
163 | else if(join.equals("1"))
|
---|
164 | return "On";
|
---|
165 | else if(join.equals("0 0"))
|
---|
166 | return "Off";
|
---|
167 | else if(join.equals("1 0"))
|
---|
168 | return "On";
|
---|
169 | else
|
---|
170 | return "Unknown (" + join + ")";
|
---|
171 |
|
---|
172 | }
|
---|
173 |
|
---|
174 | @Nullable
|
---|
175 | public String getManualFlashDescription()
|
---|
176 | {
|
---|
177 | int[] values = _directory.getIntArray(TagManualFlash);
|
---|
178 | if (values == null)
|
---|
179 | return null;
|
---|
180 |
|
---|
181 | if ((short)values[0] == 0)
|
---|
182 | return "Off";
|
---|
183 |
|
---|
184 | if ((short)values[1] == 1)
|
---|
185 | return "Full";
|
---|
186 | return "On (1/" + (short)values[1] + " strength)";
|
---|
187 | }
|
---|
188 |
|
---|
189 | @Nullable
|
---|
190 | public String getMacroLedDescription()
|
---|
191 | {
|
---|
192 | return getIndexedDescription(TagMacroLed,
|
---|
193 | "Off", "On");
|
---|
194 | }
|
---|
195 |
|
---|
196 | /// <remarks>
|
---|
197 | /// <para>TODO: Complete when Camera Model is available.</para>
|
---|
198 | /// <para>There are differences in how to interpret this tag that can only be reconciled by knowing the model.</para>
|
---|
199 | /// </remarks>
|
---|
200 | @Nullable
|
---|
201 | public String getSensorTemperatureDescription()
|
---|
202 | {
|
---|
203 | return _directory.getString(TagSensorTemperature);
|
---|
204 | }
|
---|
205 |
|
---|
206 | @Nullable
|
---|
207 | public String getImageStabilizationDescription()
|
---|
208 | {
|
---|
209 | byte[] values = _directory.getByteArray(TagImageStabilization);
|
---|
210 | if (values == null)
|
---|
211 | return null;
|
---|
212 |
|
---|
213 | if((values[0] | values[1] | values[2] | values[3]) == 0x0)
|
---|
214 | return "Off";
|
---|
215 | return "On, " + ((values[43] & 1) > 0 ? "Mode 1" : "Mode 2");
|
---|
216 | }
|
---|
217 | }
|
---|