You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by da...@apache.org on 2012/02/18 07:43:35 UTC

svn commit: r1245871 [1/5] - in /commons/proper/sanselan/trunk: ./ src/main/java/org/apache/commons/sanselan/common/ src/main/java/org/apache/commons/sanselan/formats/jpeg/ src/main/java/org/apache/commons/sanselan/formats/tiff/ src/main/java/org/apach...

Author: damjan
Date: Sat Feb 18 06:43:33 2012
New Revision: 1245871

URL: http://svn.apache.org/viewvc?rev=1245871&view=rev
Log:
Many TIFF cleanups. Subclassed TagInfo for
each possible combination of allowed types,
and made each TIFF tag constant one of those
subclasses. Deleted TiffOutputField.create()
and instead added TiffOutputDirectory.add(),
which is overloaded for each possible
combination of TagInfo subclass and the
Java type that can be written into it.
Similarly changed TiffDirectory so
TIFF types can be read with strong
typing.

Short/short[] is now handled properly
inside the TIFF implementation, instead of
always converting to Integer/int[].

Converted tests and internal code
to the new API where possible.

This essentially adds a high-level
type-safe API for reading and writing
TIFF/EXIF metadata, that's easy to use,
works with IDE code completion,
maybe the first of its kind.

Jira issue key : SANSELAN-31


Added:
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConversions.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfo.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAny.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAscii.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByte.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByteOrShort.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoDouble.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoFloat.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoLong.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoRational.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSByte.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSLong.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSRational.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSShort.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShort.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLong.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLongOrRational.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrRational.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoText.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUndefined.java   (with props)
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUnknown.java   (with props)
    commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/tiff/TiffTagIntegrityTest.java   (with props)
Removed:
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/TagHolder.java
    commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/WriteTagsTest.java
Modified:
    commons/proper/sanselan/trunk/RELEASE_NOTES
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageMetadata.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffContents.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffDirectory.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffField.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageMetadata.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageParser.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffReader.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/AllTagConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/ExifTagConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/GpsTagConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/TagConstantsUtils.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/TagInfo.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/TiffFieldTypeConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/TiffTagConstants.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/datareaders/DataReader.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/fieldtypes/FieldTypeAscii.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/fieldtypes/FieldTypeShort.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterLossless.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputDirectory.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputField.java
    commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputSet.java
    commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/MetadataExample.java
    commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/examples/WriteExifMetadataExample.java
    commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/AsciiFieldTest.java
    commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/MakerNoteFieldTest.java
    commons/proper/sanselan/trunk/src/test/java/org/apache/commons/sanselan/formats/jpeg/exif/TextFieldTest.java

Modified: commons/proper/sanselan/trunk/RELEASE_NOTES
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/RELEASE_NOTES?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/RELEASE_NOTES (original)
+++ commons/proper/sanselan/trunk/RELEASE_NOTES Sat Feb 18 06:43:33 2012
@@ -43,6 +43,7 @@ Release 0.98
  * SANSELAN-59 - deleted confusing redefinition of some constants.
  * Altered TIFF tag searching to do an exact directory match when possible.
  * SANSELAN-48 - added support for reading and writing CCITT Modified Huffman, Group 3 and Group 4 images.
