Ignore:
Timestamp:
2015-03-10T01:17:39+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #11162 - update to metadata-extractor 2.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/metadata/exif/ExifThumbnailDescriptor.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    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
    2020 */
    2121
     
    2727import com.drew.metadata.TagDescriptor;
    2828
     29import static com.drew.metadata.exif.ExifThumbnailDirectory.*;
     30
    2931/**
    30  * Provides human-readable string representations of tag values stored in a <code>ExifThumbnailDirectory</code>.
    31  *
    32  * @author Drew Noakes http://drewnoakes.com
     32 * Provides human-readable string representations of tag values stored in a {@link ExifThumbnailDirectory}.
     33 *
     34 * @author Drew Noakes https://drewnoakes.com
    3335 */
    3436public class ExifThumbnailDescriptor extends TagDescriptor<ExifThumbnailDirectory>
     
    5254
    5355    /**
    54      * Returns a descriptive value of the the specified tag for this image.
     56     * Returns a descriptive value of the specified tag for this image.
    5557     * Where possible, known values will be substituted here in place of the raw
    5658     * tokens actually kept in the Exif segment.  If no substitution is
    5759     * available, the value provided by getString(int) will be returned.
     60     *
    5861     * @param tagType the tag to find a description for
    5962     * @return a description of the image's value for the specified tag, or
    6063     *         <code>null</code> if the tag hasn't been defined.
    6164     */
     65    @Override
    6266    @Nullable
    6367    public String getDescription(int tagType)
    6468    {
    6569        switch (tagType) {
    66             case ExifThumbnailDirectory.TAG_ORIENTATION:
     70            case TAG_ORIENTATION:
    6771                return getOrientationDescription();
    68             case ExifThumbnailDirectory.TAG_RESOLUTION_UNIT:
     72            case TAG_RESOLUTION_UNIT:
    6973                return getResolutionDescription();
    70             case ExifThumbnailDirectory.TAG_YCBCR_POSITIONING:
     74            case TAG_YCBCR_POSITIONING:
    7175                return getYCbCrPositioningDescription();
    72             case ExifThumbnailDirectory.TAG_X_RESOLUTION:
     76            case TAG_X_RESOLUTION:
    7377                return getXResolutionDescription();
    74             case ExifThumbnailDirectory.TAG_Y_RESOLUTION:
     78            case TAG_Y_RESOLUTION:
    7579                return getYResolutionDescription();
    76             case ExifThumbnailDirectory.TAG_THUMBNAIL_OFFSET:
     80            case TAG_THUMBNAIL_OFFSET:
    7781                return getThumbnailOffsetDescription();
    78             case ExifThumbnailDirectory.TAG_THUMBNAIL_LENGTH:
     82            case TAG_THUMBNAIL_LENGTH:
    7983                return getThumbnailLengthDescription();
    80             case ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_WIDTH:
     84            case TAG_THUMBNAIL_IMAGE_WIDTH:
    8185                return getThumbnailImageWidthDescription();
    82             case ExifThumbnailDirectory.TAG_THUMBNAIL_IMAGE_HEIGHT:
     86            case TAG_THUMBNAIL_IMAGE_HEIGHT:
    8387                return getThumbnailImageHeightDescription();
    84             case ExifThumbnailDirectory.TAG_BITS_PER_SAMPLE:
     88            case TAG_BITS_PER_SAMPLE:
    8589                return getBitsPerSampleDescription();
    86             case ExifThumbnailDirectory.TAG_THUMBNAIL_COMPRESSION:
     90            case TAG_THUMBNAIL_COMPRESSION:
    8791                return getCompressionDescription();
    88             case ExifThumbnailDirectory.TAG_PHOTOMETRIC_INTERPRETATION:
     92            case TAG_PHOTOMETRIC_INTERPRETATION:
    8993                return getPhotometricInterpretationDescription();
    90             case ExifThumbnailDirectory.TAG_ROWS_PER_STRIP:
     94            case TAG_ROWS_PER_STRIP:
    9195                return getRowsPerStripDescription();
    92             case ExifThumbnailDirectory.TAG_STRIP_BYTE_COUNTS:
     96            case TAG_STRIP_BYTE_COUNTS:
    9397                return getStripByteCountsDescription();
    94             case ExifThumbnailDirectory.TAG_SAMPLES_PER_PIXEL:
     98            case TAG_SAMPLES_PER_PIXEL:
    9599                return getSamplesPerPixelDescription();
    96             case ExifThumbnailDirectory.TAG_PLANAR_CONFIGURATION:
     100            case TAG_PLANAR_CONFIGURATION:
    97101                return getPlanarConfigurationDescription();
    98             case ExifThumbnailDirectory.TAG_YCBCR_SUBSAMPLING:
     102            case TAG_YCBCR_SUBSAMPLING:
    99103                return getYCbCrSubsamplingDescription();
    100             case ExifThumbnailDirectory.TAG_REFERENCE_BLACK_WHITE:
     104            case TAG_REFERENCE_BLACK_WHITE:
    101105                return getReferenceBlackWhiteDescription();
    102106            default:
     
    108112    public String getReferenceBlackWhiteDescription()
    109113    {
    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)
    112116            return null;
    113117        int blackR = ints[0];
     
    117121        int blackB = ints[4];
    118122        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);
    121124    }
    122125
     
    124127    public String getYCbCrSubsamplingDescription()
    125128    {
    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)
    128131            return null;
    129132        if (positions[0] == 2 && positions[1] == 1) {
     
    143146        // pixel. If value is '2', Y/Cb/Cr value is separated and stored to Y plane/Cb plane/Cr
    144147        // 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        );
    154153    }
    155154
     
    157156    public String getSamplesPerPixelDescription()
    158157    {
    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";
    161160    }
    162161
     
    164163    public String getRowsPerStripDescription()
    165164    {
    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";
    168167    }
    169168
     
    171170    public String getStripByteCountsDescription()
    172171    {
    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";
    175174    }
    176175
     
    179178    {
    180179        // 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)
    183182            return null;
    184183        switch (value) {
     
    205204    public String getCompressionDescription()
    206205    {
    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)
    209208            return null;
    210209        switch (value) {
     
    244243    public String getBitsPerSampleDescription()
    245244    {
    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";
    248247    }
    249248
     
    251250    public String getThumbnailImageWidthDescription()
    252251    {
    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";
    255254    }
    256255
     
    258257    public String getThumbnailImageHeightDescription()
    259258    {
    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";
    262261    }
    263262
     
    265264    public String getThumbnailLengthDescription()
    266265    {
    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";
    269268    }
    270269
     
    272271    public String getThumbnailOffsetDescription()
    273272    {
    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";
    276275    }
    277276
     
    279278    public String getYResolutionDescription()
    280279    {
    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)
    283282            return null;
    284283        final String unit = getResolutionDescription();
    285284        return value.toSimpleString(_allowDecimalRepresentationOfRationals) +
    286                 " dots per " +
    287                 (unit==null ? "unit" : unit.toLowerCase());
     285            " dots per " +
     286            (unit == null ? "unit" : unit.toLowerCase());
    288287    }
    289288
     
    291290    public String getXResolutionDescription()
    292291    {
    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)
    295294            return null;
    296295        final String unit = getResolutionDescription();
    297296        return value.toSimpleString(_allowDecimalRepresentationOfRationals) +
    298                 " dots per " +
    299                 (unit==null ? "unit" : unit.toLowerCase());
     297            " dots per " +
     298            (unit == null ? "unit" : unit.toLowerCase());
    300299    }
    301300
     
    303302    public String getYCbCrPositioningDescription()
    304303    {
    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");
    314305    }
    315306
     
    317308    public String getOrientationDescription()
    318309    {
    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)");
    334319    }
    335320
     
    338323    {
    339324        // '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");
    350326    }
    351327}
Note: See TracChangeset for help on using the changeset viewer.