incubator-sanselan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmc...@apache.org
Subject svn commit: r609529 [1/2] - in /incubator/sanselan/trunk/src: main/java/org/apache/sanselan/common/ main/java/org/apache/sanselan/formats/jpeg/ main/java/org/apache/sanselan/formats/jpeg/exifRewrite/ main/java/org/apache/sanselan/formats/tiff/constants...
Date Mon, 07 Jan 2008 08:12:05 GMT
Author: cmchen
Date: Mon Jan  7 00:12:01 2008
New Revision: 609529

URL: http://svn.apache.org/viewvc?rev=609529&view=rev
Log:
Having completed the neccesarily preliminaries, I'm read to start work on the "lossless" (Maker-Note safe) exif rewrite approach.  We're going to bump up against the APP1 segment limit very quickly.

Added:
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/ImageDataOffsets.java   (with props)
Removed:
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/ImageDataInfo.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy2.java
Modified:
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/exifRewrite/ExifRewriter.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/constants/TiffFieldTypeConstants.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldType.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterBase.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossless.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java
    incubator/sanselan/trunk/src/test/java/org/apache/sanselan/formats/jpeg/ExifRewriteTest.java

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java Mon Jan  7 00:12:01 2008
@@ -519,7 +519,7 @@
 		return result;
 	}
 
-	protected final byte[] getBytearrayTail(String name, byte bytes[], int count)
+	protected final byte[] getByteArrayTail(String name, byte bytes[], int count)
 	{
 		return readBytearray(name, bytes, count, bytes.length - count);
 	}

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java Mon Jan  7 00:12:01 2008
@@ -376,7 +376,7 @@
 		//
 		//		Debug.debug("head", head);
 
-		return getBytearrayTail("trimmed exif bytes", bytes, 6);
+		return getByteArrayTail("trimmed exif bytes", bytes, 6);
 	}
 
 	private JpegImageMetadata.Photoshop getPhotoshopMetadata(

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/exifRewrite/ExifRewriter.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/exifRewrite/ExifRewriter.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/exifRewrite/ExifRewriter.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/exifRewrite/ExifRewriter.java Mon Jan  7 00:12:01 2008
@@ -33,7 +33,7 @@
 import org.apache.sanselan.formats.tiff.TiffImageMetadata;
 import org.apache.sanselan.formats.tiff.write.TiffImageWriterBase;
 import org.apache.sanselan.formats.tiff.write.TiffImageWriterLossless;
-import org.apache.sanselan.formats.tiff.write.TiffImageWriterLossy2;
+import org.apache.sanselan.formats.tiff.write.TiffImageWriterLossy;
 import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
 import org.apache.sanselan.util.Debug;
 
@@ -143,98 +143,45 @@
 		writeSegmentsReplacingExif(os, pieces, null);
 	}
 
-	//	public void rewriteExifMetadataLossless(ByteSource byteSource,
-	//			OutputStream os, Map params) throws ImageReadException,
-	//			IOException, ImageWriteException
-	//	{
-	//
-	//		rewriteExifMetadata(MODE_LOSSLESS, byteSource, os, params);
-	//	}
-	//
-	//	public void rewriteExifMetadataLossy(ByteSource byteSource,
-	//			OutputStream os, Map params) throws ImageReadException,
-	//			IOException, ImageWriteException
-	//	{
-	//
-	//		rewriteExifMetadata(MODE_LOSSY, byteSource, os, params);
-	//	}
-	//
-	//	private void rewriteExifMetadata(int mode, ByteSource byteSource,
-	//			OutputStream os, Map params) throws ImageReadException,
-	//			IOException, ImageWriteException
-	//	{
-	//		JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-	//		ArrayList pieces = jfifPieces.pieces;
-	//		GenericSegment exifSegment = jfifPieces.exifSegment;
-	//
-	//		byte exifBytes[] = exifSegment.bytes;
-	//		exifBytes = getBytearrayTail("trimmed exif bytes", exifBytes, 6);
-	//
-	//		TiffImageMetadata exifMetadata = (TiffImageMetadata) new TiffImageParser()
-	//				.getMetadata(exifBytes, params);
-	//
-	//		byte newBytes[] = writeExifSegment(mode, exifMetadata, true);
-	//		//		exifSegment.bytes = newBytes;
-	//
-	//		//		ArrayList segments = readSegments(byteSource, null, false, true);
-	//
-	//		//		TiffImageMetadata exif = getExifMetadata(byteSource, params);
-	//
-	//		writeSegmentsReplacingExif(os, pieces, newBytes);
-	//	}
-
-	//	public void updateExifMetadata(ByteSource byteSource, OutputStream os,
-	//			ArrayList outputDirectories, Map params) throws ImageReadException,
-	//			IOException, ImageWriteException
-	//	{
-	//		JFIFPieces jfifPieces = analyzeJFIF(byteSource);
-	//		ArrayList pieces = jfifPieces.pieces;
-	//		GenericSegment exifSegment = jfifPieces.exifSegment;
-	//
-	//		byte exifBytes[] = exifSegment.bytes;
-	//		exifBytes = getBytearrayTail("trimmed exif bytes", exifBytes, 6);
-	//
-	//		TiffImageMetadata exifMetadata = (TiffImageMetadata) new TiffImageParser()
-	//				.getMetadata(exifBytes, params);
-	//		int byteOrder = exifMetadata.contents.header.byteOrder;
-	//
-	//		byte newBytes[] = writeExifSegment(outputDirectories, byteOrder, true);
-	//
-	//		writeSegmentsReplacingExif(os, pieces, newBytes);
-	//	}
-
-	private static final int MODE_LOSSY = -1;
-	private static final int MODE_LOSSLESS = -2;
+	//	private static final int MODE_LOSSY = -1;
+	//	private static final int MODE_LOSSLESS = -2;
 
 	public void updateExifMetadataLossless(ByteSource byteSource,
 			OutputStream os, TiffOutputSet outputSet)
 			throws ImageReadException, IOException, ImageWriteException
 	{
-		updateExifMetadata(MODE_LOSSLESS, byteSource, os, outputSet);
+		//		List outputDirectories = outputSet.getDirectories();
+		JFIFPieces jfifPieces = analyzeJFIF(byteSource);
+		ArrayList pieces = jfifPieces.pieces;
+		GenericSegment exifSegment = jfifPieces.exifSegment;
+
+		byte exifBytes[] = exifSegment.bytes;
+		exifBytes = getByteArrayTail("trimmed exif bytes", exifBytes, 6);
+
+		TiffImageWriterBase writer = new TiffImageWriterLossless(
+				outputSet.byteOrder, exifBytes);
+
+		boolean includeEXIFPrefix = true;
+		byte newBytes[] = writeExifSegment(writer, outputSet, includeEXIFPrefix);
+
+		Debug.debug("oldBytes", exifBytes.length);
+		Debug.debug("newBytes", newBytes.length);
+
+		writeSegmentsReplacingExif(os, pieces, newBytes);
 	}
 
 	public void updateExifMetadataLossy(ByteSource byteSource, OutputStream os,
 			TiffOutputSet outputSet) throws ImageReadException, IOException,
 			ImageWriteException
 	{
-		updateExifMetadata(MODE_LOSSY, byteSource, os, outputSet);
-	}
-
-	private void updateExifMetadata(int mode, ByteSource byteSource,
-			OutputStream os, TiffOutputSet outputSet)
-			throws ImageReadException, IOException, ImageWriteException
-	{
-		//		List outputDirectories = outputSet.getDirectories();
 		JFIFPieces jfifPieces = analyzeJFIF(byteSource);
 		ArrayList pieces = jfifPieces.pieces;
-		GenericSegment exifSegment = jfifPieces.exifSegment;
-
-		byte exifBytes[] = exifSegment.bytes;
-		exifBytes = getBytearrayTail("trimmed exif bytes", exifBytes, 6);
 
-		//		int byteOrder = outputSet.byteOrder;
+		TiffImageWriterBase writer = new TiffImageWriterLossy(
+				outputSet.byteOrder);
 
-		byte newBytes[] = writeExifSegment(mode, outputSet, true);
+		boolean includeEXIFPrefix = true;
+		byte newBytes[] = writeExifSegment(writer, outputSet, includeEXIFPrefix);
 
 		writeSegmentsReplacingExif(os, pieces, newBytes);
 	}
@@ -287,75 +234,22 @@
 		}
 	}
 
-	private byte[] writeExifSegment(int mode, TiffImageMetadata exif,
-			boolean includeEXIFPrefix) throws IOException, ImageWriteException
-	{
-		if (exif == null)
-			return null;
-
-		//		int byteOrder = exif.contents.header.byteOrder;
-
-		TiffOutputSet outputSet = exif.getOutputSet();
-		//		TiffOutputSet outputSet = new TiffOutputSet(byteOrder);
-		////		ArrayList outputDirectories = new ArrayList();
-		//		ArrayList srcDirs = exif.getDirectories();
-		//		for (int i = 0; i < srcDirs.size(); i++)
-		//		{
-		//			TiffImageMetadata.Directory srcDir = (TiffImageMetadata.Directory) srcDirs
-		//					.get(i);
-		//			//			Debug.debug("srcDir", srcDir);
-		//
-		//			//			TiffOutputDirectory outputDirectory = translate(srcDir, byteOrder);
-		//			TiffOutputDirectory outputDirectory = srcDir
-		//					.getOutputDirectory(byteOrder);
-		//			outputSet.add(outputDirectory);
-		//		}
-
-		return writeExifSegment(mode, outputSet, includeEXIFPrefix);
-	}
-
-	//	private byte[] writeExifSegment(int mode, TiffOutputSet outputSet,
-	//			boolean includeEXIFPrefix) throws IOException, ImageWriteException
-	//	{
-	//		List outputDirectories = outputSet.getDirectories();
-	//
-	//		return writeExifSegment(mode, outputSet.byteOrder, outputDirectories,
-	//				includeEXIFPrefix);
-	//	}
-
 	//
-	//	public byte[] writeExifSegmentLossy(List outputDirectories, int byteOrder,
+	//	private byte[] writeExifSegment(int mode, TiffOutputSet outputSet,
 	//			boolean includeEXIFPrefix) throws IOException, ImageWriteException
 	//	{
-	//		TiffImageWriterBase writer = new TiffImageWriter(byteOrder);
-	//		return writeExifSegment(writer, outputDirectories, byteOrder,
-	//				includeEXIFPrefix);
-	//	}
+	//		TiffImageWriterBase writer;
+	//		if (mode == MODE_LOSSLESS)
+	//			writer = new TiffImageWriterLossless(outputSet.byteOrder);
+	//		else if (mode == MODE_LOSSY)
+	//			writer = new TiffImageWriterLossy(outputSet.byteOrder);
+	//		//		writer = new TiffImageWriterLossy(outputSet.byteOrder);
+	//		else
+	//			throw new ImageWriteException("Unknown TIFF write mode.");
 	//
-	//	private byte[] writeExifSegmentLossless(List outputDirectories,
-	//			int byteOrder, boolean includeEXIFPrefix) throws IOException,
-	//			ImageWriteException
-	//	{
-	//		TiffImageWriterBase writer = new TiffImageWriter(byteOrder);
-	//		return writeExifSegment(writer, outputDirectories, byteOrder,
-	//				includeEXIFPrefix);
+	//		return writeExifSegment(writer, outputSet, includeEXIFPrefix);
 	//	}
 
