You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sanselan-commits@incubator.apache.org by cm...@apache.org on 2008/05/25 13:57:44 UTC

svn commit: r659985 [1/2] - in /incubator/sanselan/trunk/src/main/java/org/apache/sanselan: ./ common/ formats/bmp/ formats/gif/ formats/ico/ formats/jpeg/ formats/png/ formats/pnm/ formats/psd/ formats/tiff/ formats/tiff/write/

Author: cmchen
Date: Sun May 25 06:57:43 2008
New Revision: 659985

URL: http://svn.apache.org/viewvc?rev=659985&view=rev
Log:
Small fix around parsing of invalid TIFF metadata in JPEG files.  Added a "strict" flag to the parameter sets of certain read methods.  When not in strict mode, Sanselan will ignore minor problems in image files that it parses.  Sanselan now defaults to strict=false.

see: https://issues.apache.org/jira/browse/SANSELAN-3

Modified:
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ColorTools.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageFormat.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/Sanselan.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/SanselanConstants.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/bmp/BmpImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/ico/IcoImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/jpeg/JpegImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/png/PngImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/pnm/PNMImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PsdImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffField.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffImageParser.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/TiffReader.java
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/tiff/write/TiffImageWriterLossless.java

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ColorTools.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ColorTools.java?rev=659985&r1=659984&r2=659985&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ColorTools.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ColorTools.java Sun May 25 06:57:43 2008
@@ -37,12 +37,10 @@
 /**
  * This class is a mess and needs to be cleaned up.
  */
