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/ExifIFD0Descriptor.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
     
    2929import java.io.UnsupportedEncodingException;
    3030
     31import static com.drew.metadata.exif.ExifIFD0Directory.*;
     32
    3133/**
    32  * Provides human-readable string representations of tag values stored in a <code>ExifIFD0Directory</code>.
    33  *
    34  * @author Drew Noakes http://drewnoakes.com
     34 * Provides human-readable string representations of tag values stored in a {@link ExifIFD0Directory}.
     35 *
     36 * @author Drew Noakes https://drewnoakes.com
    3537 */
    3638public class ExifIFD0Descriptor extends TagDescriptor<ExifIFD0Directory>
     
    5456
    5557    /**
    56      * Returns a descriptive value of the the specified tag for this image.
     58     * Returns a descriptive value of the specified tag for this image.
    5759     * Where possible, known values will be substituted here in place of the raw
    5860     * tokens actually kept in the Exif segment.  If no substitution is
     
    6264     *         <code>null</code> if the tag hasn't been defined.
    6365     */
     66    @Override
    6467    @Nullable
    6568    public String getDescription(int tagType)
    6669    {
    6770        switch (tagType) {
    68             case ExifIFD0Directory.TAG_RESOLUTION_UNIT:
     71            case TAG_RESOLUTION_UNIT:
    6972                return getResolutionDescription();
    70             case ExifIFD0Directory.TAG_YCBCR_POSITIONING:
     73            case TAG_YCBCR_POSITIONING:
    7174                return getYCbCrPositioningDescription();
    72             case ExifIFD0Directory.TAG_X_RESOLUTION:
     75            case TAG_X_RESOLUTION:
    7376                return getXResolutionDescription();
    74             case ExifIFD0Directory.TAG_Y_RESOLUTION:
     77            case TAG_Y_RESOLUTION:
    7578                return getYResolutionDescription();
    76             case ExifIFD0Directory.TAG_REFERENCE_BLACK_WHITE:
     79            case TAG_REFERENCE_BLACK_WHITE:
    7780                return getReferenceBlackWhiteDescription();
    78             case ExifIFD0Directory.TAG_ORIENTATION:
     81            case TAG_ORIENTATION:
    7982                return getOrientationDescription();
    8083
    81             case ExifIFD0Directory.TAG_WIN_AUTHOR:
     84            case TAG_WIN_AUTHOR:
    8285               return getWindowsAuthorDescription();
    83             case ExifIFD0Directory.TAG_WIN_COMMENT:
     86            case TAG_WIN_COMMENT:
    8487               return getWindowsCommentDescription();
    85             case ExifIFD0Directory.TAG_WIN_KEYWORDS:
     88            case TAG_WIN_KEYWORDS:
    8689               return getWindowsKeywordsDescription();
    87             case ExifIFD0Directory.TAG_WIN_SUBJECT:
     90            case TAG_WIN_SUBJECT:
    8891               return getWindowsSubjectDescription();
    89             case ExifIFD0Directory.TAG_WIN_TITLE:
     92            case TAG_WIN_TITLE:
    9093               return getWindowsTitleDescription();
    9194
     
    98101    public String getReferenceBlackWhiteDescription()
    99102    {
    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)
    102105            return null;
    103106        int blackR = ints[0];
     
    107110        int blackB = ints[4];
    108111        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);
    111113    }
    112114
     
    114116    public String getYResolutionDescription()
    115117    {
    116         Rational value = _directory.getRational(ExifIFD0Directory.TAG_Y_RESOLUTION);
     118        Rational value = _directory.getRational(TAG_Y_RESOLUTION);
    117119        if (value==null)
    118120            return null;
    119121        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());
    123125    }
    124126
     
    126128    public String getXResolutionDescription()
    127129    {
    128         Rational value = _directory.getRational(ExifIFD0Directory.TAG_X_RESOLUTION);
     130        Rational value = _directory.getRational(TAG_X_RESOLUTION);
    129131        if (value==null)
    130132            return null;
    131133        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());
    135137    }
    136138
     
    138140    public String getYCbCrPositioningDescription()
    139141    {
    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;
    148178        }
    149179    }
    150180
    151181    @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     @Nullable
    172     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     @Nullable
    189     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     @Nullable
    204182    public String getWindowsAuthorDescription()
    205183    {
    206        return getUnicodeDescription(ExifIFD0Directory.TAG_WIN_AUTHOR);
     184       return getUnicodeDescription(TAG_WIN_AUTHOR);
    207185    }
    208186
     
    210188    public String getWindowsCommentDescription()
    211189    {
    212        return getUnicodeDescription(ExifIFD0Directory.TAG_WIN_COMMENT);
     190       return getUnicodeDescription(TAG_WIN_COMMENT);
    213191    }
    214192
     
    216194    public String getWindowsKeywordsDescription()
    217195    {
    218        return getUnicodeDescription(ExifIFD0Directory.TAG_WIN_KEYWORDS);
     196       return getUnicodeDescription(TAG_WIN_KEYWORDS);
    219197    }
    220198
     
    222200    public String getWindowsTitleDescription()
    223201    {
    224        return getUnicodeDescription(ExifIFD0Directory.TAG_WIN_TITLE);
     202       return getUnicodeDescription(TAG_WIN_TITLE);
    225203    }
    226204
     
    228206    public String getWindowsSubjectDescription()
    229207    {
    230        return getUnicodeDescription(ExifIFD0Directory.TAG_WIN_SUBJECT);
     208       return getUnicodeDescription(TAG_WIN_SUBJECT);
    231209    }
    232210}
Note: See TracChangeset for help on using the changeset viewer.