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 [20/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/TiffField.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java Fri Sep 10 16:33:35 2010
@@ -34,763 +34,763 @@ import org.apache.sanselan.formats.tiff.
 
 public class TiffField implements TiffConstants
 {
-	public final TagInfo tagInfo;
-	public final FieldType fieldType;
+    public final TagInfo tagInfo;
+    public final FieldType fieldType;
 
-	public final int tag;
-	public final int directoryType;
-	public final int type;
-	public final int length;
-	public final int valueOffset;
-	public final byte valueOffsetBytes[];
-
-	public byte oversizeValue[] = null;
-	public final int byteOrder;
-
-	public TiffField(int tag, int directoryType, int type, int Length,
-			int ValueOffset, byte ValueOffsetBytes[], int byteOrder)
-	{
-
-		this.tag = tag;
-		this.directoryType = directoryType;
-		this.type = type;
-		this.length = Length;
-		this.valueOffset = ValueOffset;
-		this.valueOffsetBytes = ValueOffsetBytes;
-		this.byteOrder = byteOrder;
-
-		fieldType = getFieldType(type);
-		tagInfo = getTag(directoryType, tag);
-	}
-
-	private int sortHint = -1;
-
-	public boolean isLocalValue()
-	{
-		return fieldType.isLocalValue(this);
-	}
-
-	public int getBytesLength() throws ImageReadException
-	{
-		return fieldType.getBytesLength(this);
-	}
-
-	public final class OversizeValueElement extends TiffElement
-	{
-		public OversizeValueElement(int offset, int length)
-		{
-			super(offset, length);
-		}
-
-		public String getElementDescription(boolean verbose)
-		{
-			if (verbose)
-				return null;
-
-			return "OversizeValueElement, tag: " + tagInfo.name
-					+ ", fieldType: " + fieldType.name;
-		}
-	}
-
-	public TiffElement getOversizeValueElement()
-	{
-		if (fieldType.isLocalValue(this))
-			return null;
-
-		return new OversizeValueElement(valueOffset, oversizeValue.length);
-	}
-
-	public void setOversizeValue(byte bytes[])
-	{
-		this.oversizeValue = bytes;
-	}
-
-	private static FieldType getFieldType(int value)
-	{
-		for (int i = 0; i < FIELD_TYPES.length; i++)
-		{
-			FieldType fieldType = FIELD_TYPES[i];
-			if (fieldType.type == value)
-				return fieldType;
-		}
-
-		return FIELD_TYPE_UNKNOWN;
-	}
-
-	private static TagInfo getTag(int directoryType, int tag,
-			List possibleMatches)
-	{
-		if (possibleMatches.size() < 1)
-			return null;
-		// else if (possibleMatches.size() == 1)
-		// {
-		// TagInfo tagInfo = (TagInfo) possibleMatches.get(0);
-		// return tagInfo;
-		// }
-
-		// first search for exact match.
-		for (int i = 0; i < possibleMatches.size(); i++)
-		{
-			TagInfo tagInfo = (TagInfo) possibleMatches.get(i);
-			if (tagInfo.directoryType == EXIF_DIRECTORY_UNKNOWN)
-				// pass
-				continue;
-			else if (directoryType == DIRECTORY_TYPE_EXIF
-					&& tagInfo.directoryType == EXIF_DIRECTORY_EXIF_IFD)
-				return tagInfo;
-			else if (directoryType == DIRECTORY_TYPE_INTEROPERABILITY
-					&& tagInfo.directoryType == EXIF_DIRECTORY_INTEROP_IFD)
-				return tagInfo;
-			else if (directoryType == DIRECTORY_TYPE_GPS
-					&& tagInfo.directoryType == EXIF_DIRECTORY_GPS)
-				return tagInfo;
-			else if (directoryType == DIRECTORY_TYPE_MAKER_NOTES
-					&& tagInfo.directoryType == EXIF_DIRECTORY_MAKER_NOTES)
-				return tagInfo;
-			else if (directoryType == DIRECTORY_TYPE_DIR_0
-					&& tagInfo.directoryType == TIFF_DIRECTORY_IFD0)
-				return tagInfo;
-			else if (directoryType == DIRECTORY_TYPE_DIR_1
-					&& tagInfo.directoryType == TIFF_DIRECTORY_IFD1)
-				return tagInfo;
-			else if (directoryType == DIRECTORY_TYPE_DIR_2
-					&& tagInfo.directoryType == TIFF_DIRECTORY_IFD2)
-				return tagInfo;
-			else if (directoryType == DIRECTORY_TYPE_DIR_3
-					&& tagInfo.directoryType == TIFF_DIRECTORY_IFD3)
-				return tagInfo;
-		}
-
-		// accept an inexact match.
-		for (int i = 0; i < possibleMatches.size(); i++)
-		{
-			TagInfo tagInfo = (TagInfo) possibleMatches.get(i);
-
-			if (tagInfo.directoryType == EXIF_DIRECTORY_UNKNOWN)
-				// pass
-				continue;
-			else if (directoryType >= 0
-					&& tagInfo.directoryType.isImageDirectory())
-				return tagInfo;
-			else if (directoryType < 0
-					&& !tagInfo.directoryType.isImageDirectory())
-				return tagInfo;
-		}
-
-		// accept a wildcard match.
-		for (int i = 0; i < possibleMatches.size(); i++)
-		{
-			TagInfo tagInfo = (TagInfo) possibleMatches.get(i);
-
-			if (tagInfo.directoryType == EXIF_DIRECTORY_UNKNOWN)
-				return tagInfo;
-		}
-
-		// // accept a very rough match.
-		// for (int i = 0; i < possibleMatches.size(); i++)
-		// {
-		// TagInfo tagInfo = (TagInfo) possibleMatches.get(i);
-		// if (tagInfo.exifDirectory == EXIF_DIRECTORY_UNKNOWN)
-		// return tagInfo;
-		// else if (directoryType == DIRECTORY_TYPE_EXIF
-		// && tagInfo.exifDirectory == EXIF_DIRECTORY_EXIF_IFD)
-		// return tagInfo;
-		// else if (directoryType == DIRECTORY_TYPE_INTEROPERABILITY
-		// && tagInfo.exifDirectory == EXIF_DIRECTORY_INTEROP_IFD)
-		// return tagInfo;
-		// else if (directoryType == DIRECTORY_TYPE_GPS
-		// && tagInfo.exifDirectory == EXIF_DIRECTORY_GPS)
-		// return tagInfo;
-		// else if (directoryType == DIRECTORY_TYPE_MAKER_NOTES
-		// && tagInfo.exifDirectory == EXIF_DIRECTORY_MAKER_NOTES)
-		// return tagInfo;
-		// else if (directoryType >= 0
-		// && tagInfo.exifDirectory.isImageDirectory())
-		// return tagInfo;
-		// else if (directoryType < 0
-		// && !tagInfo.exifDirectory.isImageDirectory())
-		// return tagInfo;
-		// }
-
-		return TIFF_TAG_UNKNOWN;
-
-		// if (true)
-		// throw new Error("Why didn't this algorithm work?");
-		//
-		// {
-		// TagInfo tagInfo = (TagInfo) possibleMatches.get(0);
-		// return tagInfo;
-		// }
-
-		// Object key = new Integer(tag);
-		//
-		// if (directoryType == DIRECTORY_TYPE_EXIF
-		// || directoryType == DIRECTORY_TYPE_INTEROPERABILITY)
-		// {
-		// if (EXIF_TAG_MAP.containsKey(key))
-		// return (TagInfo) EXIF_TAG_MAP.get(key);
-		// }
-		// else if (directoryType == DIRECTORY_TYPE_GPS)
-		// {
-		// if (GPS_TAG_MAP.containsKey(key))
-		// return (TagInfo) GPS_TAG_MAP.get(key);
-		// }
-		// else
-		// {
-		// if (TIFF_TAG_MAP.containsKey(key))
-		// return (TagInfo) TIFF_TAG_MAP.get(key);
-		// }
-		//
-		// if (ALL_TAG_MAP.containsKey(key))
-		// return (TagInfo) ALL_TAG_MAP.get(key);
-
-		// public static final int DIRECTORY_TYPE_EXIF = -2;
-		// // public static final int DIRECTORY_TYPE_SUB = 5;
-		// public static final int DIRECTORY_TYPE_GPS = -3;
-		// public static final int DIRECTORY_TYPE_INTEROPERABILITY = -4;
-		//
-		// private static final Map GPS_TAG_MAP = makeTagMap(ALL_GPS_TAGS,
-		// false);
-		// private static final Map TIFF_TAG_MAP = makeTagMap(ALL_TIFF_TAGS,
-		// false);
-		// private static final Map EXIF_TAG_MAP = makeTagMap(ALL_EXIF_TAGS,
-		// false);
-		// private static final Map ALL_TAG_MAP = makeTagMap(ALL_TAGS, true);
-		//
-		// for (int i = 0; i < ALL_TAGS.length; i++)
-		// {
-		// TagInfo2 tag = ALL_TAGS[i];
-		// if (tag.tag == value)
-		// return tag;
-		// }
-
-		// return TIFF_TAG_UNKNOWN;
-	}
-
-	private static TagInfo getTag(int directoryType, int tag)
-	{
-		Object key = new Integer(tag);
-
-		List possibleMatches = (List) EXIF_TAG_MAP.get(key);
-
-		if (null == possibleMatches)
-		{
-			return TIFF_TAG_UNKNOWN;
-		}
-
-		TagInfo result = getTag(directoryType, tag, possibleMatches);
-		return result;
-	}
-
-	private int getValueLengthInBytes()
-	{
-		int unit_length = fieldType.length;
-		int valueLength = unit_length * length;
-
-		// Debug.debug("getValueLengthInBytes unit_length", unit_length);
-		// Debug.debug("getValueLengthInBytes length", length);
-
-		return valueLength;
-	}
-
-	public void fillInValue(ByteSource byteSource) throws ImageReadException,
-			IOException
-	{
-		if (fieldType.isLocalValue(this))
-			return;
-
-		int valueLength = getValueLengthInBytes();
-
-		// Debug.debug("fillInValue tag", tag);
-		// Debug.debug("fillInValue tagInfo", tagInfo);
-		// Debug.debug("fillInValue valueOffset", valueOffset);
-		// Debug.debug("fillInValue valueLength", valueLength);
-
-		byte bytes[] = byteSource.getBlock(valueOffset, valueLength);
-		setOversizeValue(bytes);
-	}
-
-	public String getValueDescription()
-	{
-		try
-		{
-			return getValueDescription(getValue());
-		} catch (ImageReadException e)
-		{
-			return "Invalid value: " + e.getMessage();
-		}
-	}
-
-	private String getValueDescription(Object o)
-	{
-		if (o == null)
-			return null;
-
-		if (o instanceof Number)
-		{
-			return o.toString();
-		} else if (o instanceof String)
-		{
-			return "'" + o.toString().trim() + "'";
-		} else if (o instanceof Date)
-		{
-			DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
-			return df.format((Date) o);
-		} else if (o instanceof Object[])
-		{
-			Object objects[] = (Object[]) o;
-			StringBuffer result = new StringBuffer();
-
-			for (int i = 0; i < objects.length; i++)
-			{
-				Object object = objects[i];
-
-				if (i > 50)
-				{
-					result.append("... (" + objects.length + ")");
-					break;
-				}
-				if (i > 0)
-					result.append(", ");
-				result.append("" + object);
-			}
-			return result.toString();
-		}
-		// else if (o instanceof Number[])
-		// {
-		// Number numbers[] = (Number[]) o;
-		// StringBuffer result = new StringBuffer();
-		//
-		// for (int i = 0; i < numbers.length; i++)
-		// {
-		// Number number = numbers[i];
-		//
-		// if (i > 0)
-		// result.append(", ");
-		// result.append("" + number);
-		// }
-		// return result.toString();
-		// }
-		else if (o instanceof int[])
-		{
-			int values[] = (int[]) o;
-			StringBuffer result = new StringBuffer();
-
-			for (int i = 0; i < values.length; i++)
-			{
-				int value = values[i];
-
-				if (i > 50)
-				{
-					result.append("... (" + values.length + ")");
-					break;
-				}
-				if (i > 0)
-					result.append(", ");
-				result.append("" + value);
-			}
-			return result.toString();
-		} else if (o instanceof long[])
-		{
-			long values[] = (long[]) o;
-			StringBuffer result = new StringBuffer();
-
-			for (int i = 0; i < values.length; i++)
-			{
-				long value = values[i];
-
-				if (i > 50)
-				{
-					result.append("... (" + values.length + ")");
-					break;
-				}
-				if (i > 0)
-					result.append(", ");
-				result.append("" + value);
-			}
-			return result.toString();
-		} else if (o instanceof double[])
-		{
-			double values[] = (double[]) o;
-			StringBuffer result = new StringBuffer();
-
-			for (int i = 0; i < values.length; i++)
-			{
-				double value = values[i];
-
-				if (i > 50)
-				{
-					result.append("... (" + values.length + ")");
-					break;
-				}
-				if (i > 0)
-					result.append(", ");
-				result.append("" + value);
-			}
-			return result.toString();
-		} else if (o instanceof byte[])
-		{
-			byte values[] = (byte[]) o;
-			StringBuffer result = new StringBuffer();
-
-			for (int i = 0; i < values.length; i++)
-			{
-				byte value = values[i];
-
-				if (i > 50)
-				{
-					result.append("... (" + values.length + ")");
-					break;
-				}
-				if (i > 0)
-					result.append(", ");
-				result.append("" + value);
-			}
-			return result.toString();
-		} else if (o instanceof char[])
-		{
-			char values[] = (char[]) o;
-			StringBuffer result = new StringBuffer();
-
-			for (int i = 0; i < values.length; i++)
-			{
-				char value = values[i];
-
-				if (i > 50)
-				{
-					result.append("... (" + values.length + ")");
-					break;
-				}
-				if (i > 0)
-					result.append(", ");
-				result.append("" + value);
-			}
-			return result.toString();
-		} else if (o instanceof float[])
-		{
-			float values[] = (float[]) o;
-			StringBuffer result = new StringBuffer();
-
-			for (int i = 0; i < values.length; i++)
-			{
-				float value = values[i];
-
-				if (i > 50)
-				{
-					result.append("... (" + values.length + ")");
-					break;
-				}
-				if (i > 0)
-					result.append(", ");
-				result.append("" + value);
-			}
-			return result.toString();
-		}
-		// else if (o instanceof short[])
-		// {
-		// short numbers[] = (short[]) o;
-		// StringBuffer result = new StringBuffer();
-		//
-		// for (int i = 0; i < numbers.length; i++)
-		// {
-		// short number = numbers[i];
-		//
-		// if (i > 0)
-		// result.append(", ");
-		// result.append("" + number);
-		// }
-		// return result.toString();
-		// }
-
-		return "Unknown: " + o.getClass().getName();
-	}
-
-	public void dump()
-	{
-		PrintWriter pw = new PrintWriter(System.out);
-		dump(pw);
-		pw.flush();
-	}
-
-	public void dump(PrintWriter pw)
-	{
-		dump(pw, null);
-	}
-
-	public void dump(PrintWriter pw, String prefix)
-	{
-		if (prefix != null)
-			pw.print(prefix + ": ");
-
-		pw.println(toString());
-		pw.flush();
-	}
-
-	// private void errorDump()
-	// {
-	// Debug.debug("tagInfo", tagInfo);
-	// Debug.debug("fieldType", fieldType);
-	// Debug.debug("tag", tag);
-	// Debug.debug("type", type);
-	// Debug.debug("length", length);
-	// Debug.debug("valueOffset", valueOffset);
-	// Debug.debug("valueOffsetBytes", valueOffsetBytes);
-	// Debug.debug("oversizeValue", oversizeValue);
-	// Debug.debug("byteOrder", byteOrder);
-	// }
-
-	public String getDescriptionWithoutValue()
-	{
-		return tag + " (0x" + Integer.toHexString(tag) + ": " + tagInfo.name
-				+ "): ";
-	}
-
-	public String toString()
-	{
-		StringBuffer result = new StringBuffer();
-
-		result.append(tag + " (0x" + Integer.toHexString(tag) + ": "
-				+ tagInfo.name + "): ");
-		result.append(getValueDescription() + " (" + length + " "
-				+ fieldType.name + ")");
-
-		return result.toString();
-	}
-
-	public String getTagName()
-	{
-		if (tagInfo == TIFF_TAG_UNKNOWN)
-			return tagInfo.name + " (0x" + Integer.toHexString(tag) + ")";
-		return tagInfo.name;
-	}
-
-	public String getFieldTypeName()
-	{
-		return fieldType.name;
-	}
-
-	public static final String Attribute_Tag = "Tag";
-
-	public Object getValue() throws ImageReadException
-	{
-		// System.out.print("getValue");
-		return tagInfo.getValue(this);
-	}
-
-	public String getStringValue() throws ImageReadException
-	{
-		Object o = getValue();
-		if (o == null)
-			return null;
-		if (!(o instanceof String))
-			throw new ImageReadException("Expected String value("
-					+ tagInfo.getDescription() + "): " + o);
-		return (String) o;
-	}
-
-	private static final Map makeTagMap(TagInfo tags[],
-			boolean ignoreDuplicates, String name)
-	{
-		// make sure to use the thread-safe version; this is shared state.
-		Map map = new Hashtable();
-
-		for (int i = 0; i < tags.length; i++)
-		{
-			TagInfo tag = tags[i];
-			Object key = new Integer(tag.tag);
-
-			List tagList = (List) map.get(key);
-			if (tagList == null)
-			{
-				tagList = new ArrayList();
-				map.put(key, tagList);
-			}
-			tagList.add(tag);
-
-			// if (map.get(key) == null)
-			// map.put(key, tag);
-			// else if (!ignoreDuplicates)
-			// {
-			// System.out.println("Duplicate tag in " + name + ": " + tag.tag
-			// + " (0x" + Integer.toHexString(tag.tag) + ")");
-			// System.out.println("\t" + "New name: " + tag.name);
-			// System.out.println("\t" + "Old name: "
-			// + ((TagInfo) map.get(key)).name);
-			// }
-		}
-
-		return map;
-	}
-
-	private static final Map GPS_TAG_MAP = makeTagMap(ALL_GPS_TAGS, false,
-			"GPS");
-	private static final Map TIFF_TAG_MAP = makeTagMap(ALL_TIFF_TAGS, false,
-			"TIFF");
-	private static final Map EXIF_TAG_MAP = makeTagMap(ALL_EXIF_TAGS, true,
-			"EXIF");
-	private static final Map ALL_TAG_MAP = makeTagMap(ALL_TAGS, true, "All");
-
-	// static
-	// {
-	// Map map = new HashMap();
-	//
-	// for (int i = 0; i < ALL_TAGS.length; i++)
-	// {
-	// TagInfo2 tag = ALL_TAGS[i];
-	// Object o = map.get("" + tag.tag);
-	// if (o == null)
-	// map.put("" + tag.tag, tag);
-	// else
-	// {
-	// System.out.println("Duplicate tag: " + tag.tag);
-	// System.out.println("\t" + "New name: " + tag.name);
-	// System.out.println("\t" + "Old name: " + ((TagInfo2) o).name);
-	// }
-	// }
-	//
-	// }
-
-	// public static final TagInfo2 ALL_TAGS[] = TagConstantsUtils
-	// .mergeTagLists(new TagInfo2[][]{
-	// ALL_EXIF_TAGS, ALL_TIFF_TAGS, ALL_GPS_TAGS,
-	// });
-	//
-	//	
-
-	public int[] getIntArrayValue() throws ImageReadException
-	{
-		Object o = getValue();
-		// if (o == null)
-		// return null;
-
-		if (o instanceof Number)
-			return new int[] { ((Number) o).intValue() };
-		else if (o instanceof Number[])
-		{
-			Number numbers[] = (Number[]) o;
-			int result[] = new int[numbers.length];
-			for (int i = 0; i < numbers.length; i++)
-				result[i] = numbers[i].intValue();
-			return result;
-		} else if (o instanceof int[])
-		{
-			int numbers[] = (int[]) o;
-			int result[] = new int[numbers.length];
-			for (int i = 0; i < numbers.length; i++)
-				result[i] = numbers[i];
-			return result;
-		}
-
-		throw new ImageReadException("Unknown value: " + o + " for: "
-				+ tagInfo.getDescription());
-		// return null;
-	}
-
-	public double[] getDoubleArrayValue() throws ImageReadException
-	{
-		Object o = getValue();
-		// if (o == null)
-		// return null;
-
-		if (o instanceof Number)
-		{
-			return new double[] { ((Number) o).doubleValue() };
-		} else if (o instanceof Number[])
-		{
-			Number numbers[] = (Number[]) o;
-			double result[] = new double[numbers.length];
-			for (int i = 0; i < numbers.length; i++)
-				result[i] = numbers[i].doubleValue();
-			return result;
-		} else if (o instanceof int[])
-		{
-			int numbers[] = (int[]) o;
-			double result[] = new double[numbers.length];
-			for (int i = 0; i < numbers.length; i++)
-				result[i] = numbers[i];
-			return result;
-		} else if (o instanceof float[])
-		{
-			float numbers[] = (float[]) o;
-			double result[] = new double[numbers.length];
-			for (int i = 0; i < numbers.length; i++)
-				result[i] = numbers[i];
-			return result;
-		} else if (o instanceof double[])
-		{
-			double numbers[] = (double[]) o;
-			double result[] = new double[numbers.length];
-			for (int i = 0; i < numbers.length; i++)
-				result[i] = numbers[i];
-			return result;
-		}
-
-		throw new ImageReadException("Unknown value: " + o + " for: "
-				+ tagInfo.getDescription());
-		// return null;
-	}
-
-	public int getIntValueOrArraySum() throws ImageReadException
-	{
-		Object o = getValue();
-		// if (o == null)
-		// return -1;
-
-		if (o instanceof Number)
-			return ((Number) o).intValue();
-		else if (o instanceof Number[])
-		{
-			Number numbers[] = (Number[]) o;
-			int sum = 0;
-			for (int i = 0; i < numbers.length; i++)
-				sum += numbers[i].intValue();
-			return sum;
-		} else if (o instanceof int[])
-		{
-			int numbers[] = (int[]) o;
-			int sum = 0;
-			for (int i = 0; i < numbers.length; i++)
-				sum += numbers[i];
-			return sum;
-		}
-
-		throw new ImageReadException("Unknown value: " + o + " for: "
-				+ tagInfo.getDescription());
-		// return -1;
-	}
-
-	public int getIntValue() throws ImageReadException
-	{
-		Object o = getValue();
-		if (o == null)
-			throw new ImageReadException("Missing value: "
-					+ tagInfo.getDescription());
-
-		return ((Number) o).intValue();
-	}
-
-	public double getDoubleValue() throws ImageReadException
-	{
-		Object o = getValue();
-		if (o == null)
-			throw new ImageReadException("Missing value: "
-					+ tagInfo.getDescription());
-
-		return ((Number) o).doubleValue();
-	}
-
-	public byte[] getByteArrayValue() throws ImageReadException
-	{
-		return fieldType.getRawBytes(this);
-	}
-
-	public int getSortHint()
-	{
-		return sortHint;
-	}
-
-	public void setSortHint(int sortHint)
-	{
-		this.sortHint = sortHint;
-	}
+    public final int tag;
+    public final int directoryType;
+    public final int type;
+    public final int length;
+    public final int valueOffset;
+    public final byte valueOffsetBytes[];
+
+    public byte oversizeValue[] = null;
+    public final int byteOrder;
+
+    public TiffField(int tag, int directoryType, int type, int Length,
+            int ValueOffset, byte ValueOffsetBytes[], int byteOrder)
+    {
+
+        this.tag = tag;
+        this.directoryType = directoryType;
+        this.type = type;
+        this.length = Length;
+        this.valueOffset = ValueOffset;
+        this.valueOffsetBytes = ValueOffsetBytes;
+        this.byteOrder = byteOrder;
+
+        fieldType = getFieldType(type);
+        tagInfo = getTag(directoryType, tag);
+    }
+
+    private int sortHint = -1;
+
+    public boolean isLocalValue()
+    {
+        return fieldType.isLocalValue(this);
+    }
+
+    public int getBytesLength() throws ImageReadException
+    {
+        return fieldType.getBytesLength(this);
+    }
+
+    public final class OversizeValueElement extends TiffElement
+    {
+        public OversizeValueElement(int offset, int length)
+        {
+            super(offset, length);
+        }
+
+        public String getElementDescription(boolean verbose)
+        {
+            if (verbose)
+                return null;
+
+            return "OversizeValueElement, tag: " + tagInfo.name
+                    + ", fieldType: " + fieldType.name;
+        }
+    }
+
+    public TiffElement getOversizeValueElement()
+    {
+        if (fieldType.isLocalValue(this))
+            return null;
+
+        return new OversizeValueElement(valueOffset, oversizeValue.length);
+    }
+
+    public void setOversizeValue(byte bytes[])
+    {
+        this.oversizeValue = bytes;
+    }
+
+    private static FieldType getFieldType(int value)
+    {
+        for (int i = 0; i < FIELD_TYPES.length; i++)
+        {
+            FieldType fieldType = FIELD_TYPES[i];
+            if (fieldType.type == value)
+                return fieldType;
+        }
+
+        return FIELD_TYPE_UNKNOWN;
+    }
+
+    private static TagInfo getTag(int directoryType, int tag,
+            List possibleMatches)
+    {
+        if (possibleMatches.size() < 1)
+            return null;
+        // else if (possibleMatches.size() == 1)
+        // {
+        // TagInfo tagInfo = (TagInfo) possibleMatches.get(0);
+        // return tagInfo;
+        // }
+
+        // first search for exact match.
+        for (int i = 0; i < possibleMatches.size(); i++)
+        {
+            TagInfo tagInfo = (TagInfo) possibleMatches.get(i);
+            if (tagInfo.directoryType == EXIF_DIRECTORY_UNKNOWN)
+                // pass
+                continue;
+            else if (directoryType == DIRECTORY_TYPE_EXIF
+                    && tagInfo.directoryType == EXIF_DIRECTORY_EXIF_IFD)
+                return tagInfo;
+            else if (directoryType == DIRECTORY_TYPE_INTEROPERABILITY
+                    && tagInfo.directoryType == EXIF_DIRECTORY_INTEROP_IFD)
+                return tagInfo;
+            else if (directoryType == DIRECTORY_TYPE_GPS
+                    && tagInfo.directoryType == EXIF_DIRECTORY_GPS)
+                return tagInfo;
+            else if (directoryType == DIRECTORY_TYPE_MAKER_NOTES
+                    && tagInfo.directoryType == EXIF_DIRECTORY_MAKER_NOTES)
+                return tagInfo;
+            else if (directoryType == DIRECTORY_TYPE_DIR_0
+                    && tagInfo.directoryType == TIFF_DIRECTORY_IFD0)
+                return tagInfo;
+            else if (directoryType == DIRECTORY_TYPE_DIR_1
+                    && tagInfo.directoryType == TIFF_DIRECTORY_IFD1)
+                return tagInfo;
+            else if (directoryType == DIRECTORY_TYPE_DIR_2
+                    && tagInfo.directoryType == TIFF_DIRECTORY_IFD2)
+                return tagInfo;
+            else if (directoryType == DIRECTORY_TYPE_DIR_3
+                    && tagInfo.directoryType == TIFF_DIRECTORY_IFD3)
+                return tagInfo;
+        }
+
+        // accept an inexact match.
+        for (int i = 0; i < possibleMatches.size(); i++)
+        {
+            TagInfo tagInfo = (TagInfo) possibleMatches.get(i);
+
+            if (tagInfo.directoryType == EXIF_DIRECTORY_UNKNOWN)
+                // pass
+                continue;
+            else if (directoryType >= 0
+                    && tagInfo.directoryType.isImageDirectory())
+                return tagInfo;
+            else if (directoryType < 0
+                    && !tagInfo.directoryType.isImageDirectory())
+                return tagInfo;
+        }
+
+        // accept a wildcard match.
+        for (int i = 0; i < possibleMatches.size(); i++)
+        {
+            TagInfo tagInfo = (TagInfo) possibleMatches.get(i);
+
+            if (tagInfo.directoryType == EXIF_DIRECTORY_UNKNOWN)
+                return tagInfo;
+        }
+
+        // // accept a very rough match.
+        // for (int i = 0; i < possibleMatches.size(); i++)
+        // {
+        // TagInfo tagInfo = (TagInfo) possibleMatches.get(i);
+        // if (tagInfo.exifDirectory == EXIF_DIRECTORY_UNKNOWN)
+        // return tagInfo;
+        // else if (directoryType == DIRECTORY_TYPE_EXIF
+        // && tagInfo.exifDirectory == EXIF_DIRECTORY_EXIF_IFD)
+        // return tagInfo;
+        // else if (directoryType == DIRECTORY_TYPE_INTEROPERABILITY
+        // && tagInfo.exifDirectory == EXIF_DIRECTORY_INTEROP_IFD)
+        // return tagInfo;
+        // else if (directoryType == DIRECTORY_TYPE_GPS
+        // && tagInfo.exifDirectory == EXIF_DIRECTORY_GPS)
+        // return tagInfo;
+        // else if (directoryType == DIRECTORY_TYPE_MAKER_NOTES
+        // && tagInfo.exifDirectory == EXIF_DIRECTORY_MAKER_NOTES)
+        // return tagInfo;
+        // else if (directoryType >= 0
+        // && tagInfo.exifDirectory.isImageDirectory())
+        // return tagInfo;
+        // else if (directoryType < 0
+        // && !tagInfo.exifDirectory.isImageDirectory())
+        // return tagInfo;
+        // }
+
+        return TIFF_TAG_UNKNOWN;
+
+        // if (true)
+        // throw new Error("Why didn't this algorithm work?");
+        //
+        // {
+        // TagInfo tagInfo = (TagInfo) possibleMatches.get(0);
+        // return tagInfo;
+        // }
+
+        // Object key = new Integer(tag);
+        //
+        // if (directoryType == DIRECTORY_TYPE_EXIF
+        // || directoryType == DIRECTORY_TYPE_INTEROPERABILITY)
+        // {
+        // if (EXIF_TAG_MAP.containsKey(key))
+        // return (TagInfo) EXIF_TAG_MAP.get(key);
+        // }
+        // else if (directoryType == DIRECTORY_TYPE_GPS)
+        // {
+        // if (GPS_TAG_MAP.containsKey(key))
+        // return (TagInfo) GPS_TAG_MAP.get(key);
+        // }
+        // else
+        // {
+        // if (TIFF_TAG_MAP.containsKey(key))
+        // return (TagInfo) TIFF_TAG_MAP.get(key);
+        // }
+        //
+        // if (ALL_TAG_MAP.containsKey(key))
+        // return (TagInfo) ALL_TAG_MAP.get(key);
+
+        // public static final int DIRECTORY_TYPE_EXIF = -2;
+        // // public static final int DIRECTORY_TYPE_SUB = 5;
+        // public static final int DIRECTORY_TYPE_GPS = -3;
+        // public static final int DIRECTORY_TYPE_INTEROPERABILITY = -4;
+        //
+        // private static final Map GPS_TAG_MAP = makeTagMap(ALL_GPS_TAGS,
+        // false);
+        // private static final Map TIFF_TAG_MAP = makeTagMap(ALL_TIFF_TAGS,
+        // false);
+        // private static final Map EXIF_TAG_MAP = makeTagMap(ALL_EXIF_TAGS,
+        // false);
+        // private static final Map ALL_TAG_MAP = makeTagMap(ALL_TAGS, true);
+        //
+        // for (int i = 0; i < ALL_TAGS.length; i++)
+        // {
+        // TagInfo2 tag = ALL_TAGS[i];
+        // if (tag.tag == value)
+        // return tag;
+        // }
+
+        // return TIFF_TAG_UNKNOWN;
+    }
+
+    private static TagInfo getTag(int directoryType, int tag)
+    {
+        Object key = new Integer(tag);
+
+        List possibleMatches = (List) EXIF_TAG_MAP.get(key);
+
+        if (null == possibleMatches)
+        {
+            return TIFF_TAG_UNKNOWN;
+        }
+
+        TagInfo result = getTag(directoryType, tag, possibleMatches);
+        return result;
+    }
+
+    private int getValueLengthInBytes()
+    {
+        int unit_length = fieldType.length;
+        int valueLength = unit_length * length;
+
+        // Debug.debug("getValueLengthInBytes unit_length", unit_length);
+        // Debug.debug("getValueLengthInBytes length", length);
+
+        return valueLength;
+    }
+
+    public void fillInValue(ByteSource byteSource) throws ImageReadException,
+            IOException
+    {
+        if (fieldType.isLocalValue(this))
+            return;
+
+        int valueLength = getValueLengthInBytes();
+
+        // Debug.debug("fillInValue tag", tag);
+        // Debug.debug("fillInValue tagInfo", tagInfo);
+        // Debug.debug("fillInValue valueOffset", valueOffset);
+        // Debug.debug("fillInValue valueLength", valueLength);
+
+        byte bytes[] = byteSource.getBlock(valueOffset, valueLength);
+        setOversizeValue(bytes);
+    }
+
+    public String getValueDescription()
+    {
+        try
+        {
+            return getValueDescription(getValue());
+        } catch (ImageReadException e)
+        {
+            return "Invalid value: " + e.getMessage();
+        }
+    }
+
+    private String getValueDescription(Object o)
+    {
+        if (o == null)
+            return null;
+
+        if (o instanceof Number)
+        {
+            return o.toString();
+        } else if (o instanceof String)
+        {
+            return "'" + o.toString().trim() + "'";
+        } else if (o instanceof Date)
+        {
+            DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+            return df.format((Date) o);
+        } else if (o instanceof Object[])
+        {
+            Object objects[] = (Object[]) o;
+            StringBuffer result = new StringBuffer();
+
+            for (int i = 0; i < objects.length; i++)
+            {
+                Object object = objects[i];
+
+                if (i > 50)
+                {
+                    result.append("... (" + objects.length + ")");
+                    break;
+                }
+                if (i > 0)
+                    result.append(", ");
+                result.append("" + object);
+            }
+            return result.toString();
+        }
+        // else if (o instanceof Number[])
+        // {
+        // Number numbers[] = (Number[]) o;
+        // StringBuffer result = new StringBuffer();
+        //
+        // for (int i = 0; i < numbers.length; i++)
+        // {
+        // Number number = numbers[i];
+        //
+        // if (i > 0)
+        // result.append(", ");
+        // result.append("" + number);
+        // }
+        // return result.toString();
+        // }
+        else if (o instanceof int[])
+        {
+            int values[] = (int[]) o;
+            StringBuffer result = new StringBuffer();
+
+            for (int i = 0; i < values.length; i++)
+            {
+                int value = values[i];
+
+                if (i > 50)
+                {
+                    result.append("... (" + values.length + ")");
+                    break;
+                }
+                if (i > 0)
+                    result.append(", ");
+                result.append("" + value);
+            }
+            return result.toString();
+        } else if (o instanceof long[])
+        {
+            long values[] = (long[]) o;
+            StringBuffer result = new StringBuffer();
+
+            for (int i = 0; i < values.length; i++)
+            {
+                long value = values[i];
+
+                if (i > 50)
+                {
+                    result.append("... (" + values.length + ")");
+                    break;
+                }
+                if (i > 0)
+                    result.append(", ");
+                result.append("" + value);
+            }
+            return result.toString();
+        } else if (o instanceof double[])
+        {
+            double values[] = (double[]) o;
+            StringBuffer result = new StringBuffer();
+
+            for (int i = 0; i < values.length; i++)
+            {
+                double value = values[i];
+
+                if (i > 50)
+                {
+                    result.append("... (" + values.length + ")");
+                    break;
+                }
+                if (i > 0)
+                    result.append(", ");
+                result.append("" + value);
+            }
+            return result.toString();
+        } else if (o instanceof byte[])
+        {
+            byte values[] = (byte[]) o;
+            StringBuffer result = new StringBuffer();
+
+            for (int i = 0; i < values.length; i++)
+            {
+                byte value = values[i];
+
+                if (i > 50)
+                {
+                    result.append("... (" + values.length + ")");
+                    break;
+                }
+                if (i > 0)
+                    result.append(", ");
+                result.append("" + value);
+            }
+            return result.toString();
+        } else if (o instanceof char[])
+        {
+            char values[] = (char[]) o;
+            StringBuffer result = new StringBuffer();
+
+            for (int i = 0; i < values.length; i++)
+            {
+                char value = values[i];
+
+                if (i > 50)
+                {
+                    result.append("... (" + values.length + ")");
+                    break;
+                }
+                if (i > 0)
+                    result.append(", ");
+                result.append("" + value);
+            }
+            return result.toString();
+        } else if (o instanceof float[])
+        {
+            float values[] = (float[]) o;
+            StringBuffer result = new StringBuffer();
+
+            for (int i = 0; i < values.length; i++)
+            {
+                float value = values[i];
+
+                if (i > 50)
+                {
+                    result.append("... (" + values.length + ")");
+                    break;
+                }
+                if (i > 0)
+                    result.append(", ");
+                result.append("" + value);
+            }
+            return result.toString();
+        }
+        // else if (o instanceof short[])
+        // {
+        // short numbers[] = (short[]) o;
+        // StringBuffer result = new StringBuffer();
+        //
+        // for (int i = 0; i < numbers.length; i++)
+        // {
+        // short number = numbers[i];
+        //
+        // if (i > 0)
+        // result.append(", ");
+        // result.append("" + number);
+        // }
+        // return result.toString();
+        // }
+
+        return "Unknown: " + o.getClass().getName();
+    }
+
+    public void dump()
+    {
+        PrintWriter pw = new PrintWriter(System.out);
+        dump(pw);
+        pw.flush();
+    }
+
+    public void dump(PrintWriter pw)
+    {
+        dump(pw, null);
+    }
+
+    public void dump(PrintWriter pw, String prefix)
+    {
+        if (prefix != null)
+            pw.print(prefix + ": ");
+
+        pw.println(toString());
+        pw.flush();
+    }
+
+    // private void errorDump()
+    // {
+    // Debug.debug("tagInfo", tagInfo);
+    // Debug.debug("fieldType", fieldType);
+    // Debug.debug("tag", tag);
+    // Debug.debug("type", type);
+    // Debug.debug("length", length);
+    // Debug.debug("valueOffset", valueOffset);
+    // Debug.debug("valueOffsetBytes", valueOffsetBytes);
+    // Debug.debug("oversizeValue", oversizeValue);
+    // Debug.debug("byteOrder", byteOrder);
+    // }
+
+    public String getDescriptionWithoutValue()
+    {
+        return tag + " (0x" + Integer.toHexString(tag) + ": " + tagInfo.name
+                + "): ";
+    }
+
+    public String toString()
+    {
+        StringBuffer result = new StringBuffer();
+
+        result.append(tag + " (0x" + Integer.toHexString(tag) + ": "
+                + tagInfo.name + "): ");
+        result.append(getValueDescription() + " (" + length + " "
+                + fieldType.name + ")");
+
+        return result.toString();
+    }
+
+    public String getTagName()
+    {
+        if (tagInfo == TIFF_TAG_UNKNOWN)
+            return tagInfo.name + " (0x" + Integer.toHexString(tag) + ")";
+        return tagInfo.name;
+    }
+
+    public String getFieldTypeName()
+    {
+        return fieldType.name;
+    }
+
+    public static final String Attribute_Tag = "Tag";
+
+    public Object getValue() throws ImageReadException
+    {
+        // System.out.print("getValue");
+        return tagInfo.getValue(this);
+    }
+
+    public String getStringValue() throws ImageReadException
+    {
+        Object o = getValue();
+        if (o == null)
+            return null;
+        if (!(o instanceof String))
+            throw new ImageReadException("Expected String value("
+                    + tagInfo.getDescription() + "): " + o);
+        return (String) o;
+    }
+
+    private static final Map makeTagMap(TagInfo tags[],
+            boolean ignoreDuplicates, String name)
+    {
+        // make sure to use the thread-safe version; this is shared state.
+        Map map = new Hashtable();
+
+        for (int i = 0; i < tags.length; i++)
+        {
+            TagInfo tag = tags[i];
+            Object key = new Integer(tag.tag);
+
+            List tagList = (List) map.get(key);
+            if (tagList == null)
+            {
+                tagList = new ArrayList();
+                map.put(key, tagList);
+            }
+            tagList.add(tag);
+
+            // if (map.get(key) == null)
+            // map.put(key, tag);
+            // else if (!ignoreDuplicates)
+            // {
+            // System.out.println("Duplicate tag in " + name + ": " + tag.tag
+            // + " (0x" + Integer.toHexString(tag.tag) + ")");
+            // System.out.println("\t" + "New name: " + tag.name);
+            // System.out.println("\t" + "Old name: "
+            // + ((TagInfo) map.get(key)).name);
+            // }
+        }
+
+        return map;
+    }
+
+    private static final Map GPS_TAG_MAP = makeTagMap(ALL_GPS_TAGS, false,
+            "GPS");
+    private static final Map TIFF_TAG_MAP = makeTagMap(ALL_TIFF_TAGS, false,
+            "TIFF");
+    private static final Map EXIF_TAG_MAP = makeTagMap(ALL_EXIF_TAGS, true,
+            "EXIF");
+    private static final Map ALL_TAG_MAP = makeTagMap(ALL_TAGS, true, "All");
+
+    // static
+    // {
+    // Map map = new HashMap();
+    //
+    // for (int i = 0; i < ALL_TAGS.length; i++)
+    // {
+    // TagInfo2 tag = ALL_TAGS[i];
+    // Object o = map.get("" + tag.tag);
+    // if (o == null)
+    // map.put("" + tag.tag, tag);
+    // else
+    // {
+    // System.out.println("Duplicate tag: " + tag.tag);
+    // System.out.println("\t" + "New name: " + tag.name);
+    // System.out.println("\t" + "Old name: " + ((TagInfo2) o).name);
+    // }
+    // }
+    //
+    // }
+
+    // public static final TagInfo2 ALL_TAGS[] = TagConstantsUtils
+    // .mergeTagLists(new TagInfo2[][]{
+    // ALL_EXIF_TAGS, ALL_TIFF_TAGS, ALL_GPS_TAGS,
+    // });
+    //
+    //
+
+    public int[] getIntArrayValue() throws ImageReadException
+    {
+        Object o = getValue();
+        // if (o == null)
+        // return null;
+
+        if (o instanceof Number)
+            return new int[] { ((Number) o).intValue() };
+        else if (o instanceof Number[])
+        {
+            Number numbers[] = (Number[]) o;
+            int result[] = new int[numbers.length];
+            for (int i = 0; i < numbers.length; i++)
+                result[i] = numbers[i].intValue();
+            return result;
+        } else if (o instanceof int[])
+        {
+            int numbers[] = (int[]) o;
+            int result[] = new int[numbers.length];
+            for (int i = 0; i < numbers.length; i++)
+                result[i] = numbers[i];
+            return result;
+        }
+
+        throw new ImageReadException("Unknown value: " + o + " for: "
+                + tagInfo.getDescription());
+        // return null;
+    }
+
+    public double[] getDoubleArrayValue() throws ImageReadException
+    {
+        Object o = getValue();
+        // if (o == null)
+        // return null;
+
+        if (o instanceof Number)
+        {
+            return new double[] { ((Number) o).doubleValue() };
+        } else if (o instanceof Number[])
+        {
+            Number numbers[] = (Number[]) o;
+            double result[] = new double[numbers.length];
+            for (int i = 0; i < numbers.length; i++)
+                result[i] = numbers[i].doubleValue();
+            return result;
+        } else if (o instanceof int[])
+        {
+            int numbers[] = (int[]) o;
+            double result[] = new double[numbers.length];
+            for (int i = 0; i < numbers.length; i++)
+                result[i] = numbers[i];
+            return result;
+        } else if (o instanceof float[])
+        {
+            float numbers[] = (float[]) o;
+            double result[] = new double[numbers.length];
+            for (int i = 0; i < numbers.length; i++)
+                result[i] = numbers[i];
+            return result;
+        } else if (o instanceof double[])
+        {
+            double numbers[] = (double[]) o;
+            double result[] = new double[numbers.length];
+            for (int i = 0; i < numbers.length; i++)
+                result[i] = numbers[i];
+            return result;
+        }
+
+        throw new ImageReadException("Unknown value: " + o + " for: "
+                + tagInfo.getDescription());
+        // return null;
+    }
+
+    public int getIntValueOrArraySum() throws ImageReadException
+    {
+        Object o = getValue();
+        // if (o == null)
+        // return -1;
+
+        if (o instanceof Number)
+            return ((Number) o).intValue();
+        else if (o instanceof Number[])
+        {
+            Number numbers[] = (Number[]) o;
+            int sum = 0;
+            for (int i = 0; i < numbers.length; i++)
+                sum += numbers[i].intValue();
+            return sum;
+        } else if (o instanceof int[])
+        {
+            int numbers[] = (int[]) o;
+            int sum = 0;
+            for (int i = 0; i < numbers.length; i++)
+                sum += numbers[i];
+            return sum;
+        }
+
+        throw new ImageReadException("Unknown value: " + o + " for: "
+                + tagInfo.getDescription());
+        // return -1;
+    }
+
+    public int getIntValue() throws ImageReadException
+    {
+        Object o = getValue();
+        if (o == null)
+            throw new ImageReadException("Missing value: "
+                    + tagInfo.getDescription());
+
+        return ((Number) o).intValue();
+    }
+
+    public double getDoubleValue() throws ImageReadException
+    {
+        Object o = getValue();
+        if (o == null)
+            throw new ImageReadException("Missing value: "
+                    + tagInfo.getDescription());
+
+        return ((Number) o).doubleValue();
+    }
+
+    public byte[] getByteArrayValue() throws ImageReadException
+    {
+        return fieldType.getRawBytes(this);
+    }
+
+    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/TiffHeader.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffHeader.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffHeader.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffHeader.java Fri Sep 10 16:33:35 2010
@@ -20,24 +20,24 @@ import org.apache.sanselan.formats.tiff.
 
 public class TiffHeader extends TiffElement
 {
-	public final int byteOrder;
-	public final int tiffVersion;
-	public final int offsetToFirstIFD;
+    public final int byteOrder;
+    public final int tiffVersion;
+    public final int offsetToFirstIFD;
 
-	public TiffHeader(final int byteOrder, int tiffVersion, int offsetToFirstIFD)
-	{
-		super(0, TiffConstants.TIFF_HEADER_SIZE);
+    public TiffHeader(final int byteOrder, int tiffVersion, int offsetToFirstIFD)
+    {
+        super(0, TiffConstants.TIFF_HEADER_SIZE);
 
-		this.byteOrder = byteOrder;
-		this.tiffVersion = tiffVersion;
-		this.offsetToFirstIFD = offsetToFirstIFD;
-	}
+        this.byteOrder = byteOrder;
+        this.tiffVersion = tiffVersion;
+        this.offsetToFirstIFD = offsetToFirstIFD;
+    }
 
-	public String getElementDescription(boolean verbose)
-	{
-		if (verbose)
-			return null;
+    public String getElementDescription(boolean verbose)
+    {
+        if (verbose)
+            return null;
 
-		return "TIFF Header";
-	}
+        return "TIFF Header";
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageData.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageData.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageData.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageData.java Fri Sep 10 16:33:35 2010
@@ -28,111 +28,111 @@ import org.apache.sanselan.formats.tiff.
 
 public abstract class TiffImageData
 {
-	public static class Tiles extends TiffImageData
-	{
-		public final TiffElement.DataElement tiles[];
-
-		//		public final byte tiles[][];
-		private final int tileWidth, tileLength;
-
-		public Tiles(final TiffElement.DataElement tiles[],
-				final int tileWidth, final int tileLength)
-		{
-			this.tiles = tiles;
-			this.tileWidth = tileWidth;
-			this.tileLength = tileLength;
-		}
-
-		public TiffElement.DataElement[] getImageData()
-		{
-			return tiles;
-		}
-
-		public boolean stripsNotTiles()
-		{
-			return false;
-		}
-
-		public DataReader getDataReader(ArrayList entries,
-				PhotometricInterpreter photometricInterpreter,
-				int bitsPerPixel, int bitsPerSample[], int predictor,
-				int samplesPerPixel, int width, int height, int compression)
-				throws IOException, ImageReadException
-		{
-			return new DataReaderTiled(photometricInterpreter, tileWidth,
-					tileLength, bitsPerPixel, bitsPerSample, predictor,
-					samplesPerPixel, width, height, compression, this);
-		}
-
-		//		public TiffElement[] getElements()
-		//		{
-		//			return tiles;
-		//		}
-	}
-
-	public static class Strips extends TiffImageData
-	{
-		public final TiffElement.DataElement strips[];
-		//		public final byte strips[][];
-		public final int rowsPerStrip;
-
-		public Strips(final TiffElement.DataElement strips[],
-				final int rowsPerStrip)
-		{
-			this.strips = strips;
-			this.rowsPerStrip = rowsPerStrip;
-		}
-
-		public TiffElement.DataElement[] getImageData()
-		{
-			return strips;
-		}
-
-		public boolean stripsNotTiles()
-		{
-			return true;
-		}
-
-		public DataReader getDataReader(ArrayList entries,
-				PhotometricInterpreter photometricInterpreter,
-				int bitsPerPixel, int bitsPerSample[], int predictor,
-				int samplesPerPixel, int width, int height, int compression)
-				throws IOException, ImageReadException
-		{
-			return new DataReaderStrips(photometricInterpreter, bitsPerPixel,
-					bitsPerSample, predictor, samplesPerPixel, width, height,
-					compression, rowsPerStrip, this);
-		}
-
-		//		public TiffElement[] getElements()
-		//		{
-		//			return strips;
-		//		}
-
-	}
-
-	//	public abstract TiffElement[] getElements();
-
-	public abstract TiffElement.DataElement[] getImageData();
-
-	public abstract boolean stripsNotTiles();
-
-	public abstract DataReader getDataReader(ArrayList entries,
-			PhotometricInterpreter photometricInterpreter, int bitsPerPixel,
-			int bitsPerSample[], int predictor, int samplesPerPixel, int width,
-			int height, int compression) throws IOException, ImageReadException;
-
-	public static class Data extends TiffElement.DataElement
-	{
-		public Data(int offset, int length, final byte data[])
-		{
-			super(offset, length, data);
-		}
-
-		public String getElementDescription(boolean verbose)
-		{
-			return "Tiff image data: " + data.length + " bytes";
-		}
+    public static class Tiles extends TiffImageData
+    {
+        public final TiffElement.DataElement tiles[];
+
+        //        public final byte tiles[][];
+        private final int tileWidth, tileLength;
+
+        public Tiles(final TiffElement.DataElement tiles[],
+                final int tileWidth, final int tileLength)
+        {
+            this.tiles = tiles;
+            this.tileWidth = tileWidth;
+            this.tileLength = tileLength;
+        }
+
+        public TiffElement.DataElement[] getImageData()
+        {
+            return tiles;
+        }
+
+        public boolean stripsNotTiles()
+        {
+            return false;
+        }
+
+        public DataReader getDataReader(ArrayList entries,
+                PhotometricInterpreter photometricInterpreter,
+                int bitsPerPixel, int bitsPerSample[], int predictor,
+                int samplesPerPixel, int width, int height, int compression)
+                throws IOException, ImageReadException
+        {
+            return new DataReaderTiled(photometricInterpreter, tileWidth,
+                    tileLength, bitsPerPixel, bitsPerSample, predictor,
+                    samplesPerPixel, width, height, compression, this);
+        }
+
+        //        public TiffElement[] getElements()
+        //        {
+        //            return tiles;
+        //        }
+    }
+
+    public static class Strips extends TiffImageData
+    {
+        public final TiffElement.DataElement strips[];
+        //        public final byte strips[][];
+        public final int rowsPerStrip;
+
+        public Strips(final TiffElement.DataElement strips[],
+                final int rowsPerStrip)
+        {
+            this.strips = strips;
+            this.rowsPerStrip = rowsPerStrip;
+        }
+
+        public TiffElement.DataElement[] getImageData()
+        {
+            return strips;
+        }
+
+        public boolean stripsNotTiles()
+        {
+            return true;
+        }
+
+        public DataReader getDataReader(ArrayList entries,
+                PhotometricInterpreter photometricInterpreter,
+                int bitsPerPixel, int bitsPerSample[], int predictor,
+                int samplesPerPixel, int width, int height, int compression)
+                throws IOException, ImageReadException
+        {
+            return new DataReaderStrips(photometricInterpreter, bitsPerPixel,
+                    bitsPerSample, predictor, samplesPerPixel, width, height,
+                    compression, rowsPerStrip, this);
+        }
+
+        //        public TiffElement[] getElements()
+        //        {
+        //            return strips;
+        //        }
+
+    }
+
+    //    public abstract TiffElement[] getElements();
+
+    public abstract TiffElement.DataElement[] getImageData();
+
+    public abstract boolean stripsNotTiles();
+
+    public abstract DataReader getDataReader(ArrayList entries,
+            PhotometricInterpreter photometricInterpreter, int bitsPerPixel,
+            int bitsPerSample[], int predictor, int samplesPerPixel, int width,
+            int height, int compression) throws IOException, ImageReadException;
+
+    public static class Data extends TiffElement.DataElement
+    {
+        public Data(int offset, int length, final byte data[])
+        {
+            super(offset, length, data);
+        }
+
+        public String getElementDescription(boolean verbose)
+        {
+            return "Tiff image data: " + data.length + " bytes";
+        }
 
-	}
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageMetadata.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageMetadata.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageMetadata.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageMetadata.java Fri Sep 10 16:33:35 2010
@@ -34,363 +34,363 @@ import org.apache.sanselan.formats.tiff.
 import org.apache.sanselan.formats.tiff.write.TiffOutputSet;
 
 public class TiffImageMetadata extends ImageMetadata
-		implements
-			TiffDirectoryConstants
+        implements
+            TiffDirectoryConstants
 {
-	public final TiffContents contents;
+    public final TiffContents contents;
 
-	public TiffImageMetadata(final TiffContents contents)
-	{
-		this.contents = contents;
-	}
-
-	public static class Directory extends ImageMetadata
-			implements
-				ImageMetadata.IImageMetadataItem
-	{
-		//		private BufferedImage thumbnail = null;
-
-		public final int type;
-
-		private final TiffDirectory directory;
-
-		public Directory(final TiffDirectory directory)
-		{
-			this.type = directory.type;
-			this.directory = directory;
-		}
-
-		public void add(TiffField entry)
-		{
-			add(new TiffImageMetadata.Item(entry));
-		}
-
-		public BufferedImage getThumbnail() throws ImageReadException,
-				IOException
-		{
-			return directory.getTiffImage();
-		}
-
-		public TiffImageData getTiffImageData()
-		{
-			return directory.getTiffImageData();
-		}
-
-		public TiffField findField(TagInfo tagInfo) throws ImageReadException
-		{
-			return directory.findField(tagInfo);
-		}
-
-		public List getAllFields() throws ImageReadException
-		{
-			return directory.getDirectoryEntrys();
-		}
-
-		public JpegImageData getJpegImageData()
-		{
-			return directory.getJpegImageData();
-		}
-
-		public String toString(String prefix)
-		{
-			return (prefix != null ? prefix : "") + directory.description()
-					+ ": " //
-					+ (getTiffImageData() != null ? " (tiffImageData)" : "") //
-					+ (getJpegImageData() != null ? " (jpegImageData)" : "") //
-					+ "\n" + super.toString(prefix) + "\n";
-		}
-
-		public TiffOutputDirectory getOutputDirectory(int byteOrder)
-				throws ImageWriteException
-		{
-			try
-			{
-				TiffOutputDirectory dstDir = new TiffOutputDirectory(type);
-
-				ArrayList entries = getItems();
-				for (int i = 0; i < entries.size(); i++)
-				{
-					TiffImageMetadata.Item item = (TiffImageMetadata.Item) entries
-							.get(i);
-					TiffField srcField = item.getTiffField();
-
-					if (null != dstDir.findField(srcField.tag))
-					{
-						// ignore duplicate tags in a directory.
-						continue;
-					}
-					else if (srcField.tagInfo instanceof TagInfo.Offset)
-					{
-						// ignore offset fields.
-						continue;
-					}
-
-					TagInfo tagInfo = srcField.tagInfo;
-					FieldType fieldType = srcField.fieldType;
-					int count = srcField.length;
-					//			byte bytes[] = srcField.fieldType.getRawBytes(srcField);
-
-					//					Debug.debug("tagInfo", tagInfo);
-
-					Object value = srcField.getValue();
-
-					//					Debug.debug("value", Debug.getType(value));
-
-					byte bytes[] = tagInfo.encodeValue(fieldType, value,
-							byteOrder);
-
-					//					if (tagInfo.isUnknown())
-					//						Debug.debug(
-					//								"\t" + "unknown tag(0x"
-					//										+ Integer.toHexString(srcField.tag)
-					//										+ ") bytes", bytes);
-
-					TiffOutputField dstField = new TiffOutputField(
-							srcField.tag, tagInfo, fieldType, count, bytes);
-					dstField.setSortHint(srcField.getSortHint());
-					dstDir.add(dstField);
-				}
-
-				dstDir.setTiffImageData(getTiffImageData());
-				dstDir.setJpegImageData(getJpegImageData());
-
-				return dstDir;
-			}
-			catch (ImageReadException e)
-			{
-				throw new ImageWriteException(e.getMessage(), e);
-			}
-		}
-
-	}
-
-	public ArrayList getDirectories()
-	{
-		return super.getItems();
-	}
-
-	public ArrayList getItems()
-	{
-		ArrayList result = new ArrayList();
-
-		ArrayList items = super.getItems();
-		for (int i = 0; i < items.size(); i++)
-		{
-			Directory dir = (Directory) items.get(i);
-			result.addAll(dir.getItems());
-		}
-
-		return result;
-	}
-
-	public static class Item extends ImageMetadata.Item
-	{
-		private final TiffField entry;
-
-		public Item(TiffField entry)
-		{
-			//			super(entry.getTagName() + " (" + entry.getFieldTypeName() + ")",
-			super(entry.getTagName(), entry.getValueDescription());
-			this.entry = entry;
-		}
-
-		public TiffField getTiffField()
-		{
-			return entry;
-		}
-
-	}
-
-	public TiffOutputSet getOutputSet() throws ImageWriteException
-	{
-		int byteOrder = contents.header.byteOrder;
-		TiffOutputSet result = new TiffOutputSet(byteOrder);
-
-		ArrayList srcDirs = getDirectories();
-		for (int i = 0; i < srcDirs.size(); i++)
-		{
-			TiffImageMetadata.Directory srcDir = (TiffImageMetadata.Directory) srcDirs
-					.get(i);
-
-			if (null != result.findDirectory(srcDir.type))
-			{
-				// Certain cameras right directories more than once.
-				// This is a bug.
-				// Ignore second directory of a given type.
-				continue;
-			}
-
-			TiffOutputDirectory outputDirectory = srcDir
-					.getOutputDirectory(byteOrder);
-			result.addDirectory(outputDirectory);
-		}
-
-		return result;
-	}
-
-	public TiffField findField(TagInfo tagInfo) throws ImageReadException
-	{
-		ArrayList directories = getDirectories();
-		for (int i = 0; i < directories.size(); i++)
-		{
-			Directory directory = (Directory) directories.get(i);
-			TiffField field = directory.findField(tagInfo);
-			if (null != field)
-				return field;
-		}
-		return null;
-	}
-
-	public TiffDirectory findDirectory(int directoryType)
-	{
-		ArrayList directories = getDirectories();
-		for (int i = 0; i < directories.size(); i++)
-		{
-			Directory directory = (Directory) directories.get(i);
-			if (directory.type == directoryType)
-				return directory.directory;
-		}
-		return null;
-	}
-
-	public List getAllFields() throws ImageReadException
-	{
-		List result = new ArrayList();
-		ArrayList directories = getDirectories();
-		for (int i = 0; i < directories.size(); i++)
-		{
-			Directory directory = (Directory) directories.get(i);
-			result.addAll(directory.getAllFields());
-		}
-		return result;
-	}
-
-	public GPSInfo getGPS() throws ImageReadException
-	{
-		TiffDirectory gpsDirectory = findDirectory(DIRECTORY_TYPE_GPS);
-		if (null == gpsDirectory)
-			return null;
-
-		// more specific example of how to access GPS values.
-		TiffField latitudeRefField = gpsDirectory
-				.findField(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
-		TiffField latitudeField = gpsDirectory
-				.findField(TiffConstants.GPS_TAG_GPS_LATITUDE);
-		TiffField longitudeRefField = gpsDirectory
-				.findField(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
-		TiffField longitudeField = gpsDirectory
-				.findField(TiffConstants.GPS_TAG_GPS_LONGITUDE);
-
-		if (latitudeRefField == null || latitudeField == null
-				|| longitudeRefField == null || longitudeField == null)
-			return null;
-
-		// all of these values are strings.
-		String latitudeRef = latitudeRefField.getStringValue();
-		RationalNumber latitude[] = (RationalNumber[]) latitudeField.getValue();
-		String longitudeRef = longitudeRefField.getStringValue();
-		RationalNumber longitude[] = (RationalNumber[]) longitudeField
-				.getValue();
-
-		if (latitude.length != 3 || longitude.length != 3)
-			throw new ImageReadException(
-					"Expected three values for latitude and longitude.");
-
-		RationalNumber latitudeDegrees = latitude[0];
-		RationalNumber latitudeMinutes = latitude[1];
-		RationalNumber latitudeSeconds = latitude[2];
-
-		RationalNumber longitudeDegrees = longitude[0];
-		RationalNumber longitudeMinutes = longitude[1];
-		RationalNumber longitudeSeconds = longitude[2];
-
-		return new GPSInfo(latitudeRef, longitudeRef, latitudeDegrees,
-				latitudeMinutes, latitudeSeconds, longitudeDegrees,
-				longitudeMinutes, longitudeSeconds);
-	}
-
-	public static class GPSInfo
-	{
-		public final String latitudeRef;
-		public final String longitudeRef;
-
-		public final RationalNumber latitudeDegrees;
-		public final RationalNumber latitudeMinutes;
-		public final RationalNumber latitudeSeconds;
-		public final RationalNumber longitudeDegrees;
-		public final RationalNumber longitudeMinutes;
-		public final RationalNumber longitudeSeconds;
-
-		public GPSInfo(final String latitudeRef, final String longitudeRef,
-				final RationalNumber latitudeDegrees,
-				final RationalNumber latitudeMinutes,
-				final RationalNumber latitudeSeconds,
-				final RationalNumber longitudeDegrees,
-				final RationalNumber longitudeMinutes,
-				final RationalNumber longitudeSeconds)
-		{
-			this.latitudeRef = latitudeRef;
-			this.longitudeRef = longitudeRef;
-			this.latitudeDegrees = latitudeDegrees;
-			this.latitudeMinutes = latitudeMinutes;
-			this.latitudeSeconds = latitudeSeconds;
-			this.longitudeDegrees = longitudeDegrees;
-			this.longitudeMinutes = longitudeMinutes;
-			this.longitudeSeconds = longitudeSeconds;
-		}
-
-		public String toString()
-		{
-			// This will format the gps info like so:
-			//
-			// latitude: 8 degrees, 40 minutes, 42.2 seconds S
-			// longitude: 115 degrees, 26 minutes, 21.8 seconds E
-
-			StringBuffer result = new StringBuffer();
-			result.append("[GPS. ");
-			result.append("Latitude: " + latitudeDegrees.toDisplayString()
-					+ " degrees, " + latitudeMinutes.toDisplayString()
-					+ " minutes, " + latitudeSeconds.toDisplayString()
-					+ " seconds " + latitudeRef);
-			result.append(", Longitude: " + longitudeDegrees.toDisplayString()
-					+ " degrees, " + longitudeMinutes.toDisplayString()
-					+ " minutes, " + longitudeSeconds.toDisplayString()
-					+ " seconds " + longitudeRef);
-			result.append("]");
-
-			return result.toString();
-		}
-
-		public double getLongitudeAsDegreesEast() throws ImageReadException
-		{
-			double result = longitudeDegrees.doubleValue()
-					+ (longitudeMinutes.doubleValue() / 60.0)
-					+ (longitudeSeconds.doubleValue() / 3600.0);
-
-			if (longitudeRef.trim().equalsIgnoreCase("e"))
-				return result;
-			else if (longitudeRef.trim().equalsIgnoreCase("w"))
-				return -result;
-			else
-				throw new ImageReadException("Unknown longitude ref: \""
-						+ longitudeRef + "\"");
-		}
-
-		public double getLatitudeAsDegreesNorth() throws ImageReadException
-		{
-			double result = latitudeDegrees.doubleValue()
-					+ (latitudeMinutes.doubleValue() / 60.0)
-					+ (latitudeSeconds.doubleValue() / 3600.0);
-
-			if (latitudeRef.trim().equalsIgnoreCase("n"))
-				return result;
-			else if (latitudeRef.trim().equalsIgnoreCase("s"))
-				return -result;
-			else
-				throw new ImageReadException("Unknown latitude ref: \""
-						+ latitudeRef + "\"");
-		}
+    public TiffImageMetadata(final TiffContents contents)
+    {
+        this.contents = contents;
+    }
+
+    public static class Directory extends ImageMetadata
+            implements
+                ImageMetadata.IImageMetadataItem
+    {
+        //        private BufferedImage thumbnail = null;
+
+        public final int type;
+
+        private final TiffDirectory directory;
+
+        public Directory(final TiffDirectory directory)
+        {
+            this.type = directory.type;
+            this.directory = directory;
+        }
+
+        public void add(TiffField entry)
+        {
+            add(new TiffImageMetadata.Item(entry));
+        }
+
+        public BufferedImage getThumbnail() throws ImageReadException,
+                IOException
+        {
+            return directory.getTiffImage();
+        }
+
+        public TiffImageData getTiffImageData()
+        {
+            return directory.getTiffImageData();
+        }
+
+        public TiffField findField(TagInfo tagInfo) throws ImageReadException
+        {
+            return directory.findField(tagInfo);
+        }
+
+        public List getAllFields() throws ImageReadException
+        {
+            return directory.getDirectoryEntrys();
+        }
+
+        public JpegImageData getJpegImageData()
+        {
+            return directory.getJpegImageData();
+        }
+
+        public String toString(String prefix)
+        {
+            return (prefix != null ? prefix : "") + directory.description()
+                    + ": " //
+                    + (getTiffImageData() != null ? " (tiffImageData)" : "") //
+                    + (getJpegImageData() != null ? " (jpegImageData)" : "") //
+                    + "\n" + super.toString(prefix) + "\n";
+        }
+
+        public TiffOutputDirectory getOutputDirectory(int byteOrder)
+                throws ImageWriteException
+        {
+            try
+            {
+                TiffOutputDirectory dstDir = new TiffOutputDirectory(type);
+
+                ArrayList entries = getItems();
+                for (int i = 0; i < entries.size(); i++)
+                {
+                    TiffImageMetadata.Item item = (TiffImageMetadata.Item) entries
+                            .get(i);
+                    TiffField srcField = item.getTiffField();
+
+                    if (null != dstDir.findField(srcField.tag))
+                    {
+                        // ignore duplicate tags in a directory.
+                        continue;
+                    }
+                    else if (srcField.tagInfo instanceof TagInfo.Offset)
+                    {
+                        // ignore offset fields.
+                        continue;
+                    }
+
+                    TagInfo tagInfo = srcField.tagInfo;
+                    FieldType fieldType = srcField.fieldType;
+                    int count = srcField.length;
+                    //            byte bytes[] = srcField.fieldType.getRawBytes(srcField);
+
+                    //                    Debug.debug("tagInfo", tagInfo);
+
+                    Object value = srcField.getValue();
+
+                    //                    Debug.debug("value", Debug.getType(value));
+
+                    byte bytes[] = tagInfo.encodeValue(fieldType, value,
+                            byteOrder);
+
+                    //                    if (tagInfo.isUnknown())
+                    //                        Debug.debug(
+                    //                                "\t" + "unknown tag(0x"
+                    //                                        + Integer.toHexString(srcField.tag)
+                    //                                        + ") bytes", bytes);
+
+                    TiffOutputField dstField = new TiffOutputField(
+                            srcField.tag, tagInfo, fieldType, count, bytes);
+                    dstField.setSortHint(srcField.getSortHint());
+                    dstDir.add(dstField);
+                }
+
+                dstDir.setTiffImageData(getTiffImageData());
+                dstDir.setJpegImageData(getJpegImageData());
+
+                return dstDir;
+            }
+            catch (ImageReadException e)
+            {
+                throw new ImageWriteException(e.getMessage(), e);
+            }
+        }
+
+    }
+
+    public ArrayList getDirectories()
+    {
+        return super.getItems();
+    }
+
+    public ArrayList getItems()
+    {
+        ArrayList result = new ArrayList();
+
+        ArrayList items = super.getItems();
+        for (int i = 0; i < items.size(); i++)
+        {
+            Directory dir = (Directory) items.get(i);
+            result.addAll(dir.getItems());
+        }
+
+        return result;
+    }
+
+    public static class Item extends ImageMetadata.Item
+    {
+        private final TiffField entry;
+
+        public Item(TiffField entry)
+        {
+            //            super(entry.getTagName() + " (" + entry.getFieldTypeName() + ")",
+            super(entry.getTagName(), entry.getValueDescription());
+            this.entry = entry;
+        }
+
+        public TiffField getTiffField()
+        {
+            return entry;
+        }
+
+    }
+
+    public TiffOutputSet getOutputSet() throws ImageWriteException
+    {
+        int byteOrder = contents.header.byteOrder;
+        TiffOutputSet result = new TiffOutputSet(byteOrder);
+
+        ArrayList srcDirs = getDirectories();
+        for (int i = 0; i < srcDirs.size(); i++)
+        {
+            TiffImageMetadata.Directory srcDir = (TiffImageMetadata.Directory) srcDirs
+                    .get(i);
+
+            if (null != result.findDirectory(srcDir.type))
+            {
+                // Certain cameras right directories more than once.
+                // This is a bug.
+                // Ignore second directory of a given type.
+                continue;
+            }
+
+            TiffOutputDirectory outputDirectory = srcDir
+                    .getOutputDirectory(byteOrder);
+            result.addDirectory(outputDirectory);
+        }
+
+        return result;
+    }
+
+    public TiffField findField(TagInfo tagInfo) throws ImageReadException
+    {
+        ArrayList directories = getDirectories();
+        for (int i = 0; i < directories.size(); i++)
+        {
+            Directory directory = (Directory) directories.get(i);
+            TiffField field = directory.findField(tagInfo);
+            if (null != field)
+                return field;
+        }
+        return null;
+    }
+
+    public TiffDirectory findDirectory(int directoryType)
+    {
+        ArrayList directories = getDirectories();
+        for (int i = 0; i < directories.size(); i++)
+        {
+            Directory directory = (Directory) directories.get(i);
+            if (directory.type == directoryType)
+                return directory.directory;
+        }
+        return null;
+    }
+
+    public List getAllFields() throws ImageReadException
+    {
+        List result = new ArrayList();
+        ArrayList directories = getDirectories();
+        for (int i = 0; i < directories.size(); i++)
+        {
+            Directory directory = (Directory) directories.get(i);
+            result.addAll(directory.getAllFields());
+        }
+        return result;
+    }
+
+    public GPSInfo getGPS() throws ImageReadException
+    {
+        TiffDirectory gpsDirectory = findDirectory(DIRECTORY_TYPE_GPS);
+        if (null == gpsDirectory)
+            return null;
+
+        // more specific example of how to access GPS values.
+        TiffField latitudeRefField = gpsDirectory
+                .findField(TiffConstants.GPS_TAG_GPS_LATITUDE_REF);
+        TiffField latitudeField = gpsDirectory
+                .findField(TiffConstants.GPS_TAG_GPS_LATITUDE);
+        TiffField longitudeRefField = gpsDirectory
+                .findField(TiffConstants.GPS_TAG_GPS_LONGITUDE_REF);
+        TiffField longitudeField = gpsDirectory
+                .findField(TiffConstants.GPS_TAG_GPS_LONGITUDE);
+
+        if (latitudeRefField == null || latitudeField == null
+                || longitudeRefField == null || longitudeField == null)
+            return null;
+
+        // all of these values are strings.
+        String latitudeRef = latitudeRefField.getStringValue();
+        RationalNumber latitude[] = (RationalNumber[]) latitudeField.getValue();
+        String longitudeRef = longitudeRefField.getStringValue();
+        RationalNumber longitude[] = (RationalNumber[]) longitudeField
+                .getValue();
+
+        if (latitude.length != 3 || longitude.length != 3)
+            throw new ImageReadException(
+                    "Expected three values for latitude and longitude.");
+
+        RationalNumber latitudeDegrees = latitude[0];
+        RationalNumber latitudeMinutes = latitude[1];
+        RationalNumber latitudeSeconds = latitude[2];
+
+        RationalNumber longitudeDegrees = longitude[0];
+        RationalNumber longitudeMinutes = longitude[1];
+        RationalNumber longitudeSeconds = longitude[2];
+
+        return new GPSInfo(latitudeRef, longitudeRef, latitudeDegrees,
+                latitudeMinutes, latitudeSeconds, longitudeDegrees,
+                longitudeMinutes, longitudeSeconds);
+    }
+
+    public static class GPSInfo
+    {
+        public final String latitudeRef;
+        public final String longitudeRef;
+
+        public final RationalNumber latitudeDegrees;
+        public final RationalNumber latitudeMinutes;
+        public final RationalNumber latitudeSeconds;
+        public final RationalNumber longitudeDegrees;
+        public final RationalNumber longitudeMinutes;
+        public final RationalNumber longitudeSeconds;
+
+        public GPSInfo(final String latitudeRef, final String longitudeRef,
+                final RationalNumber latitudeDegrees,
+                final RationalNumber latitudeMinutes,
+                final RationalNumber latitudeSeconds,
+                final RationalNumber longitudeDegrees,
+                final RationalNumber longitudeMinutes,
+                final RationalNumber longitudeSeconds)
+        {
+            this.latitudeRef = latitudeRef;
+            this.longitudeRef = longitudeRef;
+            this.latitudeDegrees = latitudeDegrees;
+            this.latitudeMinutes = latitudeMinutes;
+            this.latitudeSeconds = latitudeSeconds;
+            this.longitudeDegrees = longitudeDegrees;
+            this.longitudeMinutes = longitudeMinutes;
+            this.longitudeSeconds = longitudeSeconds;
+        }
+
+        public String toString()
+        {
+            // This will format the gps info like so:
+            //
+            // latitude: 8 degrees, 40 minutes, 42.2 seconds S
+            // longitude: 115 degrees, 26 minutes, 21.8 seconds E
+
+            StringBuffer result = new StringBuffer();
+            result.append("[GPS. ");
+            result.append("Latitude: " + latitudeDegrees.toDisplayString()
+                    + " degrees, " + latitudeMinutes.toDisplayString()
+                    + " minutes, " + latitudeSeconds.toDisplayString()
+                    + " seconds " + latitudeRef);
+            result.append(", Longitude: " + longitudeDegrees.toDisplayString()
+                    + " degrees, " + longitudeMinutes.toDisplayString()
+                    + " minutes, " + longitudeSeconds.toDisplayString()
+                    + " seconds " + longitudeRef);
+            result.append("]");
+
+            return result.toString();
+        }
+
+        public double getLongitudeAsDegreesEast() throws ImageReadException
+        {
+            double result = longitudeDegrees.doubleValue()
+                    + (longitudeMinutes.doubleValue() / 60.0)
+                    + (longitudeSeconds.doubleValue() / 3600.0);
+
+            if (longitudeRef.trim().equalsIgnoreCase("e"))
+                return result;
+            else if (longitudeRef.trim().equalsIgnoreCase("w"))
+                return -result;
+            else
+                throw new ImageReadException("Unknown longitude ref: \""
+                        + longitudeRef + "\"");
+        }
+
+        public double getLatitudeAsDegreesNorth() throws ImageReadException
+        {
+            double result = latitudeDegrees.doubleValue()
+                    + (latitudeMinutes.doubleValue() / 60.0)
+                    + (latitudeSeconds.doubleValue() / 3600.0);
+
+            if (latitudeRef.trim().equalsIgnoreCase("n"))
+                return result;
+            else if (latitudeRef.trim().equalsIgnoreCase("s"))
+                return -result;
+            else
+                throw new ImageReadException("Unknown latitude ref: \""
+                        + latitudeRef + "\"");
+        }
 
-	}
+    }
 
 }
\ No newline at end of file