Changeset 8132 in josm for trunk/src/com/drew/metadata/exif/ExifThumbnailDescriptor.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/ExifThumbnailDescriptor.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 … … 27 27 import com.drew.metadata.TagDescriptor; 28 28 29 import static com.drew.metadata.exif.ExifThumbnailDirectory.*; 30 29 31 /** 30 * Provides human-readable string representations of tag values stored in a <code>ExifThumbnailDirectory</code>.31 * 32 * @author Drew Noakes http ://drewnoakes.com32 * Provides human-readable string representations of tag values stored in a {@link ExifThumbnailDirectory}. 33 * 34 * @author Drew Noakes https://drewnoakes.com 33 35 */ 34 36 public class ExifThumbnailDescriptor extends TagDescriptor<ExifThumbnailDirectory> … … 52 54 53 55 /** 54 * Returns a descriptive value of the thespecified tag for this image.56 * Returns a descriptive value of the specified tag for this image. 55 57 * Where possible, known values will be substituted here in place of the raw 56 58 * tokens actually kept in the Exif segment. If no substitution is 57 59 * available, the value provided by getString(int) will be returned. 60 * 58 61 * @param tagType the tag to find a description for 59 62 * @return a description of the image's value for the specified tag, or 60 63 * <code>null</code> if the tag hasn't been defined. 61 64 */ 65 @Override 62 66 @Nullable 63 67 public String getDescription(int tagType) 64 68 { 65 69 switch (tagType) { 66 case ExifThumbnailDirectory.TAG_ORIENTATION:70 case TAG_ORIENTATION: 67 71 return getOrientationDescription(); 68 case ExifThumbnailDirectory.TAG_RESOLUTION_UNIT:72 case TAG_RESOLUTION_UNIT: 69 73 return getResolutionDescription(); 70 case ExifThumbnailDirectory.TAG_YCBCR_POSITIONING:74 case TAG_YCBCR_POSITIONING: 71 75 return getYCbCrPositioningDescription(); 72 case ExifThumbnailDirectory.TAG_X_RESOLUTION:76 case TAG_X_RESOLUTION: 73 77 return getXResolutionDescription(); 74 case ExifThumbnailDirectory.TAG_Y_RESOLUTION:78 case TAG_Y_RESOLUTION: 75 79 return getYResolutionDescription(); 76 case ExifThumbnailDirectory.TAG_THUMBNAIL_OFFSET:80 case TAG_THUMBNAIL_OFFSET: 77 81 return getThumbnailOffsetDescription(); 78 case ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH:82 case TAG_THUMBNAIL_LENGTH: 79 83 return getThumbnailLengthDescription(); 80 case ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_WIDTH:84 case TAG_THUMBNAIL_IMAGE_WIDTH: 81 85 return getThumbnailImageWidthDescription(); 82 case ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT:86 case TAG_THUMBNAIL_IMAGE_HEIGHT: 83 87 return getThumbnailImageHeightDescription(); 84 case ExifThumbnailDirectory.TAG_BITS_PER_SAMPLE:88 case TAG_BITS_PER_SAMPLE: 85 89 return getBitsPerSampleDescription(); 86 case ExifThumbnailDirectory.TAG_THUMBNAIL_COMPRESSION:90 case TAG_THUMBNAIL_COMPRESSION: 87 91 return getCompressionDescription(); 88 case ExifThumbnailDirectory.TAG_PHOTOMETRIC_INTERPRETATION:92 case TAG_PHOTOMETRIC_INTERPRETATION: 89 93 return getPhotometricInterpretationDescription(); 90 case ExifThumbnailDirectory.TAG_ROWS_PER_STRIP:94 case TAG_ROWS_PER_STRIP: 91 95 return getRowsPerStripDescription(); 92 case ExifThumbnailDirectory.TAG_STRIP_BYTE_COUNTS:96 case TAG_STRIP_BYTE_COUNTS: 93 97 return getStripByteCountsDescription(); 94 case ExifThumbnailDirectory.TAG_SAMPLES_PER_PIXEL:98 case TAG_SAMPLES_PER_PIXEL: 95 99 return getSamplesPerPixelDescription(); 96 case ExifThumbnailDirectory.TAG_PLANAR_CONFIGURATION:100 case TAG_PLANAR_CONFIGURATION: 97 101 return getPlanarConfigurationDescription(); 98 case ExifThumbnailDirectory.TAG_YCBCR_SUBSAMPLING:102 case TAG_YCBCR_SUBSAMPLING: 99 103 return getYCbCrSubsamplingDescription(); 100 case ExifThumbnailDirectory.TAG_REFERENCE_BLACK_WHITE:104 case TAG_REFERENCE_BLACK_WHITE: 101 105 return getReferenceBlackWhiteDescription(); 102 106 default: … … 108 112 public String getReferenceBlackWhiteDescription() 109 113 { 110 int[] ints = _directory.getIntArray( ExifThumbnailDirectory.TAG_REFERENCE_BLACK_WHITE);111 if (ints ==null)114 int[] ints = _directory.getIntArray(TAG_REFERENCE_BLACK_WHITE); 115 if (ints == null || ints.length < 6) 112 116 return null; 113 117 int blackR = ints[0]; … … 117 121 int blackB = ints[4]; 118 122 int whiteB = ints[5]; 119 return "[" + blackR + "," + blackG + "," + blackB + "] " + 120 "[" + whiteR + "," + whiteG + "," + whiteB + "]"; 123 return String.format("[%d,%d,%d] [%d,%d,%d]", blackR, blackG, blackB, whiteR, whiteG, whiteB); 121 124 } 122 125 … … 124 127 public String getYCbCrSubsamplingDescription() 125 128 { 126 int[] positions = _directory.getIntArray( ExifThumbnailDirectory.TAG_YCBCR_SUBSAMPLING);127 if (positions ==null || positions.length < 2)129 int[] positions = _directory.getIntArray(TAG_YCBCR_SUBSAMPLING); 130 if (positions == null || positions.length < 2) 128 131 return null; 129 132 if (positions[0] == 2 && positions[1] == 1) { … … 143 146 // pixel. If value is '2', Y/Cb/Cr value is separated and stored to Y plane/Cb plane/Cr 144 147 // plane format. 145 Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_PLANAR_CONFIGURATION); 146 if (value==null) 147 return null; 148 switch (value) { 149 case 1: return "Chunky (contiguous for each subsampling pixel)"; 150 case 2: return "Separate (Y-plane/Cb-plane/Cr-plane format)"; 151 default: 152 return "Unknown configuration"; 153 } 148 return getIndexedDescription(TAG_PLANAR_CONFIGURATION, 149 1, 150 "Chunky (contiguous for each subsampling pixel)", 151 "Separate (Y-plane/Cb-plane/Cr-plane format)" 152 ); 154 153 } 155 154 … … 157 156 public String getSamplesPerPixelDescription() 158 157 { 159 String value = _directory.getString( ExifThumbnailDirectory.TAG_SAMPLES_PER_PIXEL);160 return value ==null ? null : value + " samples/pixel";158 String value = _directory.getString(TAG_SAMPLES_PER_PIXEL); 159 return value == null ? null : value + " samples/pixel"; 161 160 } 162 161 … … 164 163 public String getRowsPerStripDescription() 165 164 { 166 final String value = _directory.getString( ExifThumbnailDirectory.TAG_ROWS_PER_STRIP);167 return value ==null ? null : value + " rows/strip";165 final String value = _directory.getString(TAG_ROWS_PER_STRIP); 166 return value == null ? null : value + " rows/strip"; 168 167 } 169 168 … … 171 170 public String getStripByteCountsDescription() 172 171 { 173 final String value = _directory.getString( ExifThumbnailDirectory.TAG_STRIP_BYTE_COUNTS);174 return value ==null ? null : value + " bytes";172 final String value = _directory.getString(TAG_STRIP_BYTE_COUNTS); 173 return value == null ? null : value + " bytes"; 175 174 } 176 175 … … 179 178 { 180 179 // Shows the color space of the image data components 181 Integer value = _directory.getInteger( ExifThumbnailDirectory.TAG_PHOTOMETRIC_INTERPRETATION);182 if (value ==null)180 Integer value = _directory.getInteger(TAG_PHOTOMETRIC_INTERPRETATION); 181 if (value == null) 183 182 return null; 184 183 switch (value) { … … 205 204 public String getCompressionDescription() 206 205 { 207 Integer value = _directory.getInteger( ExifThumbnailDirectory.TAG_THUMBNAIL_COMPRESSION);208 if (value ==null)206 Integer value = _directory.getInteger(TAG_THUMBNAIL_COMPRESSION); 207 if (value == null) 209 208 return null; 210 209 switch (value) { … … 244 243 public String getBitsPerSampleDescription() 245 244 { 246 String value = _directory.getString( ExifThumbnailDirectory.TAG_BITS_PER_SAMPLE);247 return value ==null ? null : value + " bits/component/pixel";245 String value = _directory.getString(TAG_BITS_PER_SAMPLE); 246 return value == null ? null : value + " bits/component/pixel"; 248 247 } 249 248 … … 251 250 public String getThumbnailImageWidthDescription() 252 251 { 253 String value = _directory.getString( ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_WIDTH);254 return value ==null ? null : value + " pixels";252 String value = _directory.getString(TAG_THUMBNAIL_IMAGE_WIDTH); 253 return value == null ? null : value + " pixels"; 255 254 } 256 255 … … 258 257 public String getThumbnailImageHeightDescription() 259 258 { 260 String value = _directory.getString( ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT);261 return value ==null ? null : value + " pixels";259 String value = _directory.getString(TAG_THUMBNAIL_IMAGE_HEIGHT); 260 return value == null ? null : value + " pixels"; 262 261 } 263 262 … … 265 264 public String getThumbnailLengthDescription() 266 265 { 267 String value = _directory.getString( ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH);268 return value ==null ? null : value + " bytes";266 String value = _directory.getString(TAG_THUMBNAIL_LENGTH); 267 return value == null ? null : value + " bytes"; 269 268 } 270 269 … … 272 271 public String getThumbnailOffsetDescription() 273 272 { 274 String value = _directory.getString( ExifThumbnailDirectory.TAG_THUMBNAIL_OFFSET);275 return value ==null ? null : value + " bytes";273 String value = _directory.getString(TAG_THUMBNAIL_OFFSET); 274 return value == null ? null : value + " bytes"; 276 275 } 277 276 … … 279 278 public String getYResolutionDescription() 280 279 { 281 Rational value = _directory.getRational( ExifThumbnailDirectory.TAG_Y_RESOLUTION);282 if (value ==null)280 Rational value = _directory.getRational(TAG_Y_RESOLUTION); 281 if (value == null) 283 282 return null; 284 283 final String unit = getResolutionDescription(); 285 284 return value.toSimpleString(_allowDecimalRepresentationOfRationals) + 286 287 (unit==null ? "unit" : unit.toLowerCase());285 " dots per " + 286 (unit == null ? "unit" : unit.toLowerCase()); 288 287 } 289 288 … … 291 290 public String getXResolutionDescription() 292 291 { 293 Rational value = _directory.getRational( ExifThumbnailDirectory.TAG_X_RESOLUTION);294 if (value ==null)292 Rational value = _directory.getRational(TAG_X_RESOLUTION); 293 if (value == null) 295 294 return null; 296 295 final String unit = getResolutionDescription(); 297 296 return value.toSimpleString(_allowDecimalRepresentationOfRationals) + 298 299 (unit==null ? "unit" : unit.toLowerCase());297 " dots per " + 298 (unit == null ? "unit" : unit.toLowerCase()); 300 299 } 301 300 … … 303 302 public String getYCbCrPositioningDescription() 304 303 { 305 Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_YCBCR_POSITIONING); 306 if (value==null) 307 return null; 308 switch (value) { 309 case 1: return "Center of pixel array"; 310 case 2: return "Datum point"; 311 default: 312 return String.valueOf(value); 313 } 304 return getIndexedDescription(TAG_YCBCR_POSITIONING, 1, "Center of pixel array", "Datum point"); 314 305 } 315 306 … … 317 308 public String getOrientationDescription() 318 309 { 319 Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_ORIENTATION); 320 if (value==null) 321 return null; 322 switch (value) { 323 case 1: return "Top, left side (Horizontal / normal)"; 324 case 2: return "Top, right side (Mirror horizontal)"; 325 case 3: return "Bottom, right side (Rotate 180)"; 326 case 4: return "Bottom, left side (Mirror vertical)"; 327 case 5: return "Left side, top (Mirror horizontal and rotate 270 CW)"; 328 case 6: return "Right side, top (Rotate 90 CW)"; 329 case 7: return "Right side, bottom (Mirror horizontal and rotate 90 CW)"; 330 case 8: return "Left side, bottom (Rotate 270 CW)"; 331 default: 332 return String.valueOf(value); 333 } 310 return getIndexedDescription(TAG_ORIENTATION, 1, 311 "Top, left side (Horizontal / normal)", 312 "Top, right side (Mirror horizontal)", 313 "Bottom, right side (Rotate 180)", 314 "Bottom, left side (Mirror vertical)", 315 "Left side, top (Mirror horizontal and rotate 270 CW)", 316 "Right side, top (Rotate 90 CW)", 317 "Right side, bottom (Mirror horizontal and rotate 90 CW)", 318 "Left side, bottom (Rotate 270 CW)"); 334 319 } 335 320 … … 338 323 { 339 324 // '1' means no-unit, '2' means inch, '3' means centimeter. Default value is '2'(inch) 340 Integer value = _directory.getInteger(ExifThumbnailDirectory.TAG_RESOLUTION_UNIT); 341 if (value==null) 342 return null; 343 switch (value) { 344 case 1: return "(No unit)"; 345 case 2: return "Inch"; 346 case 3: return "cm"; 347 default: 348 return ""; 349 } 325 return getIndexedDescription(TAG_RESOLUTION_UNIT, 1, "(No unit)", "Inch", "cm"); 350 326 } 351 327 }
Note:
See TracChangeset
for help on using the changeset viewer.