commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmc...@apache.org
Subject svn commit: r995556 - in /commons/proper/sanselan/trunk: ./ src/main/java/org/apache/sanselan/formats/jpeg/ src/test/data/images/jpg/3/ src/test/java/org/apache/sanselan/formats/jpeg/
Date Thu, 09 Sep 2010 19:34:07 GMT
Author: cmchen
Date: Thu Sep  9 19:34:07 2010
New Revision: 995556

URL: http://svn.apache.org/viewvc?rev=995556&view=rev
Log:
Fix for "JpegImageMetadata getEXIFThumbnail only works on Jpeg thumbnails stored as Tiff images"
issue.
patch supplied by James E-J.

Jpeg thumbnails are read using ImageIO.

Jira Key:	SANSELAN-38

Added:
    commons/proper/sanselan/trunk/jamesEJ_jpeg_patch.txt
    commons/proper/sanselan/trunk/src/test/data/images/jpg/3/
    commons/proper/sanselan/trunk/src/test/data/images/jpg/3/img_F028c_small.jpg   (with props)
    commons/proper/sanselan/trunk/src/test/data/images/jpg/3/info.txt   (with props)
    commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java
  (with props)
Modified:
    commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java
    commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java

Added: commons/proper/sanselan/trunk/jamesEJ_jpeg_patch.txt
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/jamesEJ_jpeg_patch.txt?rev=995556&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/jamesEJ_jpeg_patch.txt (added)
+++ commons/proper/sanselan/trunk/jamesEJ_jpeg_patch.txt Thu Sep  9 19:34:07 2010
@@ -0,0 +1,34 @@
+Index: src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java
+===================================================================
+--- src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java	(revision 922056)
++++ src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java	(working copy)
+@@ -18,12 +18,15 @@
+ 
+ import java.awt.Dimension;
+ import java.awt.image.BufferedImage;
++import java.io.ByteArrayInputStream;
+ import java.io.IOException;
+ import java.util.ArrayList;
++import javax.imageio.ImageIO;
+ 
+ import org.apache.sanselan.ImageReadException;
+ import org.apache.sanselan.Sanselan;
+ import org.apache.sanselan.common.IImageMetadata;
++import org.apache.sanselan.formats.tiff.JpegImageData;
+ import org.apache.sanselan.formats.tiff.TiffField;
+ import org.apache.sanselan.formats.tiff.TiffImageData;
+ import org.apache.sanselan.formats.tiff.TiffImageMetadata;
+@@ -136,6 +139,13 @@
+ 			BufferedImage image = dir.getThumbnail();
+ 			if (null != image)
+ 				return image;
++                        JpegImageData jpegImageData = dir.getJpegImageData();
++                        if(jpegImageData!=null){
++                            ByteArrayInputStream input = new ByteArrayInputStream(jpegImageData.data);
++                            image = ImageIO.read(input);
++                            if (image!=null)
++                                return image;
++                        }
+ 		}
+ 
+ 		return null;

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java?rev=995556&r1=995555&r2=995556&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java
(original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java
Thu Sep  9 19:34:07 2010
@@ -18,12 +18,16 @@ package org.apache.sanselan.formats.jpeg
 
 import java.awt.Dimension;
 import java.awt.image.BufferedImage;
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 
+import javax.imageio.ImageIO;
+
 import org.apache.sanselan.ImageReadException;
 import org.apache.sanselan.Sanselan;
 import org.apache.sanselan.common.IImageMetadata;
+import org.apache.sanselan.formats.tiff.JpegImageData;
 import org.apache.sanselan.formats.tiff.TiffField;
 import org.apache.sanselan.formats.tiff.TiffImageData;
 import org.apache.sanselan.formats.tiff.TiffImageMetadata;
@@ -134,8 +138,19 @@ public class JpegImageMetadata implement
 					.get(i);
 			// Debug.debug("dir", dir);
 			BufferedImage image = dir.getThumbnail();
-			if (null != image)
+			if (null != image) {
 				return image;
+			}
+		
+            JpegImageData jpegImageData = dir.getJpegImageData();
+            if (jpegImageData != null) {
+                ByteArrayInputStream input = new ByteArrayInputStream(jpegImageData.data);
+                // JPEG thumbnail as JPEG or other format; try to parse.
+               	image = ImageIO.read(input);
+                if (image != null) {
+                    return image;
+                }
+            }
 		}
 
 		return null;

Added: commons/proper/sanselan/trunk/src/test/data/images/jpg/3/img_F028c_small.jpg
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/data/images/jpg/3/img_F028c_small.jpg?rev=995556&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/sanselan/trunk/src/test/data/images/jpg/3/img_F028c_small.jpg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: commons/proper/sanselan/trunk/src/test/data/images/jpg/3/info.txt
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/data/images/jpg/3/info.txt?rev=995556&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/test/data/images/jpg/3/info.txt (added)
+++ commons/proper/sanselan/trunk/src/test/data/images/jpg/3/info.txt Thu Sep  9 19:34:07
2010
@@ -0,0 +1,3 @@
+Image contributed by James E-J
+
+Demonstrates JPEG with thumbnail stored as JPEG (not TIFF).
\ No newline at end of file

Propchange: commons/proper/sanselan/trunk/src/test/data/images/jpg/3/info.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java?rev=995556&r1=995555&r2=995556&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java
(original)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegBaseTest.java
Thu Sep  9 19:34:07 2010
@@ -29,7 +29,6 @@ import org.apache.sanselan.SanselanTest;
 public abstract class JpegBaseTest extends SanselanTest
 {
 
-
 	protected static boolean isJpeg(File file) throws IOException,
 			ImageReadException
 	{

Added: commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java?rev=995556&view=auto
==============================================================================
--- commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java
(added)
+++ commons/proper/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegWithJpegThumbnailTest.java
Thu Sep  9 19:34:07 2010
@@ -0,0 +1,46 @@
+/*
+ * 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;
+
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.Sanselan;
+import org.apache.sanselan.SanselanTest;
+import org.apache.sanselan.common.IImageMetadata;
+
+public class JpegWithJpegThumbnailTest extends SanselanTest {
+
+	public void testSingleImage() throws IOException, ImageReadException,
+			ImageWriteException {
+		File imageFile = getTestImageByName("img_F028c_small.jpg");
+
+		Map params = new HashMap();
+		IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
+		assertNotNull(metadata);
+		JpegImageMetadata jpegMetadata = (JpegImageMetadata) metadata;
+		BufferedImage image = jpegMetadata.getEXIFThumbnail(); 
+		assertNotNull(image);
+	}
+}
+

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



Mime
View raw message