Ignore:
Timestamp:
2013-08-09T18:05:11+02:00 (12 years ago)
Author:
bastiK
Message:

applied #8895 - Upgrade metadata-extractor to v. 2.6.4 (patch by ebourg)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/metadata/jpeg/JpegDescriptor.java

    r4231 r6127  
    11/*
    2  * This is public domain software - that is, you can do whatever you want
    3  * with it, and include it software that is licensed under the GNU or the
    4  * BSD license, or whatever other licence you choose, including proprietary
    5  * closed source licenses.  I do ask that you leave this header in tact.
     2 * Copyright 2002-2012 Drew Noakes
    63 *
    7  * If you make modifications to this code that you think would benefit the
    8  * wider community, please send me a copy and I'll post it on my site.
     4 *    Licensed under the Apache License, Version 2.0 (the "License");
     5 *    you may not use this file except in compliance with the License.
     6 *    You may obtain a copy of the License at
    97 *
    10  * If you make use of this code, I'd appreciate hearing about it.
    11  *   drew@drewnoakes.com
    12  * Latest version of this software kept at
    13  *   http://drewnoakes.com/
     8 *        http://www.apache.org/licenses/LICENSE-2.0
     9 *
     10 *    Unless required by applicable law or agreed to in writing, software
     11 *    distributed under the License is distributed on an "AS IS" BASIS,
     12 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 *    See the License for the specific language governing permissions and
     14 *    limitations under the License.
     15 *
     16 * More information about this project is available at:
     17 *
     18 *    http://drewnoakes.com/code/exif/
     19 *    http://code.google.com/p/metadata-extractor/
    1420 */
    1521package com.drew.metadata.jpeg;
    1622
    17 import com.drew.metadata.Directory;
    18 import com.drew.metadata.MetadataException;
     23import com.drew.lang.annotations.NotNull;
     24import com.drew.lang.annotations.Nullable;
    1925import com.drew.metadata.TagDescriptor;
    2026
     
    2228 * Provides human-readable string versions of the tags stored in a JpegDirectory.
    2329 * Thanks to Darrell Silver (www.darrellsilver.com) for the initial version of this class.
     30 *
     31 * @author Drew Noakes http://drewnoakes.com
    2432 */
    25 public class JpegDescriptor extends TagDescriptor
     33public class JpegDescriptor extends TagDescriptor<JpegDirectory>
    2634{
    27     public JpegDescriptor(Directory directory)
     35    public JpegDescriptor(@NotNull JpegDirectory directory)
    2836    {
    2937        super(directory);
    3038    }
    3139
    32     public String getDescription(int tagType) throws MetadataException
     40    @Nullable
     41    public String getDescription(int tagType)
    3342    {
    3443        switch (tagType)
    3544        {
     45            case JpegDirectory.TAG_JPEG_COMPRESSION_TYPE:
     46                return getImageCompressionTypeDescription();
    3647            case JpegDirectory.TAG_JPEG_COMPONENT_DATA_1:
    3748                return getComponentDataDescription(0);
     
    4859            case JpegDirectory.TAG_JPEG_IMAGE_WIDTH:
    4960                return getImageWidthDescription();
     61            default:
     62                return super.getDescription(tagType);
    5063        }
    51 
    52         return _directory.getString(tagType);
    5364    }
    5465
     66    @Nullable
     67    public String getImageCompressionTypeDescription()
     68    {
     69        Integer value = _directory.getInteger(JpegDirectory.TAG_JPEG_COMPRESSION_TYPE);
     70        if (value==null)
     71            return null;
     72        // Note there is no 2 or 12
     73        switch (value) {
     74            case 0: return "Baseline";
     75            case 1: return "Extended sequential, Huffman";
     76            case 2: return "Progressive, Huffman";
     77            case 3: return "Lossless, Huffman";
     78            case 5: return "Differential sequential, Huffman";
     79            case 6: return "Differential progressive, Huffman";
     80            case 7: return "Differential lossless, Huffman";
     81            case 8: return "Reserved for JPEG extensions";
     82            case 9: return "Extended sequential, arithmetic";
     83            case 10: return "Progressive, arithmetic";
     84            case 11: return "Lossless, arithmetic";
     85            case 13: return "Differential sequential, arithmetic";
     86            case 14: return "Differential progressive, arithmetic";
     87            case 15: return "Differential lossless, arithmetic";
     88            default:
     89                return "Unknown type: "+ value;
     90        }
     91    }
     92    @Nullable
    5593    public String getImageWidthDescription()
    5694    {
    57         return _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH) + " pixels";
     95        final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
     96        if (value==null)
     97            return null;
     98        return value + " pixels";
    5899    }
    59100
     101    @Nullable
    60102    public String getImageHeightDescription()
    61103    {
    62         return _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT) + " pixels";
     104        final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
     105        if (value==null)
     106            return null;
     107        return value + " pixels";
    63108    }
    64109
     110    @Nullable
    65111    public String getDataPrecisionDescription()
    66112    {
    67         return _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION) + " bits";
     113        final String value = _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION);
     114        if (value==null)
     115            return null;
     116        return value + " bits";
    68117    }
    69118
    70     public String getComponentDataDescription(int componentNumber) throws MetadataException
     119    @Nullable
     120    public String getComponentDataDescription(int componentNumber)
    71121    {
    72         JpegComponent component = ((JpegDirectory)_directory).getComponent(componentNumber);
     122        JpegComponent value = _directory.getComponent(componentNumber);
    73123
    74         if (component==null)
    75             throw new MetadataException("No Jpeg component exists with number " + componentNumber);
     124        if (value==null)
     125            return null;
    76126
    77         StringBuffer sb = new StringBuffer();
    78         sb.append(component.getComponentName());
     127        StringBuilder sb = new StringBuilder();
     128        sb.append(value.getComponentName());
    79129        sb.append(" component: Quantization table ");
    80         sb.append(component.getQuantizationTableNumber());
     130        sb.append(value.getQuantizationTableNumber());
    81131        sb.append(", Sampling factors ");
    82         sb.append(component.getHorizontalSamplingFactor());
     132        sb.append(value.getHorizontalSamplingFactor());
    83133        sb.append(" horiz/");
    84         sb.append(component.getVerticalSamplingFactor());
     134        sb.append(value.getVerticalSamplingFactor());
    85135        sb.append(" vert");
    86136        return sb.toString();
Note: See TracChangeset for help on using the changeset viewer.