-	private byte[] writeExifSegment(int mode, TiffOutputSet outputSet,
-			boolean includeEXIFPrefix) throws IOException, ImageWriteException
-	{
-		TiffImageWriterBase writer;
-		if (mode == MODE_LOSSLESS)
-			writer = new TiffImageWriterLossless(outputSet.byteOrder);
-		else if (mode == MODE_LOSSY)
-			writer = new TiffImageWriterLossy2(outputSet.byteOrder);
-//		writer = new TiffImageWriterLossy(outputSet.byteOrder);
-		else
-			throw new ImageWriteException("Unknown TIFF write mode.");
-
-		return writeExifSegment(writer, outputSet, includeEXIFPrefix);
-	}
-
 	private byte[] writeExifSegment(TiffImageWriterBase writer,
 			TiffOutputSet outputSet, boolean includeEXIFPrefix)
 			throws IOException, ImageWriteException
@@ -369,7 +263,7 @@
 			os.write(0);
 		}
 
-		writer.writeDirectories(os, outputSet);
+		writer.write(os, outputSet);
 
 		return os.toByteArray();
 	}

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/constants/TiffFieldTypeConstants.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/constants/TiffFieldTypeConstants.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/constants/TiffFieldTypeConstants.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/constants/TiffFieldTypeConstants.java Mon Jan  7 00:12:01 2008
@@ -30,47 +30,6 @@
 public interface TiffFieldTypeConstants extends SanselanConstants
 {
 
-	//	public static final FieldTypeByte FIELD_TYPE_BYTE = new FieldTypeByte(1,
-	//			"Byte");
-	//
-	//	public static final FieldTypeASCII FIELD_TYPE_ASCII = new FieldTypeASCII(2,
-	//			"ASCII");
-	//
-	//	public static final FieldTypeShort FIELD_TYPE_SHORT = new FieldTypeShort(3,
-	//			"Short");
-	//
-	//	public static final FieldTypeLong FIELD_TYPE_LONG = new FieldTypeLong(4,
-	//			"Long");
-	//
-	//	public static final FieldTypeRational FIELD_TYPE_RATIONAL = new FieldTypeRational(
-	//			5, "Rational");
-	//
-	//	public static final FieldType FIELD_TYPE_SBYTE = new FieldTypeByte(6,
-	//			"SByte");
-	//	public static final FieldType FIELD_TYPE_UNDEFINED = new FieldTypeByte(7,
-	//			"Undefined");
-	//	public static final FieldType FIELD_TYPE_SSHORT = new FieldTypeShort(8,
-	//			"SShort");
-	//
-	//	public static final FieldType FIELD_TYPE_SLONG = new FieldTypeLong(9,
-	//			"SLong");
-	//
-	//	public static final FieldType FIELD_TYPE_SRATIONAL = new FieldTypeRational(
-	//			10, "SRational");
-	//
-	//	public static final FieldType FIELD_TYPE_FLOAT = new FieldTypeFloat();
-	//
-	//	public static final FieldType FIELD_TYPE_DOUBLE = new FieldTypeDouble();
-	//
-	//	public static final FieldType FIELD_TYPE_UNKNOWN = new FieldTypeUnknown();
-	//
-	//	public static final FieldType FIELD_TYPES[] = {
-	//			FIELD_TYPE_BYTE, FIELD_TYPE_ASCII, FIELD_TYPE_SHORT,
-	//			FIELD_TYPE_LONG, FIELD_TYPE_RATIONAL, FIELD_TYPE_SBYTE,
-	//			FIELD_TYPE_UNDEFINED, FIELD_TYPE_SSHORT, FIELD_TYPE_SLONG,
-	//			FIELD_TYPE_SRATIONAL, FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE,
-	//	};
-
 	public static final FieldTypeByte FIELD_TYPE_BYTE = new FieldTypeByte(1,
 			"Byte");
 

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=609529&r1=609528&r2=609529&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 Mon Jan  7 00:12:01 2008
@@ -20,7 +20,6 @@
 import org.apache.sanselan.common.BinaryFileFunctions;
 import org.apache.sanselan.formats.tiff.TiffField;
 import org.apache.sanselan.formats.tiff.constants.TiffConstants;
-import org.apache.sanselan.formats.tiff.write.TiffImageWriterLossy;
 
 public abstract class FieldType extends BinaryFileFunctions
 		implements

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/ImageDataOffsets.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/ImageDataOffsets.java?rev=609529&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/ImageDataOffsets.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/ImageDataOffsets.java Mon Jan  7 00:12:01 2008
@@ -0,0 +1,42 @@
+/*
+ * 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.tiff.write;
+
+class ImageDataOffsets
+{
+	public final int imageDataOffsets[];
+	public final TiffOutputField imageDataOffsetsField;
+	public final TiffOutputItem outputItems[];
+
+	public ImageDataOffsets(final byte imageData[][],
+			final int[] imageDataOffsets, 
+			final TiffOutputField imageDataOffsetsField)
+	{
+		this.imageDataOffsets = imageDataOffsets;
+		this.imageDataOffsetsField = imageDataOffsetsField;
+
+		outputItems = new TiffOutputItem[imageData.length];
+		for (int i = 0; i < imageData.length; i++)
+		{
+			TiffOutputItem item = new TiffOutputItem.Value("TIFF image data",
+					imageData[i]);
+			outputItems[i] = item;
+		}
+
+	}
+
+}
\ No newline at end of file

Propchange: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/ImageDataOffsets.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterBase.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterBase.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterBase.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterBase.java Mon Jan  7 00:12:01 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.sanselan.formats.tiff.write;
 
+import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
@@ -27,6 +28,10 @@
 
 import org.apache.sanselan.ImageWriteException;
 import org.apache.sanselan.common.BinaryConstants;
+import org.apache.sanselan.common.PackBits;
+import org.apache.sanselan.common.mylzw.MyLZWCompressor;
+import org.apache.sanselan.formats.tiff.RawTiffImageData;
+import org.apache.sanselan.formats.tiff.TiffDirectory;
 import org.apache.sanselan.formats.tiff.constants.TiffConstants;
 
 public abstract class TiffImageWriterBase
@@ -34,6 +39,7 @@
 			TiffConstants,
 			BinaryConstants
 {
+	
 	public static final int DEFAULT_WRITE_BYTE_ORDER = BYTE_ORDER_INTEL;
 
 	protected final int byteOrder;
@@ -53,12 +59,9 @@
 		return (4 - (dataLength % 4)) % 4;
 	}
 
-	public abstract void writeDirectories(OutputStream os,
+	public abstract void write(OutputStream os,
 			TiffOutputSet outputSet) throws IOException, ImageWriteException;
 
-	//	public abstract void writeDirectories(OutputStream os, List directories)
-	//	throws IOException, ImageWriteException;
-
 	protected TiffOutputSummary validateDirectories(List directories)
 			throws ImageWriteException
 	{
@@ -249,6 +252,271 @@
 		return result;
 
 		//		Debug.debug();
+	}
+
+	public void writeImage(BufferedImage src, OutputStream os, Map params)
+			throws ImageWriteException, IOException
+	{
+		//        writeImageNew(src, os, params);
+		//    }
+		//
+		//    public void writeImageNew(BufferedImage src, OutputStream os, Map params)
+		//            throws ImageWriteException, IOException
+		//    {
+
+		// make copy of params; we'll clear keys as we consume them.
+		params = new HashMap(params);
+
+		// clear format key.
+		if (params.containsKey(PARAM_KEY_FORMAT))
+			params.remove(PARAM_KEY_FORMAT);
+
+		int width = src.getWidth();
+		int height = src.getHeight();
+
+		//        BinaryOutputStream bos = new BinaryOutputStream(os, WRITE_BYTE_ORDER);
+		//
+		//        writeImageFileHeader(bos, WRITE_BYTE_ORDER);
+
+		//        ArrayList directoryFields = new ArrayList();
+
+		final int photometricInterpretation = 2; // TODO: 
+
+		int compression = TIFF_COMPRESSION_LZW; // LZW is default
+		if (params.containsKey(PARAM_KEY_COMPRESSION))
+		{
+			Object value = params.get(PARAM_KEY_COMPRESSION);
+			if (value != null)
+			{
+				if (!(value instanceof Number))
+					throw new ImageWriteException(
+							"Invalid compression parameter: " + value);
+				compression = ((Number) value).intValue();
+			}
+			params.remove(PARAM_KEY_COMPRESSION);
+		}
+
+		final int samplesPerPixel = 3; // TODO: 
+		final int bitsPerSample = 8; // TODO: 
+
+		//        int fRowsPerStrip; // TODO: 
+		int rowsPerStrip = 8000 / (width * samplesPerPixel); // TODO: 
+		rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.
+
+		byte strips[][] = getStrips(src, samplesPerPixel, bitsPerSample,
+				rowsPerStrip);
+
+		//        int stripCount = (height + fRowsPerStrip - 1) / fRowsPerStrip;
+		//        int stripCount = strips.length;
+
+		if (params.size() > 0)
+		{
+			Object firstKey = params.keySet().iterator().next();
+			throw new ImageWriteException("Unknown parameter: " + firstKey);
+		}
+
+		//        System.out.println("width: " + width);
+		//        System.out.println("height: " + height);
+		//        System.out.println("fRowsPerStrip: " + fRowsPerStrip);
+		//        System.out.println("fSamplesPerPixel: " + fSamplesPerPixel);
+		//        System.out.println("stripCount: " + stripCount);
+
+		if (compression == TIFF_COMPRESSION_PACKBITS)
+		{
+			for (int i = 0; i < strips.length; i++)
+				strips[i] = new PackBits().compress(strips[i]);
+		}
+		else if (compression == TIFF_COMPRESSION_LZW)
+		{
+			for (int i = 0; i < strips.length; i++)
+			{
+				byte uncompressed[] = strips[i];
+
+				int LZWMinimumCodeSize = 8;
+
+				MyLZWCompressor compressor = new MyLZWCompressor(
+						LZWMinimumCodeSize, BYTE_ORDER_MSB, true);
+				byte compressed[] = compressor.compress(uncompressed);
+
+				strips[i] = compressed;
+			}
+		}
+		else if (compression == TIFF_COMPRESSION_UNCOMPRESSED)
+		{
+			// do nothing.
+		}
+		else
+			throw new ImageWriteException(
+					"Invalid compression parameter (Only LZW, Packbits and uncompressed supported).");
+
+		//        int stripOffsets[] = new int[stripCount];
+		//        int stripByteCounts[] = new int[stripCount];
+		//
+		//        for (int i = 0; i < strips.length; i++)
+		//            stripByteCounts[i] = strips[i].length;
+
+		TiffOutputSet outputSet = new TiffOutputSet(byteOrder);
+		TiffOutputDirectory directory = outputSet.addRootDirectory();
+
+		//        WriteField stripOffsetsField;
+
+		{
+			{
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_IMAGE_WIDTH, FIELD_TYPE_LONG, 1,
+						FIELD_TYPE_LONG.writeData(new int[]{
+							width,
+						}, byteOrder));
+				directory.add(field);
+			}
+			{
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_IMAGE_LENGTH, FIELD_TYPE_LONG, 1,
+						FIELD_TYPE_LONG.writeData(new int[]{
+							height,
+						}, byteOrder));
+				directory.add(field);
+			}
+			{
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_PHOTOMETRIC_INTERPRETATION, FIELD_TYPE_SHORT,
+						1, FIELD_TYPE_SHORT.writeData(new int[]{
+							photometricInterpretation,
+						}, byteOrder));
+				directory.add(field);
+			}
+			{
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_COMPRESSION, FIELD_TYPE_SHORT, 1,
+						FIELD_TYPE_SHORT.writeData(new int[]{
+							compression,
+						}, byteOrder));
+				directory.add(field);
+			}
+			{
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_SAMPLES_PER_PIXEL, FIELD_TYPE_SHORT, 1,
+						FIELD_TYPE_SHORT.writeData(new int[]{
+							samplesPerPixel,
+						}, byteOrder));
+				directory.add(field);
+			}
+			{
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_BITS_PER_SAMPLE, FIELD_TYPE_SHORT, 3,
+						FIELD_TYPE_SHORT.writeData(new int[]{
+								bitsPerSample, bitsPerSample, bitsPerSample,
+						}, byteOrder));
+				directory.add(field);
+			}
+			//            {
+			//                stripOffsetsField = new WriteField(TIFF_TAG_STRIP_OFFSETS,
+			//                        FIELD_TYPE_LONG, stripOffsets.length, FIELD_TYPE_LONG
+			//                                .writeData(stripOffsets, byteOrder));
+			//                directory.add(stripOffsetsField);
+			//            }
+			//            {
+			//                WriteField field = new WriteField(TIFF_TAG_STRIP_BYTE_COUNTS,
+			//                        FIELD_TYPE_LONG, stripByteCounts.length,
+			//                        FIELD_TYPE_LONG.writeData(stripByteCounts,
+			//                                WRITE_BYTE_ORDER));
+			//                directory.add(field);
+			//            }
+			{
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_ROWS_PER_STRIP, FIELD_TYPE_LONG, 1,
+						FIELD_TYPE_LONG.writeData(new int[]{
+							rowsPerStrip,
+						}, byteOrder));
+				directory.add(field);
+			}
+
+			{
+				int resolutionUnit = 2;// inches.
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_RESOLUTION_UNIT, FIELD_TYPE_SHORT, 1,
+						FIELD_TYPE_SHORT.writeData(new int[]{
+							resolutionUnit,
+						}, byteOrder));
+				directory.add(field);
+			}
+
+			{
+				int xResolution = 72;
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_XRESOLUTION, FIELD_TYPE_RATIONAL, 1,
+						FIELD_TYPE_RATIONAL
+								.writeData(xResolution, 1, byteOrder));
+				directory.add(field);
+			}
+
+			{
+				int yResolution = 72;
+				TiffOutputField field = new TiffOutputField(
+						TIFF_TAG_YRESOLUTION, FIELD_TYPE_RATIONAL, 1,
+						FIELD_TYPE_RATIONAL
+								.writeData(yResolution, 1, byteOrder));
+				directory.add(field);
+			}
+
+		}
+
+		RawTiffImageData rawTiffImageData = new RawTiffImageData.Strips(strips);
+		directory.setRawTiffImageData(rawTiffImageData);
+
+		write(os, outputSet);
+	}
+
+	private byte[][] getStrips(BufferedImage src, int samplesPerPixel,
+			int bitsPerSample, int rowsPerStrip)
+	{
+		int width = src.getWidth();
+		int height = src.getHeight();
+
+		int stripCount = (height + rowsPerStrip - 1) / rowsPerStrip;
+
+		byte result[][] = null;
+		{ // Write Strips
+			result = new byte[stripCount][];
+
+			int remaining_rows = height;
+
+			for (int i = 0; i < stripCount; i++)
+			{
+				int rowsInStrip = Math.min(rowsPerStrip, remaining_rows);
+				remaining_rows -= rowsInStrip;
+
+				int bitsInStrip = bitsPerSample * rowsInStrip * width
+						* samplesPerPixel;
+				int bytesInStrip = (bitsInStrip + 7) / 8;
+
+				byte uncompressed[] = new byte[bytesInStrip];
+
+				int counter = 0;
+				int y = i * rowsPerStrip;
+				int stop = i * rowsPerStrip + rowsPerStrip;
+
+				for (; (y < height) && (y < stop); y++)
+				{
+					for (int x = 0; x < width; x++)
+					{
+						int rgb = src.getRGB(x, y);
+						int red = 0xff & (rgb >> 16);
+						int green = 0xff & (rgb >> 8);
+						int blue = 0xff & (rgb >> 0);
+
+						uncompressed[counter++] = (byte) red;
+						uncompressed[counter++] = (byte) green;
+						uncompressed[counter++] = (byte) blue;
+					}
+				}
+
+				result[i] = uncompressed;
+			}
+
+		}
+
+		return result;
 	}
 
 }

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossless.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossless.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossless.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossless.java Mon Jan  7 00:12:01 2008
@@ -22,577 +22,100 @@
 
 import org.apache.sanselan.ImageWriteException;
 import org.apache.sanselan.common.BinaryOutputStream;
+import org.apache.sanselan.util.Debug;
 import org.apache.sanselan.util.DebugOutputStream;
 
 public class TiffImageWriterLossless extends TiffImageWriterBase
 {
+	private final byte exifBytes[];
 
-	public TiffImageWriterLossless()
+	public TiffImageWriterLossless(byte exifBytes[])
 	{
+		this.exifBytes = exifBytes;
 	}
 
-	public TiffImageWriterLossless(int byteOrder)
+	public TiffImageWriterLossless(int byteOrder, byte exifBytes[])
 	{
 		super(byteOrder);
+		this.exifBytes = exifBytes;
 	}
 
-	public void writeDirectories(OutputStream os, TiffOutputSet outputSet)
+	public void write(OutputStream os, TiffOutputSet outputSet)
 			throws IOException, ImageWriteException
 	{
-		writeDirectories(os, outputSet.getDirectories());
+		List directories = outputSet.getDirectories();
+
+		TiffOutputSummary outputSummary = validateDirectories(directories);
+
+		List outputItems = outputSet.getOutputItems(outputSummary);
+
+		updateOffsetsStep(outputItems);
+
+		outputSummary.updateOffsets(byteOrder);
+
+		BinaryOutputStream bos = new BinaryOutputStream(os, byteOrder);
+
+		writeStep(bos, outputItems);
+
 	}
 
-	public void writeDirectories(OutputStream os, List directories)
+	private void updateOffsetsStep(List outputItems) throws IOException,
+			ImageWriteException
+	{
+		//		int offset = TIFF_HEADER_SIZE;
+		int offset = exifBytes.length;
+
+		for (int i = 0; i < outputItems.size(); i++)
+		{
+			TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
+
+			outputItem.setOffset(offset);
+			int itemLength = outputItem.getItemLength();
+			offset += itemLength;
+
+			int remainder = imageDataPaddingLength(itemLength);
+			offset += remainder;
+		}
+	}
+
+	private void writeStep(BinaryOutputStream bos, List outputItems)
 			throws IOException, ImageWriteException
 	{
-		TiffOutputSummary outputSummary = validateDirectories(directories);
+		writeImageFileHeader(bos);
 
-		//        Collections.sort(directories, Directory.COMPARATOR);
+		bos.write(exifBytes, TIFF_HEADER_SIZE, exifBytes.length
+				- TIFF_HEADER_SIZE);
 
-		/**/
+		//		int offset = TIFF_HEADER_SIZE;
+		int offset = exifBytes.length;
+		for (int i = 0; i < outputItems.size(); i++)
+		{
+			TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
+
+			outputItem.writeItem(bos);
+
+			int length = outputItem.getItemLength();
+			offset += length;
+			int remainder = imageDataPaddingLength(length);
+			offset += remainder;
+			for (int j = 0; j < remainder; j++)
+				bos.write(0);
+		}
 
-		//        ImageDataInfo imageDataInfo = imageDataInfoStep(directories, imageData,
-		//                stripsNotTiles);
-		/**/
-
-		//		PointerDirectoriesInfo pointerDirectoriesInfo = pointerDirectoriesStep(directories);
-		/**/
-
-		//		//        final int imageDataOffset = 
-		//		calculateLengthsAndOffsetsStep(directories);
-		//
-		//		/**/
-		//
-		//		updateDirectoryPointersStep(pointerDirectoriesInfo);
-		//
-		//		/**/
-		//
-		//		//        updateImageDataOffsetsStep(imageDataInfo, imageDataOffset);
-		//		/**/
-		//
-		//		DebugOutputStream dos = null;
-		//		//        DebugOutputStream dos = new DebugOutputStream(os);
-		//		//        os = dos;
-		//		BinaryOutputStream bos = new BinaryOutputStream(os, byteOrder);
-		//
-		//		/**/
-		//
-		//		writeStep(bos, directories, dos);
 	}
 
