Here comes the first part of the ImageIO plugin for PNG, the PNGImageReader and related classes.

2006-07-20  Roman Kennke  <[EMAIL PROTECTED]>

        * gnu/javax/imageio/IIOInputStream.java: New class. Wraps
        ImageInputStreams as normal InputStreams.
        * gnu/javax/imageio/gif/GIFStream.java:
        Moved to gnu/javax/imageio/IIOInputStream.java.
        * gnu/javax/imageio/gif/GIFImageReader.java
        (readImage): Use IIOInputStream.
        * gnu/javax/imageio/gif/GIFImageReaderSpi.java
        (canDecodeInput): Use IIOInputStream.
        * gnu/javax/imageio/png/PNGException.java: Make subclass
        of IOException.
        * gnu/javax/imageio/png/PNGImageReader.java: New class.
        Implements the ImageIO ImageReader for PNG.
        * gnu/javax/imageio/png/PNGImageReaderSpi.java: New class.
        Implements the ImageIO ImageReaderSpi for PNG.
        * javax/imageio/spi/IIORegistry.java:
        (IIORegistry): Add PNGImageReaderSpi.

/Roman
Index: javax/imageio/spi/IIORegistry.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/imageio/spi/IIORegistry.java,v
retrieving revision 1.10
diff -u -1 -2 -r1.10 IIORegistry.java
--- javax/imageio/spi/IIORegistry.java	27 Jun 2006 12:30:17 -0000	1.10
+++ javax/imageio/spi/IIORegistry.java	20 Jul 2006 10:13:39 -0000
@@ -40,24 +40,25 @@
 
 import gnu.classpath.ServiceFactory;
 import gnu.java.awt.ClasspathToolkit;
 
 import java.awt.Toolkit;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 
 import gnu.javax.imageio.bmp.BMPImageReaderSpi;
 import gnu.javax.imageio.bmp.BMPImageWriterSpi;
 import gnu.javax.imageio.gif.GIFImageReaderSpi;
+import gnu.javax.imageio.png.PNGImageReaderSpi;
 
 public final class IIORegistry extends ServiceRegistry
 {
   private static final HashSet defaultCategories = new HashSet();
   
   private static HashMap instances = new HashMap();
 
   static
   {
     defaultCategories.add(ImageReaderSpi.class);
     defaultCategories.add(ImageWriterSpi.class);
     defaultCategories.add(ImageTranscoderSpi.class);
@@ -76,25 +77,26 @@
         registry = new IIORegistry();
         instances.put(group, registry);
       }
     
     return registry;
   }
 
   private IIORegistry()
   {
     super(defaultCategories.iterator());
 
     // XXX: Register built-in Spis here.
-    registerServiceProvider(new GIFImageReaderSpi()); // Register GIF decoder
+    registerServiceProvider(new PNGImageReaderSpi()); // Register PNG decoder.
+    registerServiceProvider(new GIFImageReaderSpi()); // Register GIF decoder.
     registerServiceProvider(new BMPImageReaderSpi());
     registerServiceProvider(new BMPImageWriterSpi());
 
     Toolkit toolkit = Toolkit.getDefaultToolkit();
     if (toolkit instanceof ClasspathToolkit)
       ((ClasspathToolkit)toolkit).registerImageIOSpis(this);
     
     registerApplicationClasspathSpis();
   }
 
   /**
    * Registers all available service providers found on the application
Index: gnu/javax/imageio/IIOInputStream.java
===================================================================
RCS file: gnu/javax/imageio/IIOInputStream.java
diff -N gnu/javax/imageio/IIOInputStream.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/javax/imageio/IIOInputStream.java	20 Jul 2006 10:13:39 -0000
@@ -0,0 +1,102 @@
+/* GIFStream.java --
+   Copyright (C)  2006  Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.javax.imageio;
+
+import java.io.InputStream;
+import java.io.IOException;
+import javax.imageio.stream.ImageInputStream;
+
+/**
+ * Implements InputStream on an ImageInputStream
+ * The purpose of this is to avoid IIO dependencies in the various decoders.
+ * (which only use read() anyway).
+ */
+public class IIOInputStream extends InputStream
+{
+  private ImageInputStream is;
+
+  public IIOInputStream( ImageInputStream is )
+  {
+    this.is = is;
+  }
+
+  public int available()
+  {
+    return 0;
+  }
+
+  public void close() throws IOException
+  {
+    is.close();
+  }
+
+  public void mark(int readlimit)
+  {
+    is.mark();
+  }
+
+  public boolean markSupported()
+  {
+    return true;
+  }
+
+  public int read() throws IOException
+  {
+    return is.read();    
+  }
+
+  public int read(byte[] b) throws IOException
+  {
+    return is.read(b);
+  }
+
+  public int read(byte[] b, int offset, int length) throws IOException
+  {
+    return is.read(b, offset, length);
+  }
+
+  public void reset() throws IOException
+  {
+    is.reset();
+  }
+
+  public long skip(long n) throws IOException
+  {
+    return is.skipBytes(n);
+  }
+}
Index: gnu/javax/imageio/gif/GIFImageReader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/imageio/gif/GIFImageReader.java,v
retrieving revision 1.2
diff -u -1 -2 -r1.2 GIFImageReader.java
--- gnu/javax/imageio/gif/GIFImageReader.java	13 Jul 2006 21:49:22 -0000	1.2
+++ gnu/javax/imageio/gif/GIFImageReader.java	20 Jul 2006 10:13:39 -0000
@@ -28,24 +28,26 @@
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 package gnu.javax.imageio.gif;
 
