incubator-sanselan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmc...@apache.org
Subject svn commit: r584033 [13/15] - in /incubator/sanselan/trunk: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/sanselan/ src/main/java/org/apache/sanselan/color/ src/main/java/org/apache/sanselan/comm...
Date Fri, 12 Oct 2007 02:53:01 GMT
Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeFloat.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeFloat.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeFloat.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeFloat.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.fieldtypes;
+
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.formats.tiff.TiffField;
+
+public class FieldTypeFloat extends FieldType
+{
+	public FieldTypeFloat()
+	{
+		super(11, 4, "Float");
+	}
+
+	//	= new FieldType(11, 4, "Float")
+
+	public Object getSimpleValue(TiffField entry)
+	{
+		if (entry.length == 1)
+			return new Float(convertByteArrayToFloat(name + " ("
+					+ entry.tagInfo.name + ")", entry.valueOffsetBytes,
+					entry.byteOrder));
+
+		return convertByteArrayToFloatArray(name + " (" + entry.tagInfo.name
+				+ ")", getRawBytes(entry), 0, entry.length, entry.byteOrder);
+	}
+
+	public byte[] writeData(Object o, int byteOrder) throws ImageWriteException
+	{
+		if (o instanceof Float)
+			return convertFloatToByteArray(((Float) o).floatValue(), byteOrder);
+
+		return convertFloatArrayToByteArray((float[]) o, byteOrder);
+	}
+
+	//	public byte[] writeData(Object o, float byteOrder)
+	//	{
+	//		if (o instanceof Float)
+	//			return writeData(new float[]{
+	//				((Float) o).floatValue(),
+	//			}, byteOrder);
+	//
+	//		return writeData((float[]) o, byteOrder);
+	//	}
+	//	
+	//	
+	//	
+	//	public byte[] writeData(float values[], int byteOrder)
+	//	{
+	//		return convertIntArrayToByteArray(values, byteOrder);
+	//	}
+
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeLong.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeLong.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeLong.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeLong.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.fieldtypes;
+
+import org.apache.sanselan.formats.tiff.TiffField;
+
+public class FieldTypeLong extends FieldType
+{
+	public FieldTypeLong(int type, String name)
+	{
+		super(type, 4, name);
+	}
+
+	public Object getSimpleValue(TiffField entry)
+	{
+		if (entry.length == 1)
+			return new Integer(convertByteArrayToInt(name + " ("
+					+ entry.tagInfo.name + ")", entry.valueOffsetBytes,
+					entry.byteOrder));
+
+		return convertByteArrayToIntArray(name + " (" + entry.tagInfo.name
+				+ ")", getRawBytes(entry), 0, entry.length, entry.byteOrder);
+	}
+
+	public byte[] writeData(Object o, int byteOrder)
+	{
+		if (o instanceof Integer)
+			return writeData(new int[]{
+				((Integer) o).intValue(),
+			}, byteOrder);
+
+		return writeData((int[]) o, byteOrder);
+	}
+
+	public byte[] writeData(int values[], int byteOrder)
+	{
+		return convertIntArrayToByteArray(values, byteOrder);
+	}
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeRational.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeRational.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeRational.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeRational.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,64 @@
+/*
+ * 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.fieldtypes;
+
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.common.RationalNumber;
+import org.apache.sanselan.formats.tiff.TiffField;
+
+public class FieldTypeRational extends FieldType
+{
+	public FieldTypeRational(int type, String name)
+	{
+		super(type, 8, name);
+	}
+
+	public Object getSimpleValue(TiffField entry)
+	{
+		if (entry.length == 1)
+			return convertByteArrayToRational(name + " (" + entry.tagInfo.name
+					+ ")", entry.oversizeValue, entry.byteOrder);
+
+		return convertByteArrayToRationalArray(name + " (" + entry.tagInfo.name
+				+ ")", getRawBytes(entry), 0, entry.length, entry.byteOrder);
+	}
+
+	public byte[] writeData(Object o, int byteOrder) throws ImageWriteException
+	{
+		if (o instanceof RationalNumber)
+			return convertRationalToByteArray((RationalNumber) o, byteOrder);
+
+		return convertRationalArrayToByteArray((RationalNumber[]) o, byteOrder);
+	}
+
+	public byte[] writeData(int numerator, int denominator, int byteOrder)
+			throws ImageWriteException
+	{
+		return writeData(new int[]{
+			numerator
+		}, new int[]{
+			denominator
+		}, byteOrder);
+	}
+
+	public byte[] writeData(int numerators[], int denominators[], int byteOrder)
+			throws ImageWriteException
+	{
+		return convertIntArrayToRationalArray(numerators, denominators,
+				byteOrder);
+	}
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeShort.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeShort.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeShort.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeShort.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.fieldtypes;
+
+import org.apache.sanselan.formats.tiff.TiffField;
+
+public class FieldTypeShort extends FieldType
+{
+	public FieldTypeShort(int type, String name)
+	{
+		super(type, 2, name);
+	}
+
+	//	public Object[] getValueArray(TiffField entry)
+	//	{
+	//		if(isLocalValue(entry))
+	//			return convertByteArrayToShortArray(name + " (" + entry.tagInfo.name
+	//					+ ")", entry.valueOffsetBytes, 0, entry.length, entry.byteOrder);
+	//
+	////		return new Integer(convertByteArrayToShort(name + " ("
+	////				+ entry.tagInfo.name + ")", entry.valueOffsetBytes,
+	////				entry.byteOrder));
+	//
+	//		return convertByteArrayToShortArray(name + " (" + entry.tagInfo.name
+	//				+ ")", getRawBytes(entry), 0, entry.length, entry.byteOrder);
+	//	}
+
+	public Object getSimpleValue(TiffField entry)
+	{
+		if (entry.length == 1)
+			return new Integer(convertByteArrayToShort(name + " ("
+					+ entry.tagInfo.name + ")", entry.valueOffsetBytes,
+					entry.byteOrder));
+
+		return convertByteArrayToShortArray(name + " (" + entry.tagInfo.name
+				+ ")", getRawBytes(entry), 0, entry.length, entry.byteOrder);
+	}
+
+	public byte[] writeData(Object o, int byteOrder)
+	{
+		if (o instanceof Integer)
+			return writeData(new int[]{
+				((Integer) o).intValue(),
+			}, byteOrder);
+
+		return writeData((int[]) o, byteOrder);
+	}
+
+	public byte[] writeData(int values[], int byteOrder)
+	{
+		return convertShortArrayToByteArray(values, byteOrder);
+	}
+
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeUnknown.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeUnknown.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeUnknown.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/fieldtypes/FieldTypeUnknown.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sanselan.formats.tiff.fieldtypes;
+
+import org.apache.sanselan.formats.tiff.TiffField;
+
+public class FieldTypeUnknown extends FieldType
+{
+	public FieldTypeUnknown()
+	{
+		super(-1, 1, "Unknown");
+	}
+
+	public Object getSimpleValue(TiffField entry)
+	{
+		if (entry.length == 1)
+			return new Byte(entry.valueOffsetBytes[0]);
+
+		return getRawBytes(entry);
+	}
+
+	public byte[] writeData(Object o, int byteOrder)
+	{
+		if (o instanceof Byte)
+			return new byte[]{
+				((Byte) o).byteValue(),
+			};
+
+		return (byte[]) o;
+	}
+
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreter.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreter.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreter.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreter.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,50 @@
+/*
+ * 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.photometricinterpreters;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+public abstract class PhotometricInterpreter
+{
+	protected final int samplesPerPixel;
+	protected final int bitsPerSample[];
+	protected final int predictor;
+	protected final int width;
+	protected final int height;
+
+	public PhotometricInterpreter(int fSamplesPerPixel, int fBitsPerSample[],
+			int Predictor, int width, int height)
+	{
+		this.samplesPerPixel = fSamplesPerPixel;
+		this.bitsPerSample = fBitsPerSample;
+		this.predictor = Predictor;
+		this.width = width;
+		this.height = height;
+	}
+
+	public abstract void interpretPixel(BufferedImage bi, int samples[], int x,
+			int y) throws ImageReadException, IOException;
+
+	public void dumpstats() throws ImageReadException, IOException
+	{
+
+	}
+
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterBiLevel.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterBiLevel.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterBiLevel.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterBiLevel.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,56 @@
+/*
+ * 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.photometricinterpreters;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+public class PhotometricInterpreterBiLevel extends PhotometricInterpreter
+{
+	private final boolean invert;
+	private final int bitsPerPixel;
+
+	public PhotometricInterpreterBiLevel(int fBitsPerPixel,
+			int fSamplesPerPixel, int fBitsPerSample[], int Predictor,
+			int width, int height, boolean invert)
+	{
+		super(fSamplesPerPixel, fBitsPerSample, Predictor, width, height);
+
+		this.invert = invert;
+		this.bitsPerPixel = fBitsPerPixel;
+	}
+
+	public void interpretPixel(BufferedImage bi, int samples[], int x, int y)
+			throws ImageReadException, IOException
+	{
+		int sample = samples[0];
+
+		if (invert)
+			sample = 255 - sample;
+
+		int red = sample;
+		int green = sample;
+		int blue = sample;
+
+		int alpha = 0xff;
+		int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
+
+		bi.setRGB(x, y, rgb);
+	}
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterCIELAB.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterCIELAB.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterCIELAB.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterCIELAB.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,48 @@
+/*
+ * 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.photometricinterpreters;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.color.ColorConversions;
+
+public class PhotometricInterpreterCIELAB extends PhotometricInterpreter
+{
+	public PhotometricInterpreterCIELAB(int fSamplesPerPixel,
+			int fBitsPerSample[], int Predictor, int width, int height)
+	{
+		super(fSamplesPerPixel, fBitsPerSample, Predictor, width, height);
+	}
+
+	public void dumpstats() throws ImageReadException, IOException
+	{
+	}
+
+	public void interpretPixel(BufferedImage bi, int samples[], int x, int y)
+			throws ImageReadException, IOException
+	{
+		int cieL = samples[0];
+		int cieA = (byte) samples[1];
+		int cieB = (byte) samples[2];
+
+		int rgb = ColorConversions.convertCIELabtoARGBTest(cieL, cieA, cieB);
+		bi.setRGB(x, y, rgb);
+	}
+
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterCMYK.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterCMYK.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterCMYK.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterCMYK.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sanselan.formats.tiff.photometricinterpreters;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.color.ColorConversions;
+
+public class PhotometricInterpreterCMYK extends PhotometricInterpreter
+{
+	public PhotometricInterpreterCMYK(int fSamplesPerPixel,
+			int fBitsPerSample[], int Predictor, int width, int height)
+	{
+		super(fSamplesPerPixel, fBitsPerSample, Predictor, width, height);
+	}
+
+	public void interpretPixel(BufferedImage bi, int samples[], int x, int y)
+			throws ImageReadException, IOException
+	{
+
+		int sc = samples[0];
+		int sm = samples[1];
+		int sy = samples[2];
+		int sk = samples[3];
+
+		int rgb = ColorConversions.convertCMYKtoRGB(sc, sm, sy, sk);
+		bi.setRGB(x, y, rgb);
+	}
+
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterLogLUV.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterLogLUV.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterLogLUV.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterLogLUV.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,154 @@
+/*
+ * 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.photometricinterpreters;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+public class PhotometricInterpreterLogLUV extends PhotometricInterpreter
+{
+	private final boolean yOnly;
+
+	public PhotometricInterpreterLogLUV(int fSamplesPerPixel,
+			int fBitsPerSample[], int Predictor, int width, int height,
+			boolean yonly)
+	{
+		super(fSamplesPerPixel, fBitsPerSample, Predictor, width, height);
+
+		this.yOnly = yonly;
+	}
+
+	public void dumpstats() throws ImageReadException, IOException
+	{
+	}
+
+	private float cube(float f)
+	{
+		return f * f * f;
+	}
+
+	//		private float function_f(float value, )
+
+	public void interpretPixel(BufferedImage bi, int samples[], int x, int y)
+			throws ImageReadException, IOException
+	{
+		float X, Y, Z;
+
+		int cieL = samples[0];
+		int cieA = (byte) samples[1];
+		int cieB = (byte) samples[2];
+
+		{
+
+			float var_Y = (((float) cieL * 100.0f / 255.0f) + 16.0f) / 116.0f;
+			float var_X = cieA / 500.0f + var_Y;
+			float var_Z = var_Y - cieB / 200.0f;
+
+			float var_x_cube = cube(var_X);
+			float var_y_cube = cube(var_Y);
+			float var_z_cube = cube(var_Z);
+
+			if (var_y_cube > 0.008856f)
+				var_Y = var_y_cube;
+			else
+				var_Y = (var_Y - 16 / 116.0f) / 7.787f;
+
+			if (var_x_cube > 0.008856f)
+				var_X = var_x_cube;
+			else
+				var_X = (var_X - 16 / 116.0f) / 7.787f;
+
+			if (var_z_cube > 0.008856f)
+				var_Z = var_z_cube;
+			else
+				var_Z = (var_Z - 16 / 116.0f) / 7.787f;
+
+			float ref_X = 95.047f;
+			float ref_Y = 100.000f;
+			float ref_Z = 108.883f;
+
+			X = ref_X * var_X; //ref_X =  95.047  Observer= 2°, Illuminant= D65
+			Y = ref_Y * var_Y; //ref_Y = 100.000
+			Z = ref_Z * var_Z; //ref_Z = 108.883
+
+		}
+
+		//			ref_X =  95.047        //Observer = 2°, Illuminant = D65
+		//			ref_Y = 100.000
+		//			ref_Z = 108.883
+
+		int R, G, B;
+		{
+			float var_X = X / 100f; //X = From 0 to ref_X
+			float var_Y = Y / 100f; //Y = From 0 to ref_Y
+			float var_Z = Z / 100f; //Z = From 0 to ref_Y
+
+			float var_R = var_X * 3.2406f + var_Y * -1.5372f + var_Z * -0.4986f;
+			float var_G = var_X * -0.9689f + var_Y * 1.8758f + var_Z * 0.0415f;
+			float var_B = var_X * 0.0557f + var_Y * -0.2040f + var_Z * 1.0570f;
+
+			if (var_R > 0.0031308)
+				var_R = 1.055f * (float) Math.pow(var_R, (1 / 2.4)) - 0.055f;
+			else
+				var_R = 12.92f * var_R;
+			if (var_G > 0.0031308)
+				var_G = 1.055f * (float) Math.pow(var_G, (1 / 2.4)) - 0.055f;
+			else
+				var_G = 12.92f * var_G;
+
+			if (var_B > 0.0031308)
+				var_B = 1.055f * (float) Math.pow(var_B, (1 / 2.4)) - 0.055f;
+			else
+				var_B = 12.92f * var_B;
+
+			//				var_R = (((var_R-)))
+			//				updateMaxMin(new float[]{
+			//						var_R, var_G, var_B,
+			//				}, maxVarRGB, minVarRGB);
+
+			//				var_R = ((var_R + 0.16561039f) / (3.0152583f + 0.16561039f));
+			//				var_G = ((var_G + 0.06561642f) / (3.0239854f + 0.06561642f));
+			//				var_B = ((var_B + 0.19393992f) / (3.1043448f + 0.19393992f));
+
+			R = (int) (var_R * 255f);
+			G = (int) (var_G * 255f);
+			B = (int) (var_B * 255f);
+		}
+
+		//			float R = 1.910f * X - 0.532f * Y - 0.288f * Z;
+		//			float G = -0.985f * X + 1.999f * Y - 0.028f * Z;
+		//			float B = 0.058f * X - 0.118f * Y + 0.898f * Z;
+
+		//			updateMaxMin(new float[]{
+		//					R, G, B,
+		//			}, maxRGB, minRGB);
+
+		int red = (int) R;
+		int green = (int) G;
+		int blue = (int) B;
+
+		red = Math.min(255, Math.max(0, red));
+		green = Math.min(255, Math.max(0, green));
+		blue = Math.min(255, Math.max(0, blue));
+		int alpha = 0xff;
+		int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
+		bi.setRGB(x, y, rgb);
+
+	}
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterPalette.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.photometricinterpreters;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+public class PhotometricInterpreterPalette extends PhotometricInterpreter
+{
+	private final int[] fColorMap;
+
+	public PhotometricInterpreterPalette(int fSamplesPerPixel,
+			int fBitsPerSample[], int Predictor, int width, int height,
+			int[] fColorMap)
+	{
+		super(fSamplesPerPixel, fBitsPerSample, Predictor, width, height);
+
+		this.fColorMap = fColorMap;
+	}
+
+	public void interpretPixel(BufferedImage bi, int samples[], int x, int y)
+			throws ImageReadException, IOException
+	{
+		int fBitsPerPixel = bitsPerSample[0];
+		int colormap_scale = (1 << fBitsPerPixel);
+		//			int expected_colormap_size = 3 * (1 << fBitsPerPixel);
+
+		int index = samples[0];
+		int red = fColorMap[index] >> 8;
+		int green = fColorMap[index + (colormap_scale)] >> 8;
+		int blue = fColorMap[index + (2 * colormap_scale)] >> 8;
+
+		int alpha = 0xff;
+		int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
+		bi.setRGB(x, y, rgb);
+
+	}
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterRGB.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterRGB.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterRGB.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterRGB.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.photometricinterpreters;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+public class PhotometricInterpreterRGB extends PhotometricInterpreter
+{
+	public PhotometricInterpreterRGB(int fSamplesPerPixel,
+			int fBitsPerSample[], int Predictor, int width, int height)
+	{
+		super(fSamplesPerPixel, fBitsPerSample, Predictor, width, height);
+	}
+
+	public void interpretPixel(BufferedImage bi, int samples[], int x, int y)
+			throws ImageReadException, IOException
+	{
+		int red = samples[0];
+		int green = samples[1];
+		int blue = samples[2];
+
+		int alpha = 0xff;
+		int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
+		bi.setRGB(x, y, rgb);
+
+	}
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterYCbCr.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterYCbCr.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterYCbCr.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/photometricinterpreters/PhotometricInterpreterYCbCr.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,87 @@
+/*
+ * 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.photometricinterpreters;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+public class PhotometricInterpreterYCbCr extends PhotometricInterpreter
+{
+
+	public PhotometricInterpreterYCbCr(double[] fYCbCrCoefficients,
+			int[] fYCbCrPositioning, int[] fYCbCrSubSampling,
+			double[] fReferenceBlackWhite, int fSamplesPerPixel,
+			int fBitsPerSample[], int Predictor, int width, int height)
+	{
+		super(fSamplesPerPixel, fBitsPerSample, Predictor, width, height);
+	}
+
+	public int limit(int value, int min, int max)
+	{
+		return Math.min(max, Math.max(min, value));
+	}
+
+	/**
+	 * This method converts a YUV (aka YCbCr) colorspace to a RGB colorspace.
+	 * This is handy when trying to reconstruct an image in Java from YCbCr transmitted
+	 * data. This routine expects the data to fall in the standard PC 0..255 range
+	 * per pixel, with the array dimensions corresponding to the imageWidth and imageHeight.
+	 * These variables are either set manually in the case of a null constructor,
+	 * or they are automatically calculated from the image parameter constructor.
+	 * @param Y The Y component set.
+	 * @param Cb The Cb component set.
+	 * @param Cr The Cr component set.
+	 * @return R The R component.
+	 */
+	public int convertYCbCrtoRGB(int Y, int Cb, int Cr)
+	{
+		double r1 = (((1.164 * ((double) Y - 16.0))) + (1.596 * ((double) Cr - 128.0)));
+		double g1 = (((1.164 * ((double) Y - 16.0)))
+				- (0.813 * ((double) Cr - 128.0)) - (0.392 * ((double) Cb - 128.0)));
+		double b1 = (((1.164 * ((double) Y - 16.0))) + (2.017 * ((double) Cb - 128.0)));
+
+		int r = limit((int) r1, 0, 255);
+		int g = limit((int) g1, 0, 255);
+		int b = limit((int) b1, 0, 255);
+
+		int alpha = 0xff;
+		int rgb = (alpha << 24) | (r << 16) | (g << 8) | (b << 0);
+		return rgb;
+	}
+
+	public void interpretPixel(BufferedImage bi, int samples[], int x, int y)
+			throws ImageReadException, IOException
+	{
+		int Y = samples[0];
+		int Cb = samples[1];
+		int Cr = samples[2];
+		double R = Y + 1.402 * (Cr - 128.0);
+		double G = Y - 0.34414 * (Cb - 128.0) - 0.71414 * (Cr - 128.0);
+		double B = Y + 1.772 * (Cb - 128.0);
+
+		int red = limit((int) R, 0, 255);
+		int green = limit((int) G, 0, 255);
+		int blue = limit((int) B, 0, 255);
+
+		int alpha = 0xff;
+		int rgb = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);
+		bi.setRGB(x, y, rgb);
+
+	}
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriter.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriter.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriter.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriter.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,949 @@
+/*
+ * 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;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Hashtable;
+import java.util.Map;
+import java.util.Vector;
+
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.common.BinaryConstants;
+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.TagInfo;
+import org.apache.sanselan.formats.tiff.TiffConstants;
+import org.apache.sanselan.formats.tiff.TiffDirectory;
+import org.apache.sanselan.util.Debug;
+import org.apache.sanselan.util.DebugOutputStream;
+
+public class TiffImageWriter implements TiffConstants, BinaryConstants
+{
+	//	public static final int WRITE_BYTE_ORDER = BYTE_ORDER_INTEL;
+	public static final int DEFAULT_WRITE_BYTE_ORDER = BYTE_ORDER_INTEL;
+
+	private final int byteOrder;
+
+	public TiffImageWriter()
+	{
+		this.byteOrder = DEFAULT_WRITE_BYTE_ORDER;
+	}
+
+	public TiffImageWriter(int byteOrder)
+	{
+		this.byteOrder = byteOrder;
+	}
+
+	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 Hashtable(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);
+
+		//		Vector directoryFields = new Vector();
+
+		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;
+
+		Directory directory = new Directory(TiffDirectory.DIRECTORY_TYPE_ROOT);
+
+		//		WriteField stripOffsetsField;
+
+		{
+			{
+				WriteField field = new WriteField(TIFF_TAG_ImageWidth,
+						FIELD_TYPE_LONG, 1, FIELD_TYPE_LONG.writeData(
+								new int[]{
+									width,
+								}, byteOrder));
+				directory.add(field);
+			}
+			{
+				WriteField field = new WriteField(TIFF_TAG_ImageLength,
+						FIELD_TYPE_LONG, 1, FIELD_TYPE_LONG.writeData(
+								new int[]{
+									height,
+								}, byteOrder));
+				directory.add(field);
+			}
+			{
+				WriteField field = new WriteField(
+						TIFF_TAG_PhotometricInterpretation, FIELD_TYPE_SHORT,
+						1, FIELD_TYPE_SHORT.writeData(new int[]{
+							photometricInterpretation,
+						}, byteOrder));
+				directory.add(field);
+			}
+			{
+				WriteField field = new WriteField(TIFF_TAG_Compression,
+						FIELD_TYPE_SHORT, 1, FIELD_TYPE_SHORT.writeData(
+								new int[]{
+									compression,
+								}, byteOrder));
+				directory.add(field);
+			}
+			{
+				WriteField field = new WriteField(TIFF_TAG_SamplesPerPixel,
+						FIELD_TYPE_SHORT, 1, FIELD_TYPE_SHORT.writeData(
+								new int[]{
+									samplesPerPixel,
+								}, byteOrder));
+				directory.add(field);
+			}
+			{
+				WriteField field = new WriteField(TIFF_TAG_BitsPerSample,
+						FIELD_TYPE_SHORT, 3, FIELD_TYPE_SHORT.writeData(
+								new int[]{
+										bitsPerSample, bitsPerSample,
+										bitsPerSample,
+								}, byteOrder));
+				directory.add(field);
+			}
+			//			{
+			//				stripOffsetsField = new WriteField(TIFF_TAG_StripOffsets,
+			//						FIELD_TYPE_LONG, stripOffsets.length, FIELD_TYPE_LONG
+			//								.writeData(stripOffsets, byteOrder));
+			//				directory.add(stripOffsetsField);
+			//			}
+			//			{
+			//				WriteField field = new WriteField(TIFF_TAG_StripByteCounts,
+			//						FIELD_TYPE_LONG, stripByteCounts.length,
+			//						FIELD_TYPE_LONG.writeData(stripByteCounts,
+			//								WRITE_BYTE_ORDER));
+			//				directory.add(field);
+			//			}
+			{
+				WriteField field = new WriteField(TIFF_TAG_RowsPerStrip,
+						FIELD_TYPE_LONG, 1, FIELD_TYPE_LONG.writeData(
+								new int[]{
+									rowsPerStrip,
+								}, byteOrder));
+				directory.add(field);
+			}
+
+			{
+				int resolutionUnit = 2;// inches.
+				WriteField field = new WriteField(TIFF_TAG_ResolutionUnit,
+						FIELD_TYPE_SHORT, 1, FIELD_TYPE_SHORT.writeData(
+								new int[]{
+									resolutionUnit,
+								}, byteOrder));
+				directory.add(field);
+			}
+
+			{
+				int xResolution = 72;
+				WriteField field = new WriteField(TIFF_TAG_XResolution,
+						FIELD_TYPE_RATIONAL, 1, FIELD_TYPE_RATIONAL.writeData(
+								xResolution, 1, byteOrder));
+				directory.add(field);
+			}
+
+			{
+				int yResolution = 72;
+				WriteField field = new WriteField(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);
+
+		Vector directories = new Vector();
+		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);
+	}
+
+	public static final class Directory
+	{
+		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;
+		public int nextDirectoryOffset = UNDEFINED_VALUE;
+		private final Vector fields = new Vector();
+
+		public Directory(final int type)
+		{
+			this.type = type;
+		}
+
+		public void add(WriteField field)
+		{
+			fields.add(field);
+		}
+
+		public Vector getFields()
+		{
+			return new Vector(fields);
+		}
+
+		public WriteField findField(TagInfo tagInfo)
+		{
+			for (int i = 0; i < fields.size(); i++)
+			{
+				WriteField field = (WriteField) fields.get(i);
+				if (field.tagInfo.tag == tagInfo.tag)
+					return field;
+			}
+			return null;
+		}
+
+		public void sortFields()
+		{
+			Comparator comparator = new Comparator()
+			{
+				public int compare(Object o1, Object o2)
+				{
+					WriteField e1 = (WriteField) o1;
+					WriteField e2 = (WriteField) o2;
+
+					return e1.tagInfo.tag - e2.tagInfo.tag;
+				}
+			};
+			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++)
+			{
+				WriteField field = (WriteField) fields.get(i);
+				totalLength += field.getSeperateValueLength();
+			}
+
+			if (null != imageDataInfo)
+			{
+				int imageDataOffset = offset + totalLength;
+				totalLength += imageDataInfo.totalLength;
+				updateTiffImageDataOffsetsStep(imageDataOffset, byteOrder);
+			}
+
+			if (null != rawJpegImageData)
+			{
+				int imageDataOffset = offset + totalLength;
+				totalLength += rawJpegImageData.length;
+				totalLength += imageDataPaddingLength(rawJpegImageData.length);
+				updateJpegImageDataOffsetsStep(imageDataOffset, byteOrder);
+			}
+
+		}
+
+		public String description()
+		{
+			return TiffDirectory.description(type);
+		}
+
+		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);
+
+			int nextSeperateValueOffset = offset + 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++)
+			{
+				WriteField field = (WriteField) fields.get(i);
+				//				checkOffset("ifd [" + i + "]", fOffsetToSeperateValues);
+				nextSeperateValueOffset += field.writeDirectoryEntry(bos,
+						nextSeperateValueOffset);
+			}
+
+			// Write nextDirectoryOffset
+			if (nextDirectoryOffset == UNDEFINED_VALUE)
+				bos.write4Bytes(0);
+			else
+				bos.write4Bytes(nextDirectoryOffset);
+
+			// Write Seperate Values
+			for (int i = 0; i < fields.size(); i++)
+			{
+				WriteField field = (WriteField) 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 = imageDataPaddingLength(imageDataByteCount);
+					for (int j = 0; j < remainder; j++)
+						bos.write(0);
+				}
+			}
+
+			if (null != rawJpegImageData)
+			{
+				//				byte imageData[][] = rawJpegImageData.getRawImageData();
+				bos.writeByteArray(rawJpegImageData);
+				int remainder = 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;
+			WriteField 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 += imageDataPaddingLength(imageData[i].length);
+			}
+
+			// Append imageData-related fields to first directory
+			{
+				TagInfo tagInfo;
+				if (stripsNotTiles)
+					tagInfo = TIFF_TAG_StripOffsets;
+				else
+					tagInfo = TIFF_TAG_TileOffsets;
+
+				imageDataOffsetsField = findField(tagInfo);
+				if (null == imageDataOffsetsField)
+				{
+					imageDataOffsetsField = new WriteField(tagInfo,
+							FIELD_TYPE_LONG, imageDataOffsets.length,
+							FIELD_TYPE_LONG.writeData(imageDataOffsets,
+									byteOrder));
+					add(imageDataOffsetsField);
+				}
+			}
+			{
+				TagInfo tagInfo;
+				if (stripsNotTiles)
+					tagInfo = TIFF_TAG_StripByteCounts;
+				else
+					tagInfo = TIFF_TAG_TileByteCounts;
+
+				byte data[] = FIELD_TYPE_LONG.writeData(imageDataByteCounts,
+						byteOrder);
+
+				WriteField field = findField(tagInfo);
+				if (null == field)
+					add(new WriteField(tagInfo, FIELD_TYPE_LONG,
+							imageDataByteCounts.length, data));
+				else
+					field.setData(data);
+
+			}
+
+			imageDataInfo = new ImageDataInfo(imageData, imageDataOffsets,
+					imageDataByteCounts, imageDataOffsetsField, totalLength);
+		}
+
+		WriteField jpegImageDataOffsetField = null;
+
+		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_JPEGInterchangeFormat;
+
+				jpegImageDataOffsetField = findField(tagInfo);
+				if (null == jpegImageDataOffsetField)
+				{
+					jpegImageDataOffsetField = new WriteField(tagInfo,
+							FIELD_TYPE_LONG, 1, FIELD_TYPE_LONG.writeData(
+									new int[]{
+										0,
+									}, byteOrder));
+					add(jpegImageDataOffsetField);
+				}
+			}
+			{
+				TagInfo tagInfo = TIFF_TAG_JPEGInterchangeFormatLength;
+
+				byte data[] = FIELD_TYPE_LONG.writeData(new int[]{
+					rawJpegImageData.length,
+				}, byteOrder);
+
+				WriteField field = findField(tagInfo);
+				if (null == field)
+					add(new WriteField(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 += 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)
+		{
+			this.rawTiffImageData = rawTiffImageData;
+		}
+
+		public RawTiffImageData getRawTiffImageData()
+		{
+			return rawTiffImageData;
+		}
+
+		private byte rawJpegImageData[] = null;
+
+		public void setRawJpegImageData(byte rawJpegImageData[])
+		{
+			this.rawJpegImageData = rawJpegImageData;
+		}
+
+		public byte[] getRawJpegImageData()
+		{
+			return rawJpegImageData;
+		}
+
+		//		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;
+		//			}
+		//		};
+	}
+
+	private static int imageDataPaddingLength(int dataLength)
+	{
+		return (4 - (dataLength % 4)) % 4;
+	}
+
+	private Directory findDirectoryByType(Vector directories, int type)
+	{
+		for (int i = 0; i < directories.size(); i++)
+		{
+			Directory directory = (Directory) directories.get(i);
+			if (directory.type == type)
+				return directory;
+		}
+		return null;
+	}
+
+	public void writeDirectories(OutputStream os, Vector directories
+	//			,
+	//			byte imageData[][], boolean stripsNotTiles
+	) 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 static class PointerDirectoriesInfo
+	{
+		public final WriteField exifDirectoryOffsetField;
+		public final Directory exifDirectory;
+		public final WriteField gpsDirectoryOffsetField;
+		public final Directory gpsDirectory;
+		public final WriteField iteroperabilityDirectoryOffsetField;
+		public final Directory iteroperabilityDirectory;
+
+		public PointerDirectoriesInfo(
+				final WriteField exifDirectoryOffsetField,
+				final Directory exifDirectory,
+				final WriteField gpsDirectoryOffsetField,
+				final Directory gpsDirectory,
+				final WriteField iteroperabilityDirectoryOffsetField,
+				final Directory iteroperabilityDirectory)
+		{
+			this.exifDirectoryOffsetField = exifDirectoryOffsetField;
+			this.exifDirectory = exifDirectory;
+			this.gpsDirectoryOffsetField = gpsDirectoryOffsetField;
+			this.gpsDirectory = gpsDirectory;
+			this.iteroperabilityDirectoryOffsetField = iteroperabilityDirectoryOffsetField;
+			this.iteroperabilityDirectory = iteroperabilityDirectory;
+		}
+
+	}
+
+	private PointerDirectoriesInfo pointerDirectoriesStep(Vector directories)
+			throws ImageWriteException
+	{
+		Directory firstDirectory = (Directory) directories.get(0);
+
+		WriteField exifDirectoryOffsetField = null;
+		Directory exifDirectory = findDirectoryByType(directories,
+				TiffDirectory.DIRECTORY_TYPE_EXIF);
+		if (null != exifDirectory)
+		{
+			exifDirectoryOffsetField = firstDirectory
+					.findField(TIFF_TAG_Exif_IFD_Pointer);
+
+			if (null == exifDirectoryOffsetField)
+			{
+				exifDirectoryOffsetField = new WriteField(
+						TIFF_TAG_Exif_IFD_Pointer, FIELD_TYPE_LONG, 1,
+						FIELD_TYPE_LONG.writeData(new int[]{
+							0,
+						}, byteOrder));
+				firstDirectory.add(exifDirectoryOffsetField);
+			}
+		}
+
+		WriteField gpsDirectoryOffsetField = null;
+		Directory gpsDirectory = findDirectoryByType(directories,
+				TiffDirectory.DIRECTORY_TYPE_GPS);
+		if (null != gpsDirectory)
+		{
+			gpsDirectoryOffsetField = firstDirectory
+					.findField(TIFF_TAG_GPSInfo_IFD_Pointer);
+			if (null == gpsDirectoryOffsetField)
+			{
+				gpsDirectoryOffsetField = new WriteField(
+						TIFF_TAG_GPSInfo_IFD_Pointer, FIELD_TYPE_LONG, 1,
+						FIELD_TYPE_LONG.writeData(new int[]{
+							0,
+						}, byteOrder));
+				firstDirectory.add(gpsDirectoryOffsetField);
+			}
+		}
+
+		WriteField iteroperabilityDirectoryOffsetField = null;
+		Directory 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(TIFF_TAG_Interoperability_IFD_Pointer);
+			if (null == iteroperabilityDirectoryOffsetField)
+			{
+				iteroperabilityDirectoryOffsetField = new WriteField(
+						TIFF_TAG_Interoperability_IFD_Pointer, 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 static class ImageDataInfo
+	{
+		public final byte imageData[][];
+		public final int imageDataOffsets[];
+		public final int imageDataByteCounts[];
+		public final WriteField imageDataOffsetsField;
+		public final int totalLength;
+
+		public ImageDataInfo(final byte[][] imageData,
+				final int[] imageDataOffsets, final int[] imageDataByteCounts,
+				final WriteField imageDataOffsetsField, final int totalLength)
+		{
+			this.imageData = imageData;
+			this.imageDataOffsets = imageDataOffsets;
+			this.imageDataByteCounts = imageDataByteCounts;
+			this.imageDataOffsetsField = imageDataOffsetsField;
+			this.totalLength = totalLength;
+		}
+
+	}
+
+	private void calculateLengthsAndOffsetsStep(Vector directories)
+			throws IOException, ImageWriteException
+	//	private int calculateLengthsAndOffsetsStep(Vector directories)
+	{
+		// Calculate lengths and offsets
+		int offset = TIFF_HEADER_SIZE;
+
+		Directory previousDirectory = null;
+		for (int i = 0; i < directories.size(); i++)
+		{
+			Directory directory = (Directory) 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, Vector 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++)
+		{
+			Directory directory = (Directory) 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;
+			}
+		}
+	}
+
+}

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/WriteField.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/WriteField.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/WriteField.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/WriteField.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.sanselan.ImageWriteException;
+import org.apache.sanselan.common.BinaryOutputStream;
+import org.apache.sanselan.formats.tiff.TagInfo;
+import org.apache.sanselan.formats.tiff.fieldtypes.FieldType;
+
+public class WriteField
+{
+	public final TagInfo tagInfo;
+	public final FieldType fieldType;
+	public final int count;
+
+	public byte bytes[];
+
+	public WriteField(TagInfo tag, FieldType tagtype, int count, byte bytes[])
+	{
+		this.tagInfo = tag;
+		this.fieldType = tagtype;
+		this.count = count;
+		this.bytes = bytes;
+	}
+
+	public int writeDirectoryEntry(BinaryOutputStream bos,
+			int seperateValuesOffset) throws ImageWriteException, IOException
+	{
+		bos.write2Bytes(tagInfo.tag);
+		bos.write2Bytes(fieldType.type);
+		bos.write4Bytes(count);
+
+		//		if(fieldType.type == TiffConstants.FIELD_TYPE_ASCII.type)
+		//			Debug.debug("ascii bytes", bytes);
+
+		if (bytes.length <= 4)
+		{
+			bos.writeByteArray(bytes);
+			int remainder = 4 - 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;
+		}
+	}
+
+	public int getSeperateValueLength()
+	{
+		if (bytes.length <= 4)
+			return 0;
+		else
+		{
+			int written = bytes.length;
+			if ((written % 2) != 0)
+				written++;
+
+			return written;
+		}
+	}
+
+	public int writeSeperateValue(BinaryOutputStream bos)
+			throws ImageWriteException, IOException
+	{
+		if (bytes.length <= 4)
+			return 0;
+
+		bos.writeByteArray(bytes);
+
+		int written = bytes.length;
+		if ((written % 2) != 0)
+		{
+			bos.write(0);
+			written++;
+		}
+		return written;
+	}
+
+	public void setData(byte bytes[])
+	{
+		this.bytes = bytes;
+	}
+}
\ No newline at end of file

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

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,36 @@
+/*
+ * 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.transparencyfilters;
+
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+import org.apache.sanselan.common.BinaryFileParser;
+
+public abstract class TransparencyFilter extends BinaryFileParser
+{
+	protected final byte bytes[];
+
+	public TransparencyFilter(byte bytes[])
+	{
+		this.bytes = bytes;
+
+	}
+
+	public abstract int filter(int rgb, int index) throws ImageReadException,
+			IOException;
+}
\ No newline at end of file

Propchange: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,45 @@
+/*
+ * 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.transparencyfilters;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+public class TransparencyFilterGrayscale extends TransparencyFilter
+{
+	private final int transparent_color;
+
+	public TransparencyFilterGrayscale(byte bytes[]) throws ImageReadException,
+			IOException
+	{
+		super(bytes);
+
+		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;
+	}
+}
\ No newline at end of file

Propchange: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterGrayscale.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.transparencyfilters;
+
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+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;
+	}
+}
\ No newline at end of file

Propchange: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterIndexedColor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java?rev=584033&view=auto
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java (added)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java Thu Oct 11 19:52:51 2007
@@ -0,0 +1,58 @@
+/*
+ * 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.transparencyfilters;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+
+import org.apache.sanselan.ImageReadException;
+
+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;
+
+		return rgb;
+	}
+}
\ No newline at end of file

Propchange: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/transparencyfilters/TransparencyFilterTrueColor.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message