You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by cm...@apache.org on 2009/09/12 18:23:54 UTC

svn commit: r814186 - in /commons/proper/sanselan/trunk: RELEASE_NOTES src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java

Author: cmchen
Date: Sat Sep 12 16:23:54 2009
New Revision: 814186

URL: http://svn.apache.org/viewvc?rev=814186&view=rev
Log:
* Applied patch contributed by Nicolas Richeton, adding getEXIFThumbnailSize() and getEXIFThumbnailData() methods to JpegImageMetadata.

Modified:
    commons/proper/sanselan/trunk/RELEASE_NOTES
    commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageMetadata.java

Modified: commons/proper/sanselan/trunk/RELEASE_NOTES
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/RELEASE_NOTES?rev=814186&r1=814185&r2=814186&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/RELEASE_NOTES (original)
+++ commons/proper/sanselan/trunk/RELEASE_NOTES Sat Sep 12 16:23:54 2009
@@ -20,6 +20,8 @@
    This appears to be a bug in how Microsoft Office writes gifs.
    The Image Descriptor has the correct value.
  * Added accessor methods for a number of ImageInfo properties.
+ * Applied patch contributed by Nicolas Richeton, adding getEXIFThumbnailSize() and getEXIFThumbnailData() 
+ 	methods to JpegImageMetadata.
 
 Release 0.97
 ------------

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=814186&r1=814185&r2=814186&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 Sat Sep 12 16:23:54 2009
@@ -16,11 +16,13 @@
  */
 package org.apache.sanselan.formats.jpeg;
 
+import java.awt.Dimension;
 import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.util.ArrayList;
 
 import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.Sanselan;
 import org.apache.sanselan.common.IImageMetadata;
 import org.apache.sanselan.formats.tiff.TiffField;
 import org.apache.sanselan.formats.tiff.TiffImageData;
@@ -82,6 +84,48 @@
 		return null;
 	}
 
+	/**
+	 * Returns the size of the first JPEG thumbnail found in the EXIF metadata.
+	 * 
+	 * @return Thumbnail width and height or null if no thumbnail.
+	 * @throws ImageReadException
+	 * @throws IOException
+	 */
+	public Dimension getEXIFThumbnailSize() throws ImageReadException, IOException {
+		byte[] data = getEXIFThumbnailData();
+			
+		if( data != null ){
+			return Sanselan.getImageSize(data);
+		}
+	    return null;
+	}	
+	
+	/**
+	 * Returns the data of the first JPEG thumbnail found in the EXIF metadata.  
+	 * 
+	 * @return JPEG data or null if no thumbnail.
+	 * @throws ImageReadException
+	 * @throws IOException
+	 */
+	public byte[] getEXIFThumbnailData() throws ImageReadException, IOException {
+		ArrayList dirs = exif.getDirectories();
+		for (int i = 0; i < dirs.size(); i++) {
+			TiffImageMetadata.Directory dir = (TiffImageMetadata.Directory) dirs
+					.get(i);
+			
+			byte[] data = null;
+			if( dir.getJpegImageData() != null ){
+				data = dir.getJpegImageData().data;
+			}
+			// Support other image formats here.
+			
+			if( data != null ){
+				return data;
+			}
+		}
+		return null;
+	}
+
 	public BufferedImage getEXIFThumbnail() throws ImageReadException,
 			IOException {
 		ArrayList dirs = exif.getDirectories();