-	//    public byte[][] getStrips(BufferedImage src, int fSamplesPerPixel,
-	//            int bitsPerSample, int rowsPerStrip)
-	//    {
-	//        int width = src.getWidth();
-	//        int height = src.getHeight();
-	//
-	//        int stripCount = (height + rowsPerStrip - 1) / rowsPerStrip;
-	//
-	//        byte result[][] = null;
-	//        { // Write Strips
-	//            result = new byte[stripCount][];
-	//
-	//            int remaining_rows = height;
-	//
-	//            for (int i = 0; i < stripCount; i++)
-	//            {
-	//                int rowsInStrip = Math.min(rowsPerStrip, remaining_rows);
-	//                remaining_rows -= rowsInStrip;
-	//
-	//                int bitsInStrip = bitsPerSample * rowsInStrip * width
-	//                        * fSamplesPerPixel;
-	//                int bytesInStrip = (bitsInStrip + 7) / 8;
-	//
-	//                byte uncompressed[] = new byte[bytesInStrip];
-	//
-	//                int counter = 0;
-	//                int y = i * rowsPerStrip;
-	//                int stop = i * rowsPerStrip + rowsPerStrip;
-	//
-	//                for (; (y < height) && (y < stop); y++)
-	//                {
-	//                    for (int x = 0; x < width; x++)
-	//                    {
-	//                        int rgb = src.getRGB(x, y);
-	//                        int red = 0xff & (rgb >> 16);
-	//                        int green = 0xff & (rgb >> 8);
-	//                        int blue = 0xff & (rgb >> 0);
-	//
-	//                        uncompressed[counter++] = (byte) red;
-	//                        uncompressed[counter++] = (byte) green;
-	//                        uncompressed[counter++] = (byte) blue;
-	//                    }
-	//                }
-	//
-	//                result[i] = uncompressed;
-	//            }
-	//
-	//        }
-	//
-	//        return result;
-	//    }
-	//
-	//    public void writeImage(BufferedImage src, OutputStream os, Map params)
-	//            throws ImageWriteException, IOException
-	//    {
-	//        //        writeImageNew(src, os, params);
-	//        //    }
-	//        //
-	//        //    public void writeImageNew(BufferedImage src, OutputStream os, Map params)
-	//        //            throws ImageWriteException, IOException
-	//        //    {
-	//
-	//        // make copy of params; we'll clear keys as we consume them.
-	//        params = new HashMap(params);
-	//
-	//        // clear format key.
-	//        if (params.containsKey(PARAM_KEY_FORMAT))
-	//            params.remove(PARAM_KEY_FORMAT);
-	//
-	//        int width = src.getWidth();
-	//        int height = src.getHeight();
-	//
-	//        //        BinaryOutputStream bos = new BinaryOutputStream(os, WRITE_BYTE_ORDER);
-	//        //
-	//        //        writeImageFileHeader(bos, WRITE_BYTE_ORDER);
-	//
-	//        //        ArrayList directoryFields = new ArrayList();
-	//
-	//        final int photometricInterpretation = 2; // TODO: 
-	//
-	//        int compression = TIFF_COMPRESSION_LZW; // LZW is default
-	//        if (params.containsKey(PARAM_KEY_COMPRESSION))
-	//        {
-	//            Object value = params.get(PARAM_KEY_COMPRESSION);
-	//            if (value != null)
-	//            {
-	//                if (!(value instanceof Number))
-	//                    throw new ImageWriteException(
-	//                            "Invalid compression parameter: " + value);
-	//                compression = ((Number) value).intValue();
-	//            }
-	//            params.remove(PARAM_KEY_COMPRESSION);
-	//        }
-	//
-	//        final int samplesPerPixel = 3; // TODO: 
-	//        final int bitsPerSample = 8; // TODO: 
-	//
-	//        //        int fRowsPerStrip; // TODO: 
-	//        int rowsPerStrip = 8000 / (width * samplesPerPixel); // TODO: 
-	//        rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.
-	//
-	//        byte strips[][] = getStrips(src, samplesPerPixel, bitsPerSample,
-	//                rowsPerStrip);
-	//
-	//        //        int stripCount = (height + fRowsPerStrip - 1) / fRowsPerStrip;
-	//        //        int stripCount = strips.length;
-	//
-	//        if (params.size() > 0)
-	//        {
-	//            Object firstKey = params.keySet().iterator().next();
-	//            throw new ImageWriteException("Unknown parameter: " + firstKey);
-	//        }
-	//
-	//        //        System.out.println("width: " + width);
-	//        //        System.out.println("height: " + height);
-	//        //        System.out.println("fRowsPerStrip: " + fRowsPerStrip);
-	//        //        System.out.println("fSamplesPerPixel: " + fSamplesPerPixel);
-	//        //        System.out.println("stripCount: " + stripCount);
-	//
-	//        if (compression == TIFF_COMPRESSION_PACKBITS)
-	//        {
-	//            for (int i = 0; i < strips.length; i++)
-	//                strips[i] = new PackBits().compress(strips[i]);
-	//        }
-	//        else if (compression == TIFF_COMPRESSION_LZW)
-	//        {
-	//            for (int i = 0; i < strips.length; i++)
-	//            {
-	//                byte uncompressed[] = strips[i];
-	//
-	//                int LZWMinimumCodeSize = 8;
-	//
-	//                MyLZWCompressor compressor = new MyLZWCompressor(
-	//                        LZWMinimumCodeSize, BYTE_ORDER_MSB, true);
-	//                byte compressed[] = compressor.compress(uncompressed);
-	//
-	//                strips[i] = compressed;
-	//            }
-	//        }
-	//        else if (compression == TIFF_COMPRESSION_UNCOMPRESSED)
-	//        {
-	//            // do nothing.
-	//        }
-	//        else
-	//            throw new ImageWriteException(
-	//                    "Invalid compression parameter (Only LZW, Packbits and uncompressed supported).");
-	//
-	//        //        int stripOffsets[] = new int[stripCount];
-	//        //        int stripByteCounts[] = new int[stripCount];
-	//        //
-	//        //        for (int i = 0; i < strips.length; i++)
-	//        //            stripByteCounts[i] = strips[i].length;
-	//
-	//        TiffOutputDirectory directory = new TiffOutputDirectory(
-	//                TiffDirectory.DIRECTORY_TYPE_ROOT);
-	//
-	//        //        WriteField stripOffsetsField;
-	//
-	//        {
-	//            {
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_IMAGE_WIDTH, FIELD_TYPE_LONG, 1,
-	//                        FIELD_TYPE_LONG.writeData(new int[]{
-	//                            width,
-	//                        }, byteOrder));
-	//                directory.add(field);
-	//            } 
-	//            {
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_IMAGE_LENGTH, FIELD_TYPE_LONG, 1,
-	//                        FIELD_TYPE_LONG.writeData(new int[]{
-	//                            height,
-	//                        }, byteOrder));
-	//                directory.add(field);
-	//            }
-	//            {
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_PHOTOMETRIC_INTERPRETATION, FIELD_TYPE_SHORT,
-	//                        1, FIELD_TYPE_SHORT.writeData(new int[]{
-	//                            photometricInterpretation,
-	//                        }, byteOrder));
-	//                directory.add(field);
-	//            }
-	//            {
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_COMPRESSION, FIELD_TYPE_SHORT, 1,
-	//                        FIELD_TYPE_SHORT.writeData(new int[]{
-	//                            compression,
-	//                        }, byteOrder));
-	//                directory.add(field);
-	//            }
-	//            {
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_SAMPLES_PER_PIXEL, FIELD_TYPE_SHORT, 1,
-	//                        FIELD_TYPE_SHORT.writeData(new int[]{
-	//                            samplesPerPixel,
-	//                        }, byteOrder));
-	//                directory.add(field);
-	//            }
-	//            {
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_BITS_PER_SAMPLE, FIELD_TYPE_SHORT, 3,
-	//                        FIELD_TYPE_SHORT.writeData(new int[]{
-	//                                bitsPerSample, bitsPerSample, bitsPerSample,
-	//                        }, byteOrder));
-	//                directory.add(field);
-	//            }
-	//            //            {
-	//            //                stripOffsetsField = new WriteField(TIFF_TAG_STRIP_OFFSETS,
-	//            //                        FIELD_TYPE_LONG, stripOffsets.length, FIELD_TYPE_LONG
-	//            //                                .writeData(stripOffsets, byteOrder));
-	//            //                directory.add(stripOffsetsField);
-	//            //            }
-	//            //            {
-	//            //                WriteField field = new WriteField(TIFF_TAG_STRIP_BYTE_COUNTS,
-	//            //                        FIELD_TYPE_LONG, stripByteCounts.length,
-	//            //                        FIELD_TYPE_LONG.writeData(stripByteCounts,
-	//            //                                WRITE_BYTE_ORDER));
-	//            //                directory.add(field);
-	//            //            }
-	//            {
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_ROWS_PER_STRIP, FIELD_TYPE_LONG, 1,
-	//                        FIELD_TYPE_LONG.writeData(new int[]{
-	//                            rowsPerStrip,
-	//                        }, byteOrder));
-	//                directory.add(field);
-	//            }
-	//
-	//            {
-	//                int resolutionUnit = 2;// inches.
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_RESOLUTION_UNIT, FIELD_TYPE_SHORT, 1,
-	//                        FIELD_TYPE_SHORT.writeData(new int[]{
-	//                            resolutionUnit,
-	//                        }, byteOrder));
-	//                directory.add(field);
-	//            }
-	//
-	//            {
-	//                int xResolution = 72;
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_XRESOLUTION, FIELD_TYPE_RATIONAL, 1,
-	//                        FIELD_TYPE_RATIONAL
-	//                                .writeData(xResolution, 1, byteOrder));
-	//                directory.add(field);
-	//            }
-	//
-	//            {
-	//                int yResolution = 72;
-	//                TiffOutputField field = new TiffOutputField(
-	//                        TIFF_TAG_YRESOLUTION, FIELD_TYPE_RATIONAL, 1,
-	//                        FIELD_TYPE_RATIONAL
-	//                                .writeData(yResolution, 1, byteOrder));
-	//                directory.add(field);
-	//            }
-	//
-	//        }
-	//
-	//        RawTiffImageData rawTiffImageData = new RawTiffImageData.Strips(strips);
-	//        directory.setRawTiffImageData(rawTiffImageData);
-	//
-	//        ArrayList directories = new ArrayList();
-	//        directories.add(directory);
-	//
-	//        writeDirectories(os, directories);
-	//    }
-	//
-	//    private void writeImageFileHeader(BinaryOutputStream bos)
-	//            throws IOException, ImageWriteException
-	//    {
-	//        bos.write(byteOrder);
-	//        bos.write(byteOrder);
-	//
-	//        bos.write2Bytes(42); // tiffVersion
-	//
-	//        int foffsetToFirstIFD = TIFF_HEADER_SIZE;
-	//
-	//        bos.write4Bytes(foffsetToFirstIFD);
-	//    }
-	//
-	//    static int imageDataPaddingLength(int dataLength)
-	//    {
-	//        return (4 - (dataLength % 4)) % 4;
-	//    }
-	//
-	//    private TiffOutputDirectory findDirectoryByType(List directories,
-	//            int type)
-	//    {
-	//        for (int i = 0; i < directories.size(); i++)
-	//        {
-	//            TiffOutputDirectory directory = (TiffOutputDirectory) directories
-	//                    .get(i);
-	//            if (directory.type == type)
-	//                return directory;
-	//        }
-	//        return null;
-	//    }
-	//
-	//    public void writeDirectories(OutputStream os, List directories)
-	//            throws IOException, ImageWriteException
-	//    {
-	//        //        Collections.sort(directories, Directory.COMPARATOR);
-	//
-	//        /**/
-	//
-	//        //        ImageDataInfo imageDataInfo = imageDataInfoStep(directories, imageData,
-	//        //                stripsNotTiles);
-	//        /**/
-	//
-	//        PointerDirectoriesInfo pointerDirectoriesInfo = pointerDirectoriesStep(directories);
-	//
-	//        /**/
-	//
-	//        //        final int imageDataOffset = 
-	//        calculateLengthsAndOffsetsStep(directories);
-	//
-	//        /**/
-	//
-	//        updateDirectoryPointersStep(pointerDirectoriesInfo);
-	//
-	//        /**/
-	//
-	//        //        updateImageDataOffsetsStep(imageDataInfo, imageDataOffset);
-	//        /**/
-	//
-	//        DebugOutputStream dos = null;
-	//        //        DebugOutputStream dos = new DebugOutputStream(os);
-	//        //        os = dos;
-	//        BinaryOutputStream bos = new BinaryOutputStream(os, byteOrder);
-	//
-	//        /**/
-	//
-	//        writeStep(bos, directories, dos);
-	//
-	//        /**/
-	//
-	//        //        writeImageDataStep(bos, directories, imageDataInfo);
-	//        /**/
-	//    }
-	//
-	//    private PointerDirectoriesInfo pointerDirectoriesStep(List directories)
-	//            throws ImageWriteException
-	//    {
-	//        TiffOutputDirectory firstDirectory = (TiffOutputDirectory) directories
-	//                .get(0);
-	//
-	//        TiffOutputField exifDirectoryOffsetField = null;
-	//        TiffOutputDirectory exifDirectory = findDirectoryByType(directories,
-	//                TiffDirectory.DIRECTORY_TYPE_EXIF);
-	//        if (null != exifDirectory)
-	//        {
-	//            exifDirectoryOffsetField = firstDirectory
-	//                    .findField(EXIF_TAG_GPSINFO);
-	//
-	//            if (null == exifDirectoryOffsetField)
-	//            {
-	//                exifDirectoryOffsetField = new TiffOutputField(
-	//                        EXIF_TAG_GPSINFO, FIELD_TYPE_LONG, 1,
-	//                        FIELD_TYPE_LONG.writeData(new int[]{
-	//                            0,
-	//                        }, byteOrder));
-	//                firstDirectory.add(exifDirectoryOffsetField);
-	//            }
-	//        }
-	//
-	//        TiffOutputField gpsDirectoryOffsetField = null;
-	//        TiffOutputDirectory gpsDirectory = findDirectoryByType(directories,
-	//                TiffDirectory.DIRECTORY_TYPE_GPS);
-	//        if (null != gpsDirectory)
-	//        {
-	//            gpsDirectoryOffsetField = firstDirectory
-	//                    .findField(EXIF_TAG_GPSINFO);
-	//            if (null == gpsDirectoryOffsetField)
-	//            {
-	//                gpsDirectoryOffsetField = new TiffOutputField(
-	//                        EXIF_TAG_GPSINFO, FIELD_TYPE_LONG, 1,
-	//                        FIELD_TYPE_LONG.writeData(new int[]{
-	//                            0,
-	//                        }, byteOrder));
-	//                firstDirectory.add(gpsDirectoryOffsetField);
-	//            }
-	//        }
-	//
-	//        TiffOutputField iteroperabilityDirectoryOffsetField = null;
-	//        TiffOutputDirectory iteroperabilityDirectory = findDirectoryByType(
-	//                directories, TiffDirectory.DIRECTORY_TYPE_INTEROPERABILITY);
-	//        if (null != iteroperabilityDirectory)
-	//        {
-	//            if (null == exifDirectory)
-	//                throw new ImageWriteException(
-	//                        "Can't write iteroperability directory without EXIF directory.");
-	//
-	//            iteroperabilityDirectoryOffsetField = exifDirectory
-	//                    .findField(EXIF_TAG_INTEROP_OFFSET);
-	//            if (null == iteroperabilityDirectoryOffsetField)
-	//            {
-	//                iteroperabilityDirectoryOffsetField = new TiffOutputField(
-	//                        EXIF_TAG_INTEROP_OFFSET, FIELD_TYPE_LONG,
-	//                        1, FIELD_TYPE_LONG.writeData(new int[]{
-	//                            0,
-	//                        }, byteOrder));
-	//                exifDirectory.add(iteroperabilityDirectoryOffsetField);
-	//            }
-	//        }
-	//
-	//        return new PointerDirectoriesInfo(exifDirectoryOffsetField,
-	//                exifDirectory, gpsDirectoryOffsetField, gpsDirectory,
-	//                iteroperabilityDirectoryOffsetField, iteroperabilityDirectory);
-	//
-	//    }
-	//
-	//    private void calculateLengthsAndOffsetsStep(List directories)
-	//            throws IOException, ImageWriteException
-	//    //    private int calculateLengthsAndOffsetsStep(ArrayList directories)
-	//    {
-	//        // Calculate lengths and offsets
-	//        int offset = TIFF_HEADER_SIZE;
-	//
-	//        TiffOutputDirectory previousDirectory = null;
-	//        for (int i = 0; i < directories.size(); i++)
-	//        {
-	//            TiffOutputDirectory directory = (TiffOutputDirectory) directories
-	//                    .get(i);
-	//
-	//            // fields must be written in ascending order.
-	//            directory.sortFields();
-	//
-	//            directory.offset = offset;
-	//
-	//            if (directory.type == TiffDirectory.DIRECTORY_TYPE_EXIF
-	//                    || directory.type == TiffDirectory.DIRECTORY_TYPE_GPS
-	//                    || directory.type == TiffDirectory.DIRECTORY_TYPE_INTEROPERABILITY)
-	//            {
-	//                // "pointer" directories don't partcipate in normal TIFF directory chain.
-	//                directory.calculateLengths(byteOrder);
-	//                offset += directory.totalLength;
-	//            }
-	//            else
-	//            {
-	//                if (null != previousDirectory)
-	//                    previousDirectory.nextDirectoryOffset = offset;
-	//
-	//                directory.calculateLengths(byteOrder);
-	//                offset += directory.totalLength;
-	//
-	//                previousDirectory = directory;
-	//            }
-	//        }
-	//        //        return offset;
-	//    }
-	//
-	//    private void updateDirectoryPointersStep(
-	//            PointerDirectoriesInfo pointerDirectoriesInfo)
-	//    {
-	//        if (null != pointerDirectoriesInfo.exifDirectory)
-	//        {
-	//            byte value[] = FIELD_TYPE_LONG.writeData(new int[]{
-	//                pointerDirectoriesInfo.exifDirectory.offset,
-	//            }, byteOrder);
-	//            pointerDirectoriesInfo.exifDirectoryOffsetField.setData(value);
-	//        }
-	//
-	//        if (null != pointerDirectoriesInfo.gpsDirectory)
-	//        {
-	//            byte value[] = FIELD_TYPE_LONG.writeData(new int[]{
-	//                pointerDirectoriesInfo.gpsDirectory.offset,
-	//            }, byteOrder);
-	//            pointerDirectoriesInfo.gpsDirectoryOffsetField.setData(value);
-	//        }
-	//
-	//        if (null != pointerDirectoriesInfo.iteroperabilityDirectory)
-	//        {
-	//            byte value[] = FIELD_TYPE_LONG.writeData(new int[]{
-	//                pointerDirectoriesInfo.iteroperabilityDirectory.offset,
-	//            }, byteOrder);
-	//            pointerDirectoriesInfo.iteroperabilityDirectoryOffsetField
-	//                    .setData(value);
-	//        }
-	//    }
-	//
-	//    private void writeStep(BinaryOutputStream bos, List directories,
-	//            DebugOutputStream dos) throws IOException, ImageWriteException
-	//    {
-	//        writeImageFileHeader(bos);
-	//
-	//        long count, lastCount = 0;
-	//
-	//        if (null != dos)
-	//        {
-	//            count = dos.count();
-	//            Debug.debug("image header" + " start: " + lastCount + ", end: "
-	//                    + dos.count() + ", length: " + (count - lastCount));
-	//            lastCount = count;
-	//        }
-	//
-	//        for (int i = 0; i < directories.size(); i++)
-	//        {
-	//            TiffOutputDirectory directory = (TiffOutputDirectory) directories
-	//                    .get(i);
-	//            directory.write(bos);
-	//
-	//            if (null != dos)
-	//            {
-	//                count = dos.count();
-	//                Debug.debug("directory("
-	//                        + TiffDirectory.description(directory.type) + ")"
-	//                        + " start: " + lastCount + ", end: " + dos.count()
-	//                        + ", length: " + (count - lastCount)
-	//                        + ", expected length: " + directory.totalLength);
-	//                lastCount = count;
-	//            }
-	//        }
-	//    }
+	private void writeImageFileHeader(BinaryOutputStream bos)
+			throws IOException, ImageWriteException
+	{
+		bos.write(byteOrder);
+		bos.write(byteOrder);
+
+		bos.write2Bytes(42); // tiffVersion
+
+		//		int foffsetToFirstIFD = TIFF_HEADER_SIZE;
+		int offsetToFirstIFD = exifBytes.length;
+
+		bos.write4Bytes(offsetToFirstIFD);
+	}
 
 }

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java Mon Jan  7 00:12:01 2008
@@ -16,21 +16,12 @@
  */
 package org.apache.sanselan.formats.tiff.write;
 
