You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2010/09/10 18:33:42 UTC

svn commit: r995859 [26/30] - in /commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan: ./ color/ common/ common/byteSources/ common/mylzw/ formats/bmp/ formats/bmp/pixelparsers/ formats/bmp/writers/ formats/gif/ formats/ico/ formats/jpeg/ f...

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossy.java Fri Sep 10 16:33:35 2010
@@ -26,66 +26,66 @@ import org.apache.sanselan.common.Binary
 public class TiffImageWriterLossy extends TiffImageWriterBase
 {
 
-	public TiffImageWriterLossy()
-	{
-	}
+    public TiffImageWriterLossy()
+    {
+    }
 
-	public TiffImageWriterLossy(int byteOrder)
-	{
-		super(byteOrder);
-	}
+    public TiffImageWriterLossy(int byteOrder)
+    {
+        super(byteOrder);
+    }
 
-	public void write(OutputStream os, TiffOutputSet outputSet)
-			throws IOException, ImageWriteException
-	{
-		TiffOutputSummary outputSummary = validateDirectories(outputSet);
+    public void write(OutputStream os, TiffOutputSet outputSet)
+            throws IOException, ImageWriteException
+    {
+        TiffOutputSummary outputSummary = validateDirectories(outputSet);
 
-		List outputItems = outputSet.getOutputItems(outputSummary);
+        List outputItems = outputSet.getOutputItems(outputSummary);
 
-		updateOffsetsStep(outputItems);
+        updateOffsetsStep(outputItems);
 
-		outputSummary.updateOffsets(byteOrder);
+        outputSummary.updateOffsets(byteOrder);
 
-		BinaryOutputStream bos = new BinaryOutputStream(os, byteOrder);
+        BinaryOutputStream bos = new BinaryOutputStream(os, byteOrder);
 
-		writeStep(bos, outputItems);
-	}
+        writeStep(bos, outputItems);
+    }
 
-	private void updateOffsetsStep(List outputItems) throws IOException,
-			ImageWriteException
-	{
-		int offset = TIFF_HEADER_SIZE;
+    private void updateOffsetsStep(List outputItems) throws IOException,
+            ImageWriteException
+    {
+        int offset = TIFF_HEADER_SIZE;
 
-		for (int i = 0; i < outputItems.size(); i++)
-		{
-			TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
+        for (int i = 0; i < outputItems.size(); i++)
+        {
+            TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
 
-			outputItem.setOffset(offset);
-			int itemLength = outputItem.getItemLength();
-			offset += itemLength;
+            outputItem.setOffset(offset);
+            int itemLength = outputItem.getItemLength();
+            offset += itemLength;
 
-			int remainder = imageDataPaddingLength(itemLength);
-			offset += remainder;
-		}
-	}
+            int remainder = imageDataPaddingLength(itemLength);
+            offset += remainder;
+        }
+    }
 
-	private void writeStep(BinaryOutputStream bos, List outputItems)
-			throws IOException, ImageWriteException
-	{
-		writeImageFileHeader(bos);
+    private void writeStep(BinaryOutputStream bos, List outputItems)
+            throws IOException, ImageWriteException
+    {
+        writeImageFileHeader(bos);
 
-		for (int i = 0; i < outputItems.size(); i++)
-		{
-			TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
+        for (int i = 0; i < outputItems.size(); i++)
+        {
+            TiffOutputItem outputItem = (TiffOutputItem) outputItems.get(i);
 
-			outputItem.writeItem(bos);
+            outputItem.writeItem(bos);
 
-			int length = outputItem.getItemLength();
+            int length = outputItem.getItemLength();
 
-			int remainder = imageDataPaddingLength(length);
-			for (int j = 0; j < remainder; j++)
-				bos.write(0);
-		}
+            int remainder = imageDataPaddingLength(length);
+            for (int j = 0; j < remainder; j++)
+                bos.write(0);
+        }
 
-	}
+    }
 }

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputDirectory.java Fri Sep 10 16:33:35 2010
@@ -34,284 +34,284 @@ import org.apache.sanselan.formats.tiff.
 import org.apache.sanselan.formats.tiff.fieldtypes.FieldType;
 
 public final class TiffOutputDirectory extends TiffOutputItem implements
