[6127] | 1 | /*
|
---|
[8132] | 2 | * Copyright 2002-2015 Drew Noakes
|
---|
[6127] | 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 | *
|
---|
[8132] | 18 | * https://drewnoakes.com/code/exif/
|
---|
| 19 | * https://github.com/drewnoakes/metadata-extractor
|
---|
[6127] | 20 | */
|
---|
| 21 | package com.drew.metadata.exif;
|
---|
| 22 |
|
---|
| 23 | import com.drew.imaging.PhotographicConversions;
|
---|
| 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 | import java.io.UnsupportedEncodingException;
|
---|
| 30 | import java.text.DecimalFormat;
|
---|
| 31 | import java.util.HashMap;
|
---|
| 32 | import java.util.Map;
|
---|
| 33 |
|
---|
[8132] | 34 | import static com.drew.metadata.exif.ExifSubIFDDirectory.*;
|
---|
| 35 |
|
---|
[6127] | 36 | /**
|
---|
[8132] | 37 | * Provides human-readable string representations of tag values stored in a {@link ExifSubIFDDirectory}.
|
---|
[6127] | 38 | *
|
---|
[8132] | 39 | * @author Drew Noakes https://drewnoakes.com
|
---|
[6127] | 40 | */
|
---|
| 41 | public class ExifSubIFDDescriptor extends TagDescriptor<ExifSubIFDDirectory>
|
---|
| 42 | {
|
---|
| 43 | /**
|
---|
| 44 | * Dictates whether rational values will be represented in decimal format in instances
|
---|
| 45 | * where decimal notation is elegant (such as 1/2 -> 0.5, but not 1/3).
|
---|
| 46 | */
|
---|
| 47 | private final boolean _allowDecimalRepresentationOfRationals = true;
|
---|
| 48 |
|
---|
| 49 | @NotNull
|
---|
| 50 | private static final java.text.DecimalFormat SimpleDecimalFormatter = new DecimalFormat("0.#");
|
---|
| 51 |
|
---|
| 52 | public ExifSubIFDDescriptor(@NotNull ExifSubIFDDirectory directory)
|
---|
| 53 | {
|
---|
| 54 | super(directory);
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | // Note for the potential addition of brightness presentation in eV:
|
---|
| 58 | // Brightness of taken subject. To calculate Exposure(Ev) from BrightnessValue(Bv),
|
---|
| 59 | // you must add SensitivityValue(Sv).
|
---|
| 60 | // Ev=BV+Sv Sv=log2(ISOSpeedRating/3.125)
|
---|
| 61 | // ISO100:Sv=5, ISO200:Sv=6, ISO400:Sv=7, ISO125:Sv=5.32.
|
---|
| 62 |
|
---|
| 63 | /**
|
---|
[8132] | 64 | * Returns a descriptive value of the specified tag for this image.
|
---|
[6127] | 65 | * Where possible, known values will be substituted here in place of the raw
|
---|
| 66 | * tokens actually kept in the Exif segment. If no substitution is
|
---|
| 67 | * available, the value provided by getString(int) will be returned.
|
---|
[8132] | 68 | *
|
---|
[6127] | 69 | * @param tagType the tag to find a description for
|
---|
| 70 | * @return a description of the image's value for the specified tag, or
|
---|
| 71 | * <code>null</code> if the tag hasn't been defined.
|
---|
| 72 | */
|
---|
[8132] | 73 | @Override
|
---|
[6127] | 74 | @Nullable
|
---|
| 75 | public String getDescription(int tagType)
|
---|
| 76 | {
|
---|
| 77 | switch (tagType) {
|
---|
[8132] | 78 | case TAG_NEW_SUBFILE_TYPE:
|
---|
[6127] | 79 | return getNewSubfileTypeDescription();
|
---|
[8132] | 80 | case TAG_SUBFILE_TYPE:
|
---|
[6127] | 81 | return getSubfileTypeDescription();
|
---|
[8132] | 82 | case TAG_THRESHOLDING:
|
---|
[6127] | 83 | return getThresholdingDescription();
|
---|
[8132] | 84 | case TAG_FILL_ORDER:
|
---|
[6127] | 85 | return getFillOrderDescription();
|
---|
[8132] | 86 | case TAG_EXPOSURE_TIME:
|
---|
[6127] | 87 | return getExposureTimeDescription();
|
---|
[8132] | 88 | case TAG_SHUTTER_SPEED:
|
---|
[6127] | 89 | return getShutterSpeedDescription();
|
---|
[8132] | 90 | case TAG_FNUMBER:
|
---|
[6127] | 91 | return getFNumberDescription();
|
---|
[8132] | 92 | case TAG_COMPRESSED_AVERAGE_BITS_PER_PIXEL:
|
---|
[6127] | 93 | return getCompressedAverageBitsPerPixelDescription();
|
---|
[8132] | 94 | case TAG_SUBJECT_DISTANCE:
|
---|
[6127] | 95 | return getSubjectDistanceDescription();
|
---|
[8132] | 96 | case TAG_METERING_MODE:
|
---|
[6127] | 97 | return getMeteringModeDescription();
|
---|
[8132] | 98 | case TAG_WHITE_BALANCE:
|
---|
[6127] | 99 | return getWhiteBalanceDescription();
|
---|
[8132] | 100 | case TAG_FLASH:
|
---|
[6127] | 101 | return getFlashDescription();
|
---|
[8132] | 102 | case TAG_FOCAL_LENGTH:
|
---|
[6127] | 103 | return getFocalLengthDescription();
|
---|
[8132] | 104 | case TAG_COLOR_SPACE:
|
---|
[6127] | 105 | return getColorSpaceDescription();
|
---|
[8132] | 106 | case TAG_EXIF_IMAGE_WIDTH:
|
---|
[6127] | 107 | return getExifImageWidthDescription();
|
---|
[8132] | 108 | case TAG_EXIF_IMAGE_HEIGHT:
|
---|
[6127] | 109 | return getExifImageHeightDescription();
|
---|
[8132] | 110 | case TAG_FOCAL_PLANE_RESOLUTION_UNIT:
|
---|
[6127] | 111 | return getFocalPlaneResolutionUnitDescription();
|
---|
[8132] | 112 | case TAG_FOCAL_PLANE_X_RESOLUTION:
|
---|
[6127] | 113 | return getFocalPlaneXResolutionDescription();
|
---|
[8132] | 114 | case TAG_FOCAL_PLANE_Y_RESOLUTION:
|
---|
[6127] | 115 | return getFocalPlaneYResolutionDescription();
|
---|
[8132] | 116 | case TAG_BITS_PER_SAMPLE:
|
---|
[6127] | 117 | return getBitsPerSampleDescription();
|
---|
[8132] | 118 | case TAG_PHOTOMETRIC_INTERPRETATION:
|
---|
[6127] | 119 | return getPhotometricInterpretationDescription();
|
---|
[8132] | 120 | case TAG_ROWS_PER_STRIP:
|
---|
[6127] | 121 | return getRowsPerStripDescription();
|
---|
[8132] | 122 | case TAG_STRIP_BYTE_COUNTS:
|
---|
[6127] | 123 | return getStripByteCountsDescription();
|
---|
[8132] | 124 | case TAG_SAMPLES_PER_PIXEL:
|
---|
[6127] | 125 | return getSamplesPerPixelDescription();
|
---|
[8132] | 126 | case TAG_PLANAR_CONFIGURATION:
|
---|
[6127] | 127 | return getPlanarConfigurationDescription();
|
---|
[8132] | 128 | case TAG_YCBCR_SUBSAMPLING:
|
---|
[6127] | 129 | return getYCbCrSubsamplingDescription();
|
---|
[8132] | 130 | case TAG_EXPOSURE_PROGRAM:
|
---|
[6127] | 131 | return getExposureProgramDescription();
|
---|
[8132] | 132 | case TAG_APERTURE:
|
---|
[6127] | 133 | return getApertureValueDescription();
|
---|
[8132] | 134 | case TAG_MAX_APERTURE:
|
---|
[6127] | 135 | return getMaxApertureValueDescription();
|
---|
[8132] | 136 | case TAG_SENSING_METHOD:
|
---|
[6127] | 137 | return getSensingMethodDescription();
|
---|
[8132] | 138 | case TAG_EXPOSURE_BIAS:
|
---|
[6127] | 139 | return getExposureBiasDescription();
|
---|
[8132] | 140 | case TAG_FILE_SOURCE:
|
---|
[6127] | 141 | return getFileSourceDescription();
|
---|
[8132] | 142 | case TAG_SCENE_TYPE:
|
---|
[6127] | 143 | return getSceneTypeDescription();
|
---|
[8132] | 144 | case TAG_COMPONENTS_CONFIGURATION:
|
---|
[6127] | 145 | return getComponentConfigurationDescription();
|
---|
[8132] | 146 | case TAG_EXIF_VERSION:
|
---|
[6127] | 147 | return getExifVersionDescription();
|
---|
[8132] | 148 | case TAG_FLASHPIX_VERSION:
|
---|
[6127] | 149 | return getFlashPixVersionDescription();
|
---|
[8132] | 150 | case TAG_ISO_EQUIVALENT:
|
---|
[6127] | 151 | return getIsoEquivalentDescription();
|
---|
[8132] | 152 | case TAG_USER_COMMENT:
|
---|
[6127] | 153 | return getUserCommentDescription();
|
---|
[8132] | 154 | case TAG_CUSTOM_RENDERED:
|
---|
[6127] | 155 | return getCustomRenderedDescription();
|
---|
[8132] | 156 | case TAG_EXPOSURE_MODE:
|
---|
[6127] | 157 | return getExposureModeDescription();
|
---|
[8132] | 158 | case TAG_WHITE_BALANCE_MODE:
|
---|
[6127] | 159 | return getWhiteBalanceModeDescription();
|
---|
[8132] | 160 | case TAG_DIGITAL_ZOOM_RATIO:
|
---|
[6127] | 161 | return getDigitalZoomRatioDescription();
|
---|
[8132] | 162 | case TAG_35MM_FILM_EQUIV_FOCAL_LENGTH:
|
---|
[6127] | 163 | return get35mmFilmEquivFocalLengthDescription();
|
---|
[8132] | 164 | case TAG_SCENE_CAPTURE_TYPE:
|
---|
[6127] | 165 | return getSceneCaptureTypeDescription();
|
---|
[8132] | 166 | case TAG_GAIN_CONTROL:
|
---|
[6127] | 167 | return getGainControlDescription();
|
---|
[8132] | 168 | case TAG_CONTRAST:
|
---|
[6127] | 169 | return getContrastDescription();
|
---|
[8132] | 170 | case TAG_SATURATION:
|
---|
[6127] | 171 | return getSaturationDescription();
|
---|
[8132] | 172 | case TAG_SHARPNESS:
|
---|
[6127] | 173 | return getSharpnessDescription();
|
---|
[8132] | 174 | case TAG_SUBJECT_DISTANCE_RANGE:
|
---|
[6127] | 175 | return getSubjectDistanceRangeDescription();
|
---|
| 176 | default:
|
---|
| 177 | return super.getDescription(tagType);
|
---|
| 178 | }
|
---|
| 179 | }
|
---|
| 180 |
|
---|
| 181 | @Nullable
|
---|
| 182 | public String getNewSubfileTypeDescription()
|
---|
| 183 | {
|
---|
[8132] | 184 | return getIndexedDescription(TAG_NEW_SUBFILE_TYPE, 1,
|
---|
| 185 | "Full-resolution image",
|
---|
| 186 | "Reduced-resolution image",
|
---|
| 187 | "Single page of multi-page reduced-resolution image",
|
---|
| 188 | "Transparency mask",
|
---|
| 189 | "Transparency mask of reduced-resolution image",
|
---|
| 190 | "Transparency mask of multi-page image",
|
---|
| 191 | "Transparency mask of reduced-resolution multi-page image"
|
---|
| 192 | );
|
---|
[6127] | 193 | }
|
---|
| 194 |
|
---|
| 195 | @Nullable
|
---|
| 196 | public String getSubfileTypeDescription()
|
---|
| 197 | {
|
---|
[8132] | 198 | return getIndexedDescription(TAG_SUBFILE_TYPE, 1,
|
---|
| 199 | "Full-resolution image",
|
---|
| 200 | "Reduced-resolution image",
|
---|
| 201 | "Single page of multi-page image"
|
---|
| 202 | );
|
---|
[6127] | 203 | }
|
---|
| 204 |
|
---|
| 205 | @Nullable
|
---|
| 206 | public String getThresholdingDescription()
|
---|
| 207 | {
|
---|
[8132] | 208 | return getIndexedDescription(TAG_THRESHOLDING, 1,
|
---|
| 209 | "No dithering or halftoning",
|
---|
| 210 | "Ordered dither or halftone",
|
---|
| 211 | "Randomized dither"
|
---|
| 212 | );
|
---|
[6127] | 213 | }
|
---|
| 214 |
|
---|
| 215 | @Nullable
|
---|
| 216 | public String getFillOrderDescription()
|
---|
| 217 | {
|
---|
[8132] | 218 | return getIndexedDescription(TAG_FILL_ORDER, 1,
|
---|
| 219 | "Normal",
|
---|
| 220 | "Reversed"
|
---|
| 221 | );
|
---|
[6127] | 222 | }
|
---|
| 223 |
|
---|
| 224 | @Nullable
|
---|
| 225 | public String getSubjectDistanceRangeDescription()
|
---|
| 226 | {
|
---|
[8132] | 227 | return getIndexedDescription(TAG_SUBJECT_DISTANCE_RANGE,
|
---|
| 228 | "Unknown",
|
---|
| 229 | "Macro",
|
---|
| 230 | "Close view",
|
---|
| 231 | "Distant view"
|
---|
| 232 | );
|
---|
[6127] | 233 | }
|
---|
| 234 |
|
---|
| 235 | @Nullable
|
---|
| 236 | public String getSharpnessDescription()
|
---|
| 237 | {
|
---|
[8132] | 238 | return getIndexedDescription(TAG_SHARPNESS,
|
---|
| 239 | "None",
|
---|
| 240 | "Low",
|
---|
| 241 | "Hard"
|
---|
| 242 | );
|
---|
[6127] | 243 | }
|
---|
| 244 |
|
---|
| 245 | @Nullable
|
---|
| 246 | public String getSaturationDescription()
|
---|
| 247 | {
|
---|
[8132] | 248 | return getIndexedDescription(TAG_SATURATION,
|
---|
| 249 | "None",
|
---|
| 250 | "Low saturation",
|
---|
| 251 | "High saturation"
|
---|
| 252 | );
|
---|
[6127] | 253 | }
|
---|
| 254 |
|
---|
| 255 | @Nullable
|
---|
| 256 | public String getContrastDescription()
|
---|
| 257 | {
|
---|
[8132] | 258 | return getIndexedDescription(TAG_CONTRAST,
|
---|
| 259 | "None",
|
---|
| 260 | "Soft",
|
---|
| 261 | "Hard"
|
---|
| 262 | );
|
---|
[6127] | 263 | }
|
---|
| 264 |
|
---|
| 265 | @Nullable
|
---|
| 266 | public String getGainControlDescription()
|
---|
| 267 | {
|
---|
[8132] | 268 | return getIndexedDescription(TAG_GAIN_CONTROL,
|
---|
| 269 | "None",
|
---|
| 270 | "Low gain up",
|
---|
| 271 | "Low gain down",
|
---|
| 272 | "High gain up",
|
---|
| 273 | "High gain down"
|
---|
| 274 | );
|
---|
[6127] | 275 | }
|
---|
| 276 |
|
---|
| 277 | @Nullable
|
---|
| 278 | public String getSceneCaptureTypeDescription()
|
---|
| 279 | {
|
---|
[8132] | 280 | return getIndexedDescription(TAG_SCENE_CAPTURE_TYPE,
|
---|
| 281 | "Standard",
|
---|
| 282 | "Landscape",
|
---|
| 283 | "Portrait",
|
---|
| 284 | "Night scene"
|
---|
| 285 | );
|
---|
[6127] | 286 | }
|
---|
| 287 |
|
---|
| 288 | @Nullable
|
---|
| 289 | public String get35mmFilmEquivFocalLengthDescription()
|
---|
| 290 | {
|
---|
[8132] | 291 | Integer value = _directory.getInteger(TAG_35MM_FILM_EQUIV_FOCAL_LENGTH);
|
---|
| 292 | return value == null
|
---|
| 293 | ? null
|
---|
| 294 | : value == 0
|
---|
| 295 | ? "Unknown"
|
---|
| 296 | : SimpleDecimalFormatter.format(value) + "mm";
|
---|
[6127] | 297 | }
|
---|
| 298 |
|
---|
| 299 | @Nullable
|
---|
| 300 | public String getDigitalZoomRatioDescription()
|
---|
| 301 | {
|
---|
[8132] | 302 | Rational value = _directory.getRational(TAG_DIGITAL_ZOOM_RATIO);
|
---|
| 303 | return value == null
|
---|
| 304 | ? null
|
---|
| 305 | : value.getNumerator() == 0
|
---|
| 306 | ? "Digital zoom not used."
|
---|
| 307 | : SimpleDecimalFormatter.format(value.doubleValue());
|
---|
[6127] | 308 | }
|
---|
| 309 |
|
---|
| 310 | @Nullable
|
---|
| 311 | public String getWhiteBalanceModeDescription()
|
---|
| 312 | {
|
---|
[8132] | 313 | return getIndexedDescription(TAG_WHITE_BALANCE_MODE,
|
---|
| 314 | "Auto white balance",
|
---|
| 315 | "Manual white balance"
|
---|
| 316 | );
|
---|
[6127] | 317 | }
|
---|
| 318 |
|
---|
| 319 | @Nullable
|
---|
| 320 | public String getExposureModeDescription()
|
---|
| 321 | {
|
---|
[8132] | 322 | return getIndexedDescription(TAG_EXPOSURE_MODE,
|
---|
| 323 | "Auto exposure",
|
---|
| 324 | "Manual exposure",
|
---|
| 325 | "Auto bracket"
|
---|
| 326 | );
|
---|
[6127] | 327 | }
|
---|
| 328 |
|
---|
| 329 | @Nullable
|
---|
| 330 | public String getCustomRenderedDescription()
|
---|
| 331 | {
|
---|
[8132] | 332 | return getIndexedDescription(TAG_CUSTOM_RENDERED,
|
---|
| 333 | "Normal process",
|
---|
| 334 | "Custom process"
|
---|
| 335 | );
|
---|
[6127] | 336 | }
|
---|
| 337 |
|
---|
| 338 | @Nullable
|
---|
| 339 | public String getUserCommentDescription()
|
---|
| 340 | {
|
---|
[8132] | 341 | byte[] commentBytes = _directory.getByteArray(TAG_USER_COMMENT);
|
---|
| 342 | if (commentBytes == null)
|
---|
[6127] | 343 | return null;
|
---|
| 344 | if (commentBytes.length == 0)
|
---|
| 345 | return "";
|
---|
| 346 |
|
---|
| 347 | final Map<String, String> encodingMap = new HashMap<String, String>();
|
---|
[8132] | 348 | encodingMap.put("ASCII", System.getProperty("file.encoding")); // Someone suggested "ISO-8859-1".
|
---|
| 349 | encodingMap.put("UNICODE", "UTF-16LE");
|
---|
| 350 | encodingMap.put("JIS", "Shift-JIS"); // We assume this charset for now. Another suggestion is "JIS".
|
---|
[6127] | 351 |
|
---|
| 352 | try {
|
---|
| 353 | if (commentBytes.length >= 10) {
|
---|
| 354 | String firstTenBytesString = new String(commentBytes, 0, 10);
|
---|
| 355 |
|
---|
| 356 | // try each encoding name
|
---|
| 357 | for (Map.Entry<String, String> pair : encodingMap.entrySet()) {
|
---|
| 358 | String encodingName = pair.getKey();
|
---|
| 359 | String charset = pair.getValue();
|
---|
| 360 | if (firstTenBytesString.startsWith(encodingName)) {
|
---|
| 361 | // skip any null or blank characters commonly present after the encoding name, up to a limit of 10 from the start
|
---|
| 362 | for (int j = encodingName.length(); j < 10; j++) {
|
---|
| 363 | byte b = commentBytes[j];
|
---|
| 364 | if (b != '\0' && b != ' ')
|
---|
| 365 | return new String(commentBytes, j, commentBytes.length - j, charset).trim();
|
---|
| 366 | }
|
---|
| 367 | return new String(commentBytes, 10, commentBytes.length - 10, charset).trim();
|
---|
| 368 | }
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 | // special handling fell through, return a plain string representation
|
---|
| 372 | return new String(commentBytes, System.getProperty("file.encoding")).trim();
|
---|
| 373 | } catch (UnsupportedEncodingException ex) {
|
---|
| 374 | return null;
|
---|
| 375 | }
|
---|
| 376 | }
|
---|
| 377 |
|
---|
| 378 | @Nullable
|
---|
| 379 | public String getIsoEquivalentDescription()
|
---|
| 380 | {
|
---|
| 381 | // Have seen an exception here from files produced by ACDSEE that stored an int[] here with two values
|
---|
[8132] | 382 | Integer isoEquiv = _directory.getInteger(TAG_ISO_EQUIVALENT);
|
---|
[6127] | 383 | // There used to be a check here that multiplied ISO values < 50 by 200.
|
---|
| 384 | // Issue 36 shows a smart-phone image from a Samsung Galaxy S2 with ISO-40.
|
---|
[8132] | 385 | return isoEquiv != null
|
---|
| 386 | ? Integer.toString(isoEquiv)
|
---|
| 387 | : null;
|
---|
[6127] | 388 | }
|
---|
| 389 |
|
---|
| 390 | @Nullable
|
---|
| 391 | public String getExifVersionDescription()
|
---|
| 392 | {
|
---|
[8132] | 393 | return getVersionBytesDescription(TAG_EXIF_VERSION, 2);
|
---|
[6127] | 394 | }
|
---|
| 395 |
|
---|
| 396 | @Nullable
|
---|
| 397 | public String getFlashPixVersionDescription()
|
---|
| 398 | {
|
---|
[8132] | 399 | return getVersionBytesDescription(TAG_FLASHPIX_VERSION, 2);
|
---|
[6127] | 400 | }
|
---|
| 401 |
|
---|
| 402 | @Nullable
|
---|
| 403 | public String getSceneTypeDescription()
|
---|
| 404 | {
|
---|
[8132] | 405 | return getIndexedDescription(TAG_SCENE_TYPE,
|
---|
| 406 | 1,
|
---|
| 407 | "Directly photographed image"
|
---|
| 408 | );
|
---|
[6127] | 409 | }
|
---|
| 410 |
|
---|
| 411 | @Nullable
|
---|
| 412 | public String getFileSourceDescription()
|
---|
| 413 | {
|
---|
[8132] | 414 | return getIndexedDescription(TAG_FILE_SOURCE,
|
---|
| 415 | 1,
|
---|
| 416 | "Film Scanner",
|
---|
| 417 | "Reflection Print Scanner",
|
---|
| 418 | "Digital Still Camera (DSC)"
|
---|
| 419 | );
|
---|
[6127] | 420 | }
|
---|
| 421 |
|
---|
| 422 | @Nullable
|
---|
| 423 | public String getExposureBiasDescription()
|
---|
| 424 | {
|
---|
[8132] | 425 | Rational value = _directory.getRational(TAG_EXPOSURE_BIAS);
|
---|
| 426 | if (value == null)
|
---|
[6127] | 427 | return null;
|
---|
| 428 | return value.toSimpleString(true) + " EV";
|
---|
| 429 | }
|
---|
| 430 |
|
---|
| 431 | @Nullable
|
---|
| 432 | public String getMaxApertureValueDescription()
|
---|
| 433 | {
|
---|
[8132] | 434 | Double aperture = _directory.getDoubleObject(TAG_MAX_APERTURE);
|
---|
| 435 | if (aperture == null)
|
---|
[6127] | 436 | return null;
|
---|
| 437 | double fStop = PhotographicConversions.apertureToFStop(aperture);
|
---|
| 438 | return "F" + SimpleDecimalFormatter.format(fStop);
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | @Nullable
|
---|
| 442 | public String getApertureValueDescription()
|
---|
| 443 | {
|
---|
[8132] | 444 | Double aperture = _directory.getDoubleObject(TAG_APERTURE);
|
---|
| 445 | if (aperture == null)
|
---|
[6127] | 446 | return null;
|
---|
| 447 | double fStop = PhotographicConversions.apertureToFStop(aperture);
|
---|
| 448 | return "F" + SimpleDecimalFormatter.format(fStop);
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | @Nullable
|
---|
| 452 | public String getExposureProgramDescription()
|
---|
| 453 | {
|
---|
[8132] | 454 | return getIndexedDescription(TAG_EXPOSURE_PROGRAM,
|
---|
| 455 | 1,
|
---|
| 456 | "Manual control",
|
---|
| 457 | "Program normal",
|
---|
| 458 | "Aperture priority",
|
---|
| 459 | "Shutter priority",
|
---|
| 460 | "Program creative (slow program)",
|
---|
| 461 | "Program action (high-speed program)",
|
---|
| 462 | "Portrait mode",
|
---|
| 463 | "Landscape mode"
|
---|
| 464 | );
|
---|
[6127] | 465 | }
|
---|
| 466 |
|
---|
| 467 | @Nullable
|
---|
| 468 | public String getYCbCrSubsamplingDescription()
|
---|
| 469 | {
|
---|
[8132] | 470 | int[] positions = _directory.getIntArray(TAG_YCBCR_SUBSAMPLING);
|
---|
| 471 | if (positions == null)
|
---|
[6127] | 472 | return null;
|
---|
| 473 | if (positions[0] == 2 && positions[1] == 1) {
|
---|
| 474 | return "YCbCr4:2:2";
|
---|
| 475 | } else if (positions[0] == 2 && positions[1] == 2) {
|
---|
| 476 | return "YCbCr4:2:0";
|
---|
| 477 | } else {
|
---|
| 478 | return "(Unknown)";
|
---|
| 479 | }
|
---|
| 480 | }
|
---|
| 481 |
|
---|
| 482 | @Nullable
|
---|
| 483 | public String getPlanarConfigurationDescription()
|
---|
| 484 | {
|
---|
| 485 | // When image format is no compression YCbCr, this value shows byte aligns of YCbCr
|
---|
| 486 | // data. If value is '1', Y/Cb/Cr value is chunky format, contiguous for each subsampling
|
---|
| 487 | // pixel. If value is '2', Y/Cb/Cr value is separated and stored to Y plane/Cb plane/Cr
|
---|
| 488 | // plane format.
|
---|
[8132] | 489 | return getIndexedDescription(TAG_PLANAR_CONFIGURATION,
|
---|
| 490 | 1,
|
---|
| 491 | "Chunky (contiguous for each subsampling pixel)",
|
---|
| 492 | "Separate (Y-plane/Cb-plane/Cr-plane format)"
|
---|
| 493 | );
|
---|
[6127] | 494 | }
|
---|
| 495 |
|
---|
| 496 | @Nullable
|
---|
| 497 | public String getSamplesPerPixelDescription()
|
---|
| 498 | {
|
---|
[8132] | 499 | String value = _directory.getString(TAG_SAMPLES_PER_PIXEL);
|
---|
| 500 | return value == null ? null : value + " samples/pixel";
|
---|
[6127] | 501 | }
|
---|
| 502 |
|
---|
| 503 | @Nullable
|
---|
| 504 | public String getRowsPerStripDescription()
|
---|
| 505 | {
|
---|
[8132] | 506 | final String value = _directory.getString(TAG_ROWS_PER_STRIP);
|
---|
| 507 | return value == null ? null : value + " rows/strip";
|
---|
[6127] | 508 | }
|
---|
| 509 |
|
---|
| 510 | @Nullable
|
---|
| 511 | public String getStripByteCountsDescription()
|
---|
| 512 | {
|
---|
[8132] | 513 | final String value = _directory.getString(TAG_STRIP_BYTE_COUNTS);
|
---|
| 514 | return value == null ? null : value + " bytes";
|
---|
[6127] | 515 | }
|
---|
| 516 |
|
---|
| 517 | @Nullable
|
---|
| 518 | public String getPhotometricInterpretationDescription()
|
---|
| 519 | {
|
---|
| 520 | // Shows the color space of the image data components
|
---|
[8132] | 521 | Integer value = _directory.getInteger(TAG_PHOTOMETRIC_INTERPRETATION);
|
---|
| 522 | if (value == null)
|
---|
[6127] | 523 | return null;
|
---|
| 524 | switch (value) {
|
---|
| 525 | case 0: return "WhiteIsZero";
|
---|
| 526 | case 1: return "BlackIsZero";
|
---|
| 527 | case 2: return "RGB";
|
---|
| 528 | case 3: return "RGB Palette";
|
---|
| 529 | case 4: return "Transparency Mask";
|
---|
| 530 | case 5: return "CMYK";
|
---|
| 531 | case 6: return "YCbCr";
|
---|
| 532 | case 8: return "CIELab";
|
---|
| 533 | case 9: return "ICCLab";
|
---|
| 534 | case 10: return "ITULab";
|
---|
| 535 | case 32803: return "Color Filter Array";
|
---|
| 536 | case 32844: return "Pixar LogL";
|
---|
| 537 | case 32845: return "Pixar LogLuv";
|
---|
| 538 | case 32892: return "Linear Raw";
|
---|
| 539 | default:
|
---|
| 540 | return "Unknown colour space";
|
---|
| 541 | }
|
---|
| 542 | }
|
---|
| 543 |
|
---|
| 544 | @Nullable
|
---|
| 545 | public String getBitsPerSampleDescription()
|
---|
| 546 | {
|
---|
[8132] | 547 | String value = _directory.getString(TAG_BITS_PER_SAMPLE);
|
---|
| 548 | return value == null ? null : value + " bits/component/pixel";
|
---|
[6127] | 549 | }
|
---|
| 550 |
|
---|
| 551 | @Nullable
|
---|
| 552 | public String getFocalPlaneXResolutionDescription()
|
---|
| 553 | {
|
---|
[8132] | 554 | Rational rational = _directory.getRational(TAG_FOCAL_PLANE_X_RESOLUTION);
|
---|
| 555 | if (rational == null)
|
---|
[6127] | 556 | return null;
|
---|
| 557 | final String unit = getFocalPlaneResolutionUnitDescription();
|
---|
| 558 | return rational.getReciprocal().toSimpleString(_allowDecimalRepresentationOfRationals)
|
---|
[8132] | 559 | + (unit == null ? "" : " " + unit.toLowerCase());
|
---|
[6127] | 560 | }
|
---|
| 561 |
|
---|
| 562 | @Nullable
|
---|
| 563 | public String getFocalPlaneYResolutionDescription()
|
---|
| 564 | {
|
---|
[8132] | 565 | Rational rational = _directory.getRational(TAG_FOCAL_PLANE_Y_RESOLUTION);
|
---|
| 566 | if (rational == null)
|
---|
[6127] | 567 | return null;
|
---|
| 568 | final String unit = getFocalPlaneResolutionUnitDescription();
|
---|
| 569 | return rational.getReciprocal().toSimpleString(_allowDecimalRepresentationOfRationals)
|
---|
[8132] | 570 | + (unit == null ? "" : " " + unit.toLowerCase());
|
---|
[6127] | 571 | }
|
---|
| 572 |
|
---|
| 573 | @Nullable
|
---|
| 574 | public String getFocalPlaneResolutionUnitDescription()
|
---|
| 575 | {
|
---|
[8132] | 576 | // Unit of FocalPlaneXResolution/FocalPlaneYResolution.
|
---|
| 577 | // '1' means no-unit, '2' inch, '3' centimeter.
|
---|
| 578 | return getIndexedDescription(TAG_FOCAL_PLANE_RESOLUTION_UNIT,
|
---|
| 579 | 1,
|
---|
| 580 | "(No unit)",
|
---|
| 581 | "Inches",
|
---|
| 582 | "cm"
|
---|
| 583 | );
|
---|
[6127] | 584 | }
|
---|
| 585 |
|
---|
| 586 | @Nullable
|
---|
| 587 | public String getExifImageWidthDescription()
|
---|
| 588 | {
|
---|
[8132] | 589 | final Integer value = _directory.getInteger(TAG_EXIF_IMAGE_WIDTH);
|
---|
| 590 | return value == null ? null : value + " pixels";
|
---|
[6127] | 591 | }
|
---|
| 592 |
|
---|
| 593 | @Nullable
|
---|
| 594 | public String getExifImageHeightDescription()
|
---|
| 595 | {
|
---|
[8132] | 596 | final Integer value = _directory.getInteger(TAG_EXIF_IMAGE_HEIGHT);
|
---|
| 597 | return value == null ? null : value + " pixels";
|
---|
[6127] | 598 | }
|
---|
| 599 |
|
---|
| 600 | @Nullable
|
---|
| 601 | public String getColorSpaceDescription()
|
---|
| 602 | {
|
---|
[8132] | 603 | final Integer value = _directory.getInteger(TAG_COLOR_SPACE);
|
---|
| 604 | if (value == null)
|
---|
[6127] | 605 | return null;
|
---|
| 606 | if (value == 1)
|
---|
| 607 | return "sRGB";
|
---|
| 608 | if (value == 65535)
|
---|
| 609 | return "Undefined";
|
---|
[8132] | 610 | return "Unknown (" + value + ")";
|
---|
[6127] | 611 | }
|
---|
| 612 |
|
---|
| 613 | @Nullable
|
---|
| 614 | public String getFocalLengthDescription()
|
---|
| 615 | {
|
---|
[8132] | 616 | Rational value = _directory.getRational(TAG_FOCAL_LENGTH);
|
---|
| 617 | if (value == null)
|
---|
[6127] | 618 | return null;
|
---|
| 619 | java.text.DecimalFormat formatter = new DecimalFormat("0.0##");
|
---|
| 620 | return formatter.format(value.doubleValue()) + " mm";
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | @Nullable
|
---|
| 624 | public String getFlashDescription()
|
---|
| 625 | {
|
---|
| 626 | /*
|
---|
[8132] | 627 | * This is a bit mask.
|
---|
[6127] | 628 | * 0 = flash fired
|
---|
| 629 | * 1 = return detected
|
---|
| 630 | * 2 = return able to be detected
|
---|
| 631 | * 3 = unknown
|
---|
| 632 | * 4 = auto used
|
---|
| 633 | * 5 = unknown
|
---|
| 634 | * 6 = red eye reduction used
|
---|
| 635 | */
|
---|
| 636 |
|
---|
[8132] | 637 | final Integer value = _directory.getInteger(TAG_FLASH);
|
---|
[6127] | 638 |
|
---|
[8132] | 639 | if (value == null)
|
---|
[6127] | 640 | return null;
|
---|
| 641 |
|
---|
| 642 | StringBuilder sb = new StringBuilder();
|
---|
| 643 |
|
---|
[8132] | 644 | if ((value & 0x1) != 0)
|
---|
[6127] | 645 | sb.append("Flash fired");
|
---|
| 646 | else
|
---|
| 647 | sb.append("Flash did not fire");
|
---|
| 648 |
|
---|
| 649 | // check if we're able to detect a return, before we mention it
|
---|
[8132] | 650 | if ((value & 0x4) != 0) {
|
---|
| 651 | if ((value & 0x2) != 0)
|
---|
[6127] | 652 | sb.append(", return detected");
|
---|
| 653 | else
|
---|
| 654 | sb.append(", return not detected");
|
---|
| 655 | }
|
---|
| 656 |
|
---|
[8132] | 657 | if ((value & 0x10) != 0)
|
---|
[6127] | 658 | sb.append(", auto");
|
---|
| 659 |
|
---|
[8132] | 660 | if ((value & 0x40) != 0)
|
---|
[6127] | 661 | sb.append(", red-eye reduction");
|
---|
| 662 |
|
---|
| 663 | return sb.toString();
|
---|
| 664 | }
|
---|
| 665 |
|
---|
| 666 | @Nullable
|
---|
| 667 | public String getWhiteBalanceDescription()
|
---|
| 668 | {
|
---|
| 669 | // '0' means unknown, '1' daylight, '2' fluorescent, '3' tungsten, '10' flash,
|
---|
| 670 | // '17' standard light A, '18' standard light B, '19' standard light C, '20' D55,
|
---|
| 671 | // '21' D65, '22' D75, '255' other.
|
---|
[8132] | 672 | final Integer value = _directory.getInteger(TAG_WHITE_BALANCE);
|
---|
| 673 | if (value == null)
|
---|
[6127] | 674 | return null;
|
---|
| 675 | switch (value) {
|
---|
| 676 | case 0: return "Unknown";
|
---|
| 677 | case 1: return "Daylight";
|
---|
| 678 | case 2: return "Florescent";
|
---|
| 679 | case 3: return "Tungsten";
|
---|
| 680 | case 10: return "Flash";
|
---|
| 681 | case 17: return "Standard light";
|
---|
| 682 | case 18: return "Standard light (B)";
|
---|
| 683 | case 19: return "Standard light (C)";
|
---|
| 684 | case 20: return "D55";
|
---|
| 685 | case 21: return "D65";
|
---|
| 686 | case 22: return "D75";
|
---|
| 687 | case 255: return "(Other)";
|
---|
| 688 | default:
|
---|
| 689 | return "Unknown (" + value + ")";
|
---|
| 690 | }
|
---|
| 691 | }
|
---|
| 692 |
|
---|
| 693 | @Nullable
|
---|
| 694 | public String getMeteringModeDescription()
|
---|
| 695 | {
|
---|
| 696 | // '0' means unknown, '1' average, '2' center weighted average, '3' spot
|
---|
| 697 | // '4' multi-spot, '5' multi-segment, '6' partial, '255' other
|
---|
[8132] | 698 | Integer value = _directory.getInteger(TAG_METERING_MODE);
|
---|
| 699 | if (value == null)
|
---|
[6127] | 700 | return null;
|
---|
| 701 | switch (value) {
|
---|
| 702 | case 0: return "Unknown";
|
---|
| 703 | case 1: return "Average";
|
---|
| 704 | case 2: return "Center weighted average";
|
---|
| 705 | case 3: return "Spot";
|
---|
| 706 | case 4: return "Multi-spot";
|
---|
| 707 | case 5: return "Multi-segment";
|
---|
| 708 | case 6: return "Partial";
|
---|
| 709 | case 255: return "(Other)";
|
---|
| 710 | default:
|
---|
| 711 | return "";
|
---|
| 712 | }
|
---|
| 713 | }
|
---|
| 714 |
|
---|
| 715 | @Nullable
|
---|
| 716 | public String getSubjectDistanceDescription()
|
---|
| 717 | {
|
---|
[8132] | 718 | Rational value = _directory.getRational(TAG_SUBJECT_DISTANCE);
|
---|
| 719 | if (value == null)
|
---|
[6127] | 720 | return null;
|
---|
| 721 | java.text.DecimalFormat formatter = new DecimalFormat("0.0##");
|
---|
| 722 | return formatter.format(value.doubleValue()) + " metres";
|
---|
| 723 | }
|
---|
| 724 |
|
---|
| 725 | @Nullable
|
---|
| 726 | public String getCompressedAverageBitsPerPixelDescription()
|
---|
| 727 | {
|
---|
[8132] | 728 | Rational value = _directory.getRational(TAG_COMPRESSED_AVERAGE_BITS_PER_PIXEL);
|
---|
| 729 | if (value == null)
|
---|
[6127] | 730 | return null;
|
---|
| 731 | String ratio = value.toSimpleString(_allowDecimalRepresentationOfRationals);
|
---|
[8132] | 732 | return value.isInteger() && value.intValue() == 1
|
---|
| 733 | ? ratio + " bit/pixel"
|
---|
| 734 | : ratio + " bits/pixel";
|
---|
[6127] | 735 | }
|
---|
| 736 |
|
---|
| 737 | @Nullable
|
---|
| 738 | public String getExposureTimeDescription()
|
---|
| 739 | {
|
---|
[8132] | 740 | String value = _directory.getString(TAG_EXPOSURE_TIME);
|
---|
| 741 | return value == null ? null : value + " sec";
|
---|
[6127] | 742 | }
|
---|
| 743 |
|
---|
| 744 | @Nullable
|
---|
| 745 | public String getShutterSpeedDescription()
|
---|
| 746 | {
|
---|
| 747 | // I believe this method to now be stable, but am leaving some alternative snippets of
|
---|
| 748 | // code in here, to assist anyone who's looking into this (given that I don't have a public CVS).
|
---|
| 749 |
|
---|
| 750 | // float apexValue = _directory.getFloat(ExifSubIFDDirectory.TAG_SHUTTER_SPEED);
|
---|
| 751 | // int apexPower = (int)Math.pow(2.0, apexValue);
|
---|
| 752 | // return "1/" + apexPower + " sec";
|
---|
| 753 | // TODO test this method
|
---|
| 754 | // thanks to Mark Edwards for spotting and patching a bug in the calculation of this
|
---|
| 755 | // description (spotted bug using a Canon EOS 300D)
|
---|
| 756 | // thanks also to Gli Blr for spotting this bug
|
---|
[8132] | 757 | Float apexValue = _directory.getFloatObject(TAG_SHUTTER_SPEED);
|
---|
| 758 | if (apexValue == null)
|
---|
[6127] | 759 | return null;
|
---|
[8132] | 760 | if (apexValue <= 1) {
|
---|
| 761 | float apexPower = (float)(1 / (Math.exp(apexValue * Math.log(2))));
|
---|
[6127] | 762 | long apexPower10 = Math.round((double)apexPower * 10.0);
|
---|
[8132] | 763 | float fApexPower = (float)apexPower10 / 10.0f;
|
---|
[6127] | 764 | return fApexPower + " sec";
|
---|
| 765 | } else {
|
---|
[8132] | 766 | int apexPower = (int)((Math.exp(apexValue * Math.log(2))));
|
---|
[6127] | 767 | return "1/" + apexPower + " sec";
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | /*
|
---|
| 771 | // This alternative implementation offered by Bill Richards
|
---|
| 772 | // TODO determine which is the correct / more-correct implementation
|
---|
| 773 | double apexValue = _directory.getDouble(ExifSubIFDDirectory.TAG_SHUTTER_SPEED);
|
---|
| 774 | double apexPower = Math.pow(2.0, apexValue);
|
---|
| 775 |
|
---|
| 776 | StringBuffer sb = new StringBuffer();
|
---|
| 777 | if (apexPower > 1)
|
---|
| 778 | apexPower = Math.floor(apexPower);
|
---|
| 779 |
|
---|
| 780 | if (apexPower < 1) {
|
---|
| 781 | sb.append((int)Math.round(1/apexPower));
|
---|
| 782 | } else {
|
---|
| 783 | sb.append("1/");
|
---|
| 784 | sb.append((int)apexPower);
|
---|
| 785 | }
|
---|
| 786 | sb.append(" sec");
|
---|
| 787 | return sb.toString();
|
---|
| 788 | */
|
---|
| 789 | }
|
---|
| 790 |
|
---|
| 791 | @Nullable
|
---|
| 792 | public String getFNumberDescription()
|
---|
| 793 | {
|
---|
[8132] | 794 | Rational value = _directory.getRational(TAG_FNUMBER);
|
---|
| 795 | if (value == null)
|
---|
[6127] | 796 | return null;
|
---|
| 797 | return "F" + SimpleDecimalFormatter.format(value.doubleValue());
|
---|
| 798 | }
|
---|
| 799 |
|
---|
| 800 | @Nullable
|
---|
| 801 | public String getSensingMethodDescription()
|
---|
| 802 | {
|
---|
| 803 | // '1' Not defined, '2' One-chip color area sensor, '3' Two-chip color area sensor
|
---|
| 804 | // '4' Three-chip color area sensor, '5' Color sequential area sensor
|
---|
| 805 | // '7' Trilinear sensor '8' Color sequential linear sensor, 'Other' reserved
|
---|
[8132] | 806 | return getIndexedDescription(TAG_SENSING_METHOD,
|
---|
| 807 | 1,
|
---|
| 808 | "(Not defined)",
|
---|
| 809 | "One-chip color area sensor",
|
---|
| 810 | "Two-chip color area sensor",
|
---|
| 811 | "Three-chip color area sensor",
|
---|
| 812 | "Color sequential area sensor",
|
---|
| 813 | null,
|
---|
| 814 | "Trilinear sensor",
|
---|
| 815 | "Color sequential linear sensor"
|
---|
| 816 | );
|
---|
[6127] | 817 | }
|
---|
| 818 |
|
---|
| 819 | @Nullable
|
---|
| 820 | public String getComponentConfigurationDescription()
|
---|
| 821 | {
|
---|
[8132] | 822 | int[] components = _directory.getIntArray(TAG_COMPONENTS_CONFIGURATION);
|
---|
| 823 | if (components == null)
|
---|
[6127] | 824 | return null;
|
---|
| 825 | String[] componentStrings = {"", "Y", "Cb", "Cr", "R", "G", "B"};
|
---|
| 826 | StringBuilder componentConfig = new StringBuilder();
|
---|
| 827 | for (int i = 0; i < Math.min(4, components.length); i++) {
|
---|
| 828 | int j = components[i];
|
---|
| 829 | if (j > 0 && j < componentStrings.length) {
|
---|
| 830 | componentConfig.append(componentStrings[j]);
|
---|
| 831 | }
|
---|
| 832 | }
|
---|
| 833 | return componentConfig.toString();
|
---|
| 834 | }
|
---|
| 835 | }
|
---|