-import java.awt.image.BufferedImage;
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.apache.sanselan.ImageWriteException;
 import org.apache.sanselan.common.BinaryOutputStream;
-import org.apache.sanselan.common.PackBits;
-import org.apache.sanselan.common.mylzw.MyLZWCompressor;
-import org.apache.sanselan.formats.tiff.RawTiffImageData;
-import org.apache.sanselan.formats.tiff.TiffDirectory;
 import org.apache.sanselan.util.Debug;
 import org.apache.sanselan.util.DebugOutputStream;
 
@@ -46,272 +37,64 @@
 		super(byteOrder);
 	}
 
-	public byte[][] getStrips(BufferedImage src, int fSamplesPerPixel,
-			int bitsPerSample, int rowsPerStrip)
+	public void write(OutputStream os, TiffOutputSet outputSet)
+			throws IOException, ImageWriteException
 	{
-		int width = src.getWidth();
-		int height = src.getHeight();
-
-		int stripCount = (height + rowsPerStrip - 1) / rowsPerStrip;
-
-		byte result[][] = null;
-		{ // Write Strips
-			result = new byte[stripCount][];
-
-			int remaining_rows = height;
-
-			for (int i = 0; i < stripCount; i++)
-			{
-				int rowsInStrip = Math.min(rowsPerStrip, remaining_rows);
-				remaining_rows -= rowsInStrip;
-
-				int bitsInStrip = bitsPerSample * rowsInStrip * width
-						* fSamplesPerPixel;
-				int bytesInStrip = (bitsInStrip + 7) / 8;
-
-				byte uncompressed[] = new byte[bytesInStrip];
-
-				int counter = 0;
-				int y = i * rowsPerStrip;
-				int stop = i * rowsPerStrip + rowsPerStrip;
-
-				for (; (y < height) && (y < stop); y++)
-				{
-					for (int x = 0; x < width; x++)
-					{
-						int rgb = src.getRGB(x, y);
-						int red = 0xff & (rgb >> 16);
-						int green = 0xff & (rgb >> 8);
-						int blue = 0xff & (rgb >> 0);
-
-						uncompressed[counter++] = (byte) red;
-						uncompressed[counter++] = (byte) green;
-						uncompressed[counter++] = (byte) blue;
-					}
-				}
-
-				result[i] = uncompressed;
-			}
-
-		}
+		List directories = outputSet.getDirectories();
 
-		return result;
-	}
+		TiffOutputSummary outputSummary = validateDirectories(directories);
 