+import gnu.javax.imageio.IIOInputStream;
+
 import java.io.IOException;
 import java.io.InputStream;
 import javax.imageio.*;
 import javax.imageio.spi.*;
 import javax.imageio.metadata.*;
 import javax.imageio.stream.ImageInputStream;
 import java.util.Iterator;
 import java.awt.image.BufferedImage;
 import java.awt.image.IndexColorModel;
 import java.awt.image.SampleModel;
 import java.awt.image.MultiPixelPackedSampleModel;
 import java.awt.image.SinglePixelPackedSampleModel;
@@ -65,25 +67,25 @@
   }
   
   private void readImage() throws IOException
   {
     if( file != null )
       return;
 
     try
       {
 	if( input instanceof InputStream )
 	  file = new GIFFile( (InputStream)input );
 	else
-	  file = new GIFFile( new GIFStream((ImageInputStream)input) );
+	  file = new GIFFile( new IIOInputStream((ImageInputStream)input) );
       }
     catch(GIFFile.GIFException ge)
       {
 	throw new IIOException(ge.getMessage());
       }
   }
 
   /**
    * Returns the Global/Local palette as an IndexColorModel
    */
   private IndexColorModel getPalette(int index)
   {
Index: gnu/javax/imageio/gif/GIFImageReaderSpi.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/imageio/gif/GIFImageReaderSpi.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 GIFImageReaderSpi.java
--- gnu/javax/imageio/gif/GIFImageReaderSpi.java	26 Jun 2006 16:06:30 -0000	1.1
+++ gnu/javax/imageio/gif/GIFImageReaderSpi.java	20 Jul 2006 10:13:39 -0000
@@ -28,24 +28,26 @@
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 package gnu.javax.imageio.gif;
 
+import gnu.javax.imageio.IIOInputStream;
+
 import java.io.InputStream;
 import java.io.IOException;
 import java.util.Locale;
 import javax.imageio.ImageReader;
 import javax.imageio.spi.ImageReaderSpi;
 import javax.imageio.stream.ImageInputStream;
 
 public class GIFImageReaderSpi extends ImageReaderSpi 
 {
   static final String vendorName = "GNU";
   static final String version = "0.1";
   static final String readerClassName =
@@ -95,25 +97,25 @@
     throws IOException 
   {
     if( input == null )
       throw new IllegalArgumentException("Input object cannot be null.");
 
     if( !(input instanceof ImageInputStream) && 
 	!(input instanceof InputStream)) 
       return false;
 
     boolean retval;
     InputStream in;
     if( input instanceof ImageInputStream )
-      in = new GIFStream( (ImageInputStream)input );
+      in = new IIOInputStream( (ImageInputStream)input );
     else
       in = (InputStream)input;
 
     in.mark(10); // we read 6 bytes
     retval = GIFFile.readSignature( in );
     in.reset();
 
     return retval;
   }
     
   public ImageReader createReaderInstance(Object extension) 
   {
Index: gnu/javax/imageio/gif/GIFStream.java
===================================================================
RCS file: gnu/javax/imageio/gif/GIFStream.java
diff -N gnu/javax/imageio/gif/GIFStream.java
--- gnu/javax/imageio/gif/GIFStream.java	26 Jun 2006 16:06:30 -0000	1.1
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,102 +0,0 @@
-/* GIFStream.java --
-   Copyright (C)  2006  Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING.  If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library.  Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module.  An independent module is a module which is not derived from
-or based on this library.  If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so.  If you do not wish to do so, delete this
-exception statement from your version. */
-
-package gnu.javax.imageio.gif;
-
-import java.io.InputStream;
-import java.io.IOException;
-import javax.imageio.stream.ImageInputStream;
-
-/**
- * Implements InputStream on an ImageInputStream
- * The purpose of this is to avoid IIO dependencies in GIFFile
- * (which only uses read() anyway).
- */
-public class GIFStream extends InputStream
-{
-  private ImageInputStream is;
-
-  public GIFStream( ImageInputStream is )
-  {
-    this.is = is;
-  }
-
-  public int available()
-  {
-    return 0;
-  }
-
-  public void close() throws IOException
-  {
-    is.close();
-  }
-
-  public void mark(int readlimit)
-  {
-    is.mark();
-  }
-
-  public boolean markSupported()
-  {
-    return true;
-  }
-
-  public int read() throws IOException
-  {
-    return is.read();    
-  }
-
-  public int read(byte[] b) throws IOException
-  {
-    return is.read(b);
-  }
-
-  public int read(byte[] b, int offset, int length) throws IOException
-  {
-    return is.read(b, offset, length);
-  }
-
-  public void reset() throws IOException
-  {
-    is.reset();
-  }
-
-  public long skip(long n) throws IOException
-  {
-    return is.skipBytes(n);
-  }
-}
Index: gnu/javax/imageio/png/PNGException.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/imageio/png/PNGException.java,v
retrieving revision 1.1
diff -u -1 -2 -r1.1 PNGException.java
--- gnu/javax/imageio/png/PNGException.java	19 Jul 2006 16:49:18 -0000	1.1
+++ gnu/javax/imageio/png/PNGException.java	20 Jul 2006 10:13:39 -0000
@@ -28,19 +28,21 @@
 executable, regardless of the license terms of these independent
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 package gnu.javax.imageio.png;
 
-public class PNGException extends Exception 
+import java.io.IOException;
+
+public class PNGException extends IOException 
 {
   public PNGException(String msg)
   {
     super( msg );
   }
 }
Index: gnu/javax/imageio/png/PNGImageReader.java
===================================================================
RCS file: gnu/javax/imageio/png/PNGImageReader.java
diff -N gnu/javax/imageio/png/PNGImageReader.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/javax/imageio/png/PNGImageReader.java	20 Jul 2006 10:13:39 -0000
@@ -0,0 +1,224 @@
+/* PNGImageReader.java -- The ImageIO ImageReader for PNG
+   Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.imageio.png;
+
+import gnu.javax.imageio.IIOInputStream;
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.imageio.ImageReadParam;
+import javax.imageio.ImageReader;
+import javax.imageio.ImageTypeSpecifier;
+import javax.imageio.metadata.IIOMetadata;
+import javax.imageio.stream.ImageInputStream;
+
+/**
+ * The ImageIO ImageReader for PNG images.
+ *
+ * @author Roman Kennke ([EMAIL PROTECTED])
+ */
+public class PNGImageReader
+  extends ImageReader
+{
+
+  /**
+   * The PNG file.
+   */
+  private PNGFile pngFile;
+
+  /**
+   * The decoded image.
+   */
+  private BufferedImage image;
+
+  /**
+   * The supported image types for PNG.
+   */
+  private ArrayList imageTypes;
+
+  /**
+   * Creates a new instance.
+   *
+   * @param spi the corresponding ImageReaderSpi
+   */
+  public PNGImageReader(PNGImageReaderSpi spi)
+  {
+    super(spi);
+  }
+
+  /**
+   * Returns the height of the image.
+   */
+  public int getHeight(int imageIndex)
+    throws IOException
+  {
+    checkIndex(imageIndex);
+    readImage();
+    return image.getHeight();
+  }
+
+  /**
+   * Returns the width of the image.
+   *
+   * @param imageIndex the index of the image
+   *
+   * @return the width of the image
+   */
+  public int getWidth(int imageIndex) throws IOException
+  {
+    checkIndex(imageIndex);
+    readImage();
+    return image.getWidth();
+  }
+
+  /**
+   * Returns the image types for the image.
+   *
+   * @see ImageReader#getImageTypes(int)
+   */
+  public Iterator getImageTypes(int imageIndex)
+    throws IOException
+  {
+    checkIndex(imageIndex);
+    readImage();
+    if (imageTypes == null)
+      {
+        imageTypes = new ArrayList();
+        imageTypes.add(new ImageTypeSpecifier(image.getColorModel(),
+                                              image.getSampleModel()));
+      }
+    return imageTypes.iterator();
+  }
+
+  /**
+   * Returns the number of images in the stream.
+   *
+   * @return the number of images in the stream
+   *
+   * @see ImageReader#getNumImages(boolean)
+   */
+  public int getNumImages(boolean allowSearch)
+    throws IOException
+  {
+    return 1;
+  }
+
+  /**
+   * Reads the image.
+   *
+   * @param imageIndex the index of the image to read
+   * @param param additional parameters
+   */
+  public BufferedImage read(int imageIndex, ImageReadParam param)
+    throws IOException
+  {
+    checkIndex(imageIndex);
+    readImage();
+    return image;
+  }
+
+  /**
+   * Sets the input and checks the input parameter.
+   *
+   * @see ImageReader#setInput(Object, boolean, boolean)
+   */
+  public void setInput(Object input, 
+                       boolean seekForwardOnly, 
+                       boolean ignoreMetadata) 
+  {
+    super.setInput(input, seekForwardOnly, ignoreMetadata);
+    if (! (input instanceof InputStream || input instanceof ImageInputStream))
+      throw new IllegalArgumentException("Input not an ImageInputStream");
+  }
+
+  public IIOMetadata getImageMetadata(int imageIndex)
+    throws IOException
+  {
+    // TODO: Not (yet) supported.
+    checkIndex(imageIndex);
+    return null;
+  }
+
+  public IIOMetadata getStreamMetadata()
+    throws IOException
+  {
+    // TODO: Not (yet) supported.
+    return null;
+  }
+
+  /**
+   * Checks the image indexa and throws and IndexOutOfBoundsException if
+   * appropriate.
+   *
+   * @param index the index to check
+   */
+  private void checkIndex(int index)
+  {
+    if (index > 0)
+      throw new IndexOutOfBoundsException("Image index out of bounds");
+  }
+
+  /**
+   * Makes sure that the image is read.
+   *
+   * @throws IOException if something goes wrong
+   */
+  private void readImage()
+    throws IOException
+  {
+    if (pngFile == null)
+      {
+        if (input instanceof InputStream)
+          pngFile = new PNGFile((InputStream) input);
+        else if (input instanceof ImageInputStream)
+          pngFile = new PNGFile(new IIOInputStream((ImageInputStream) input));
+        else
+          assert false : "Must not happen";
+      }
+
+    if (pngFile != null && image == null)
+      {
+        image = pngFile.getBufferedImage();
+      }
+  }
+}
Index: gnu/javax/imageio/png/PNGImageReaderSpi.java
===================================================================
RCS file: gnu/javax/imageio/png/PNGImageReaderSpi.java
diff -N gnu/javax/imageio/png/PNGImageReaderSpi.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/javax/imageio/png/PNGImageReaderSpi.java	20 Jul 2006 10:13:39 -0000
@@ -0,0 +1,128 @@
+/* PNGImageReaderSpi.java -- The ImageReader service provider for PNG
+   Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.imageio.png;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Locale;
+
+import javax.imageio.ImageReader;
+import javax.imageio.spi.ImageReaderSpi;
+import javax.imageio.stream.ImageInputStream;
+
+/**
+ * The ImageIO ImageReader service provider for PNG images.
+ *
+ * @author Roman Kennke ([EMAIL PROTECTED])
+ */
+public class PNGImageReaderSpi
+  extends ImageReaderSpi
+{
+
+  /**
+   * The PNG file signature.
+   */
+  private static final byte[] SIGNATURE = new byte[]
+                              { (byte) 137, 80, 78, 71, 13, 10, 26, 10 };
+
+  private static final String VENDOR_NAME = "GNU";
+  static final String VERSION = "1.0";
+  static final String READER_CLASSNAME =
+                                       "gnu.javax.imageio.png.PNGImageReader";
+  static final String[] NAMES = { "Portable Network Graphics" };
+  static final String[] SUFFIXES = { ".png" , ".PNG" };
+  static final String[] MIME_TYPES = { "image/png" };
+  static final String[] WRITER_SPI_NAMES =
+    new String[] { "gnu.javax.imageio.png.PNGWriterSpi" };
+  static final Class[] INPUT_TYPES = new Class[]{ InputStream.class,
+                                                  ImageInputStream.class};
+  public PNGImageReaderSpi()
+  {
+    super(VENDOR_NAME, VERSION, NAMES, SUFFIXES, MIME_TYPES, READER_CLASSNAME,
+          INPUT_TYPES, WRITER_SPI_NAMES, false, null, null, null, null, false,
+          null, null, null, null);
+  }
+
+  /**
+   * Determines if the PNG ImageReader can decode the specified input.
+   *
+   * @param source the source to decode
+   */
+  public boolean canDecodeInput(Object source) throws IOException
+  {
+    boolean canDecode = false;
+    if (source instanceof ImageInputStream)
+      {
+        ImageInputStream in = (ImageInputStream) source;
+        in.mark();
+        canDecode = true;
+        for (int i = 0; i < SIGNATURE.length && canDecode; i++)
+          {
+            byte sig = (byte) in.read();
+            if (sig != SIGNATURE[i]) {
+              canDecode = false;
+            }
+          }
+        in.reset();
+      }
+    return canDecode;
+  }
+
+  /**
+   * Returns a new PNGImageReader instance.
+   *
+   * @param extension the extension, ignored
+   */
+  public ImageReader createReaderInstance(Object extension)
+    throws IOException
+  {
+    return new PNGImageReader(this);
+  }
+
+  /**
+   * Returns a description.
+   *
+   * @param locale the locale
+   */
+  public String getDescription(Locale locale)
+  {
+    return "Portable Network Graphics";
+  }
+
+}

Reply via email to