-		TiffConstants
+        TiffConstants
 {
-	public final int type;
-	private final ArrayList fields = new ArrayList();
+    public final int type;
+    private final ArrayList fields = new ArrayList();
 
-	private TiffOutputDirectory nextDirectory = null;
+    private TiffOutputDirectory nextDirectory = null;
 
-	public void setNextDirectory(TiffOutputDirectory nextDirectory)
-	{
-		this.nextDirectory = nextDirectory;
-	}
-
-	public TiffOutputDirectory(final int type)
-	{
-		this.type = type;
-	}
-
-	public void add(TiffOutputField field)
-	{
-		fields.add(field);
-	}
-
-	public ArrayList getFields()
-	{
-		return new ArrayList(fields);
-	}
-
-	public void removeField(TagInfo tagInfo)
-	{
-		removeField(tagInfo.tag);
-	}
-
-	public void removeField(int tag)
-	{
-		ArrayList matches = new ArrayList();
-		for (int i = 0; i < fields.size(); i++)
-		{
-			TiffOutputField field = (TiffOutputField) fields.get(i);
-			if (field.tag == tag)
-				matches.add(field);
-		}
-		fields.removeAll(matches);
-	}
-
-	public TiffOutputField findField(TagInfo tagInfo)
-	{
-		return findField(tagInfo.tag);
-	}
-
-	public TiffOutputField findField(int tag)
-	{
-		for (int i = 0; i < fields.size(); i++)
-		{
-			TiffOutputField field = (TiffOutputField) fields.get(i);
-			if (field.tag == tag)
-				return field;
-		}
-		return null;
-	}
-
-	public void sortFields()
-	{
-		Comparator comparator = new Comparator() {
-			public int compare(Object o1, Object o2)
-			{
-				TiffOutputField e1 = (TiffOutputField) o1;
-				TiffOutputField e2 = (TiffOutputField) o2;
-
-				if (e1.tag != e2.tag)
-					return e1.tag - e2.tag;
-				return e1.getSortHint() - e2.getSortHint();
-			}
-		};
-		Collections.sort(fields, comparator);
-	}
-
-	public String description()
-	{
-		return TiffDirectory.description(type);
-	}
-
-	public void writeItem(BinaryOutputStream bos) throws IOException,
-			ImageWriteException
-	{
-		// 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);
-			field.writeField(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);
-	}
-
-	private JpegImageData jpegImageData = null;
-
-	public void setJpegImageData(JpegImageData rawJpegImageData)
-	{
-		this.jpegImageData = rawJpegImageData;
-	}
-
-	public JpegImageData getRawJpegImageData()
-	{
-		return jpegImageData;
-	}
-
-	private TiffImageData tiffImageData = null;
-
-	public void setTiffImageData(TiffImageData rawTiffImageData)
-	{
-		this.tiffImageData = rawTiffImageData;
-	}
-
-	public TiffImageData getRawTiffImageData()
-	{
-		return tiffImageData;
-	}
-
-	public int getItemLength()
-	{
-		return TIFF_ENTRY_LENGTH * fields.size() + TIFF_DIRECTORY_HEADER_LENGTH
-				+ TIFF_DIRECTORY_FOOTER_LENGTH;
-	}
-
-	public String getItemDescription()
-	{
-		ExifDirectoryType dirType = TagConstantsUtils
-				.getExifDirectoryType(type);
-		return "Directory: " + dirType.name + " (" + type + ")";
-	}
-
-	private void removeFieldIfPresent(TagInfo tagInfo)
-	{
-		TiffOutputField field = findField(tagInfo);
-		if (null != field)
-			fields.remove(field);
-	}
-
-	protected List getOutputItems(TiffOutputSummary outputSummary)
-			throws ImageWriteException
-	{
-		// first validate directory fields.
-
-		removeFieldIfPresent(TIFF_TAG_JPEG_INTERCHANGE_FORMAT);
-		removeFieldIfPresent(TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
-
-		TiffOutputField jpegOffsetField = null;
-		if (null != jpegImageData)
-		{
-			jpegOffsetField = new TiffOutputField(
-					TIFF_TAG_JPEG_INTERCHANGE_FORMAT, FIELD_TYPE_LONG, 1,
-					FieldType.getStubLocalValue());
-			add(jpegOffsetField);
-
-			byte lengthValue[] = FIELD_TYPE_LONG.writeData(
-					new int[] { jpegImageData.length, },
-					outputSummary.byteOrder);
-
-			TiffOutputField jpegLengthField = new TiffOutputField(
-					TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, FIELD_TYPE_LONG,
-					1, lengthValue);
-			add(jpegLengthField);
-
-		}
-
-		// --------------------------------------------------------------
-
-		removeFieldIfPresent(TIFF_TAG_STRIP_OFFSETS);
-		removeFieldIfPresent(TIFF_TAG_STRIP_BYTE_COUNTS);
-		removeFieldIfPresent(TIFF_TAG_TILE_OFFSETS);
-		removeFieldIfPresent(TIFF_TAG_TILE_BYTE_COUNTS);
-
-		TiffOutputField imageDataOffsetField;
-		ImageDataOffsets imageDataInfo = null;
-		if (null != tiffImageData)
-		{
-			boolean stripsNotTiles = tiffImageData.stripsNotTiles();
-
-			TagInfo offsetTag;
-			TagInfo byteCountsTag;
-			if (stripsNotTiles)
-			{
-				offsetTag = TIFF_TAG_STRIP_OFFSETS;
-				byteCountsTag = TIFF_TAG_STRIP_BYTE_COUNTS;
-			} else
-			{
-				offsetTag = TIFF_TAG_TILE_OFFSETS;
-				byteCountsTag = TIFF_TAG_TILE_BYTE_COUNTS;
-			}
-
-			// --------
-
-			TiffElement.DataElement imageData[] = tiffImageData.getImageData();
-
-			int imageDataOffsets[] = null;
-			int imageDataByteCounts[] = null;
-			// TiffOutputField imageDataOffsetsField = null;
-
-			imageDataOffsets = new int[imageData.length];
-			imageDataByteCounts = new int[imageData.length];
-			for (int i = 0; i < imageData.length; i++)
-			{
-				imageDataByteCounts[i] = imageData[i].length;
-			}
-
-			// --------
-
-			// Append imageData-related fields to first directory
-			imageDataOffsetField = new TiffOutputField(offsetTag,
-					FIELD_TYPE_LONG, imageDataOffsets.length, FIELD_TYPE_LONG
-							.writeData(imageDataOffsets,
-									outputSummary.byteOrder));
-			add(imageDataOffsetField);
-
-			// --------
-
-			byte data[] = FIELD_TYPE_LONG.writeData(imageDataByteCounts,
-					outputSummary.byteOrder);
-			TiffOutputField byteCountsField = new TiffOutputField(
-					byteCountsTag, FIELD_TYPE_LONG, imageDataByteCounts.length,
-					data);
-			add(byteCountsField);
-
-			// --------
-
-			imageDataInfo = new ImageDataOffsets(imageData, imageDataOffsets,
-					imageDataOffsetField);
-		}
-
-		// --------------------------------------------------------------
-
-		List result = new ArrayList();
-		result.add(this);
-		sortFields();
-
-		for (int i = 0; i < fields.size(); i++)
-		{
-			TiffOutputField field = (TiffOutputField) fields.get(i);
-			if (field.isLocalValue())
-				continue;
-
-			TiffOutputItem item = field.getSeperateValue();
-			result.add(item);
-			// outputSummary.add(item, field);
-		}
-
-		if (null != imageDataInfo)
-		{
-			for (int i = 0; i < imageDataInfo.outputItems.length; i++)
-				result.add(imageDataInfo.outputItems[i]);
-
-			outputSummary.addTiffImageData(imageDataInfo);
-		}
-
-		if (null != jpegImageData)
-		{
-			TiffOutputItem item = new TiffOutputItem.Value("JPEG image data",
-					jpegImageData.data);
-			result.add(item);
-			outputSummary.add(item, jpegOffsetField);
-		}
+    public void setNextDirectory(TiffOutputDirectory nextDirectory)
+    {
+        this.nextDirectory = nextDirectory;
+    }
+
+    public TiffOutputDirectory(final int type)
+    {
+        this.type = type;
+    }
+
+    public void add(TiffOutputField field)
+    {
+        fields.add(field);
+    }
+
+    public ArrayList getFields()
+    {
+        return new ArrayList(fields);
+    }
+
+    public void removeField(TagInfo tagInfo)
+    {
+        removeField(tagInfo.tag);
+    }
+
+    public void removeField(int tag)
+    {
+        ArrayList matches = new ArrayList();
+        for (int i = 0; i < fields.size(); i++)
+        {
+            TiffOutputField field = (TiffOutputField) fields.get(i);
+            if (field.tag == tag)
+                matches.add(field);
+        }
+        fields.removeAll(matches);
+    }
+
+    public TiffOutputField findField(TagInfo tagInfo)
+    {
+        return findField(tagInfo.tag);
+    }
+
+    public TiffOutputField findField(int tag)
+    {
+        for (int i = 0; i < fields.size(); i++)
+        {
+            TiffOutputField field = (TiffOutputField) fields.get(i);
+            if (field.tag == tag)
+                return field;
+        }
+        return null;
+    }
+
+    public void sortFields()
+    {
+        Comparator comparator = new Comparator() {
+            public int compare(Object o1, Object o2)
+            {
+                TiffOutputField e1 = (TiffOutputField) o1;
+                TiffOutputField e2 = (TiffOutputField) o2;
+
+                if (e1.tag != e2.tag)
+                    return e1.tag - e2.tag;
+                return e1.getSortHint() - e2.getSortHint();
+            }
+        };
+        Collections.sort(fields, comparator);
+    }
+
+    public String description()
+    {
+        return TiffDirectory.description(type);
+    }
+
+    public void writeItem(BinaryOutputStream bos) throws IOException,
+            ImageWriteException
+    {
+        // 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);
+            field.writeField(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);
+    }
+
+    private JpegImageData jpegImageData = null;
+
+    public void setJpegImageData(JpegImageData rawJpegImageData)
+    {
+        this.jpegImageData = rawJpegImageData;
+    }
+
+    public JpegImageData getRawJpegImageData()
+    {
+        return jpegImageData;
+    }
+
+    private TiffImageData tiffImageData = null;
+
+    public void setTiffImageData(TiffImageData rawTiffImageData)
+    {
+        this.tiffImageData = rawTiffImageData;
+    }
+
+    public TiffImageData getRawTiffImageData()
+    {
+        return tiffImageData;
+    }
+
+    public int getItemLength()
+    {
+        return TIFF_ENTRY_LENGTH * fields.size() + TIFF_DIRECTORY_HEADER_LENGTH
+                + TIFF_DIRECTORY_FOOTER_LENGTH;
+    }
+
+    public String getItemDescription()
+    {
+        ExifDirectoryType dirType = TagConstantsUtils
+                .getExifDirectoryType(type);
+        return "Directory: " + dirType.name + " (" + type + ")";
+    }
+
+    private void removeFieldIfPresent(TagInfo tagInfo)
+    {
+        TiffOutputField field = findField(tagInfo);
+        if (null != field)
+            fields.remove(field);
+    }
+
+    protected List getOutputItems(TiffOutputSummary outputSummary)
+            throws ImageWriteException
+    {
+        // first validate directory fields.
+
+        removeFieldIfPresent(TIFF_TAG_JPEG_INTERCHANGE_FORMAT);
+        removeFieldIfPresent(TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH);
+
+        TiffOutputField jpegOffsetField = null;
+        if (null != jpegImageData)
+        {
+            jpegOffsetField = new TiffOutputField(
+                    TIFF_TAG_JPEG_INTERCHANGE_FORMAT, FIELD_TYPE_LONG, 1,
+                    FieldType.getStubLocalValue());
+            add(jpegOffsetField);
+
+            byte lengthValue[] = FIELD_TYPE_LONG.writeData(
+                    new int[] { jpegImageData.length, },
+                    outputSummary.byteOrder);
+
+            TiffOutputField jpegLengthField = new TiffOutputField(
+                    TIFF_TAG_JPEG_INTERCHANGE_FORMAT_LENGTH, FIELD_TYPE_LONG,
+                    1, lengthValue);
+            add(jpegLengthField);
+
+        }
+
+        // --------------------------------------------------------------
+
+        removeFieldIfPresent(TIFF_TAG_STRIP_OFFSETS);
+        removeFieldIfPresent(TIFF_TAG_STRIP_BYTE_COUNTS);
+        removeFieldIfPresent(TIFF_TAG_TILE_OFFSETS);
+        removeFieldIfPresent(TIFF_TAG_TILE_BYTE_COUNTS);
+
+        TiffOutputField imageDataOffsetField;
+        ImageDataOffsets imageDataInfo = null;
+        if (null != tiffImageData)
+        {
+            boolean stripsNotTiles = tiffImageData.stripsNotTiles();
+
+            TagInfo offsetTag;
+            TagInfo byteCountsTag;
+            if (stripsNotTiles)
+            {
+                offsetTag = TIFF_TAG_STRIP_OFFSETS;
+                byteCountsTag = TIFF_TAG_STRIP_BYTE_COUNTS;
+            } else
+            {
+                offsetTag = TIFF_TAG_TILE_OFFSETS;
+                byteCountsTag = TIFF_TAG_TILE_BYTE_COUNTS;
+            }
+
+            // --------
+
+            TiffElement.DataElement imageData[] = tiffImageData.getImageData();
+
+            int imageDataOffsets[] = null;
+            int imageDataByteCounts[] = null;
+            // TiffOutputField imageDataOffsetsField = null;
+
+            imageDataOffsets = new int[imageData.length];
+            imageDataByteCounts = new int[imageData.length];
+            for (int i = 0; i < imageData.length; i++)
+            {
+                imageDataByteCounts[i] = imageData[i].length;
+            }
+
+            // --------
+
+            // Append imageData-related fields to first directory
+            imageDataOffsetField = new TiffOutputField(offsetTag,
+                    FIELD_TYPE_LONG, imageDataOffsets.length, FIELD_TYPE_LONG
+                            .writeData(imageDataOffsets,
+                                    outputSummary.byteOrder));
+            add(imageDataOffsetField);
+
+            // --------
+
+            byte data[] = FIELD_TYPE_LONG.writeData(imageDataByteCounts,
+                    outputSummary.byteOrder);
+            TiffOutputField byteCountsField = new TiffOutputField(
+                    byteCountsTag, FIELD_TYPE_LONG, imageDataByteCounts.length,
+                    data);
+            add(byteCountsField);
+
+            // --------
+
+            imageDataInfo = new ImageDataOffsets(imageData, imageDataOffsets,
+                    imageDataOffsetField);
+        }
+
+        // --------------------------------------------------------------
+
+        List result = new ArrayList();
+        result.add(this);
+        sortFields();
+
+        for (int i = 0; i < fields.size(); i++)
+        {
+            TiffOutputField field = (TiffOutputField) fields.get(i);
+            if (field.isLocalValue())
+                continue;
+
+            TiffOutputItem item = field.getSeperateValue();
+            result.add(item);
+            // outputSummary.add(item, field);
+        }
+
+        if (null != imageDataInfo)
+        {
+            for (int i = 0; i < imageDataInfo.outputItems.length; i++)
+                result.add(imageDataInfo.outputItems[i]);
+
+            outputSummary.addTiffImageData(imageDataInfo);
+        }
+
+        if (null != jpegImageData)
+        {
+            TiffOutputItem item = new TiffOutputItem.Value("JPEG image data",
+                    jpegImageData.data);
+            result.add(item);
+            outputSummary.add(item, jpegOffsetField);
+        }
 
-		return result;
-	}
+        return result;
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputField.java Fri Sep 10 16:33:35 2010
@@ -26,187 +26,187 @@ import org.apache.sanselan.formats.tiff.
 
 public class TiffOutputField implements TiffConstants
 {
-	public final int tag;
-	public final TagInfo tagInfo;
-	public final FieldType fieldType;
-	public final int count;
-
-	private byte bytes[];
-
-	private final TiffOutputItem.Value separateValueItem;
-
-	public TiffOutputField(TagInfo tagInfo, FieldType tagtype, int count,
-			byte bytes[])
-	{
-		this(tagInfo.tag, tagInfo, tagtype, count, bytes);
-	}
-
-	public TiffOutputField(final int tag, TagInfo tagInfo, FieldType fieldType,
-			int count, byte bytes[])
-	{
-		this.tag = tag;
-		this.tagInfo = tagInfo;
-		this.fieldType = fieldType;
-		this.count = count;
-		this.bytes = bytes;
-
-		if (isLocalValue())
-			separateValueItem = null;
-		else
-		{
-			String name = "Field Seperate value (" + tagInfo.getDescription()
-					+ ")";
-			separateValueItem = new TiffOutputItem.Value(name, bytes);
-		}
-	}
-
-	private int sortHint = -1;
-
-	public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
-			Number number) throws ImageWriteException
-	{
-		if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
-			throw new ImageWriteException("Tag has no default data type.");
-		FieldType fieldType = tagInfo.dataTypes[0];
-
-		if (tagInfo.length != 1)
-			throw new ImageWriteException("Tag does not expect a single value.");
-
-		byte bytes[] = fieldType.writeData(number, byteOrder);
-
-		return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
-	}
-
-	public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
-			Number value[]) throws ImageWriteException
-	{
-		if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
-			throw new ImageWriteException("Tag has no default data type.");
-		FieldType fieldType = tagInfo.dataTypes[0];
-
-		if (tagInfo.length != value.length)
-			throw new ImageWriteException("Tag does not expect a single value.");
-
-		byte bytes[] = fieldType.writeData(value, byteOrder);
-
-		return new TiffOutputField(tagInfo.tag, tagInfo, fieldType,
-				value.length, bytes);
-	}
-
-	public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
-			String value) throws ImageWriteException
-	{
-		FieldType fieldType;
-		if (tagInfo.dataTypes == null)
-			fieldType = FIELD_TYPE_ASCII;
-		else if (tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII)
-			fieldType = FIELD_TYPE_ASCII;
-		else
-			throw new ImageWriteException("Tag has unexpected data type.");
-
-		byte bytes[] = fieldType.writeData(value, byteOrder);
-
-		return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
-	}
-
-	protected static final TiffOutputField createOffsetField(TagInfo tagInfo,
-			int byteOrder) throws ImageWriteException
-	{
-		return new TiffOutputField(tagInfo, FIELD_TYPE_LONG, 1, FIELD_TYPE_LONG
-				.writeData(new int[] { 0, }, byteOrder));
-	}
-
-	protected void writeField(BinaryOutputStream bos) throws IOException,
-			ImageWriteException
-	{
-		bos.write2Bytes(tag);
-		bos.write2Bytes(fieldType.type);
-		bos.write4Bytes(count);
-
-		if (isLocalValue())
-		{
-			if (separateValueItem != null)
-				throw new ImageWriteException("Unexpected separate value item.");
-			if (bytes.length > 4)
-				throw new ImageWriteException(
-						"Local value has invalid length: " + bytes.length);
-
-			bos.writeByteArray(bytes);
-			int remainder = TIFF_ENTRY_MAX_VALUE_LENGTH - bytes.length;
-			for (int i = 0; i < remainder; i++)
-				bos.write(0);
-		} else
-		{
-			if (separateValueItem == null)
-				throw new ImageWriteException("Missing separate value item.");
-
-			bos.write4Bytes(separateValueItem.getOffset());
-		}
-	}
-
-	protected TiffOutputItem getSeperateValue()
-	{
-		return separateValueItem;
-	}
-
-	protected boolean isLocalValue()
-	{
-		return bytes.length <= TIFF_ENTRY_MAX_VALUE_LENGTH;
-	}
-
-	protected void setData(byte bytes[]) throws ImageWriteException
-	{
-		// if(tagInfo.isUnknown())
-		// Debug.debug("unknown tag(0x" + Integer.toHexString(tag)
-		// + ") setData", bytes);
-
-		if (this.bytes.length != bytes.length)
-			throw new ImageWriteException("Cannot change size of value.");
-
-		// boolean wasLocalValue = isLocalValue();
-		this.bytes = bytes;
-		if (separateValueItem != null)
-			separateValueItem.updateValue(bytes);
-		// if (isLocalValue() != wasLocalValue)
-		// throw new Error("Bug. Locality disrupted! "
-		// + tagInfo.getDescription());
-	}
-
-	private static final String newline = System.getProperty("line.separator");
-
-	public String toString()
-	{
-		return toString(null);
-	}
-
-	public String toString(String prefix)
-	{
-		if (prefix == null)
-			prefix = "";
-		StringBuffer result = new StringBuffer();
-
-		result.append(prefix);
-		result.append(tagInfo);
-		result.append(newline);
-
-		result.append(prefix);
-		result.append("count: " + count);
-		result.append(newline);
-
-		result.append(prefix);
-		result.append(fieldType);
-		result.append(newline);
-
-		return result.toString();
-	}
-
-	public int getSortHint()
-	{
-		return sortHint;
-	}
-
-	public void setSortHint(int sortHint)
-	{
-		this.sortHint = sortHint;
-	}
+    public final int tag;
+    public final TagInfo tagInfo;
+    public final FieldType fieldType;
+    public final int count;
+
+    private byte bytes[];
+
+    private final TiffOutputItem.Value separateValueItem;
+
+    public TiffOutputField(TagInfo tagInfo, FieldType tagtype, int count,
+            byte bytes[])
+    {
+        this(tagInfo.tag, tagInfo, tagtype, count, bytes);
+    }
+
+    public TiffOutputField(final int tag, TagInfo tagInfo, FieldType fieldType,
+            int count, byte bytes[])
+    {
+        this.tag = tag;
+        this.tagInfo = tagInfo;
+        this.fieldType = fieldType;
+        this.count = count;
+        this.bytes = bytes;
+
+        if (isLocalValue())
+            separateValueItem = null;
+        else
+        {
+            String name = "Field Seperate value (" + tagInfo.getDescription()
+                    + ")";
+            separateValueItem = new TiffOutputItem.Value(name, bytes);
+        }
+    }
+
+    private int sortHint = -1;
+
+    public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
+            Number number) throws ImageWriteException
+    {
+        if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
+            throw new ImageWriteException("Tag has no default data type.");
+        FieldType fieldType = tagInfo.dataTypes[0];
+
+        if (tagInfo.length != 1)
+            throw new ImageWriteException("Tag does not expect a single value.");
+
+        byte bytes[] = fieldType.writeData(number, byteOrder);
+
+        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
+    }
+
+    public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
+            Number value[]) throws ImageWriteException
+    {
+        if (tagInfo.dataTypes == null || tagInfo.dataTypes.length < 1)
+            throw new ImageWriteException("Tag has no default data type.");
+        FieldType fieldType = tagInfo.dataTypes[0];
+
+        if (tagInfo.length != value.length)
+            throw new ImageWriteException("Tag does not expect a single value.");
+
+        byte bytes[] = fieldType.writeData(value, byteOrder);
+
+        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType,
+                value.length, bytes);
+    }
+
+    public static TiffOutputField create(TagInfo tagInfo, int byteOrder,
+            String value) throws ImageWriteException
+    {
+        FieldType fieldType;
+        if (tagInfo.dataTypes == null)
+            fieldType = FIELD_TYPE_ASCII;
+        else if (tagInfo.dataTypes == FIELD_TYPE_DESCRIPTION_ASCII)
+            fieldType = FIELD_TYPE_ASCII;
+        else
+            throw new ImageWriteException("Tag has unexpected data type.");
+
+        byte bytes[] = fieldType.writeData(value, byteOrder);
+
+        return new TiffOutputField(tagInfo.tag, tagInfo, fieldType, 1, bytes);
+    }
+
+    protected static final TiffOutputField createOffsetField(TagInfo tagInfo,
+            int byteOrder) throws ImageWriteException
+    {
+        return new TiffOutputField(tagInfo, FIELD_TYPE_LONG, 1, FIELD_TYPE_LONG
+                .writeData(new int[] { 0, }, byteOrder));
+    }
+
+    protected void writeField(BinaryOutputStream bos) throws IOException,
+            ImageWriteException
+    {
+        bos.write2Bytes(tag);
+        bos.write2Bytes(fieldType.type);
+        bos.write4Bytes(count);
+
+        if (isLocalValue())
+        {
+            if (separateValueItem != null)
+                throw new ImageWriteException("Unexpected separate value item.");
+            if (bytes.length > 4)
+                throw new ImageWriteException(
+                        "Local value has invalid length: " + bytes.length);
+
+            bos.writeByteArray(bytes);
+            int remainder = TIFF_ENTRY_MAX_VALUE_LENGTH - bytes.length;
+            for (int i = 0; i < remainder; i++)
+                bos.write(0);
+        } else
+        {
+            if (separateValueItem == null)
+                throw new ImageWriteException("Missing separate value item.");
+
+            bos.write4Bytes(separateValueItem.getOffset());
+        }
+    }
+
+    protected TiffOutputItem getSeperateValue()
+    {
+        return separateValueItem;
+    }
+
+    protected boolean isLocalValue()
+    {
+        return bytes.length <= TIFF_ENTRY_MAX_VALUE_LENGTH;
+    }
+
+    protected void setData(byte bytes[]) throws ImageWriteException
+    {
+        // if(tagInfo.isUnknown())
+        // Debug.debug("unknown tag(0x" + Integer.toHexString(tag)
+        // + ") setData", bytes);
+
+        if (this.bytes.length != bytes.length)
+            throw new ImageWriteException("Cannot change size of value.");
+
+        // boolean wasLocalValue = isLocalValue();
+        this.bytes = bytes;
+        if (separateValueItem != null)
+            separateValueItem.updateValue(bytes);
+        // if (isLocalValue() != wasLocalValue)
+        // throw new Error("Bug. Locality disrupted! "
+        // + tagInfo.getDescription());
+    }
+
+    private static final String newline = System.getProperty("line.separator");
+
+    public String toString()
+    {
+        return toString(null);
+    }
+
+    public String toString(String prefix)
+    {
+        if (prefix == null)
+            prefix = "";
+        StringBuffer result = new StringBuffer();
+
+        result.append(prefix);
+        result.append(tagInfo);
+        result.append(newline);
+
+        result.append(prefix);
+        result.append("count: " + count);
+        result.append(newline);
+
+        result.append(prefix);
+        result.append(fieldType);
+        result.append(newline);
+
+        return result.toString();
+    }
+
+    public int getSortHint()
+    {
+        return sortHint;
+    }
+
+    public void setSortHint(int sortHint)
+    {
+        this.sortHint = sortHint;
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputItem.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputItem.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputItem.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputItem.java Fri Sep 10 16:33:35 2010
@@ -24,60 +24,60 @@ import org.apache.sanselan.formats.tiff.
 
 abstract class TiffOutputItem implements AllTagConstants
 {
-	public static final int UNDEFINED_VALUE = -1;
+    public static final int UNDEFINED_VALUE = -1;
 
-	private int offset = UNDEFINED_VALUE;
+    private int offset = UNDEFINED_VALUE;
 
-	protected int getOffset()
-	{
-		return offset;
-	}
-
-	protected void setOffset(int offset)
-	{
-		this.offset = offset;
-	}
-
-	public abstract int getItemLength();
-
-	public abstract String getItemDescription();
-
-	public abstract void writeItem(BinaryOutputStream bos) throws IOException,
-			ImageWriteException;
-
-	public static class Value extends TiffOutputItem
-	{
-		private final byte bytes[];
-		private final String name;
-
-		public Value(final String name, final byte[] bytes)
-		{
-			this.name = name;
-			this.bytes = bytes;
-		}
-
-		public int getItemLength()
-		{
-			return bytes.length;
-		}
-
-		public String getItemDescription()
-		{
-			return name;
-		}
-
-		public void updateValue(byte bytes[]) throws ImageWriteException
-		{
-			if (this.bytes.length != bytes.length)
-				throw new ImageWriteException("Updated data size mismatch: "
-						+ this.bytes.length + " vs. " + bytes.length);
-			System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
-		}
-
-		public void writeItem(BinaryOutputStream bos) throws IOException,
-				ImageWriteException
-		{
-			bos.write(bytes);
-		}
-	}
+    protected int getOffset()
+    {
+        return offset;
+    }
+
+    protected void setOffset(int offset)
+    {
+        this.offset = offset;
+    }
+
+    public abstract int getItemLength();
+
+    public abstract String getItemDescription();
+
+    public abstract void writeItem(BinaryOutputStream bos) throws IOException,
+            ImageWriteException;
+
+    public static class Value extends TiffOutputItem
+    {
+        private final byte bytes[];
+        private final String name;
+
+        public Value(final String name, final byte[] bytes)
+        {
+            this.name = name;
+            this.bytes = bytes;
+        }
+
+        public int getItemLength()
+        {
+            return bytes.length;
+        }
+
+        public String getItemDescription()
+        {
+            return name;
+        }
+
+        public void updateValue(byte bytes[]) throws ImageWriteException
+        {
+            if (this.bytes.length != bytes.length)
+                throw new ImageWriteException("Updated data size mismatch: "
+                        + this.bytes.length + " vs. " + bytes.length);
+            System.arraycopy(bytes, 0, this.bytes, 0, bytes.length);
+        }
+
+        public void writeItem(BinaryOutputStream bos) throws IOException,
+                ImageWriteException
+        {
+            bos.write(bytes);
+        }
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSet.java Fri Sep 10 16:33:35 2010
@@ -26,308 +26,308 @@ import org.apache.sanselan.util.Debug;
 
 public final class TiffOutputSet implements TiffConstants
 {
-	public final int byteOrder;
-	private final ArrayList directories = new ArrayList();
+    public final int byteOrder;
+    private final ArrayList directories = new ArrayList();
 
-	public TiffOutputSet()
-	{
-		this(TiffConstants.DEFAULT_TIFF_BYTE_ORDER);
-	}
-
-	public TiffOutputSet(final int byteOrder)
-	{
-		super();
-		this.byteOrder = byteOrder;
-	}
-
-	protected List getOutputItems(TiffOutputSummary outputSummary)
-			throws ImageWriteException
-	{
-		List result = new ArrayList();
-
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffOutputDirectory directory = (TiffOutputDirectory) directories
-					.get(i);
-
-			result.addAll(directory.getOutputItems(outputSummary));
-		}
-
-		return result;
-	}
-
-	public void addDirectory(TiffOutputDirectory directory)
-			throws ImageWriteException
-	{
-		if (null != findDirectory(directory.type))
-			throw new ImageWriteException(
-					"Output set already contains a directory of that type.");
-		directories.add(directory);
-	}
-
-	public List getDirectories()
-	{
-		return new ArrayList(directories);
-	}
-
-	public TiffOutputDirectory getRootDirectory()
-	{
-		return findDirectory(DIRECTORY_TYPE_ROOT);
-	}
-
-	public TiffOutputDirectory getExifDirectory()
-	{
-		return findDirectory(DIRECTORY_TYPE_EXIF);
-	}
-
-	public TiffOutputDirectory getOrCreateRootDirectory()
-			throws ImageWriteException
-	{
-		TiffOutputDirectory result = findDirectory(DIRECTORY_TYPE_ROOT);
-		if (null != result)
-			return result;
-		return addRootDirectory();
-	}
-
-	public TiffOutputDirectory getOrCreateExifDirectory()
-			throws ImageWriteException
-	{
-		// EXIF directory requires root directory.
-		getOrCreateRootDirectory();
-
-		TiffOutputDirectory result = findDirectory(DIRECTORY_TYPE_EXIF);
-		if (null != result)
-			return result;
-		return addExifDirectory();
-	}
-
-	public TiffOutputDirectory getOrCreateGPSDirectory()
-			throws ImageWriteException
-	{
-		// GPS directory requires EXIF directory
-		getOrCreateExifDirectory();
-
-		TiffOutputDirectory result = findDirectory(DIRECTORY_TYPE_GPS);
-		if (null != result)
-			return result;
-		return addGPSDirectory();
-	}
-
-	public TiffOutputDirectory getGPSDirectory()
-	{
-		return findDirectory(DIRECTORY_TYPE_GPS);
-	}
-
-	public TiffOutputDirectory getInteroperabilityDirectory()
-	{
-		return findDirectory(DIRECTORY_TYPE_INTEROPERABILITY);
-	}
-
-	public TiffOutputDirectory findDirectory(int directoryType)
-	{
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffOutputDirectory directory = (TiffOutputDirectory) directories
-					.get(i);
-			if (directory.type == directoryType)
-				return directory;
-		}
-		return null;
-	}
-
-	/**
-	 * A convenience method to update GPS values in EXIF metadata.
-	 * 
-	 * @param longitude Longitude in degrees E, negative values are W.
-	 * @param latitude latitude in degrees N, negative values are S.
-	 * @throws ImageWriteException
-	 */
-	public void setGPSInDegrees(double longitude, double latitude)
-			throws ImageWriteException
-	{
-		TiffOutputDirectory gpsDirectory = getOrCreateGPSDirectory();
-
-		String longitudeRef = longitude < 0 ? "W" : "E";
-		longitude = Math.abs(longitude);
-		String latitudeRef = latitude < 0 ? "S" : "N";
-		latitude = Math.abs(latitude);
-
-		{
-			TiffOutputField longitudeRefField = TiffOutputField.create(
-					TiffConstants.GPS_TAG_GPS_LONGITUDE_REF, byteOrder,
-					longitudeRef);
-			gpsDirectory.removeField(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
-			gpsDirectory.add(longitudeRefField);
-		}
-
-		{
-			TiffOutputField latitudeRefField = TiffOutputField.create(
-					TiffConstants.GPS_TAG_GPS_LATITUDE_REF, byteOrder,
-					latitudeRef);
-			gpsDirectory.removeField(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
-			gpsDirectory.add(latitudeRefField);
-		}
-
-		{
-			double value = longitude;
-			double longitudeDegrees = (long) value;
-			value %= 1;
-			value *= 60.0;
-			double longitudeMinutes = (long) value;
-			value %= 1;
-			value *= 60.0;
-			double longitudeSeconds = value;
-			Double values[] = {
-					new Double(longitudeDegrees), new Double(longitudeMinutes),
-					new Double(longitudeSeconds),
-			};
-
-			TiffOutputField longitudeField = TiffOutputField.create(
-					TiffConstants.GPS_TAG_GPS_LONGITUDE, byteOrder, values);
-			gpsDirectory.removeField(TiffConstants.GPS_TAG_GPS_LONGITUDE);
-			gpsDirectory.add(longitudeField);
-		}
-
-		{
-			double value = latitude;
-			double latitudeDegrees = (long) value;
-			value %= 1;
-			value *= 60.0;
-			double latitudeMinutes = (long) value;
-			value %= 1;
-			value *= 60.0;
-			double latitudeSeconds = value;
-			Double values[] = {
-					new Double(latitudeDegrees), new Double(latitudeMinutes),
-					new Double(latitudeSeconds),
-			};
-
-			TiffOutputField latitudeField = TiffOutputField.create(
-					TiffConstants.GPS_TAG_GPS_LATITUDE, byteOrder, values);
-			gpsDirectory.removeField(TiffConstants.GPS_TAG_GPS_LATITUDE);
-			gpsDirectory.add(latitudeField);
-		}
-
-	}
-
-	public void removeField(TagInfo tagInfo)
-	{
-		removeField(tagInfo.tag);
-	}
-
-	public void removeField(int tag)
-	{
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffOutputDirectory directory = (TiffOutputDirectory) directories
-					.get(i);
-			directory.removeField(tag);
-		}
-	}
-
-	public TiffOutputField findField(TagInfo tagInfo)
-	{
-		return findField(tagInfo.tag);
-	}
-
-	public TiffOutputField findField(int tag)
-	{
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffOutputDirectory directory = (TiffOutputDirectory) directories
-					.get(i);
-			TiffOutputField field = directory.findField(tag);
-			if (null != field)
-				return field;
-		}
-		return null;
-	}
-
-	public TiffOutputDirectory addRootDirectory() throws ImageWriteException
-	{
-		TiffOutputDirectory result = new TiffOutputDirectory(
-				DIRECTORY_TYPE_ROOT);
-		addDirectory(result);
-		return result;
-	}
-
-	public TiffOutputDirectory addExifDirectory() throws ImageWriteException
-	{
-		TiffOutputDirectory result = new TiffOutputDirectory(
-				DIRECTORY_TYPE_EXIF);
-		addDirectory(result);
-		return result;
-	}
-
-	public TiffOutputDirectory addGPSDirectory() throws ImageWriteException
-	{
-		TiffOutputDirectory result = new TiffOutputDirectory(DIRECTORY_TYPE_GPS);
-		addDirectory(result);
-		return result;
-	}
-
-	public TiffOutputDirectory addInteroperabilityDirectory()
-			throws ImageWriteException
-	{
-		getOrCreateExifDirectory();
-
-		TiffOutputDirectory result = new TiffOutputDirectory(
-				DIRECTORY_TYPE_INTEROPERABILITY);
-		addDirectory(result);
-		return result;
-	}
-
-	private static final String newline = System.getProperty("line.separator");
-
-	public String toString()
-	{
-		return toString(null);
-	}
-
-	public String toString(String prefix)
-	{
-		if (prefix == null)
-			prefix = "";
-
-		StringBuffer result = new StringBuffer();
-
-		result.append(prefix);
-		result.append("TiffOutputSet {");
-		result.append(newline);
-
-		result.append(prefix);
-		result.append("byteOrder: " + byteOrder);
-		result.append(newline);
-
-		for (int i = 0; i < directories.size(); i++)
-		{
-			TiffOutputDirectory directory = (TiffOutputDirectory) directories
-					.get(i);
-			result.append(prefix);
-			result.append("\t" + "directory " + i + ": "
-					+ directory.description() + " (" + directory.type + ")");
-			result.append(newline);
-
-			ArrayList fields = directory.getFields();
-			for (int j = 0; j < fields.size(); j++)
-			{
-				TiffOutputField field = (TiffOutputField) fields.get(j);
-				result.append(prefix);
-				result.append("\t\t" + "field " + i + ": " + field.tagInfo);
-				result.append(newline);
-			}
-		}
-
-		result.append(prefix);
-		result.append("}");
-		result.append(newline);
-
-		return result.toString();
-	}
-
-	public void dump()
-	{
-		Debug.debug(this.toString());
-	}
+    public TiffOutputSet()
+    {
+        this(TiffConstants.DEFAULT_TIFF_BYTE_ORDER);
+    }
+
+    public TiffOutputSet(final int byteOrder)
+    {
+        super();
+        this.byteOrder = byteOrder;
+    }
+
+    protected List getOutputItems(TiffOutputSummary outputSummary)
+            throws ImageWriteException
+    {
+        List result = new ArrayList();
+
+        for (int i = 0; i < directories.size(); i++)
+        {
+            TiffOutputDirectory directory = (TiffOutputDirectory) directories
+                    .get(i);
+
+            result.addAll(directory.getOutputItems(outputSummary));
+        }
+
+        return result;
+    }
+
+    public void addDirectory(TiffOutputDirectory directory)
+            throws ImageWriteException
+    {
+        if (null != findDirectory(directory.type))
+            throw new ImageWriteException(
+                    "Output set already contains a directory of that type.");
+        directories.add(directory);
+    }
+
+    public List getDirectories()
+    {
+        return new ArrayList(directories);
+    }
+
+    public TiffOutputDirectory getRootDirectory()
+    {
+        return findDirectory(DIRECTORY_TYPE_ROOT);
+    }
+
+    public TiffOutputDirectory getExifDirectory()
+    {
+        return findDirectory(DIRECTORY_TYPE_EXIF);
+    }
+
+    public TiffOutputDirectory getOrCreateRootDirectory()
+            throws ImageWriteException
+    {
+        TiffOutputDirectory result = findDirectory(DIRECTORY_TYPE_ROOT);
+        if (null != result)
+            return result;
+        return addRootDirectory();
+    }
+
+    public TiffOutputDirectory getOrCreateExifDirectory()
+            throws ImageWriteException
+    {
+        // EXIF directory requires root directory.
+        getOrCreateRootDirectory();
+
+        TiffOutputDirectory result = findDirectory(DIRECTORY_TYPE_EXIF);
+        if (null != result)
+            return result;
+        return addExifDirectory();
+    }
+
+    public TiffOutputDirectory getOrCreateGPSDirectory()
+            throws ImageWriteException
+    {
+        // GPS directory requires EXIF directory
+        getOrCreateExifDirectory();
+
+        TiffOutputDirectory result = findDirectory(DIRECTORY_TYPE_GPS);
+        if (null != result)
+            return result;
+        return addGPSDirectory();
+    }
+
+    public TiffOutputDirectory getGPSDirectory()
+    {
+        return findDirectory(DIRECTORY_TYPE_GPS);
+    }
+
+    public TiffOutputDirectory getInteroperabilityDirectory()
+    {
+        return findDirectory(DIRECTORY_TYPE_INTEROPERABILITY);
+    }
+
+    public TiffOutputDirectory findDirectory(int directoryType)
+    {
+        for (int i = 0; i < directories.size(); i++)
+        {
+            TiffOutputDirectory directory = (TiffOutputDirectory) directories
+                    .get(i);
+            if (directory.type == directoryType)
+                return directory;
+        }
+        return null;
+    }
+
+    /**
+     * A convenience method to update GPS values in EXIF metadata.
+     *
+     * @param longitude Longitude in degrees E, negative values are W.
+     * @param latitude latitude in degrees N, negative values are S.
+     * @throws ImageWriteException
+     */
+    public void setGPSInDegrees(double longitude, double latitude)
+            throws ImageWriteException
+    {
+        TiffOutputDirectory gpsDirectory = getOrCreateGPSDirectory();
+
+        String longitudeRef = longitude < 0 ? "W" : "E";
+        longitude = Math.abs(longitude);
+        String latitudeRef = latitude < 0 ? "S" : "N";
+        latitude = Math.abs(latitude);
+
+        {
+            TiffOutputField longitudeRefField = TiffOutputField.create(
+                    TiffConstants.GPS_TAG_GPS_LONGITUDE_REF, byteOrder,
+                    longitudeRef);
+            gpsDirectory.removeField(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
+            gpsDirectory.add(longitudeRefField);
+        }
+
+        {
+            TiffOutputField latitudeRefField = TiffOutputField.create(
+                    TiffConstants.GPS_TAG_GPS_LATITUDE_REF, byteOrder,
+                    latitudeRef);
+            gpsDirectory.removeField(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
+            gpsDirectory.add(latitudeRefField);
+        }
+
+        {
+            double value = longitude;
+            double longitudeDegrees = (long) value;
+            value %= 1;
+            value *= 60.0;
+            double longitudeMinutes = (long) value;
+            value %= 1;
+            value *= 60.0;
+            double longitudeSeconds = value;
+            Double values[] = {
+                    new Double(longitudeDegrees), new Double(longitudeMinutes),
+                    new Double(longitudeSeconds),
+            };
+
+            TiffOutputField longitudeField = TiffOutputField.create(
+                    TiffConstants.GPS_TAG_GPS_LONGITUDE, byteOrder, values);
+            gpsDirectory.removeField(TiffConstants.GPS_TAG_GPS_LONGITUDE);
+            gpsDirectory.add(longitudeField);
+        }
+
+        {
+            double value = latitude;
+            double latitudeDegrees = (long) value;
+            value %= 1;
+            value *= 60.0;
+            double latitudeMinutes = (long) value;
+            value %= 1;
+            value *= 60.0;
+            double latitudeSeconds = value;
+            Double values[] = {
+                    new Double(latitudeDegrees), new Double(latitudeMinutes),
+                    new Double(latitudeSeconds),
+            };
+
+            TiffOutputField latitudeField = TiffOutputField.create(
+                    TiffConstants.GPS_TAG_GPS_LATITUDE, byteOrder, values);
+            gpsDirectory.removeField(TiffConstants.GPS_TAG_GPS_LATITUDE);
+            gpsDirectory.add(latitudeField);
+        }
+
+    }
+
+    public void removeField(TagInfo tagInfo)
+    {
+        removeField(tagInfo.tag);
+    }
+
+    public void removeField(int tag)
+    {
+        for (int i = 0; i < directories.size(); i++)
+        {
+            TiffOutputDirectory directory = (TiffOutputDirectory) directories
+                    .get(i);
+            directory.removeField(tag);
+        }
+    }
+
+    public TiffOutputField findField(TagInfo tagInfo)
+    {
+        return findField(tagInfo.tag);
+    }
+
+    public TiffOutputField findField(int tag)
+    {
+        for (int i = 0; i < directories.size(); i++)
+        {
+            TiffOutputDirectory directory = (TiffOutputDirectory) directories
+                    .get(i);
+            TiffOutputField field = directory.findField(tag);
+            if (null != field)
+                return field;
+        }
+        return null;
+    }
+
+    public TiffOutputDirectory addRootDirectory() throws ImageWriteException
+    {
+        TiffOutputDirectory result = new TiffOutputDirectory(
+                DIRECTORY_TYPE_ROOT);
+        addDirectory(result);
+        return result;
+    }
+
+    public TiffOutputDirectory addExifDirectory() throws ImageWriteException
+    {
+        TiffOutputDirectory result = new TiffOutputDirectory(
+                DIRECTORY_TYPE_EXIF);
+        addDirectory(result);
+        return result;
+    }
+
+    public TiffOutputDirectory addGPSDirectory() throws ImageWriteException
+    {
+        TiffOutputDirectory result = new TiffOutputDirectory(DIRECTORY_TYPE_GPS);
+        addDirectory(result);
+        return result;
+    }
+
+    public TiffOutputDirectory addInteroperabilityDirectory()
+            throws ImageWriteException
+    {
+        getOrCreateExifDirectory();
+
+        TiffOutputDirectory result = new TiffOutputDirectory(
+                DIRECTORY_TYPE_INTEROPERABILITY);
+        addDirectory(result);
+        return result;
+    }
+
+    private static final String newline = System.getProperty("line.separator");
+
+    public String toString()
+    {
+        return toString(null);
+    }
+
+    public String toString(String prefix)
+    {
+        if (prefix == null)
+            prefix = "";
+
+        StringBuffer result = new StringBuffer();
+
+        result.append(prefix);
+        result.append("TiffOutputSet {");
+        result.append(newline);
+
+        result.append(prefix);
+        result.append("byteOrder: " + byteOrder);
+        result.append(newline);
+
+        for (int i = 0; i < directories.size(); i++)
+        {
+            TiffOutputDirectory directory = (TiffOutputDirectory) directories
+                    .get(i);
+            result.append(prefix);
+            result.append("\t" + "directory " + i + ": "
+                    + directory.description() + " (" + directory.type + ")");
+            result.append(newline);
+
+            ArrayList fields = directory.getFields();
+            for (int j = 0; j < fields.size(); j++)
+            {
+                TiffOutputField field = (TiffOutputField) fields.get(j);
+                result.append(prefix);
+                result.append("\t\t" + "field " + i + ": " + field.tagInfo);
+                result.append(newline);
+            }
+        }
+
+        result.append(prefix);
+        result.append("}");
+        result.append(newline);
+
+        return result.toString();
+    }
+
+    public void dump()
+    {
+        Debug.debug(this.toString());
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffOutputSummary.java Fri Sep 10 16:33:35 2010
@@ -25,73 +25,73 @@ import org.apache.sanselan.formats.tiff.
 
 class TiffOutputSummary implements TiffConstants
 {
-	public final int byteOrder;
-	public final TiffOutputDirectory rootDirectory;
-	public final Map directoryTypeMap;
-
-	public TiffOutputSummary(final int byteOrder,
-			final TiffOutputDirectory rootDirectory, final Map directoryTypeMap)
-	{
-		this.byteOrder = byteOrder;
-		this.rootDirectory = rootDirectory;
-		this.directoryTypeMap = directoryTypeMap;
-	}
-
-	private static class OffsetItem
-	{
-		public final TiffOutputItem item;
-		public final TiffOutputField itemOffsetField;
-
-		public OffsetItem(final TiffOutputItem item,
-				final TiffOutputField itemOffsetField)
-		{
-			super();
-			this.itemOffsetField = itemOffsetField;
-			this.item = item;
-		}
-	}
-
-	private List offsetItems = new ArrayList();
-
-	public void add(final TiffOutputItem item,
-			final TiffOutputField itemOffsetField)
-	{
-		offsetItems.add(new OffsetItem(item, itemOffsetField));
-	}
-
-	public void updateOffsets(int byteOrder) throws ImageWriteException
-	{
-		for (int i = 0; i < offsetItems.size(); i++)
-		{
-			OffsetItem offset = (OffsetItem) offsetItems.get(i);
-
-			byte value[] = FIELD_TYPE_LONG.writeData(new int[]{
-				offset.item.getOffset(),
-			}, byteOrder);
-			offset.itemOffsetField.setData(value);
-		}
-
-		for (int i = 0; i < imageDataItems.size(); i++)
-		{
-			ImageDataOffsets imageDataInfo = (ImageDataOffsets) imageDataItems
-					.get(i);
-
-			for (int j = 0; j < imageDataInfo.outputItems.length; j++)
-			{
-				TiffOutputItem item = imageDataInfo.outputItems[j];
-				imageDataInfo.imageDataOffsets[j] = item.getOffset();
-			}
-
-			imageDataInfo.imageDataOffsetsField.setData(FIELD_TYPE_LONG
-					.writeData(imageDataInfo.imageDataOffsets, byteOrder));
-		}
-	}
-
-	private List imageDataItems = new ArrayList();
-
-	public void addTiffImageData(final ImageDataOffsets imageDataInfo)
-	{
-		imageDataItems.add(imageDataInfo);
-	}
+    public final int byteOrder;
+    public final TiffOutputDirectory rootDirectory;
+    public final Map directoryTypeMap;
+
+    public TiffOutputSummary(final int byteOrder,
+            final TiffOutputDirectory rootDirectory, final Map directoryTypeMap)
+    {
+        this.byteOrder = byteOrder;
+        this.rootDirectory = rootDirectory;
+        this.directoryTypeMap = directoryTypeMap;
+    }
+
+    private static class OffsetItem
+    {
+        public final TiffOutputItem item;
+        public final TiffOutputField itemOffsetField;
+
+        public OffsetItem(final TiffOutputItem item,
+                final TiffOutputField itemOffsetField)
+        {
+            super();
+            this.itemOffsetField = itemOffsetField;
+            this.item = item;
+        }
+    }
+
+    private List offsetItems = new ArrayList();
+
+    public void add(final TiffOutputItem item,
+            final TiffOutputField itemOffsetField)
+    {
+        offsetItems.add(new OffsetItem(item, itemOffsetField));
+    }
+
+    public void updateOffsets(int byteOrder) throws ImageWriteException
+    {
+        for (int i = 0; i < offsetItems.size(); i++)
+        {
+            OffsetItem offset = (OffsetItem) offsetItems.get(i);
+
+            byte value[] = FIELD_TYPE_LONG.writeData(new int[]{
+                offset.item.getOffset(),
+            }, byteOrder);
+            offset.itemOffsetField.setData(value);
+        }
+
+        for (int i = 0; i < imageDataItems.size(); i++)
+        {
+            ImageDataOffsets imageDataInfo = (ImageDataOffsets) imageDataItems
+                    .get(i);
+
+            for (int j = 0; j < imageDataInfo.outputItems.length; j++)
+            {
+                TiffOutputItem item = imageDataInfo.outputItems[j];
+                imageDataInfo.imageDataOffsets[j] = item.getOffset();
+            }
+
+            imageDataInfo.imageDataOffsetsField.setData(FIELD_TYPE_LONG
+                    .writeData(imageDataInfo.imageDataOffsets, byteOrder));
+        }
+    }
+
+    private List imageDataItems = new ArrayList();
+
+    public void addTiffImageData(final ImageDataOffsets imageDataInfo)
+    {
+        imageDataItems.add(imageDataInfo);
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java Fri Sep 10 16:33:35 2010
@@ -23,14 +23,14 @@ import org.apache.sanselan.common.Binary
 
 public abstract class TransparencyFilter extends BinaryFileParser
 {
-	protected final byte bytes[];
+    protected final byte bytes[];
 
-	public TransparencyFilter(byte bytes[])
-	{
-		this.bytes = bytes;
+    public TransparencyFilter(byte bytes[])
+    {
+        this.bytes = bytes;
 
-	}
+    }
 
-	public abstract int filter(int rgb, int index) throws ImageReadException,
-			IOException;
+    public abstract int filter(int rgb, int index) throws ImageReadException,
+            IOException;
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java Fri Sep 10 16:33:35 2010
@@ -23,23 +23,23 @@ import org.apache.sanselan.ImageReadExce
 
 public class TransparencyFilterGrayscale extends TransparencyFilter
 {
-	private final int transparent_color;
+    private final int transparent_color;
 
-	public TransparencyFilterGrayscale(byte bytes[]) throws ImageReadException,
-			IOException
-	{
-		super(bytes);
+    public TransparencyFilterGrayscale(byte bytes[]) throws ImageReadException,
+            IOException
+    {
+        super(bytes);
 
-		ByteArrayInputStream is = new ByteArrayInputStream(bytes);
-		transparent_color = read2Bytes("transparent_color", is,
-				"tRNS: Missing transparent_color");
-	}
+        ByteArrayInputStream is = new ByteArrayInputStream(bytes);
+        transparent_color = read2Bytes("transparent_color", is,
+                "tRNS: Missing transparent_color");
+    }
 
-	public int filter(int rgb, int index) throws ImageReadException,
-			IOException
-	{
-		if (index != transparent_color)
-			return rgb;
-		return 0x00;
-	}
+    public int filter(int rgb, int index) throws ImageReadException,
+            IOException
+    {
+        if (index != transparent_color)
+            return rgb;
+        return 0x00;
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java Fri Sep 10 16:33:35 2010
@@ -23,31 +23,31 @@ import org.apache.sanselan.ImageReadExce
 public class TransparencyFilterIndexedColor extends TransparencyFilter
 {
 
-	public TransparencyFilterIndexedColor(byte bytes[])
-	{
-		super(bytes);
-	}
-
-	int count = 0;
-
-	public int filter(int rgb, int index) throws ImageReadException,
-			IOException
-	{
-		if (index >= bytes.length)
-			return rgb;
-
-		if ((index < 0) || (index > bytes.length))
-			throw new ImageReadException(
-					"TransparencyFilterIndexedColor index: " + index
-							+ ", bytes.length: " + bytes.length);
-
-		int alpha = bytes[index];
-		int result = ((0xff & alpha) << 24) | (0x00ffffff & rgb);
-
-		if ((count < 100) && (index > 0))
-		{
-			count++;
-		}
-		return result;
-	}
+    public TransparencyFilterIndexedColor(byte bytes[])
+    {
+        super(bytes);
+    }
+
+    int count = 0;
+
+    public int filter(int rgb, int index) throws ImageReadException,
+            IOException
+    {
+        if (index >= bytes.length)
+            return rgb;
+
+        if ((index < 0) || (index > bytes.length))
+            throw new ImageReadException(
+                    "TransparencyFilterIndexedColor index: " + index
+                            + ", bytes.length: " + bytes.length);
+
+        int alpha = bytes[index];
+        int result = ((0xff & alpha) << 24) | (0x00ffffff & rgb);
+
+        if ((count < 100) && (index > 0))
+        {
+            count++;
+        }
+        return result;
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java Fri Sep 10 16:33:35 2010
@@ -23,36 +23,36 @@ import org.apache.sanselan.ImageReadExce
 
 public class TransparencyFilterTrueColor extends TransparencyFilter
 {
-	private final int transparent_red;
-	private final int transparent_green;
-	private final int transparent_blue;
-	private final int transparent_color;
-
-	public TransparencyFilterTrueColor(byte bytes[]) throws ImageReadException,
-			IOException
-	{
-		super(bytes);
-
-		ByteArrayInputStream is = new ByteArrayInputStream(bytes);
-		transparent_red = read2Bytes("transparent_red", is,
-				"tRNS: Missing transparent_color");
-		transparent_green = read2Bytes("transparent_green", is,
-				"tRNS: Missing transparent_color");
-		transparent_blue = read2Bytes("transparent_blue", is,
-				"tRNS: Missing transparent_color");
-
-		transparent_color = ((0xff & transparent_red) << 16)
-				| ((0xff & transparent_green) << 8)
-				| ((0xff & transparent_blue) << 0);
-
-	}
-
-	public int filter(int rgb, int sample) throws ImageReadException,
-			IOException
-	{
-		if ((0x00ffffff & rgb) == transparent_color)
-			return 0x00;
+    private final int transparent_red;
+    private final int transparent_green;
+    private final int transparent_blue;
+    private final int transparent_color;
+
+    public TransparencyFilterTrueColor(byte bytes[]) throws ImageReadException,
+            IOException
+    {
+        super(bytes);
+
+        ByteArrayInputStream is = new ByteArrayInputStream(bytes);
+        transparent_red = read2Bytes("transparent_red", is,
+                "tRNS: Missing transparent_color");
+        transparent_green = read2Bytes("transparent_green", is,
+                "tRNS: Missing transparent_color");
+        transparent_blue = read2Bytes("transparent_blue", is,
+                "tRNS: Missing transparent_color");
+
+        transparent_color = ((0xff & transparent_red) << 16)
+                | ((0xff & transparent_green) << 8)
+                | ((0xff & transparent_blue) << 0);
+
+    }
+
+    public int filter(int rgb, int sample) throws ImageReadException,
+            IOException
+    {
+        if ((0x00ffffff & rgb) == transparent_color)
+            return 0x00;
 
-		return rgb;
-	}
+        return rgb;
+    }
 }
\ No newline at end of file