-	public void writeImage(BufferedImage src, OutputStream os, Map params)
-			throws ImageWriteException, IOException
-	{
-		//        writeImageNew(src, os, params);
-		//    }
-		//
-		//    public void writeImageNew(BufferedImage src, OutputStream os, Map params)
-		//            throws ImageWriteException, IOException
-		//    {
+		List outputItems = outputSet.getOutputItems(outputSummary);
 
-		// make copy of params; we'll clear keys as we consume them.
-		params = new HashMap(params);
+		updateOffsetsStep(outputItems);
 
-		// clear format key.
-		if (params.containsKey(PARAM_KEY_FORMAT))
-			params.remove(PARAM_KEY_FORMAT);
+		outputSummary.updateOffsets(byteOrder);
 
-		int width = src.getWidth();
-		int height = src.getHeight();
+		BinaryOutputStream bos = new BinaryOutputStream(os, byteOrder);
 
-		//        BinaryOutputStream bos = new BinaryOutputStream(os, WRITE_BYTE_ORDER);
-		//
-		//        writeImageFileHeader(bos, WRITE_BYTE_ORDER);
+		writeStep(bos, outputItems);
 
-		//        ArrayList directoryFields = new ArrayList();
+	}
 
-		final int photometricInterpretation = 2; // TODO: 
+	private void updateOffsetsStep(List outputItems) throws IOException,
+			ImageWriteException
+	{
+		int offset = TIFF_HEADER_SIZE;
 
-		int compression = TIFF_COMPRESSION_LZW; // LZW is default
-		if (params.containsKey(PARAM_KEY_COMPRESSION))
+		for (int i = 0; i < outputItems.size(); i++)
 		{
-			Object value = params.get(PARAM_KEY_COMPRESSION);
-			if (value != null)
-			{
-				if (!(value instanceof Number))
-					throw new ImageWriteException(
-							"Invalid compression parameter: " + value);
-				compression = ((Number) value).intValue();
-			}
-			params.remove(PARAM_KEY_COMPRESSION);
-		}
-
-		final int samplesPerPixel = 3; // TODO: 
-		final int bitsPerSample = 8; // TODO: 
-
-		//        int fRowsPerStrip; // TODO: 
-		int rowsPerStrip = 8000 / (width * samplesPerPixel); // TODO: 
-		rowsPerStrip = Math.max(1, rowsPerStrip); // must have at least one.
+			TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
 
-		byte strips[][] = getStrips(src, samplesPerPixel, bitsPerSample,
-				rowsPerStrip);
+			outputItem.setOffset(offset);
+			int itemLength = outputItem.getItemLength();
+			offset += itemLength;
 
-		//        int stripCount = (height + fRowsPerStrip - 1) / fRowsPerStrip;
-		//        int stripCount = strips.length;
-
-		if (params.size() > 0)
-		{
-			Object firstKey = params.keySet().iterator().next();
-			throw new ImageWriteException("Unknown parameter: " + firstKey);
+			int remainder = imageDataPaddingLength(itemLength);
+			offset += remainder;
 		}
+	}
 
