2898 lines · 116.6 KB · Java
RawDownload
    /**     * Reads the image indexed by <code>imageIndex</code> and returns     * an <code>IIOImage</code> containing the image, thumbnails, and     * associated image metadata, using a supplied     * <code>ImageReadParam</code>.     *     * <p> The actual <code>BufferedImage</code> referenced by the     * returned <code>IIOImage</code> will be chosen using the     * algorithm defined by the <code>getDestination</code> method.     *     * <p> Any registered <code>IIOReadProgressListener</code> objects     * will be notified by calling their <code>imageStarted</code>     * method, followed by calls to their <code>imageProgress</code>     * method as the read progresses.  Finally their     * <code>imageComplete</code> method will be called.     * <code>IIOReadUpdateListener</code> objects may be updated at     * other times during the read as pixels are decoded.  Finally,     * <code>IIOReadWarningListener</code> objects will receive     * notification of any non-fatal warnings that occur during     * decoding.     *     * <p> The set of source bands to be read and destination bands to     * be written is determined by calling <code>getSourceBands</code>     * and <code>getDestinationBands</code> on the supplied     * <code>ImageReadParam</code>.  If the lengths of the arrays     * returned by these methods differ, the set of source bands     * contains an index larger that the largest available source     * index, or the set of destination bands contains an index larger     * than the largest legal destination index, an     * <code>IllegalArgumentException</code> is thrown.     *     * <p> Thumbnails will be returned in their entirety regardless of     * the region settings.     *     * <p> If the supplied <code>ImageReadParam</code> contains     * optional setting values not supported by this reader (<i>e.g.</i>     * source render size or any format-specific settings), those     * values will be ignored.     *     * @param imageIndex the index of the image to be retrieved.     * @param param an <code>ImageReadParam</code> used to control     * the reading process, or <code>null</code>.     *     * @return an <code>IIOImage</code> containing the desired portion     * of the image, a set of thumbnails, and associated image     * metadata.     *     * @exception IllegalStateException if the input source has not been     * set.     * @exception IndexOutOfBoundsException if the supplied index is     * out of bounds.     * @exception IllegalArgumentException if the set of source and     * destination bands specified by     * <code>param.getSourceBands</code> and     * <code>param.getDestinationBands</code> differ in length or     * include indices that are out of bounds.     * @exception IllegalArgumentException if the resulting image     * would have a width or height less than 1.     * @exception IOException if an error occurs during reading.     */    public IIOImage readAll(int imageIndex, ImageReadParam param)        throws IOException {        if (imageIndex < getMinIndex()) {            throw new IndexOutOfBoundsException("imageIndex < getMinIndex()!");        }         BufferedImage im = read(imageIndex, param);         ArrayList thumbnails = null;        int numThumbnails = getNumThumbnails(imageIndex);        if (numThumbnails > 0) {            thumbnails = new ArrayList();            for (int j = 0; j < numThumbnails; j++) {                thumbnails.add(readThumbnail(imageIndex, j));            }        }         IIOMetadata metadata = getImageMetadata(imageIndex);        return new IIOImage(im, thumbnails, metadata);    }     /**     * Returns an <code>Iterator</code> containing all the images,     * thumbnails, and metadata, starting at the index given by     * <code>getMinIndex</code>, from the input source in the form of     * <code>IIOImage</code> objects.  An <code>Iterator</code>     * containing <code>ImageReadParam</code> objects is supplied; one     * element is consumed for each image read from the input source     * until no more images are available.  If the read param     * <code>Iterator</code> runs out of elements, but there are still     * more images available from the input source, default read     * params are used for the remaining images.     *     * <p> If <code>params</code> is <code>null</code>, a default read     * param will be used for all images.     *     * <p> The actual <code>BufferedImage</code> referenced by the     * returned <code>IIOImage</code> will be chosen using the     * algorithm defined by the <code>getDestination</code> method.     *     * <p> Any registered <code>IIOReadProgressListener</code> objects     * will be notified by calling their <code>sequenceStarted</code>     * method once.  Then, for each image decoded, there will be a     * call to <code>imageStarted</code>, followed by calls to     * <code>imageProgress</code> as the read progresses, and finally     * to <code>imageComplete</code>.  The     * <code>sequenceComplete</code> method will be called after the     * last image has been decoded.     * <code>IIOReadUpdateListener</code> objects may be updated at     * other times during the read as pixels are decoded.  Finally,     * <code>IIOReadWarningListener</code> objects will receive     * notification of any non-fatal warnings that occur during     * decoding.     *     * <p> The set of source bands to be read and destination bands to     * be written is determined by calling <code>getSourceBands</code>     * and <code>getDestinationBands</code> on the supplied     * <code>ImageReadParam</code>.  If the lengths of the arrays     * returned by these methods differ, the set of source bands     * contains an index larger that the largest available source     * index, or the set of destination bands contains an index larger     * than the largest legal destination index, an     * <code>IllegalArgumentException</code> is thrown.     *     * <p> Thumbnails will be returned in their entirety regardless of the     * region settings.     *     * <p> If any of the supplied <code>ImageReadParam</code>s contain     * optional setting values not supported by this reader (<i>e.g.</i>     * source render size or any format-specific settings), they will     * be ignored.     *     * @param params an <code>Iterator</code> containing     * <code>ImageReadParam</code> objects.     *     * @return an <code>Iterator</code> representing the     * contents of the input source as <code>IIOImage</code>s.     *     * @exception IllegalStateException if the input source has not been     * set.     * @exception IllegalArgumentException if any     * non-<code>null</code> element of <code>params</code> is not an     * <code>ImageReadParam</code>.     * @exception IllegalArgumentException if the set of source and     * destination bands specified by     * <code>param.getSourceBands</code> and     * <code>param.getDestinationBands</code> differ in length or     * include indices that are out of bounds.     * @exception IllegalArgumentException if a resulting image would     * have a width or height less than 1.     * @exception IOException if an error occurs during reading.     *     * @see ImageReadParam     * @see IIOImage     */    public Iterator<IIOImage>        readAll(Iterator<? extends ImageReadParam> params)        throws IOException    {        List output = new ArrayList();         int imageIndex = getMinIndex();         // Inform IIOReadProgressListeners we're starting a sequence        processSequenceStarted(imageIndex);         while (true) {            // Inform IIOReadProgressListeners and IIOReadUpdateListeners            // that we're starting a new image             ImageReadParam param = null;            if (params != null && params.hasNext()) {                Object o = params.next();                if (o != null) {                    if (o instanceof ImageReadParam) {                        param = (ImageReadParam)o;                    } else {                        throw new IllegalArgumentException                            ("Non-ImageReadParam supplied as part of params!");                    }                }            }             BufferedImage bi = null;            try {                bi = read(imageIndex, param);            } catch (IndexOutOfBoundsException e) {                break;            }             ArrayList thumbnails = null;            int numThumbnails = getNumThumbnails(imageIndex);            if (numThumbnails > 0) {                thumbnails = new ArrayList();                for (int j = 0; j < numThumbnails; j++) {                    thumbnails.add(readThumbnail(imageIndex, j));                }            }             IIOMetadata metadata = getImageMetadata(imageIndex);            IIOImage im = new IIOImage(bi, thumbnails, metadata);            output.add(im);             ++imageIndex;        }         // Inform IIOReadProgressListeners we're ending a sequence        processSequenceComplete();         return output.iterator();    }     /**     * Returns <code>true</code> if this plug-in supports reading     * just a {@link java.awt.image.Raster <code>Raster</code>} of pixel data.     * If this method returns <code>false</code>, calls to     * {@link #readRaster <code>readRaster</code>} or {@link #readTileRaster     * <code>readTileRaster</code>} will throw an     * <code>UnsupportedOperationException</code>.     *     * <p> The default implementation returns <code>false</code>.     *     * @return <code>true</code> if this plug-in supports reading raw     * <code>Raster</code>s.     *     * @see #readRaster     * @see #readTileRaster     */    public boolean canReadRaster() {        return false;    }     /**     * Returns a new <code>Raster</code> object containing the raw pixel data     * from the image stream, without any color conversion applied.  The     * application must determine how to interpret the pixel data by other     * means.  Any destination or image-type parameters in the supplied     * <code>ImageReadParam</code> object are ignored, but all other     * parameters are used exactly as in the {@link #read <code>read</code>}     * method, except that any destination offset is used as a logical rather     * than a physical offset.  The size of the returned <code>Raster</code>     * will always be that of the source region clipped to the actual image.     * Logical offsets in the stream itself are ignored.     *     * <p> This method allows formats that normally apply a color     * conversion, such as JPEG, and formats that do not normally have an     * associated colorspace, such as remote sensing or medical imaging data,     * to provide access to raw pixel data.     *     * <p> Any registered <code>readUpdateListener</code>s are ignored, as     * there is no <code>BufferedImage</code>, but all other listeners are     * called exactly as they are for the {@link #read <code>read</code>}     * method.     *     * <p> If {@link #canReadRaster <code>canReadRaster()</code>} returns     * <code>false</code>, this method throws an     * <code>UnsupportedOperationException</code>.     *     * <p> If the supplied <code>ImageReadParam</code> contains     * optional setting values not supported by this reader (<i>e.g.</i>     * source render size or any format-specific settings), they will     * be ignored.     *     * <p> The default implementation throws an     * <code>UnsupportedOperationException</code>.     *     * @param imageIndex the index of the image to be read.     * @param param an <code>ImageReadParam</code> used to control     * the reading process, or <code>null</code>.     *     * @return the desired portion of the image as a     * <code>Raster</code>.     *     * @exception UnsupportedOperationException if this plug-in does not     * support reading raw <code>Raster</code>s.     * @exception IllegalStateException if the input source has not been     * set.     * @exception IndexOutOfBoundsException if the supplied index is     * out of bounds.     * @exception IOException if an error occurs during reading.     *     * @see #canReadRaster     * @see #read     * @see java.awt.image.Raster     */    public Raster readRaster(int imageIndex, ImageReadParam param)        throws IOException {        throw new UnsupportedOperationException("readRaster not supported!");    }     /**     * Returns <code>true</code> if the image is organized into     * <i>tiles</i>, that is, equal-sized non-overlapping rectangles.     *     * <p> A reader plug-in may choose whether or not to expose tiling     * that is present in the image as it is stored.  It may even     * choose to advertise tiling when none is explicitly present.  In     * general, tiling should only be advertised if there is some     * advantage (in speed or space) to accessing individual tiles.     * Regardless of whether the reader advertises tiling, it must be     * capable of reading an arbitrary rectangular region specified in     * an <code>ImageReadParam</code>.     *     * <p> A reader for which all images are guaranteed to be tiled,     * or are guaranteed not to be tiled, may return <code>true</code>     * or <code>false</code> respectively without accessing any image     * data.  In such cases, it is not necessary to throw an exception     * even if no input source has been set or the image index is out     * of bounds.     *     * <p> The default implementation just returns <code>false</code>.     *     * @param imageIndex the index of the image to be queried.     *     * @return <code>true</code> if the image is tiled.     *     * @exception IllegalStateException if an input source is required     * to determine the return value, but none has been set.     * @exception IndexOutOfBoundsException if an image must be     * accessed to determine the return value, but the supplied index     * is out of bounds.     * @exception IOException if an error occurs during reading.     */    public boolean isImageTiled(int imageIndex) throws IOException {        return false;    }     /**     * Returns the width of a tile in the given image.     *     * <p> The default implementation simply returns     * <code>getWidth(imageIndex)</code>, which is correct for     * non-tiled images.  Readers that support tiling should override     * this method.     *     * @return the width of a tile.     *     * @param imageIndex the index of the image to be queried.     *     * @exception IllegalStateException if the input source has not been set.     * @exception IndexOutOfBoundsException if the supplied index is     * out of bounds.     * @exception IOException if an error occurs during reading.     */    public int getTileWidth(int imageIndex) throws IOException {        return getWidth(imageIndex);    }     /**     * Returns the height of a tile in the given image.     *     * <p> The default implementation simply returns     * <code>getHeight(imageIndex)</code>, which is correct for     * non-tiled images.  Readers that support tiling should override     * this method.     *     * @return the height of a tile.     *     * @param imageIndex the index of the image to be queried.     *     * @exception IllegalStateException if the input source has not been set.     * @exception IndexOutOfBoundsException if the supplied index is     * out of bounds.     * @exception IOException if an error occurs during reading.     */    public int getTileHeight(int imageIndex) throws IOException {        return getHeight(imageIndex);    }     /**     * Returns the X coordinate of the upper-left corner of tile (0,     * 0) in the given image.     *     * <p> A reader for which the tile grid X offset always has the     * same value (usually 0), may return the value without accessing     * any image data.  In such cases, it is not necessary to throw an     * exception even if no input source has been set or the image     * index is out of bounds.     *     * <p> The default implementation simply returns 0, which is     * correct for non-tiled images and tiled images in most formats.     * Readers that support tiling with non-(0, 0) offsets should     * override this method.     *     * @return the X offset of the tile grid.     *     * @param imageIndex the index of the image to be queried.     *     * @exception IllegalStateException if an input source is required     * to determine the return value, but none has been set.     * @exception IndexOutOfBoundsException if an image must be     * accessed to determine the return value, but the supplied index     * is out of bounds.     * @exception IOException if an error occurs during reading.     */    public int getTileGridXOffset(int imageIndex) throws IOException {        return 0;    }     /**     * Returns the Y coordinate of the upper-left corner of tile (0,     * 0) in the given image.     *     * <p> A reader for which the tile grid Y offset always has the     * same value (usually 0), may return the value without accessing     * any image data.  In such cases, it is not necessary to throw an     * exception even if no input source has been set or the image     * index is out of bounds.     *     * <p> The default implementation simply returns 0, which is     * correct for non-tiled images and tiled images in most formats.     * Readers that support tiling with non-(0, 0) offsets should     * override this method.     *     * @return the Y offset of the tile grid.     *     * @param imageIndex the index of the image to be queried.     *     * @exception IllegalStateException if an input source is required     * to determine the return value, but none has been set.     * @exception IndexOutOfBoundsException if an image must be     * accessed to determine the return value, but the supplied index     * is out of bounds.     * @exception IOException if an error occurs during reading.     */    public int getTileGridYOffset(int imageIndex) throws IOException {        return 0;    }     /**     * Reads the tile indicated by the <code>tileX</code> and     * <code>tileY</code> arguments, returning it as a     * <code>BufferedImage</code>.  If the arguments are out of range,     * an <code>IllegalArgumentException</code> is thrown.  If the     * image is not tiled, the values 0, 0 will return the entire     * image; any other values will cause an     * <code>IllegalArgumentException</code> to be thrown.     *     * <p> This method is merely a convenience equivalent to calling     * <code>read(int, ImageReadParam)</code> with a read param     * specifiying a source region having offsets of     * <code>tileX*getTileWidth(imageIndex)</code>,     * <code>tileY*getTileHeight(imageIndex)</code> and width and     * height of <code>getTileWidth(imageIndex)</code>,     * <code>getTileHeight(imageIndex)</code>; and subsampling     * factors of 1 and offsets of 0.  To subsample a tile, call     * <code>read</code> with a read param specifying this region     * and different subsampling parameters.     *     * <p> The default implementation returns the entire image if     * <code>tileX</code> and <code>tileY</code> are 0, or throws     * an <code>IllegalArgumentException</code> otherwise.     *     * @param imageIndex the index of the image to be retrieved.     * @param tileX the column index (starting with 0) of the tile     * to be retrieved.     * @param tileY the row index (starting with 0) of the tile     * to be retrieved.     *     * @return the tile as a <code>BufferedImage</code>.     *     * @exception IllegalStateException if the input source has not been     * set.     * @exception IndexOutOfBoundsException if <code>imageIndex</code>     * is out of bounds.     * @exception IllegalArgumentException if the tile indices are     * out of bounds.     * @exception IOException if an error occurs during reading.     */    public BufferedImage readTile(int imageIndex,                                  int tileX, int tileY) throws IOException {        if ((tileX != 0) || (tileY != 0)) {            throw new IllegalArgumentException("Invalid tile indices");        }        return read(imageIndex);    }     /**     * Returns a new <code>Raster</code> object containing the raw     * pixel data from the tile, without any color conversion applied.     * The application must determine how to interpret the pixel data by other     * means.     *     * <p> If {@link #canReadRaster <code>canReadRaster()</code>} returns     * <code>false</code>, this method throws an     * <code>UnsupportedOperationException</code>.     *     * <p> The default implementation checks if reading     * <code>Raster</code>s is supported, and if so calls {@link     * #readRaster <code>readRaster(imageIndex, null)</code>} if     * <code>tileX</code> and <code>tileY</code> are 0, or throws an     * <code>IllegalArgumentException</code> otherwise.     *     * @param imageIndex the index of the image to be retrieved.     * @param tileX the column index (starting with 0) of the tile     * to be retrieved.     * @param tileY the row index (starting with 0) of the tile     * to be retrieved.     *     * @return the tile as a <code>Raster</code>.

Lines 1001–1500 of 2898. Previous lines