Changeset 8132 in josm for trunk/src/com/drew/metadata/jpeg


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

fix #11162 - update to metadata-extractor 2.7.2

Location:
trunk/src/com/drew/metadata/jpeg
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/metadata/jpeg/JpegCommentDescriptor.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 */
    2121package com.drew.metadata.jpeg;
     
    2626
    2727/**
    28  * Provides human-readable string representations of tag values stored in a <code>JpegCommentDirectory</code>.
     28 * Provides human-readable string representations of tag values stored in a {@link JpegCommentDirectory}.
    2929 *
    30  * @author Drew Noakes http://drewnoakes.com
     30 * @author Drew Noakes https://drewnoakes.com
    3131 */
    3232public class JpegCommentDescriptor extends TagDescriptor<JpegCommentDirectory>
     
    4040    public String getJpegCommentDescription()
    4141    {
    42         return _directory.getString(JpegCommentDirectory.TAG_JPEG_COMMENT);
     42        return _directory.getString(JpegCommentDirectory.TAG_COMMENT);
    4343    }
    4444}
  • trunk/src/com/drew/metadata/jpeg/JpegCommentDirectory.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 */
    2121package com.drew.metadata.jpeg;
     
    2929 * Describes tags used by a JPEG file comment.
    3030 *
    31  * @author Drew Noakes http://drewnoakes.com
     31 * @author Drew Noakes https://drewnoakes.com
    3232 */
    3333public class JpegCommentDirectory extends Directory
     
    3737     * consistency with other directory types.
    3838     */
    39     public static final int TAG_JPEG_COMMENT = 0;
     39    public static final int TAG_COMMENT = 0;
    4040
    4141    @NotNull
     
    4343
    4444    static {
    45         _tagNameMap.put(TAG_JPEG_COMMENT, "Jpeg Comment");
     45        _tagNameMap.put(TAG_COMMENT, "JPEG Comment");
    4646    }
    4747
     
    5151    }
    5252
     53    @Override
    5354    @NotNull
    5455    public String getName()
     
    5758    }
    5859
     60    @Override
    5961    @NotNull
    6062    protected HashMap<Integer, String> getTagNameMap()
  • trunk/src/com/drew/metadata/jpeg/JpegCommentReader.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 */
    2121package com.drew.metadata.jpeg;
    2222
    23 import com.drew.lang.BufferBoundsException;
    24 import com.drew.lang.BufferReader;
     23import com.drew.imaging.jpeg.JpegSegmentMetadataReader;
     24import com.drew.imaging.jpeg.JpegSegmentType;
    2525import com.drew.lang.annotations.NotNull;
    2626import com.drew.metadata.Metadata;
    27 import com.drew.metadata.MetadataReader;
     27
     28import java.util.Arrays;
    2829
    2930/**
    30  * Decodes the comment stored within Jpeg files, populating a <code>Metadata</code> object with tag values in a
    31  * <code>JpegCommentDirectory</code>.
     31 * Decodes the comment stored within JPEG files, populating a {@link Metadata} object with tag values in a
     32 * {@link JpegCommentDirectory}.
    3233 *
    33  * @author Drew Noakes http://drewnoakes.com
     34 * @author Drew Noakes https://drewnoakes.com
    3435 */
    35 public class JpegCommentReader implements MetadataReader
     36public class JpegCommentReader implements JpegSegmentMetadataReader
    3637{
    37     /**
    38      * Performs the Jpeg data extraction, adding found values to the specified
    39      * instance of <code>Metadata</code>.
    40      */
    41     public void extract(@NotNull final BufferReader reader, @NotNull Metadata metadata)
     38    @NotNull
     39    public Iterable<JpegSegmentType> getSegmentTypes()
     40    {
     41        return Arrays.asList(JpegSegmentType.COM);
     42    }
     43
     44    public boolean canProcess(@NotNull byte[] segmentBytes, @NotNull JpegSegmentType segmentType)
     45    {
     46        // The entire contents of the byte[] is the comment. There's nothing here to discriminate upon.
     47        return true;
     48    }
     49
     50    public void extract(@NotNull byte[] segmentBytes, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
    4251    {
    4352        JpegCommentDirectory directory = metadata.getOrCreateDirectory(JpegCommentDirectory.class);
    4453
    45         try {
    46             directory.setString(JpegCommentDirectory.TAG_JPEG_COMMENT, reader.getString(0, (int)reader.getLength()));
    47         } catch (BufferBoundsException e) {
    48             directory.addError("Exception reading JPEG comment string");
    49         }
     54        // The entire contents of the directory are the comment
     55        directory.setString(JpegCommentDirectory.TAG_COMMENT, new String(segmentBytes));
    5056    }
    5157}
  • trunk/src/com/drew/metadata/jpeg/JpegComponent.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 */
    2121package com.drew.metadata.jpeg;
     
    2626
    2727/**
    28  * Stores information about a Jpeg image component such as the component id, horiz/vert sampling factor and
     28 * Stores information about a JPEG image component such as the component id, horiz/vert sampling factor and
    2929 * quantization table number.
    3030 *
    31  * @author Drew Noakes http://drewnoakes.com
     31 * @author Drew Noakes https://drewnoakes.com
    3232 */
    3333public class JpegComponent implements Serializable
  • trunk/src/com/drew/metadata/jpeg/JpegDescriptor.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 */
    2121package com.drew.metadata.jpeg;
     
    2929 * Thanks to Darrell Silver (www.darrellsilver.com) for the initial version of this class.
    3030 *
    31  * @author Drew Noakes http://drewnoakes.com
     31 * @author Drew Noakes https://drewnoakes.com
    3232 */
    3333public class JpegDescriptor extends TagDescriptor<JpegDirectory>
     
    3838    }
    3939
     40    @Override
    4041    @Nullable
    4142    public String getDescription(int tagType)
     
    4344        switch (tagType)
    4445        {
    45             case JpegDirectory.TAG_JPEG_COMPRESSION_TYPE:
     46            case JpegDirectory.TAG_COMPRESSION_TYPE:
    4647                return getImageCompressionTypeDescription();
    47             case JpegDirectory.TAG_JPEG_COMPONENT_DATA_1:
     48            case JpegDirectory.TAG_COMPONENT_DATA_1:
    4849                return getComponentDataDescription(0);
    49             case JpegDirectory.TAG_JPEG_COMPONENT_DATA_2:
     50            case JpegDirectory.TAG_COMPONENT_DATA_2:
    5051                return getComponentDataDescription(1);
    51             case JpegDirectory.TAG_JPEG_COMPONENT_DATA_3:
     52            case JpegDirectory.TAG_COMPONENT_DATA_3:
    5253                return getComponentDataDescription(2);
    53             case JpegDirectory.TAG_JPEG_COMPONENT_DATA_4:
     54            case JpegDirectory.TAG_COMPONENT_DATA_4:
    5455                return getComponentDataDescription(3);
    55             case JpegDirectory.TAG_JPEG_DATA_PRECISION:
     56            case JpegDirectory.TAG_DATA_PRECISION:
    5657                return getDataPrecisionDescription();
    57             case JpegDirectory.TAG_JPEG_IMAGE_HEIGHT:
     58            case JpegDirectory.TAG_IMAGE_HEIGHT:
    5859                return getImageHeightDescription();
    59             case JpegDirectory.TAG_JPEG_IMAGE_WIDTH:
     60            case JpegDirectory.TAG_IMAGE_WIDTH:
    6061                return getImageWidthDescription();
    6162            default:
     
    6768    public String getImageCompressionTypeDescription()
    6869    {
    69         Integer value = _directory.getInteger(JpegDirectory.TAG_JPEG_COMPRESSION_TYPE);
     70        Integer value = _directory.getInteger(JpegDirectory.TAG_COMPRESSION_TYPE);
    7071        if (value==null)
    7172            return null;
     
    9394    public String getImageWidthDescription()
    9495    {
    95         final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
     96        final String value = _directory.getString(JpegDirectory.TAG_IMAGE_WIDTH);
    9697        if (value==null)
    9798            return null;
     
    102103    public String getImageHeightDescription()
    103104    {
    104         final String value = _directory.getString(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
     105        final String value = _directory.getString(JpegDirectory.TAG_IMAGE_HEIGHT);
    105106        if (value==null)
    106107            return null;
     
    111112    public String getDataPrecisionDescription()
    112113    {
    113         final String value = _directory.getString(JpegDirectory.TAG_JPEG_DATA_PRECISION);
     114        final String value = _directory.getString(JpegDirectory.TAG_DATA_PRECISION);
    114115        if (value==null)
    115116            return null;
     
    125126            return null;
    126127
    127         StringBuilder sb = new StringBuilder();
    128         sb.append(value.getComponentName());
    129         sb.append(" component: Quantization table ");
    130         sb.append(value.getQuantizationTableNumber());
    131         sb.append(", Sampling factors ");
    132         sb.append(value.getHorizontalSamplingFactor());
    133         sb.append(" horiz/");
    134         sb.append(value.getVerticalSamplingFactor());
    135         sb.append(" vert");
    136         return sb.toString();
     128        return value.getComponentName() + " component: Quantization table " + value.getQuantizationTableNumber()
     129            + ", Sampling factors " + value.getHorizontalSamplingFactor()
     130            + " horiz/" + value.getVerticalSamplingFactor() + " vert";
    137131    }
    138132}
  • trunk/src/com/drew/metadata/jpeg/JpegDirectory.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 */
    2121package com.drew.metadata.jpeg;
     
    2929
    3030/**
    31  * Directory of tags and values for the SOF0 Jpeg segment.  This segment holds basic metadata about the image.
     31 * Directory of tags and values for the SOF0 JPEG segment.  This segment holds basic metadata about the image.
    3232 *
    33  * @author Darrell Silver http://www.darrellsilver.com and Drew Noakes http://drewnoakes.com
     33 * @author Darrell Silver http://www.darrellsilver.com and Drew Noakes https://drewnoakes.com
    3434 */
    3535public class JpegDirectory extends Directory
    3636{
    37     public static final int TAG_JPEG_COMPRESSION_TYPE = -3;
     37    public static final int TAG_COMPRESSION_TYPE = -3;
    3838    /** This is in bits/sample, usually 8 (12 and 16 not supported by most software). */
    39     public static final int TAG_JPEG_DATA_PRECISION = 0;
     39    public static final int TAG_DATA_PRECISION = 0;
    4040    /** The image's height.  Necessary for decoding the image, so it should always be there. */
    41     public static final int TAG_JPEG_IMAGE_HEIGHT = 1;
     41    public static final int TAG_IMAGE_HEIGHT = 1;
    4242    /** The image's width.  Necessary for decoding the image, so it should always be there. */
    43     public static final int TAG_JPEG_IMAGE_WIDTH = 3;
     43    public static final int TAG_IMAGE_WIDTH = 3;
    4444    /**
    4545     * Usually 1 = grey scaled, 3 = color YcbCr or YIQ, 4 = color CMYK
     
    4848     * sampling factors (1byte) (bit 0-3 vertical., 4-7 horizontal.),
    4949     * quantization table number (1 byte).
    50      * <p/>
     50     * <p>
    5151     * This info is from http://www.funducode.com/freec/Fileformats/format3/format3b.htm
    5252     */
    53     public static final int TAG_JPEG_NUMBER_OF_COMPONENTS = 5;
     53    public static final int TAG_NUMBER_OF_COMPONENTS = 5;
    5454
    5555    // NOTE!  Component tag type int values must increment in steps of 1
    5656
    57     /** the first of a possible 4 color components.  Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS. */
    58     public static final int TAG_JPEG_COMPONENT_DATA_1 = 6;
    59     /** the second of a possible 4 color components.  Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS. */
    60     public static final int TAG_JPEG_COMPONENT_DATA_2 = 7;
    61     /** the third of a possible 4 color components.  Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS. */
    62     public static final int TAG_JPEG_COMPONENT_DATA_3 = 8;
    63     /** the fourth of a possible 4 color components.  Number of components specified in TAG_JPEG_NUMBER_OF_COMPONENTS. */
    64     public static final int TAG_JPEG_COMPONENT_DATA_4 = 9;
     57    /** the first of a possible 4 color components.  Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
     58    public static final int TAG_COMPONENT_DATA_1 = 6;
     59    /** the second of a possible 4 color components.  Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
     60    public static final int TAG_COMPONENT_DATA_2 = 7;
     61    /** the third of a possible 4 color components.  Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
     62    public static final int TAG_COMPONENT_DATA_3 = 8;
     63    /** the fourth of a possible 4 color components.  Number of components specified in TAG_NUMBER_OF_COMPONENTS. */
     64    public static final int TAG_COMPONENT_DATA_4 = 9;
    6565
    6666    @NotNull
     
    6868
    6969    static {
    70         _tagNameMap.put(TAG_JPEG_COMPRESSION_TYPE, "Compression Type");
    71         _tagNameMap.put(TAG_JPEG_DATA_PRECISION, "Data Precision");
    72         _tagNameMap.put(TAG_JPEG_IMAGE_WIDTH, "Image Width");
    73         _tagNameMap.put(TAG_JPEG_IMAGE_HEIGHT, "Image Height");
    74         _tagNameMap.put(TAG_JPEG_NUMBER_OF_COMPONENTS, "Number of Components");
    75         _tagNameMap.put(TAG_JPEG_COMPONENT_DATA_1, "Component 1");
    76         _tagNameMap.put(TAG_JPEG_COMPONENT_DATA_2, "Component 2");
    77         _tagNameMap.put(TAG_JPEG_COMPONENT_DATA_3, "Component 3");
    78         _tagNameMap.put(TAG_JPEG_COMPONENT_DATA_4, "Component 4");
     70        _tagNameMap.put(TAG_COMPRESSION_TYPE, "Compression Type");
     71        _tagNameMap.put(TAG_DATA_PRECISION, "Data Precision");
     72        _tagNameMap.put(TAG_IMAGE_WIDTH, "Image Width");
     73        _tagNameMap.put(TAG_IMAGE_HEIGHT, "Image Height");
     74        _tagNameMap.put(TAG_NUMBER_OF_COMPONENTS, "Number of Components");
     75        _tagNameMap.put(TAG_COMPONENT_DATA_1, "Component 1");
     76        _tagNameMap.put(TAG_COMPONENT_DATA_2, "Component 2");
     77        _tagNameMap.put(TAG_COMPONENT_DATA_3, "Component 3");
     78        _tagNameMap.put(TAG_COMPONENT_DATA_4, "Component 4");
    7979    }
    8080
     
    8484    }
    8585
     86    @Override
    8687    @NotNull
    8788    public String getName()
    8889    {
    89         return "Jpeg";
     90        return "JPEG";
    9091    }
    9192
     93    @Override
    9294    @NotNull
    9395    protected HashMap<Integer, String> getTagNameMap()
     
    104106    public JpegComponent getComponent(int componentNumber)
    105107    {
    106         int tagType = JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + componentNumber;
     108        int tagType = JpegDirectory.TAG_COMPONENT_DATA_1 + componentNumber;
    107109        return (JpegComponent)getObject(tagType);
    108110    }
     
    110112    public int getImageWidth() throws MetadataException
    111113    {
    112         return getInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
     114        return getInt(JpegDirectory.TAG_IMAGE_WIDTH);
    113115    }
    114116
    115117    public int getImageHeight() throws MetadataException
    116118    {
    117         return getInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
     119        return getInt(JpegDirectory.TAG_IMAGE_HEIGHT);
    118120    }
    119121
    120122    public int getNumberOfComponents() throws MetadataException
    121123    {
    122         return getInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS);
     124        return getInt(JpegDirectory.TAG_NUMBER_OF_COMPONENTS);
    123125    }
    124126}
  • trunk/src/com/drew/metadata/jpeg/JpegReader.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 */
    2121package com.drew.metadata.jpeg;
    2222
    23 import com.drew.lang.BufferBoundsException;
    24 import com.drew.lang.BufferReader;
     23import com.drew.imaging.jpeg.JpegSegmentMetadataReader;
     24import com.drew.imaging.jpeg.JpegSegmentType;
     25import com.drew.lang.SequentialByteArrayReader;
     26import com.drew.lang.SequentialReader;
    2527import com.drew.lang.annotations.NotNull;
    2628import com.drew.metadata.Metadata;
    27 import com.drew.metadata.MetadataReader;
     29
     30import java.io.IOException;
     31import java.util.Arrays;
    2832
    2933/**
    30  * Decodes Jpeg SOF0 data, populating a <code>Metadata</code> object with tag values in a <code>JpegDirectory</code>.
     34 * Decodes JPEG SOFn data, populating a {@link Metadata} object with tag values in a {@link JpegDirectory}.
    3135 *
    32  * @author Darrell Silver http://www.darrellsilver.com and Drew Noakes http://drewnoakes.com
     36 * @author Drew Noakes https://drewnoakes.com
     37 * @author Darrell Silver http://www.darrellsilver.com
    3338 */
    34 public class JpegReader implements MetadataReader
     39public class JpegReader implements JpegSegmentMetadataReader
    3540{
    36     /**
    37      * Performs the Jpeg data extraction, adding found values to the specified
    38      * instance of <code>Metadata</code>.
    39      */
    40     public void extract(@NotNull final BufferReader reader, @NotNull Metadata metadata)
     41    @NotNull
     42    public Iterable<JpegSegmentType> getSegmentTypes()
    4143    {
     44        // NOTE that some SOFn values do not exist
     45        return Arrays.asList(
     46            JpegSegmentType.SOF0,
     47            JpegSegmentType.SOF1,
     48            JpegSegmentType.SOF2,
     49            JpegSegmentType.SOF3,
     50//            JpegSegmentType.SOF4,
     51            JpegSegmentType.SOF5,
     52            JpegSegmentType.SOF6,
     53            JpegSegmentType.SOF7,
     54            JpegSegmentType.SOF8,
     55            JpegSegmentType.SOF9,
     56            JpegSegmentType.SOF10,
     57            JpegSegmentType.SOF11,
     58//            JpegSegmentType.SOF12,
     59            JpegSegmentType.SOF13,
     60            JpegSegmentType.SOF14,
     61            JpegSegmentType.SOF15
     62        );
     63    }
     64
     65    public boolean canProcess(@NotNull byte[] segmentBytes, @NotNull JpegSegmentType segmentType)
     66    {
     67        return true;
     68    }
     69
     70    public void extract(@NotNull byte[] segmentBytes, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType)
     71    {
     72        if (metadata.containsDirectory(JpegDirectory.class)) {
     73            // If this directory is already present, discontinue this operation.
     74            // We only store metadata for the *first* matching SOFn segment.
     75            return;
     76        }
     77
    4278        JpegDirectory directory = metadata.getOrCreateDirectory(JpegDirectory.class);
    4379
     80        // The value of TAG_COMPRESSION_TYPE is determined by the segment type found
     81        directory.setInt(JpegDirectory.TAG_COMPRESSION_TYPE, segmentType.byteValue - JpegSegmentType.SOF0.byteValue);
     82
     83        SequentialReader reader = new SequentialByteArrayReader(segmentBytes);
     84
    4485        try {
    45             // data precision
    46             int dataPrecision = reader.getUInt8(JpegDirectory.TAG_JPEG_DATA_PRECISION);
    47             directory.setInt(JpegDirectory.TAG_JPEG_DATA_PRECISION, dataPrecision);
    48 
    49             // process height
    50             int height = reader.getUInt16(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT);
    51             directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_HEIGHT, height);
    52 
    53             // process width
    54             int width = reader.getUInt16(JpegDirectory.TAG_JPEG_IMAGE_WIDTH);
    55             directory.setInt(JpegDirectory.TAG_JPEG_IMAGE_WIDTH, width);
    56 
    57             // number of components
    58             int numberOfComponents = reader.getUInt8(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS);
    59             directory.setInt(JpegDirectory.TAG_JPEG_NUMBER_OF_COMPONENTS, numberOfComponents);
     86            directory.setInt(JpegDirectory.TAG_DATA_PRECISION, reader.getUInt8());
     87            directory.setInt(JpegDirectory.TAG_IMAGE_HEIGHT, reader.getUInt16());
     88            directory.setInt(JpegDirectory.TAG_IMAGE_WIDTH, reader.getUInt16());
     89            short componentCount = reader.getUInt8();
     90            directory.setInt(JpegDirectory.TAG_NUMBER_OF_COMPONENTS, componentCount);
    6091
    6192            // for each component, there are three bytes of data:
     
    6394            // 2 - Sampling factors: bit 0-3 vertical, 4-7 horizontal
    6495            // 3 - Quantization table number
    65             int offset = 6;
    66             for (int i = 0; i < numberOfComponents; i++) {
    67                 int componentId = reader.getUInt8(offset++);
    68                 int samplingFactorByte = reader.getUInt8(offset++);
    69                 int quantizationTableNumber = reader.getUInt8(offset++);
    70                 JpegComponent component = new JpegComponent(componentId, samplingFactorByte, quantizationTableNumber);
    71                 directory.setObject(JpegDirectory.TAG_JPEG_COMPONENT_DATA_1 + i, component);
     96            for (int i = 0; i < (int)componentCount; i++) {
     97                final int componentId = reader.getUInt8();
     98                final int samplingFactorByte = reader.getUInt8();
     99                final int quantizationTableNumber = reader.getUInt8();
     100                final JpegComponent component = new JpegComponent(componentId, samplingFactorByte, quantizationTableNumber);
     101                directory.setObject(JpegDirectory.TAG_COMPONENT_DATA_1 + i, component);
    72102            }
    73103
    74         } catch (BufferBoundsException ex) {
     104        } catch (IOException ex) {
    75105            directory.addError(ex.getMessage());
    76106        }
Note: See TracChangeset for help on using the changeset viewer.