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 [2/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/ fo...
Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageParser.java Fri Sep 10 16:33:35 2010
@@ -44,375 +44,375 @@ import org.apache.sanselan.formats.tiff.
import org.apache.sanselan.util.Debug;
public abstract class ImageParser extends BinaryFileParser implements
- SanselanConstants
+ 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 JBig2ImageParser(),
- // new TgaImageParser(),
- };
-
- return result;
- }
-
- public final IImageMetadata getMetadata(ByteSource byteSource)
- throws ImageReadException, IOException
- {
- return getMetadata(byteSource, null);
- }
-
- public abstract IImageMetadata getMetadata(ByteSource byteSource, Map params)
- throws ImageReadException, IOException;
-
- public final IImageMetadata getMetadata(byte bytes[])
- throws ImageReadException, IOException
- {
- return getMetadata(bytes);
- }
-
- public final IImageMetadata getMetadata(byte bytes[], Map params)
- throws ImageReadException, IOException
- {
- return getMetadata(new ByteSourceArray(bytes), params);
- }
-
- public final IImageMetadata getMetadata(File file)
- throws ImageReadException, IOException
- {
- return getMetadata(file, null);
- }
-
- public final IImageMetadata getMetadata(File file, Map params)
- throws ImageReadException, IOException
- {
- if (debug)
- System.out.println(getName() + ".getMetadata" + ": "
- + file.getName());
-
- if (!canAcceptExtension(file))
- return null;
-
- return getMetadata(new ByteSourceFile(file), params);
- }
-
- public abstract ImageInfo getImageInfo(ByteSource byteSource, Map params)
- throws ImageReadException, IOException;
-
- public final ImageInfo getImageInfo(ByteSource byteSource)
- throws ImageReadException, IOException
- {
- return getImageInfo(byteSource, null);
- }
-
- public final ImageInfo getImageInfo(byte bytes[], Map params)
- throws ImageReadException, IOException
- {
- return getImageInfo(new ByteSourceArray(bytes), params);
- }
-
- public final ImageInfo getImageInfo(File file, Map params)
- throws ImageReadException, IOException
- {
- if (!canAcceptExtension(file))
- return null;
-
- return getImageInfo(new ByteSourceFile(file), params);
- }
-
- public FormatCompliance getFormatCompliance(ByteSource byteSource)
- throws ImageReadException, IOException
- {
- return null;
- }
-
- public final FormatCompliance getFormatCompliance(byte bytes[])
- throws ImageReadException, IOException
- {
- return getFormatCompliance(new ByteSourceArray(bytes));
- }
-
- public final FormatCompliance getFormatCompliance(File file)
- throws ImageReadException, IOException
- {
- if (!canAcceptExtension(file))
- return null;
-
- return getFormatCompliance(new ByteSourceFile(file));
- }
-
- public ArrayList getAllBufferedImages(ByteSource byteSource)
- throws ImageReadException, IOException
- {
- BufferedImage bi = getBufferedImage(byteSource, null);
-
- ArrayList result = new ArrayList();
-
- result.add(bi);
-
- return result;
- }
-
- public final ArrayList getAllBufferedImages(byte bytes[])
- throws ImageReadException, IOException
- {
- return getAllBufferedImages(new ByteSourceArray(bytes));
- }
-
- public final ArrayList getAllBufferedImages(File file)
- 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);
- //
- // 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);
- // }
- //
- // return false;
- // }
- //
- // public final boolean extractImages(byte bytes[], File dstDir,
- // String dstRoot, ImageParser 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)
- //
- // throws ImageReadException, IOException, ImageWriteException
- // {
- // if (!canAcceptExtension(file))
- // return false;
- //
- // 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
- {
- return getBufferedImage(new ByteSourceArray(bytes), params);
- }
-
- public final BufferedImage getBufferedImage(File file, Map params)
- throws ImageReadException, IOException
- {
- if (!canAcceptExtension(file))
- return null;
-
- return getBufferedImage(new ByteSourceFile(file), params);
- }
-
- public void writeImage(BufferedImage src, OutputStream os, Map params)
- throws ImageWriteException, IOException
- {
- try
- {
- os.close(); // we are obligated to close stream.
- } catch (Exception e)
- {
- Debug.debug(e);
- }
-
- throw new ImageWriteException("This image format (" + getName()
- + ") cannot be written.");
- }
-
- public final Dimension getImageSize(byte 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
- {
-
- 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), params);
- }
-
- public abstract Dimension getImageSize(ByteSource byteSource, Map params)
- throws ImageReadException, IOException;
-
- public abstract String getXmpXml(ByteSource byteSource, Map params)
- throws ImageReadException, IOException;
-
- public final byte[] getICCProfileBytes(byte 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
- {
- 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), params);
- }
-
- public abstract byte[] getICCProfileBytes(ByteSource byteSource, Map params)
- throws ImageReadException, IOException;
-
- public final String dumpImageFile(byte bytes[]) throws ImageReadException,
- IOException
- {
- return dumpImageFile(new ByteSourceArray(bytes));
- }
-
- public final String dumpImageFile(File file) throws ImageReadException,
- IOException
- {
- if (!canAcceptExtension(file))
- return null;
-
- if (debug)
- System.out.println(getName() + ": " + file.getName());
-
- return dumpImageFile(new ByteSourceFile(file));
- }
-
- public final String dumpImageFile(ByteSource byteSource)
- throws ImageReadException, IOException
- {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
-
- dumpImageFile(pw, byteSource);
-
- pw.flush();
-
- return sw.toString();
- }
-
- public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
- throws ImageReadException, IOException
- {
- return false;
- }
-
- public abstract boolean embedICCProfile(File src, File dst, byte profile[]);
-
- public abstract String getName();
-
- public abstract String getDefaultExtension();
-
- protected abstract String[] getAcceptedExtensions();
-
- protected abstract ImageFormat[] getAcceptedTypes();
-
- public boolean canAcceptType(ImageFormat type)
- {
- ImageFormat types[] = getAcceptedTypes();
-
- for (int i = 0; i < types.length; i++)
- if (types[i].equals(type))
- return true;
- return false;
- }
-
- protected final boolean canAcceptExtension(File file)
- {
- return canAcceptExtension(file.getName());
- }
-
- protected final boolean canAcceptExtension(String filename)
- {
- String exts[] = getAcceptedExtensions();
- if (exts == null)
- return true;
-
- int index = filename.lastIndexOf('.');
- if (index >= 0)
- {
- String ext = filename.substring(index);
- ext = ext.toLowerCase();
-
- for (int i = 0; i < exts.length; i++)
- if (exts[i].toLowerCase().equals(ext))
- return true;
- }
- return false;
- }
-
- protected IBufferedImageFactory getBufferedImageFactory(Map params)
- {
- if (params == null)
- return new SimpleBufferedImageFactory();
-
- IBufferedImageFactory result = (IBufferedImageFactory) params
- .get(SanselanConstants.BUFFERED_IMAGE_FACTORY);
-
- if (null != result)
- return result;
-
- 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();
- }
+ public static final ImageParser[] getAllImageParsers()
+ {
+ ImageParser result[] = { new JpegImageParser(), new TiffImageParser(),
+ new PngImageParser(), new BmpImageParser(),
+ new GifImageParser(), new PsdImageParser(),
+ new PNMImageParser(), new IcoImageParser(),
+ // new JBig2ImageParser(),
+ // new TgaImageParser(),
+ };
+
+ return result;
+ }
+
+ public final IImageMetadata getMetadata(ByteSource byteSource)
+ throws ImageReadException, IOException
+ {
+ return getMetadata(byteSource, null);
+ }
+
+ public abstract IImageMetadata getMetadata(ByteSource byteSource, Map params)
+ throws ImageReadException, IOException;
+
+ public final IImageMetadata getMetadata(byte bytes[])
+ throws ImageReadException, IOException
+ {
+ return getMetadata(bytes);
+ }
+
+ public final IImageMetadata getMetadata(byte bytes[], Map params)
+ throws ImageReadException, IOException
+ {
+ return getMetadata(new ByteSourceArray(bytes), params);
+ }
+
+ public final IImageMetadata getMetadata(File file)
+ throws ImageReadException, IOException
+ {
+ return getMetadata(file, null);
+ }
+
+ public final IImageMetadata getMetadata(File file, Map params)
+ throws ImageReadException, IOException
+ {
+ if (debug)
+ System.out.println(getName() + ".getMetadata" + ": "
+ + file.getName());
+
+ if (!canAcceptExtension(file))
+ return null;
+
+ return getMetadata(new ByteSourceFile(file), params);
+ }
+
+ public abstract ImageInfo getImageInfo(ByteSource byteSource, Map params)
+ throws ImageReadException, IOException;
+
+ public final ImageInfo getImageInfo(ByteSource byteSource)
+ throws ImageReadException, IOException
+ {
+ return getImageInfo(byteSource, null);
+ }
+
+ public final ImageInfo getImageInfo(byte bytes[], Map params)
+ throws ImageReadException, IOException
+ {
+ return getImageInfo(new ByteSourceArray(bytes), params);
+ }
+
+ public final ImageInfo getImageInfo(File file, Map params)
+ throws ImageReadException, IOException
+ {
+ if (!canAcceptExtension(file))
+ return null;
+
+ return getImageInfo(new ByteSourceFile(file), params);
+ }
+
+ public FormatCompliance getFormatCompliance(ByteSource byteSource)
+ throws ImageReadException, IOException
+ {
+ return null;
+ }
+
+ public final FormatCompliance getFormatCompliance(byte bytes[])
+ throws ImageReadException, IOException
+ {
+ return getFormatCompliance(new ByteSourceArray(bytes));
+ }
+
+ public final FormatCompliance getFormatCompliance(File file)
+ throws ImageReadException, IOException
+ {
+ if (!canAcceptExtension(file))
+ return null;
+
+ return getFormatCompliance(new ByteSourceFile(file));
+ }
+
+ public ArrayList getAllBufferedImages(ByteSource byteSource)
+ throws ImageReadException, IOException
+ {
+ BufferedImage bi = getBufferedImage(byteSource, null);
+
+ ArrayList result = new ArrayList();
+
+ result.add(bi);
+
+ return result;
+ }
+
+ public final ArrayList getAllBufferedImages(byte bytes[])
+ throws ImageReadException, IOException
+ {
+ return getAllBufferedImages(new ByteSourceArray(bytes));
+ }
+
+ public final ArrayList getAllBufferedImages(File file)
+ 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);
+ //
+ // 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);
+ // }
+ //
+ // return false;
+ // }
+ //
+ // public final boolean extractImages(byte bytes[], File dstDir,
+ // String dstRoot, ImageParser 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)
+ //
+ // throws ImageReadException, IOException, ImageWriteException
+ // {
+ // if (!canAcceptExtension(file))
+ // return false;
+ //
+ // 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
+ {
+ return getBufferedImage(new ByteSourceArray(bytes), params);
+ }
+
+ public final BufferedImage getBufferedImage(File file, Map params)
+ throws ImageReadException, IOException
+ {
+ if (!canAcceptExtension(file))
+ return null;
+
+ return getBufferedImage(new ByteSourceFile(file), params);
+ }
+
+ public void writeImage(BufferedImage src, OutputStream os, Map params)
+ throws ImageWriteException, IOException
+ {
+ try
+ {
+ os.close(); // we are obligated to close stream.
+ } catch (Exception e)
+ {
+ Debug.debug(e);
+ }
+
+ throw new ImageWriteException("This image format (" + getName()
+ + ") cannot be written.");
+ }
+
+ public final Dimension getImageSize(byte 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
+ {
+
+ 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), params);
+ }
+
+ public abstract Dimension getImageSize(ByteSource byteSource, Map params)
+ throws ImageReadException, IOException;
+
+ public abstract String getXmpXml(ByteSource byteSource, Map params)
+ throws ImageReadException, IOException;
+
+ public final byte[] getICCProfileBytes(byte 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
+ {
+ 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), params);
+ }
+
+ public abstract byte[] getICCProfileBytes(ByteSource byteSource, Map params)
+ throws ImageReadException, IOException;
+
+ public final String dumpImageFile(byte bytes[]) throws ImageReadException,
+ IOException
+ {
+ return dumpImageFile(new ByteSourceArray(bytes));
+ }
+
+ public final String dumpImageFile(File file) throws ImageReadException,
+ IOException
+ {
+ if (!canAcceptExtension(file))
+ return null;
+
+ if (debug)
+ System.out.println(getName() + ": " + file.getName());
+
+ return dumpImageFile(new ByteSourceFile(file));
+ }
+
+ public final String dumpImageFile(ByteSource byteSource)
+ throws ImageReadException, IOException
+ {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+
+ dumpImageFile(pw, byteSource);
+
+ pw.flush();
+
+ return sw.toString();
+ }
+
+ public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
+ throws ImageReadException, IOException
+ {
+ return false;
+ }
+
+ public abstract boolean embedICCProfile(File src, File dst, byte profile[]);
+
+ public abstract String getName();
+
+ public abstract String getDefaultExtension();
+
+ protected abstract String[] getAcceptedExtensions();
+
+ protected abstract ImageFormat[] getAcceptedTypes();
+
+ public boolean canAcceptType(ImageFormat type)
+ {
+ ImageFormat types[] = getAcceptedTypes();
+
+ for (int i = 0; i < types.length; i++)
+ if (types[i].equals(type))
+ return true;
+ return false;
+ }
+
+ protected final boolean canAcceptExtension(File file)
+ {
+ return canAcceptExtension(file.getName());
+ }
+
+ protected final boolean canAcceptExtension(String filename)
+ {
+ String exts[] = getAcceptedExtensions();
+ if (exts == null)
+ return true;
+
+ int index = filename.lastIndexOf('.');
+ if (index >= 0)
+ {
+ String ext = filename.substring(index);
+ ext = ext.toLowerCase();
+
+ for (int i = 0; i < exts.length; i++)
+ if (exts[i].toLowerCase().equals(ext))
+ return true;
+ }
+ return false;
+ }
+
+ protected IBufferedImageFactory getBufferedImageFactory(Map params)
+ {
+ if (params == null)
+ return new SimpleBufferedImageFactory();
+
+ IBufferedImageFactory result = (IBufferedImageFactory) params
+ .get(SanselanConstants.BUFFERED_IMAGE_FACTORY);
+
+ if (null != result)
+ return result;
+
+ 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: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageReadException.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageReadException.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageReadException.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageReadException.java Fri Sep 10 16:33:35 2010
@@ -18,15 +18,15 @@ package org.apache.sanselan;
public class ImageReadException extends SanselanException
{
- static final long serialVersionUID = -1L;
+ static final long serialVersionUID = -1L;
- public ImageReadException(String s)
- {
- super(s);
- }
+ public ImageReadException(String s)
+ {
+ super(s);
+ }
- public ImageReadException(String s, Exception e)
- {
- super(s, e);
- }
+ public ImageReadException(String s, Exception e)
+ {
+ super(s, e);
+ }
}
\ No newline at end of file
Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageWriteException.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageWriteException.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageWriteException.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/ImageWriteException.java Fri Sep 10 16:33:35 2010
@@ -18,15 +18,15 @@ package org.apache.sanselan;
public class ImageWriteException extends SanselanException
{
- static final long serialVersionUID = -1L;
+ static final long serialVersionUID = -1L;
- public ImageWriteException(String s)
- {
- super(s);
- }
+ public ImageWriteException(String s)
+ {
+ super(s);
+ }
- public ImageWriteException(String s, Exception e)
- {
- super(s, e);
- }
+ public ImageWriteException(String s, Exception e)
+ {
+ super(s, e);
+ }
}
\ No newline at end of file