+ * SANSELAN-31 - added a high level type-safe API for reading and writing EXIF fields.
 
 Release 0.97
 ------------

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConversions.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConversions.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConversions.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConversions.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,362 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.sanselan.common;
+
+public class BinaryConversions implements BinaryConstants {
+    public static byte[] convertToByteArray(short[] values, int byteOrder) {
+        return convertToByteArray(values, 0, values.length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(short[] values, int length, int byteOrder) {
+        return convertToByteArray(values, 0, length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(short[] values, int offset, int length, int byteOrder) {
+        byte[] result = new byte[length * 2];
+        for (int i = 0; i < length; i++) {
+            short value = values[offset + i];
+            int start = i * 2;
+            if (byteOrder == BYTE_ORDER_MOTOROLA) {
+                result[start + 0] = (byte) (value >> 8);
+                result[start + 1] = (byte) (value >> 0);
+            } else {
+                result[start + 1] = (byte) (value >> 8);
+                result[start + 0] = (byte) (value >> 0);
+            }
+        }
+        return result;
+    }
+    
+    public static byte[] convertToByteArray(int[] values, int byteOrder) {
+        return convertToByteArray(values, 0, values.length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(int[] values, int length, int byteOrder) {
+        return convertToByteArray(values, 0, length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(int[] values, int offset, int length, int byteOrder) {
+        byte[] result = new byte[length * 4];
+        for (int i = 0; i < length; i++) {
+            int value = values[offset + i];
+            int start = i * 4;
+            if (byteOrder == BYTE_ORDER_MOTOROLA) {
+                result[start + 0] = (byte) (value >> 24);
+                result[start + 1] = (byte) (value >> 16);
+                result[start + 2] = (byte) (value >> 8);
+                result[start + 3] = (byte) (value >> 0);
+            } else {
+                result[start + 3] = (byte) (value >> 24);
+                result[start + 2] = (byte) (value >> 16);
+                result[start + 1] = (byte) (value >> 8);
+                result[start + 0] = (byte) (value >> 0);
+            }
+        }
+        return result;
+    }
+
+    public static byte[] convertToByteArray(float[] values, int byteOrder) {
+        return convertToByteArray(values, 0, values.length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(float[] values, int length, int byteOrder) {
+        return convertToByteArray(values, 0, length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(float[] values, int offset, int length, int byteOrder) {
+        byte[] result = new byte[values.length * 4];
+        for (int i = 0; i < values.length; i++) {
+            float value = values[i];
+            int bits = Float.floatToRawIntBits(value);
+            int start = i * 4;
+            if (byteOrder == BYTE_ORDER_INTEL) {
+                result[start + 0] = (byte) (0xff & (bits >> 0));
+                result[start + 1] = (byte) (0xff & (bits >> 8));
+                result[start + 2] = (byte) (0xff & (bits >> 16));
+                result[start + 3] = (byte) (0xff & (bits >> 24));
+            } else {
+                result[start + 3] = (byte) (0xff & (bits >> 0));
+                result[start + 2] = (byte) (0xff & (bits >> 8));
+                result[start + 1] = (byte) (0xff & (bits >> 16));
+                result[start + 0] = (byte) (0xff & (bits >> 24));
+            }
+        }
+        return result;
+    }
+    
+    public static byte[] convertToByteArray(double[] values, int byteOrder) {
+        return convertToByteArray(values, 0, values.length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(double[] values, int length, int byteOrder) {
+        return convertToByteArray(values, 0, length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(double[] values, int offset, int length, int byteOrder) {
+        byte[] result = new byte[length * 8];
+        for (int i = 0; i < length; i++) {
+            double value = values[offset + i];
+            long bits = Double.doubleToRawLongBits(value);
+            int start = i * 8;
+            if (byteOrder == BYTE_ORDER_INTEL) {
+                result[start + 0] = (byte) (0xff & (bits >> 0));
+                result[start + 1] = (byte) (0xff & (bits >> 8));
+                result[start + 2] = (byte) (0xff & (bits >> 16));
+                result[start + 3] = (byte) (0xff & (bits >> 24));
+                result[start + 4] = (byte) (0xff & (bits >> 32));
+                result[start + 5] = (byte) (0xff & (bits >> 40));
+                result[start + 6] = (byte) (0xff & (bits >> 48));
+                result[start + 7] = (byte) (0xff & (bits >> 56));
+            } else {
+                result[start + 7] = (byte) (0xff & (bits >> 0));
+                result[start + 6] = (byte) (0xff & (bits >> 8));
+                result[start + 5] = (byte) (0xff & (bits >> 16));
+                result[start + 4] = (byte) (0xff & (bits >> 24));
+                result[start + 3] = (byte) (0xff & (bits >> 32));
+                result[start + 2] = (byte) (0xff & (bits >> 40));
+                result[start + 1] = (byte) (0xff & (bits >> 48));
+                result[start + 0] = (byte) (0xff & (bits >> 56));
+            }
+        }
+        return result;
+    }
+    
+    public static byte[] convertToByteArray(RationalNumber[] values, int byteOrder) {
+        return convertToByteArray(values, 0, values.length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(RationalNumber[] values, int length, int byteOrder) {
+        return convertToByteArray(values, 0, length, byteOrder);
+    }
+    
+    public static byte[] convertToByteArray(RationalNumber[] values, int offset, int length, int byteOrder) {
+        byte[] result = new byte[length * 8];
+        for (int i = 0; i < length; i++) {
+            RationalNumber value = values[offset + i];
+            int start = i * 8;
+            if (byteOrder == BYTE_ORDER_MOTOROLA) {
+                result[start + 0] = (byte) (value.numerator >> 24);
+                result[start + 1] = (byte) (value.numerator >> 16);
+                result[start + 2] = (byte) (value.numerator >> 8);
+                result[start + 3] = (byte) (value.numerator >> 0);
+                result[start + 4] = (byte) (value.divisor >> 24);
+                result[start + 5] = (byte) (value.divisor >> 16);
+                result[start + 6] = (byte) (value.divisor >> 8);
+                result[start + 7] = (byte) (value.divisor >> 0);
+            } else {
+                result[start + 3] = (byte) (value.numerator >> 24);
+                result[start + 2] = (byte) (value.numerator >> 16);
+                result[start + 1] = (byte) (value.numerator >> 8);
+                result[start + 0] = (byte) (value.numerator >> 0);
+                result[start + 7] = (byte) (value.divisor >> 24);
+                result[start + 6] = (byte) (value.divisor >> 16);
+                result[start + 5] = (byte) (value.divisor >> 8);
+                result[start + 4] = (byte) (value.divisor >> 0);
+            }
+        }
+        return result;
+    }
+
+    public static short convertToShort(byte[] bytes, int byteOrder) {
+        return convertToShort(bytes, 0, byteOrder);
+    }
+    
+    public static short convertToShort(byte[] bytes, int offset, int byteOrder) {
+        int byte0 = 0xff & bytes[offset + 0];
+        int byte1 = 0xff & bytes[offset + 1];
+        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+            return (short) ((byte0 << 8) | byte1);
+        } else {
+            return (short) ((byte1 << 8) | byte0);
+        }
+    }
+    
+    public static short[] convertToShortArray(byte[] bytes, int byteOrder) {
+        return convertToShortArray(bytes, 0, bytes.length, byteOrder);
+    }
+    
+    public static short[] convertToShortArray(byte[] bytes, int length, int byteOrder) {
+        return convertToShortArray(bytes, 0, length, byteOrder);
+    }
+    
+    public static short[] convertToShortArray(byte[] bytes, int offset, int length, int byteOrder) {
+        short[] result = new short[length / 2];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = convertToShort(bytes, offset + 2*i, byteOrder);
+        }
+        return result;
+    }
+
+    public static int convertToInt(byte[] bytes, int byteOrder) {
+        return convertToInt(bytes, 0, byteOrder);
+    }
+    
+    public static int convertToInt(byte[] bytes, int offset, int byteOrder) {
+        int byte0 = 0xff & bytes[offset + 0];
+        int byte1 = 0xff & bytes[offset + 1];
+        int byte2 = 0xff & bytes[offset + 2];
+        int byte3 = 0xff & bytes[offset + 3];
+        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+            return (byte0 << 24) | (byte1 << 16) |
+                    (byte2 << 8) | byte3;
+        } else {
+            return (byte3 << 24) | (byte2 << 16) |
+                    (byte1 << 8) | byte0;
+        }
+    }
+    
+    public static int[] convertToIntArray(byte[] bytes, int byteOrder) {
+        return convertToIntArray(bytes, 0, bytes.length, byteOrder);
+    }
+    
+    public static int[] convertToIntArray(byte[] bytes, int length, int byteOrder) {
+        return convertToIntArray(bytes, 0, length, byteOrder);
+    }
+    
+    public static int[] convertToIntArray(byte[] bytes, int offset, int length, int byteOrder) {
+        int[] result = new int[length / 4];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = convertToInt(bytes, offset + 4*i, byteOrder);
+        }
+        return result;
+    }
+    
+    public static float convertToFloat(byte[] bytes, int byteOrder) {
+        return convertToFloat(bytes, 0, byteOrder);
+    }
+    
+    public static float convertToFloat(byte[] bytes, int offset, int byteOrder) {
+        int byte0 = 0xff & bytes[offset + 0];
+        int byte1 = 0xff & bytes[offset + 1];
+        int byte2 = 0xff & bytes[offset + 2];
+        int byte3 = 0xff & bytes[offset + 3];
+        int bits;
+        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+            bits = (byte0 << 24) | (byte1 << 16) |
+                    (byte2 << 8) | (byte3 << 0);
+        } else {
+            bits = (byte3 << 24) | (byte2 << 16) |
+                    (byte1 << 8) | (byte0 << 0);
+        }
+        return Float.intBitsToFloat(bits);
+    }
+    
+    public static float[] convertToFloatArray(byte[] bytes, int byteOrder) {
+        return convertToFloatArray(bytes, 0, bytes.length, byteOrder);
+    }
+    
+    public static float[] convertToFloatArray(byte[] bytes, int length, int byteOrder) {
+        return convertToFloatArray(bytes, 0, length, byteOrder);
+    }
+
+    public static float[] convertToFloatArray(byte[] bytes, int offset, int length, int byteOrder) {
+        float[] result = new float[length / 4];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = convertToFloat(bytes, offset + 4*i, byteOrder);
+        }
+        return result;
+    }
+    
+    public static double convertToDouble(byte[] bytes, int byteOrder) {
+        return convertToDouble(bytes, 0, byteOrder);
+    }
+    
+    public static double convertToDouble(byte[] bytes, int offset, int byteOrder) {
+        long byte0 = 0xffL & bytes[offset + 0];
+        long byte1 = 0xffL & bytes[offset + 1];
+        long byte2 = 0xffL & bytes[offset + 2];
+        long byte3 = 0xffL & bytes[offset + 3];
+        long byte4 = 0xffL & bytes[offset + 4];
+        long byte5 = 0xffL & bytes[offset + 5];
+        long byte6 = 0xffL & bytes[offset + 6];
+        long byte7 = 0xffL & bytes[offset + 7];
+        long bits;
+        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+            bits = (byte0 << 56) | (byte1 << 48) |
+                    (byte2 << 40) | (byte3 << 32) |
+                    (byte4 << 24) | (byte5 << 16) |
+                    (byte6 << 8) | (byte7 << 0);
+        } else {
+            bits = (byte7 << 56) | (byte6 << 48) |
+                    (byte5 << 40) | (byte4 << 32) |
+                    (byte3 << 24) | (byte2 << 16) |
+                    (byte1 << 8) | (byte0 << 0);
+        }
+        return Double.longBitsToDouble(bits);
+    }
+    
+    public static double[] convertToDoubleArray(byte[] bytes, int byteOrder) {
+        return convertToDoubleArray(bytes, 0, bytes.length, byteOrder);
+    }
+    
+    public static double[] convertToDoubleArray(byte[] bytes, int length, int byteOrder) {
+        return convertToDoubleArray(bytes, 0, length, byteOrder);
+    }
+    
+    public static double[] convertToDoubleArray(byte[] bytes, int offset, int length, int byteOrder) {
+        double[] result = new double[length / 8];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = convertToDouble(bytes, offset + 8*i, byteOrder);
+        }
+        return result;
+    }
+    
+    public static RationalNumber convertToRational(byte[] bytes, int byteOrder) {
+        return convertToRational(bytes, 0, byteOrder);
+    }
+    
+    public static RationalNumber convertToRational(byte[] bytes, int offset, int byteOrder) {
+        int byte0 = 0xff & bytes[offset + 0];
+        int byte1 = 0xff & bytes[offset + 1];
+        int byte2 = 0xff & bytes[offset + 2];
+        int byte3 = 0xff & bytes[offset + 3];
+        int byte4 = 0xff & bytes[offset + 4];
+        int byte5 = 0xff & bytes[offset + 5];
+        int byte6 = 0xff & bytes[offset + 6];
+        int byte7 = 0xff & bytes[offset + 7];
+        int numerator;
+        int divisor;
+        if (byteOrder == BYTE_ORDER_MOTOROLA) {
+            numerator = (byte0 << 24) | (byte1 << 16) |
+                    (byte2 << 8) | byte3;
+            divisor = (byte4 << 24) | (byte5 << 16) |
+                    (byte6 << 8) | byte7;
+        } else {
+            numerator = (byte3 << 24) | (byte2 << 16) |
+                    (byte1 << 8) | byte0;
+            divisor = (byte7 << 24) | (byte6 << 16) |
+                    (byte5 << 8) | byte4;
+        }
+        return new RationalNumber(numerator, divisor);
+    }
+    
+    public static RationalNumber[] convertToRationalArray(byte[] bytes, int byteOrder) {
+        return convertToRationalArray(bytes, 0, bytes.length, byteOrder);
+    }
+    
+    public static RationalNumber[] convertToRationalArray(byte[] bytes, int length, int byteOrder) {
+        return convertToRationalArray(bytes, 0, length, byteOrder);
+    }
+    
+    public static RationalNumber[] convertToRationalArray(byte[] bytes, int offset, int length, int byteOrder) {
+        RationalNumber[] result = new RationalNumber[length / 8];
+        for (int i = 0; i < result.length; i++) {
+            result[i] = convertToRational(bytes, offset + 8*i, byteOrder);
+        }
+        return result;
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/common/BinaryConversions.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageMetadata.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageMetadata.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageMetadata.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageMetadata.java Sat Feb 18 06:43:33 2012
@@ -32,7 +32,7 @@ import org.apache.commons.sanselan.forma
 import org.apache.commons.sanselan.formats.tiff.TiffField;
 import org.apache.commons.sanselan.formats.tiff.TiffImageData;
 import org.apache.commons.sanselan.formats.tiff.TiffImageMetadata;
-import org.apache.commons.sanselan.formats.tiff.constants.TagInfo;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
 import org.apache.commons.sanselan.util.Debug;
 
 public class JpegImageMetadata implements IImageMetadata {

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/jpeg/JpegImageParser.java Sat Feb 18 06:43:33 2012
@@ -734,19 +734,19 @@ public class JpegImageParser extends Ima
             {
                 {
                     TiffField field = metadata
-                            .findEXIFValue(TiffTagConstants.XRESOLUTION.tagInfo);
+                            .findEXIFValue(TiffTagConstants.TIFF_TAG_XRESOLUTION);
                     if (field != null)
                         x_density = ((Number) field.getValue()).doubleValue();
                 }
                 {
                     TiffField field = metadata
-                            .findEXIFValue(TiffTagConstants.YRESOLUTION.tagInfo);
+                            .findEXIFValue(TiffTagConstants.TIFF_TAG_YRESOLUTION);
                     if (field != null)
                         y_density = ((Number) field.getValue()).doubleValue();
                 }
                 {
                     TiffField field = metadata
-                            .findEXIFValue(TiffTagConstants.RESOLUTION_UNIT.tagInfo);
+                            .findEXIFValue(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT);
                     if (field != null)
                     {
                         int density_units = ((Number) field.getValue())

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffContents.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffContents.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffContents.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffContents.java Sat Feb 18 06:43:33 2012
@@ -21,7 +21,7 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.commons.sanselan.ImageReadException;
-import org.apache.commons.sanselan.formats.tiff.constants.TagInfo;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
 import org.apache.commons.sanselan.util.Debug;
 
 public class TiffContents

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffDirectory.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffDirectory.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffDirectory.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffDirectory.java Sat Feb 18 06:43:33 2012
@@ -23,9 +23,21 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.sanselan.ImageReadException;
-import org.apache.commons.sanselan.formats.tiff.constants.TagInfo;
+import org.apache.commons.sanselan.common.RationalNumber;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffConstants;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffTagConstants;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoAscii;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoByte;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoDouble;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoFloat;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoLong;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoRational;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoSByte;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoSLong;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoSRational;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoSShort;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoShort;
 
 public class TiffDirectory extends TiffElement implements TiffConstants
 //extends BinaryFileFunctions
@@ -121,7 +133,7 @@ public class TiffDirectory extends TiffE
 
     public boolean hasJpegImageData() throws ImageReadException
     {
-        if (null != findField(TiffTagConstants.JPEG_INTERCHANGE_FORMAT.tagInfo))
+        if (null != findField(TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT))
             return true;
 
         return false;
@@ -129,10 +141,10 @@ public class TiffDirectory extends TiffE
 
     public boolean hasTiffImageData() throws ImageReadException
     {
-        if (null != findField(TiffTagConstants.TILE_OFFSETS.tagInfo))
+        if (null != findField(TiffTagConstants.TIFF_TAG_TILE_OFFSETS))
             return true;
 
-        if (null != findField(TiffTagConstants.STRIP_OFFSETS.tagInfo))
+        if (null != findField(TiffTagConstants.TIFF_TAG_STRIP_OFFSETS))
             return true;
 
         return false;
@@ -178,7 +190,145 @@ public class TiffDirectory extends TiffE
 
         return null;
     }
-
+    
+    public Object getFieldValue(TagInfo tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        return field.getValue();
+    }
+    
+    public byte[] getFieldValue(TagInfoByte tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        return field.fieldType.getRawBytes(field);
+    }
+    
+    public String[] getFieldValue(TagInfoAscii tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
+    public short[] getFieldValue(TagInfoShort tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
+    public int[] getFieldValue(TagInfoLong tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
+    public RationalNumber[] getFieldValue(TagInfoRational tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
+    public byte[] getFieldValue(TagInfoSByte tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        return field.fieldType.getRawBytes(field);
+    }
+    
+    public short[] getFieldValue(TagInfoSShort tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
+    public int[] getFieldValue(TagInfoSLong tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
+    public RationalNumber[] getFieldValue(TagInfoSRational tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
+    public float[] getFieldValue(TagInfoFloat tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
+    public double[] getFieldValue(TagInfoDouble tag) throws ImageReadException {
+        TiffField field = findField(tag);
+        if (field == null) {
+            return null;
+        }
+        if (!tag.dataTypes.contains(field.fieldType)) {
+            return null;
+        }
+        byte[] bytes = field.fieldType.getRawBytes(field);
+        return tag.getValue(field.byteOrder, bytes);
+    }
+    
     public final class ImageDataElement extends TiffElement
     {
         public ImageDataElement(int offset, int length)
@@ -214,10 +364,10 @@ public class TiffDirectory extends TiffE
 
     public List<ImageDataElement> getTiffRawImageDataElements() throws ImageReadException
     {
-        TiffField tileOffsets = findField(TiffTagConstants.TILE_OFFSETS.tagInfo);
-        TiffField tileByteCounts = findField(TiffTagConstants.TILE_BYTE_COUNTS.tagInfo);
-        TiffField stripOffsets = findField(TiffTagConstants.STRIP_OFFSETS.tagInfo);
-        TiffField stripByteCounts = findField(TiffTagConstants.STRIP_BYTE_COUNTS.tagInfo);
+        TiffField tileOffsets = findField(TiffTagConstants.TIFF_TAG_TILE_OFFSETS);
+        TiffField tileByteCounts = findField(TiffTagConstants.TIFF_TAG_TILE_BYTE_COUNTS);
+        TiffField stripOffsets = findField(TiffTagConstants.TIFF_TAG_STRIP_OFFSETS);
+        TiffField stripByteCounts = findField(TiffTagConstants.TIFF_TAG_STRIP_BYTE_COUNTS);
 
         if ((tileOffsets != null) && (tileByteCounts != null))
         {
@@ -233,10 +383,10 @@ public class TiffDirectory extends TiffE
 
     public boolean imageDataInStrips() throws ImageReadException
     {
-        TiffField tileOffsets = findField(TiffTagConstants.TILE_OFFSETS.tagInfo);
-        TiffField tileByteCounts = findField(TiffTagConstants.TILE_BYTE_COUNTS.tagInfo);
-        TiffField stripOffsets = findField(TiffTagConstants.STRIP_OFFSETS.tagInfo);
-        TiffField stripByteCounts = findField(TiffTagConstants.STRIP_BYTE_COUNTS.tagInfo);
+        TiffField tileOffsets = findField(TiffTagConstants.TIFF_TAG_TILE_OFFSETS);
+        TiffField tileByteCounts = findField(TiffTagConstants.TIFF_TAG_TILE_BYTE_COUNTS);
+        TiffField stripOffsets = findField(TiffTagConstants.TIFF_TAG_STRIP_OFFSETS);
+        TiffField stripByteCounts = findField(TiffTagConstants.TIFF_TAG_STRIP_BYTE_COUNTS);
 
         if ((tileOffsets != null) && (tileByteCounts != null))
             return false;
@@ -251,8 +401,8 @@ public class TiffDirectory extends TiffE
     public ImageDataElement getJpegRawImageDataElement()
             throws ImageReadException
     {
-        TiffField jpegInterchangeFormat = findField(TiffTagConstants.JPEG_INTERCHANGE_FORMAT.tagInfo);
-        TiffField jpegInterchangeFormatLength = findField(TiffTagConstants.JPEG_INTERCHANGE_FORMAT_LENGTH.tagInfo);
+        TiffField jpegInterchangeFormat = findField(TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT);
+        TiffField jpegInterchangeFormatLength = findField(TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
 
         if ((jpegInterchangeFormat != null)
                 && (jpegInterchangeFormatLength != null))

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffField.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffField.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffField.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffField.java Sat Feb 18 06:43:33 2012
@@ -30,11 +30,11 @@ import org.apache.commons.sanselan.Image
 import org.apache.commons.sanselan.common.bytesource.ByteSource;
 import org.apache.commons.sanselan.formats.tiff.constants.ExifTagConstants;
 import org.apache.commons.sanselan.formats.tiff.constants.GpsTagConstants;
-import org.apache.commons.sanselan.formats.tiff.constants.TagInfo;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffConstants;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffTagConstants;
 import org.apache.commons.sanselan.formats.tiff.fieldtypes.FieldType;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
 
 public class TiffField implements TiffConstants
 {
@@ -111,9 +111,9 @@ public class TiffField implements TiffCo
 
     private static FieldType getFieldType(int value)
     {
-        for (int i = 0; i < FIELD_TYPES.length; i++)
+        for (int i = 0; i < FIELD_TYPES.size(); i++)
         {
-            FieldType fieldType = FIELD_TYPES[i];
+            FieldType fieldType = FIELD_TYPES.get(i);
             if (fieldType.type == value)
                 return fieldType;
         }
@@ -196,7 +196,7 @@ public class TiffField implements TiffCo
         // return tagInfo;
         // }
 
-        return TiffTagConstants.UNKNOWN.tagInfo;
+        return TiffTagConstants.TIFF_TAG_UNKNOWN;
 
         // if (true)
         // throw new Error("Why didn't this algorithm work?");
@@ -259,7 +259,7 @@ public class TiffField implements TiffCo
 
         if (null == possibleMatches)
         {
-            return TiffTagConstants.UNKNOWN.tagInfo;
+            return TiffTagConstants.TIFF_TAG_UNKNOWN;
         }
 
         TagInfo result = getTag(directoryType, tag, possibleMatches);
@@ -362,6 +362,26 @@ public class TiffField implements TiffCo
         // }
         // return result.toString();
         // }
+        else if (o instanceof short[])
+        {
+            short values[] = (short[]) o;
+            StringBuffer result = new StringBuffer();
+
+            for (int i = 0; i < values.length; i++)
+            {
+                short value = values[i];
+
+                if (i > 50)
+                {
+                    result.append("... (" + values.length + ")");
+                    break;
+                }
+                if (i > 0)
+                    result.append(", ");
+                result.append("" + value);
+            }
+            return result.toString();
+        }
         else if (o instanceof int[])
         {
             int values[] = (int[]) o;
@@ -550,7 +570,7 @@ public class TiffField implements TiffCo
 
     public String getTagName()
     {
-        if (tagInfo == TiffTagConstants.UNKNOWN.tagInfo)
+        if (tagInfo == TiffTagConstants.TIFF_TAG_UNKNOWN)
             return tagInfo.name + " (0x" + Integer.toHexString(tag) + ")";
         return tagInfo.name;
     }
@@ -663,6 +683,12 @@ public class TiffField implements TiffCo
             for (int i = 0; i < numbers.length; i++)
                 result[i] = numbers[i].intValue();
             return result;
+        } else if (o instanceof short[]) {
+            short numbers[] = (short[]) o;
+            int result[] = new int[numbers.length];
+            for (int i = 0; i < numbers.length; i++)
+                result[i] = 0xffff & numbers[i];
+            return result;
         } else if (o instanceof int[])
         {
             int numbers[] = (int[]) o;
@@ -693,6 +719,12 @@ public class TiffField implements TiffCo
             for (int i = 0; i < numbers.length; i++)
                 result[i] = numbers[i].doubleValue();
             return result;
+        } else if (o instanceof short[]) {
+            short numbers[] = (short[]) o;
+            double result[] = new double[numbers.length];
+            for (int i = 0; i < numbers.length; i++)
+                result[i] = numbers[i];
+            return result;
         } else if (o instanceof int[])
         {
             int numbers[] = (int[]) o;
@@ -729,15 +761,19 @@ public class TiffField implements TiffCo
 
         if (o instanceof Number)
             return ((Number) o).intValue();
-        else if (o instanceof Number[])
-        {
+        else if (o instanceof Number[]) {
             Number numbers[] = (Number[]) o;
             int sum = 0;
             for (int i = 0; i < numbers.length; i++)
                 sum += numbers[i].intValue();
             return sum;
-        } else if (o instanceof int[])
-        {
+        } else if (o instanceof short[]) {
+            short[] numbers = (short[]) o;
+            int sum = 0;
+            for (int i = 0; i < numbers.length; i++)
+                sum += numbers[i];
+            return sum;
+        } else if (o instanceof int[]) {
             int numbers[] = (int[]) o;
             int sum = 0;
             for (int i = 0; i < numbers.length; i++)

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageMetadata.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageMetadata.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageMetadata.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageMetadata.java Sat Feb 18 06:43:33 2012
@@ -29,10 +29,10 @@ import org.apache.commons.sanselan.commo
 import org.apache.commons.sanselan.common.RationalNumber;
 import org.apache.commons.sanselan.formats.tiff.constants.AllTagConstants;
 import org.apache.commons.sanselan.formats.tiff.constants.GpsTagConstants;
-import org.apache.commons.sanselan.formats.tiff.constants.TagInfo;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryConstants;
 import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
 import org.apache.commons.sanselan.formats.tiff.fieldtypes.FieldType;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
 import org.apache.commons.sanselan.formats.tiff.write.TiffOutputDirectory;
 import org.apache.commons.sanselan.formats.tiff.write.TiffOutputField;
 import org.apache.commons.sanselan.formats.tiff.write.TiffOutputSet;
@@ -127,7 +127,7 @@ public class TiffImageMetadata extends I
         {
             try
             {
-                TiffOutputDirectory dstDir = new TiffOutputDirectory(type);
+                TiffOutputDirectory dstDir = new TiffOutputDirectory(type, byteOrder);
 
                 List<? extends IImageMetadataItem> entries = getItems();
                 for (int i = 0; i < entries.size(); i++)
@@ -141,7 +141,7 @@ public class TiffImageMetadata extends I
                         // ignore duplicate tags in a directory.
                         continue;
                     }
-                    else if (srcField.tagInfo instanceof TagInfo.Offset)
+                    else if (srcField.tagInfo.isOffset())
                     {
                         // ignore offset fields.
                         continue;
@@ -340,13 +340,13 @@ public class TiffImageMetadata extends I
 
         // more specific example of how to access GPS values.
         TiffField latitudeRefField = gpsDirectory
-                .findField(GpsTagConstants.GPS_LATITUDE_REF.tagInfo);
+                .findField(GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF);
         TiffField latitudeField = gpsDirectory
-                .findField(GpsTagConstants.GPS_LATITUDE.tagInfo);
+                .findField(GpsTagConstants.GPS_TAG_GPS_LATITUDE);
         TiffField longitudeRefField = gpsDirectory
-                .findField(GpsTagConstants.GPS_LONGITUDE_REF.tagInfo);
+                .findField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF);
         TiffField longitudeField = gpsDirectory
-                .findField(GpsTagConstants.GPS_LONGITUDE.tagInfo);
+                .findField(GpsTagConstants.GPS_TAG_GPS_LONGITUDE);
 
         if (latitudeRefField == null || latitudeField == null
                 || longitudeRefField == null || longitudeField == null)

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageParser.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageParser.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffImageParser.java Sat Feb 18 06:43:33 2012
@@ -90,10 +90,7 @@ public class TiffImageParser extends Ima
                 .readFirstDirectory(byteSource, params, false, formatCompliance);
         TiffDirectory directory = contents.directories.get(0);
 
-        TiffField field = directory.findField(ExifTagConstants.ICC_PROFILE.tagInfo);
-        if (null == field)
-            return null;
-        return field.oversizeValue;
+        return directory.getFieldValue(ExifTagConstants.EXIF_TAG_ICC_PROFILE);
     }
 
     public Dimension getImageSize(ByteSource byteSource, Map params)
@@ -104,8 +101,15 @@ public class TiffImageParser extends Ima
                 .readFirstDirectory(byteSource, params, false, formatCompliance);
         TiffDirectory directory = contents.directories.get(0);
 
-        int width = directory.findField(TiffTagConstants.IMAGE_WIDTH.tagInfo).getIntValue();
-        int height = directory.findField(TiffTagConstants.IMAGE_LENGTH.tagInfo).getIntValue();
+        TiffField widthField = directory.findField(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, true);
+        TiffField heightField = directory
+                .findField(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, true);
+
+        if ((widthField == null) || (heightField == null))
+            throw new ImageReadException("TIFF image missing size info.");
+
+        int height = heightField.getIntValue();
+        int width = widthField.getIntValue();
 
         return new Dimension(width, height);
     }
@@ -159,9 +163,9 @@ public class TiffImageParser extends Ima
                 .readDirectories(byteSource, false, formatCompliance);
         TiffDirectory directory = contents.directories.get(0);
 
-        TiffField widthField = directory.findField(TiffTagConstants.IMAGE_WIDTH.tagInfo, true);
+        TiffField widthField = directory.findField(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, true);
         TiffField heightField = directory
-                .findField(TiffTagConstants.IMAGE_LENGTH.tagInfo, true);
+                .findField(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, true);
 
         if ((widthField == null) || (heightField == null))
             throw new ImageReadException("TIFF image missing size info.");
@@ -172,7 +176,7 @@ public class TiffImageParser extends Ima
         // -------------------
 
         TiffField resolutionUnitField = directory
-                .findField(TiffTagConstants.RESOLUTION_UNIT.tagInfo);
+                .findField(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT);
         int resolutionUnit = 2; // Inch
         if ((resolutionUnitField != null)
                 && (resolutionUnitField.getValue() != null))
@@ -193,8 +197,8 @@ public class TiffImageParser extends Ima
             break;
 
         }
-        TiffField xResolutionField = directory.findField(TiffTagConstants.XRESOLUTION.tagInfo);
-        TiffField yResolutionField = directory.findField(TiffTagConstants.YRESOLUTION.tagInfo);
+        TiffField xResolutionField = directory.findField(TiffTagConstants.TIFF_TAG_XRESOLUTION);
+        TiffField yResolutionField = directory.findField(TiffTagConstants.TIFF_TAG_YRESOLUTION);
 
         int physicalWidthDpi = -1;
         float physicalWidthInch = -1;
@@ -224,7 +228,7 @@ public class TiffImageParser extends Ima
         // -------------------
 
         TiffField bitsPerSampleField = directory
-                .findField(TiffTagConstants.BITS_PER_SAMPLE.tagInfo);
+                .findField(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE);
 
         int bitsPerSample = 1;
         if ((bitsPerSampleField != null)
@@ -257,13 +261,13 @@ public class TiffImageParser extends Ima
 
         boolean isTransparent = false; // TODO: wrong
         boolean usesPalette = false;
-        TiffField colorMapField = directory.findField(TiffTagConstants.COLOR_MAP.tagInfo);
+        TiffField colorMapField = directory.findField(TiffTagConstants.TIFF_TAG_COLOR_MAP);
         if (colorMapField != null)
             usesPalette = true;
 
         int colorType = ImageInfo.COLOR_TYPE_RGB;
 
-        int compression = directory.findField(TiffTagConstants.COMPRESSION.tagInfo)
+        int compression = directory.findField(TiffTagConstants.TIFF_TAG_COMPRESSION)
                 .getIntValue();
         String compressionAlgorithm;
 
@@ -315,11 +319,10 @@ public class TiffImageParser extends Ima
                 .readDirectories(byteSource, false, formatCompliance);
         TiffDirectory directory = contents.directories.get(0);
 
-        TiffField xmpField = directory.findField(TiffTagConstants.XMP.tagInfo, false);
-        if (xmpField == null)
+        byte bytes[] = directory.getFieldValue(TiffTagConstants.TIFF_TAG_XMP);
+        if (bytes == null) {
             return null;
-
-        byte bytes[] = xmpField.getByteArrayValue();
+        }
 
         try
         {
@@ -473,20 +476,20 @@ public class TiffImageParser extends Ima
             throw new ImageReadException("TIFF missing entries");
 
         int photometricInterpretation = directory.findField(
-                TiffTagConstants.PHOTOMETRIC_INTERPRETATION.tagInfo, true).getIntValue();
-        int compression = directory.findField(TiffTagConstants.COMPRESSION.tagInfo, true)
+                TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION, true).getIntValue();
+        int compression = directory.findField(TiffTagConstants.TIFF_TAG_COMPRESSION, true)
                 .getIntValue();
-        int width = directory.findField(TiffTagConstants.IMAGE_WIDTH.tagInfo, true)
+        int width = directory.findField(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, true)
                 .getIntValue();
-        int height = directory.findField(TiffTagConstants.IMAGE_LENGTH.tagInfo, true)
+        int height = directory.findField(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, true)
                 .getIntValue();
         int samplesPerPixel = 1;
-        TiffField samplesPerPixelField = directory.findField(TiffTagConstants.SAMPLES_PER_PIXEL.tagInfo);
+        TiffField samplesPerPixelField = directory.findField(TiffTagConstants.TIFF_TAG_SAMPLES_PER_PIXEL);
         if (samplesPerPixelField != null)
             samplesPerPixel = samplesPerPixelField.getIntValue();
         int bitsPerSample[] = { 1 };
         int bitsPerPixel = samplesPerPixel;
-        TiffField bitsPerSampleField = directory.findField(TiffTagConstants.BITS_PER_SAMPLE.tagInfo);
+        TiffField bitsPerSampleField = directory.findField(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE);
         if (bitsPerSampleField != null)
         {
             bitsPerSample = bitsPerSampleField.getIntArrayValue();
@@ -503,7 +506,7 @@ public class TiffImageParser extends Ima
             // dumpOptionalNumberTag(entries, TIFF_TAG_FREE_OFFSETS);
             // dumpOptionalNumberTag(entries, TIFF_TAG_ORIENTATION);
             // dumpOptionalNumberTag(entries, TIFF_TAG_PLANAR_CONFIGURATION);
-            TiffField predictorField = directory.findField(TiffTagConstants.PREDICTOR.tagInfo);
+            TiffField predictorField = directory.findField(TiffTagConstants.TIFF_TAG_PREDICTOR);
             if (null != predictorField)
                 predictor = predictorField.getIntValueOrArraySum();
         }
@@ -550,7 +553,7 @@ public class TiffImageParser extends Ima
                     invert);
         case 3: // Palette
         {
-            int colorMap[] = directory.findField(TiffTagConstants.COLOR_MAP.tagInfo, true)
+            int colorMap[] = directory.findField(TiffTagConstants.TIFF_TAG_COLOR_MAP, true)
                     .getIntArrayValue();
 
             int expected_colormap_size = 3 * (1 << bitsPerPixel);
@@ -572,15 +575,15 @@ public class TiffImageParser extends Ima
         case 6: //
         {
             double yCbCrCoefficients[] = directory.findField(
-                    TiffTagConstants.YCBCR_COEFFICIENTS.tagInfo, true).getDoubleArrayValue();
+                    TiffTagConstants.TIFF_TAG_YCBCR_COEFFICIENTS, true).getDoubleArrayValue();
 
             int yCbCrPositioning[] = directory.findField(
-                    TiffTagConstants.YCBCR_POSITIONING.tagInfo, true).getIntArrayValue();
+                    TiffTagConstants.TIFF_TAG_YCBCR_POSITIONING, true).getIntArrayValue();
             int yCbCrSubSampling[] = directory.findField(
-                    TiffTagConstants.YCBCR_SUB_SAMPLING.tagInfo, true).getIntArrayValue();
+                    TiffTagConstants.TIFF_TAG_YCBCR_SUB_SAMPLING, true).getIntArrayValue();
 
             double referenceBlackWhite[] = directory.findField(
-                    TiffTagConstants.REFERENCE_BLACK_WHITE.tagInfo, true).getDoubleArrayValue();
+                    TiffTagConstants.TIFF_TAG_REFERENCE_BLACK_WHITE, true).getDoubleArrayValue();
 
             return new PhotometricInterpreterYCbCr(yCbCrCoefficients,
                     yCbCrPositioning, yCbCrSubSampling, referenceBlackWhite,

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffReader.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffReader.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffReader.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/TiffReader.java Sat Feb 18 06:43:33 2012
@@ -249,9 +249,9 @@ public class TiffReader extends BinaryFi
                 {
                     TiffField entry = fields.get(j);
 
-                    if (entry.tag == ExifTagConstants.EXIF_OFFSET.tagInfo.tag
-                            || entry.tag == ExifTagConstants.GPSINFO.tagInfo.tag
-                            || entry.tag == ExifTagConstants.INTEROP_OFFSET.tagInfo.tag)
+                    if (entry.tag == ExifTagConstants.EXIF_TAG_EXIF_OFFSET.tag
+                            || entry.tag == ExifTagConstants.EXIF_TAG_GPSINFO.tag
+                            || entry.tag == ExifTagConstants.EXIF_TAG_INTEROP_OFFSET.tag)
                     { /* do nothing */ }
                     else
                         continue;
@@ -259,11 +259,11 @@ public class TiffReader extends BinaryFi
                     int subDirectoryOffset = ((Number) entry.getValue())
                             .intValue();
                     int subDirectoryType;
-                    if (entry.tag == ExifTagConstants.EXIF_OFFSET.tagInfo.tag)
+                    if (entry.tag == ExifTagConstants.EXIF_TAG_EXIF_OFFSET.tag)
                         subDirectoryType = TiffDirectory.DIRECTORY_TYPE_EXIF;
-                    else if (entry.tag == ExifTagConstants.GPSINFO.tagInfo.tag)
+                    else if (entry.tag == ExifTagConstants.EXIF_TAG_GPSINFO.tag)
                         subDirectoryType = TiffDirectory.DIRECTORY_TYPE_GPS;
-                    else if (entry.tag == ExifTagConstants.INTEROP_OFFSET.tagInfo.tag)
+                    else if (entry.tag == ExifTagConstants.EXIF_TAG_INTEROP_OFFSET.tag)
                         subDirectoryType = TiffDirectory.DIRECTORY_TYPE_INTEROPERABILITY;
                     else
                         throw new ImageReadException(
@@ -479,7 +479,7 @@ public class TiffReader extends BinaryFi
         if (directory.imageDataInStrips())
         {
             TiffField rowsPerStripField = directory
-                    .findField(TiffTagConstants.ROWS_PER_STRIP.tagInfo);
+                    .findField(TiffTagConstants.TIFF_TAG_ROWS_PER_STRIP);
             if (null == rowsPerStripField)
                 throw new ImageReadException("Can't find rows per strip field.");
             int rowsPerStrip = rowsPerStripField.getIntValue();
@@ -487,13 +487,13 @@ public class TiffReader extends BinaryFi
             return new TiffImageData.Strips(data, rowsPerStrip);
         } else
         {
-            TiffField tileWidthField = directory.findField(TiffTagConstants.TILE_WIDTH.tagInfo);
+            TiffField tileWidthField = directory.findField(TiffTagConstants.TIFF_TAG_TILE_WIDTH);
             if (null == tileWidthField)
                 throw new ImageReadException("Can't find tile width field.");
             int tileWidth = tileWidthField.getIntValue();
 
             TiffField tileLengthField = directory
-                    .findField(TiffTagConstants.TILE_LENGTH.tagInfo);
+                    .findField(TiffTagConstants.TIFF_TAG_TILE_LENGTH);
             if (null == tileLengthField)
                 throw new ImageReadException("Can't find tile length field.");
             int tileLength = tileLengthField.getIntValue();

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/AllTagConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/AllTagConstants.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/AllTagConstants.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/constants/AllTagConstants.java Sat Feb 18 06:43:33 2012
@@ -20,13 +20,14 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.commons.sanselan.SanselanConstants;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
 
 public interface AllTagConstants
         extends
             SanselanConstants
 {
     public static final List<TagInfo> ALL_TAGS = Collections.unmodifiableList(
-            TagConstantsUtils.mergeTagLists(TiffTagConstants.values(),
-                    GpsTagConstants.values(), ExifTagConstants.values()));
+            TagConstantsUtils.mergeTagLists(TiffTagConstants.ALL_TIFF_TAGS,
+                    GpsTagConstants.ALL_GPS_TAGS, ExifTagConstants.ALL_EXIF_TAGS));
 
 }
\ No newline at end of file