-		//        System.out.println("width: " + width);
-		//        System.out.println("height: " + height);
-		//        System.out.println("fRowsPerStrip: " + fRowsPerStrip);
-		//        System.out.println("fSamplesPerPixel: " + fSamplesPerPixel);
-		//        System.out.println("stripCount: " + stripCount);
+	private void writeStep(BinaryOutputStream bos, List outputItems)
+			throws IOException, ImageWriteException
+	{
 
-		if (compression == TIFF_COMPRESSION_PACKBITS)
-		{
-			for (int i = 0; i < strips.length; i++)
-				strips[i] = new PackBits().compress(strips[i]);
-		}
-		else if (compression == TIFF_COMPRESSION_LZW)
-		{
-			for (int i = 0; i < strips.length; i++)
-			{
-				byte uncompressed[] = strips[i];
-
-				int LZWMinimumCodeSize = 8;
-
-				MyLZWCompressor compressor = new MyLZWCompressor(
-						LZWMinimumCodeSize, BYTE_ORDER_MSB, true);
-				byte compressed[] = compressor.compress(uncompressed);
+		writeImageFileHeader(bos);
 
-				strips[i] = compressed;
-			}
-		}
-		else if (compression == TIFF_COMPRESSION_UNCOMPRESSED)
+		int offset = TIFF_HEADER_SIZE;
+		for (int i = 0; i < outputItems.size(); i++)
 		{
-			// do nothing.
-		}
-		else
-			throw new ImageWriteException(
-					"Invalid compression parameter (Only LZW, Packbits and uncompressed supported).");
-
-		//        int stripOffsets[] = new int[stripCount];
-		//        int stripByteCounts[] = new int[stripCount];
-		//
-		//        for (int i = 0; i < strips.length; i++)
-		//            stripByteCounts[i] = strips[i].length;
-
-		TiffOutputDirectory directory = new TiffOutputDirectory(
-				TiffDirectory.DIRECTORY_TYPE_ROOT);
+			TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
 
-		//        WriteField stripOffsetsField;
-
-		{
-			{
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_IMAGE_WIDTH, FIELD_TYPE_LONG, 1,
-						FIELD_TYPE_LONG.writeData(new int[]{
-							width,
-						}, byteOrder));
-				directory.add(field);
-			}
-			{
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_IMAGE_LENGTH, FIELD_TYPE_LONG, 1,
-						FIELD_TYPE_LONG.writeData(new int[]{
-							height,
-						}, byteOrder));
-				directory.add(field);
-			}
-			{
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_PHOTOMETRIC_INTERPRETATION, FIELD_TYPE_SHORT,
-						1, FIELD_TYPE_SHORT.writeData(new int[]{
-							photometricInterpretation,
-						}, byteOrder));
-				directory.add(field);
-			}
-			{
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_COMPRESSION, FIELD_TYPE_SHORT, 1,
-						FIELD_TYPE_SHORT.writeData(new int[]{
-							compression,
-						}, byteOrder));
-				directory.add(field);
-			}
-			{
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_SAMPLES_PER_PIXEL, FIELD_TYPE_SHORT, 1,
-						FIELD_TYPE_SHORT.writeData(new int[]{
-							samplesPerPixel,
-						}, byteOrder));
-				directory.add(field);
-			}
-			{
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_BITS_PER_SAMPLE, FIELD_TYPE_SHORT, 3,
-						FIELD_TYPE_SHORT.writeData(new int[]{
-								bitsPerSample, bitsPerSample, bitsPerSample,
-						}, byteOrder));
-				directory.add(field);
-			}
-			//            {
-			//                stripOffsetsField = new WriteField(TIFF_TAG_STRIP_OFFSETS,
-			//                        FIELD_TYPE_LONG, stripOffsets.length, FIELD_TYPE_LONG
-			//                                .writeData(stripOffsets, byteOrder));
-			//                directory.add(stripOffsetsField);
-			//            }
-			//            {
-			//                WriteField field = new WriteField(TIFF_TAG_STRIP_BYTE_COUNTS,
-			//                        FIELD_TYPE_LONG, stripByteCounts.length,
-			//                        FIELD_TYPE_LONG.writeData(stripByteCounts,
-			//                                WRITE_BYTE_ORDER));
-			//                directory.add(field);
-			//            }
-			{
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_ROWS_PER_STRIP, FIELD_TYPE_LONG, 1,
-						FIELD_TYPE_LONG.writeData(new int[]{
-							rowsPerStrip,
-						}, byteOrder));
-				directory.add(field);
-			}
-
-			{
-				int resolutionUnit = 2;// inches.
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_RESOLUTION_UNIT, FIELD_TYPE_SHORT, 1,
-						FIELD_TYPE_SHORT.writeData(new int[]{
-							resolutionUnit,
-						}, byteOrder));
-				directory.add(field);
-			}
-
-			{
-				int xResolution = 72;
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_XRESOLUTION, FIELD_TYPE_RATIONAL, 1,
-						FIELD_TYPE_RATIONAL
-								.writeData(xResolution, 1, byteOrder));
-				directory.add(field);
-			}
-
-			{
-				int yResolution = 72;
-				TiffOutputField field = new TiffOutputField(
-						TIFF_TAG_YRESOLUTION, FIELD_TYPE_RATIONAL, 1,
-						FIELD_TYPE_RATIONAL
-								.writeData(yResolution, 1, byteOrder));
-				directory.add(field);
-			}
+			outputItem.writeItem(bos);
 
+			int length = outputItem.getItemLength();
+			offset += length;
+			int remainder = imageDataPaddingLength(length);
+			offset += remainder;
+			for (int j = 0; j < remainder; j++)
+				bos.write(0);
 		}
 
-		RawTiffImageData rawTiffImageData = new RawTiffImageData.Strips(strips);
-		directory.setRawTiffImageData(rawTiffImageData);
-
-		ArrayList directories = new ArrayList();
-		directories.add(directory);
-
-		writeDirectories(os, directories);
 	}
 
 	private void writeImageFileHeader(BinaryOutputStream bos)
@@ -322,139 +105,9 @@
 
 		bos.write2Bytes(42); // tiffVersion
 
-		int foffsetToFirstIFD = TIFF_HEADER_SIZE;
-
-		bos.write4Bytes(foffsetToFirstIFD);
-	}
+		int offsetToFirstIFD = TIFF_HEADER_SIZE;
 
-	private TiffOutputDirectory findDirectoryByType(List directories, int type)
-	{
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffOutputDirectory directory = (TiffOutputDirectory) directories
-					.get(i);
-			if (directory.type == type)
-				return directory;
-		}
-		return null;
-	}
-
-	public void writeDirectories(OutputStream os, TiffOutputSet outputSet)
-			throws IOException, ImageWriteException
-	{
-		writeDirectories(os, outputSet.getDirectories());
-	}
-
-	public void writeDirectories(OutputStream os, List directories)
-			throws IOException, ImageWriteException
-	{
-
-		TiffOutputSummary outputSummary = validateDirectories(directories);
-
-		//        Collections.sort(directories, Directory.COMPARATOR);
-
-		/**/
-
-		//        ImageDataInfo imageDataInfo = imageDataInfoStep(directories, imageData,
-		//                stripsNotTiles);
-		/**/
-
-		//		PointerDirectoriesInfo pointerDirectoriesInfo = pointerDirectoriesStep(directories);
-		/**/
-
-		//        final int imageDataOffset = 
-		calculateLengthsAndOffsetsStep(directories);
-
-		/**/
-
-		outputSummary.updateOffsets(byteOrder);
-
-		/**/
-
-		//        updateImageDataOffsetsStep(imageDataInfo, imageDataOffset);
-		/**/
-
-		DebugOutputStream dos = null;
-		//        DebugOutputStream dos = new DebugOutputStream(os);
-		//        os = dos;
-		BinaryOutputStream bos = new BinaryOutputStream(os, byteOrder);
-
-		/**/
-
-		writeStep(bos, directories, dos);
-
-		/**/
-
-		//        writeImageDataStep(bos, directories, imageDataInfo);
-		/**/
-	}
-
-	private void calculateLengthsAndOffsetsStep(List directories)
-			throws IOException, ImageWriteException
-	//    private int calculateLengthsAndOffsetsStep(ArrayList directories)
-	{
-		// Calculate lengths and offsets
-		int offset = TIFF_HEADER_SIZE;
-
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffOutputDirectory directory = (TiffOutputDirectory) directories
-					.get(i);
-
-			// fields must be written in ascending order.
-			directory.sortFields();
-
-			directory.setOffset(offset);
-
-			if (directory.type == TiffDirectory.DIRECTORY_TYPE_EXIF
-					|| directory.type == TiffDirectory.DIRECTORY_TYPE_GPS
-					|| directory.type == TiffDirectory.DIRECTORY_TYPE_INTEROPERABILITY)
-			{
-				// "pointer" directories don't partcipate in normal TIFF directory chain.
-				directory.calculateLengths(byteOrder);
-				offset += directory.totalLength;
-			}
-			else
-			{
-				directory.calculateLengths(byteOrder);
-				offset += directory.totalLength;
-			}
-		}
-		//        return offset;
-	}
-
-	private void writeStep(BinaryOutputStream bos, List directories,
-			DebugOutputStream dos) throws IOException, ImageWriteException
-	{
-		writeImageFileHeader(bos);
-
-		long count, lastCount = 0;
-
-		if (null != dos)
-		{
-			count = dos.count();
-			Debug.debug("image header" + " start: " + lastCount + ", end: "
-					+ dos.count() + ", length: " + (count - lastCount));
-			lastCount = count;
-		}
-
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffOutputDirectory directory = (TiffOutputDirectory) directories
-					.get(i);
-			directory.write(bos);
-
-			if (null != dos)
-			{
-				count = dos.count();
-				Debug.debug("directory("
-						+ TiffDirectory.description(directory.type) + ")"
-						+ " start: " + lastCount + ", end: " + dos.count()
-						+ ", length: " + (count - lastCount)
-						+ ", expected length: " + directory.totalLength);
-				lastCount = count;
-			}
-		}
+		bos.write4Bytes(offsetToFirstIFD);
 	}
 
 }

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java Mon Jan  7 00:12:01 2008
@@ -36,12 +36,7 @@
 		implements
 			TiffConstants
 {
-	public static final int UNDEFINED_VALUE = -1;
-
 	public final int type;
-	public int internalLength = UNDEFINED_VALUE;
-	public int totalLength = UNDEFINED_VALUE;
-	//	public int offset = UNDEFINED_VALUE;
 	private final ArrayList fields = new ArrayList();
 
 	private TiffOutputDirectory nextDirectory = null;
@@ -90,48 +85,6 @@
 			}
 		};
 		Collections.sort(fields, comparator);
