public Filter handleStream(InputStream inIS,
                               ParsedURL origURL,
                               boolean     needRawData) {
        final DeferRable dr  = new DeferRable();
        final InputStream is  = inIS;
        final String      errCode;
        final Object []   errParam;
        if (origURL != null) {
            errCode  = ERR_URL_FORMAT_UNREADABLE;
            errParam = new Object[] {getFormatName(), origURL};
        } else {
            errCode  = ERR_STREAM_FORMAT_UNREADABLE;
            errParam = new Object[] {getFormatName()};
        }

        Thread t = new Thread() {
                @Override
                public void run() {
                    Filter filt;
                    try{
                        Iterator<ImageReader> iter = ImageIO.getImageReadersByMIMEType(
                                getMimeTypes().get(0).toString());
                        if (!iter.hasNext()) {
                            throw new UnsupportedOperationException(
                                    "No image reader for "
                                        + getFormatName() + " available!");
                        }
                        ImageReader reader = iter.next();
                        ImageInputStream imageIn = ImageIO.createImageInputStream(is);
                        reader.setInput(imageIn, true);

                        int imageIndex = 0;
                        dr.setBounds(new Rectangle2D.Double
                                     (0, 0,
                                      reader.getWidth(imageIndex),
                                      reader.getHeight(imageIndex)));
                        CachableRed cr;
                        //Naive approach possibly wasting lots of memory
                        //and ignoring the gamma correction done by PNGRed :-(
                        //Matches the code used by the former JPEGRegistryEntry, though.
                        BufferedImage bi = reader.read(imageIndex);
                        if(bi.getType() == BufferedImage.TYPE_BYTE_INDEXED) {
                            BufferedImage image = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB);
                            Graphics2D g2d = image.createGraphics();
                            g2d.drawImage(bi, 0, 0, null);
                            g2d.dispose();
                            cr = GraphicsUtil.wrap(image);
                        } else {
                            cr = GraphicsUtil.wrap(bi);
                            cr = new Any2sRGBRed(cr);
                            cr = new FormatRed(cr, GraphicsUtil.sRGB_Unpre);
                            WritableRaster wr = (WritableRaster)cr.getData();
                            ColorModel cm = cr.getColorModel();
                            BufferedImage image = new BufferedImage
                                (cm, wr, cm.isAlphaPremultiplied(), null);
                            cr = GraphicsUtil.wrap(image);
                        }
                        filt = new RedRable(cr);
                    } catch (IOException ioe) {
                        // Something bad happened here...
                        filt = ImageTagRegistry.getBrokenLinkImage
                            (AbstractImageIORegistryEntry.this,
                             errCode, errParam);
                    } catch (ThreadDeath td) {
                        filt = ImageTagRegistry.getBrokenLinkImage
                            (AbstractImageIORegistryEntry.this,
                             errCode, errParam);
                        dr.setSource(filt);
                        throw td;
                    } catch (Throwable t) {
                        filt = ImageTagRegistry.getBrokenLinkImage
                            (AbstractImageIORegistryEntry.this,
                             errCode, errParam);
                    }

                    dr.setSource(filt);
                }
            };
        t.start();
        return dr;
    }
Decode the Stream into a RenderableImage

@param inIS The input stream that contains the image.
@param origURL The original URL, if any, for documentation
               purposes only.  This may be null.
@param needRawData If true the image returned should not have
                   any default color correction the file may
                   specify applied.
plugins/svg-plugin/batik-codec-fix/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/AbstractImageIORegistryEntry.java