commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1245871 [4/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...
Date Sat, 18 Feb 2012 06:43:35 GMT
Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAny.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAny.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAny.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAny.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,25 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoAny extends TagInfo {
+    public TagInfoAny(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_ANY, length, directoryType);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAny.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAscii.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAscii.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAscii.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAscii.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,51 @@
+package org.apache.commons.sanselan.formats.tiff.taginfos;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoAscii extends TagInfo {
+    public TagInfoAscii(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_ASCII, length, directoryType);
+    }
+    
+    public String[] getValue(int byteOrder, byte[] bytes) {
+        int nullCount = 1;
+        for (int i = 0; i < bytes.length - 1; i++) {
+            if (bytes[i] == 0) {
+                nullCount++;
+            }
+        }
+        String[] strings = new String[nullCount + 1];
+        int stringsAdded = 0;
+        strings[0] = ""; // if we have a 0 length string
+        int nextStringPos = 0;
+        // According to the Exiftool FAQ, http://www.metadataworkinggroup.org
+        // specifies that the TIFF ASCII fields are actually UTF-8.
+        // Exiftool however allows you to configure the charset used.
+        for (int i = 0; i < bytes.length; i++) {
+            if (bytes[i] == 0) {
+                try {
+                    String string = new String(bytes, nextStringPos, i - nextStringPos, "UTF-8");
+                    strings[stringsAdded++] = string;
+                } catch (UnsupportedEncodingException unsupportedEncoding) {
+                }
+                nextStringPos = i + 1;
+            }
+        }
+        if (nextStringPos < bytes.length) {
+            // Buggy file, string wasn't null terminated
+            try {
+                String string = new String(bytes, nextStringPos, bytes.length - nextStringPos, "UTF-8");
+                strings[stringsAdded++] = string;
+            } catch (UnsupportedEncodingException unsupportedEncoding) {
+            }
+        }
+        return strings;
+    }
+
+    public byte[] encodeValue(int byteOrder, String... values) throws ImageWriteException {
+        return FIELD_TYPE_ASCII.writeData(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoAscii.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByte.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByte.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByte.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByte.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,37 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import java.util.List;
+
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+import org.apache.commons.sanselan.formats.tiff.fieldtypes.FieldType;
+
+public class TagInfoByte extends TagInfo {
+    public TagInfoByte(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_BYTE, length, directoryType);
+    }
+    
+    public TagInfoByte(String name, int tag, List<FieldType> fieldTypes,
+            int length, TiffDirectoryType directoryType) {
+        super(name, tag, fieldTypes, length, directoryType);
+    }
+
+    public byte[] encodeValue(int byteOrder, byte... values) {
+        return values;
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByte.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByteOrShort.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByteOrShort.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByteOrShort.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByteOrShort.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,34 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoByteOrShort extends TagInfo {
+    public TagInfoByteOrShort(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_DESCRIPTION_BYTE_OR_SHORT, length, directoryType);
+    }
+    
+    public byte[] encodeValue(int byteOrder, byte... values) {
+        return values;
+    }
+    
+    public byte[] encodeValue(int byteOrder, short... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoByteOrShort.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoDouble.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoDouble.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoDouble.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoDouble.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoDouble extends TagInfo {
+    public TagInfoDouble(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_DOUBLE, length, directoryType);
+    }
+    
+    public double[] getValue(int byteOrder, byte[] bytes) {
+        return BinaryConversions.convertToDoubleArray(bytes, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, double... values) throws ImageWriteException {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoDouble.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoFloat.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoFloat.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoFloat.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoFloat.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoFloat extends TagInfo {
+    public TagInfoFloat(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_FLOAT, length, directoryType);
+    }
+    
+    public float[] getValue(int byteOrder, byte[] bytes) {
+        return BinaryConversions.convertToFloatArray(bytes, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, float... values) throws ImageWriteException {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoFloat.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoLong.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoLong.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoLong.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoLong.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,40 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+
+public class TagInfoLong extends TagInfo {
+    public TagInfoLong(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_LONG, length, directoryType);
+    }
+    
+    public TagInfoLong(String name, int tag, int length, TiffDirectoryType directoryType, boolean isOffset) {
+        super(name, tag, FIELD_TYPE_LONG, length, directoryType, isOffset);
+    }
+    
+    public int[] getValue(int byteOrder, byte[] bytes) {
+        return BinaryConversions.convertToIntArray(bytes, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, int... values) throws ImageWriteException {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoLong.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoRational.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoRational.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoRational.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoRational.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,36 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.common.RationalNumber;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoRational extends TagInfo {
+    public TagInfoRational(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_RATIONAL, length, directoryType);
+    }
+
+    public RationalNumber[] getValue(int byteOrder, byte[] bytes) {
+        return BinaryConversions.convertToRationalArray(bytes, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, RationalNumber... values) throws ImageWriteException {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoRational.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSByte.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSByte.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSByte.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSByte.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,30 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoSByte extends TagInfo {
+    public TagInfoSByte(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_SBYTE, length, directoryType);
+    }
+
+    public byte[] encodeValue(int byteOrder, byte... values) throws ImageWriteException {
+        return values;
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSByte.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSLong.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSLong.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSLong.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSLong.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoSLong extends TagInfo {
+    public TagInfoSLong(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_SLONG, length, directoryType);
+    }
+    
+    public int[] getValue(int byteOrder, byte[] bytes) {
+        return BinaryConversions.convertToIntArray(bytes, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, int... values) throws ImageWriteException {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSLong.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSRational.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSRational.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSRational.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSRational.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,36 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.common.RationalNumber;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoSRational extends TagInfo {
+    public TagInfoSRational(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_SRATIONAL, length, directoryType);
+    }
+
+    public RationalNumber[] getValue(int byteOrder, byte[] bytes) {
+        return BinaryConversions.convertToRationalArray(bytes, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, RationalNumber... values) throws ImageWriteException {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSRational.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSShort.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSShort.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSShort.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSShort.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoSShort extends TagInfo {
+    public TagInfoSShort(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_SSHORT, length, directoryType);
+    }
+    
+    public short[] getValue(int byteOrder, byte[] bytes) {
+        return BinaryConversions.convertToShortArray(bytes, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, short... values) throws ImageWriteException {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoSShort.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShort.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShort.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShort.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShort.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,34 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoShort extends TagInfo {
+    public TagInfoShort(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_SHORT, length, directoryType);
+    }
+    
+    public short[] getValue(int byteOrder, byte[] bytes) {
+        return BinaryConversions.convertToShortArray(bytes, byteOrder);
+    }
+
+    public byte[] encodeValue(int byteOrder, short... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShort.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLong.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLong.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLong.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLong.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,38 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoShortOrLong extends TagInfo {
+    public TagInfoShortOrLong(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_DESCRIPTION_SHORT_OR_LONG, length, directoryType, false);
+    }
+    
+    public TagInfoShortOrLong(String name, int tag, int length, TiffDirectoryType directoryType, boolean isOffset) {
+        super(name, tag, FIELD_TYPE_DESCRIPTION_SHORT_OR_LONG, length, directoryType, isOffset);
+    }
+    
+    public byte[] encodeValue(int byteOrder, short... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, int... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLong.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLongOrRational.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLongOrRational.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLongOrRational.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLongOrRational.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,39 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.common.RationalNumber;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoShortOrLongOrRational extends TagInfo {
+    public TagInfoShortOrLongOrRational(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_DESCRIPTION_SHORT_OR_LONG, length, directoryType);
+    }
+    
+    public byte[] encodeValue(int byteOrder, short... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, int... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+    
+    public byte[] encodeValue(int byteOrder, RationalNumber... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrLongOrRational.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrRational.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrRational.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrRational.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrRational.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,35 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import org.apache.commons.sanselan.common.BinaryConversions;
+import org.apache.commons.sanselan.common.RationalNumber;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoShortOrRational extends TagInfo {
+    public TagInfoShortOrRational(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, FIELD_TYPE_DESCRIPTION_SHORT_OR_RATIONAL, length, directoryType, false);
+    }
+    
+    public byte[] encodeValue(int byteOrder, short... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+
+    public byte[] encodeValue(int byteOrder, RationalNumber... values) {
+        return BinaryConversions.convertToByteArray(values, byteOrder);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoShortOrRational.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoText.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoText.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoText.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoText.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,200 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import java.io.UnsupportedEncodingException;
+
+import org.apache.commons.sanselan.ImageReadException;
+import org.apache.commons.sanselan.ImageWriteException;
+import org.apache.commons.sanselan.common.BinaryFileFunctions;
+import org.apache.commons.sanselan.formats.tiff.TiffField;
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+import org.apache.commons.sanselan.formats.tiff.fieldtypes.FieldType;
+import org.apache.commons.sanselan.util.Debug;
+
+public final class TagInfoText extends TagInfo
+{
+    public TagInfoText(String name, int tag, FieldType dataType, int length,
+            TiffDirectoryType exifDirectory)
+    {
+        super(name, tag, dataType, length, exifDirectory);
+    }
+
+    public boolean isText()
+    {
+        return true;
+    }
+
+    private static final class TextEncoding
+    {
+        public final byte prefix[];
+        public final String encodingName;
+
+        public TextEncoding(final byte[] prefix, final String encodingName)
+        {
+            this.prefix = prefix;
+            this.encodingName = encodingName;
+        }
+    }
+
+    private static final TagInfoText.TextEncoding TEXT_ENCODING_ASCII = new TextEncoding(
+            new byte[]{
+                    0x41, 0x53, 0x43, 0x49, 0x49, 0x00, 0x00, 0x00,
+            }, "US-ASCII"); // ITU-T T.50 IA5
+    private static final TagInfoText.TextEncoding TEXT_ENCODING_JIS = new TextEncoding(
+            new byte[]{
+                    0x4A, 0x49, 0x53, 0x00, 0x00, 0x00, 0x00, 0x00,
+            }, "JIS"); // JIS X208-1990
+    private static final TagInfoText.TextEncoding TEXT_ENCODING_UNICODE = new TextEncoding(
+            new byte[]{
+                    0x55, 0x4E, 0x49, 0x43, 0x4F, 0x44, 0x45, 0x00,
+            // Which Unicode encoding to use, UTF-8?
+            }, "UTF-8"); // Unicode Standard
+    private static final TagInfoText.TextEncoding TEXT_ENCODING_UNDEFINED = new TextEncoding(
+            new byte[]{
+                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+            // Try to interpret an undefined text as ISO-8859-1 (Latin)
+            }, "ISO-8859-1"); // Undefined
+    private static final TagInfoText.TextEncoding TEXT_ENCODINGS[] = {
+            TEXT_ENCODING_ASCII, //
+            TEXT_ENCODING_JIS, //
+            TEXT_ENCODING_UNICODE, //
+            TEXT_ENCODING_UNDEFINED, //
+    };
+
+    public byte[] encodeValue(FieldType fieldType, Object value,
+            int byteOrder) throws ImageWriteException
+    {
+        if (!(value instanceof String))
+            throw new ImageWriteException("Text value not String: " + value
+                    + " (" + Debug.getType(value) + ")");
+        String s = (String) value;
+
+        try
+        {
+            // try ASCII, with NO prefix.
+            byte asciiBytes[] = s
+                    .getBytes(TEXT_ENCODING_ASCII.encodingName);
+            String decodedAscii = new String(asciiBytes,
+                    TEXT_ENCODING_ASCII.encodingName);
+            if (decodedAscii.equals(s))
+            {
+                // no unicode/non-ascii values.
+                byte result[] = new byte[asciiBytes.length
+                        + TEXT_ENCODING_ASCII.prefix.length];
+                System.arraycopy(TEXT_ENCODING_ASCII.prefix, 0, result, 0,
+                        TEXT_ENCODING_ASCII.prefix.length);
+                System.arraycopy(asciiBytes, 0, result,
+                        TEXT_ENCODING_ASCII.prefix.length,
+                        asciiBytes.length);
+                return result;
+            }
+            else
+            {
+                // use unicode
+                byte unicodeBytes[] = s
+                        .getBytes(TEXT_ENCODING_UNICODE.encodingName);
+                byte result[] = new byte[unicodeBytes.length
+                        + TEXT_ENCODING_UNICODE.prefix.length];
+                System.arraycopy(TEXT_ENCODING_UNICODE.prefix, 0, result,
+                        0, TEXT_ENCODING_UNICODE.prefix.length);
+                System.arraycopy(unicodeBytes, 0, result,
+                        TEXT_ENCODING_UNICODE.prefix.length,
+                        unicodeBytes.length);
+                return result;
+            }
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            throw new ImageWriteException(e.getMessage(), e);
+        }
+    }
+
+    public Object getValue(TiffField entry) throws ImageReadException
+    {
+        //            Debug.debug("entry.type", entry.type);
+        //            Debug.debug("entry.type", entry.getDescriptionWithoutValue());
+        //            Debug.debug("entry.type", entry.fieldType);
+
+        if (entry.type == FIELD_TYPE_ASCII.type)
+            return FIELD_TYPE_ASCII.getSimpleValue(entry);
+        else if (entry.type == FIELD_TYPE_UNDEFINED.type)
+        { /* do nothing */ }
+        else if (entry.type == FIELD_TYPE_BYTE.type)
+        { /* do nothing */ }
+        else
+        {
+            Debug.debug("entry.type", entry.type);
+            Debug.debug("entry.directoryType", entry.directoryType);
+            Debug.debug("entry.type", entry.getDescriptionWithoutValue());
+            Debug.debug("entry.type", entry.fieldType);
+            throw new ImageReadException("Text field not encoded as bytes.");
+        }
+
+        byte bytes[] = entry.fieldType.getRawBytes(entry);
+        if (bytes.length < 8)
+        {
+            try
+            {
+                // try ASCII, with NO prefix.
+                return new String(bytes, "US-ASCII");
+            }
+            catch (UnsupportedEncodingException e)
+            {
+                throw new ImageReadException(
+                        "Text field missing encoding prefix.");
+            }
+        }
+
+        for (int i = 0; i < TEXT_ENCODINGS.length; i++)
+        {
+            TagInfoText.TextEncoding encoding = TEXT_ENCODINGS[i];
+            if (BinaryFileFunctions.compareBytes(bytes, 0, encoding.prefix,
+                    0, encoding.prefix.length))
+            {
+                try
+                {
+                    //                        Debug.debug("encodingName", encoding.encodingName);
+                    return new String(bytes, encoding.prefix.length,
+                            bytes.length - encoding.prefix.length,
+                            encoding.encodingName);
+                }
+                catch (UnsupportedEncodingException e)
+                {
+                    throw new ImageReadException(e.getMessage(), e);
+                }
+            }
+        }
+
+        //                        Debug.debug("entry.tag", entry.tag + " (0x" + Integer.toHexString(entry.tag ) +")");
+        //                        Debug.debug("entry.type", entry.type);
+        //                        Debug.debug("bytes", bytes, 10);
+        //            throw new ImageReadException(
+        //                    "Unknown Text encoding prefix.");
+
+        try
+        {
+            // try ASCII, with NO prefix.
+            return new String(bytes, "US-ASCII");
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            throw new ImageReadException("Unknown text encoding prefix.");
+        }
+
+    }
+}
\ No newline at end of file

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoText.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUndefined.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUndefined.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUndefined.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUndefined.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,27 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import java.util.Arrays;
+
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public class TagInfoUndefined extends TagInfoByte {
+    public TagInfoUndefined(String name, int tag, int length, TiffDirectoryType directoryType) {
+        super(name, tag, Arrays.asList(FIELD_TYPE_UNDEFINED), length, directoryType);
+    }
+}

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUndefined.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUnknown.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUnknown.java?rev=1245871&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUnknown.java (added)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUnknown.java Sat Feb 18 06:43:33 2012
@@ -0,0 +1,31 @@
+/*
+ * 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.formats.tiff.taginfos;
+
+import java.util.Arrays;
+
+import org.apache.commons.sanselan.formats.tiff.constants.TiffDirectoryType;
+
+public final class TagInfoUnknown extends TagInfoByte {
+    public TagInfoUnknown(String name, int tag, int length, TiffDirectoryType exifDirectory) {
+        super(name, tag, Arrays.asList(FIELD_TYPE_UNKNOWN), length, exifDirectory);
+    }
+
+    public boolean isUnknown() {
+        return true;
+    }
+}
\ No newline at end of file

Propchange: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/taginfos/TagInfoUnknown.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterBase.java Sat Feb 18 06:43:33 2012
@@ -30,6 +30,7 @@ import org.apache.commons.sanselan.Image
 import org.apache.commons.sanselan.common.BinaryConstants;
 import org.apache.commons.sanselan.common.BinaryOutputStream;
 import org.apache.commons.sanselan.common.PackBits;
+import org.apache.commons.sanselan.common.RationalNumberUtilities;
 import org.apache.commons.sanselan.common.itu_t4.T4AndT6Compression;
 import org.apache.commons.sanselan.common.mylzw.MyLzwCompressor;
 import org.apache.commons.sanselan.formats.tiff.TiffElement;
@@ -140,19 +141,19 @@ public abstract class TiffImageWriterBas
                             + ") appears twice in directory.");
                 fieldTags.add(fieldKey);
 
-                if (field.tag == ExifTagConstants.EXIF_OFFSET.tagInfo.tag)
+                if (field.tag == ExifTagConstants.EXIF_TAG_EXIF_OFFSET.tag)
                 {
                     if (exifDirectoryOffsetField != null)
                         throw new ImageWriteException(
                                 "More than one Exif directory offset field.");
                     exifDirectoryOffsetField = field;
-                } else if (field.tag == ExifTagConstants.INTEROP_OFFSET.tagInfo.tag)
+                } else if (field.tag == ExifTagConstants.EXIF_TAG_INTEROP_OFFSET.tag)
                 {
                     if (interoperabilityDirectoryOffsetField != null)
                         throw new ImageWriteException(
                                 "More than one Interoperability directory offset field.");
                     interoperabilityDirectoryOffsetField = field;
-                } else if (field.tag == ExifTagConstants.GPSINFO.tagInfo.tag)
+                } else if (field.tag == ExifTagConstants.EXIF_TAG_GPSINFO.tag)
                 {
                     if (gpsDirectoryOffsetField != null)
                         throw new ImageWriteException(
@@ -208,7 +209,7 @@ public abstract class TiffImageWriterBas
             if (interoperabilityDirectoryOffsetField == null)
             {
                 interoperabilityDirectoryOffsetField = TiffOutputField
-                        .createOffsetField(ExifTagConstants.INTEROP_OFFSET.tagInfo, byteOrder);
+                        .createOffsetField(ExifTagConstants.EXIF_TAG_INTEROP_OFFSET, byteOrder);
                 exifDirectory.add(interoperabilityDirectoryOffsetField);
             }
 
@@ -227,7 +228,7 @@ public abstract class TiffImageWriterBas
             if (exifDirectoryOffsetField == null)
             {
                 exifDirectoryOffsetField = TiffOutputField.createOffsetField(
-                        ExifTagConstants.EXIF_OFFSET.tagInfo, byteOrder);
+                        ExifTagConstants.EXIF_TAG_EXIF_OFFSET, byteOrder);
                 rootDirectory.add(exifDirectoryOffsetField);
             }
 
@@ -244,7 +245,7 @@ public abstract class TiffImageWriterBas
             if (gpsDirectoryOffsetField == null)
             {
                 gpsDirectoryOffsetField = TiffOutputField.createOffsetField(
-                        ExifTagConstants.GPSINFO.tagInfo, byteOrder);
+                        ExifTagConstants.EXIF_TAG_GPSINFO, byteOrder);
                 rootDirectory.add(gpsDirectoryOffsetField);
             }
 
@@ -410,57 +411,20 @@ public abstract class TiffImageWriterBas
         // WriteField stripOffsetsField;
 
         {
-            {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.IMAGE_WIDTH.tagInfo, FIELD_TYPE_LONG, 1,
-                        FIELD_TYPE_LONG.writeData(new int[] { width, },
-                                byteOrder));
-                directory.add(field);
-            }
-            {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.IMAGE_LENGTH.tagInfo, FIELD_TYPE_LONG, 1,
-                        FIELD_TYPE_LONG.writeData(new int[] { height, },
-                                byteOrder));
-                directory.add(field);
-            }
-            {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.PHOTOMETRIC_INTERPRETATION.tagInfo, FIELD_TYPE_SHORT,
-                        1, FIELD_TYPE_SHORT.writeData(
-                                new int[] { photometricInterpretation, },
-                                byteOrder));
-                directory.add(field);
-            }
-            {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.COMPRESSION.tagInfo, FIELD_TYPE_SHORT, 1,
-                        FIELD_TYPE_SHORT.writeData(new int[] { compression, },
-                                byteOrder));
-                directory.add(field);
-            }
-            {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.SAMPLES_PER_PIXEL.tagInfo, FIELD_TYPE_SHORT, 1,
-                        FIELD_TYPE_SHORT.writeData(
-                                new int[] { samplesPerPixel, }, byteOrder));
-                directory.add(field);
-            }
+
+            directory.add(TiffTagConstants.TIFF_TAG_IMAGE_WIDTH, width);
+            directory.add(TiffTagConstants.TIFF_TAG_IMAGE_LENGTH, height);
+            directory.add(TiffTagConstants.TIFF_TAG_PHOTOMETRIC_INTERPRETATION, (short)photometricInterpretation);
+            directory.add(TiffTagConstants.TIFF_TAG_COMPRESSION, (short)compression);
+            directory.add(TiffTagConstants.TIFF_TAG_SAMPLES_PER_PIXEL, (short)samplesPerPixel);
             
             if (samplesPerPixel == 3)
             {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.BITS_PER_SAMPLE.tagInfo, FIELD_TYPE_SHORT, 3,
-                        FIELD_TYPE_SHORT.writeData(new int[] { bitsPerSample,
-                                bitsPerSample, bitsPerSample, }, byteOrder));
-                directory.add(field);
+                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE, (short)bitsPerSample,
+                        (short)bitsPerSample, (short)bitsPerSample);
             } else if (samplesPerPixel == 1)
             {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.BITS_PER_SAMPLE.tagInfo, FIELD_TYPE_SHORT, 1,
-                        FIELD_TYPE_SHORT.writeData(
-                                new int[] { bitsPerSample, }, byteOrder));
-                directory.add(field);
+                directory.add(TiffTagConstants.TIFF_TAG_BITS_PER_SAMPLE, (short)bitsPerSample);
             }
             // {
             // stripOffsetsField = new WriteField(TIFF_TAG_STRIP_OFFSETS,
@@ -475,62 +439,24 @@ public abstract class TiffImageWriterBas
             // WRITE_BYTE_ORDER));
             // directory.add(field);
             // }
-            {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.ROWS_PER_STRIP.tagInfo, FIELD_TYPE_LONG, 1,
-                        FIELD_TYPE_LONG.writeData(new int[] { rowsPerStrip, },
-                                byteOrder));
-                directory.add(field);
-            }
-
-            {
-                int resolutionUnit = 2;// inches.
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.RESOLUTION_UNIT.tagInfo, FIELD_TYPE_SHORT, 1,
-                        FIELD_TYPE_SHORT.writeData(
-                                new int[] { resolutionUnit, }, byteOrder));
-                directory.add(field);
-            }
-
-            {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.XRESOLUTION.tagInfo, FIELD_TYPE_RATIONAL, 1,
-                        FIELD_TYPE_RATIONAL
-                                .writeData(xResolution.intValue(), 1, byteOrder));
-                directory.add(field);
-            }
-
-            {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.YRESOLUTION.tagInfo, FIELD_TYPE_RATIONAL, 1,
-                        FIELD_TYPE_RATIONAL
-                                .writeData(yResolution.intValue(), 1, byteOrder));
-                directory.add(field);
-            }
-            
+            directory.add(TiffTagConstants.TIFF_TAG_ROWS_PER_STRIP, rowsPerStrip);
+            directory.add(TiffTagConstants.TIFF_TAG_RESOLUTION_UNIT, (short)2); // inches
+            directory.add(TiffTagConstants.TIFF_TAG_XRESOLUTION,
+                    RationalNumberUtilities.getRationalNumber(xResolution.doubleValue()));
+            directory.add(TiffTagConstants.TIFF_TAG_YRESOLUTION,
+                    RationalNumberUtilities.getRationalNumber(yResolution.doubleValue()));
             if (t4Options != 0) {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.T4_OPTIONS.tagInfo, FIELD_TYPE_LONG, 1,
-                        FIELD_TYPE_LONG
-                                .writeData(Integer.valueOf(t4Options), byteOrder));
-                directory.add(field);
+                directory.add(TiffTagConstants.TIFF_TAG_T4_OPTIONS, t4Options);
             }
             if (t6Options != 0) {
-                TiffOutputField field = new TiffOutputField(
-                        TiffTagConstants.T6_OPTIONS.tagInfo, FIELD_TYPE_LONG, 1,
-                        FIELD_TYPE_LONG
-                                .writeData(Integer.valueOf(t6Options), byteOrder));
-                directory.add(field);
+                directory.add(TiffTagConstants.TIFF_TAG_T6_OPTIONS, t6Options);
             }
 
 
             if (null != xmpXml)
             {
                 byte xmpXmlBytes[] = xmpXml.getBytes("utf-8");
-
-                TiffOutputField field = new TiffOutputField(TiffTagConstants.XMP.tagInfo,
-                        FIELD_TYPE_BYTE, xmpXmlBytes.length, xmpXmlBytes);
-                directory.add(field);
+                directory.add(TiffTagConstants.TIFF_TAG_XMP, xmpXmlBytes);
             }
 
         }

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterLossless.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterLossless.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterLossless.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffImageWriterLossless.java Sat Feb 18 06:43:33 2012
@@ -143,7 +143,7 @@ public class TiffImageWriterLossless ext
                 for (int f = 0; f < fields.size(); f++)
                 {
                     TiffField field = fields.get(f);
-                    if (field.tag == ExifTagConstants.MAKER_NOTE.tagInfo.tag) {
+                    if (field.tag == ExifTagConstants.EXIF_TAG_MAKER_NOTE.tag) {
                         // Some maker notes reference values stored
                         // inside the maker note itself
                         // using addresses relative to the beginning

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputDirectory.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputDirectory.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputDirectory.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputDirectory.java Sat Feb 18 06:43:33 2012
@@ -24,23 +24,41 @@ import java.util.List;
 
 import org.apache.commons.sanselan.ImageWriteException;
 import org.apache.commons.sanselan.common.BinaryOutputStream;
+import org.apache.commons.sanselan.common.RationalNumber;
 import org.apache.commons.sanselan.formats.tiff.JpegImageData;
 import org.apache.commons.sanselan.formats.tiff.TiffDirectory;
 import org.apache.commons.sanselan.formats.tiff.TiffElement;
 import org.apache.commons.sanselan.formats.tiff.TiffImageData;
 import org.apache.commons.sanselan.formats.tiff.constants.TagConstantsUtils;
-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.TiffFieldTypeConstants;
 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;
+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.TagInfoByteOrShort;
+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;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoShortOrLong;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoShortOrLongOrRational;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoShortOrRational;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfoText;
 
 public final class TiffOutputDirectory extends TiffOutputItem implements
         TiffConstants
 {
     public final int type;
     private final List<TiffOutputField> fields = new ArrayList<TiffOutputField>();
-
+    private final int byteOrder;
     private TiffOutputDirectory nextDirectory = null;
 
     public void setNextDirectory(TiffOutputDirectory nextDirectory)
@@ -48,11 +66,239 @@ public final class TiffOutputDirectory e
         this.nextDirectory = nextDirectory;
     }
 
-    public TiffOutputDirectory(final int type)
+    public TiffOutputDirectory(final int type, final int byteOrder)
     {
         this.type = type;
+        this.byteOrder = byteOrder;
+    }
+    
+    public void add(TagInfoByte tagInfo, byte... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_BYTE, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoAscii tagInfo, String... values) throws ImageWriteException {
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        if (tagInfo.length > 0 && tagInfo.length != bytes.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " byte(s), not " + values.length);
+        }
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_ASCII, bytes.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoShort tagInfo, short... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_SHORT, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoLong tagInfo, int... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoRational tagInfo, RationalNumber... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoSByte tagInfo, byte... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_SBYTE, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoSShort tagInfo, short... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_SSHORT, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoSLong tagInfo, int... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_SLONG, values.length, bytes);
+        add(tiffOutputField);
     }
 
+    public void add(TagInfoSRational tagInfo, RationalNumber... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_SRATIONAL, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoFloat tagInfo, float... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_FLOAT, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoDouble tagInfo, double... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_DOUBLE, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoByteOrShort tagInfo, byte... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_SHORT, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoByteOrShort tagInfo, short... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_SHORT, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoShortOrLong tagInfo, short... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoShortOrLong tagInfo, int... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_LONG, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoShortOrLongOrRational tagInfo, short... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoShortOrLongOrRational tagInfo, int... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoShortOrLongOrRational tagInfo, RationalNumber... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        add(tiffOutputField);
+    }
+    
+    public void add(TagInfoShortOrRational tagInfo, short... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoShortOrRational tagInfo, RationalNumber... values) throws ImageWriteException {
+        if (tagInfo.length > 0 && tagInfo.length != values.length) {
+            throw new ImageWriteException("Tag expects " + tagInfo.length +
+                    " value(s), not " + values.length);
+        }
+        byte[] bytes = tagInfo.encodeValue(byteOrder, values);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_RATIONAL, values.length, bytes);
+        add(tiffOutputField);
+    }
+
+    public void add(TagInfoText tagInfo, String value) throws ImageWriteException {
+        byte[] bytes = tagInfo.encodeValue(TiffFieldTypeConstants.FIELD_TYPE_UNKNOWN, value, byteOrder);
+        TiffOutputField tiffOutputField = new TiffOutputField(tagInfo.tag, tagInfo,
+                TiffFieldTypeConstants.FIELD_TYPE_UNKNOWN, bytes.length, bytes);
+        add(tiffOutputField);
+    }
+    
     public void add(TiffOutputField field)
     {
         fields.add(field);
@@ -192,14 +438,14 @@ public final class TiffOutputDirectory e
     {
         // first validate directory fields.
 
-        removeFieldIfPresent(TiffTagConstants.JPEG_INTERCHANGE_FORMAT.tagInfo);
-        removeFieldIfPresent(TiffTagConstants.JPEG_INTERCHANGE_FORMAT_LENGTH.tagInfo);
+        removeFieldIfPresent(TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT);
+        removeFieldIfPresent(TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
 
         TiffOutputField jpegOffsetField = null;
         if (null != jpegImageData)
         {
             jpegOffsetField = new TiffOutputField(
-                    TiffTagConstants.JPEG_INTERCHANGE_FORMAT.tagInfo, FIELD_TYPE_LONG, 1,
+                    TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT, FIELD_TYPE_LONG, 1,
                     FieldType.getStubLocalValue());
             add(jpegOffsetField);
 
@@ -208,7 +454,7 @@ public final class TiffOutputDirectory e
                     outputSummary.byteOrder);
 
             TiffOutputField jpegLengthField = new TiffOutputField(
-                    TiffTagConstants.JPEG_INTERCHANGE_FORMAT_LENGTH.tagInfo, FIELD_TYPE_LONG,
+                    TiffTagConstants.TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, FIELD_TYPE_LONG,
                     1, lengthValue);
             add(jpegLengthField);
 
@@ -216,10 +462,10 @@ public final class TiffOutputDirectory e
 
         // --------------------------------------------------------------
 
-        removeFieldIfPresent(TiffTagConstants.STRIP_OFFSETS.tagInfo);
-        removeFieldIfPresent(TiffTagConstants.STRIP_BYTE_COUNTS.tagInfo);
-        removeFieldIfPresent(TiffTagConstants.TILE_OFFSETS.tagInfo);
-        removeFieldIfPresent(TiffTagConstants.TILE_BYTE_COUNTS.tagInfo);
+        removeFieldIfPresent(TiffTagConstants.TIFF_TAG_STRIP_OFFSETS);
+        removeFieldIfPresent(TiffTagConstants.TIFF_TAG_STRIP_BYTE_COUNTS);
+        removeFieldIfPresent(TiffTagConstants.TIFF_TAG_TILE_OFFSETS);
+        removeFieldIfPresent(TiffTagConstants.TIFF_TAG_TILE_BYTE_COUNTS);
 
         TiffOutputField imageDataOffsetField;
         ImageDataOffsets imageDataInfo = null;
@@ -231,12 +477,12 @@ public final class TiffOutputDirectory e
             TagInfo byteCountsTag;
             if (stripsNotTiles)
             {
-                offsetTag = TiffTagConstants.STRIP_OFFSETS.tagInfo;
-                byteCountsTag = TiffTagConstants.STRIP_BYTE_COUNTS.tagInfo;
+                offsetTag = TiffTagConstants.TIFF_TAG_STRIP_OFFSETS;
+                byteCountsTag = TiffTagConstants.TIFF_TAG_STRIP_BYTE_COUNTS;
             } else
             {
-                offsetTag = TiffTagConstants.TILE_OFFSETS.tagInfo;
-                byteCountsTag = TiffTagConstants.TILE_BYTE_COUNTS.tagInfo;
+                offsetTag = TiffTagConstants.TIFF_TAG_TILE_OFFSETS;
+                byteCountsTag = TiffTagConstants.TIFF_TAG_TILE_BYTE_COUNTS;
             }
 
             // --------

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputField.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputField.java?rev=1245871&r1=1245870&r2=1245871&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputField.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/commons/sanselan/formats/tiff/write/TiffOutputField.java Sat Feb 18 06:43:33 2012
@@ -20,9 +20,9 @@ import java.io.IOException;
 
 import org.apache.commons.sanselan.ImageWriteException;
 import org.apache.commons.sanselan.common.BinaryOutputStream;
-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.fieldtypes.FieldType;
+import org.apache.commons.sanselan.formats.tiff.taginfos.TagInfo;
 
 public class TiffOutputField implements TiffConstants
 {
@@ -62,56 +62,6 @@ public class TiffOutputField implements 
 
     private int sortHint = -1;
 
-    public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
-            Number number) throws ImageWriteException
-    {
-        if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
-            throw new ImageWriteException("Tag has no default data type.");
-        FieldType fieldType = tagInfo.dataTypes[0];
-
-        if (tagInfo.length != 1)
-            throw new ImageWriteException("Tag does not expect a single value.");
-
-        byte bytes[] = fieldType.writeData(number, byteOrder);
-
-        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
-    }
-
-    public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
-            Number value[]) throws ImageWriteException
-    {
-        if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
-            throw new ImageWriteException("Tag has no default data type.");
-        FieldType fieldType = tagInfo.dataTypes[0];
-
-        if (tagInfo.length >= 0 && tagInfo.length != value.length)
-            throw new ImageWriteException("Tag expects " + tagInfo.length + " values.");
-
-        byte bytes[] = fieldType.writeData(value, byteOrder);
-
-        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType,
-                value.length, bytes);
-    }
-
-    public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
-            String value) throws ImageWriteException
-    {
-        FieldType fieldType;
-        if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
-            fieldType = FIELD_TYPE_ASCII;
-        else
-        {
-            if (tagInfo.dataTypes[0] == FIELD_TYPE_ASCII)
-                fieldType = FIELD_TYPE_ASCII;
-            else
-                throw new ImageWriteException("Tag has unexpected data type.");
-        }
-
-        byte bytes[] = fieldType.writeData(value, byteOrder);
-
-        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, bytes.length, bytes);
-    }
-
     protected static final TiffOutputField createOffsetField(TagInfo tagInfo,
             int byteOrder) throws ImageWriteException
     {



Mime
View raw message