-		//			Debug.debug("first field", ((WriteField) fields.get(0)).tagInfo);
-		//			Debug.debug("last field", ((WriteField) fields.get(fields.size()-1)).tagInfo);
-		//			for(int i=0;i<fields.size();i++)
-		//			{
-		//				WriteField field = (WriteField) fields.get(i);
-		//				Debug.debug(" field", field.tagInfo);
-		//			}
-	}
-
-	public void calculateLengths(int byteOrder) throws IOException,
-			ImageWriteException
-	{
-		tiffImageDataInfoStep(byteOrder);
-		jpegImageDataInfoStep(byteOrder);
-
-		internalLength = TIFF_ENTRY_LENGTH * fields.size()
-				+ TIFF_DIRECTORY_HEADER_LENGTH + TIFF_DIRECTORY_FOOTER_LENGTH;
-
-		totalLength = internalLength;
-
-		for (int i = 0; i < fields.size(); i++)
-		{
-			TiffOutputField field = (TiffOutputField) fields.get(i);
-			totalLength += field.getSeperateValueLength();
-		}
-
-		if (null != imageDataInfo)
-		{
-			int imageDataOffset = getOffset() + totalLength;
-			totalLength += imageDataInfo.totalLength;
-			updateTiffImageDataOffsetsStep(imageDataOffset, byteOrder);
-		}
-
-		if (null != rawJpegImageData)
-		{
-			int imageDataOffset = getOffset() + totalLength;
-			totalLength += rawJpegImageData.length;
-			totalLength += TiffImageWriterBase
-					.imageDataPaddingLength(rawJpegImageData.length);
-			updateJpegImageDataOffsetsStep(imageDataOffset, byteOrder);
-		}
-
 	}
 
 	public String description()
@@ -149,83 +102,11 @@
 		for (int i = 0; i < fields.size(); i++)
 		{
 			TiffOutputField field = (TiffOutputField) fields.get(i);
-			field.writeSimple(bos);
-
-//			Debug.debug("\t" + "writing field (" + field.tag + ", 0x" + Integer.toHexString(field.tag) + ")", field.tagInfo);
-//			if(field.tagInfo.isOffset())
-//				Debug.debug("\t\tOFFSET!", field.bytes);
-		}
-
-		int nextDirectoryOffset = 0;
-		if (nextDirectory != null)
-			nextDirectoryOffset = nextDirectory.getOffset();
-
-		// Write nextDirectoryOffset
-		if (nextDirectoryOffset == UNDEFINED_VALUE)
-			bos.write4Bytes(0);
-		else
-			bos.write4Bytes(nextDirectoryOffset);
-
-		//		// Write Seperate Values
-		//		for (int i = 0; i < fields.size(); i++)
-		//		{
-		//			TiffOutputField field = (TiffOutputField) fields.get(i);
-		//			field.writeSeperateValue(bos);
-		//		}
-
-		//		if (null != rawTiffImageData)
-		//		{
-		//			byte imageData[][] = rawTiffImageData.getRawImageData();
-		//			for (int i = 0; i < imageData.length; i++)
-		//			{
-		//				bos.writeByteArray(imageData[i]);
-		//				int imageDataByteCount = imageData[i].length;
-		//
-		//				int remainder = TiffImageWriterBase
-		//						.imageDataPaddingLength(imageDataByteCount);
-		//				for (int j = 0; j < remainder; j++)
-		//					bos.write(0);
-		//			}
-		//		}
-		//
-		//		if (null != rawJpegImageData)
-		//		{
-		//			//				byte imageData[][] = rawJpegImageData.getRawImageData();
-		//			bos.writeByteArray(rawJpegImageData);
-		//			int remainder = TiffImageWriterBase
-		//					.imageDataPaddingLength(rawJpegImageData.length);
-		//			for (int j = 0; j < remainder; j++)
-		//				bos.write(0);
-		//		}
-
-	}
-
-	public void write(BinaryOutputStream bos) throws IOException,
-			ImageWriteException
-	{
-
-		//			Debug.debug("dir write");
-		//			Debug.debug("dir write offset", offset);
-		//			Debug.debug("dir write internalLength", internalLength);
-		//			Debug.debug("dir write totalLength", totalLength);
-		//			Debug.debug("dir write fields", fields.size());
-		//			Debug.debug("dir write nextDirectoryOffset", nextDirectoryOffset);
+			field.writeField(bos);
 
-		int nextSeperateValueOffset = getOffset() + internalLength;
-
-		//			Debug.debug("writing directory", description());
-		//			Debug.debug("writing fields.size()", fields.size());
-
-		// Write Directory Field Count
-		bos.write2Bytes(fields.size()); // DirectoryFieldCount
-
-		// Write Fields
-		for (int i = 0; i < fields.size(); i++)
-		{
-			TiffOutputField field = (TiffOutputField) fields.get(i);
-			//				checkOffset("ifd [" + i + "]", fOffsetToSeperateValues);
-			nextSeperateValueOffset += field.writeDirectoryEntry(bos,
-					nextSeperateValueOffset);
+			//			Debug.debug("\t" + "writing field (" + field.tag + ", 0x" + Integer.toHexString(field.tag) + ")", field.tagInfo);
+			//			if(field.tagInfo.isOffset())
+			//				Debug.debug("\t\tOFFSET!", field.bytes);
 		}
 
 		int nextDirectoryOffset = 0;
@@ -237,110 +118,8 @@
 			bos.write4Bytes(0);
 		else
 			bos.write4Bytes(nextDirectoryOffset);
-
-		// Write Seperate Values
-		for (int i = 0; i < fields.size(); i++)
-		{
-			TiffOutputField field = (TiffOutputField) fields.get(i);
-			field.writeSeperateValue(bos);
-		}
-
-		if (null != rawTiffImageData)
-		{
-			byte imageData[][] = rawTiffImageData.getRawImageData();
-			for (int i = 0; i < imageData.length; i++)
-			{
-				bos.writeByteArray(imageData[i]);
-				int imageDataByteCount = imageData[i].length;
-
-				int remainder = TiffImageWriterBase
-						.imageDataPaddingLength(imageDataByteCount);
-				for (int j = 0; j < remainder; j++)
-					bos.write(0);
-			}
-		}
-
-		if (null != rawJpegImageData)
-		{
-			//				byte imageData[][] = rawJpegImageData.getRawImageData();
-			bos.writeByteArray(rawJpegImageData);
-			int remainder = TiffImageWriterBase
-					.imageDataPaddingLength(rawJpegImageData.length);
-			for (int j = 0; j < remainder; j++)
-				bos.write(0);
-		}
-
 	}
 
-	private ImageDataInfo imageDataInfo = null;
-
-	private void tiffImageDataInfoStep(int byteOrder)
-	{
-		if (null == rawTiffImageData)
-			return;
-
-		byte imageData[][] = rawTiffImageData.getRawImageData();
-		boolean stripsNotTiles = rawTiffImageData.stripsNotTiles();
-
-		int imageDataOffsets[] = null;
-		int imageDataByteCounts[] = null;
-		TiffOutputField imageDataOffsetsField = null;
-
-		imageDataOffsets = new int[imageData.length];
-		imageDataByteCounts = new int[imageData.length];
-
-		int totalLength = 0;
-		for (int i = 0; i < imageData.length; i++)
-		{
-			imageDataByteCounts[i] = imageData[i].length;
-			totalLength += imageData[i].length;
-
-			totalLength += TiffImageWriterBase
-					.imageDataPaddingLength(imageData[i].length);
-		}
-
-		// Append imageData-related fields to first directory
-		{
-			TagInfo tagInfo;
-			if (stripsNotTiles)
-				tagInfo = TIFF_TAG_STRIP_OFFSETS;
-			else
-				tagInfo = TIFF_TAG_TILE_OFFSETS;
-
-			imageDataOffsetsField = findField(tagInfo);
-			if (null == imageDataOffsetsField)
-			{
-				imageDataOffsetsField = new TiffOutputField(tagInfo,
-						FIELD_TYPE_LONG, imageDataOffsets.length,
-						FIELD_TYPE_LONG.writeData(imageDataOffsets, byteOrder));
-				add(imageDataOffsetsField);
-			}
-		}
-		{
-			TagInfo tagInfo;
-			if (stripsNotTiles)
-				tagInfo = TIFF_TAG_STRIP_BYTE_COUNTS;
-			else
-				tagInfo = TIFF_TAG_TILE_BYTE_COUNTS;
-
-			byte data[] = FIELD_TYPE_LONG.writeData(imageDataByteCounts,
-					byteOrder);
-
-			TiffOutputField field = findField(tagInfo);
-			if (null == field)
-				add(new TiffOutputField(tagInfo, FIELD_TYPE_LONG,
-						imageDataByteCounts.length, data));
-			else
-				field.setData(data);
-
-		}
-
-		imageDataInfo = new ImageDataInfo(imageData, imageDataOffsets,
-				imageDataByteCounts, imageDataOffsetsField, totalLength);
-	}
-
-	TiffOutputField jpegImageDataOffsetField = null;
-
 	private byte rawJpegImageData[] = null;
 
 	public void setRawJpegImageData(byte rawJpegImageData[])
@@ -353,69 +132,6 @@
 		return rawJpegImageData;
 	}
 
