Author: damjan
Date: Fri Dec 9 09:37:20 2011
New Revision: 1212304
URL: http://svn.apache.org/viewvc?rev=1212304&view=rev
Log:
Add some EXIF tag writing tests,
and fix TiffOutputField to allow
writing to fields that specify
they require an unknown number
of values.
Added:
commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteTagsTest.java
Modified:
commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java
Modified:
commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java
URL:
http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java?rev=1212304&r1=1212303&r2=1212304&view=diff
==============================================================================
---
commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java
(original)
+++
commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java
Fri Dec 9 09:37:20 2011
@@ -84,8 +84,8 @@ public class TiffOutputField implements
throw new ImageWriteException("Tag has no default data type.");
FieldType fieldType = tagInfo.dataTypes[0];
- if (tagInfo.length != value.length)
- throw new ImageWriteException("Tag does not expect a single
value.");
+ if (tagInfo.length >= 0 && tagInfo.length != value.length)
+ throw new ImageWriteException("Tag expects " + tagInfo.length + "
values.");
byte bytes[] = fieldType.writeData(value, byteOrder);
@@ -209,4 +209,4 @@ public class TiffOutputField implements
{
this.sortHint = sortHint;
}
-}
\ No newline at end of file
+}
Added:
commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteTagsTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteTagsTest.java?rev=1212304&view=auto
==============================================================================
---
commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteTagsTest.java
(added)
+++
commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/WriteTagsTest.java
Fri Dec 9 09:37:20 2011
@@ -0,0 +1,68 @@
+/*
+ * 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.sanselan.formats.jpeg.exif;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.SanselanConstants;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.common.BinaryConstants;
+import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
+import org.apache.sanselan.formats.tiff.TiffImageMetadata;
+import org.apache.sanselan.formats.tiff.constants.TiffConstants;
+import org.apache.sanselan.formats.tiff.write.TiffOutputField;
+import org.apache.sanselan.util.Debug;
+
+public class WriteTagsTest extends ExifBaseTest implements SanselanConstants
+{
+
+ public void test() throws Exception
+ {
+ boolean worked;
+
+ // 2 SHORTs
+ worked = true;
+ try {
+ TiffOutputField pageNumber = TiffOutputField.create(
+ TiffConstants.EXIF_TAG_PAGE_NUMBER,
+ BinaryConstants.BYTE_ORDER_LITTLE_ENDIAN,
+ new Integer[] { new Integer(1), new Integer(10) } );
+ } catch (ImageWriteException e) {
+ Debug.debug(e);
+ worked = false;
+ }
+ assertTrue(worked);
+
+ // any number of SHORTS
+ worked = true;
+ try {
+ TiffOutputField gpsAreaInfo = TiffOutputField.create(
+ TiffConstants.TIFF_TAG_BITS_PER_SAMPLE,
+ BinaryConstants.BYTE_ORDER_LITTLE_ENDIAN,
+ new Integer[] { new Integer(1), new Integer(1) } );
+ } catch (ImageWriteException e) {
+ Debug.debug(e);
+ worked = false;
+ }
+ assertTrue(worked);
+ }
+}