0N/A/*
2362N/A * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.imageio;
0N/A
0N/Aimport java.awt.Point;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.RenderedImage;
0N/Aimport java.io.IOException;
0N/Aimport java.util.ArrayList;
0N/Aimport java.util.Iterator;
0N/Aimport java.util.List;
0N/Aimport java.util.Locale;
0N/Aimport java.util.MissingResourceException;
0N/Aimport java.util.ResourceBundle;
0N/Aimport java.util.Set;
0N/Aimport javax.imageio.spi.ImageReaderSpi;
0N/Aimport javax.imageio.event.IIOReadWarningListener;
0N/Aimport javax.imageio.event.IIOReadProgressListener;
0N/Aimport javax.imageio.event.IIOReadUpdateListener;
0N/Aimport javax.imageio.metadata.IIOMetadata;
0N/Aimport javax.imageio.metadata.IIOMetadataFormatImpl;
0N/Aimport javax.imageio.stream.ImageInputStream;
0N/A
0N/A/**
0N/A * An abstract superclass for parsing and decoding of images. This
0N/A * class must be subclassed by classes that read in images in the
0N/A * context of the Java Image I/O framework.
0N/A *
0N/A * <p> <code>ImageReader</code> objects are normally instantiated by
0N/A * the service provider interface (SPI) class for the specific format.
0N/A * Service provider classes (e.g., instances of
0N/A * <code>ImageReaderSpi</code>) are registered with the
0N/A * <code>IIORegistry</code>, which uses them for format recognition
0N/A * and presentation of available format readers and writers.
0N/A *
0N/A * <p> When an input source is set (using the <code>setInput</code>
0N/A * method), it may be marked as "seek forward only". This setting
0N/A * means that images contained within the input source will only be
0N/A * read in order, possibly allowing the reader to avoid caching
0N/A * portions of the input containing data associated with images that
0N/A * have been read previously.
0N/A *
0N/A * @see ImageWriter
0N/A * @see javax.imageio.spi.IIORegistry
0N/A * @see javax.imageio.spi.ImageReaderSpi
0N/A *
0N/A */
0N/Apublic abstract class ImageReader {
0N/A
0N/A /**
0N/A * The <code>ImageReaderSpi</code> that instantiated this object,
0N/A * or <code>null</code> if its identity is not known or none
0N/A * exists. By default it is initialized to <code>null</code>.
0N/A */
0N/A protected ImageReaderSpi originatingProvider;
0N/A
0N/A /**
0N/A * The <code>ImageInputStream</code> or other
0N/A * <code>Object</code> by <code>setInput</code> and retrieved
0N/A * by <code>getInput</code>. By default it is initialized to
0N/A * <code>null</code>.
0N/A */
0N/A protected Object input = null;
0N/A
0N/A /**
0N/A * <code>true</code> if the current input source has been marked
0N/A * as allowing only forward seeking by <code>setInput</code>. By
0N/A * default, the value is <code>false</code>.
0N/A *
0N/A * @see #minIndex
0N/A * @see #setInput
0N/A */
0N/A protected boolean seekForwardOnly = false;
0N/A
0N/A /**
0N/A * <code>true</code> if the current input source has been marked
0N/A * as allowing metadata to be ignored by <code>setInput</code>.
0N/A * By default, the value is <code>false</code>.
0N/A *
0N/A * @see #setInput
0N/A */
0N/A protected boolean ignoreMetadata = false;
0N/A
0N/A /**
0N/A * The smallest valid index for reading, initially 0. When
0N/A * <code>seekForwardOnly</code> is <code>true</code>, various methods
0N/A * may throw an <code>IndexOutOfBoundsException</code> on an
0N/A * attempt to access data associate with an image having a lower
0N/A * index.
0N/A *
0N/A * @see #seekForwardOnly
0N/A * @see #setInput
0N/A */
0N/A protected int minIndex = 0;
0N/A
0N/A /**
0N/A * An array of <code>Locale</code>s which may be used to localize
0N/A * warning messages, or <code>null</code> if localization is not
0N/A * supported.
0N/A */
0N/A protected Locale[] availableLocales = null;
0N/A
0N/A /**
0N/A * The current <code>Locale</code> to be used for localization, or
0N/A * <code>null</code> if none has been set.
0N/A */
0N/A protected Locale locale = null;
0N/A
0N/A /**
0N/A * A <code>List</code> of currently registered
0N/A * <code>IIOReadWarningListener</code>s, initialized by default to
0N/A * <code>null</code>, which is synonymous with an empty
0N/A * <code>List</code>.
0N/A */
0N/A protected List<IIOReadWarningListener> warningListeners = null;
0N/A
0N/A /**
0N/A * A <code>List</code> of the <code>Locale</code>s associated with
0N/A * each currently registered <code>IIOReadWarningListener</code>,
0N/A * initialized by default to <code>null</code>, which is
0N/A * synonymous with an empty <code>List</code>.
0N/A */
0N/A protected List<Locale> warningLocales = null;
0N/A
0N/A /**
0N/A * A <code>List</code> of currently registered
0N/A * <code>IIOReadProgressListener</code>s, initialized by default
0N/A * to <code>null</code>, which is synonymous with an empty
0N/A * <code>List</code>.
0N/A */
0N/A protected List<IIOReadProgressListener> progressListeners = null;
0N/A
0N/A /**
0N/A * A <code>List</code> of currently registered
0N/A * <code>IIOReadUpdateListener</code>s, initialized by default to
0N/A * <code>null</code>, which is synonymous with an empty
0N/A * <code>List</code>.
0N/A */
0N/A protected List<IIOReadUpdateListener> updateListeners = null;
0N/A
0N/A /**
0N/A * If <code>true</code>, the current read operation should be
0N/A * aborted.
0N/A */
0N/A private boolean abortFlag = false;
0N/A
0N/A /**
0N/A * Constructs an <code>ImageReader</code> and sets its
0N/A * <code>originatingProvider</code> field to the supplied value.
0N/A *
0N/A * <p> Subclasses that make use of extensions should provide a
0N/A * constructor with signature <code>(ImageReaderSpi,
0N/A * Object)</code> in order to retrieve the extension object. If
0N/A * the extension object is unsuitable, an
0N/A * <code>IllegalArgumentException</code> should be thrown.
0N/A *
0N/A * @param originatingProvider the <code>ImageReaderSpi</code> that is
0N/A * invoking this constructor, or <code>null</code>.
0N/A */
0N/A protected ImageReader(ImageReaderSpi originatingProvider) {
0N/A this.originatingProvider = originatingProvider;
0N/A }
0N/A
0N/A /**
0N/A * Returns a <code>String</code> identifying the format of the
0N/A * input source.
0N/A *
0N/A * <p> The default implementation returns
0N/A * <code>originatingProvider.getFormatNames()[0]</code>.
0N/A * Implementations that may not have an originating service
0N/A * provider, or which desire a different naming policy should
0N/A * override this method.
0N/A *
0N/A * @exception IOException if an error occurs reading the
0N/A * information from the input source.
0N/A *
0N/A * @return the format name, as a <code>String</code>.
0N/A */
0N/A public String getFormatName() throws IOException {
0N/A return originatingProvider.getFormatNames()[0];
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>ImageReaderSpi</code> that was passed in on
0N/A * the constructor. Note that this value may be <code>null</code>.
0N/A *
0N/A * @return an <code>ImageReaderSpi</code>, or <code>null</code>.
0N/A *
0N/A * @see ImageReaderSpi
0N/A */
0N/A public ImageReaderSpi getOriginatingProvider() {
0N/A return originatingProvider;
0N/A }
0N/A
0N/A /**
0N/A * Sets the input source to use to the given
0N/A * <code>ImageInputStream</code> or other <code>Object</code>.
0N/A * The input source must be set before any of the query or read
0N/A * methods are used. If <code>input</code> is <code>null</code>,
0N/A * any currently set input source will be removed. In any case,
0N/A * the value of <code>minIndex</code> will be initialized to 0.
0N/A *
0N/A * <p> The <code>seekForwardOnly</code> parameter controls whether
0N/A * the value returned by <code>getMinIndex</code> will be
0N/A * increased as each image (or thumbnail, or image metadata) is
0N/A * read. If <code>seekForwardOnly</code> is true, then a call to
0N/A * <code>read(index)</code> will throw an
0N/A * <code>IndexOutOfBoundsException</code> if <code>index &lt
0N/A * this.minIndex</code>; otherwise, the value of
0N/A * <code>minIndex</code> will be set to <code>index</code>. If
0N/A * <code>seekForwardOnly</code> is <code>false</code>, the value of
0N/A * <code>minIndex</code> will remain 0 regardless of any read
0N/A * operations.
0N/A *
0N/A * <p> The <code>ignoreMetadata</code> parameter, if set to
0N/A * <code>true</code>, allows the reader to disregard any metadata
0N/A * encountered during the read. Subsequent calls to the
0N/A * <code>getStreamMetadata</code> and
0N/A * <code>getImageMetadata</code> methods may return
0N/A * <code>null</code>, and an <code>IIOImage</code> returned from
0N/A * <code>readAll</code> may return <code>null</code> from their
0N/A * <code>getMetadata</code> method. Setting this parameter may
0N/A * allow the reader to work more efficiently. The reader may
0N/A * choose to disregard this setting and return metadata normally.
0N/A *
0N/A * <p> Subclasses should take care to remove any cached
0N/A * information based on the previous stream, such as header
0N/A * information or partially decoded image data.
0N/A *
0N/A * <p> Use of a general <code>Object</code> other than an
0N/A * <code>ImageInputStream</code> is intended for readers that
0N/A * interact directly with a capture device or imaging protocol.
0N/A * The set of legal classes is advertised by the reader's service
0N/A * provider's <code>getInputTypes</code> method; most readers
0N/A * will return a single-element array containing only
0N/A * <code>ImageInputStream.class</code> to indicate that they
0N/A * accept only an <code>ImageInputStream</code>.
0N/A *
0N/A * <p> The default implementation checks the <code>input</code>
0N/A * argument against the list returned by
0N/A * <code>originatingProvider.getInputTypes()</code> and fails
0N/A * if the argument is not an instance of one of the classes
0N/A * in the list. If the originating provider is set to
0N/A * <code>null</code>, the input is accepted only if it is an
0N/A * <code>ImageInputStream</code>.
0N/A *
0N/A * @param input the <code>ImageInputStream</code> or other
0N/A * <code>Object</code> to use for future decoding.
0N/A * @param seekForwardOnly if <code>true</code>, images and metadata
0N/A * may only be read in ascending order from this input source.
0N/A * @param ignoreMetadata if <code>true</code>, metadata
0N/A * may be ignored during reads.
0N/A *
0N/A * @exception IllegalArgumentException if <code>input</code> is
0N/A * not an instance of one of the classes returned by the
0N/A * originating service provider's <code>getInputTypes</code>
0N/A * method, or is not an <code>ImageInputStream</code>.
0N/A *
0N/A * @see ImageInputStream
0N/A * @see #getInput
0N/A * @see javax.imageio.spi.ImageReaderSpi#getInputTypes
0N/A */
0N/A public void setInput(Object input,
0N/A boolean seekForwardOnly,
0N/A boolean ignoreMetadata) {
0N/A if (input != null) {
0N/A boolean found = false;
0N/A if (originatingProvider != null) {
0N/A Class[] classes = originatingProvider.getInputTypes();
0N/A for (int i = 0; i < classes.length; i++) {
0N/A if (classes[i].isInstance(input)) {
0N/A found = true;
0N/A break;
0N/A }
0N/A }
0N/A } else {
0N/A if (input instanceof ImageInputStream) {
0N/A found = true;
0N/A }
0N/A }
0N/A if (!found) {
0N/A throw new IllegalArgumentException("Incorrect input type!");
0N/A }
0N/A
0N/A this.seekForwardOnly = seekForwardOnly;
0N/A this.ignoreMetadata = ignoreMetadata;
0N/A this.minIndex = 0;
0N/A }
0N/A
0N/A this.input = input;
0N/A }
0N/A
0N/A /**
0N/A * Sets the input source to use to the given
0N/A * <code>ImageInputStream</code> or other <code>Object</code>.
0N/A * The input source must be set before any of the query or read
0N/A * methods are used. If <code>input</code> is <code>null</code>,
0N/A * any currently set input source will be removed. In any case,
0N/A * the value of <code>minIndex</code> will be initialized to 0.
0N/A *
0N/A * <p> The <code>seekForwardOnly</code> parameter controls whether
0N/A * the value returned by <code>getMinIndex</code> will be
0N/A * increased as each image (or thumbnail, or image metadata) is
0N/A * read. If <code>seekForwardOnly</code> is true, then a call to
0N/A * <code>read(index)</code> will throw an
0N/A * <code>IndexOutOfBoundsException</code> if <code>index &lt
0N/A * this.minIndex</code>; otherwise, the value of
0N/A * <code>minIndex</code> will be set to <code>index</code>. If
0N/A * <code>seekForwardOnly</code> is <code>false</code>, the value of
0N/A * <code>minIndex</code> will remain 0 regardless of any read
0N/A * operations.
0N/A *
0N/A * <p> This method is equivalent to <code>setInput(input,
0N/A * seekForwardOnly, false)</code>.
0N/A *
0N/A * @param input the <code>ImageInputStream</code> or other
0N/A * <code>Object</code> to use for future decoding.
0N/A * @param seekForwardOnly if <code>true</code>, images and metadata
0N/A * may only be read in ascending order from this input source.
0N/A *
0N/A * @exception IllegalArgumentException if <code>input</code> is
0N/A * not an instance of one of the classes returned by the
0N/A * originating service provider's <code>getInputTypes</code>
0N/A * method, or is not an <code>ImageInputStream</code>.
0N/A *
0N/A * @see #getInput
0N/A */
0N/A public void setInput(Object input,
0N/A boolean seekForwardOnly) {
0N/A setInput(input, seekForwardOnly, false);
0N/A }
0N/A
0N/A /**
0N/A * Sets the input source to use to the given
0N/A * <code>ImageInputStream</code> or other <code>Object</code>.
0N/A * The input source must be set before any of the query or read
0N/A * methods are used. If <code>input</code> is <code>null</code>,
0N/A * any currently set input source will be removed. In any case,
0N/A * the value of <code>minIndex</code> will be initialized to 0.
0N/A *
0N/A * <p> This method is equivalent to <code>setInput(input, false,
0N/A * false)</code>.
0N/A *
0N/A * @param input the <code>ImageInputStream</code> or other
0N/A * <code>Object</code> to use for future decoding.
0N/A *
0N/A * @exception IllegalArgumentException if <code>input</code> is
0N/A * not an instance of one of the classes returned by the
0N/A * originating service provider's <code>getInputTypes</code>
0N/A * method, or is not an <code>ImageInputStream</code>.
0N/A *
0N/A * @see #getInput
0N/A */
0N/A public void setInput(Object input) {
0N/A setInput(input, false, false);
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>ImageInputStream</code> or other
0N/A * <code>Object</code> previously set as the input source. If the
0N/A * input source has not been set, <code>null</code> is returned.
0N/A *
0N/A * @return the <code>Object</code> that will be used for future
0N/A * decoding, or <code>null</code>.
0N/A *
0N/A * @see ImageInputStream
0N/A * @see #setInput
0N/A */
0N/A public Object getInput() {
0N/A return input;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the current input source has been
0N/A * marked as seek forward only by passing <code>true</code> as the
0N/A * <code>seekForwardOnly</code> argument to the
0N/A * <code>setInput</code> method.
0N/A *
0N/A * @return <code>true</code> if the input source is seek forward
0N/A * only.
0N/A *
0N/A * @see #setInput
0N/A */
0N/A public boolean isSeekForwardOnly() {
0N/A return seekForwardOnly;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the current input source has been
0N/A * marked as allowing metadata to be ignored by passing
0N/A * <code>true</code> as the <code>ignoreMetadata</code> argument
0N/A * to the <code>setInput</code> method.
0N/A *
0N/A * @return <code>true</code> if the metadata may be ignored.
0N/A *
0N/A * @see #setInput
0N/A */
0N/A public boolean isIgnoringMetadata() {
0N/A return ignoreMetadata;
0N/A }
0N/A
0N/A /**
0N/A * Returns the lowest valid index for reading an image, thumbnail,
0N/A * or image metadata. If <code>seekForwardOnly()</code> is
0N/A * <code>false</code>, this value will typically remain 0,
0N/A * indicating that random access is possible. Otherwise, it will
0N/A * contain the value of the most recently accessed index, and
0N/A * increase in a monotonic fashion.
0N/A *
0N/A * @return the minimum legal index for reading.
0N/A */
0N/A public int getMinIndex() {
0N/A return minIndex;
0N/A }
0N/A
0N/A // Localization
0N/A
0N/A /**
0N/A * Returns an array of <code>Locale</code>s that may be used to
0N/A * localize warning listeners and compression settings. A return
0N/A * value of <code>null</code> indicates that localization is not
0N/A * supported.
0N/A *
0N/A * <p> The default implementation returns a clone of the
0N/A * <code>availableLocales</code> instance variable if it is
0N/A * non-<code>null</code>, or else returns <code>null</code>.
0N/A *
0N/A * @return an array of <code>Locale</code>s that may be used as
0N/A * arguments to <code>setLocale</code>, or <code>null</code>.
0N/A */
0N/A public Locale[] getAvailableLocales() {
0N/A if (availableLocales == null) {
0N/A return null;
0N/A } else {
0N/A return (Locale[])availableLocales.clone();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the current <code>Locale</code> of this
0N/A * <code>ImageReader</code> to the given value. A value of
0N/A * <code>null</code> removes any previous setting, and indicates
0N/A * that the reader should localize as it sees fit.
0N/A *
0N/A * @param locale the desired <code>Locale</code>, or
0N/A * <code>null</code>.
0N/A *
0N/A * @exception IllegalArgumentException if <code>locale</code> is
0N/A * non-<code>null</code> but is not one of the values returned by
0N/A * <code>getAvailableLocales</code>.
0N/A *
0N/A * @see #getLocale
0N/A */
0N/A public void setLocale(Locale locale) {
0N/A if (locale != null) {
0N/A Locale[] locales = getAvailableLocales();
0N/A boolean found = false;
0N/A if (locales != null) {
0N/A for (int i = 0; i < locales.length; i++) {
0N/A if (locale.equals(locales[i])) {
0N/A found = true;
0N/A break;
0N/A }
0N/A }
0N/A }
0N/A if (!found) {
0N/A throw new IllegalArgumentException("Invalid locale!");
0N/A }
0N/A }
0N/A this.locale = locale;
0N/A }
0N/A
0N/A /**
0N/A * Returns the currently set <code>Locale</code>, or
0N/A * <code>null</code> if none has been set.
0N/A *
0N/A * @return the current <code>Locale</code>, or <code>null</code>.
0N/A *
0N/A * @see #setLocale
0N/A */
0N/A public Locale getLocale() {
0N/A return locale;
0N/A }
0N/A
0N/A // Image queries
0N/A
0N/A /**
0N/A * Returns the number of images, not including thumbnails, available
0N/A * from the current input source.
0N/A *
0N/A * <p> Note that some image formats (such as animated GIF) do not
0N/A * specify how many images are present in the stream. Thus
0N/A * determining the number of images will require the entire stream
0N/A * to be scanned and may require memory for buffering. If images
0N/A * are to be processed in order, it may be more efficient to
0N/A * simply call <code>read</code> with increasing indices until an
0N/A * <code>IndexOutOfBoundsException</code> is thrown to indicate
0N/A * that no more images are available. The
0N/A * <code>allowSearch</code> parameter may be set to
0N/A * <code>false</code> to indicate that an exhaustive search is not
0N/A * desired; the return value will be <code>-1</code> to indicate
0N/A * that a search is necessary. If the input has been specified
0N/A * with <code>seekForwardOnly</code> set to <code>true</code>,
0N/A * this method throws an <code>IllegalStateException</code> if
0N/A * <code>allowSearch</code> is set to <code>true</code>.
0N/A *
0N/A * @param allowSearch if <code>true</code>, the true number of
0N/A * images will be returned even if a search is required. If
0N/A * <code>false</code>, the reader may return <code>-1</code>
0N/A * without performing the search.
0N/A *
0N/A * @return the number of images, as an <code>int</code>, or
0N/A * <code>-1</code> if <code>allowSearch</code> is
0N/A * <code>false</code> and a search would be required.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been set,
0N/A * or if the input has been specified with <code>seekForwardOnly</code>
0N/A * set to <code>true</code>.
0N/A * @exception IOException if an error occurs reading the
0N/A * information from the input source.
0N/A *
0N/A * @see #setInput
0N/A */
0N/A public abstract int getNumImages(boolean allowSearch) throws IOException;
0N/A
0N/A /**
0N/A * Returns the width in pixels of the given image within the input
0N/A * source.
0N/A *
0N/A * <p> If the image can be rendered to a user-specified size, then
0N/A * this method returns the default width.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @return the width of the image, as an <code>int</code>.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs reading the width
0N/A * information from the input source.
0N/A */
0N/A public abstract int getWidth(int imageIndex) throws IOException;
0N/A
0N/A /**
0N/A * Returns the height in pixels of the given image within the
0N/A * input source.
0N/A *
0N/A * <p> If the image can be rendered to a user-specified size, then
0N/A * this method returns the default height.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @return the height of the image, as an <code>int</code>.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs reading the height
0N/A * information from the input source.
0N/A */
0N/A public abstract int getHeight(int imageIndex) throws IOException;
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the storage format of the given
0N/A * image places no inherent impediment on random access to pixels.
0N/A * For most compressed formats, such as JPEG, this method should
0N/A * return <code>false</code>, as a large section of the image in
0N/A * addition to the region of interest may need to be decoded.
0N/A *
0N/A * <p> This is merely a hint for programs that wish to be
0N/A * efficient; all readers must be able to read arbitrary regions
0N/A * as specified in an <code>ImageReadParam</code>.
0N/A *
0N/A * <p> Note that formats that return <code>false</code> from
0N/A * this method may nonetheless allow tiling (<i>e.g.</i> Restart
0N/A * Markers in JPEG), and random access will likely be reasonably
0N/A * efficient on tiles. See {@link #isImageTiled
0N/A * <code>isImageTiled</code>}.
0N/A *
0N/A * <p> A reader for which all images are guaranteed to support
0N/A * easy random access, or are guaranteed not to support easy
0N/A * random access, may return <code>true</code> or
0N/A * <code>false</code> respectively without accessing any image
0N/A * data. In such cases, it is not necessary to throw an exception
0N/A * even if no input source has been set or the image index is out
0N/A * of bounds.
0N/A *
0N/A * <p> The default implementation returns <code>false</code>.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @return <code>true</code> if reading a region of interest of
0N/A * the given image is likely to be efficient.
0N/A *
0N/A * @exception IllegalStateException if an input source is required
0N/A * to determine the return value, but none has been set.
0N/A * @exception IndexOutOfBoundsException if an image must be
0N/A * accessed to determine the return value, but the supplied index
0N/A * is out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public boolean isRandomAccessEasy(int imageIndex) throws IOException {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns the aspect ratio of the given image (that is, its width
0N/A * divided by its height) as a <code>float</code>. For images
0N/A * that are inherently resizable, this method provides a way to
0N/A * determine the appropriate width given a deired height, or vice
0N/A * versa. For non-resizable images, the true width and height
0N/A * are used.
0N/A *
0N/A * <p> The default implementation simply returns
0N/A * <code>(float)getWidth(imageIndex)/getHeight(imageIndex)</code>.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @return a <code>float</code> indicating the aspect ratio of the
0N/A * given image.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public float getAspectRatio(int imageIndex) throws IOException {
0N/A return (float)getWidth(imageIndex)/getHeight(imageIndex);
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>ImageTypeSpecifier</code> indicating the
0N/A * <code>SampleModel</code> and <code>ColorModel</code> which most
0N/A * closely represents the "raw" internal format of the image. For
0N/A * example, for a JPEG image the raw type might have a YCbCr color
0N/A * space even though the image would conventionally be transformed
0N/A * into an RGB color space prior to display. The returned value
0N/A * should also be included in the list of values returned by
0N/A * <code>getImageTypes</code>.
0N/A *
0N/A * <p> The default implementation simply returns the first entry
0N/A * from the list provided by <code>getImageType</code>.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @return an <code>ImageTypeSpecifier</code>.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs reading the format
0N/A * information from the input source.
0N/A */
0N/A public ImageTypeSpecifier getRawImageType(int imageIndex)
0N/A throws IOException {
0N/A return (ImageTypeSpecifier)getImageTypes(imageIndex).next();
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Iterator</code> containing possible image
0N/A * types to which the given image may be decoded, in the form of
0N/A * <code>ImageTypeSpecifiers</code>s. At least one legal image
0N/A * type will be returned.
0N/A *
0N/A * <p> The first element of the iterator should be the most
0N/A * "natural" type for decoding the image with as little loss as
0N/A * possible. For example, for a JPEG image the first entry should
0N/A * be an RGB image, even though the image data is stored
0N/A * internally in a YCbCr color space.
0N/A *
0N/A * @param imageIndex the index of the image to be
0N/A * <code>retrieved</code>.
0N/A *
0N/A * @return an <code>Iterator</code> containing at least one
0N/A * <code>ImageTypeSpecifier</code> representing suggested image
0N/A * types for decoding the current given image.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs reading the format
0N/A * information from the input source.
0N/A *
0N/A * @see ImageReadParam#setDestination(BufferedImage)
0N/A * @see ImageReadParam#setDestinationType(ImageTypeSpecifier)
0N/A */
0N/A public abstract Iterator<ImageTypeSpecifier>
0N/A getImageTypes(int imageIndex) throws IOException;
0N/A
0N/A /**
0N/A * Returns a default <code>ImageReadParam</code> object
0N/A * appropriate for this format. All subclasses should define a
0N/A * set of default values for all parameters and return them with
0N/A * this call. This method may be called before the input source
0N/A * is set.
0N/A *
0N/A * <p> The default implementation constructs and returns a new
0N/A * <code>ImageReadParam</code> object that does not allow source
0N/A * scaling (<i>i.e.</i>, it returns <code>new
0N/A * ImageReadParam()</code>.
0N/A *
0N/A * @return an <code>ImageReadParam</code> object which may be used
0N/A * to control the decoding process using a set of default settings.
0N/A */
0N/A public ImageReadParam getDefaultReadParam() {
0N/A return new ImageReadParam();
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>IIOMetadata</code> object representing the
0N/A * metadata associated with the input source as a whole (i.e., not
0N/A * associated with any particular image), or <code>null</code> if
0N/A * the reader does not support reading metadata, is set to ignore
0N/A * metadata, or if no metadata is available.
0N/A *
0N/A * @return an <code>IIOMetadata</code> object, or <code>null</code>.
0N/A *
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public abstract IIOMetadata getStreamMetadata() throws IOException;
0N/A
0N/A /**
0N/A * Returns an <code>IIOMetadata</code> object representing the
0N/A * metadata associated with the input source as a whole (i.e.,
0N/A * not associated with any particular image). If no such data
0N/A * exists, <code>null</code> is returned.
0N/A *
0N/A * <p> The resuting metadata object is only responsible for
0N/A * returning documents in the format named by
0N/A * <code>formatName</code>. Within any documents that are
0N/A * returned, only nodes whose names are members of
0N/A * <code>nodeNames</code> are required to be returned. In this
0N/A * way, the amount of metadata processing done by the reader may
0N/A * be kept to a minimum, based on what information is actually
0N/A * needed.
0N/A *
0N/A * <p> If <code>formatName</code> is not the name of a supported
0N/A * metadata format, <code>null</code> is returned.
0N/A *
0N/A * <p> In all cases, it is legal to return a more capable metadata
0N/A * object than strictly necessary. The format name and node names
0N/A * are merely hints that may be used to reduce the reader's
0N/A * workload.
0N/A *
0N/A * <p> The default implementation simply returns the result of
0N/A * calling <code>getStreamMetadata()</code>, after checking that
0N/A * the format name is supported. If it is not,
0N/A * <code>null</code> is returned.
0N/A *
0N/A * @param formatName a metadata format name that may be used to retrieve
0N/A * a document from the returned <code>IIOMetadata</code> object.
0N/A * @param nodeNames a <code>Set</code> containing the names of
0N/A * nodes that may be contained in a retrieved document.
0N/A *
0N/A * @return an <code>IIOMetadata</code> object, or <code>null</code>.
0N/A *
0N/A * @exception IllegalArgumentException if <code>formatName</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>nodeNames</code>
0N/A * is <code>null</code>.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public IIOMetadata getStreamMetadata(String formatName,
0N/A Set<String> nodeNames)
0N/A throws IOException
0N/A {
0N/A return getMetadata(formatName, nodeNames, true, 0);
0N/A }
0N/A
0N/A private IIOMetadata getMetadata(String formatName,
0N/A Set nodeNames,
0N/A boolean wantStream,
0N/A int imageIndex) throws IOException {
0N/A if (formatName == null) {
0N/A throw new IllegalArgumentException("formatName == null!");
0N/A }
0N/A if (nodeNames == null) {
0N/A throw new IllegalArgumentException("nodeNames == null!");
0N/A }
0N/A IIOMetadata metadata =
0N/A wantStream
0N/A ? getStreamMetadata()
0N/A : getImageMetadata(imageIndex);
0N/A if (metadata != null) {
0N/A if (metadata.isStandardMetadataFormatSupported() &&
0N/A formatName.equals
0N/A (IIOMetadataFormatImpl.standardMetadataFormatName)) {
0N/A return metadata;
0N/A }
0N/A String nativeName = metadata.getNativeMetadataFormatName();
0N/A if (nativeName != null && formatName.equals(nativeName)) {
0N/A return metadata;
0N/A }
0N/A String[] extraNames = metadata.getExtraMetadataFormatNames();
0N/A if (extraNames != null) {
0N/A for (int i = 0; i < extraNames.length; i++) {
0N/A if (formatName.equals(extraNames[i])) {
0N/A return metadata;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>IIOMetadata</code> object containing metadata
0N/A * associated with the given image, or <code>null</code> if the
0N/A * reader does not support reading metadata, is set to ignore
0N/A * metadata, or if no metadata is available.
0N/A *
0N/A * @param imageIndex the index of the image whose metadata is to
0N/A * be retrieved.
0N/A *
0N/A * @return an <code>IIOMetadata</code> object, or
0N/A * <code>null</code>.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public abstract IIOMetadata getImageMetadata(int imageIndex)
0N/A throws IOException;
0N/A
0N/A /**
0N/A * Returns an <code>IIOMetadata</code> object representing the
0N/A * metadata associated with the given image, or <code>null</code>
0N/A * if the reader does not support reading metadata or none
0N/A * is available.
0N/A *
0N/A * <p> The resuting metadata object is only responsible for
0N/A * returning documents in the format named by
0N/A * <code>formatName</code>. Within any documents that are
0N/A * returned, only nodes whose names are members of
0N/A * <code>nodeNames</code> are required to be returned. In this
0N/A * way, the amount of metadata processing done by the reader may
0N/A * be kept to a minimum, based on what information is actually
0N/A * needed.
0N/A *
0N/A * <p> If <code>formatName</code> is not the name of a supported
0N/A * metadata format, <code>null</code> may be returned.
0N/A *
0N/A * <p> In all cases, it is legal to return a more capable metadata
0N/A * object than strictly necessary. The format name and node names
0N/A * are merely hints that may be used to reduce the reader's
0N/A * workload.
0N/A *
0N/A * <p> The default implementation simply returns the result of
0N/A * calling <code>getImageMetadata(imageIndex)</code>, after
0N/A * checking that the format name is supported. If it is not,
0N/A * <code>null</code> is returned.
0N/A *
0N/A * @param imageIndex the index of the image whose metadata is to
0N/A * be retrieved.
0N/A * @param formatName a metadata format name that may be used to retrieve
0N/A * a document from the returned <code>IIOMetadata</code> object.
0N/A * @param nodeNames a <code>Set</code> containing the names of
0N/A * nodes that may be contained in a retrieved document.
0N/A *
0N/A * @return an <code>IIOMetadata</code> object, or <code>null</code>.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IllegalArgumentException if <code>formatName</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>nodeNames</code>
0N/A * is <code>null</code>.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public IIOMetadata getImageMetadata(int imageIndex,
0N/A String formatName,
0N/A Set<String> nodeNames)
0N/A throws IOException {
0N/A return getMetadata(formatName, nodeNames, false, imageIndex);
0N/A }
0N/A
0N/A /**
0N/A * Reads the image indexed by <code>imageIndex</code> and returns
0N/A * it as a complete <code>BufferedImage</code>, using a default
0N/A * <code>ImageReadParam</code>. This is a convenience method
0N/A * that calls <code>read(imageIndex, null)</code>.
0N/A *
0N/A * <p> The image returned will be formatted according to the first
0N/A * <code>ImageTypeSpecifier</code> returned from
0N/A * <code>getImageTypes</code>.
0N/A *
0N/A * <p> Any registered <code>IIOReadProgressListener</code> objects
0N/A * will be notified by calling their <code>imageStarted</code>
0N/A * method, followed by calls to their <code>imageProgress</code>
0N/A * method as the read progresses. Finally their
0N/A * <code>imageComplete</code> method will be called.
0N/A * <code>IIOReadUpdateListener</code> objects may be updated at
0N/A * other times during the read as pixels are decoded. Finally,
0N/A * <code>IIOReadWarningListener</code> objects will receive
0N/A * notification of any non-fatal warnings that occur during
0N/A * decoding.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A *
0N/A * @return the desired portion of the image as a
0N/A * <code>BufferedImage</code>.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public BufferedImage read(int imageIndex) throws IOException {
0N/A return read(imageIndex, null);
0N/A }
0N/A
0N/A /**
0N/A * Reads the image indexed by <code>imageIndex</code> and returns
0N/A * it as a complete <code>BufferedImage</code>, using a supplied
0N/A * <code>ImageReadParam</code>.
0N/A *
0N/A * <p> The actual <code>BufferedImage</code> returned will be
0N/A * chosen using the algorithm defined by the
0N/A * <code>getDestination</code> method.
0N/A *
0N/A * <p> Any registered <code>IIOReadProgressListener</code> objects
0N/A * will be notified by calling their <code>imageStarted</code>
0N/A * method, followed by calls to their <code>imageProgress</code>
0N/A * method as the read progresses. Finally their
0N/A * <code>imageComplete</code> method will be called.
0N/A * <code>IIOReadUpdateListener</code> objects may be updated at
0N/A * other times during the read as pixels are decoded. Finally,
0N/A * <code>IIOReadWarningListener</code> objects will receive
0N/A * notification of any non-fatal warnings that occur during
0N/A * decoding.
0N/A *
0N/A * <p> The set of source bands to be read and destination bands to
0N/A * be written is determined by calling <code>getSourceBands</code>
0N/A * and <code>getDestinationBands</code> on the supplied
0N/A * <code>ImageReadParam</code>. If the lengths of the arrays
0N/A * returned by these methods differ, the set of source bands
0N/A * contains an index larger that the largest available source
0N/A * index, or the set of destination bands contains an index larger
0N/A * than the largest legal destination index, an
0N/A * <code>IllegalArgumentException</code> is thrown.
0N/A *
0N/A * <p> If the supplied <code>ImageReadParam</code> contains
0N/A * optional setting values not supported by this reader (<i>e.g.</i>
0N/A * source render size or any format-specific settings), they will
0N/A * be ignored.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A * @param param an <code>ImageReadParam</code> used to control
0N/A * the reading process, or <code>null</code>.
0N/A *
0N/A * @return the desired portion of the image as a
0N/A * <code>BufferedImage</code>.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IllegalArgumentException if the set of source and
0N/A * destination bands specified by
0N/A * <code>param.getSourceBands</code> and
0N/A * <code>param.getDestinationBands</code> differ in length or
0N/A * include indices that are out of bounds.
0N/A * @exception IllegalArgumentException if the resulting image would
0N/A * have a width or height less than 1.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public abstract BufferedImage read(int imageIndex, ImageReadParam param)
0N/A throws IOException;
0N/A
0N/A /**
0N/A * Reads the image indexed by <code>imageIndex</code> and returns
0N/A * an <code>IIOImage</code> containing the image, thumbnails, and
0N/A * associated image metadata, using a supplied
0N/A * <code>ImageReadParam</code>.
0N/A *
0N/A * <p> The actual <code>BufferedImage</code> referenced by the
0N/A * returned <code>IIOImage</code> will be chosen using the
0N/A * algorithm defined by the <code>getDestination</code> method.
0N/A *
0N/A * <p> Any registered <code>IIOReadProgressListener</code> objects
0N/A * will be notified by calling their <code>imageStarted</code>
0N/A * method, followed by calls to their <code>imageProgress</code>
0N/A * method as the read progresses. Finally their
0N/A * <code>imageComplete</code> method will be called.
0N/A * <code>IIOReadUpdateListener</code> objects may be updated at
0N/A * other times during the read as pixels are decoded. Finally,
0N/A * <code>IIOReadWarningListener</code> objects will receive
0N/A * notification of any non-fatal warnings that occur during
0N/A * decoding.
0N/A *
0N/A * <p> The set of source bands to be read and destination bands to
0N/A * be written is determined by calling <code>getSourceBands</code>
0N/A * and <code>getDestinationBands</code> on the supplied
0N/A * <code>ImageReadParam</code>. If the lengths of the arrays
0N/A * returned by these methods differ, the set of source bands
0N/A * contains an index larger that the largest available source
0N/A * index, or the set of destination bands contains an index larger
0N/A * than the largest legal destination index, an
0N/A * <code>IllegalArgumentException</code> is thrown.
0N/A *
0N/A * <p> Thumbnails will be returned in their entirety regardless of
0N/A * the region settings.
0N/A *
0N/A * <p> If the supplied <code>ImageReadParam</code> contains
0N/A * optional setting values not supported by this reader (<i>e.g.</i>
0N/A * source render size or any format-specific settings), those
0N/A * values will be ignored.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A * @param param an <code>ImageReadParam</code> used to control
0N/A * the reading process, or <code>null</code>.
0N/A *
0N/A * @return an <code>IIOImage</code> containing the desired portion
0N/A * of the image, a set of thumbnails, and associated image
0N/A * metadata.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IllegalArgumentException if the set of source and
0N/A * destination bands specified by
0N/A * <code>param.getSourceBands</code> and
0N/A * <code>param.getDestinationBands</code> differ in length or
0N/A * include indices that are out of bounds.
0N/A * @exception IllegalArgumentException if the resulting image
0N/A * would have a width or height less than 1.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public IIOImage readAll(int imageIndex, ImageReadParam param)
0N/A throws IOException {
0N/A if (imageIndex < getMinIndex()) {
0N/A throw new IndexOutOfBoundsException("imageIndex < getMinIndex()!");
0N/A }
0N/A
0N/A BufferedImage im = read(imageIndex, param);
0N/A
0N/A ArrayList thumbnails = null;
0N/A int numThumbnails = getNumThumbnails(imageIndex);
0N/A if (numThumbnails > 0) {
0N/A thumbnails = new ArrayList();
0N/A for (int j = 0; j < numThumbnails; j++) {
0N/A thumbnails.add(readThumbnail(imageIndex, j));
0N/A }
0N/A }
0N/A
0N/A IIOMetadata metadata = getImageMetadata(imageIndex);
0N/A return new IIOImage(im, thumbnails, metadata);
0N/A }
0N/A
0N/A /**
0N/A * Returns an <code>Iterator</code> containing all the images,
0N/A * thumbnails, and metadata, starting at the index given by
0N/A * <code>getMinIndex</code>, from the input source in the form of
0N/A * <code>IIOImage</code> objects. An <code>Iterator</code>
0N/A * containing <code>ImageReadParam</code> objects is supplied; one
0N/A * element is consumed for each image read from the input source
0N/A * until no more images are available. If the read param
0N/A * <code>Iterator</code> runs out of elements, but there are still
0N/A * more images available from the input source, default read
0N/A * params are used for the remaining images.
0N/A *
0N/A * <p> If <code>params</code> is <code>null</code>, a default read
0N/A * param will be used for all images.
0N/A *
0N/A * <p> The actual <code>BufferedImage</code> referenced by the
0N/A * returned <code>IIOImage</code> will be chosen using the
0N/A * algorithm defined by the <code>getDestination</code> method.
0N/A *
0N/A * <p> Any registered <code>IIOReadProgressListener</code> objects
0N/A * will be notified by calling their <code>sequenceStarted</code>
0N/A * method once. Then, for each image decoded, there will be a
0N/A * call to <code>imageStarted</code>, followed by calls to
0N/A * <code>imageProgress</code> as the read progresses, and finally
0N/A * to <code>imageComplete</code>. The
0N/A * <code>sequenceComplete</code> method will be called after the
0N/A * last image has been decoded.
0N/A * <code>IIOReadUpdateListener</code> objects may be updated at
0N/A * other times during the read as pixels are decoded. Finally,
0N/A * <code>IIOReadWarningListener</code> objects will receive
0N/A * notification of any non-fatal warnings that occur during
0N/A * decoding.
0N/A *
0N/A * <p> The set of source bands to be read and destination bands to
0N/A * be written is determined by calling <code>getSourceBands</code>
0N/A * and <code>getDestinationBands</code> on the supplied
0N/A * <code>ImageReadParam</code>. If the lengths of the arrays
0N/A * returned by these methods differ, the set of source bands
0N/A * contains an index larger that the largest available source
0N/A * index, or the set of destination bands contains an index larger
0N/A * than the largest legal destination index, an
0N/A * <code>IllegalArgumentException</code> is thrown.
0N/A *
0N/A * <p> Thumbnails will be returned in their entirety regardless of the
0N/A * region settings.
0N/A *
0N/A * <p> If any of the supplied <code>ImageReadParam</code>s contain
0N/A * optional setting values not supported by this reader (<i>e.g.</i>
0N/A * source render size or any format-specific settings), they will
0N/A * be ignored.
0N/A *
0N/A * @param params an <code>Iterator</code> containing
0N/A * <code>ImageReadParam</code> objects.
0N/A *
0N/A * @return an <code>Iterator</code> representing the
0N/A * contents of the input source as <code>IIOImage</code>s.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IllegalArgumentException if any
0N/A * non-<code>null</code> element of <code>params</code> is not an
0N/A * <code>ImageReadParam</code>.
0N/A * @exception IllegalArgumentException if the set of source and
0N/A * destination bands specified by
0N/A * <code>param.getSourceBands</code> and
0N/A * <code>param.getDestinationBands</code> differ in length or
0N/A * include indices that are out of bounds.
0N/A * @exception IllegalArgumentException if a resulting image would
0N/A * have a width or height less than 1.
0N/A * @exception IOException if an error occurs during reading.
0N/A *
0N/A * @see ImageReadParam
0N/A * @see IIOImage
0N/A */
0N/A public Iterator<IIOImage>
0N/A readAll(Iterator<? extends ImageReadParam> params)
0N/A throws IOException
0N/A {
0N/A List output = new ArrayList();
0N/A
0N/A int imageIndex = getMinIndex();
0N/A
0N/A // Inform IIOReadProgressListeners we're starting a sequence
0N/A processSequenceStarted(imageIndex);
0N/A
0N/A while (true) {
0N/A // Inform IIOReadProgressListeners and IIOReadUpdateListeners
0N/A // that we're starting a new image
0N/A
0N/A ImageReadParam param = null;
0N/A if (params != null && params.hasNext()) {
0N/A Object o = params.next();
0N/A if (o != null) {
0N/A if (o instanceof ImageReadParam) {
0N/A param = (ImageReadParam)o;
0N/A } else {
0N/A throw new IllegalArgumentException
0N/A ("Non-ImageReadParam supplied as part of params!");
0N/A }
0N/A }
0N/A }
0N/A
0N/A BufferedImage bi = null;
0N/A try {
0N/A bi = read(imageIndex, param);
0N/A } catch (IndexOutOfBoundsException e) {
0N/A break;
0N/A }
0N/A
0N/A ArrayList thumbnails = null;
0N/A int numThumbnails = getNumThumbnails(imageIndex);
0N/A if (numThumbnails > 0) {
0N/A thumbnails = new ArrayList();
0N/A for (int j = 0; j < numThumbnails; j++) {
0N/A thumbnails.add(readThumbnail(imageIndex, j));
0N/A }
0N/A }
0N/A
0N/A IIOMetadata metadata = getImageMetadata(imageIndex);
0N/A IIOImage im = new IIOImage(bi, thumbnails, metadata);
0N/A output.add(im);
0N/A
0N/A ++imageIndex;
0N/A }
0N/A
0N/A // Inform IIOReadProgressListeners we're ending a sequence
0N/A processSequenceComplete();
0N/A
0N/A return output.iterator();
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if this plug-in supports reading
0N/A * just a {@link java.awt.image.Raster <code>Raster</code>} of pixel data.
0N/A * If this method returns <code>false</code>, calls to
0N/A * {@link #readRaster <code>readRaster</code>} or {@link #readTileRaster
0N/A * <code>readTileRaster</code>} will throw an
0N/A * <code>UnsupportedOperationException</code>.
0N/A *
0N/A * <p> The default implementation returns <code>false</code>.
0N/A *
0N/A * @return <code>true</code> if this plug-in supports reading raw
0N/A * <code>Raster</code>s.
0N/A *
0N/A * @see #readRaster
0N/A * @see #readTileRaster
0N/A */
0N/A public boolean canReadRaster() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns a new <code>Raster</code> object containing the raw pixel data
0N/A * from the image stream, without any color conversion applied. The
0N/A * application must determine how to interpret the pixel data by other
0N/A * means. Any destination or image-type parameters in the supplied
0N/A * <code>ImageReadParam</code> object are ignored, but all other
0N/A * parameters are used exactly as in the {@link #read <code>read</code>}
0N/A * method, except that any destination offset is used as a logical rather
0N/A * than a physical offset. The size of the returned <code>Raster</code>
0N/A * will always be that of the source region clipped to the actual image.
0N/A * Logical offsets in the stream itself are ignored.
0N/A *
0N/A * <p> This method allows formats that normally apply a color
0N/A * conversion, such as JPEG, and formats that do not normally have an
0N/A * associated colorspace, such as remote sensing or medical imaging data,
0N/A * to provide access to raw pixel data.
0N/A *
0N/A * <p> Any registered <code>readUpdateListener</code>s are ignored, as
0N/A * there is no <code>BufferedImage</code>, but all other listeners are
0N/A * called exactly as they are for the {@link #read <code>read</code>}
0N/A * method.
0N/A *
0N/A * <p> If {@link #canReadRaster <code>canReadRaster()</code>} returns
0N/A * <code>false</code>, this method throws an
0N/A * <code>UnsupportedOperationException</code>.
0N/A *
0N/A * <p> If the supplied <code>ImageReadParam</code> contains
0N/A * optional setting values not supported by this reader (<i>e.g.</i>
0N/A * source render size or any format-specific settings), they will
0N/A * be ignored.
0N/A *
0N/A * <p> The default implementation throws an
0N/A * <code>UnsupportedOperationException</code>.
0N/A *
0N/A * @param imageIndex the index of the image to be read.
0N/A * @param param an <code>ImageReadParam</code> used to control
0N/A * the reading process, or <code>null</code>.
0N/A *
0N/A * @return the desired portion of the image as a
0N/A * <code>Raster</code>.
0N/A *
0N/A * @exception UnsupportedOperationException if this plug-in does not
0N/A * support reading raw <code>Raster</code>s.
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A *
0N/A * @see #canReadRaster
0N/A * @see #read
0N/A * @see java.awt.image.Raster
0N/A */
0N/A public Raster readRaster(int imageIndex, ImageReadParam param)
0N/A throws IOException {
0N/A throw new UnsupportedOperationException("readRaster not supported!");
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the image is organized into
0N/A * <i>tiles</i>, that is, equal-sized non-overlapping rectangles.
0N/A *
0N/A * <p> A reader plug-in may choose whether or not to expose tiling
0N/A * that is present in the image as it is stored. It may even
0N/A * choose to advertise tiling when none is explicitly present. In
0N/A * general, tiling should only be advertised if there is some
0N/A * advantage (in speed or space) to accessing individual tiles.
0N/A * Regardless of whether the reader advertises tiling, it must be
0N/A * capable of reading an arbitrary rectangular region specified in
0N/A * an <code>ImageReadParam</code>.
0N/A *
0N/A * <p> A reader for which all images are guaranteed to be tiled,
0N/A * or are guaranteed not to be tiled, may return <code>true</code>
0N/A * or <code>false</code> respectively without accessing any image
0N/A * data. In such cases, it is not necessary to throw an exception
0N/A * even if no input source has been set or the image index is out
0N/A * of bounds.
0N/A *
0N/A * <p> The default implementation just returns <code>false</code>.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @return <code>true</code> if the image is tiled.
0N/A *
0N/A * @exception IllegalStateException if an input source is required
0N/A * to determine the return value, but none has been set.
0N/A * @exception IndexOutOfBoundsException if an image must be
0N/A * accessed to determine the return value, but the supplied index
0N/A * is out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public boolean isImageTiled(int imageIndex) throws IOException {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns the width of a tile in the given image.
0N/A *
0N/A * <p> The default implementation simply returns
0N/A * <code>getWidth(imageIndex)</code>, which is correct for
0N/A * non-tiled images. Readers that support tiling should override
0N/A * this method.
0N/A *
0N/A * @return the width of a tile.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public int getTileWidth(int imageIndex) throws IOException {
0N/A return getWidth(imageIndex);
0N/A }
0N/A
0N/A /**
0N/A * Returns the height of a tile in the given image.
0N/A *
0N/A * <p> The default implementation simply returns
0N/A * <code>getHeight(imageIndex)</code>, which is correct for
0N/A * non-tiled images. Readers that support tiling should override
0N/A * this method.
0N/A *
0N/A * @return the height of a tile.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public int getTileHeight(int imageIndex) throws IOException {
0N/A return getHeight(imageIndex);
0N/A }
0N/A
0N/A /**
0N/A * Returns the X coordinate of the upper-left corner of tile (0,
0N/A * 0) in the given image.
0N/A *
0N/A * <p> A reader for which the tile grid X offset always has the
0N/A * same value (usually 0), may return the value without accessing
0N/A * any image data. In such cases, it is not necessary to throw an
0N/A * exception even if no input source has been set or the image
0N/A * index is out of bounds.
0N/A *
0N/A * <p> The default implementation simply returns 0, which is
0N/A * correct for non-tiled images and tiled images in most formats.
0N/A * Readers that support tiling with non-(0, 0) offsets should
0N/A * override this method.
0N/A *
0N/A * @return the X offset of the tile grid.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @exception IllegalStateException if an input source is required
0N/A * to determine the return value, but none has been set.
0N/A * @exception IndexOutOfBoundsException if an image must be
0N/A * accessed to determine the return value, but the supplied index
0N/A * is out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public int getTileGridXOffset(int imageIndex) throws IOException {
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Returns the Y coordinate of the upper-left corner of tile (0,
0N/A * 0) in the given image.
0N/A *
0N/A * <p> A reader for which the tile grid Y offset always has the
0N/A * same value (usually 0), may return the value without accessing
0N/A * any image data. In such cases, it is not necessary to throw an
0N/A * exception even if no input source has been set or the image
0N/A * index is out of bounds.
0N/A *
0N/A * <p> The default implementation simply returns 0, which is
0N/A * correct for non-tiled images and tiled images in most formats.
0N/A * Readers that support tiling with non-(0, 0) offsets should
0N/A * override this method.
0N/A *
0N/A * @return the Y offset of the tile grid.
0N/A *
0N/A * @param imageIndex the index of the image to be queried.
0N/A *
0N/A * @exception IllegalStateException if an input source is required
0N/A * to determine the return value, but none has been set.
0N/A * @exception IndexOutOfBoundsException if an image must be
0N/A * accessed to determine the return value, but the supplied index
0N/A * is out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public int getTileGridYOffset(int imageIndex) throws IOException {
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Reads the tile indicated by the <code>tileX</code> and
0N/A * <code>tileY</code> arguments, returning it as a
0N/A * <code>BufferedImage</code>. If the arguments are out of range,
0N/A * an <code>IllegalArgumentException</code> is thrown. If the
0N/A * image is not tiled, the values 0, 0 will return the entire
0N/A * image; any other values will cause an
0N/A * <code>IllegalArgumentException</code> to be thrown.
0N/A *
0N/A * <p> This method is merely a convenience equivalent to calling
0N/A * <code>read(int, ImageReadParam)</code> with a read param
0N/A * specifiying a source region having offsets of
0N/A * <code>tileX*getTileWidth(imageIndex)</code>,
0N/A * <code>tileY*getTileHeight(imageIndex)</code> and width and
0N/A * height of <code>getTileWidth(imageIndex)</code>,
0N/A * <code>getTileHeight(imageIndex)</code>; and subsampling
0N/A * factors of 1 and offsets of 0. To subsample a tile, call
0N/A * <code>read</code> with a read param specifying this region
0N/A * and different subsampling parameters.
0N/A *
0N/A * <p> The default implementation returns the entire image if
0N/A * <code>tileX</code> and <code>tileY</code> are 0, or throws
0N/A * an <code>IllegalArgumentException</code> otherwise.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A * @param tileX the column index (starting with 0) of the tile
0N/A * to be retrieved.
0N/A * @param tileY the row index (starting with 0) of the tile
0N/A * to be retrieved.
0N/A *
0N/A * @return the tile as a <code>BufferedImage</code>.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if <code>imageIndex</code>
0N/A * is out of bounds.
0N/A * @exception IllegalArgumentException if the tile indices are
0N/A * out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public BufferedImage readTile(int imageIndex,
0N/A int tileX, int tileY) throws IOException {
0N/A if ((tileX != 0) || (tileY != 0)) {
0N/A throw new IllegalArgumentException("Invalid tile indices");
0N/A }
0N/A return read(imageIndex);
0N/A }
0N/A
0N/A /**
0N/A * Returns a new <code>Raster</code> object containing the raw
0N/A * pixel data from the tile, without any color conversion applied.
0N/A * The application must determine how to interpret the pixel data by other
0N/A * means.
0N/A *
0N/A * <p> If {@link #canReadRaster <code>canReadRaster()</code>} returns
0N/A * <code>false</code>, this method throws an
0N/A * <code>UnsupportedOperationException</code>.
0N/A *
0N/A * <p> The default implementation checks if reading
0N/A * <code>Raster</code>s is supported, and if so calls {@link
0N/A * #readRaster <code>readRaster(imageIndex, null)</code>} if
0N/A * <code>tileX</code> and <code>tileY</code> are 0, or throws an
0N/A * <code>IllegalArgumentException</code> otherwise.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A * @param tileX the column index (starting with 0) of the tile
0N/A * to be retrieved.
0N/A * @param tileY the row index (starting with 0) of the tile
0N/A * to be retrieved.
0N/A *
0N/A * @return the tile as a <code>Raster</code>.
0N/A *
0N/A * @exception UnsupportedOperationException if this plug-in does not
0N/A * support reading raw <code>Raster</code>s.
0N/A * @exception IllegalArgumentException if the tile indices are
0N/A * out of bounds.
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if <code>imageIndex</code>
0N/A * is out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A *
0N/A * @see #readTile
0N/A * @see #readRaster
0N/A * @see java.awt.image.Raster
0N/A */
0N/A public Raster readTileRaster(int imageIndex,
0N/A int tileX, int tileY) throws IOException {
0N/A if (!canReadRaster()) {
0N/A throw new UnsupportedOperationException
0N/A ("readTileRaster not supported!");
0N/A }
0N/A if ((tileX != 0) || (tileY != 0)) {
0N/A throw new IllegalArgumentException("Invalid tile indices");
0N/A }
0N/A return readRaster(imageIndex, null);
0N/A }
0N/A
0N/A // RenderedImages
0N/A
0N/A /**
0N/A * Returns a <code>RenderedImage</code> object that contains the
0N/A * contents of the image indexed by <code>imageIndex</code>. By
0N/A * default, the returned image is simply the
0N/A * <code>BufferedImage</code> returned by <code>read(imageIndex,
0N/A * param)</code>.
0N/A *
0N/A * <p> The semantics of this method may differ from those of the
0N/A * other <code>read</code> methods in several ways. First, any
0N/A * destination image and/or image type set in the
0N/A * <code>ImageReadParam</code> may be ignored. Second, the usual
0N/A * listener calls are not guaranteed to be made, or to be
0N/A * meaningful if they are. This is because the returned image may
0N/A * not be fully populated with pixel data at the time it is
0N/A * returned, or indeed at any time.
0N/A *
0N/A * <p> If the supplied <code>ImageReadParam</code> contains
0N/A * optional setting values not supported by this reader (<i>e.g.</i>
0N/A * source render size or any format-specific settings), they will
0N/A * be ignored.
0N/A *
0N/A * <p> The default implementation just calls {@link #read
0N/A * <code>read(imageIndex, param)</code>}.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A * @param param an <code>ImageReadParam</code> used to control
0N/A * the reading process, or <code>null</code>.
0N/A *
0N/A * @return a <code>RenderedImage</code> object providing a view of
0N/A * the image.
0N/A *
0N/A * @exception IllegalStateException if the input source has not been
0N/A * set.
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * out of bounds.
0N/A * @exception IllegalArgumentException if the set of source and
0N/A * destination bands specified by
0N/A * <code>param.getSourceBands</code> and
0N/A * <code>param.getDestinationBands</code> differ in length or
0N/A * include indices that are out of bounds.
0N/A * @exception IllegalArgumentException if the resulting image
0N/A * would have a width or height less than 1.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public RenderedImage readAsRenderedImage(int imageIndex,
0N/A ImageReadParam param)
0N/A throws IOException {
0N/A return read(imageIndex, param);
0N/A }
0N/A
0N/A // Thumbnails
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the image format understood by
0N/A * this reader supports thumbnail preview images associated with
0N/A * it. The default implementation returns <code>false</code>.
0N/A *
0N/A * <p> If this method returns <code>false</code>,
0N/A * <code>hasThumbnails</code> and <code>getNumThumbnails</code>
0N/A * will return <code>false</code> and <code>0</code>,
0N/A * respectively, and <code>readThumbnail</code> will throw an
0N/A * <code>UnsupportedOperationException</code>, regardless of their
0N/A * arguments.
0N/A *
0N/A * <p> A reader that does not support thumbnails need not
0N/A * implement any of the thumbnail-related methods.
0N/A *
0N/A * @return <code>true</code> if thumbnails are supported.
0N/A */
0N/A public boolean readerSupportsThumbnails() {
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the given image has thumbnail
0N/A * preview images associated with it. If the format does not
0N/A * support thumbnails (<code>readerSupportsThumbnails</code>
0N/A * returns <code>false</code>), <code>false</code> will be
0N/A * returned regardless of whether an input source has been set or
0N/A * whether <code>imageIndex</code> is in bounds.
0N/A *
0N/A * <p> The default implementation returns <code>true</code> if
0N/A * <code>getNumThumbnails</code> returns a value greater than 0.
0N/A *
0N/A * @param imageIndex the index of the image being queried.
0N/A *
0N/A * @return <code>true</code> if the given image has thumbnails.
0N/A *
0N/A * @exception IllegalStateException if the reader supports
0N/A * thumbnails but the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the reader supports
0N/A * thumbnails but <code>imageIndex</code> is out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public boolean hasThumbnails(int imageIndex) throws IOException {
0N/A return getNumThumbnails(imageIndex) > 0;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of thumbnail preview images associated with
0N/A * the given image. If the format does not support thumbnails,
0N/A * (<code>readerSupportsThumbnails</code> returns
0N/A * <code>false</code>), <code>0</code> will be returned regardless
0N/A * of whether an input source has been set or whether
0N/A * <code>imageIndex</code> is in bounds.
0N/A *
0N/A * <p> The default implementation returns 0 without checking its
0N/A * argument.
0N/A *
0N/A * @param imageIndex the index of the image being queried.
0N/A *
0N/A * @return the number of thumbnails associated with the given
0N/A * image.
0N/A *
0N/A * @exception IllegalStateException if the reader supports
0N/A * thumbnails but the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if the reader supports
0N/A * thumbnails but <code>imageIndex</code> is out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public int getNumThumbnails(int imageIndex)
0N/A throws IOException {
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Returns the width of the thumbnail preview image indexed by
0N/A * <code>thumbnailIndex</code>, associated with the image indexed
0N/A * by <code>ImageIndex</code>.
0N/A *
0N/A * <p> If the reader does not support thumbnails,
0N/A * (<code>readerSupportsThumbnails</code> returns
0N/A * <code>false</code>), an <code>UnsupportedOperationException</code>
0N/A * will be thrown.
0N/A *
0N/A * <p> The default implementation simply returns
0N/A * <code>readThumbnail(imageindex,
0N/A * thumbnailIndex).getWidth()</code>. Subclasses should therefore
0N/A * override this method if possible in order to avoid forcing the
0N/A * thumbnail to be read.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A * @param thumbnailIndex the index of the thumbnail to be retrieved.
0N/A *
0N/A * @return the width of the desired thumbnail as an <code>int</code>.
0N/A *
0N/A * @exception UnsupportedOperationException if thumbnails are not
0N/A * supported.
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if either of the supplied
0N/A * indices are out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public int getThumbnailWidth(int imageIndex, int thumbnailIndex)
0N/A throws IOException {
0N/A return readThumbnail(imageIndex, thumbnailIndex).getWidth();
0N/A }
0N/A
0N/A /**
0N/A * Returns the height of the thumbnail preview image indexed by
0N/A * <code>thumbnailIndex</code>, associated with the image indexed
0N/A * by <code>ImageIndex</code>.
0N/A *
0N/A * <p> If the reader does not support thumbnails,
0N/A * (<code>readerSupportsThumbnails</code> returns
0N/A * <code>false</code>), an <code>UnsupportedOperationException</code>
0N/A * will be thrown.
0N/A *
0N/A * <p> The default implementation simply returns
0N/A * <code>readThumbnail(imageindex,
0N/A * thumbnailIndex).getHeight()</code>. Subclasses should
0N/A * therefore override this method if possible in order to avoid
0N/A * forcing the thumbnail to be read.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A * @param thumbnailIndex the index of the thumbnail to be retrieved.
0N/A *
0N/A * @return the height of the desired thumbnail as an <code>int</code>.
0N/A *
0N/A * @exception UnsupportedOperationException if thumbnails are not
0N/A * supported.
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if either of the supplied
0N/A * indices are out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public int getThumbnailHeight(int imageIndex, int thumbnailIndex)
0N/A throws IOException {
0N/A return readThumbnail(imageIndex, thumbnailIndex).getHeight();
0N/A }
0N/A
0N/A /**
0N/A * Returns the thumbnail preview image indexed by
0N/A * <code>thumbnailIndex</code>, associated with the image indexed
0N/A * by <code>ImageIndex</code> as a <code>BufferedImage</code>.
0N/A *
0N/A * <p> Any registered <code>IIOReadProgressListener</code> objects
0N/A * will be notified by calling their
0N/A * <code>thumbnailStarted</code>, <code>thumbnailProgress</code>,
0N/A * and <code>thumbnailComplete</code> methods.
0N/A *
0N/A * <p> If the reader does not support thumbnails,
0N/A * (<code>readerSupportsThumbnails</code> returns
0N/A * <code>false</code>), an <code>UnsupportedOperationException</code>
0N/A * will be thrown regardless of whether an input source has been
0N/A * set or whether the indices are in bounds.
0N/A *
0N/A * <p> The default implementation throws an
0N/A * <code>UnsupportedOperationException</code>.
0N/A *
0N/A * @param imageIndex the index of the image to be retrieved.
0N/A * @param thumbnailIndex the index of the thumbnail to be retrieved.
0N/A *
0N/A * @return the desired thumbnail as a <code>BufferedImage</code>.
0N/A *
0N/A * @exception UnsupportedOperationException if thumbnails are not
0N/A * supported.
0N/A * @exception IllegalStateException if the input source has not been set.
0N/A * @exception IndexOutOfBoundsException if either of the supplied
0N/A * indices are out of bounds.
0N/A * @exception IOException if an error occurs during reading.
0N/A */
0N/A public BufferedImage readThumbnail(int imageIndex,
0N/A int thumbnailIndex)
0N/A throws IOException {
0N/A throw new UnsupportedOperationException("Thumbnails not supported!");
0N/A }
0N/A
0N/A // Abort
0N/A
0N/A /**
0N/A * Requests that any current read operation be aborted. The
0N/A * contents of the image following the abort will be undefined.
0N/A *
0N/A * <p> Readers should call <code>clearAbortRequest</code> at the
0N/A * beginning of each read operation, and poll the value of
0N/A * <code>abortRequested</code> regularly during the read.
0N/A */
0N/A public synchronized void abort() {
0N/A this.abortFlag = true;
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if a request to abort the current
0N/A * read operation has been made since the reader was instantiated or
0N/A * <code>clearAbortRequest</code> was called.
0N/A *
0N/A * @return <code>true</code> if the current read operation should
0N/A * be aborted.
0N/A *
0N/A * @see #abort
0N/A * @see #clearAbortRequest
0N/A */
0N/A protected synchronized boolean abortRequested() {
0N/A return this.abortFlag;
0N/A }
0N/A
0N/A /**
0N/A * Clears any previous abort request. After this method has been
0N/A * called, <code>abortRequested</code> will return
0N/A * <code>false</code>.
0N/A *
0N/A * @see #abort
0N/A * @see #abortRequested
0N/A */
0N/A protected synchronized void clearAbortRequest() {
0N/A this.abortFlag = false;
0N/A }
0N/A
0N/A // Listeners
0N/A
0N/A // Add an element to a list, creating a new list if the
0N/A // existing list is null, and return the list.
0N/A static List addToList(List l, Object elt) {
0N/A if (l == null) {
0N/A l = new ArrayList();
0N/A }
0N/A l.add(elt);
0N/A return l;
0N/A }
0N/A
0N/A
0N/A // Remove an element from a list, discarding the list if the
0N/A // resulting list is empty, and return the list or null.
0N/A static List removeFromList(List l, Object elt) {
0N/A if (l == null) {
0N/A return l;
0N/A }
0N/A l.remove(elt);
0N/A if (l.size() == 0) {
0N/A l = null;
0N/A }
0N/A return l;
0N/A }
0N/A
0N/A /**
0N/A * Adds an <code>IIOReadWarningListener</code> to the list of
0N/A * registered warning listeners. If <code>listener</code> is
0N/A * <code>null</code>, no exception will be thrown and no action
0N/A * will be taken. Messages sent to the given listener will be
0N/A * localized, if possible, to match the current
0N/A * <code>Locale</code>. If no <code>Locale</code> has been set,
0N/A * warning messages may be localized as the reader sees fit.
0N/A *
0N/A * @param listener an <code>IIOReadWarningListener</code> to be registered.
0N/A *
0N/A * @see #removeIIOReadWarningListener
0N/A */
0N/A public void addIIOReadWarningListener(IIOReadWarningListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A warningListeners = addToList(warningListeners, listener);
0N/A warningLocales = addToList(warningLocales, getLocale());
0N/A }
0N/A
0N/A /**
0N/A * Removes an <code>IIOReadWarningListener</code> from the list of
0N/A * registered error listeners. If the listener was not previously
0N/A * registered, or if <code>listener</code> is <code>null</code>,
0N/A * no exception will be thrown and no action will be taken.
0N/A *
0N/A * @param listener an IIOReadWarningListener to be unregistered.
0N/A *
0N/A * @see #addIIOReadWarningListener
0N/A */
0N/A public void removeIIOReadWarningListener(IIOReadWarningListener listener) {
0N/A if (listener == null || warningListeners == null) {
0N/A return;
0N/A }
0N/A int index = warningListeners.indexOf(listener);
0N/A if (index != -1) {
0N/A warningListeners.remove(index);
0N/A warningLocales.remove(index);
0N/A if (warningListeners.size() == 0) {
0N/A warningListeners = null;
0N/A warningLocales = null;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes all currently registered
0N/A * <code>IIOReadWarningListener</code> objects.
0N/A *
0N/A * <p> The default implementation sets the
0N/A * <code>warningListeners</code> and <code>warningLocales</code>
0N/A * instance variables to <code>null</code>.
0N/A */
0N/A public void removeAllIIOReadWarningListeners() {
0N/A warningListeners = null;
0N/A warningLocales = null;
0N/A }
0N/A
0N/A /**
0N/A * Adds an <code>IIOReadProgressListener</code> to the list of
0N/A * registered progress listeners. If <code>listener</code> is
0N/A * <code>null</code>, no exception will be thrown and no action
0N/A * will be taken.
0N/A *
0N/A * @param listener an IIOReadProgressListener to be registered.
0N/A *
0N/A * @see #removeIIOReadProgressListener
0N/A */
0N/A public void addIIOReadProgressListener(IIOReadProgressListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A progressListeners = addToList(progressListeners, listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes an <code>IIOReadProgressListener</code> from the list
0N/A * of registered progress listeners. If the listener was not
0N/A * previously registered, or if <code>listener</code> is
0N/A * <code>null</code>, no exception will be thrown and no action
0N/A * will be taken.
0N/A *
0N/A * @param listener an IIOReadProgressListener to be unregistered.
0N/A *
0N/A * @see #addIIOReadProgressListener
0N/A */
0N/A public void
0N/A removeIIOReadProgressListener (IIOReadProgressListener listener) {
0N/A if (listener == null || progressListeners == null) {
0N/A return;
0N/A }
0N/A progressListeners = removeFromList(progressListeners, listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes all currently registered
0N/A * <code>IIOReadProgressListener</code> objects.
0N/A *
0N/A * <p> The default implementation sets the
0N/A * <code>progressListeners</code> instance variable to
0N/A * <code>null</code>.
0N/A */
0N/A public void removeAllIIOReadProgressListeners() {
0N/A progressListeners = null;
0N/A }
0N/A
0N/A /**
0N/A * Adds an <code>IIOReadUpdateListener</code> to the list of
0N/A * registered update listeners. If <code>listener</code> is
0N/A * <code>null</code>, no exception will be thrown and no action
0N/A * will be taken. The listener will receive notification of pixel
0N/A * updates as images and thumbnails are decoded, including the
0N/A * starts and ends of progressive passes.
0N/A *
0N/A * <p> If no update listeners are present, the reader may choose
0N/A * to perform fewer updates to the pixels of the destination
0N/A * images and/or thumbnails, which may result in more efficient
0N/A * decoding.
0N/A *
0N/A * <p> For example, in progressive JPEG decoding each pass
0N/A * contains updates to a set of coefficients, which would have to
0N/A * be transformed into pixel values and converted to an RGB color
0N/A * space for each pass if listeners are present. If no listeners
0N/A * are present, the coefficients may simply be accumulated and the
0N/A * final results transformed and color converted one time only.
0N/A *
0N/A * <p> The final results of decoding will be the same whether or
0N/A * not intermediate updates are performed. Thus if only the final
0N/A * image is desired it may be perferable not to register any
0N/A * <code>IIOReadUpdateListener</code>s. In general, progressive
0N/A * updating is most effective when fetching images over a network
0N/A * connection that is very slow compared to local CPU processing;
0N/A * over a fast connection, progressive updates may actually slow
0N/A * down the presentation of the image.
0N/A *
0N/A * @param listener an IIOReadUpdateListener to be registered.
0N/A *
0N/A * @see #removeIIOReadUpdateListener
0N/A */
0N/A public void
0N/A addIIOReadUpdateListener(IIOReadUpdateListener listener) {
0N/A if (listener == null) {
0N/A return;
0N/A }
0N/A updateListeners = addToList(updateListeners, listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes an <code>IIOReadUpdateListener</code> from the list of
0N/A * registered update listeners. If the listener was not
0N/A * previously registered, or if <code>listener</code> is
0N/A * <code>null</code>, no exception will be thrown and no action
0N/A * will be taken.
0N/A *
0N/A * @param listener an IIOReadUpdateListener to be unregistered.
0N/A *
0N/A * @see #addIIOReadUpdateListener
0N/A */
0N/A public void removeIIOReadUpdateListener(IIOReadUpdateListener listener) {
0N/A if (listener == null || updateListeners == null) {
0N/A return;
0N/A }
0N/A updateListeners = removeFromList(updateListeners, listener);
0N/A }
0N/A
0N/A /**
0N/A * Removes all currently registered
0N/A * <code>IIOReadUpdateListener</code> objects.
0N/A *
0N/A * <p> The default implementation sets the
0N/A * <code>updateListeners</code> instance variable to
0N/A * <code>null</code>.
0N/A */
0N/A public void removeAllIIOReadUpdateListeners() {
0N/A updateListeners = null;
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the start of an sequence of image reads to all
0N/A * registered <code>IIOReadProgressListener</code>s by calling
0N/A * their <code>sequenceStarted</code> method. Subclasses may use
0N/A * this method as a convenience.
0N/A *
0N/A * @param minIndex the lowest index being read.
0N/A */
0N/A protected void processSequenceStarted(int minIndex) {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.sequenceStarted(this, minIndex);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the completion of an sequence of image reads to all
0N/A * registered <code>IIOReadProgressListener</code>s by calling
0N/A * their <code>sequenceComplete</code> method. Subclasses may use
0N/A * this method as a convenience.
0N/A */
0N/A protected void processSequenceComplete() {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.sequenceComplete(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the start of an image read to all registered
0N/A * <code>IIOReadProgressListener</code>s by calling their
0N/A * <code>imageStarted</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param imageIndex the index of the image about to be read.
0N/A */
0N/A protected void processImageStarted(int imageIndex) {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.imageStarted(this, imageIndex);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the current percentage of image completion to all
0N/A * registered <code>IIOReadProgressListener</code>s by calling
0N/A * their <code>imageProgress</code> method. Subclasses may use
0N/A * this method as a convenience.
0N/A *
0N/A * @param percentageDone the current percentage of completion,
0N/A * as a <code>float</code>.
0N/A */
0N/A protected void processImageProgress(float percentageDone) {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.imageProgress(this, percentageDone);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the completion of an image read to all registered
0N/A * <code>IIOReadProgressListener</code>s by calling their
0N/A * <code>imageComplete</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A */
0N/A protected void processImageComplete() {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.imageComplete(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the start of a thumbnail read to all registered
0N/A * <code>IIOReadProgressListener</code>s by calling their
0N/A * <code>thumbnailStarted</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param imageIndex the index of the image associated with the
0N/A * thumbnail.
0N/A * @param thumbnailIndex the index of the thumbnail.
0N/A */
0N/A protected void processThumbnailStarted(int imageIndex,
0N/A int thumbnailIndex) {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the current percentage of thumbnail completion to
0N/A * all registered <code>IIOReadProgressListener</code>s by calling
0N/A * their <code>thumbnailProgress</code> method. Subclasses may
0N/A * use this method as a convenience.
0N/A *
0N/A * @param percentageDone the current percentage of completion,
0N/A * as a <code>float</code>.
0N/A */
0N/A protected void processThumbnailProgress(float percentageDone) {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.thumbnailProgress(this, percentageDone);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the completion of a thumbnail read to all registered
0N/A * <code>IIOReadProgressListener</code>s by calling their
0N/A * <code>thumbnailComplete</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A */
0N/A protected void processThumbnailComplete() {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.thumbnailComplete(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts that the read has been aborted to all registered
0N/A * <code>IIOReadProgressListener</code>s by calling their
0N/A * <code>readAborted</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A */
0N/A protected void processReadAborted() {
0N/A if (progressListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = progressListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadProgressListener listener =
0N/A (IIOReadProgressListener)progressListeners.get(i);
0N/A listener.readAborted(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the beginning of a progressive pass to all
0N/A * registered <code>IIOReadUpdateListener</code>s by calling their
0N/A * <code>passStarted</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param theImage the <code>BufferedImage</code> being updated.
0N/A * @param pass the index of the current pass, starting with 0.
0N/A * @param minPass the index of the first pass that will be decoded.
0N/A * @param maxPass the index of the last pass that will be decoded.
0N/A * @param minX the X coordinate of the upper-left pixel included
0N/A * in the pass.
0N/A * @param minY the X coordinate of the upper-left pixel included
0N/A * in the pass.
0N/A * @param periodX the horizontal separation between pixels.
0N/A * @param periodY the vertical separation between pixels.
0N/A * @param bands an array of <code>int</code>s indicating the
0N/A * set of affected bands of the destination.
0N/A */
0N/A protected void processPassStarted(BufferedImage theImage,
0N/A int pass,
0N/A int minPass, int maxPass,
0N/A int minX, int minY,
0N/A int periodX, int periodY,
0N/A int[] bands) {
0N/A if (updateListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = updateListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadUpdateListener listener =
0N/A (IIOReadUpdateListener)updateListeners.get(i);
0N/A listener.passStarted(this, theImage, pass,
0N/A minPass,
0N/A maxPass,
0N/A minX, minY,
0N/A periodX, periodY,
0N/A bands);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the update of a set of samples to all registered
0N/A * <code>IIOReadUpdateListener</code>s by calling their
0N/A * <code>imageUpdate</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param theImage the <code>BufferedImage</code> being updated.
0N/A * @param minX the X coordinate of the upper-left pixel included
0N/A * in the pass.
0N/A * @param minY the X coordinate of the upper-left pixel included
0N/A * in the pass.
0N/A * @param width the total width of the area being updated, including
0N/A * pixels being skipped if <code>periodX &gt; 1</code>.
0N/A * @param height the total height of the area being updated,
0N/A * including pixels being skipped if <code>periodY &gt; 1</code>.
0N/A * @param periodX the horizontal separation between pixels.
0N/A * @param periodY the vertical separation between pixels.
0N/A * @param bands an array of <code>int</code>s indicating the
0N/A * set of affected bands of the destination.
0N/A */
0N/A protected void processImageUpdate(BufferedImage theImage,
0N/A int minX, int minY,
0N/A int width, int height,
0N/A int periodX, int periodY,
0N/A int[] bands) {
0N/A if (updateListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = updateListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadUpdateListener listener =
0N/A (IIOReadUpdateListener)updateListeners.get(i);
0N/A listener.imageUpdate(this,
0N/A theImage,
0N/A minX, minY,
0N/A width, height,
0N/A periodX, periodY,
0N/A bands);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the end of a progressive pass to all
0N/A * registered <code>IIOReadUpdateListener</code>s by calling their
0N/A * <code>passComplete</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param theImage the <code>BufferedImage</code> being updated.
0N/A */
0N/A protected void processPassComplete(BufferedImage theImage) {
0N/A if (updateListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = updateListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadUpdateListener listener =
0N/A (IIOReadUpdateListener)updateListeners.get(i);
0N/A listener.passComplete(this, theImage);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the beginning of a thumbnail progressive pass to all
0N/A * registered <code>IIOReadUpdateListener</code>s by calling their
0N/A * <code>thumbnailPassStarted</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param theThumbnail the <code>BufferedImage</code> thumbnail
0N/A * being updated.
0N/A * @param pass the index of the current pass, starting with 0.
0N/A * @param minPass the index of the first pass that will be decoded.
0N/A * @param maxPass the index of the last pass that will be decoded.
0N/A * @param minX the X coordinate of the upper-left pixel included
0N/A * in the pass.
0N/A * @param minY the X coordinate of the upper-left pixel included
0N/A * in the pass.
0N/A * @param periodX the horizontal separation between pixels.
0N/A * @param periodY the vertical separation between pixels.
0N/A * @param bands an array of <code>int</code>s indicating the
0N/A * set of affected bands of the destination.
0N/A */
0N/A protected void processThumbnailPassStarted(BufferedImage theThumbnail,
0N/A int pass,
0N/A int minPass, int maxPass,
0N/A int minX, int minY,
0N/A int periodX, int periodY,
0N/A int[] bands) {
0N/A if (updateListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = updateListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadUpdateListener listener =
0N/A (IIOReadUpdateListener)updateListeners.get(i);
0N/A listener.thumbnailPassStarted(this, theThumbnail, pass,
0N/A minPass,
0N/A maxPass,
0N/A minX, minY,
0N/A periodX, periodY,
0N/A bands);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the update of a set of samples in a thumbnail image
0N/A * to all registered <code>IIOReadUpdateListener</code>s by
0N/A * calling their <code>thumbnailUpdate</code> method. Subclasses may
0N/A * use this method as a convenience.
0N/A *
0N/A * @param theThumbnail the <code>BufferedImage</code> thumbnail
0N/A * being updated.
0N/A * @param minX the X coordinate of the upper-left pixel included
0N/A * in the pass.
0N/A * @param minY the X coordinate of the upper-left pixel included
0N/A * in the pass.
0N/A * @param width the total width of the area being updated, including
0N/A * pixels being skipped if <code>periodX &gt; 1</code>.
0N/A * @param height the total height of the area being updated,
0N/A * including pixels being skipped if <code>periodY &gt; 1</code>.
0N/A * @param periodX the horizontal separation between pixels.
0N/A * @param periodY the vertical separation between pixels.
0N/A * @param bands an array of <code>int</code>s indicating the
0N/A * set of affected bands of the destination.
0N/A */
0N/A protected void processThumbnailUpdate(BufferedImage theThumbnail,
0N/A int minX, int minY,
0N/A int width, int height,
0N/A int periodX, int periodY,
0N/A int[] bands) {
0N/A if (updateListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = updateListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadUpdateListener listener =
0N/A (IIOReadUpdateListener)updateListeners.get(i);
0N/A listener.thumbnailUpdate(this,
0N/A theThumbnail,
0N/A minX, minY,
0N/A width, height,
0N/A periodX, periodY,
0N/A bands);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts the end of a thumbnail progressive pass to all
0N/A * registered <code>IIOReadUpdateListener</code>s by calling their
0N/A * <code>thumbnailPassComplete</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param theThumbnail the <code>BufferedImage</code> thumbnail
0N/A * being updated.
0N/A */
0N/A protected void processThumbnailPassComplete(BufferedImage theThumbnail) {
0N/A if (updateListeners == null) {
0N/A return;
0N/A }
0N/A int numListeners = updateListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadUpdateListener listener =
0N/A (IIOReadUpdateListener)updateListeners.get(i);
0N/A listener.thumbnailPassComplete(this, theThumbnail);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts a warning message to all registered
0N/A * <code>IIOReadWarningListener</code>s by calling their
0N/A * <code>warningOccurred</code> method. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param warning the warning message to send.
0N/A *
0N/A * @exception IllegalArgumentException if <code>warning</code>
0N/A * is <code>null</code>.
0N/A */
0N/A protected void processWarningOccurred(String warning) {
0N/A if (warningListeners == null) {
0N/A return;
0N/A }
0N/A if (warning == null) {
0N/A throw new IllegalArgumentException("warning == null!");
0N/A }
0N/A int numListeners = warningListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadWarningListener listener =
0N/A (IIOReadWarningListener)warningListeners.get(i);
0N/A
0N/A listener.warningOccurred(this, warning);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Broadcasts a localized warning message to all registered
0N/A * <code>IIOReadWarningListener</code>s by calling their
0N/A * <code>warningOccurred</code> method with a string taken
0N/A * from a <code>ResourceBundle</code>. Subclasses may use this
0N/A * method as a convenience.
0N/A *
0N/A * @param baseName the base name of a set of
0N/A * <code>ResourceBundle</code>s containing localized warning
0N/A * messages.
0N/A * @param keyword the keyword used to index the warning message
0N/A * within the set of <code>ResourceBundle</code>s.
0N/A *
0N/A * @exception IllegalArgumentException if <code>baseName</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>keyword</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if no appropriate
0N/A * <code>ResourceBundle</code> may be located.
0N/A * @exception IllegalArgumentException if the named resource is
0N/A * not found in the located <code>ResourceBundle</code>.
0N/A * @exception IllegalArgumentException if the object retrieved
0N/A * from the <code>ResourceBundle</code> is not a
0N/A * <code>String</code>.
0N/A */
0N/A protected void processWarningOccurred(String baseName,
0N/A String keyword) {
0N/A if (warningListeners == null) {
0N/A return;
0N/A }
0N/A if (baseName == null) {
0N/A throw new IllegalArgumentException("baseName == null!");
0N/A }
0N/A if (keyword == null) {
0N/A throw new IllegalArgumentException("keyword == null!");
0N/A }
0N/A int numListeners = warningListeners.size();
0N/A for (int i = 0; i < numListeners; i++) {
0N/A IIOReadWarningListener listener =
0N/A (IIOReadWarningListener)warningListeners.get(i);
0N/A Locale locale = (Locale)warningLocales.get(i);
0N/A if (locale == null) {
0N/A locale = Locale.getDefault();
0N/A }
0N/A
0N/A /**
0N/A * If an applet supplies an implementation of ImageReader and
0N/A * resource bundles, then the resource bundle will need to be
0N/A * accessed via the applet class loader. So first try the context
0N/A * class loader to locate the resource bundle.
0N/A * If that throws MissingResourceException, then try the
0N/A * system class loader.
0N/A */
0N/A ClassLoader loader = (ClassLoader)
0N/A java.security.AccessController.doPrivileged(
0N/A new java.security.PrivilegedAction() {
0N/A public Object run() {
0N/A return Thread.currentThread().getContextClassLoader();
0N/A }
0N/A });
0N/A
0N/A ResourceBundle bundle = null;
0N/A try {
0N/A bundle = ResourceBundle.getBundle(baseName, locale, loader);
0N/A } catch (MissingResourceException mre) {
0N/A try {
0N/A bundle = ResourceBundle.getBundle(baseName, locale);
0N/A } catch (MissingResourceException mre1) {
0N/A throw new IllegalArgumentException("Bundle not found!");
0N/A }
0N/A }
0N/A
0N/A String warning = null;
0N/A try {
0N/A warning = bundle.getString(keyword);
0N/A } catch (ClassCastException cce) {
0N/A throw new IllegalArgumentException("Resource is not a String!");
0N/A } catch (MissingResourceException mre) {
0N/A throw new IllegalArgumentException("Resource is missing!");
0N/A }
0N/A
0N/A listener.warningOccurred(this, warning);
0N/A }
0N/A }
0N/A
0N/A // State management
0N/A
0N/A /**
0N/A * Restores the <code>ImageReader</code> to its initial state.
0N/A *
0N/A * <p> The default implementation calls <code>setInput(null,
0N/A * false)</code>, <code>setLocale(null)</code>,
0N/A * <code>removeAllIIOReadUpdateListeners()</code>,
0N/A * <code>removeAllIIOReadWarningListeners()</code>,
0N/A * <code>removeAllIIOReadProgressListeners()</code>, and
0N/A * <code>clearAbortRequest</code>.
0N/A */
0N/A public void reset() {
0N/A setInput(null, false, false);
0N/A setLocale(null);
0N/A removeAllIIOReadUpdateListeners();
0N/A removeAllIIOReadProgressListeners();
0N/A removeAllIIOReadWarningListeners();
0N/A clearAbortRequest();
0N/A }
0N/A
0N/A /**
0N/A * Allows any resources held by this object to be released. The
0N/A * result of calling any other method (other than
0N/A * <code>finalize</code>) subsequent to a call to this method
0N/A * is undefined.
0N/A *
0N/A * <p>It is important for applications to call this method when they
0N/A * know they will no longer be using this <code>ImageReader</code>.
0N/A * Otherwise, the reader may continue to hold on to resources
0N/A * indefinitely.
0N/A *
0N/A * <p>The default implementation of this method in the superclass does
0N/A * nothing. Subclass implementations should ensure that all resources,
0N/A * especially native resources, are released.
0N/A */
0N/A public void dispose() {
0N/A }
0N/A
0N/A // Utility methods
0N/A
0N/A /**
0N/A * A utility method that may be used by readers to compute the
0N/A * region of the source image that should be read, taking into
0N/A * account any source region and subsampling offset settings in
0N/A * the supplied <code>ImageReadParam</code>. The actual
0N/A * subsampling factors, destination size, and destination offset
0N/A * are <em>not</em> taken into consideration, thus further
0N/A * clipping must take place. The {@link #computeRegions
0N/A * <code>computeRegions</code>} method performs all necessary
0N/A * clipping.
0N/A *
0N/A * @param param the <code>ImageReadParam</code> being used, or
0N/A * <code>null</code>.
0N/A * @param srcWidth the width of the source image.
0N/A * @param srcHeight the height of the source image.
0N/A *
0N/A * @return the source region as a <code>Rectangle</code>.
0N/A */
0N/A protected static Rectangle getSourceRegion(ImageReadParam param,
0N/A int srcWidth,
0N/A int srcHeight) {
0N/A Rectangle sourceRegion = new Rectangle(0, 0, srcWidth, srcHeight);
0N/A if (param != null) {
0N/A Rectangle region = param.getSourceRegion();
0N/A if (region != null) {
0N/A sourceRegion = sourceRegion.intersection(region);
0N/A }
0N/A
0N/A int subsampleXOffset = param.getSubsamplingXOffset();
0N/A int subsampleYOffset = param.getSubsamplingYOffset();
0N/A sourceRegion.x += subsampleXOffset;
0N/A sourceRegion.y += subsampleYOffset;
0N/A sourceRegion.width -= subsampleXOffset;
0N/A sourceRegion.height -= subsampleYOffset;
0N/A }
0N/A
0N/A return sourceRegion;
0N/A }
0N/A
0N/A /**
0N/A * Computes the source region of interest and the destination
0N/A * region of interest, taking the width and height of the source
0N/A * image, an optional destination image, and an optional
0N/A * <code>ImageReadParam</code> into account. The source region
0N/A * begins with the entire source image. Then that is clipped to
0N/A * the source region specified in the <code>ImageReadParam</code>,
0N/A * if one is specified.
0N/A *
0N/A * <p> If either of the destination offsets are negative, the
0N/A * source region is clipped so that its top left will coincide
0N/A * with the top left of the destination image, taking subsampling
0N/A * into account. Then the result is clipped to the destination
0N/A * image on the right and bottom, if one is specified, taking
0N/A * subsampling and destination offsets into account.
0N/A *
0N/A * <p> Similarly, the destination region begins with the source
0N/A * image, is translated to the destination offset given in the
0N/A * <code>ImageReadParam</code> if there is one, and finally is
0N/A * clipped to the destination image, if there is one.
0N/A *
0N/A * <p> If either the source or destination regions end up having a
0N/A * width or height of 0, an <code>IllegalArgumentException</code>
0N/A * is thrown.
0N/A *
0N/A * <p> The {@link #getSourceRegion <code>getSourceRegion</code>}
0N/A * method may be used if only source clipping is desired.
0N/A *
0N/A * @param param an <code>ImageReadParam</code>, or <code>null</code>.
0N/A * @param srcWidth the width of the source image.
0N/A * @param srcHeight the height of the source image.
0N/A * @param image a <code>BufferedImage</code> that will be the
0N/A * destination image, or <code>null</code>.
0N/A * @param srcRegion a <code>Rectangle</code> that will be filled with
0N/A * the source region of interest.
0N/A * @param destRegion a <code>Rectangle</code> that will be filled with
0N/A * the destination region of interest.
0N/A * @exception IllegalArgumentException if <code>srcRegion</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if <code>dstRegion</code>
0N/A * is <code>null</code>.
0N/A * @exception IllegalArgumentException if the resulting source or
0N/A * destination region is empty.
0N/A */
0N/A protected static void computeRegions(ImageReadParam param,
0N/A int srcWidth,
0N/A int srcHeight,
0N/A BufferedImage image,
0N/A Rectangle srcRegion,
0N/A Rectangle destRegion) {
0N/A if (srcRegion == null) {
0N/A throw new IllegalArgumentException("srcRegion == null!");
0N/A }
0N/A if (destRegion == null) {
0N/A throw new IllegalArgumentException("destRegion == null!");
0N/A }
0N/A
0N/A // Start with the entire source image
0N/A srcRegion.setBounds(0, 0, srcWidth, srcHeight);
0N/A
0N/A // Destination also starts with source image, as that is the
0N/A // maximum extent if there is no subsampling
0N/A destRegion.setBounds(0, 0, srcWidth, srcHeight);
0N/A
0N/A // Clip that to the param region, if there is one
0N/A int periodX = 1;
0N/A int periodY = 1;
0N/A int gridX = 0;
0N/A int gridY = 0;
0N/A if (param != null) {
0N/A Rectangle paramSrcRegion = param.getSourceRegion();
0N/A if (paramSrcRegion != null) {
0N/A srcRegion.setBounds(srcRegion.intersection(paramSrcRegion));
0N/A }
0N/A periodX = param.getSourceXSubsampling();
0N/A periodY = param.getSourceYSubsampling();
0N/A gridX = param.getSubsamplingXOffset();
0N/A gridY = param.getSubsamplingYOffset();
0N/A srcRegion.translate(gridX, gridY);
0N/A srcRegion.width -= gridX;
0N/A srcRegion.height -= gridY;
0N/A destRegion.setLocation(param.getDestinationOffset());
0N/A }
0N/A
0N/A // Now clip any negative destination offsets, i.e. clip
0N/A // to the top and left of the destination image
0N/A if (destRegion.x < 0) {
0N/A int delta = -destRegion.x*periodX;
0N/A srcRegion.x += delta;
0N/A srcRegion.width -= delta;
0N/A destRegion.x = 0;
0N/A }
0N/A if (destRegion.y < 0) {
0N/A int delta = -destRegion.y*periodY;
0N/A srcRegion.y += delta;
0N/A srcRegion.height -= delta;
0N/A destRegion.y = 0;
0N/A }
0N/A
0N/A // Now clip the destination Region to the subsampled width and height
0N/A int subsampledWidth = (srcRegion.width + periodX - 1)/periodX;
0N/A int subsampledHeight = (srcRegion.height + periodY - 1)/periodY;
0N/A destRegion.width = subsampledWidth;
0N/A destRegion.height = subsampledHeight;
0N/A
0N/A // Now clip that to right and bottom of the destination image,
0N/A // if there is one, taking subsampling into account
0N/A if (image != null) {
0N/A Rectangle destImageRect = new Rectangle(0, 0,
0N/A image.getWidth(),
0N/A image.getHeight());
0N/A destRegion.setBounds(destRegion.intersection(destImageRect));
0N/A if (destRegion.isEmpty()) {
0N/A throw new IllegalArgumentException
0N/A ("Empty destination region!");
0N/A }
0N/A
0N/A int deltaX = destRegion.x + subsampledWidth - image.getWidth();
0N/A if (deltaX > 0) {
0N/A srcRegion.width -= deltaX*periodX;
0N/A }
0N/A int deltaY = destRegion.y + subsampledHeight - image.getHeight();
0N/A if (deltaY > 0) {
0N/A srcRegion.height -= deltaY*periodY;
0N/A }
0N/A }
0N/A if (srcRegion.isEmpty() || destRegion.isEmpty()) {
0N/A throw new IllegalArgumentException("Empty region!");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * A utility method that may be used by readers to test the
0N/A * validity of the source and destination band settings of an
0N/A * <code>ImageReadParam</code>. This method may be called as soon
0N/A * as the reader knows both the number of bands of the source
0N/A * image as it exists in the input stream, and the number of bands
0N/A * of the destination image that being written.
0N/A *
0N/A * <p> The method retrieves the source and destination band
0N/A * setting arrays from param using the <code>getSourceBands</code>
0N/A * and <code>getDestinationBands</code>methods (or considers them
0N/A * to be <code>null</code> if <code>param</code> is
0N/A * <code>null</code>). If the source band setting array is
0N/A * <code>null</code>, it is considered to be equal to the array
0N/A * <code>{ 0, 1, ..., numSrcBands - 1 }</code>, and similarly for
0N/A * the destination band setting array.
0N/A *
0N/A * <p> The method then tests that both arrays are equal in length,
0N/A * and that neither array contains a value larger than the largest
0N/A * available band index.
0N/A *
0N/A * <p> Any failure results in an
0N/A * <code>IllegalArgumentException</code> being thrown; success
0N/A * results in the method returning silently.
0N/A *
0N/A * @param param the <code>ImageReadParam</code> being used to read
0N/A * the image.
0N/A * @param numSrcBands the number of bands of the image as it exists
0N/A * int the input source.
0N/A * @param numDstBands the number of bands in the destination image
0N/A * being written.
0N/A *
0N/A * @exception IllegalArgumentException if <code>param</code>
0N/A * contains an invalid specification of a source and/or
0N/A * destination band subset.
0N/A */
0N/A protected static void checkReadParamBandSettings(ImageReadParam param,
0N/A int numSrcBands,
0N/A int numDstBands) {
0N/A // A null param is equivalent to srcBands == dstBands == null.
0N/A int[] srcBands = null;
0N/A int[] dstBands = null;
0N/A if (param != null) {
0N/A srcBands = param.getSourceBands();
0N/A dstBands = param.getDestinationBands();
0N/A }
0N/A
0N/A int paramSrcBandLength =
0N/A (srcBands == null) ? numSrcBands : srcBands.length;
0N/A int paramDstBandLength =
0N/A (dstBands == null) ? numDstBands : dstBands.length;
0N/A
0N/A if (paramSrcBandLength != paramDstBandLength) {
0N/A throw new IllegalArgumentException("ImageReadParam num source & dest bands differ!");
0N/A }
0N/A
0N/A if (srcBands != null) {
0N/A for (int i = 0; i < srcBands.length; i++) {
0N/A if (srcBands[i] >= numSrcBands) {
0N/A throw new IllegalArgumentException("ImageReadParam source bands contains a value >= the number of source bands!");
0N/A }
0N/A }
0N/A }
0N/A
0N/A if (dstBands != null) {
0N/A for (int i = 0; i < dstBands.length; i++) {
0N/A if (dstBands[i] >= numDstBands) {
0N/A throw new IllegalArgumentException("ImageReadParam dest bands contains a value >= the number of dest bands!");
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>BufferedImage</code> to which decoded pixel
0N/A * data should be written. The image is determined by inspecting
0N/A * the supplied <code>ImageReadParam</code> if it is
0N/A * non-<code>null</code>; if its <code>getDestination</code>
0N/A * method returns a non-<code>null</code> value, that image is
0N/A * simply returned. Otherwise,
0N/A * <code>param.getDestinationType</code> method is called to
0N/A * determine if a particular image type has been specified. If
0N/A * so, the returned <code>ImageTypeSpecifier</code> is used after
0N/A * checking that it is equal to one of those included in
0N/A * <code>imageTypes</code>.
0N/A *
0N/A * <p> If <code>param</code> is <code>null</code> or the above
0N/A * steps have not yielded an image or an
0N/A * <code>ImageTypeSpecifier</code>, the first value obtained from
0N/A * the <code>imageTypes</code> parameter is used. Typically, the
0N/A * caller will set <code>imageTypes</code> to the value of
0N/A * <code>getImageTypes(imageIndex)</code>.
0N/A *
0N/A * <p> Next, the dimensions of the image are determined by a call
0N/A * to <code>computeRegions</code>. The actual width and height of
0N/A * the image being decoded are passed in as the <code>width</code>
0N/A * and <code>height</code> parameters.
0N/A *
0N/A * @param param an <code>ImageReadParam</code> to be used to get
0N/A * the destination image or image type, or <code>null</code>.
0N/A * @param imageTypes an <code>Iterator</code> of
0N/A * <code>ImageTypeSpecifier</code>s indicating the legal image
0N/A * types, with the default first.
0N/A * @param width the true width of the image or tile begin decoded.
0N/A * @param height the true width of the image or tile being decoded.
0N/A *
0N/A * @return the <code>BufferedImage</code> to which decoded pixel
0N/A * data should be written.
0N/A *
0N/A * @exception IIOException if the <code>ImageTypeSpecifier</code>
0N/A * specified by <code>param</code> does not match any of the legal
0N/A * ones from <code>imageTypes</code>.
0N/A * @exception IllegalArgumentException if <code>imageTypes</code>
0N/A * is <code>null</code> or empty, or if an object not of type
0N/A * <code>ImageTypeSpecifier</code> is retrieved from it.
0N/A * @exception IllegalArgumentException if the resulting image would
0N/A * have a width or height less than 1.
0N/A * @exception IllegalArgumentException if the product of
0N/A * <code>width</code> and <code>height</code> is greater than
0N/A * <code>Integer.MAX_VALUE</code>.
0N/A */
0N/A protected static BufferedImage
0N/A getDestination(ImageReadParam param,
0N/A Iterator<ImageTypeSpecifier> imageTypes,
0N/A int width, int height)
0N/A throws IIOException {
0N/A if (imageTypes == null || !imageTypes.hasNext()) {
0N/A throw new IllegalArgumentException("imageTypes null or empty!");
0N/A }
0N/A if ((long)width*height > Integer.MAX_VALUE) {
0N/A throw new IllegalArgumentException
0N/A ("width*height > Integer.MAX_VALUE!");
0N/A }
0N/A
0N/A BufferedImage dest = null;
0N/A ImageTypeSpecifier imageType = null;
0N/A
0N/A // If param is non-null, use it
0N/A if (param != null) {
0N/A // Try to get the image itself
0N/A dest = param.getDestination();
0N/A if (dest != null) {
0N/A return dest;
0N/A }
0N/A
0N/A // No image, get the image type
0N/A imageType = param.getDestinationType();
0N/A }
0N/A
0N/A // No info from param, use fallback image type
0N/A if (imageType == null) {
0N/A Object o = imageTypes.next();
0N/A if (!(o instanceof ImageTypeSpecifier)) {
0N/A throw new IllegalArgumentException
0N/A ("Non-ImageTypeSpecifier retrieved from imageTypes!");
0N/A }
0N/A imageType = (ImageTypeSpecifier)o;
0N/A } else {
0N/A boolean foundIt = false;
0N/A while (imageTypes.hasNext()) {
0N/A ImageTypeSpecifier type =
0N/A (ImageTypeSpecifier)imageTypes.next();
0N/A if (type.equals(imageType)) {
0N/A foundIt = true;
0N/A break;
0N/A }
0N/A }
0N/A
0N/A if (!foundIt) {
0N/A throw new IIOException
0N/A ("Destination type from ImageReadParam does not match!");
0N/A }
0N/A }
0N/A
0N/A Rectangle srcRegion = new Rectangle(0,0,0,0);
0N/A Rectangle destRegion = new Rectangle(0,0,0,0);
0N/A computeRegions(param,
0N/A width,
0N/A height,
0N/A null,
0N/A srcRegion,
0N/A destRegion);
0N/A
0N/A int destWidth = destRegion.x + destRegion.width;
0N/A int destHeight = destRegion.y + destRegion.height;
0N/A // Create a new image based on the type specifier
0N/A return imageType.createBufferedImage(destWidth, destHeight);
0N/A }
0N/A}