Changeset 8243 in josm for trunk/src/com/drew/metadata/exif/ExifIFD0Descriptor.java
- Timestamp:
- 2015-04-21T00:42:50+02:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/exif/ExifIFD0Descriptor.java
r8132 r8243 22 22 package com.drew.metadata.exif; 23 23 24 import com.drew.lang.Rational;25 24 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 25 33 26 /** … … 36 29 * @author Drew Noakes https://drewnoakes.com 37 30 */ 38 public class ExifIFD0Descriptor extends TagDescriptor<ExifIFD0Directory>31 public class ExifIFD0Descriptor extends ExifDescriptorBase<ExifIFD0Directory> 39 32 { 40 /**41 * Dictates whether rational values will be represented in decimal format in instances42 * where decimal notation is elegant (such as 1/2 -> 0.5, but not 1/3).43 */44 private final boolean _allowDecimalRepresentationOfRationals = true;45 46 33 public ExifIFD0Descriptor(@NotNull ExifIFD0Directory directory) 47 34 { 48 35 super(directory); 49 36 } 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 raw60 * tokens actually kept in the Exif segment. If no substitution is61 * available, the value provided by getString(int) will be returned.62 * @param tagType the tag to find a description for63 * @return a description of the image's value for the specified tag, or64 * <code>null</code> if the tag hasn't been defined.65 */66 @Override67 @Nullable68 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 @Nullable101 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 @Nullable116 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 @Nullable128 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 @Nullable140 public String getYCbCrPositioningDescription()141 {142 return getIndexedDescription(TAG_YCBCR_POSITIONING, 1, "Center of pixel array", "Datum point");143 }144 145 @Nullable146 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 @Nullable160 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 @Nullable168 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 @Nullable182 public String getWindowsAuthorDescription()183 {184 return getUnicodeDescription(TAG_WIN_AUTHOR);185 }186 187 @Nullable188 public String getWindowsCommentDescription()189 {190 return getUnicodeDescription(TAG_WIN_COMMENT);191 }192 193 @Nullable194 public String getWindowsKeywordsDescription()195 {196 return getUnicodeDescription(TAG_WIN_KEYWORDS);197 }198 199 @Nullable200 public String getWindowsTitleDescription()201 {202 return getUnicodeDescription(TAG_WIN_TITLE);203 }204 205 @Nullable206 public String getWindowsSubjectDescription()207 {208 return getUnicodeDescription(TAG_WIN_SUBJECT);209 }210 37 }
Note:
See TracChangeset
for help on using the changeset viewer.