commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmc...@apache.org
Subject svn commit: r995534 - in /commons/proper/sanselan/trunk/src: main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java test/java/org/apache/sanselan/SanselanTest.java test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
Date Thu, 09 Sep 2010 18:38:21 GMT
Author: cmchen
Date: Thu Sep  9 18:38:21 2010
New Revision: 995534

URL: http://svn.apache.org/viewvc?rev=995534&view=rev
Log:
Fixed issue "FieldTypeASCII does not conform to the EXIF specification," identified by Libor
Nenadál.
Added unit test.

Jira Key:	SANSELAN-34

Added:
    commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
  (with props)
Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java
    commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java?rev=995534&r1=995533&r2=995534&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java
Thu Sep  9 18:38:21 2010
@@ -26,9 +26,11 @@ public class FieldTypeASCII extends Fiel
 		super(type, 1, name);
 	}
 
-	public Object getSimpleValue(TiffField entry) 
-	{
-		return new String(getRawBytes(entry));
+	public Object getSimpleValue(TiffField entry) {
+		// According to EXIF specification "2 = ASCII An 8-bit byte containing one 7-bit ASCII
code. The final byte is terminated with NULL." 
+		byte bytes[] = getRawBytes(entry);
+		// Ignore last (should be NULL) byte.
+		return new String(bytes, 0, bytes.length-1);
 	}
 
 	public byte[] writeData(Object o, int byteOrder) throws ImageWriteException

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java?rev=995534&r1=995533&r2=995534&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java (original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java Thu
Sep  9 18:38:21 2010
@@ -75,6 +75,15 @@ public abstract class SanselanTest exten
 		return getTestImage(null);
 	}
 
+	protected File getTestImageByName(final String filename) 
+			throws IOException, ImageReadException {
+		return getTestImage(new ImageFilter() {
+			public boolean accept(File file) throws IOException, ImageReadException {
+				return file.getName().equals(filename);
+			}
+		});
+	}
+
 	protected File getTestImage(ImageFilter filter) throws IOException,
 			ImageReadException {
 		List images = getTestImages(filter, 1);

Added: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java?rev=995534&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
(added)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
Thu Sep  9 18:38:21 2010
@@ -0,0 +1,86 @@
+/*
+ * 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.io.IOException;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.common.IImageMetadata;
+import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
+import org.apache.sanselan.formats.tiff.TiffField;
+import org.apache.sanselan.formats.tiff.TiffImageMetadata;
+import org.apache.sanselan.formats.tiff.constants.AllTagConstants;
+
+public class AsciiFieldTest extends ExifBaseTest implements AllTagConstants {
+
+	public void testSingleImage() throws IOException, ImageReadException,
+			ImageWriteException {
+		File imageFile = getTestImageByName("Canon Powershot SD750 - 2007.12.26.n.IMG_3704.JPG");
+
+		Map params = new HashMap();
+//		boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+//		params.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(!ignoreImageData));
+
+		// note that metadata might be null if no metadata is found.
+		IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
+		if (null == metadata)
+			return;
+		JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+
+		// note that exif might be null if no Exif metadata is found.
+		TiffImageMetadata exif = jpegMetadata.getExif();
+		if (null == exif)
+			return;
+
+		List fields = exif.getAllFields();
+		Map fieldMap = new Hashtable();
+		// Build a simplified field tag -> field map, ignoring directory structures.
+		// Good enough for our purposes, since the image in question is known.
+		for (int i = 0; i < fields.size(); i++) {
+			TiffField field = (TiffField) fields.get(i);
+//			Debug.debug("field", field);
+			// checkField(imageFile, field);
+			fieldMap.put(new Integer(field.tag), field);
+		}
+		
+		Map expectedFieldValues = new Hashtable();
+		expectedFieldValues.put(new Integer(EXIF_TAG_MAKE.tag), "Canon");
+		expectedFieldValues.put(new Integer(EXIF_TAG_MODEL.tag), "Canon PowerShot SD750");
+		expectedFieldValues.put(new Integer(EXIF_TAG_MODIFY_DATE.tag), "2007:12:25 13:34:39");
+		Iterator expectedTags = expectedFieldValues.keySet().iterator();
+		while (expectedTags.hasNext()) {
+			Integer tag = (Integer) expectedTags.next();
+			Object expectedValue = expectedFieldValues.get(tag);
+
+			assertTrue(fieldMap.containsKey(tag));
+			TiffField field = (TiffField) fieldMap.get(tag);
+			assertNotNull(field);
+			Object value = field.getValue();
+			assertNotNull(value);
+			assertEquals(value, expectedValue);
+		}
+	}
+}

Propchange: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/exif/AsciiFieldTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message