incubator-sanselan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmc...@apache.org
Subject svn commit: r688558 [2/2] - in /incubator/sanselan/trunk: ./ src/main/java/org/apache/sanselan/common/ src/main/java/org/apache/sanselan/formats/jpeg/ src/main/java/org/apache/sanselan/formats/jpeg/iptc/ src/main/java/org/apache/sanselan/formats/jpeg/s...
Date Sun, 24 Aug 2008 20:47:31 GMT
Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/App13Segment.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/App13Segment.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/App13Segment.java
(original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/segments/App13Segment.java
Sun Aug 24 13:47:30 2008
@@ -19,17 +19,19 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.ArrayList;
+import java.util.Map;
 
 import org.apache.sanselan.ImageReadException;
-import org.apache.sanselan.formats.jpeg.IptcElement;
-import org.apache.sanselan.formats.jpeg.IptcType;
 import org.apache.sanselan.formats.jpeg.JpegImageParser;
+import org.apache.sanselan.formats.jpeg.iptc.IPTCParser;
+import org.apache.sanselan.formats.jpeg.iptc.PhotoshopApp13Data;
 
 public class App13Segment extends APPNSegment
 {
 	protected final JpegImageParser parser;
-	public final ArrayList elements = new ArrayList();
+
+	// public final ArrayList elements = new ArrayList();
+	// public final boolean isIPTCJpegSegment;
 
 	public App13Segment(JpegImageParser parser, int marker, byte segmentData[])
 			throws ImageReadException, IOException
@@ -38,97 +40,43 @@
 				segmentData));
 	}
 
-	// TODO:
 	public App13Segment(JpegImageParser parser, int marker, int marker_length,
 			InputStream is) throws ImageReadException, IOException
 	{
 		super(marker, marker_length, is);
 		this.parser = parser;
 
-		boolean verbose = false;
-
-		if (!compareByteArrays(bytes, 0,
-				JpegImageParser.PhotoshopIdentificationString, 0,
-				JpegImageParser.PhotoshopIdentificationString.length))
-			throw new ImageReadException("Invalid App13 Segment");
-		//			readAndVerifyBytes("Photoshop Identification String", bais,
-		//					kPhotoshopIdentificationString, "Invalid App13 Segment");
-
-		int index = JpegImageParser.PhotoshopIdentificationString.length;
-		while (index < bytes.length)
-		{
-			if (!compareByteArrays(bytes, index, JpegImageParser.CONST_8BIM, 0,
-					JpegImageParser.CONST_8BIM.length))
-			{
-				//					dump(index);
-				throw new ImageReadException("Invalid .CONST_8BIM Segment");
-			}
-			index += JpegImageParser.CONST_8BIM.length;
-
-			int segmentType = convertByteArrayToShort("SegmentType", index,
-					bytes);
-			if (verbose)
-				debugNumber("segmentType", segmentType, 2);
-			index += 2;
-
-			// padding
-			index += 4;
-
-			int segmentSize = convertByteArrayToShort("SegmentSize", index,
-					bytes);
-			if (verbose)
-				debugNumber("segmentSize", segmentSize, 2);
-			index += 2;
-
-			int index2 = index;
-
-			index += segmentSize;
-
-			while (index2 + 1 < index)
-			{
-				int iptcPrefix = convertByteArrayToShort("IPTCPrefix", index2,
-						bytes);
-				if (verbose)
-					debugNumber("IPTCPrefix", iptcPrefix, 2);
-				index2 += 2;
-
-				if (iptcPrefix == 0x1c02)
-				{
-					//						System.out.println("								TEXTBLOCK:  "
-					//								+ fSegmentType);
-				}
-				else
-				{
-					//						System.out.println("								!TEXTBLOCK: " + fSegmentType);
-					break;
-				}
-
-				byte iptcSegmentType = bytes[index2];
-				//					debugNumber("fIPTCSegmentType", fIPTCSegmentType);
-				index2++;
-
-				int iptcSegmentSize = convertByteArrayToShort(
-						"IPTCSegmentSize", index2, bytes);
-				//					debugNumber("fIPTCegmentSize", fIPTCegmentSize, 2);
-				index2 += 2;
-
-				byte iptcData[] = readBytearray("iptc_data", bytes, index2,
-						iptcSegmentSize);
-				index2 += iptcSegmentSize;
-
-				String value = new String(iptcData);
-				//					System.out.println("iptc_data: '" + value + "' ("
-				//							+ fIPTCegmentSize + ")");
-
-				IptcType iptcType = IptcType.getIptcType(iptcSegmentType);
-				IptcElement element = new IptcElement(iptcType, value);
-				elements.add(element);
-			}
-
-			if ((segmentSize % 2) != 0)
-				index++;
-		}
+		// isIPTCJpegSegment = new IPTCParser().isIPTCJpegSegment(bytes);
+		// if (isIPTCJpegSegment)
+		// {
+		// /*
+		// * In practice, App13 segments are only used for Photoshop/IPTC
+		// * metadata. However, we should not treat App13 signatures without
+		// * Photoshop's signature as Photoshop/IPTC segments.
+		// */
+		// boolean verbose = false;
+		// boolean strict = false;
+		// elements.addAll(new IPTCParser().parseIPTCJPEGSegment(bytes,
+		// verbose, strict));
+		// }
+	}
 