-public class ColorTools
-{
+public class ColorTools {
 
 	public BufferedImage correctImage(BufferedImage src, File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		ICC_Profile icc = Sanselan.getICCProfile(file);
 		if (icc == null)
 			return src;
@@ -53,72 +51,19 @@
 		return dst;
 	}
 
-	public BufferedImage correctImageX2(BufferedImage src, byte bytes[])
-			throws ImageReadException, IOException
-	{
-		return correctImageX2(src, new ByteSourceArray(bytes));
-	}
-
-	public BufferedImage correctImageX2(BufferedImage src, File file)
-			throws ImageReadException, IOException
-	{
-		return correctImageX2(src, new ByteSourceFile(file));
-	}
-
-	public BufferedImage correctImageX2(BufferedImage src,
-			ByteSource byte_source) throws ImageReadException, IOException
-	{
-		ICC_Profile icc = Sanselan.getICCProfile(byte_source);
-		if (icc == null)
-			return src;
-
-		ICC_ColorSpace cs = new ICC_ColorSpace(icc);
-
-		ColorSpace cs_sRGB;
-		cs_sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
-
-		BufferedImage dst = convertBetweenColorSpacesX2(src, cs, cs_sRGB);
-
-		return dst;
-	}
-
-	public BufferedImage relabelColorSpace(BufferedImage bi, File file)
-			throws ImagingOpException, ImageReadException, IOException
-	{
-		return relabelColorSpace(bi, new ByteSourceFile(file));
-	}
-
-	public BufferedImage relabelColorSpace(BufferedImage bi, byte bytes[])
-			throws ImagingOpException, ImageReadException, IOException
-	{
-		return relabelColorSpace(bi, new ByteSourceArray(bytes));
-	}
-
-	private final BufferedImage relabelColorSpace(BufferedImage bi,
-			ByteSource byte_source) throws ImagingOpException,
-			ImageReadException, IOException
-	{
-		ICC_Profile icc = Sanselan.getICCProfile(byte_source);
-		if (icc == null)
-			return bi;
-
-		return relabelColorSpace(bi, icc);
-	}
-
 	public BufferedImage relabelColorSpace(BufferedImage bi, ICC_Profile profile)
-			throws ImagingOpException
-	{
+			throws ImagingOpException {
 		ICC_ColorSpace cs = new ICC_ColorSpace(profile);
 
 		return relabelColorSpace(bi, cs);
 	}
 
 	public BufferedImage relabelColorSpace(BufferedImage bi, ColorSpace cs)
-			throws ImagingOpException
-	{
-		// This does not do the conversion.  It tries to relabel the BufferedImage
+			throws ImagingOpException {
+		// This does not do the conversion. It tries to relabel the
+		// BufferedImage
 		// with its actual (presumably correct) Colorspace.
-		// use this when the image is mislabeled, presumably having been 
+		// use this when the image is mislabeled, presumably having been
 		// wrongly assumed to be sRGB
 
 		ColorModel cm = deriveColorModel(bi, cs);
@@ -128,11 +73,11 @@
 	}
 
 	public BufferedImage relabelColorSpace(BufferedImage bi, ColorModel cm)
-			throws ImagingOpException
-	{
-		// This does not do the conversion.  It tries to relabel the BufferedImage
+			throws ImagingOpException {
+		// This does not do the conversion. It tries to relabel the
+		// BufferedImage
 		// with its actual (presumably correct) Colorspace.
-		// use this when the image is mislabeled, presumably having been 
+		// use this when the image is mislabeled, presumably having been
 		// wrongly assumed to be sRGB
 
 		BufferedImage result = new BufferedImage(cm, bi.getRaster(), false,
@@ -142,26 +87,22 @@
 	}
 
 	public ColorModel deriveColorModel(BufferedImage bi, ColorSpace cs)
-			throws ImagingOpException
-	{
-		//		boolean hasAlpha = (bi.getAlphaRaster() != null);
+			throws ImagingOpException {
+		// boolean hasAlpha = (bi.getAlphaRaster() != null);
 		return deriveColorModel(bi, cs, false);
 	}
 
 	public ColorModel deriveColorModel(BufferedImage bi, ColorSpace cs,
-			boolean force_no_alpha) throws ImagingOpException
-	{
+			boolean force_no_alpha) throws ImagingOpException {
 		return deriveColorModel(bi.getColorModel(), cs, force_no_alpha);
 	}
 
 	public ColorModel deriveColorModel(ColorModel old_cm, ColorSpace cs,
-			boolean force_no_alpha) throws ImagingOpException
-	{
+			boolean force_no_alpha) throws ImagingOpException {
 
-		if (old_cm instanceof ComponentColorModel)
-		{
+		if (old_cm instanceof ComponentColorModel) {
 			ComponentColorModel ccm = (ComponentColorModel) old_cm;
-			//				ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
+			// ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
 			if (force_no_alpha)
 				return new ComponentColorModel(cs, false, false,
 						ComponentColorModel.OPAQUE, ccm.getTransferType());
@@ -169,9 +110,7 @@
 				return new ComponentColorModel(cs, ccm.hasAlpha(), ccm
 						.isAlphaPremultiplied(), ccm.getTransparency(), ccm
 						.getTransferType());
-		}
-		else if (old_cm instanceof DirectColorModel)
-		{
+		} else if (old_cm instanceof DirectColorModel) {
 			DirectColorModel dcm = (DirectColorModel) old_cm;
 
 			int old_mask = dcm.getRedMask() | dcm.getGreenMask()
@@ -183,33 +122,33 @@
 					.getGreenMask(), dcm.getBlueMask(), dcm.getAlphaMask(), dcm
 					.isAlphaPremultiplied(), dcm.getTransferType());
 		}
-		//		else if (old_cm instanceof PackedColorModel)
-		//		{
-		//			PackedColorModel pcm = (PackedColorModel) old_cm;
+		// else if (old_cm instanceof PackedColorModel)
+		// {
+		// PackedColorModel pcm = (PackedColorModel) old_cm;
 		//
-		//			//			int old_mask = dcm.getRedMask() | dcm.getGreenMask()
-		//			//					| dcm.getBlueMask() | dcm.getAlphaMask();
+		// // int old_mask = dcm.getRedMask() | dcm.getGreenMask()
+		// // | dcm.getBlueMask() | dcm.getAlphaMask();
 		//
-		//			int old_masks[] = pcm.getMasks();
-		//			//			System.out.println("old_mask: " + old_mask);
-		//			int old_bits = count_bits_in_mask(old_masks);
-		//			//			System.out.println("old_bits: " + old_bits);
+		// int old_masks[] = pcm.getMasks();
+		// // System.out.println("old_mask: " + old_mask);
+		// int old_bits = count_bits_in_mask(old_masks);
+		// // System.out.println("old_bits: " + old_bits);
 		//
-		//			//			PackedColorModel(ColorSpace space, int bits, int rmask, int gmask, int bmask, int amask, boolean isAlphaPremultiplied, int trans, int transferType) 
-		//			cm = new PackedColorModel(cs, old_bits, pcm.getMasks(),
+		// // PackedColorModel(ColorSpace space, int bits, int rmask, int gmask,
+		// int bmask, int amask, boolean isAlphaPremultiplied, int trans, int
+		// transferType)
+		// cm = new PackedColorModel(cs, old_bits, pcm.getMasks(),
 		//
-		//			pcm.isAlphaPremultiplied(), pcm.getTransparency(), pcm
-		//					.getTransferType());
-		//		}
+		// pcm.isAlphaPremultiplied(), pcm.getTransparency(), pcm
+		// .getTransferType());
+		// }
 
 		throw new ImagingOpException("Could not clone unknown ColorModel Type.");
 	}
 
-	private int count_bits_in_mask(int i)
-	{
+	private int count_bits_in_mask(int i) {
 		int count = 0;
-		while (i != 0)
-		{
+		while (i != 0) {
 			count += (i & 1);
 			// uses the unsigned version of java's right shift operator,
 			// so that left hand bits are zeroed.
@@ -218,8 +157,7 @@
 		return count;
 	}
 
-	public BufferedImage convertToColorSpace(BufferedImage bi, ColorSpace to)
-	{
+	public BufferedImage convertToColorSpace(BufferedImage bi, ColorSpace to) {
 		ColorSpace from = bi.getColorModel().getColorSpace();
 
 		RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING,
@@ -238,8 +176,7 @@
 		return result;
 	}
 
-	public BufferedImage convertTosRGB(BufferedImage bi)
-	{
+	public BufferedImage convertTosRGB(BufferedImage bi) {
 		ColorSpace cs_sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB);
 
 		ColorModel srgbCM = ColorModel.getRGBdefault();
@@ -249,8 +186,7 @@
 	}
 
 	protected BufferedImage convertFromColorSpace(BufferedImage bi,
-			ColorSpace from)
-	{
+			ColorSpace from) {
 		ColorSpace cs_sRGB;
 
 		ColorModel srgbCM = ColorModel.getRGBdefault();
@@ -261,24 +197,21 @@
 	}
 
 	public BufferedImage convertBetweenICCProfiles(BufferedImage bi,
-			ICC_Profile from, ICC_Profile to)
-	{
+			ICC_Profile from, ICC_Profile to) {
 		ICC_ColorSpace cs_from = new ICC_ColorSpace(from);
 		ICC_ColorSpace cs_to = new ICC_ColorSpace(to);
 
 		return convertBetweenColorSpaces(bi, cs_from, cs_to);
 	}
 
-	public BufferedImage convertToICCProfile(BufferedImage bi, ICC_Profile to)
-	{
+	public BufferedImage convertToICCProfile(BufferedImage bi, ICC_Profile to) {
 		ICC_ColorSpace cs_to = new ICC_ColorSpace(to);
 
 		return convertToColorSpace(bi, cs_to);
 	}
 
 	public BufferedImage convertBetweenColorSpacesX2(BufferedImage bi,
-			ColorSpace from, ColorSpace to)
-	{
+			ColorSpace from, ColorSpace to) {
 		RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING,
 				RenderingHints.VALUE_RENDER_QUALITY);
 		hints.put(RenderingHints.KEY_COLOR_RENDERING,
@@ -286,9 +219,10 @@
 		hints.put(RenderingHints.KEY_DITHERING,
 				RenderingHints.VALUE_DITHER_ENABLE);
 
-		//			bi = relabelColorSpace(bi, cs);
-		//			dumpColorSpace("\tcs_sRGB", cs_sRGB);
-		//			dumpColorSpace("\tColorModel.getRGBdefaultc", ColorModel.getRGBdefault().getColorSpace());
+		// bi = relabelColorSpace(bi, cs);
+		// dumpColorSpace("\tcs_sRGB", cs_sRGB);
+		// dumpColorSpace("\tColorModel.getRGBdefaultc",
+		// ColorModel.getRGBdefault().getColorSpace());
 
 		bi = relabelColorSpace(bi, from);
 		ColorConvertOp op = new ColorConvertOp(from, to, hints);
@@ -305,8 +239,7 @@
 	}
 
 	public BufferedImage convertBetweenColorSpaces(BufferedImage bi,
-			ColorSpace from, ColorSpace to)
-	{
+			ColorSpace from, ColorSpace to) {
 		RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING,
 				RenderingHints.VALUE_RENDER_QUALITY);
 		hints.put(RenderingHints.KEY_COLOR_RENDERING,

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageFormat.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageFormat.java?rev=659985&r1=659984&r2=659985&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageFormat.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageFormat.java Sun May 25 06:57:43 2008
@@ -71,6 +71,7 @@
 	public static final ImageFormat IMAGE_FORMAT_PPM = new ImageFormat("PPM");
 	public static final ImageFormat IMAGE_FORMAT_PNM = new ImageFormat("PNM");
 	public static final ImageFormat IMAGE_FORMAT_TGA = new ImageFormat("TGA");
+	public static final ImageFormat IMAGE_FORMAT_JBIG2 = new ImageFormat("JBig2");
 
 	public static final ImageFormat[] getAllFormats()
 	{
@@ -79,6 +80,7 @@
 				IMAGE_FORMAT_TIFF, IMAGE_FORMAT_JPEG, IMAGE_FORMAT_BMP,
 				IMAGE_FORMAT_PSD, IMAGE_FORMAT_PBM, IMAGE_FORMAT_PGM,
 				IMAGE_FORMAT_PPM, IMAGE_FORMAT_PNM, IMAGE_FORMAT_TGA,
+				IMAGE_FORMAT_JBIG2,
 		};
 
 		return result;

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java?rev=659985&r1=659984&r2=659985&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java Sun May 25 06:57:43 2008
@@ -36,6 +36,7 @@
 import org.apache.sanselan.formats.bmp.BmpImageParser;
 import org.apache.sanselan.formats.gif.GifImageParser;
 import org.apache.sanselan.formats.ico.IcoImageParser;
+import org.apache.sanselan.formats.jbig2.JBig2ImageParser;
 import org.apache.sanselan.formats.jpeg.JpegImageParser;
 import org.apache.sanselan.formats.png.PngImageParser;
 import org.apache.sanselan.formats.pnm.PNMImageParser;
@@ -43,27 +44,23 @@
 import org.apache.sanselan.formats.tiff.TiffImageParser;
 import org.apache.sanselan.util.Debug;
 
-public abstract class ImageParser extends BinaryFileParser
-		implements
-			SanselanConstants
-{
-
-	public static final ImageParser[] getAllImageParsers()
-	{
-		ImageParser result[] = {
-				new JpegImageParser(), new TiffImageParser(),
+public abstract class ImageParser extends BinaryFileParser implements
+		SanselanConstants {
+
+	public static final ImageParser[] getAllImageParsers() {
+		ImageParser result[] = { new JpegImageParser(), new TiffImageParser(),
 				new PngImageParser(), new BmpImageParser(),
 				new GifImageParser(), new PsdImageParser(),
 				new PNMImageParser(), new IcoImageParser(),
-		//				new TgaImageParser(),
+				new JBig2ImageParser(),
+		// new TgaImageParser(),
 		};
 
 		return result;
 	}
 
 	public final IImageMetadata getMetadata(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(byteSource, null);
 	}
 
@@ -71,26 +68,22 @@
 			throws ImageReadException, IOException;
 
 	public final IImageMetadata getMetadata(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(bytes);
 	}
 
 	public final IImageMetadata getMetadata(byte bytes[], Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(new ByteSourceArray(bytes), params);
 	}
 
 	public final IImageMetadata getMetadata(File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(file, null);
 	}
 
 	public final IImageMetadata getMetadata(File file, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		if (debug)
 			System.out.println(getName() + ".getMetadata" + ": "
 					+ file.getName());
@@ -105,20 +98,17 @@
 			throws ImageReadException, IOException;
 
 	public final ImageInfo getImageInfo(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getImageInfo(byteSource, null);
 	}
 
 	public final ImageInfo getImageInfo(byte bytes[], Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getImageInfo(new ByteSourceArray(bytes), params);
 	}
 
 	public final ImageInfo getImageInfo(File file, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		if (!canAcceptExtension(file))
 			return null;
 
@@ -126,20 +116,17 @@
 	}
 
 	public FormatCompliance getFormatCompliance(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return null;
 	}
 
 	public final FormatCompliance getFormatCompliance(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getFormatCompliance(new ByteSourceArray(bytes));
 	}
 
 	public final FormatCompliance getFormatCompliance(File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		if (!canAcceptExtension(file))
 			return null;
 
@@ -147,8 +134,7 @@
 	}
 
 	public ArrayList getAllBufferedImages(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		BufferedImage bi = getBufferedImage(byteSource, null);
 
 		ArrayList result = new ArrayList();
@@ -159,73 +145,69 @@
 	}
 
 	public final ArrayList getAllBufferedImages(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getAllBufferedImages(new ByteSourceArray(bytes));
 	}
 
 	public final ArrayList getAllBufferedImages(File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		if (!canAcceptExtension(file))
 			return null;
 
 		return getAllBufferedImages(new ByteSourceFile(file));
 	}
 
-	//	public boolean extractImages(ByteSource byteSource, File dstDir,
-	//			String dstRoot, ImageParser encoder) throws ImageReadException,
-	//			IOException, ImageWriteException
-	//	{
-	//		ArrayList v = getAllBufferedImages(byteSource);
+	// public boolean extractImages(ByteSource byteSource, File dstDir,
+	// String dstRoot, ImageParser encoder) throws ImageReadException,
+	// IOException, ImageWriteException
+	// {
+	// ArrayList v = getAllBufferedImages(byteSource);
 	//
-	//		if (v == null)
-	//			return false;
+	// if (v == null)
+	// return false;
 	//
-	//		for (int i = 0; i < v.size(); i++)
-	//		{
-	//			BufferedImage image = (BufferedImage) v.get(i);
-	//			File file = new File(dstDir, dstRoot + "_" + i
-	//					+ encoder.getDefaultExtension());
-	//			encoder.writeImage(image, new FileOutputStream(file), null);
-	//		}
+	// for (int i = 0; i < v.size(); i++)
+	// {
+	// BufferedImage image = (BufferedImage) v.get(i);
+	// File file = new File(dstDir, dstRoot + "_" + i
+	// + encoder.getDefaultExtension());
+	// encoder.writeImage(image, new FileOutputStream(file), null);
+	// }
 	//
-	//		return false;
-	//	}
+	// return false;
+	// }
 	//
-	//	public final boolean extractImages(byte bytes[], File dstDir,
-	//			String dstRoot, ImageParser encoder)
+	// public final boolean extractImages(byte bytes[], File dstDir,
+	// String dstRoot, ImageParser encoder)
 	//
-	//	throws ImageReadException, IOException, ImageWriteException
-	//	{
-	//		return extractImages(new ByteSourceArray(bytes), dstDir, dstRoot,
-	//				encoder);
-	//	}
+	// throws ImageReadException, IOException, ImageWriteException
+	// {
+	// return extractImages(new ByteSourceArray(bytes), dstDir, dstRoot,
+	// encoder);
+	// }
 	//
-	//	public final boolean extractImages(File file, File dstDir,
-	//			String dstRoot, ImageParser encoder)
+	// public final boolean extractImages(File file, File dstDir,
+	// String dstRoot, ImageParser encoder)
 	//
-	//	throws ImageReadException, IOException, ImageWriteException
-	//	{
-	//		if (!canAcceptExtension(file))
-	//			return false;
+	// throws ImageReadException, IOException, ImageWriteException
+	// {
+	// if (!canAcceptExtension(file))
+	// return false;
 	//
-	//		return extractImages(new ByteSourceFile(file), dstDir, dstRoot,
-	//				encoder);
-	//	}
+	// return extractImages(new ByteSourceFile(file), dstDir, dstRoot,
+	// encoder);
+	// }
 
 	public abstract BufferedImage getBufferedImage(ByteSource byteSource,
 			Map params) throws ImageReadException, IOException;
 
 	public final BufferedImage getBufferedImage(byte bytes[], Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getBufferedImage(new ByteSourceArray(bytes), params);
 	}
 
 	public final BufferedImage getBufferedImage(File file, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		if (!canAcceptExtension(file))
 			return null;
 
@@ -233,14 +215,10 @@
 	}
 
 	public void writeImage(BufferedImage src, OutputStream os, Map params)
-			throws ImageWriteException, IOException
-	{
-		try
-		{
+			throws ImageWriteException, IOException {
+		try {
 			os.close(); // we are obligated to close stream.
-		}
-		catch (Exception e)
-		{
+		} catch (Exception e) {
 			Debug.debug(e);
 		}
 
@@ -249,57 +227,69 @@
 	}
 
 	public final Dimension getImageSize(byte bytes[])
-			throws ImageReadException, IOException
-	{
-		return getImageSize(new ByteSourceArray(bytes));
+			throws ImageReadException, IOException {
+		return getImageSize(bytes, null);
+	}
+
+	public final Dimension getImageSize(byte bytes[], Map params)
+			throws ImageReadException, IOException {
+		return getImageSize(new ByteSourceArray(bytes), params);
 	}
 
 	public final Dimension getImageSize(File file) throws ImageReadException,
-			IOException
-	{
-		if (debug)
-			System.out.println("JpegIccAdapterCustom.getSize" + ": "
-					+ file.getName());
+			IOException {
+
+		return getImageSize(file, null);
+	}
+
+	public final Dimension getImageSize(File file, Map params)
+			throws ImageReadException, IOException {
 
 		if (!canAcceptExtension(file))
 			return null;
 
-		return getImageSize(new ByteSourceFile(file));
+		return getImageSize(new ByteSourceFile(file), params);
 	}
 
-	public abstract Dimension getImageSize(ByteSource byteSource)
+	public abstract Dimension getImageSize(ByteSource byteSource, Map params)
 			throws ImageReadException, IOException;
 
 	public final byte[] getICCProfileBytes(byte bytes[])
-			throws ImageReadException, IOException
-	{
-		return getICCProfileBytes(new ByteSourceArray(bytes));
+			throws ImageReadException, IOException {
+		return getICCProfileBytes(bytes, null);
+	}
+
+	public final byte[] getICCProfileBytes(byte bytes[], Map params)
+			throws ImageReadException, IOException {
+		return getICCProfileBytes(new ByteSourceArray(bytes), params);
 	}
 
 	public final byte[] getICCProfileBytes(File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
+		return getICCProfileBytes(file, null);
+	}
+
+	public final byte[] getICCProfileBytes(File file, Map params)
+			throws ImageReadException, IOException {
 		if (!canAcceptExtension(file))
 			return null;
 
 		if (debug)
 			System.out.println(getName() + ": " + file.getName());
 
-		return getICCProfileBytes(new ByteSourceFile(file));
+		return getICCProfileBytes(new ByteSourceFile(file), params);
 	}
 
-	public abstract byte[] getICCProfileBytes(ByteSource byteSource)
+	public abstract byte[] getICCProfileBytes(ByteSource byteSource, Map params)
 			throws ImageReadException, IOException;
 
 	public final String dumpImageFile(byte bytes[]) throws ImageReadException,
-			IOException
-	{
+			IOException {
 		return dumpImageFile(new ByteSourceArray(bytes));
 	}
 
 	public final String dumpImageFile(File file) throws ImageReadException,
-			IOException
-	{
+			IOException {
 		if (!canAcceptExtension(file))
 			return null;
 
@@ -310,8 +300,7 @@
 	}
 
 	public final String dumpImageFile(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		StringWriter sw = new StringWriter();
 		PrintWriter pw = new PrintWriter(sw);
 
@@ -323,8 +312,7 @@
 	}
 
 	public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return false;
 	}
 
@@ -338,8 +326,7 @@
 
 	protected abstract ImageFormat[] getAcceptedTypes();
 
-	public boolean canAcceptType(ImageFormat type)
-	{
+	public boolean canAcceptType(ImageFormat type) {
 		ImageFormat types[] = getAcceptedTypes();
 
 		for (int i = 0; i < types.length; i++)
@@ -348,20 +335,17 @@
 		return false;
 	}
 
-	protected final boolean canAcceptExtension(File file)
-	{
+	protected final boolean canAcceptExtension(File file) {
 		return canAcceptExtension(file.getName());
 	}
 
-	protected final boolean canAcceptExtension(String filename)
-	{
+	protected final boolean canAcceptExtension(String filename) {
 		String exts[] = getAcceptedExtensions();
 		if (exts == null)
 			return true;
 
 		int index = filename.lastIndexOf('.');
-		if (index >= 0)
-		{
+		if (index >= 0) {
 			String ext = filename.substring(index);
 			ext = ext.toLowerCase();
 
@@ -372,8 +356,7 @@
 		return false;
 	}
 
-	protected IBufferedImageFactory getBufferedImageFactory(Map params)
-	{
+	protected IBufferedImageFactory getBufferedImageFactory(Map params) {
 		if (params == null)
 			return new SimpleBufferedImageFactory();
 
@@ -386,4 +369,9 @@
 		return new SimpleBufferedImageFactory();
 	}
 
+	public static final boolean isStrict(Map params) {
+		if (params == null || !params.containsKey(PARAM_KEY_STRICT))
+			return false;
+		return ((Boolean) params.get(PARAM_KEY_STRICT)).booleanValue();
+	}
 }
\ No newline at end of file

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/Sanselan.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/Sanselan.java?rev=659985&r1=659984&r2=659985&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/Sanselan.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/Sanselan.java Sun May 25 06:57:43 2008
@@ -42,55 +42,57 @@
 /**
  * The primary interface to the sanselan library.
  * <p>
- * Almost all of the Sanselan library's core functionality can be accessed through it's methods.
+ * Almost all of the Sanselan library's core functionality can be accessed
+ * through it's methods.
  * <p>
  * All of Sanselan's methods are static.
  * <p>
- * See the source of the SampleUsage class and other classes in the org.apache.sanselan.sampleUsage 
- * package for examples.
+ * See the source of the SampleUsage class and other classes in the
+ * org.apache.sanselan.sampleUsage package for examples.
  * 
  * @see org.apache.sanselan.sampleUsage.SampleUsage
  */
-public abstract class Sanselan implements SanselanConstants
-{
+public abstract class Sanselan implements SanselanConstants {
 
-	/** 
-	 * Tries to guess whether a file contains an image based on its file extension.
+	/**
+	 * Tries to guess whether a file contains an image based on its file
+	 * extension.
 	 * <p>
-	 * Returns true if the file has a file extension associated with 
-	 *  a file format, such as .jpg or .gif.
+	 * Returns true if the file has a file extension associated with a file
+	 * format, such as .jpg or .gif.
 	 * <p>
-	 * @param  file  File which may contain an image.
-	 * @return      true if the file has an image format file extension.
+	 * 
+	 * @param file
+	 *            File which may contain an image.
+	 * @return true if the file has an image format file extension.
 	 */
-	public static boolean hasImageFileExtension(File file)
-	{
+	public static boolean hasImageFileExtension(File file) {
 		if (!file.isFile())
 			return false;
 		return hasImageFileExtension(file.getName());
 	}
 
-	/** 
-	 * Tries to guess whether a filename represents an image based on its file extension.
-	 * <p>
-	 * Returns true if the filename has a file extension associated with 
-	 *  a file format, such as .jpg or .gif.
-	 * <p>
-	 * @param  filename  String representing name of file which may contain an image.
-	 * @return      true if the filename has an image format file extension.
+	/**
+	 * Tries to guess whether a filename represents an image based on its file
+	 * extension.
+	 * <p>
+	 * Returns true if the filename has a file extension associated with a file
+	 * format, such as .jpg or .gif.
+	 * <p>
+	 * 
+	 * @param filename
+	 *            String representing name of file which may contain an image.
+	 * @return true if the filename has an image format file extension.
 	 */
-	public static boolean hasImageFileExtension(String filename)
-	{
+	public static boolean hasImageFileExtension(String filename) {
 		filename = filename.toLowerCase();
 
 		ImageParser imageParsers[] = ImageParser.getAllImageParsers();
-		for (int i = 0; i < imageParsers.length; i++)
-		{
+		for (int i = 0; i < imageParsers.length; i++) {
 			ImageParser imageParser = imageParsers[i];
 			String exts[] = imageParser.getAcceptedExtensions();
 
-			for (int j = 0; j < exts.length; j++)
-			{
+			for (int j = 0; j < exts.length; j++) {
 				String ext = exts[j];
 				if (filename.endsWith(ext.toLowerCase()))
 					return true;
@@ -100,41 +102,43 @@
 		return false;
 	}
 
-	/** 
-	 * Tries to guess what the image type (if any) of data based on the 
-	 * file's "magic numbers," the first bytes of the data. 
-	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      An ImageFormat, such as ImageFormat.IMAGE_FORMAT_JPEG.
-	 * 				Returns ImageFormat.IMAGE_FORMAT_UNKNOWN if the image type cannot be guessed.
+	/**
+	 * Tries to guess what the image type (if any) of data based on the file's
+	 * "magic numbers," the first bytes of the data.
+	 * <p>
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return An ImageFormat, such as ImageFormat.IMAGE_FORMAT_JPEG. Returns
+	 *         ImageFormat.IMAGE_FORMAT_UNKNOWN if the image type cannot be
+	 *         guessed.
 	 */
 	public static ImageFormat guessFormat(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return guessFormat(new ByteSourceArray(bytes));
 	}
 
-	/** 
-	 * Tries to guess what the image type (if any) of a file based on the 
-	 * file's "magic numbers," the first bytes of the file. 
-	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      An ImageFormat, such as ImageFormat.IMAGE_FORMAT_JPEG.
-	 * 				Returns ImageFormat.IMAGE_FORMAT_UNKNOWN if the image type cannot be guessed.
+	/**
+	 * Tries to guess what the image type (if any) of a file based on the file's
+	 * "magic numbers," the first bytes of the file.
+	 * <p>
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return An ImageFormat, such as ImageFormat.IMAGE_FORMAT_JPEG. Returns
+	 *         ImageFormat.IMAGE_FORMAT_UNKNOWN if the image type cannot be
+	 *         guessed.
 	 */
 	public static ImageFormat guessFormat(File file) throws ImageReadException,
-			IOException
-	{
+			IOException {
 		return guessFormat(new ByteSourceFile(file));
 	}
 
-	private static ImageFormat guessFormat(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+	public static ImageFormat guessFormat(ByteSource byteSource)
+			throws ImageReadException, IOException {
 		InputStream is = null;
 
-		try
-		{
+		try {
 			is = byteSource.getInputStream();
 
 			int i1 = is.read();
@@ -146,76 +150,61 @@
 			int b1 = i1 & 0xff;
 			int b2 = i2 & 0xff;
 
-			if (b1 == 0x47 && b2 == 0x49)
-			{
+			if (b1 == 0x47 && b2 == 0x49) {
 				return ImageFormat.IMAGE_FORMAT_GIF;
 			}
-			//			else if (b1 == 0x00 && b2 == 0x00)  // too similar to tga
-			//			{
-			//				return ImageFormat.IMAGE_FORMAT_ICO;
-			//			}
-			else if (b1 == 0x89 && b2 == 0x50)
-			{
+			// else if (b1 == 0x00 && b2 == 0x00) // too similar to tga
+			// {
+			// return ImageFormat.IMAGE_FORMAT_ICO;
+			// }
+			else if (b1 == 0x89 && b2 == 0x50) {
 				return ImageFormat.IMAGE_FORMAT_PNG;
-			}
-			else if (b1 == 0xff && b2 == 0xd8)
-			{
+			} else if (b1 == 0xff && b2 == 0xd8) {
 				return ImageFormat.IMAGE_FORMAT_JPEG;
-			}
-			else if (b1 == 0x42 && b2 == 0x4d)
-			{
+			} else if (b1 == 0x42 && b2 == 0x4d) {
 				return ImageFormat.IMAGE_FORMAT_BMP;
-			}
-			else if (b1 == 0x4D && b2 == 0x4D) // Motorola byte order TIFF
+			} else if (b1 == 0x4D && b2 == 0x4D) // Motorola byte order TIFF
 			{
 				return ImageFormat.IMAGE_FORMAT_TIFF;
-			}
-			else if (b1 == 0x49 && b2 == 0x49) // Intel byte order TIFF
+			} else if (b1 == 0x49 && b2 == 0x49) // Intel byte order TIFF
 			{
 				return ImageFormat.IMAGE_FORMAT_TIFF;
-			}
-			else if (b1 == 0x38 && b2 == 0x42)
-			{
+			} else if (b1 == 0x38 && b2 == 0x42) {
 				return ImageFormat.IMAGE_FORMAT_PSD;
-			}
-			else if (b1 == 0x50 && b2 == 0x31)
-			{
+			} else if (b1 == 0x50 && b2 == 0x31) {
 				return ImageFormat.IMAGE_FORMAT_PBM;
-			}
-			else if (b1 == 0x50 && b2 == 0x34)
-			{
+			} else if (b1 == 0x50 && b2 == 0x34) {
 				return ImageFormat.IMAGE_FORMAT_PBM;
-			}
-			else if (b1 == 0x50 && b2 == 0x32)
-			{
+			} else if (b1 == 0x50 && b2 == 0x32) {
 				return ImageFormat.IMAGE_FORMAT_PGM;
-			}
-			else if (b1 == 0x50 && b2 == 0x35)
-			{
+			} else if (b1 == 0x50 && b2 == 0x35) {
 				return ImageFormat.IMAGE_FORMAT_PGM;
-			}
-			else if (b1 == 0x50 && b2 == 0x33)
-			{
+			} else if (b1 == 0x50 && b2 == 0x33) {
 				return ImageFormat.IMAGE_FORMAT_PPM;
-			}
-			else if (b1 == 0x50 && b2 == 0x36)
-			{
+			} else if (b1 == 0x50 && b2 == 0x36) {
 				return ImageFormat.IMAGE_FORMAT_PPM;
+			} else if (b1 == 0x97 && b2 == 0x4A) {
+
+				int i3 = is.read();
+				int i4 = is.read();
+				if ((i3 < 0) || (i4 < 0))
+					throw new ImageReadException(
+							"Couldn't read magic numbers to guess format.");
+
+				int b3 = i3 & 0xff;
+				int b4 = i4 & 0xff;
+
+				if (b3 == 0x42 && b4 == 0x32)
+					return ImageFormat.IMAGE_FORMAT_JBIG2;
 			}
 
 			return ImageFormat.IMAGE_FORMAT_UNKNOWN;
-		}
-		finally
-		{
-			if (is != null)
-			{
-				try
-				{
+		} finally {
+			if (is != null) {
+				try {
 					is.close();
 
-				}
-				catch (IOException e)
-				{
+				} catch (IOException e) {
 					Debug.debug(e);
 
 				}
@@ -223,47 +212,109 @@
 		}
 	}
 
-	/** 
-	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
-	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      An instance of ICC_Profile or null if the image contains no ICC profile..
+	/**
+	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and
+	 * TIFF images.
+	 * <p>
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return An instance of ICC_Profile or null if the image contains no ICC
+	 *         profile..
 	 */
 	public static ICC_Profile getICCProfile(byte bytes[])
-			throws ImageReadException, IOException
-	{
-		return getICCProfile(new ByteSourceArray(bytes));
+			throws ImageReadException, IOException {
+		return getICCProfile(bytes, null);
 	}
 
-	/** 
-	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
-	 * <p>
-	 * @param  is InputStream from which to read image data.
-	 * @param  filename Filename associated with image data (optional).
-	 * @return      An instance of ICC_Profile or null if the image contains no ICC profile..
+	/**
+	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and
+	 * TIFF images.
+	 * <p>
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of ICC_Profile or null if the image contains no ICC
+	 *         profile..
+	 */
+	public static ICC_Profile getICCProfile(byte bytes[], Map params)
+			throws ImageReadException, IOException {
+		return getICCProfile(new ByteSourceArray(bytes), params);
+	}
+
+	/**
+	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and
+	 * TIFF images.
+	 * <p>
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @return An instance of ICC_Profile or null if the image contains no ICC
+	 *         profile..
 	 */
 	public static ICC_Profile getICCProfile(InputStream is, String filename)
-			throws ImageReadException, IOException
-	{
-		return getICCProfile(new ByteSourceInputStream(is, filename));
+			throws ImageReadException, IOException {
+		return getICCProfile(is, filename, null);
 	}
 
-	/** 
-	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
-	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      An instance of ICC_Profile or null if the image contains no ICC profile..
+	/**
+	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and
+	 * TIFF images.
+	 * <p>
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of ICC_Profile or null if the image contains no ICC
+	 *         profile..
+	 */
+	public static ICC_Profile getICCProfile(InputStream is, String filename,
+			Map params) throws ImageReadException, IOException {
+		return getICCProfile(new ByteSourceInputStream(is, filename), params);
+	}
+
+	/**
+	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and
+	 * TIFF images.
+	 * <p>
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return An instance of ICC_Profile or null if the image contains no ICC
+	 *         profile..
 	 */
 	public static ICC_Profile getICCProfile(File file)
-			throws ImageReadException, IOException
-	{
-		return getICCProfile(new ByteSourceFile(file));
+			throws ImageReadException, IOException {
+		return getICCProfile(file, null);
 	}
 
-	protected static ICC_Profile getICCProfile(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
-		byte bytes[] = getICCProfileBytes(byteSource);
+	/**
+	 * Extracts an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and
+	 * TIFF images.
+	 * <p>
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of ICC_Profile or null if the image contains no ICC
+	 *         profile..
+	 */
+	public static ICC_Profile getICCProfile(File file, Map params)
+			throws ImageReadException, IOException {
+		return getICCProfile(new ByteSourceFile(file), params);
+	}
+
+	protected static ICC_Profile getICCProfile(ByteSource byteSource, Map params)
+			throws ImageReadException, IOException {
+		byte bytes[] = getICCProfileBytes(byteSource, params);
 		if (bytes == null)
 			return null;
 
@@ -276,201 +327,263 @@
 		return icc;
 	}
 
-	/** 
-	 * Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
-	 * <p>
-	 * To parse the result use IccProfileParser or ICC_Profile.getInstance(bytes).
-	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      A byte array.
-	 * @see         IccProfileParser
-	 * @see         ICC_Profile
+	/**
+	 * Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD
+	 * (Photoshop) and TIFF images.
+	 * <p>
+	 * To parse the result use IccProfileParser or
+	 * ICC_Profile.getInstance(bytes).
+	 * <p>
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return A byte array.
+	 * @see IccProfileParser
+	 * @see ICC_Profile
 	 */
 	public static byte[] getICCProfileBytes(byte bytes[])
-			throws ImageReadException, IOException
-	{
-		return getICCProfileBytes(new ByteSourceArray(bytes));
+			throws ImageReadException, IOException {
+		return getICCProfileBytes(bytes, null);
+	}
+
+	/**
+	 * Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD
+	 * (Photoshop) and TIFF images.
+	 * <p>
+	 * To parse the result use IccProfileParser or
+	 * ICC_Profile.getInstance(bytes).
+	 * <p>
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return A byte array.
+	 * @see IccProfileParser
+	 * @see ICC_Profile
+	 */
+	public static byte[] getICCProfileBytes(byte bytes[], Map params)
+			throws ImageReadException, IOException {
+		return getICCProfileBytes(new ByteSourceArray(bytes), params);
+	}
+
+	/**
+	 * Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD
+	 * (Photoshop) and TIFF images.
+	 * <p>
+	 * To parse the result use IccProfileParser or
+	 * ICC_Profile.getInstance(bytes).
+	 * <p>
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return A byte array.
+	 * @see IccProfileParser
+	 * @see ICC_Profile
+	 */
+	public static byte[] getICCProfileBytes(File file)
+			throws ImageReadException, IOException {
+		return getICCProfileBytes(file, null);
 	}
 
-	/** 
-	 * Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD (Photoshop) and TIFF images.
+	/**
+	 * Extracts the raw bytes of an ICC Profile (if present) from JPEG, PNG, PSD
+	 * (Photoshop) and TIFF images.
 	 * <p>
-	 * To parse the result use IccProfileParser or ICC_Profile.getInstance(bytes).
+	 * To parse the result use IccProfileParser or
+	 * ICC_Profile.getInstance(bytes).
 	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      A byte array.
-	 * @see         IccProfileParser
-	 * @see         ICC_Profile
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return A byte array.
+	 * @see IccProfileParser
+	 * @see ICC_Profile
 	 */
-	public static byte[] getICCProfileBytes(File file)
-			throws ImageReadException, IOException
-	{
-		return getICCProfileBytes(new ByteSourceFile(file));
+	public static byte[] getICCProfileBytes(File file, Map params)
+			throws ImageReadException, IOException {
+		return getICCProfileBytes(new ByteSourceFile(file), params);
 	}
 
-	private static byte[] getICCProfileBytes(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+	private static byte[] getICCProfileBytes(ByteSource byteSource, Map params)
+			throws ImageReadException, IOException {
 		ImageParser imageParser = getImageParser(byteSource);
 
-		return imageParser.getICCProfileBytes(byteSource);
+		return imageParser.getICCProfileBytes(byteSource, params);
 	}
 
-	/** 
+	/**
 	 * Parses the "image info" of an image.
 	 * <p>
-	 * "Image info" is a summary of basic information about the image such as: 
+	 * "Image info" is a summary of basic information about the image such as:
 	 * width, height, file format, bit depth, color type, etc.
 	 * <p>
 	 * Not to be confused with "image metadata."
 	 * <p>
-	 * @param  filename String.
-	 * @param  bytes  Byte array containing an image file.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      An instance of ImageInfo.
-	 * @see         ImageInfo
+	 * 
+	 * @param filename
+	 *            String.
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of ImageInfo.
+	 * @see ImageInfo
 	 */
 	public static ImageInfo getImageInfo(String filename, byte bytes[],
-			Map params) throws ImageReadException, IOException
-	{
+			Map params) throws ImageReadException, IOException {
 		return getImageInfo(new ByteSourceArray(filename, bytes), params);
 	}
 
-	/** 
+	/**
 	 * Parses the "image info" of an image.
 	 * <p>
-	 * "Image info" is a summary of basic information about the image such as: 
+	 * "Image info" is a summary of basic information about the image such as:
 	 * width, height, file format, bit depth, color type, etc.
 	 * <p>
 	 * Not to be confused with "image metadata."
 	 * <p>
-	 * @param  filename String.
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      An instance of ImageInfo.
-	 * @see         ImageInfo
+	 * 
+	 * @param filename
+	 *            String.
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return An instance of ImageInfo.
+	 * @see ImageInfo
 	 */
 	public static ImageInfo getImageInfo(String filename, byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getImageInfo(new ByteSourceArray(filename, bytes), null);
 	}
 
-	/** 
+	/**
 	 * Parses the "image info" of an image.
 	 * <p>
-	 * "Image info" is a summary of basic information about the image such as: 
+	 * "Image info" is a summary of basic information about the image such as:
 	 * width, height, file format, bit depth, color type, etc.
 	 * <p>
 	 * Not to be confused with "image metadata."
 	 * <p>
-	 * @param  is InputStream from which to read image data.
-	 * @param  filename Filename associated with image data (optional).
-	 * @return      An instance of ImageInfo.
-	 * @see         ImageInfo
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @return An instance of ImageInfo.
+	 * @see ImageInfo
 	 */
 	public static ImageInfo getImageInfo(InputStream is, String filename)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getImageInfo(new ByteSourceInputStream(is, filename), null);
 	}
 
-	/** 
+	/**
 	 * Parses the "image info" of an image.
 	 * <p>
-	 * "Image info" is a summary of basic information about the image such as: 
+	 * "Image info" is a summary of basic information about the image such as:
 	 * width, height, file format, bit depth, color type, etc.
 	 * <p>
 	 * Not to be confused with "image metadata."
 	 * <p>
-	 * @param  is InputStream from which to read image data.
-	 * @param  filename Filename associated with image data (optional).
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      An instance of ImageInfo.
-	 * @see         ImageInfo
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of ImageInfo.
+	 * @see ImageInfo
 	 */
 	public static ImageInfo getImageInfo(InputStream is, String filename,
-			Map params) throws ImageReadException, IOException
-	{
+			Map params) throws ImageReadException, IOException {
 		return getImageInfo(new ByteSourceInputStream(is, filename), params);
 	}
 
-	/** 
+	/**
 	 * Parses the "image info" of an image.
 	 * <p>
-	 * "Image info" is a summary of basic information about the image such as: 
+	 * "Image info" is a summary of basic information about the image such as:
 	 * width, height, file format, bit depth, color type, etc.
 	 * <p>
 	 * Not to be confused with "image metadata."
 	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      An instance of ImageInfo.
-	 * @see         ImageInfo
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return An instance of ImageInfo.
+	 * @see ImageInfo
 	 */
 	public static ImageInfo getImageInfo(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getImageInfo(new ByteSourceArray(bytes), null);
 	}
 
-	/** 
+	/**
 	 * Parses the "image info" of an image.
 	 * <p>
-	 * "Image info" is a summary of basic information about the image such as: 
+	 * "Image info" is a summary of basic information about the image such as:
 	 * width, height, file format, bit depth, color type, etc.
 	 * <p>
 	 * Not to be confused with "image metadata."
 	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      An instance of ImageInfo.
-	 * @see         ImageInfo
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of ImageInfo.
+	 * @see ImageInfo
 	 */
 	public static ImageInfo getImageInfo(byte bytes[], Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getImageInfo(new ByteSourceArray(bytes), params);
 	}
 
-	/** 
+	/**
 	 * Parses the "image info" of an image file.
 	 * <p>
-	 * "Image info" is a summary of basic information about the image such as: 
+	 * "Image info" is a summary of basic information about the image such as:
 	 * width, height, file format, bit depth, color type, etc.
 	 * <p>
 	 * Not to be confused with "image metadata."
 	 * <p>
-	 * @param  file  File containing image data.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      An instance of ImageInfo.
-	 * @see         ImageInfo
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of ImageInfo.
+	 * @see ImageInfo
 	 */
 	public static ImageInfo getImageInfo(File file, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getImageInfo(new ByteSourceFile(file), params);
 	}
 
-	/** 
+	/**
 	 * Parses the "image info" of an image file.
 	 * <p>
-	 * "Image info" is a summary of basic information about the image such as: 
+	 * "Image info" is a summary of basic information about the image such as:
 	 * width, height, file format, bit depth, color type, etc.
 	 * <p>
 	 * Not to be confused with "image metadata."
 	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      An instance of ImageInfo.
-	 * @see         ImageInfo
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return An instance of ImageInfo.
+	 * @see ImageInfo
 	 */
 	public static ImageInfo getImageInfo(File file) throws ImageReadException,
-			IOException
-	{
+			IOException {
 		return getImageInfo(file, null);
 	}
 
 	private static ImageInfo getImageInfo(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		ImageParser imageParser = getImageParser(byteSource);
 
 		ImageInfo imageInfo = imageParser.getImageInfo(byteSource, params);
@@ -479,16 +592,13 @@
 	}
 
 	private static final ImageParser getImageParser(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		ImageFormat format = guessFormat(byteSource);
-		if (!format.equals(ImageFormat.IMAGE_FORMAT_UNKNOWN))
-		{
+		if (!format.equals(ImageFormat.IMAGE_FORMAT_UNKNOWN)) {
 
 			ImageParser imageParsers[] = ImageParser.getAllImageParsers();
 
-			for (int i = 0; i < imageParsers.length; i++)
-			{
+			for (int i = 0; i < imageParsers.length; i++) {
 				ImageParser imageParser = imageParsers[i];
 
 				if (imageParser.canAcceptType(format))
@@ -497,12 +607,10 @@
 		}
 
 		String filename = byteSource.getFilename();
-		if (filename != null)
-		{
+		if (filename != null) {
 			ImageParser imageParsers[] = ImageParser.getAllImageParsers();
 
-			for (int i = 0; i < imageParsers.length; i++)
-			{
+			for (int i = 0; i < imageParsers.length; i++) {
 				ImageParser imageParser = imageParsers[i];
 
 				if (imageParser.canAcceptExtension(filename))
@@ -513,453 +621,535 @@
 		throw new ImageReadException("Can't parse this format.");
 	}
 
-	/** 
+	/**
 	 * Determines the width and height of an image.
 	 * <p>
-	 * @param  is InputStream from which to read image data.
-	 * @param  filename Filename associated with image data (optional).
-	 * @return      The width and height of the image.
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @return The width and height of the image.
 	 */
 	public static Dimension getImageSize(InputStream is, String filename)
-			throws ImageReadException, IOException
-	{
-		return getImageSize(new ByteSourceInputStream(is, filename));
+			throws ImageReadException, IOException {
+		return getImageSize(is, filename, null);
+	}
+
+	/**
+	 * Determines the width and height of an image.
+	 * <p>
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return The width and height of the image.
+	 */
+	public static Dimension getImageSize(InputStream is, String filename,
+			Map params) throws ImageReadException, IOException {
+		return getImageSize(new ByteSourceInputStream(is, filename), params);
 	}
 
-	/** 
+	/**
 	 * Determines the width and height of an image.
 	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      The width and height of the image.
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return The width and height of the image.
 	 */
 	public static Dimension getImageSize(byte bytes[])
-			throws ImageReadException, IOException
-	{
-		return getImageSize(new ByteSourceArray(bytes));
+			throws ImageReadException, IOException {
+		return getImageSize(bytes, null);
 	}
 
-	/** 
+	/**
+	 * Determines the width and height of an image.
+	 * <p>
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return The width and height of the image.
+	 */
+	public static Dimension getImageSize(byte bytes[], Map params)
+			throws ImageReadException, IOException {
+		return getImageSize(new ByteSourceArray(bytes), params);
+	}
+
+	/**
 	 * Determines the width and height of an image file.
 	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      The width and height of the image.
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return The width and height of the image.
 	 */
 	public static Dimension getImageSize(File file) throws ImageReadException,
-			IOException
-	{
-		return getImageSize(new ByteSourceFile(file));
+			IOException {
+		return getImageSize(file, null);
+	}
+
+	/**
+	 * Determines the width and height of an image file.
+	 * <p>
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return The width and height of the image.
+	 */
+	public static Dimension getImageSize(File file, Map params)
+			throws ImageReadException, IOException {
+		return getImageSize(new ByteSourceFile(file), params);
 	}
 
-	private static Dimension getImageSize(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+	public static Dimension getImageSize(ByteSource byteSource, Map params)
+			throws ImageReadException, IOException {
 		ImageParser imageParser = getImageParser(byteSource);
 
-		return imageParser.getImageSize(byteSource);
+		return imageParser.getImageSize(byteSource, params);
 	}
 
-	/** 
-	 * Parses the metadata of an image.  This metadata depends on the format of the image.  
+	/**
+	 * Parses the metadata of an image. This metadata depends on the format of
+	 * the image.
 	 * <p>
-	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata.
-	 * PNG files may contain comments.
-	 * TIFF files may contain metadata.
+	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may
+	 * contain comments. TIFF files may contain metadata.
 	 * <p>
-	 * The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).
+	 * The instance of IImageMetadata returned by getMetadata() should be upcast
+	 * (depending on image format).
 	 * <p>
 	 * Not to be confused with "image info."
 	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      An instance of IImageMetadata.
-	 * @see         IImageMetadata
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return An instance of IImageMetadata.
+	 * @see IImageMetadata
 	 */
 	public static IImageMetadata getMetadata(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(bytes, null);
 	}
 
-	/** 
-	 * Parses the metadata of an image.  This metadata depends on the format of the image.  
+	/**
+	 * Parses the metadata of an image. This metadata depends on the format of
+	 * the image.
 	 * <p>
-	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata.
-	 * PNG files may contain comments.
-	 * TIFF files may contain metadata.
+	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may
+	 * contain comments. TIFF files may contain metadata.
 	 * <p>
-	 * The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).
+	 * The instance of IImageMetadata returned by getMetadata() should be upcast
+	 * (depending on image format).
 	 * <p>
 	 * Not to be confused with "image info."
 	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      An instance of IImageMetadata.
-	 * @see         IImageMetadata
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of IImageMetadata.
+	 * @see IImageMetadata
 	 */
 	public static IImageMetadata getMetadata(byte bytes[], Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(new ByteSourceArray(bytes), params);
 	}
 
-	/** 
-	 * Parses the metadata of an image file.  This metadata depends on the format of the image.  
+	/**
+	 * Parses the metadata of an image file. This metadata depends on the format
+	 * of the image.
 	 * <p>
-	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata.
-	 * PNG files may contain comments.
-	 * TIFF files may contain metadata.
+	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may
+	 * contain comments. TIFF files may contain metadata.
 	 * <p>
-	 * The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).
+	 * The instance of IImageMetadata returned by getMetadata() should be upcast
+	 * (depending on image format).
 	 * <p>
 	 * Not to be confused with "image info."
 	 * <p>
-	 * @param  is InputStream from which to read image data.
-	 * @param  filename Filename associated with image data (optional).
-	 * @return      An instance of IImageMetadata.
-	 * @see         IImageMetadata
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @return An instance of IImageMetadata.
+	 * @see IImageMetadata
 	 */
 	public static IImageMetadata getMetadata(InputStream is, String filename)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(is, filename, null);
 	}
 
-	/** 
-	 * Parses the metadata of an image file.  This metadata depends on the format of the image.  
+	/**
+	 * Parses the metadata of an image file. This metadata depends on the format
+	 * of the image.
 	 * <p>
-	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata.
-	 * PNG files may contain comments.
-	 * TIFF files may contain metadata.
+	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may
+	 * contain comments. TIFF files may contain metadata.
 	 * <p>
-	 * The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).
+	 * The instance of IImageMetadata returned by getMetadata() should be upcast
+	 * (depending on image format).
 	 * <p>
 	 * Not to be confused with "image info."
 	 * <p>
-	 * @param  is InputStream from which to read image data.
-	 * @param  filename Filename associated with image data (optional).
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      An instance of IImageMetadata.
-	 * @see         IImageMetadata
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of IImageMetadata.
+	 * @see IImageMetadata
 	 */
 	public static IImageMetadata getMetadata(InputStream is, String filename,
-			Map params) throws ImageReadException, IOException
-	{
+			Map params) throws ImageReadException, IOException {
 		return getMetadata(new ByteSourceInputStream(is, filename), params);
 	}
 
-	/** 
-	 * Parses the metadata of an image file.  This metadata depends on the format of the image.  
+	/**
+	 * Parses the metadata of an image file. This metadata depends on the format
+	 * of the image.
 	 * <p>
-	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata.
-	 * PNG files may contain comments.
-	 * TIFF files may contain metadata.
+	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may
+	 * contain comments. TIFF files may contain metadata.
 	 * <p>
-	 * The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).
+	 * The instance of IImageMetadata returned by getMetadata() should be upcast
+	 * (depending on image format).
 	 * <p>
 	 * Not to be confused with "image info."
 	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      An instance of IImageMetadata.
-	 * @see         IImageMetadata
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return An instance of IImageMetadata.
+	 * @see IImageMetadata
 	 */
 	public static IImageMetadata getMetadata(File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(file, null);
 	}
 
-	/** 
-	 * Parses the metadata of an image file.  This metadata depends on the format of the image.  
+	/**
+	 * Parses the metadata of an image file. This metadata depends on the format
+	 * of the image.
 	 * <p>
-	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata.
-	 * PNG files may contain comments.
-	 * TIFF files may contain metadata.
+	 * JPEG/JFIF files may contain EXIF and/or IPTC metadata. PNG files may
+	 * contain comments. TIFF files may contain metadata.
 	 * <p>
-	 * The instance of IImageMetadata returned by getMetadata() should be upcast (depending on image format).
+	 * The instance of IImageMetadata returned by getMetadata() should be upcast
+	 * (depending on image format).
 	 * <p>
 	 * Not to be confused with "image info."
 	 * <p>
-	 * @param  file  File containing image data.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      An instance of IImageMetadata.
-	 * @see         IImageMetadata
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return An instance of IImageMetadata.
+	 * @see IImageMetadata
 	 */
 	public static IImageMetadata getMetadata(File file, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getMetadata(new ByteSourceFile(file), params);
 	}
 
 	private static IImageMetadata getMetadata(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		ImageParser imageParser = getImageParser(byteSource);
 
 		return imageParser.getMetadata(byteSource, params);
 	}
 
-	/** 
+	/**
 	 * Returns a description of the image's structure.
 	 * <p>
 	 * Useful for exploring format-specific details of image files.
 	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      A description of the image file's structure.
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return A description of the image file's structure.
 	 */
 	public static String dumpImageFile(byte bytes[]) throws ImageReadException,
-			IOException
-	{
+			IOException {
 		return dumpImageFile(new ByteSourceArray(bytes));
 	}
 
-	/** 
+	/**
 	 * Returns a description of the image file's structure.
 	 * <p>
 	 * Useful for exploring format-specific details of image files.
 	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      A description of the image file's structure.
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return A description of the image file's structure.
 	 */
 	public static String dumpImageFile(File file) throws ImageReadException,
-			IOException
-	{
+			IOException {
 		return dumpImageFile(new ByteSourceFile(file));
 	}
 
 	private static String dumpImageFile(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		ImageParser imageParser = getImageParser(byteSource);
 
 		return imageParser.dumpImageFile(byteSource);
 	}
 
 	public static FormatCompliance getFormatCompliance(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getFormatCompliance(new ByteSourceArray(bytes));
 	}
 
 	public static FormatCompliance getFormatCompliance(File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getFormatCompliance(new ByteSourceFile(file));
 	}
 
 	private static FormatCompliance getFormatCompliance(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		ImageParser imageParser = getImageParser(byteSource);
 
 		return imageParser.getFormatCompliance(byteSource);
 	}
 
-	/** 
+	/**
 	 * Returns all images contained in an image.
 	 * <p>
-	 * Useful for image formats such as GIF and ICO in which a single file may 
+	 * Useful for image formats such as GIF and ICO in which a single file may
 	 * contain multiple images.
 	 * <p>
-	 * @param  is InputStream from which to read image data.
-	 * @param  filename Filename associated with image data (optional).
-	 * @return      A vector of BufferedImages.
+	 * 
+	 * @param is
+	 *            InputStream from which to read image data.
+	 * @param filename
+	 *            Filename associated with image data (optional).
+	 * @return A vector of BufferedImages.
 	 */
 	public static ArrayList getAllBufferedImages(InputStream is, String filename)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getAllBufferedImages(new ByteSourceInputStream(is, filename));
 	}
 
-	/** 
+	/**
 	 * Returns all images contained in an image.
 	 * <p>
-	 * Useful for image formats such as GIF and ICO in which a single file may 
+	 * Useful for image formats such as GIF and ICO in which a single file may
 	 * contain multiple images.
 	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      A vector of BufferedImages.
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return A vector of BufferedImages.
 	 */
 	public static ArrayList getAllBufferedImages(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getAllBufferedImages(new ByteSourceArray(bytes));
 	}
 
-	/** 
+	/**
 	 * Returns all images contained in an image file.
 	 * <p>
-	 * Useful for image formats such as GIF and ICO in which a single file may 
+	 * Useful for image formats such as GIF and ICO in which a single file may
 	 * contain multiple images.
 	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      A vector of BufferedImages.
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return A vector of BufferedImages.
 	 */
 	public static ArrayList getAllBufferedImages(File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getAllBufferedImages(new ByteSourceFile(file));
 	}
 
 	private static ArrayList getAllBufferedImages(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		ImageParser imageParser = getImageParser(byteSource);
 
 		return imageParser.getAllBufferedImages(byteSource);
 	}
 
-	//	public static boolean extractImages(byte bytes[], File dstDir,
-	//			String dstRoot, ImageParser encoder) throws ImageReadException,
-	//			IOException, ImageWriteException
-	//	{
-	//		return extractImages(new ByteSourceArray(bytes), dstDir, dstRoot,
-	//				encoder);
-	//	}
+	// public static boolean extractImages(byte bytes[], File dstDir,
+	// String dstRoot, ImageParser encoder) throws ImageReadException,
+	// IOException, ImageWriteException
+	// {
+	// return extractImages(new ByteSourceArray(bytes), dstDir, dstRoot,
+	// encoder);
+	// }
 	//
-	//	public static boolean extractImages(File file, File dstDir, String dstRoot,
-	//			ImageParser encoder) throws ImageReadException, IOException,
-	//			ImageWriteException
-	//	{
-	//		return extractImages(new ByteSourceFile(file), dstDir, dstRoot, encoder);
-	//	}
+	// public static boolean extractImages(File file, File dstDir, String
+	// dstRoot,
+	// ImageParser encoder) throws ImageReadException, IOException,
+	// ImageWriteException
+	// {
+	// return extractImages(new ByteSourceFile(file), dstDir, dstRoot, encoder);
+	// }
 	//
-	//	public static boolean extractImages(ByteSource byteSource, File dstDir,
-	//			String dstRoot, ImageParser encoder) throws ImageReadException,
-	//			IOException, ImageWriteException
-	//	{
-	//		ImageParser imageParser = getImageParser(byteSource);
+	// public static boolean extractImages(ByteSource byteSource, File dstDir,
+	// String dstRoot, ImageParser encoder) throws ImageReadException,
+	// IOException, ImageWriteException
+	// {
+	// ImageParser imageParser = getImageParser(byteSource);
 	//
-	//		return imageParser.extractImages(byteSource, dstDir, dstRoot, encoder);
-	//	}
+	// return imageParser.extractImages(byteSource, dstDir, dstRoot, encoder);
+	// }
 
-	/** 
+	/**
 	 * Reads the first image from an InputStream as a BufferedImage.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  is  InputStream to read image data from.
-	 * @return      A BufferedImage.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param is
+	 *            InputStream to read image data from.
+	 * @return A BufferedImage.
 	 * @see SanselanConstants
 	 */
 	public static BufferedImage getBufferedImage(InputStream is)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getBufferedImage(is, null);
 	}
 
-	/** 
+	/**
 	 * Reads the first image from an InputStream as a BufferedImage.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  is  InputStream to read image data from.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      A BufferedImage.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param is
+	 *            InputStream to read image data from.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return A BufferedImage.
 	 * @see SanselanConstants
 	 */
 	public static BufferedImage getBufferedImage(InputStream is, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		String filename = null;
 		if (params != null && params.containsKey(PARAM_KEY_FILENAME))
 			filename = (String) params.get(PARAM_KEY_FILENAME);
 		return getBufferedImage(new ByteSourceInputStream(is, filename), params);
 	}
 
-	/** 
+	/**
 	 * Reads the first image from an image file as a BufferedImage.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @return      A BufferedImage.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @return A BufferedImage.
 	 * @see SanselanConstants
 	 */
 	public static BufferedImage getBufferedImage(byte bytes[])
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getBufferedImage(new ByteSourceArray(bytes), null);
 	}
 
-	/** 
+	/**
 	 * Reads the first image from an image file as a BufferedImage.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  bytes  Byte array containing an image file.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      A BufferedImage.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param bytes
+	 *            Byte array containing an image file.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return A BufferedImage.
 	 * @see SanselanConstants
 	 */
 	public static BufferedImage getBufferedImage(byte bytes[], Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getBufferedImage(new ByteSourceArray(bytes), params);
 	}
 
-	/** 
+	/**
 	 * Reads the first image from an image file as a BufferedImage.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  file  File containing image data.
-	 * @return      A BufferedImage.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @return A BufferedImage.
 	 * @see SanselanConstants
 	 */
 	public static BufferedImage getBufferedImage(File file)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getBufferedImage(new ByteSourceFile(file), null);
 	}
 
-	/** 
+	/**
 	 * Reads the first image from an image file as a BufferedImage.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  file  File containing image data.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
-	 * @return      A BufferedImage.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param file
+	 *            File containing image data.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
+	 * @return A BufferedImage.
 	 * @see SanselanConstants
 	 */
 	public static BufferedImage getBufferedImage(File file, Map params)
-			throws ImageReadException, IOException
-	{
+			throws ImageReadException, IOException {
 		return getBufferedImage(new ByteSourceFile(file), params);
 	}
 
 	private static BufferedImage getBufferedImage(ByteSource byteSource,
-			Map params) throws ImageReadException, IOException
-	{
+			Map params) throws ImageReadException, IOException {
 		ImageParser imageParser = getImageParser(byteSource);
 		if (null == params)
 			params = new HashMap();
@@ -967,69 +1157,72 @@
 		return imageParser.getBufferedImage(byteSource, params);
 	}
 
-	/** 
+	/**
 	 * Writes a BufferedImage to a file.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  src The BufferedImage to be written.
-	 * @param  file File to write to.
-	 * @param format The ImageFormat to use.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param src
+	 *            The BufferedImage to be written.
+	 * @param file
+	 *            File to write to.
+	 * @param format
+	 *            The ImageFormat to use.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
 	 * @see SanselanConstants
 	 */
 	public static void writeImage(BufferedImage src, File file,
 			ImageFormat format, Map params) throws ImageWriteException,
-			IOException
-	{
+			IOException {
 		OutputStream os = null;
 
-		try
-		{
+		try {
 			os = new FileOutputStream(file);
 			os = new BufferedOutputStream(os);
 
 			writeImage(src, os, format, params);
-		}
-		finally
-		{
-			try
-			{
+		} finally {
+			try {
 				if (os != null)
 					os.close();
-			}
-			catch (Exception e)
-			{
+			} catch (Exception e) {
 				Debug.debug(e);
 			}
 		}
 	}
 
-	/** 
+	/**
 	 * Writes a BufferedImage to a byte array.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  src The BufferedImage to be written.
-	 * @param format The ImageFormat to use.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param src
+	 *            The BufferedImage to be written.
+	 * @param format
+	 *            The ImageFormat to use.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
 	 * @return A byte array containing the image file.
 	 * @see SanselanConstants
 	 */
 	public static byte[] writeImageToBytes(BufferedImage src,
 			ImageFormat format, Map params) throws ImageWriteException,
-			IOException
-	{
+			IOException {
 		ByteArrayOutputStream os = new ByteArrayOutputStream();
 
 		writeImage(src, os, format, params);
@@ -1037,26 +1230,31 @@
 		return os.toByteArray();
 	}
 
-	/** 
+	/**
 	 * Writes a BufferedImage to an OutputStream.
 	 * <p>
 	 * (TODO: elaborate here.)
 	 * <p>
-	 * Sanselan can only read image info, metadata and ICC profiles from all image formats.
-	 * However, note that the library cannot currently read or write JPEG image data.
-	 * PSD (Photoshop) files can only be partially read and cannot be written.
-	 * All other formats (PNG, GIF, TIFF, BMP, etc.) are fully supported.
-	 * <p>
-	 * @param  src The BufferedImage to be written.
-	 * @param  os The OutputStream to write to.
-	 * @param format The ImageFormat to use.
-	 * @param  params Map of optional parameters, defined in SanselanConstants.
+	 * Sanselan can only read image info, metadata and ICC profiles from all
+	 * image formats. However, note that the library cannot currently read or
+	 * write JPEG image data. PSD (Photoshop) files can only be partially read
+	 * and cannot be written. All other formats (PNG, GIF, TIFF, BMP, etc.) are
+	 * fully supported.
+	 * <p>
+	 * 
+	 * @param src
+	 *            The BufferedImage to be written.
+	 * @param os
+	 *            The OutputStream to write to.
+	 * @param format
+	 *            The ImageFormat to use.
+	 * @param params
+	 *            Map of optional parameters, defined in SanselanConstants.
 	 * @see SanselanConstants
 	 */
 	public static void writeImage(BufferedImage src, OutputStream os,
 			ImageFormat format, Map params) throws ImageWriteException,
-			IOException
-	{
+			IOException {
 		ImageParser imageParsers[] = ImageParser.getAllImageParsers();
 
 		// make sure params are non-null
@@ -1065,8 +1263,7 @@
 
 		params.put(PARAM_KEY_FORMAT, format);
 
-		for (int i = 0; i < imageParsers.length; i++)
-		{
+		for (int i = 0; i < imageParsers.length; i++) {
 			ImageParser imageParser = imageParsers[i];
 
 			if (!imageParser.canAcceptType(format))

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/SanselanConstants.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/SanselanConstants.java?rev=659985&r1=659984&r2=659985&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/SanselanConstants.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/SanselanConstants.java Sun May 25 06:57:43 2008
@@ -74,4 +74,15 @@
 	 */
 	public static final String PARAM_KEY_READ_THUMBNAILS = "READ_THUMBNAILS";
 
+	/** 
+	 * Parameter key.  Indicates whether to throw exceptions when parsing
+	 * invalid files, or whether to tolerate small problems.  
+	 * <p>
+	 * Valid values: Boolean.TRUE and Boolean.FALSE.
+	 * Default value: Boolean.FALSE.
+	 * <p>
+	 * @see TiffConstants
+	 */
+	public static final String PARAM_KEY_STRICT = "STRICT";
+
 }

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java?rev=659985&r1=659984&r2=659985&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/common/BinaryFileFunctions.java Sun May 25 06:57:43 2008
@@ -476,6 +476,13 @@
 		return result;
 	}
 
+	public final byte[] readByteArray(String name, int length, InputStream is)
+			throws IOException
+	{
+		String exception = name + " could not be read.";
+		return readByteArray(name, length, is, exception);
+	}
+
 	public final byte[] readByteArray(String name, int length, InputStream is,
 			String exception) throws IOException
 	{

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/bmp/BmpImageParser.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/bmp/BmpImageParser.java?rev=659985&r1=659984&r2=659985&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/bmp/BmpImageParser.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/bmp/BmpImageParser.java Sun May 25 06:57:43 2008
@@ -403,13 +403,14 @@
 		//		return null;
 	}
 
-	public byte[] getICCProfileBytes(ByteSource byteSource)
+	public byte[] getICCProfileBytes(ByteSource byteSource, Map params)
 			throws ImageReadException, IOException
 	{
 		return null;
 	}
 
-	public Dimension getImageSize(ByteSource byteSource)
+	public Dimension getImageSize(ByteSource byteSource,
+			Map params)
 			throws ImageReadException, IOException
 	{
 		BmpHeaderInfo bhi = readBmpHeaderInfo(byteSource);

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java?rev=659985&r1=659984&r2=659985&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java Sun May 25 06:57:43 2008
@@ -525,13 +525,14 @@
 		}
 	}
 
-	public byte[] getICCProfileBytes(ByteSource byteSource)
+	public byte[] getICCProfileBytes(ByteSource byteSource, Map params)
 			throws ImageReadException, IOException
 	{
 		return null;
 	}
 
-	public Dimension getImageSize(ByteSource byteSource)
+	public Dimension getImageSize(ByteSource byteSource,
+			Map params)
 			throws ImageReadException, IOException
 	{
 		GIFHeaderInfo bhi = readHeader(byteSource);