Changeset 8132 in josm for trunk/src/com/drew/metadata/exif/ExifIFD0Descriptor.java
- Timestamp:
- 2015-03-10T01:17:39+01:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/com/drew/metadata/exif/ExifIFD0Descriptor.java
r6127 r8132 1 1 /* 2 * Copyright 2002-201 2Drew Noakes2 * Copyright 2002-2015 Drew Noakes 3 3 * 4 4 * Licensed under the Apache License, Version 2.0 (the "License"); … … 16 16 * More information about this project is available at: 17 17 * 18 * http ://drewnoakes.com/code/exif/19 * http ://code.google.com/p/metadata-extractor/18 * https://drewnoakes.com/code/exif/ 19 * https://github.com/drewnoakes/metadata-extractor 20 20 */ 21 21 … … 29 29 import java.io.UnsupportedEncodingException; 30 30 31 import static com.drew.metadata.exif.ExifIFD0Directory.*; 32 31 33 /** 32 * Provides human-readable string representations of tag values stored in a <code>ExifIFD0Directory</code>.33 * 34 * @author Drew Noakes http ://drewnoakes.com34 * Provides human-readable string representations of tag values stored in a {@link ExifIFD0Directory}. 35 * 36 * @author Drew Noakes https://drewnoakes.com 35 37 */ 36 38 public class ExifIFD0Descriptor extends TagDescriptor<ExifIFD0Directory> … … 54 56 55 57 /** 56 * Returns a descriptive value of the thespecified tag for this image.58 * Returns a descriptive value of the specified tag for this image. 57 59 * Where possible, known values will be substituted here in place of the raw 58 60 * tokens actually kept in the Exif segment. If no substitution is … … 62 64 * <code>null</code> if the tag hasn't been defined. 63 65 */ 66 @Override 64 67 @Nullable 65 68 public String getDescription(int tagType) 66 69 { 67 70 switch (tagType) { 68 case ExifIFD0Directory.TAG_RESOLUTION_UNIT:71 case TAG_RESOLUTION_UNIT: 69 72 return getResolutionDescription(); 70 case ExifIFD0Directory.TAG_YCBCR_POSITIONING:73 case TAG_YCBCR_POSITIONING: 71 74 return getYCbCrPositioningDescription(); 72 case ExifIFD0Directory.TAG_X_RESOLUTION:75 case TAG_X_RESOLUTION: 73 76 return getXResolutionDescription(); 74 case ExifIFD0Directory.TAG_Y_RESOLUTION:77 case TAG_Y_RESOLUTION: 75 78 return getYResolutionDescription(); 76 case ExifIFD0Directory.TAG_REFERENCE_BLACK_WHITE:79 case TAG_REFERENCE_BLACK_WHITE: 77 80 return getReferenceBlackWhiteDescription(); 78 case ExifIFD0Directory.TAG_ORIENTATION:81 case TAG_ORIENTATION: 79 82 return getOrientationDescription(); 80 83 81 case ExifIFD0Directory.TAG_WIN_AUTHOR:84 case TAG_WIN_AUTHOR: 82 85 return getWindowsAuthorDescription(); 83 case ExifIFD0Directory.TAG_WIN_COMMENT:86 case TAG_WIN_COMMENT: 84 87 return getWindowsCommentDescription(); 85 case ExifIFD0Directory.TAG_WIN_KEYWORDS:88 case TAG_WIN_KEYWORDS: 86 89 return getWindowsKeywordsDescription(); 87 case ExifIFD0Directory.TAG_WIN_SUBJECT:90 case TAG_WIN_SUBJECT: 88 91 return getWindowsSubjectDescription(); 89 case ExifIFD0Directory.TAG_WIN_TITLE:92 case TAG_WIN_TITLE: 90 93 return getWindowsTitleDescription(); 91 94 … … 98 101 public String getReferenceBlackWhiteDescription() 99 102 { 100 int[] ints = _directory.getIntArray( ExifIFD0Directory.TAG_REFERENCE_BLACK_WHITE);101 if (ints==null )103 int[] ints = _directory.getIntArray(TAG_REFERENCE_BLACK_WHITE); 104 if (ints==null || ints.length < 6) 102 105 return null; 103 106 int blackR = ints[0]; … … 107 110 int blackB = ints[4]; 108 111 int whiteB = ints[5]; 109 return "[" + blackR + "," + blackG + "," + blackB + "] " + 110 "[" + whiteR + "," + whiteG + "," + whiteB + "]"; 112 return String.format("[%d,%d,%d] [%d,%d,%d]", blackR, blackG, blackB, whiteR, whiteG, whiteB); 111 113 } 112 114 … … 114 116 public String getYResolutionDescription() 115 117 { 116 Rational value = _directory.getRational( ExifIFD0Directory.TAG_Y_RESOLUTION);118 Rational value = _directory.getRational(TAG_Y_RESOLUTION); 117 119 if (value==null) 118 120 return null; 119 121 final String unit = getResolutionDescription(); 120 return value.toSimpleString(_allowDecimalRepresentationOfRationals) +121 " dots per " +122 (unit==null ? "unit" : unit.toLowerCase());122 return String.format("%s dots per %s", 123 value.toSimpleString(_allowDecimalRepresentationOfRationals), 124 unit == null ? "unit" : unit.toLowerCase()); 123 125 } 124 126 … … 126 128 public String getXResolutionDescription() 127 129 { 128 Rational value = _directory.getRational( ExifIFD0Directory.TAG_X_RESOLUTION);130 Rational value = _directory.getRational(TAG_X_RESOLUTION); 129 131 if (value==null) 130 132 return null; 131 133 final String unit = getResolutionDescription(); 132 return value.toSimpleString(_allowDecimalRepresentationOfRationals) +133 " dots per " +134 (unit==null ? "unit" : unit.toLowerCase());134 return String.format("%s dots per %s", 135 value.toSimpleString(_allowDecimalRepresentationOfRationals), 136 unit == null ? "unit" : unit.toLowerCase()); 135 137 } 136 138 … … 138 140 public String getYCbCrPositioningDescription() 139 141 { 140 Integer value = _directory.getInteger(ExifIFD0Directory.TAG_YCBCR_POSITIONING); 141 if (value==null) 142 return null; 143 switch (value) { 144 case 1: return "Center of pixel array"; 145 case 2: return "Datum point"; 146 default: 147 return String.valueOf(value); 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; 148 178 } 149 179 } 150 180 151 181 @Nullable 152 public String getOrientationDescription()153 {154 Integer value = _directory.getInteger(ExifIFD0Directory.TAG_ORIENTATION);155 if (value==null)156 return null;157 switch (value) {158 case 1: return "Top, left side (Horizontal / normal)";159 case 2: return "Top, right side (Mirror horizontal)";160 case 3: return "Bottom, right side (Rotate 180)";161 case 4: return "Bottom, left side (Mirror vertical)";162 case 5: return "Left side, top (Mirror horizontal and rotate 270 CW)";163 case 6: return "Right side, top (Rotate 90 CW)";164 case 7: return "Right side, bottom (Mirror horizontal and rotate 90 CW)";165 case 8: return "Left side, bottom (Rotate 270 CW)";166 default:167 return String.valueOf(value);168 }169 }170 171 @Nullable172 public String getResolutionDescription()173 {174 // '1' means no-unit, '2' means inch, '3' means centimeter. Default value is '2'(inch)175 Integer value = _directory.getInteger(ExifIFD0Directory.TAG_RESOLUTION_UNIT);176 if (value==null)177 return null;178 switch (value) {179 case 1: return "(No unit)";180 case 2: return "Inch";181 case 3: return "cm";182 default:183 return "";184 }185 }186 187 /** The Windows specific tags uses plain Unicode. */188 @Nullable189 private String getUnicodeDescription(int tag)190 {191 byte[] commentBytes = _directory.getByteArray(tag);192 if (commentBytes==null)193 return null;194 try {195 // Decode the unicode string and trim the unicode zero "\0" from the end.196 return new String(commentBytes, "UTF-16LE").trim();197 }198 catch (UnsupportedEncodingException ex) {199 return null;200 }201 }202 203 @Nullable204 182 public String getWindowsAuthorDescription() 205 183 { 206 return getUnicodeDescription( ExifIFD0Directory.TAG_WIN_AUTHOR);184 return getUnicodeDescription(TAG_WIN_AUTHOR); 207 185 } 208 186 … … 210 188 public String getWindowsCommentDescription() 211 189 { 212 return getUnicodeDescription( ExifIFD0Directory.TAG_WIN_COMMENT);190 return getUnicodeDescription(TAG_WIN_COMMENT); 213 191 } 214 192 … … 216 194 public String getWindowsKeywordsDescription() 217 195 { 218 return getUnicodeDescription( ExifIFD0Directory.TAG_WIN_KEYWORDS);196 return getUnicodeDescription(TAG_WIN_KEYWORDS); 219 197 } 220 198 … … 222 200 public String getWindowsTitleDescription() 223 201 { 224 return getUnicodeDescription( ExifIFD0Directory.TAG_WIN_TITLE);202 return getUnicodeDescription(TAG_WIN_TITLE); 225 203 } 226 204 … … 228 206 public String getWindowsSubjectDescription() 229 207 { 230 return getUnicodeDescription( ExifIFD0Directory.TAG_WIN_SUBJECT);208 return getUnicodeDescription(TAG_WIN_SUBJECT); 231 209 } 232 210 }
Note:
See TracChangeset
for help on using the changeset viewer.