+	public boolean isPhotoshopJpegSegment() throws ImageReadException, IOException
+	{
+		return new IPTCParser().isPhotoshopJpegSegment(bytes);
 	}
 
+	public PhotoshopApp13Data parsePhotoshopSegment(Map params)
+			throws ImageReadException, IOException
+	{
+		/*
+		 * In practice, App13 segments are only used for Photoshop/IPTC
+		 * metadata. However, we should not treat App13 signatures without
+		 * Photoshop's signature as Photoshop/IPTC segments.
+		 */
+		if (!new IPTCParser().isPhotoshopJpegSegment(bytes))
+			return null;
+
+		return new IPTCParser().parsePhotoshopSegment(bytes, params);
+	}
 }
\ No newline at end of file

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegRewriter.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegRewriter.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegRewriter.java
(original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/xmp/JpegRewriter.java
Sun Aug 24 13:47:30 2008
@@ -16,10 +16,7 @@
  */
 package org.apache.sanselan.formats.jpeg.xmp;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -28,16 +25,9 @@
 import org.apache.sanselan.ImageWriteException;
 import org.apache.sanselan.common.BinaryFileParser;
 import org.apache.sanselan.common.byteSources.ByteSource;
-import org.apache.sanselan.common.byteSources.ByteSourceArray;
-import org.apache.sanselan.common.byteSources.ByteSourceFile;
-import org.apache.sanselan.common.byteSources.ByteSourceInputStream;
 import org.apache.sanselan.formats.jpeg.JpegConstants;
 import org.apache.sanselan.formats.jpeg.JpegUtils;
-import org.apache.sanselan.formats.tiff.write.TiffImageWriterBase;
-import org.apache.sanselan.formats.tiff.write.TiffImageWriterLossless;
-import org.apache.sanselan.formats.tiff.write.TiffImageWriterLossy;
-import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
-import org.apache.sanselan.util.Debug;
+import org.apache.sanselan.formats.jpeg.iptc.IPTCParser;
 
 /**
  * Interface for Exif write/update/remove functionality for Jpeg/JFIF images.
@@ -76,6 +66,11 @@
 	protected abstract static class JFIFPiece
 	{
 		protected abstract void write(OutputStream os) throws IOException;
+		
+		public String toString()
+		{
+			return "[" + this.getClass().getSimpleName() + "]";
+		}
 	}
 
 	protected static class JFIFPieceSegment extends JFIFPiece
@@ -88,7 +83,7 @@
 		public JFIFPieceSegment(final int marker, final byte[] segmentData)
 		{
 			this(marker, int2ToByteArray(marker, JPEG_BYTE_ORDER),
-					int2ToByteArray(segmentData.length+2, JPEG_BYTE_ORDER),
+					int2ToByteArray(segmentData.length + 2, JPEG_BYTE_ORDER),
 					segmentData);
 		}
 
@@ -101,6 +96,11 @@
 			this.segmentData = segmentData;
 		}
 
+		public String toString()
+		{
+			return "[" + this.getClass().getSimpleName() + " (0x" + Integer.toHexString(marker) +
")]";
+		}
+
 		protected void write(OutputStream os) throws IOException
 		{
 			os.write(markerBytes);
@@ -127,6 +127,15 @@
 			return true;
 		}
 
+		public boolean isPhotoshopApp13Segment()
+		{
+			if (marker != JPEG_APP13_Marker)
+				return false;
+			if (!new IPTCParser().isPhotoshopJpegSegment(segmentData))
+				return false;
+			return true;
+		}
+
 		public boolean isXmpSegment()
 		{
 			if (marker != JPEG_APP1_Marker)
@@ -216,11 +225,28 @@
 		}
 	};
 
+	private static final SegmentFilter PHOTOSHOP_APP13_SEGMENT_FILTER = new SegmentFilter()
{
+		public boolean filter(JFIFPieceSegment segment)
+		{
+			return segment.isPhotoshopApp13Segment();
+		}
+	};
+
 	protected List removeXmpSegments(List segments)
 	{
 		return filterSegments(segments, XMP_SEGMENT_FILTER);
 	}
 
+	protected List removePhotoshopApp13Segments(List segments)
+	{
+		return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER);
+	}
+
+	protected List findPhotoshopApp13Segments(List segments)
+	{
+		return filterSegments(segments, PHOTOSHOP_APP13_SEGMENT_FILTER, true);
+	}
+
 	protected List removeExifSegments(List segments)
 	{
 		return filterSegments(segments, EXIF_SEGMENT_FILTER);
@@ -228,6 +254,12 @@
 
 	protected List filterSegments(List segments, SegmentFilter filter)
 	{
+		return filterSegments(segments, filter, false);
+	}
+
+	protected List filterSegments(List segments, SegmentFilter filter,
+			boolean reverse)
+	{
 		List result = new ArrayList();
 
 		for (int i = 0; i < segments.size(); i++)
@@ -235,9 +267,9 @@
 			JFIFPiece piece = (JFIFPiece) segments.get(i);
 			if (piece instanceof JFIFPieceSegment)
 			{
-				if (!filter.filter((JFIFPieceSegment) piece))
+				if (filter.filter((JFIFPieceSegment) piece) ^ !reverse)
 					result.add(piece);
-			} else
+			} else if(!reverse)
 				result.add(piece);
 		}
 

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldType.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldType.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldType.java
(original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldType.java
Sun Aug 24 13:47:30 2008
@@ -22,9 +22,8 @@
 import org.apache.sanselan.formats.tiff.TiffField;
 import org.apache.sanselan.formats.tiff.constants.TiffConstants;
 
-public abstract class FieldType extends BinaryFileFunctions
-		implements
-			TiffConstants
+public abstract class FieldType extends BinaryFileFunctions implements
+		TiffConstants
 {
 	public final int type, length;
 	public final String name;
@@ -49,7 +48,8 @@
 		return length * entry.length;
 	}
 
-	//	public static final byte[] STUB_LOCAL_VALUE  = new byte[TIFF_ENTRY_MAX_VALUE_LENGTH];
+	// public static final byte[] STUB_LOCAL_VALUE = new
+	// byte[TIFF_ENTRY_MAX_VALUE_LENGTH];
 
 	public static final byte[] getStubLocalValue()
 	{
@@ -73,10 +73,14 @@
 	{
 		if (isLocalValue(entry))
 		{
-			return readBytearray(name, entry.valueOffsetBytes, 0, length
-					* entry.length);
-			//			return getBytearrayHead(name + " (" + entry.tagInfo.name + ")",
-			//					entry.valueOffsetBytes, length * entry.length);
+			int rawLength = length * entry.length;
+			byte result[] = new byte[rawLength];
+			System.arraycopy(entry.valueOffsetBytes, 0, result, 0, rawLength);
+			return result;
+//			return readBytearray(name, entry.valueOffsetBytes, 0, length
+//					* entry.length);
+			// return getBytearrayHead(name + " (" + entry.tagInfo.name + ")",
+			// entry.valueOffsetBytes, length * entry.length);
 		}
 
 		return entry.oversizeValue;
@@ -85,17 +89,17 @@
 	public abstract Object getSimpleValue(TiffField entry)
 			throws ImageReadException;
 
-	//	public final Object getSimpleValue(TiffField entry)
-	//	{
-	//		Object array[] = getValueArray(entry);
-	//		if (null == array)
-	//			return null;
-	//		if (array.length == 1)
-	//			return array[0];
-	//		return array;
-	//	}
+	// public final Object getSimpleValue(TiffField entry)
+	// {
+	// Object array[] = getValueArray(entry);
+	// if (null == array)
+	// return null;
+	// if (array.length == 1)
+	// return array[0];
+	// return array;
+	// }
 	//
-	//	public abstract Object[] getValueArray(TiffField entry);
+	// public abstract Object[] getValueArray(TiffField entry);
 
 	public String toString()
 	{

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java
(original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeASCII.java
Sun Aug 24 13:47:30 2008
@@ -26,7 +26,7 @@
 		super(type, 1, name);
 	}
 
-	public Object getSimpleValue(TiffField entry)
+	public Object getSimpleValue(TiffField entry) 
 	{
 		return new String(getRawBytes(entry));
 	}

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java (original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/SanselanTest.java Sun Aug 24
13:47:30 2008
@@ -116,22 +116,43 @@
 		File testFolder = new File(srcFolder, "test");
 		File dataFolder = new File(testFolder, "data");
 		File imagesFolder = new File(dataFolder, "images");
-		
-//		 imagesFolder = new File(imagesFolder, "ignore\\xml-sdk-examples\\BlueSquare.psd");
-//		 imagesFolder = new File(imagesFolder, "ignore\\PngSuite\\BGYN6A16.PNG");
+
+		// imagesFolder = new File(imagesFolder,
+		// "ignore\\xml-sdk-examples\\BlueSquare.psd");
+		// imagesFolder = new File(imagesFolder,
+		// "exif\\drewNoakes\\007_Canon EOS D60.jpg");
+		// imagesFolder = new File(imagesFolder,
+		// "ignore\\PngSuite\\BGYN6A16.PNG");
 		// imagesFolder = new File(imagesFolder, "jpg\\3");
 		// imagesFolder = new File(imagesFolder, "");
 		// imagesFolder = new File(imagesFolder,
 		// "exif\\philHarvey\\Nokia\\Nokia5500.jpg");
-//		imagesFolder = new File(imagesFolder, "png\\2\\");
+		// imagesFolder = new File(imagesFolder, "png\\2\\");
 		// imagesFolder = new File(imagesFolder,
 		// "exif\\drewNoakes\\007_FujiFilm FinePixS1Pro (5).jpg");
+		// imagesFolder = new File(imagesFolder,
+		// "iptc");
 		// src\\test\\data\\images\\exif\\drewNoakes\\007_Nikon D1X.jpg
 		// src\\test\\data\\images\\exif\\drewNoakes\\007_FujiFilm FinePixS1Pro
 		// (5).jpg
+		// imagesFolder = new File(imagesFolder,
+		// "exif\\drewNoakes\\007_Nikon D70.jpg");
+		// imagesFolder = new File(imagesFolder,
+		// "exif\\philHarvey\\Canon\\CanonEOS_D2000.jpg");
+		// imagesFolder = new File(imagesFolder,
+		// "exif\\philHarvey\\Motorola\\MotorolaE365.jpg");
+		// imagesFolder = new File(
+		// "C:\\work\\personal\\apache\\sanselan\\src\\test\\data\\images\\exif\\drewNoakes\\007_Canon
EOS D60.jpg"
+		// );
+		// imagesFolder = new File(
+		// "C:\\work\\personal\\apache\\sanselan\\src\\test\\data\\images\\exif\\drewNoakes\\007_FujiFilm
FinePixS1Pro (1).jpg"
+		// );
+		// imagesFolder = new File(
+		// "C:\\work\\personal\\apache\\sanselan\\src\\test\\data\\images\\exif\\philHarvey\\Nikon\\NikonCoolpixS7.jpg"
+		// );
 
 		imagesFolder = imagesFolder.getAbsoluteFile();
-		
+
 		assertTrue(imagesFolder.exists());
 
 		Debug.debug("imagesFolder", imagesFolder);
@@ -188,4 +209,10 @@
 
 		return filtered;
 	}
+
+	protected boolean isInvalidPNGTestFile(File file)
+	{
+		return (file.getParentFile().getName().equalsIgnoreCase("pngsuite") && file
+				.getName().toLowerCase().startsWith("x"));
+	}
 }

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegReadTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegReadTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegReadTest.java
(original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/JpegReadTest.java
Sun Aug 24 13:47:30 2008
@@ -56,6 +56,7 @@
 
 			IImageMetadata metadata = Sanselan.getMetadata(imageFile, params);
 			//			assertNotNull(metadata);
+			Debug.debug("metadata", metadata);
 
 			ImageInfo imageInfo = Sanselan.getImageInfo(imageFile, params);
 			assertNotNull(imageInfo);

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java?rev=688558&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java
(added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java
Sun Aug 24 13:47:30 2008
@@ -0,0 +1,113 @@
+/*
+ * 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.iptc;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.SanselanTest;
+import org.apache.sanselan.common.byteSources.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSourceFile;
+import org.apache.sanselan.formats.jpeg.JpegImageParser;
+
+public abstract class IptcBaseTest extends SanselanTest
+{
+	//	public IptcBaseTest(String name)
+	//	{
+	//		super(name);
+	//	}
+
+	protected static boolean hasIptcData(File file) throws IOException,
+			ImageReadException
+	{
+		//		Debug.debug("hasIptcData file", file.getAbsoluteFile());
+
+		if (!file.getName().toLowerCase().endsWith(".jpg"))
+			return false;
+		//ImageFormat format = Sanselan.guessFormat(file);
+		//if (format != ImageFormat.IMAGE_FORMAT_JPEG)
+		//	return false;
+
+		//		Debug.debug("possible file", file);
+
+		try
+		{
+			ByteSource byteSource = new ByteSourceFile(file);
+			return new JpegImageParser().hasIptcSegment(byteSource);
+		}
+		catch (Exception e)
+		{
+			//			Debug.debug("Error file", file.getAbsoluteFile());
+			//			Debug.debug(e, 4);
+			return false;
+		}
+	}
+
+	private static final ImageFilter HAS_IPTC_IMAGE_FILTER = new ImageFilter()
+	{
+		public boolean accept(File file) throws IOException, ImageReadException
+		{
+			return hasIptcData(file);
+		}
+	};
+
+	private static final ImageFilter JPEG_IMAGE_FILTER = new ImageFilter()
+	{
+		public boolean accept(File file) throws IOException, ImageReadException
+		{
+			return file.getName().toLowerCase().endsWith(".jpg");
+		}
+	};
+
+	protected File getImageWithIptcData() throws IOException,
+			ImageReadException
+	{
+		return getTestImage(HAS_IPTC_IMAGE_FILTER);
+	}
+
+	protected List getImagesWithIptcData() throws IOException,
+			ImageReadException
+	{
+		return getTestImages(HAS_IPTC_IMAGE_FILTER);
+	}
+
+	protected List getImagesWithIptcData(int max) throws IOException,
+			ImageReadException
+	{
+		return getTestImages(HAS_IPTC_IMAGE_FILTER, max);
+	}
+
+	protected File getJpegImage() throws IOException, ImageReadException
+	{
+		return getTestImage(JPEG_IMAGE_FILTER);
+	}
+
+	protected List getJpegImages() throws IOException, ImageReadException
+	{
+		return getTestImages(JPEG_IMAGE_FILTER);
+	}
+
+	protected List getJpegImages(int max) throws IOException,
+			ImageReadException
+	{
+		return getTestImages(JPEG_IMAGE_FILTER, max);
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcBaseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java?rev=688558&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java
(added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java
Sun Aug 24 13:47:30 2008
@@ -0,0 +1,73 @@
+/*
+ * 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.iptc;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+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.byteSources.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSourceFile;
+import org.apache.sanselan.formats.jpeg.JpegImageMetadata;
+import org.apache.sanselan.formats.jpeg.JpegUtils;
+import org.apache.sanselan.util.Debug;
+
+public class IptcDumpTest extends IptcBaseTest
+{
+
+	public void test() throws IOException, ImageReadException,
+			ImageWriteException
+	{
+		List images = getImagesWithIptcData();
+		for (int i = 0; i < images.size(); i++)
+		{
+			if (i % 10 == 0)
+				Debug.purgeMemory();
+
+			File imageFile = (File) images.get(i);
+			Debug.debug("imageFile", imageFile);
+			Debug.debug();
+
+			// ByteSource byteSource = new ByteSourceFile(imageFile);
+			// Debug.debug("Segments:");
+			// new JpegUtils().dumpJFIF(byteSource);
+
+			Map params = new HashMap();
+			boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+			params
+					.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+							!ignoreImageData));
+//			params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+
+			JpegImageMetadata metadata = (JpegImageMetadata) Sanselan
+					.getMetadata(imageFile, params);
+			assertNotNull(metadata);
+			assertNotNull(metadata.getPhotoshop());
+
+			metadata.getPhotoshop().dump();
+			// if(metadata.getPhotoshop().getItems().size()>0)
+//			Debug.debug("iptc size", metadata.getPhotoshop().getItems().size());
+		}
+	}
+
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcDumpTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java?rev=688558&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java
(added)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java
Sun Aug 24 13:47:30 2008
@@ -0,0 +1,308 @@
+/*
+ * 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.iptc;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.common.byteSources.ByteSource;
+import org.apache.sanselan.common.byteSources.ByteSourceFile;
+import org.apache.sanselan.formats.jpeg.JpegImageParser;
+import org.apache.sanselan.formats.jpeg.JpegPhotoshopMetadata;
+import org.apache.sanselan.formats.jpeg.JpegUtils;
+import org.apache.sanselan.util.Debug;
+
+public class IptcUpdateTest extends IptcBaseTest
+{
+	private List imagesWithIptcData;
+
+	public void setUp() throws Exception
+	{
+		super.setUp();
+
+		imagesWithIptcData = getImagesWithIptcData();
+	}
+
+//	public void testRemove() throws IOException, ImageReadException,
+//			ImageWriteException
+//	{
+//		List images = imagesWithIptcData;
+//		for (int i = 0; i < images.size(); i++)
+//		{
+//			if (i % 10 == 0)
+//				Debug.purgeMemory();
+//
+//			File imageFile = (File) images.get(i);
+//			Debug.debug("imageFile", imageFile);
+//			Debug.debug();
+//
+//			ByteSource byteSource = new ByteSourceFile(imageFile);
+//			// Debug.debug("Segments:");
+//			// new JpegUtils().dumpJFIF(byteSource);
+//
+//			Map params = new HashMap();
+//			boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+//			params
+//					.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+//							!ignoreImageData));
+//			// params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+//			// params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+//
+//			JpegPhotoshopMetadata metadata = new JpegImageParser()
+//					.getPhotoshopMetadata(byteSource, params);
+//			assertNotNull(metadata);
+//			metadata.dump();
+//
+//			File noIptcFile = createTempFile(imageFile.getName()
+//					+ ".iptc.remove.", ".jpg");
+//			{
+//				// test remove
+//
+//				OutputStream os = null;
+//				try
+//				{
+//					os = new FileOutputStream(noIptcFile);
+//					os = new BufferedOutputStream(os);
+//					new JpegIptcRewriter().removeIPTC(byteSource, os);
+//				} finally
+//				{
+//					os.close();
+//					os = null;
+//				}
+//
+//				// Debug.debug("Source Segments:");
+//				// new JpegUtils().dumpJFIF(new ByteSourceFile(noIptcFile));
+//
+//				JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+//						.getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
+//								params);
+//				assertTrue(outMetadata == null
+//						|| outMetadata.getItems().size() == 0);
+//			}
+//
+//		}
+//	}
+
+	public void testRemoveInsertUpdate() throws IOException,
+			ImageReadException, ImageWriteException
+	{
+		List images = imagesWithIptcData;
+		for (int i = 0; i < images.size(); i++)
+		{
+			if (i % 10 == 0)
+				Debug.purgeMemory();
+
+			File imageFile = (File) images.get(i);
+			Debug.debug("imageFile", imageFile);
+			Debug.debug();
+
+			ByteSource byteSource = new ByteSourceFile(imageFile);
+			// Debug.debug("Segments:");
+			// new JpegUtils().dumpJFIF(byteSource);
+
+			Map params = new HashMap();
+			boolean ignoreImageData = isPhilHarveyTestImage(imageFile);
+			params
+					.put(PARAM_KEY_READ_THUMBNAILS, new Boolean(
+							!ignoreImageData));
+			// params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+			// params.put(PARAM_KEY_VERBOSE, Boolean.TRUE);
+
+			JpegPhotoshopMetadata metadata = new JpegImageParser()
+					.getPhotoshopMetadata(byteSource, params);
+			assertNotNull(metadata);
+			metadata.dump();
+
+			File noIptcFile = createTempFile(imageFile.getName()
+					+ ".iptc.remove.", ".jpg");
+			{
+				// test remove
+
+				OutputStream os = null;
+				try
+				{
+					os = new FileOutputStream(noIptcFile);
+					os = new BufferedOutputStream(os);
+					new JpegIptcRewriter().removeIPTC(byteSource, os);
+				} finally
+				{
+					os.close();
+					os = null;
+				}
+
+				// Debug.debug("Source Segments:");
+				// new JpegUtils().dumpJFIF(new ByteSourceFile(noIptcFile));
+
+				JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+						.getPhotoshopMetadata(new ByteSourceFile(noIptcFile),
+								params);
+				assertTrue(outMetadata == null
+						|| outMetadata.getItems().size() == 0);
+			}
+			{
+				// test no-change update
+
+				List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
+				List oldRecords = metadata.photoshopApp13Data.getRecords();
+				List newRecords = new ArrayList();
+				for (int j = 0; j < oldRecords.size(); j++)
+				{
+					IPTCRecord record = (IPTCRecord) oldRecords.get(j);
+					if (record.iptcType.type != IPTCConstants.IPTC_TYPE_CITY.type
+							&& record.iptcType.type != IPTCConstants.IPTC_TYPE_CREDIT.type)
+						newRecords.add(record);
+				}
+
+				newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
+						"Albany, NY"));
+				newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
+						"William Sorensen"));
+
+				PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
+						newBlocks);
+
+				File updated = createTempFile(imageFile.getName()
+						+ ".iptc.update.", ".jpg");
+				OutputStream os = null;
+				try
+				{
+					os = new FileOutputStream(updated);
+					os = new BufferedOutputStream(os);
+					new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
+				} finally
+				{
+					os.close();
+					os = null;
+				}
+
+				// Debug.debug("Source Segments:");
+				// new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+				ByteSource updateByteSource = new ByteSourceFile(updated);
+				JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+						.getPhotoshopMetadata(updateByteSource, params);
+
+				// Debug.debug("outMetadata", outMetadata.toString());
+				// Debug.debug("hasIptcSegment", new JpegImageParser()
+				// .hasIptcSegment(updateByteSource));
+
+				assertNotNull(outMetadata);
+				assertTrue(outMetadata.getItems().size() == newRecords.size());
+				// assertEquals(metadata.toString(), outMetadata.toString());
+			}
+
+			{
+				// test update
+
+				List newBlocks = metadata.photoshopApp13Data.getNonIptcBlocks();
+				List newRecords = new ArrayList();
+
+				newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
+						"Albany, NY"));
+				newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
+						"William Sorensen"));
+
+				PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
+						newBlocks);
+
+				File updated = createTempFile(imageFile.getName()
+						+ ".iptc.update.", ".jpg");
+				OutputStream os = null;
+				try
+				{
+					os = new FileOutputStream(updated);
+					os = new BufferedOutputStream(os);
+					new JpegIptcRewriter().writeIPTC(byteSource, os, newData);
+				} finally
+				{
+					os.close();
+					os = null;
+				}
+
+				// Debug.debug("Source Segments:");
+				// new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+				ByteSource updateByteSource = new ByteSourceFile(updated);
+				JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+						.getPhotoshopMetadata(updateByteSource, params);
+
+				// Debug.debug("outMetadata", outMetadata.toString());
+				// Debug.debug("hasIptcSegment", new JpegImageParser()
+				// .hasIptcSegment(updateByteSource));
+
+				assertNotNull(outMetadata);
+				assertTrue(outMetadata.getItems().size() == 2);
+				// assertEquals(metadata.toString(), outMetadata.toString());
+			}
+
+			{
+				// test insert
+
+				List newBlocks = new ArrayList();
+				List newRecords = new ArrayList();
+
+				newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CITY,
+						"Albany, NY"));
+				newRecords.add(new IPTCRecord(IPTCConstants.IPTC_TYPE_CREDIT,
+						"William Sorensen"));
+
+				PhotoshopApp13Data newData = new PhotoshopApp13Data(newRecords,
+						newBlocks);
+
+				File updated = createTempFile(imageFile.getName()
+						+ ".iptc.insert.", ".jpg");
+				OutputStream os = null;
+				try
+				{
+					os = new FileOutputStream(updated);
+					os = new BufferedOutputStream(os);
+					new JpegIptcRewriter().writeIPTC(new ByteSourceFile(noIptcFile), os, newData);
+				} finally
+				{
+					os.close();
+					os = null;
+				}
+
+				// Debug.debug("Source Segments:");
+				// new JpegUtils().dumpJFIF(new ByteSourceFile(updated));
+
+				ByteSource updateByteSource = new ByteSourceFile(updated);
+				JpegPhotoshopMetadata outMetadata = new JpegImageParser()
+						.getPhotoshopMetadata(updateByteSource, params);
+
+				// Debug.debug("outMetadata", outMetadata.toString());
+				// Debug.debug("hasIptcSegment", new JpegImageParser()
+				// .hasIptcSegment(updateByteSource));
+
+				assertNotNull(outMetadata);
+				assertTrue(outMetadata.getItems().size() == 2);
+				// assertEquals(metadata.toString(), outMetadata.toString());
+			}
+
+		}
+	}
+}

Propchange: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/iptc/IptcUpdateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpBaseTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpBaseTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpBaseTest.java
(original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpBaseTest.java
Sun Aug 24 13:47:30 2008
@@ -70,19 +70,19 @@
 //		}
 //	};
 
-	protected File getImageWithIptcData() throws IOException,
+	protected File getImageWithXmpData() throws IOException,
 			ImageReadException
 	{
 		return getTestImage(HAS_JPEG_XMP_IMAGE_FILTER);
 	}
 
-	protected List getImagesWithIptcData() throws IOException,
+	protected List getImagesWithXmpData() throws IOException,
 			ImageReadException
 	{
 		return getTestImages(HAS_JPEG_XMP_IMAGE_FILTER);
 	}
 
-	protected List getImagesWithIptcData(int max) throws IOException,
+	protected List getImagesWithXmpData(int max) throws IOException,
 			ImageReadException
 	{
 		return getTestImages(HAS_JPEG_XMP_IMAGE_FILTER, max);

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpDumpTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpDumpTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpDumpTest.java
(original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpDumpTest.java
Sun Aug 24 13:47:30 2008
@@ -36,7 +36,7 @@
 	public void test() throws IOException, ImageReadException,
 			ImageWriteException
 	{
-		List images = getImagesWithIptcData();
+		List images = getImagesWithXmpData();
 		for (int i = 0; i < images.size(); i++)
 		{
 			if (i % 10 == 0)

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriteTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriteTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriteTest.java
(original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/xmp/JpegXmpRewriteTest.java
Sun Aug 24 13:47:30 2008
@@ -37,10 +37,10 @@
 public class JpegXmpRewriteTest extends JpegXmpBaseTest
 {
 
-	public void testRemove() throws IOException, ImageReadException,
+	public void testRemoveInsertUpdate() throws IOException, ImageReadException,
 			ImageWriteException
 	{
-		List images = getImagesWithIptcData();
+		List images = getImagesWithXmpData();
 		for (int i = 0; i < images.size(); i++)
 		{
 			if (i % 10 == 0)

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngBaseTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngBaseTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngBaseTest.java
(original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngBaseTest.java
Sun Aug 24 13:47:30 2008
@@ -53,10 +53,6 @@
 		return getTestImages(imageFilter);
 	}
 
-	protected boolean isInvalidPNGTestFile(File file)
-	{
-		return (file.getParentFile().getName().equalsIgnoreCase("pngsuite") && file
-				.getName().toLowerCase().startsWith("x"));
-	}
+
 
 }

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngMultipleRoundtripTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngMultipleRoundtripTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngMultipleRoundtripTest.java
(original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/png/PngMultipleRoundtripTest.java
Sun Aug 24 13:47:30 2008
@@ -20,9 +20,7 @@
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 
 import org.apache.sanselan.ImageFormat;
@@ -38,7 +36,7 @@
 			ImageWriteException
 	{
 		File imagesFolder = new File("src\\test\\data\\images\\png\\3");
-		assert(imagesFolder.exists() && imagesFolder.isDirectory());
+		assertTrue(imagesFolder.exists() && imagesFolder.isDirectory());
 		
 		File files[] = imagesFolder.listFiles();
 		for (int i = 0; i < files.length; i++)

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/xmp/XmpDumpTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/xmp/XmpDumpTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/xmp/XmpDumpTest.java
(original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/xmp/XmpDumpTest.java
Sun Aug 24 13:47:30 2008
@@ -45,13 +45,18 @@
 				Debug.purgeMemory();
 
 			File imageFile = (File) images.get(i);
+
+			if (imageFile.getName().toLowerCase().endsWith(".png")
+					&& isInvalidPNGTestFile(imageFile))
+				continue;
+
 			Debug.debug("imageFile", imageFile);
 			Debug.debug();
 
 			String xmpXml = Sanselan.getXmpXml(imageFile);
-			if(null==xmpXml)
+			if (null == xmpXml)
 				continue;
-			
+
 			assertNotNull(xmpXml);
 
 			Debug.debug("xmpXml", xmpXml);

Modified: incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/xmp/XmpUpdateTest.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/xmp/XmpUpdateTest.java?rev=688558&r1=688557&r2=688558&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/xmp/XmpUpdateTest.java
(original)
+++ incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/xmp/XmpUpdateTest.java
Sun Aug 24 13:47:30 2008
@@ -44,6 +44,11 @@
 				Debug.purgeMemory();
 
 			File imageFile = (File) images.get(i);
+
+			if (imageFile.getName().toLowerCase().endsWith(".png")
+					&& isInvalidPNGTestFile(imageFile))
+				continue;
+			
 			Debug.debug("imageFile", imageFile);
 			Debug.debug();
 



Mime
View raw message