| 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 |
|
|---|
| 22 | package com.drew.metadata.exif;
|
|---|
| 23 |
|
|---|
| 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 |
|
|---|
| 31 | import static com.drew.metadata.exif.ExifIFD0Directory.*;
|
|---|
| 32 |
|
|---|
| 33 | /**
|
|---|
| 34 | * Provides human-readable string representations of tag values stored in a {@link ExifIFD0Directory}.
|
|---|
| 35 | *
|
|---|
| 36 | * @author Drew Noakes https://drewnoakes.com
|
|---|
| 37 | */
|
|---|
| 38 | public class ExifIFD0Descriptor extends TagDescriptor<ExifIFD0Directory>
|
|---|
| 39 | {
|
|---|
| 40 | /**
|
|---|
| 41 | * Dictates whether rational values will be represented in decimal format in instances
|
|---|
| 42 | * where decimal notation is elegant (such as 1/2 -> 0.5, but not 1/3).
|
|---|
| 43 | */
|
|---|
| 44 | private final boolean _allowDecimalRepresentationOfRationals = true;
|
|---|
| 45 |
|
|---|
| 46 | public ExifIFD0Descriptor(@NotNull ExifIFD0Directory directory)
|
|---|
| 47 | {
|
|---|
| 48 | super(directory);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | // Note for the potential addition of brightness presentation in eV:
|
|---|
| 52 | // Brightness of taken subject. To calculate Exposure(Ev) from BrightnessValue(Bv),
|
|---|
| 53 | // you must add SensitivityValue(Sv).
|
|---|
| 54 | // Ev=BV+Sv Sv=log2(ISOSpeedRating/3.125)
|
|---|
| 55 | // ISO100:Sv=5, ISO200:Sv=6, ISO400:Sv=7, ISO125:Sv=5.32.
|
|---|
| 56 |
|
|---|
| 57 | /**
|
|---|
| 58 | * Returns a descriptive value of the specified tag for this image.
|
|---|
| 59 | * Where possible, known values will be substituted here in place of the raw
|
|---|
| 60 | * tokens actually kept in the Exif segment. If no substitution is
|
|---|
| 61 | * available, the value provided by getString(int) will be returned.
|
|---|
| 62 | * @param tagType the tag to find a description for
|
|---|
| 63 | * @return a description of the image's value for the specified tag, or
|
|---|
| 64 | * <code>null</code> if the tag hasn't been defined.
|
|---|
| 65 | */
|
|---|
| 66 | @Override
|
|---|
| 67 | @Nullable
|
|---|
| 68 | public String getDescription(int tagType)
|
|---|
| 69 | {
|
|---|
| 70 | switch (tagType) {
|
|---|
| 71 | case TAG_RESOLUTION_UNIT:
|
|---|
| 72 | return getResolutionDescription();
|
|---|
| 73 | case TAG_YCBCR_POSITIONING:
|
|---|
| 74 | return getYCbCrPositioningDescription();
|
|---|
| 75 | case TAG_X_RESOLUTION:
|
|---|
| 76 | return getXResolutionDescription();
|
|---|
| 77 | case TAG_Y_RESOLUTION:
|
|---|
| 78 | return getYResolutionDescription();
|
|---|
| 79 | case TAG_REFERENCE_BLACK_WHITE:
|
|---|
| 80 | return getReferenceBlackWhiteDescription();
|
|---|
| 81 | case TAG_ORIENTATION:
|
|---|
| 82 | return getOrientationDescription();
|
|---|
| 83 |
|
|---|
| 84 | case TAG_WIN_AUTHOR:
|
|---|
| 85 | return getWindowsAuthorDescription();
|
|---|
| 86 | case TAG_WIN_COMMENT:
|
|---|
| 87 | return getWindowsCommentDescription();
|
|---|
| 88 | case TAG_WIN_KEYWORDS:
|
|---|
| 89 | return getWindowsKeywordsDescription();
|
|---|
| 90 | case TAG_WIN_SUBJECT:
|
|---|
| 91 | return getWindowsSubjectDescription();
|
|---|
| 92 | case TAG_WIN_TITLE:
|
|---|
| 93 | return getWindowsTitleDescription();
|
|---|
| 94 |
|
|---|
| 95 | default:
|
|---|
| 96 | return super.getDescription(tagType);
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | @Nullable
|
|---|
| 101 | public String getReferenceBlackWhiteDescription()
|
|---|
| 102 | {
|
|---|
| 103 | int[] ints = _directory.getIntArray(TAG_REFERENCE_BLACK_WHITE);
|
|---|
| 104 | if (ints==null || ints.length < 6)
|
|---|
| 105 | return null;
|
|---|
| 106 | int blackR = ints[0];
|
|---|
| 107 | int whiteR = ints[1];
|
|---|
| 108 | int blackG = ints[2];
|
|---|
| 109 | int whiteG = ints[3];
|
|---|
| 110 | int blackB = ints[4];
|
|---|
| 111 | int whiteB = ints[5];
|
|---|
| 112 | return String.format("[%d,%d,%d] [%d,%d,%d]", blackR, blackG, blackB, whiteR, whiteG, whiteB);
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | @Nullable
|
|---|
| 116 | public String getYResolutionDescription()
|
|---|
| 117 | {
|
|---|
| 118 | Rational value = _directory.getRational(TAG_Y_RESOLUTION);
|
|---|
| 119 | if (value==null)
|
|---|
| 120 | return null;
|
|---|
| 121 | final String unit = getResolutionDescription();
|
|---|
| 122 | return String.format("%s dots per %s",
|
|---|
| 123 | value.toSimpleString(_allowDecimalRepresentationOfRationals),
|
|---|
| 124 | unit == null ? "unit" : unit.toLowerCase());
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | @Nullable
|
|---|
| 128 | public String getXResolutionDescription()
|
|---|
| 129 | {
|
|---|
| 130 | Rational value = _directory.getRational(TAG_X_RESOLUTION);
|
|---|
| 131 | if (value==null)
|
|---|
| 132 | return null;
|
|---|
| 133 | final String unit = getResolutionDescription();
|
|---|
| 134 | return String.format("%s dots per %s",
|
|---|
| 135 | value.toSimpleString(_allowDecimalRepresentationOfRationals),
|
|---|
| 136 | unit == null ? "unit" : unit.toLowerCase());
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | @Nullable
|
|---|
| 140 | public String getYCbCrPositioningDescription()
|
|---|
| 141 | {
|
|---|
| 142 | return getIndexedDescription(TAG_YCBCR_POSITIONING, 1, "Center of pixel array", "Datum point");
|
|---|
| 143 | }
|
|---|
| 144 |
|
|---|
| 145 | @Nullable
|
|---|
| 146 | public String getOrientationDescription()
|
|---|
| 147 | {
|
|---|
| 148 | return getIndexedDescription(TAG_ORIENTATION, 1,
|
|---|
| 149 | "Top, left side (Horizontal / normal)",
|
|---|
| 150 | "Top, right side (Mirror horizontal)",
|
|---|
| 151 | "Bottom, right side (Rotate 180)",
|
|---|
| 152 | "Bottom, left side (Mirror vertical)",
|
|---|
| 153 | "Left side, top (Mirror horizontal and rotate 270 CW)",
|
|---|
| 154 | "Right side, top (Rotate 90 CW)",
|
|---|
| 155 | "Right side, bottom (Mirror horizontal and rotate 90 CW)",
|
|---|
| 156 | "Left side, bottom (Rotate 270 CW)");
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | @Nullable
|
|---|
| 160 | public String getResolutionDescription()
|
|---|
| 161 | {
|
|---|
| 162 | // '1' means no-unit, '2' means inch, '3' means centimeter. Default value is '2'(inch)
|
|---|
| 163 | return getIndexedDescription(TAG_RESOLUTION_UNIT, 1, "(No unit)", "Inch", "cm");
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | /** The Windows specific tags uses plain Unicode. */
|
|---|
| 167 | @Nullable
|
|---|
| 168 | private String getUnicodeDescription(int tag)
|
|---|
| 169 | {
|
|---|
| 170 | byte[] bytes = _directory.getByteArray(tag);
|
|---|
| 171 | if (bytes == null)
|
|---|
| 172 | return null;
|
|---|
| 173 | try {
|
|---|
| 174 | // Decode the unicode string and trim the unicode zero "\0" from the end.
|
|---|
| 175 | return new String(bytes, "UTF-16LE").trim();
|
|---|
| 176 | } catch (UnsupportedEncodingException ex) {
|
|---|
| 177 | return null;
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | @Nullable
|
|---|
| 182 | public String getWindowsAuthorDescription()
|
|---|
| 183 | {
|
|---|
| 184 | return getUnicodeDescription(TAG_WIN_AUTHOR);
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | @Nullable
|
|---|
| 188 | public String getWindowsCommentDescription()
|
|---|
| 189 | {
|
|---|
| 190 | return getUnicodeDescription(TAG_WIN_COMMENT);
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | @Nullable
|
|---|
| 194 | public String getWindowsKeywordsDescription()
|
|---|
| 195 | {
|
|---|
| 196 | return getUnicodeDescription(TAG_WIN_KEYWORDS);
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | @Nullable
|
|---|
| 200 | public String getWindowsTitleDescription()
|
|---|
| 201 | {
|
|---|
| 202 | return getUnicodeDescription(TAG_WIN_TITLE);
|
|---|
| 203 | }
|
|---|
| 204 |
|
|---|
| 205 | @Nullable
|
|---|
| 206 | public String getWindowsSubjectDescription()
|
|---|
| 207 | {
|
|---|
| 208 | return getUnicodeDescription(TAG_WIN_SUBJECT);
|
|---|
| 209 | }
|
|---|
| 210 | }
|
|---|