-	private void jpegImageDataInfoStep(int byteOrder)
-	{
-		if (null == rawJpegImageData)
-			return;
-
-		//			int totalLength = 0;
-		//			totalLength += rawJpegImageData.length;
-		//			totalLength += imageDataPaddingLength(rawJpegImageData.length);
-
-		// Append imageData-related fields to first directory
-		{
-			TagInfo tagInfo = TIFF_TAG_JPEG_INTERCHANGE_FORMAT;
-
-			jpegImageDataOffsetField = findField(tagInfo);
-			if (null == jpegImageDataOffsetField)
-			{
-				jpegImageDataOffsetField = new TiffOutputField(tagInfo,
-						FIELD_TYPE_LONG, 1, FIELD_TYPE_LONG.getStubValue(1));
-				add(jpegImageDataOffsetField);
-			}
-		}
-		{
-			TagInfo tagInfo = TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH;
-
-			byte data[] = FIELD_TYPE_LONG.writeData(new int[]{
-				rawJpegImageData.length,
-			}, byteOrder);
-
-			TiffOutputField field = findField(tagInfo);
-			if (null == field)
-				add(new TiffOutputField(tagInfo, FIELD_TYPE_LONG, 1, data));
-			else
-				field.setData(data);
-		}
-	}
-
-	private void updateTiffImageDataOffsetsStep(final int imageDataOffset,
-			int byteOrder) throws IOException, ImageWriteException
-	{
-		int currentOffset = imageDataOffset;
-
-		for (int i = 0; i < imageDataInfo.imageData.length; i++)
-		{
-			imageDataInfo.imageDataOffsets[i] = currentOffset;
-			currentOffset += imageDataInfo.imageDataByteCounts[i];
-
-			currentOffset += TiffImageWriterBase
-					.imageDataPaddingLength(imageDataInfo.imageDataByteCounts[i]);
-		}
-
-		imageDataInfo.imageDataOffsetsField.setData(FIELD_TYPE_LONG.writeData(
-				imageDataInfo.imageDataOffsets, byteOrder));
-		//			}
-	}
-
-	private void updateJpegImageDataOffsetsStep(final int imageDataOffset,
-			int byteOrder) throws IOException, ImageWriteException
-	{
-		jpegImageDataOffsetField.setData(FIELD_TYPE_LONG.writeData(new int[]{
-			imageDataOffset,
-		}, byteOrder));
-	}
-
 	private RawTiffImageData rawTiffImageData = null;
 
 	public void setRawTiffImageData(RawTiffImageData rawTiffImageData)
@@ -428,16 +144,6 @@
 		return rawTiffImageData;
 	}
 
-	//		public static final Comparator COMPARATOR = new Comparator()
-	//		{
-	//			public int compare(Object o1, Object o2)
-	//			{
-	//				Directory e1 = (Directory) o1;
-	//				Directory e2 = (Directory) o2;
-	//				return e1.offset - e2.offset;
-	//			}
-	//		};
-
 	public int getItemLength()
 	{
 		return TIFF_ENTRY_LENGTH * fields.size() + TIFF_DIRECTORY_HEADER_LENGTH
@@ -461,7 +167,7 @@
 	protected List getOutputItems(TiffOutputSummary outputSummary)
 	{
 		// first validate directory fields.
-		
+
 		removeFieldIfPresent(TIFF_TAG_JPEG_INTERCHANGE_FORMAT);
 		removeFieldIfPresent(TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
 
@@ -473,15 +179,15 @@
 					FieldType.getStubLocalValue());
 			add(jpegOffsetField);
 
+			byte lengthValue[] = FIELD_TYPE_LONG.writeData(new int[]{
+				rawJpegImageData.length,
+			}, outputSummary.byteOrder);
+
 			TiffOutputField jpegLengthField = new TiffOutputField(
 					TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, FIELD_TYPE_LONG,
-					1, FieldType.getStubLocalValue());
+					1, lengthValue);
 			add(jpegLengthField);
 
-			byte lengthValue[] = FIELD_TYPE_LONG.writeData(new int[]{
-				rawJpegImageData.length,
-			}, outputSummary.byteOrder);
-			jpegLengthField.setData(lengthValue);
 		}
 
 		// --------------------------------------------------------------
@@ -492,7 +198,7 @@
 		removeFieldIfPresent(TIFF_TAG_TILE_BYTE_COUNTS);
 
 		TiffOutputField imageDataOffsetField;
-		ImageDataInfo imageDataInfo = null;
+		ImageDataOffsets imageDataInfo = null;
 		if (null != rawTiffImageData)
 		{
 			boolean stripsNotTiles = rawTiffImageData.stripsNotTiles();
@@ -520,15 +226,9 @@
 
 			imageDataOffsets = new int[imageData.length];
 			imageDataByteCounts = new int[imageData.length];
-
-			int imageDataTotalLength = 0;
 			for (int i = 0; i < imageData.length; i++)
 			{
 				imageDataByteCounts[i] = imageData[i].length;
-				imageDataTotalLength += imageData[i].length;
-
-				imageDataTotalLength += TiffImageWriterBase
-						.imageDataPaddingLength(imageData[i].length);
 			}
 
 			// --------
@@ -551,9 +251,8 @@
 
 			// --------
 
-			imageDataInfo = new ImageDataInfo(imageData, imageDataOffsets,
-					imageDataByteCounts, imageDataOffsetField,
-					imageDataTotalLength);
+			imageDataInfo = new ImageDataOffsets(imageData, imageDataOffsets,
+					 imageDataOffsetField);
 		}
 
 		// --------------------------------------------------------------
@@ -562,18 +261,6 @@
 		result.add(this);
 		sortFields();
 
-		//		public void calculateLengths(int byteOrder) throws IOException,
-		//		ImageWriteException
-		//{
-		//	tiffImageDataInfoStep(byteOrder);
-		//	jpegImageDataInfoStep(byteOrder);
-		//
-		//	internalLength = TIFF_ENTRY_LENGTH * fields.size()
-		//			+ TIFF_DIRECTORY_HEADER_LENGTH
-		//			+ TIFF_DIRECTORY_FOOTER_LENGTH;
-		//
-		//	totalLength = internalLength;
-		//
 		for (int i = 0; i < fields.size(); i++)
 		{
 			TiffOutputField field = (TiffOutputField) fields.get(i);
@@ -582,7 +269,7 @@
 
 			TiffOutputItem item = field.getSeperateValue();
 			result.add(item);
-//			outputSummary.add(item, field);
+			//			outputSummary.add(item, field);
 		}
 
 		if (null != imageDataInfo)

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java Mon Jan  7 00:12:01 2008
@@ -69,7 +69,7 @@
 				}, byteOrder));
 	}
 
-	protected void writeSimple(BinaryOutputStream bos) throws IOException,
+	protected void writeField(BinaryOutputStream bos) throws IOException,
 			ImageWriteException
 	{
 		bos.write2Bytes(tag);
@@ -99,36 +99,6 @@
 		}
 	}
 
-	protected int writeDirectoryEntry(BinaryOutputStream bos,
-			int seperateValuesOffset) throws ImageWriteException, IOException
-	{
-		bos.write2Bytes(tag);
-		bos.write2Bytes(fieldType.type);
-		bos.write4Bytes(count);
-
-		//		if(fieldType.type == TiffConstants.FIELD_TYPE_ASCII.type)
-		//			Debug.debug("ascii bytes", bytes);
-
-		if (isLocalValue())
-		{
-			bos.writeByteArray(bytes);
-			int remainder = TIFF_ENTRY_MAX_VALUE_LENGTH - bytes.length;
-			for (int i = 0; i < remainder; i++)
-				bos.write(0);
-			return 0;
-		}
-		else
-		{
-			bos.write4Bytes(seperateValuesOffset);
-
-			int written = bytes.length;
-			if ((written % 2) != 0)
-				written++;
-
-			return written;
-		}
-	}
-
 	protected TiffOutputItem getSeperateValue()
 	{
 		return separateValueItem;
@@ -139,47 +109,16 @@
 		return bytes.length <= TIFF_ENTRY_MAX_VALUE_LENGTH;
 	}
 
-	protected int getSeperateValueLength()
-	{
-		if (isLocalValue())
-			return 0;
-		else
-		{
-			int written = bytes.length;
-			if ((written % 2) != 0)
-				written++;
-
-			return written;
-		}
-	}
-
-	protected int writeSeperateValue(BinaryOutputStream bos)
-			throws ImageWriteException, IOException
-	{
-		if (isLocalValue())
-			return 0;
-
-		bos.writeByteArray(bytes);
-
-		int written = bytes.length;
-		if ((written % 2) != 0)
-		{
-			bos.write(0);
-			written++;
-		}
-		return written;
-	}
-
-	protected void setData(byte bytes[])
+	protected void setData(byte bytes[]) throws ImageWriteException
 	{
 		if (this.bytes.length != bytes.length)
-			throw new Error("Bug. Locality disrupted! "
-					+ tagInfo.getDescription());
-		boolean wasLocalValue = isLocalValue();
+			throw new ImageWriteException("Cannot change size of value.");
+
+		//		boolean wasLocalValue = isLocalValue();
 		this.bytes = bytes;
-		if (isLocalValue() != wasLocalValue)
-			throw new Error("Bug. Locality disrupted! "
-					+ tagInfo.getDescription());
+		//		if (isLocalValue() != wasLocalValue)
+		//			throw new Error("Bug. Locality disrupted! "
+		//					+ tagInfo.getDescription());
 	}
 
 	private static final String newline = System.getProperty("line.separator");

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java Mon Jan  7 00:12:01 2008
@@ -127,20 +127,6 @@
 		return result;
 	}
 
-	//	public static final int DIRECTORY_TYPE_UNKNOWN = -1;
-	//	public static final int DIRECTORY_TYPE_ROOT = 0;
-	//	public static final int DIRECTORY_TYPE_SUB = 1;
-	//	public static final int DIRECTORY_TYPE_THUMBNAIL = 2;
-	//	public static final int DIRECTORY_TYPE_EXIF = -2;
-	//	//	public static final int DIRECTORY_TYPE_SUB = 5;
-	//	public static final int DIRECTORY_TYPE_GPS = -3;
-	//	public static final int DIRECTORY_TYPE_INTEROPERABILITY = -4;
-	//	public static final int DIRECTORY_TYPE_DIR_0 = 0;
-	//	public static final int DIRECTORY_TYPE_DIR_1 = 1;
-	//	public static final int DIRECTORY_TYPE_DIR_2 = 2;
-	//	public static final int DIRECTORY_TYPE_DIR_3 = 3;
-	//	public static final int DIRECTORY_TYPE_DIR_4 = 4;
-
 	private static final String newline = System.getProperty("line.separator");
 
 	public String toString()

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java?rev=609529&r1=609528&r2=609529&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java Mon Jan  7 00:12:01 2008
@@ -60,7 +60,7 @@
 		offsetItems.add(new OffsetItem(item, itemOffsetField));
 	}
 
-	public void updateOffsets(int byteOrder)
+	public void updateOffsets(int byteOrder) throws ImageWriteException
 	{
 		for (int i = 0; i < offsetItems.size(); i++)
 		{
@@ -74,9 +74,9 @@
 
 		for (int i = 0; i < imageDataItems.size(); i++)
 		{
-			ImageDataInfo imageDataInfo = (ImageDataInfo) imageDataItems.get(i);
+			ImageDataOffsets imageDataInfo = (ImageDataOffsets) imageDataItems.get(i);
 
-			for (int j = 0; j < imageDataInfo.imageData.length; j++)
+			for (int j = 0; j < imageDataInfo.outputItems.length; j++)
 			{
 				TiffOutputItem item = imageDataInfo.outputItems[j];
 				imageDataInfo.imageDataOffsets[j] = item.getOffset();
@@ -89,7 +89,7 @@
 
 	private List imageDataItems = new ArrayList();
 
-	public void addTiffImageData(final ImageDataInfo imageDataInfo)
+	public void addTiffImageData(final ImageDataOffsets imageDataInfo)
 	{
 		offsetItems.add(imageDataInfo);
 	}



Mime
View raw message