Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / javax / imageio / ImageReader.java
blobcdd77d52bad299b6ed92faf390bd8255514c3997
1 /* ImageReader.java -- Decodes raster images.
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.imageio;
41 import java.awt.Point;
42 import java.awt.Rectangle;
43 import java.awt.image.BufferedImage;
44 import java.awt.image.Raster;
45 import java.awt.image.RenderedImage;
46 import java.io.IOException;
47 import java.util.ArrayList;
48 import java.util.Iterator;
49 import java.util.List;
50 import java.util.Locale;
51 import java.util.ResourceBundle;
52 import java.util.MissingResourceException;
53 import java.util.Set;
55 import javax.imageio.event.IIOReadProgressListener;
56 import javax.imageio.event.IIOReadUpdateListener;
57 import javax.imageio.event.IIOReadWarningListener;
58 import javax.imageio.metadata.IIOMetadata;
59 import javax.imageio.spi.ImageReaderSpi;
60 import javax.imageio.stream.ImageInputStream;
62 /**
63 * A class for decoding images within the ImageIO framework.
65 * An ImageReader for a given format is instantiated by an
66 * ImageReaderSpi for that format. ImageReaderSpis are registered
67 * with the IIORegistry.
69 * The ImageReader API supports reading animated images that may have
70 * multiple frames; to support such images many methods take an index
71 * parameter.
73 * Images may also be read in multiple passes, where each successive
74 * pass increases the level of detail in the destination image.
76 public abstract class ImageReader
78 private boolean aborted;
80 /**
81 * All locales available for localization of warning messages, or
82 * null if localization is not supported.
84 protected Locale[] availableLocales = null;
86 /**
87 * true if the input source does not require metadata to be read,
88 * false otherwise.
90 protected boolean ignoreMetadata = false;
92 /**
93 * An ImageInputStream from which image data is read.
95 protected Object input = null;
97 /**
98 * The current locale used to localize warning messages, or null if
99 * no locale has been set.
101 protected Locale locale = null;
104 * The minimum index at which data can be read. Constantly 0 if
105 * seekForwardOnly is false, always increasing if seekForwardOnly is
106 * true.
108 protected int minIndex = 0;
111 * The image reader SPI that instantiated this reader.
113 protected ImageReaderSpi originatingProvider = null;
116 * A list of installed progress listeners. Initially null, meaning
117 * no installed listeners.
119 protected List progressListeners = null;
122 * true if this reader should only read data further ahead in the
123 * stream than its current location. false if it can read backwards
124 * in the stream. If this is true then caching can be avoided.
126 protected boolean seekForwardOnly = false;
129 * A list of installed update listeners. Initially null, meaning no
130 * installed listeners.
132 protected List updateListeners = null;
135 * A list of installed warning listeners. Initially null, meaning
136 * no installed listeners.
138 protected List warningListeners = null;
141 * A list of warning locales corresponding with the list of
142 * installed warning listeners. Initially null, meaning no locales.
144 protected List warningLocales = null;
147 * Construct an image reader.
149 * @param originatingProvider the provider that is constructing this
150 * image reader, or null
152 protected ImageReader(ImageReaderSpi originatingProvider)
154 this.originatingProvider = originatingProvider;
158 * Request that reading be aborted. The unread contents of the
159 * image will be undefined.
161 * Readers should clear the abort flag before starting a read
162 * operation, then poll it periodically during the read operation.
164 public void abort()
166 aborted = true;
170 * Check if the abort flag is set.
172 * @return true if the current read operation should be aborted,
173 * false otherwise
175 protected boolean abortRequested()
177 return aborted;
181 * Install a read progress listener. This method will return
182 * immediately if listener is null.
184 * @param listener a read progress listener or null
186 public void addIIOReadProgressListener(IIOReadProgressListener listener)
188 if (listener == null)
189 return;
190 if (progressListeners == null)
191 progressListeners = new ArrayList ();
192 progressListeners.add(listener);
196 * Install a read update listener. This method will return
197 * immediately if listener is null.
199 * @param listener a read update listener
201 public void addIIOReadUpdateListener(IIOReadUpdateListener listener)
203 if (listener == null)
204 return;
205 if (updateListeners == null)
206 updateListeners = new ArrayList ();
207 updateListeners.add(listener);
211 * Install a read warning listener. This method will return
212 * immediately if listener is null. Warning messages sent to this
213 * listener will be localized using the current locale. If the
214 * current locale is null then this reader will select a sensible
215 * default.
217 * @param listener a read warning listener
219 public void addIIOReadWarningListener(IIOReadWarningListener listener)
221 if (listener == null)
222 return;
223 if (warningListeners == null)
224 warningListeners = new ArrayList ();
225 warningListeners.add(listener);
229 * Check if this reader can handle raster data. Determines whether
230 * or not readRaster and readTileRaster throw
231 * UnsupportedOperationException.
233 * @return true if this reader supports raster data, false if not
235 public boolean canReadRaster()
237 return false;
241 * Clear the abort flag.
243 protected void clearAbortRequest()
245 aborted = false;
249 * Releases any resources allocated to this object. Subsequent
250 * calls to methods on this object will produce undefined results.
252 * The default implementation does nothing; subclasses should use
253 * this method ensure that native resources are released.
255 public void dispose()
257 // The default implementation does nothing.
261 * Returns the aspect ratio of this image, the ration of its width
262 * to its height. The aspect ratio is useful when resizing an image
263 * while keeping its proportions constant.
265 * @param imageIndex the frame index
267 * @return the image's aspect ratio
269 * @exception IllegalStateException if input is null
270 * @exception IndexOutOfBoundsException if the frame index is
271 * out-of-bounds
272 * @exception IOException if a read error occurs
274 public float getAspectRatio(int imageIndex)
275 throws IOException
277 if (input == null)
278 throw new IllegalStateException("input is null");
280 return (float) (getWidth(imageIndex) / getHeight(imageIndex));
284 * Retrieve the available locales. Return null if no locales are
285 * available or a clone of availableLocales.
287 * @return an array of locales or null
289 public Locale[] getAvailableLocales()
291 if (availableLocales == null)
292 return null;
294 return (Locale[]) availableLocales.clone();
298 * Retrieve the default read parameters for this reader's image
299 * format.
301 * The default implementation returns new ImageReadParam().
303 * @return image reading parameters
305 public ImageReadParam getDefaultReadParam()
307 return new ImageReadParam();
311 * Retrieve the format of the input source.
313 * @return the input source format name
315 * @exception IOException if a read error occurs
317 public String getFormatName()
318 throws IOException
320 return originatingProvider.getFormatNames()[0];
324 * Get the height of the input image in pixels. If the input image
325 * is resizable then a default height is returned.
327 * @param imageIndex the frame index
329 * @return the height of the input image
331 * @exception IllegalStateException if input has not been set
332 * @exception IndexOutOfBoundsException if the frame index is
333 * out-of-bounds
334 * @exception IOException if a read error occurs
336 public abstract int getHeight(int imageIndex)
337 throws IOException;
340 * Get the metadata associated with this image. If the reader is
341 * set to ignore metadata or does not support reading metadata, or
342 * if no metadata is available then null is returned.
344 * @param imageIndex the frame index
346 * @return a metadata object, or null
348 * @exception IllegalStateException if input has not been set
349 * @exception IndexOutOfBoundsException if the frame index is
350 * out-of-bounds
351 * @exception IOException if a read error occurs
353 public abstract IIOMetadata getImageMetadata(int imageIndex)
354 throws IOException;
357 * Get an iterator over the collection of image types into which
358 * this reader can decode image data. This method is guaranteed to
359 * return at least one valid image type specifier.
361 * The elements of the iterator should be ordered; the first element
362 * should be the most appropriate image type for this decoder,
363 * followed by the second-most appropriate, and so on.
365 * @param imageIndex the frame index
367 * @return an iterator over a collection of image type specifiers
369 * @exception IllegalStateException if input has not been set
370 * @exception IndexOutOfBoundsException if the frame index is
371 * out-of-bounds
372 * @exception IOException if a read error occurs
374 public abstract Iterator getImageTypes(int imageIndex)
375 throws IOException;
378 * Set the input source to the given object, specify whether this
379 * reader should be allowed to read input from the data stream more
380 * than once, and specify whether this reader should ignore metadata
381 * in the input stream. The input source must be set before many
382 * methods can be called on this reader. (see all ImageReader
383 * methods that throw IllegalStateException). If input is null then
384 * the current input source will be removed.
386 * Unless this reader has direct access with imaging hardware, input
387 * should be an ImageInputStream.
389 * @param input the input source object
390 * @param seekForwardOnly true if this reader should be allowed to
391 * read input from the data stream more than once, false otherwise
392 * @param ignoreMetadata true if this reader should ignore metadata
393 * associated with the input source, false otherwise
395 * @exception IllegalArgumentException if input is not a valid input
396 * source for this reader and is not an ImageInputStream
398 public void setInput(Object input,
399 boolean seekForwardOnly,
400 boolean ignoreMetadata)
402 Class[] okClasses = originatingProvider.getInputTypes();
403 if (okClasses == null)
405 if (!(input instanceof ImageInputStream))
406 throw new IllegalArgumentException();
408 else
410 boolean classOk = false;
411 for (int i = 0; i < okClasses.length; ++i)
412 if (okClasses[i].isInstance(input))
413 classOk = true;
414 if (!classOk)
415 throw new IllegalArgumentException();
418 this.input = input;
419 this.seekForwardOnly = seekForwardOnly;
420 this.ignoreMetadata = ignoreMetadata;
421 this.minIndex = 0;
425 * Set the input source to the given object and specify whether this
426 * reader should be allowed to read input from the data stream more
427 * than once. The input source must be set before many methods can
428 * be called on this reader. (see all ImageReader methods that throw
429 * IllegalStateException). If input is null then the current input
430 * source will be removed.
432 * @param input the input source object
433 * @param seekForwardOnly true if this reader should be allowed to
434 * read input from the data stream more than once, false otherwise
436 * @exception IllegalArgumentException if input is not a valid input
437 * source for this reader and is not an ImageInputStream
439 public void setInput(Object in, boolean seekForwardOnly)
441 setInput(in, seekForwardOnly, false);
445 * Set the input source to the given object. The input source must
446 * be set before many methods can be called on this reader. (see all
447 * ImageReader methods that throw IllegalStateException). If input
448 * is null then the current input source will be removed.
450 * @param input the input source object
452 * @exception IllegalArgumentException if input is not a valid input
453 * source for this reader and is not an ImageInputStream
455 public void setInput(Object input)
457 setInput(input, false, false);
461 * Get this reader's image input source. null is returned if the
462 * image source has not been set.
464 * @return an image input source object, or null
466 public Object getInput()
468 return input;
472 * Get this reader's locale. null is returned if the locale has not
473 * been set.
475 * @return this reader's locale, or null
477 public Locale getLocale()
479 return locale;
483 * Return the number of images available from the image input
484 * source, not including thumbnails. This method will return 1
485 * unless this reader is reading an animated image.
487 * Certain multi-image formats do not encode the total number of
488 * images. When reading images in those formats it may be necessary
489 * to repeatedly call read, incrementing the image index at each
490 * call, until an IndexOutOfBoundsException is thrown.
492 * The allowSearch parameter determines whether all images must be
493 * available at all times. When allowSearch is false, getNumImages
494 * will return -1 if the total number of images is unknown.
495 * Otherwise this method returns the number of images.
497 * @param allowSearch true if all images should be available at
498 * once, false otherwise
500 * @return -1 if allowSearch is false and the total number of images
501 * is currently unknown, or the number of images
503 * @exception IllegalStateException if input has not been set, or if
504 * seekForwardOnly is true
505 * @exception IOException if a read error occurs
507 public abstract int getNumImages(boolean allowSearch)
508 throws IOException;
511 * Get the number of thumbnails associated with an image.
513 * @param imageIndex the frame index
515 * @return the number of thumbnails associated with this image
517 public int getNumThumbnails(int imageIndex)
518 throws IOException
520 return 0;
524 * Get the ImageReaderSpi that created this reader or null.
526 * @return an ImageReaderSpi, or null
528 public ImageReaderSpi getOriginatingProvider()
530 return originatingProvider;
534 * Get the metadata associated with the image being read. If the
535 * reader is set to ignore metadata or does not support reading
536 * metadata, or if no metadata is available then null is returned.
537 * This method returns metadata associated with the entirety of the
538 * image data, whereas getImageMetadata(int) returns metadata
539 * associated with a frame within a multi-image data stream.
541 * @return metadata associated with the image being read, or null
543 * @exception IOException if a read error occurs
545 public abstract IIOMetadata getStreamMetadata()
546 throws IOException;
549 * Get the height of a thumbnail image.
551 * @param imageIndex the frame index
552 * @param thumbnailIndex the thumbnail index
554 * @return the height of the thumbnail image
556 * @exception UnsupportedOperationException if this reader does not
557 * support thumbnails
558 * @exception IllegalStateException if input is null
559 * @exception IndexOutOfBoundsException if either index is
560 * out-of-bounds
561 * @exception IOException if a read error occurs
563 public int getThumbnailHeight(int imageIndex, int thumbnailIndex)
564 throws IOException
566 return readThumbnail(imageIndex, thumbnailIndex).getHeight();
570 * Get the width of a thumbnail image.
572 * @param imageIndex the frame index
573 * @param thumbnailIndex the thumbnail index
575 * @return the width of the thumbnail image
577 * @exception UnsupportedOperationException if this reader does not
578 * support thumbnails
579 * @exception IllegalStateException if input is null
580 * @exception IndexOutOfBoundsException if either index is
581 * out-of-bounds
582 * @exception IOException if a read error occurs
584 public int getThumbnailWidth(int imageIndex, int thumbnailIndex)
585 throws IOException
587 return readThumbnail(imageIndex, thumbnailIndex).getWidth();
591 * Get the X coordinate in pixels of the top-left corner of the
592 * first tile in this image.
594 * @param imageIndex the frame index
596 * @return the X coordinate of this image's first tile
598 * @exception IllegalStateException if input is needed but the input
599 * source is not set
600 * @exception IndexOutOfBoundsException if the frame index is
601 * out-of-bounds
602 * @exception IOException if a read error occurs
604 public int getTileGridXOffset(int imageIndex)
605 throws IOException
607 return 0;
611 * Get the Y coordinate in pixels of the top-left corner of the
612 * first tile in this image.
614 * @param imageIndex the frame index
616 * @return the Y coordinate of this image's first tile
618 * @exception IllegalStateException if input is needed but the input
619 * source is not set
620 * @exception IndexOutOfBoundsException if the frame index is
621 * out-of-bounds
622 * @exception IOException if a read error occurs
624 public int getTileGridYOffset(int imageIndex)
625 throws IOException
627 return 0;
631 * Get the height of an image tile.
633 * @param imageIndex the frame index
635 * @return the tile height for the given image
637 * @exception IllegalStateException if input is null
638 * @exception IndexOutOfBoundsException if the frame index is
639 * out-of-bounds
640 * @exception IOException if a read error occurs
642 public int getTileHeight(int imageIndex)
643 throws IOException
645 return getHeight(imageIndex);
649 * Get the width of an image tile.
651 * @param imageIndex the frame index
653 * @return the tile width for the given image
655 * @exception IllegalStateException if input is null
656 * @exception IndexOutOfBoundsException if the frame index is
657 * out-of-bounds
658 * @exception IOException if a read error occurs
660 public int getTileWidth(int imageIndex)
661 throws IOException
663 return getWidth(imageIndex);
667 * Get the width of the input image in pixels. If the input image
668 * is resizable then a default width is returned.
670 * @param imageIndex the image's index
672 * @return the width of the input image
674 * @exception IllegalStateException if input has not been set
675 * @exception IndexOutOfBoundsException if the frame index is
676 * out-of-bounds
677 * @exception IOException if a read error occurs
679 public abstract int getWidth(int imageIndex)
680 throws IOException;
683 * Check whether or not the given image has thumbnails associated
684 * with it.
686 * @return true if the given image has thumbnails, false otherwise
688 * @exception IllegalStateException if input is null
689 * @exception IndexOutOfBoundsException if the frame index is
690 * out-of-bounds
691 * @exception IOException if a read error occurs
693 public boolean hasThumbnails(int imageIndex)
694 throws IOException
696 return getNumThumbnails(imageIndex) > 0;
700 * Check if this image reader ignores metadata. This method simply
701 * returns the value of ignoreMetadata.
703 * @return true if metadata is being ignored, false otherwise
705 public boolean isIgnoringMetadata()
707 return ignoreMetadata;
711 * Check if the given image is sub-divided into equal-sized
712 * non-overlapping pixel rectangles.
714 * A reader may expose tiling in the underlying format, hide it, or
715 * simulate tiling even if the underlying format is not tiled.
717 * @return true if the given image is tiled, false otherwise
719 * @exception IllegalStateException if input is null
720 * @exception IndexOutOfBoundsException if the frame index is
721 * out-of-bounds
722 * @exception IOException if a read error occurs
724 public boolean isImageTiled(int imageIndex)
725 throws IOException
727 return false;
731 * Check if all pixels in this image are readily accessible. This
732 * method should return false for compressed formats. The return
733 * value is a hint as to the efficiency of certain image reader
734 * operations.
736 * @param imageIndex the frame index
738 * @return true if random pixel access is fast, false otherwise
740 * @exception IllegalStateException if input is null and it is
741 * needed to determine the return value
742 * @exception IndexOutOfBoundsException if the frame index is
743 * out-of-bounds but the frame data must be accessed to determine
744 * the return value
745 * @exception IOException if a read error occurs
747 public boolean isRandomAccessEasy(int imageIndex)
748 throws IOException
750 return false;
754 * Check if this image reader may only seek forward within the input
755 * stream.
757 * @return true if this reader may only seek forward, false
758 * otherwise
760 public boolean isSeekForwardOnly()
762 return seekForwardOnly;
766 * Notifies all installed read progress listeners that image loading
767 * has completed by calling their imageComplete methods.
769 protected void processImageComplete()
771 if (progressListeners != null)
773 Iterator it = progressListeners.iterator();
775 while (it.hasNext())
777 IIOReadProgressListener listener =
778 (IIOReadProgressListener) it.next();
779 listener.imageComplete (this);
785 * Notifies all installed read progress listeners that a certain
786 * percentage of the image has been loaded, by calling their
787 * imageProgress methods.
789 * @param percentageDone the percentage of image data that has been
790 * loaded
792 protected void processImageProgress(float percentageDone)
794 if (progressListeners != null)
796 Iterator it = progressListeners.iterator();
798 while (it.hasNext())
800 IIOReadProgressListener listener =
801 (IIOReadProgressListener) it.next();
802 listener.imageProgress(this, percentageDone);
807 * Notifies all installed read progress listeners, by calling their
808 * imageStarted methods, that image loading has started on the given
809 * image.
811 * @param imageIndex the frame index of the image that has started
812 * loading
814 protected void processImageStarted(int imageIndex)
816 if (progressListeners != null)
818 Iterator it = progressListeners.iterator();
820 while (it.hasNext())
822 IIOReadProgressListener listener =
823 (IIOReadProgressListener) it.next();
824 listener.imageStarted(this, imageIndex);
830 * Notifies all installed read update listeners, by calling their
831 * imageUpdate methods, that the set of samples has changed.
833 * @param image the buffered image that is being updated
834 * @param minX the X coordinate of the top-left pixel in this pass
835 * @param minY the Y coordinate of the top-left pixel in this pass
836 * @param width the total width of the rectangle covered by this
837 * pass, including skipped pixels
838 * @param height the total height of the rectangle covered by this
839 * pass, including skipped pixels
840 * @param periodX the horizontal sample interval
841 * @param periodY the vertical sample interval
842 * @param bands the affected bands in the destination
844 protected void processImageUpdate(BufferedImage image, int minX, int minY,
845 int width, int height, int periodX,
846 int periodY, int[] bands)
848 if (updateListeners != null)
850 Iterator it = updateListeners.iterator();
852 while (it.hasNext())
854 IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
855 listener.imageUpdate(this, image, minX, minY, width, height,
856 periodX, periodY, bands);
862 * Notifies all installed update progress listeners, by calling
863 * their passComplete methods, that a progressive pass has
864 * completed.
866 * @param image the image that has being updated
868 protected void processPassComplete(BufferedImage image)
870 if (updateListeners != null)
872 Iterator it = updateListeners.iterator();
874 while (it.hasNext())
876 IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
877 listener.passComplete(this, image);
883 * Notifies all installed read update listeners, by calling their
884 * passStarted methods, that a new pass has begun.
886 * @param image the buffered image that is being updated
887 * @param pass the current pass number
888 * @param minPass the pass at which decoding will begin
889 * @param maxPass the pass at which decoding will end
890 * @param minX the X coordinate of the top-left pixel in this pass
891 * @param minY the Y coordinate of the top-left pixel in this pass
892 * @param width the total width of the rectangle covered by this
893 * pass, including skipped pixels
894 * @param height the total height of the rectangle covered by this
895 * pass, including skipped pixels
896 * @param periodX the horizontal sample interval
897 * @param periodY the vertical sample interval
898 * @param bands the affected bands in the destination
900 protected void processPassStarted(BufferedImage image, int pass, int minPass,
901 int maxPass, int minX, int minY,
902 int periodX, int periodY, int[] bands)
904 if (updateListeners != null)
906 Iterator it = updateListeners.iterator();
908 while (it.hasNext())
910 IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
911 listener.passStarted(this, image, pass, minPass, maxPass, minX,
912 minY, periodX, periodY, bands);
918 * Notifies all installed read progress listeners that image loading
919 * has been aborted by calling their readAborted methods.
921 protected void processReadAborted()
923 if (progressListeners != null)
925 Iterator it = progressListeners.iterator();
927 while (it.hasNext())
929 IIOReadProgressListener listener =
930 (IIOReadProgressListener) it.next();
931 listener.readAborted(this);
936 * Notifies all installed read progress listeners, by calling their
937 * sequenceComplete methods, that a sequence of images has completed
938 * loading.
940 protected void processSequenceComplete()
942 if (progressListeners != null)
944 Iterator it = progressListeners.iterator();
946 while (it.hasNext())
948 IIOReadProgressListener listener =
949 (IIOReadProgressListener) it.next();
950 listener.sequenceComplete(this);
956 * Notifies all installed read progress listeners, by calling their
957 * sequenceStarted methods, a sequence of images has started
958 * loading.
960 * @param minIndex the index of the first image in the sequence
962 protected void processSequenceStarted(int minIndex)
965 if (progressListeners != null)
967 Iterator it = progressListeners.iterator();
969 while (it.hasNext())
971 IIOReadProgressListener listener =
972 (IIOReadProgressListener) it.next();
973 listener.sequenceStarted(this, minIndex);
979 * Notifies all installed read progress listeners, by calling their
980 * thumbnailComplete methods, that a thumbnail has completed
981 * loading.
983 protected void processThumbnailComplete()
985 if (progressListeners != null)
987 Iterator it = progressListeners.iterator();
989 while (it.hasNext())
991 IIOReadProgressListener listener =
992 (IIOReadProgressListener) it.next();
993 listener.thumbnailComplete(this);
999 * Notifies all installed update progress listeners, by calling
1000 * their thumbnailPassComplete methods, that a progressive pass has
1001 * completed on a thumbnail.
1003 * @param thumbnail the thumbnail that has being updated
1005 protected void processThumbnailPassComplete(BufferedImage thumbnail)
1007 if (updateListeners != null)
1009 Iterator it = updateListeners.iterator();
1011 while (it.hasNext())
1013 IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
1014 listener.thumbnailPassComplete(this, thumbnail);
1020 * Notifies all installed read update listeners, by calling their
1021 * thumbnailPassStarted methods, that a new pass has begun.
1023 * @param thumbnail the thumbnail that is being updated
1024 * @param pass the current pass number
1025 * @param minPass the pass at which decoding will begin
1026 * @param maxPass the pass at which decoding will end
1027 * @param minX the X coordinate of the top-left pixel in this pass
1028 * @param minY the Y coordinate of the top-left pixel in this pass
1029 * @param width the total width of the rectangle covered by this
1030 * pass, including skipped pixels
1031 * @param height the total height of the rectangle covered by this
1032 * pass, including skipped pixels
1033 * @param periodX the horizontal sample interval
1034 * @param periodY the vertical sample interval
1035 * @param bands the affected bands in the destination
1037 protected void processThumbnailPassStarted(BufferedImage thumbnail, int pass,
1038 int minPass, int maxPass, int minX,
1039 int minY, int periodX, int periodY,
1040 int[] bands)
1042 if (updateListeners != null)
1044 Iterator it = updateListeners.iterator();
1046 while (it.hasNext())
1048 IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
1049 listener.thumbnailPassStarted(this, thumbnail, pass, minPass,
1050 maxPass, minX, minY, periodX,
1051 periodY, bands);
1057 * Notifies all installed read progress listeners that a certain
1058 * percentage of a thumbnail has been loaded, by calling their
1059 * thumbnailProgress methods.
1061 * @param percentageDone the percentage of thumbnail data that has
1062 * been loaded
1064 protected void processThumbnailProgress(float percentageDone)
1066 if (progressListeners != null)
1068 Iterator it = progressListeners.iterator();
1070 while (it.hasNext())
1072 IIOReadProgressListener listener =
1073 (IIOReadProgressListener) it.next();
1074 listener.thumbnailProgress(this, percentageDone);
1080 * Notifies all installed read progress listeners, by calling their
1081 * imageStarted methods, that thumbnail loading has started on the
1082 * given thumbnail of the given image.
1084 * @param imageIndex the frame index of the image one of who's
1085 * thumbnails has started loading
1086 * @param thumbnailIndex the index of the thumbnail that has started
1087 * loading
1089 protected void processThumbnailStarted(int imageIndex, int thumbnailIndex)
1091 if (progressListeners != null)
1093 Iterator it = progressListeners.iterator();
1095 while (it.hasNext())
1097 IIOReadProgressListener listener =
1098 (IIOReadProgressListener) it.next();
1099 listener.thumbnailStarted(this, imageIndex, thumbnailIndex);
1105 * Notifies all installed read update listeners, by calling their
1106 * thumbnailUpdate methods, that the set of samples has changed.
1108 * @param image the buffered image that is being updated
1109 * @param minX the X coordinate of the top-left pixel in this pass
1110 * @param minY the Y coordinate of the top-left pixel in this pass
1111 * @param width the total width of the rectangle covered by this
1112 * pass, including skipped pixels
1113 * @param height the total height of the rectangle covered by this
1114 * pass, including skipped pixels
1115 * @param periodX the horizontal sample interval
1116 * @param periodY the vertical sample interval
1117 * @param bands the affected bands in the destination
1119 protected void processThumbnailUpdate(BufferedImage image, int minX, int minY,
1120 int width, int height, int periodX,
1121 int periodY, int[] bands)
1123 if (updateListeners != null)
1125 Iterator it = updateListeners.iterator();
1127 while (it.hasNext())
1129 IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next();
1130 listener.thumbnailUpdate(this, image, minX, minY, width, height,
1131 periodX, periodY, bands);
1137 * Notifies all installed warning listeners, by calling their
1138 * warningOccurred methods, that a warning message has been raised.
1140 * @param warning the warning message
1142 * @exception IllegalArgumentException if warning is null
1144 protected void processWarningOccurred(String warning)
1146 if (warning == null)
1147 throw new IllegalArgumentException ("null argument");
1148 if (warningListeners != null)
1150 Iterator it = warningListeners.iterator();
1152 while (it.hasNext())
1154 IIOReadWarningListener listener =
1155 (IIOReadWarningListener) it.next();
1156 listener.warningOccurred(this, warning);
1162 * Notify all installed warning listeners, by calling their
1163 * warningOccurred methods, that a warning message has been raised.
1164 * The warning message is retrieved from a resource bundle, using
1165 * the given basename and keyword.
1167 * @param baseName the basename of the resource from which to
1168 * retrieve the warning message
1169 * @param keyword the keyword used to retrieve the warning from the
1170 * resource bundle
1172 * @exception IllegalArgumentException if either baseName or keyword
1173 * is null
1174 * @exception IllegalArgumentException if no resource bundle is
1175 * found using baseName
1176 * @exception IllegalArgumentException if the given keyword produces
1177 * no results from the resource bundle
1178 * @exception IllegalArgumentException if the retrieved object is
1179 * not a String
1181 protected void processWarningOccurred(String baseName,
1182 String keyword)
1184 if (baseName == null || keyword == null)
1185 throw new IllegalArgumentException ("null argument");
1187 ResourceBundle b = null;
1191 b = ResourceBundle.getBundle(baseName, getLocale());
1193 catch (MissingResourceException e)
1195 throw new IllegalArgumentException ("no resource bundle found");
1198 Object str = null;
1202 str = b.getObject(keyword);
1204 catch (MissingResourceException e)
1206 throw new IllegalArgumentException ("no results found for keyword");
1209 if (! (str instanceof String))
1210 throw new IllegalArgumentException ("retrieved object not a String");
1212 String warning = (String) str;
1214 if (warningListeners != null)
1216 Iterator it = warningListeners.iterator();
1218 while (it.hasNext())
1220 IIOReadWarningListener listener =
1221 (IIOReadWarningListener) it.next();
1222 listener.warningOccurred(this, warning);
1228 * Read the given frame into a buffered image using the given read
1229 * parameters. Listeners will be notified of image loading progress
1230 * and warnings.
1232 * @param imageIndex the index of the frame to read
1233 * @param param the image read parameters to use when reading
1235 * @return a buffered image
1237 * @exception IllegalStateException if input is null
1238 * @exception IndexOutOfBoundsException if the frame index is
1239 * out-of-bounds
1240 * @exception IOException if a read error occurs
1242 public abstract BufferedImage read(int imageIndex, ImageReadParam param)
1243 throws IOException;
1246 * Check if this reader supports reading thumbnails.
1248 * @return true if this reader supports reading thumbnails, false
1249 * otherwise
1251 public boolean readerSupportsThumbnails()
1253 return false;
1257 * Read raw raster data. The image type specifier in param is
1258 * ignored but all other parameters are used. Offset parameters are
1259 * translated into the raster's coordinate space. This method may
1260 * be implemented by image readers that want to provide direct
1261 * access to raw image data.
1263 * @param imageIndex the frame index
1264 * @param param the image read parameters
1266 * @return a raster containing the read image data
1268 * @exception UnsupportedOperationException if this reader doesn't
1269 * support rasters
1270 * @exception IllegalStateException if input is null
1271 * @exception IndexOutOfBoundsException if the frame index is
1272 * out-of-bounds
1273 * @exception IOException if a read error occurs
1275 public Raster readRaster(int imageIndex, ImageReadParam param)
1276 throws IOException
1278 throw new UnsupportedOperationException();
1282 * Read a thumbnail.
1284 * @param imageIndex the frame index
1285 * @param thumbnailIndex the thumbnail index
1287 * @return a buffered image of the thumbnail
1289 * @exception UnsupportedOperationException if this reader doesn't
1290 * support thumbnails
1291 * @exception IllegalStateException if input is null
1292 * @exception IndexOutOfBoundsException if either the frame index or
1293 * the thumbnail index is out-of-bounds
1294 * @exception IOException if a read error occurs
1297 public BufferedImage readThumbnail(int imageIndex, int thumbnailIndex)
1298 throws IOException
1300 throw new UnsupportedOperationException();
1304 * Uninstall all read progress listeners.
1306 public void removeAllIIOReadProgressListeners()
1308 progressListeners = null;
1312 * Uninstall all read update listeners.
1314 public void removeAllIIOReadUpdateListeners()
1316 updateListeners = null;
1320 * Uninstall all read warning listeners.
1322 public void removeAllIIOReadWarningListeners()
1324 warningListeners = null;
1328 * Uninstall the given read progress listener.
1330 * @param listener the listener to remove
1332 public void removeIIOReadProgressListener(IIOReadProgressListener listener)
1334 if (listener == null)
1335 return;
1336 if (progressListeners != null)
1338 progressListeners.remove(listener);
1343 * Uninstall the given read update listener.
1345 * @param listener the listener to remove
1347 public void removeIIOReadUpdateListener(IIOReadUpdateListener listener)
1349 if (listener == null)
1350 return;
1352 if (updateListeners != null)
1354 updateListeners.remove(listener);
1359 * Uninstall the given read warning listener.
1361 * @param listener the listener to remove
1363 public void removeIIOReadWarningListener(IIOReadWarningListener listener)
1365 if (listener == null)
1366 return;
1367 if (warningListeners != null)
1369 warningListeners.remove(listener);
1374 * Set the current locale or use the default locale.
1376 * @param locale the locale to set, or null
1378 public void setLocale(Locale locale)
1380 if (locale != null)
1382 // Check if its a valid locale.
1383 boolean found = false;
1385 if (availableLocales != null)
1386 for (int i = availableLocales.length - 1; i >= 0; --i)
1387 if (availableLocales[i].equals(locale))
1388 found = true;
1390 if (! found)
1391 throw new IllegalArgumentException("looale not available");
1394 this.locale = locale;
1398 * Check that the given read parameters have valid source and
1399 * destination band settings. If the param.getSourceBands() returns
1400 * null, the array is assumed to include all band indices, 0 to
1401 * numSrcBands - 1; likewise if param.getDestinationBands() returns
1402 * null, it is assumed to be an array containing indices 0 to
1403 * numDstBands - 1. A failure will cause this method to throw
1404 * IllegalArgumentException.
1406 * @param param the image parameters to check
1407 * @param numSrcBands the number of input source bands
1408 * @param numDstBands the number of ouput destination bands
1410 * @exception IllegalArgumentException if either the given source or
1411 * destination band indices are invalid
1413 protected static void checkReadParamBandSettings(ImageReadParam param,
1414 int numSrcBands,
1415 int numDstBands)
1417 int[] srcBands = param.getSourceBands();
1418 int[] dstBands = param.getDestinationBands();
1419 boolean lengthsDiffer = false;
1420 boolean srcOOB = false;
1421 boolean dstOOB = false;
1423 if (srcBands == null)
1425 if (dstBands == null)
1427 if (numSrcBands != numDstBands)
1428 lengthsDiffer = true;
1430 else
1432 if (numSrcBands != dstBands.length)
1433 lengthsDiffer = true;
1435 for (int i = 0; i < dstBands.length; i++)
1436 if (dstBands[i] > numSrcBands - 1)
1438 dstOOB = true;
1439 break;
1443 else
1445 if (dstBands == null)
1447 if (srcBands.length != numDstBands)
1448 lengthsDiffer = true;
1450 for (int i = 0; i < srcBands.length; i++)
1451 if (srcBands[i] > numDstBands - 1)
1453 srcOOB = true;
1454 break;
1457 else
1459 if (srcBands.length != dstBands.length)
1460 lengthsDiffer = true;
1462 for (int i = 0; i < srcBands.length; i++)
1463 if (srcBands[i] > numDstBands - 1)
1465 srcOOB = true;
1466 break;
1469 for (int i = 0; i < dstBands.length; i++)
1470 if (dstBands[i] > numSrcBands - 1)
1472 dstOOB = true;
1473 break;
1478 if (lengthsDiffer)
1479 throw new IllegalArgumentException ("array lengths differ");
1481 if (srcOOB)
1482 throw new IllegalArgumentException ("source band index"
1483 + " out-of-bounds");
1485 if (dstOOB)
1486 throw new IllegalArgumentException ("destination band index"
1487 + " out-of-bounds");
1491 * Calcluate the source and destination regions that will be read
1492 * from and written to, given image parameters and/or a destination
1493 * buffered image. The source region will be clipped if any of its
1494 * bounds are outside the destination region. Clipping will account
1495 * for subsampling and destination offsets. Likewise, the
1496 * destination region is clipped to the given destination image, if
1497 * it is not null, using the given image parameters, if they are not
1498 * null. IllegalArgumentException is thrown if either region will
1499 * contain 0 pixels after clipping.
1501 * @param image read parameters, or null
1502 * @param srcWidth the width of the source image
1503 * @param srcHeight the height of the source image
1504 * @param image the destination image, or null
1505 * @param srcRegion a rectangle whose values will be set to the
1506 * clipped source region
1507 * @param destRegion a rectangle whose values will be set to the
1508 * clipped destination region
1510 * @exception IllegalArgumentException if either srcRegion or
1511 * destRegion is null
1512 * @exception IllegalArgumentException if either of the calculated
1513 * regions is empty
1515 protected static void computeRegions (ImageReadParam param,
1516 int srcWidth,
1517 int srcHeight,
1518 BufferedImage image,
1519 Rectangle srcRegion,
1520 Rectangle destRegion)
1522 if (srcRegion == null || destRegion == null)
1523 throw new IllegalArgumentException ("null region");
1525 if (srcWidth == 0 || srcHeight == 0)
1526 throw new IllegalArgumentException ("zero-sized region");
1528 srcRegion = getSourceRegion(param, srcWidth, srcHeight);
1529 if (image != null)
1530 destRegion = new Rectangle (0, 0, image.getWidth(), image.getHeight());
1531 else
1532 destRegion = new Rectangle (0, 0, srcWidth, srcHeight);
1534 if (param != null)
1536 Point offset = param.getDestinationOffset();
1538 if (offset.x < 0)
1540 srcRegion.x -= offset.x;
1541 srcRegion.width += offset.x;
1543 if (offset.y < 0)
1545 srcRegion.y -= offset.y;
1546 srcRegion.height += offset.y;
1549 srcRegion.width = srcRegion.width > destRegion.width
1550 ? destRegion.width : srcRegion.width;
1551 srcRegion.height = srcRegion.height > destRegion.height
1552 ? destRegion.height : srcRegion.height;
1554 if (offset.x >= 0)
1556 destRegion.x += offset.x;
1557 destRegion.width -= offset.x;
1559 if (offset.y >= 0)
1561 destRegion.y += offset.y;
1562 destRegion.height -= offset.y;
1566 if (srcRegion.isEmpty() || destRegion.isEmpty())
1567 throw new IllegalArgumentException ("zero-sized region");
1571 * Return a suitable destination buffered image. If
1572 * param.getDestination() is non-null, then it is returned,
1573 * otherwise a buffered image is created using
1574 * param.getDestinationType() if it is non-null and also in the
1575 * given imageTypes collection, or the first element of imageTypes
1576 * otherwise.
1578 * @param param image read parameters from which a destination image
1579 * or image type is retrieved, or null
1580 * @param imageTypes a collection of legal image types
1581 * @param width the width of the source image
1582 * @param height the height of the source image
1584 * @return a suitable destination buffered image
1586 * @exception IIOException if param.getDestinationType() does not
1587 * return an image type in imageTypes
1588 * @exception IllegalArgumentException if imageTypes is null or
1589 * empty, or if a non-ImageTypeSpecifier object is retrieved from
1590 * imageTypes
1591 * @exception IllegalArgumentException if the resulting destination
1592 * region is empty
1593 * @exception IllegalArgumentException if the product of width and
1594 * height is greater than Integer.MAX_VALUE
1596 protected static BufferedImage getDestination (ImageReadParam param,
1597 Iterator imageTypes,
1598 int width,
1599 int height)
1600 throws IIOException
1602 if (imageTypes == null || !imageTypes.hasNext())
1603 throw new IllegalArgumentException ("imageTypes null or empty");
1605 if (width < 0 || height < 0)
1606 throw new IllegalArgumentException ("negative dimension");
1608 // test for overflow
1609 if (width * height < Math.min (width, height))
1610 throw new IllegalArgumentException ("width * height > Integer.MAX_VALUE");
1612 BufferedImage dest = null;
1613 ImageTypeSpecifier destType = null;
1615 if (param != null)
1617 dest = param.getDestination ();
1618 if (dest == null)
1620 ImageTypeSpecifier type = param.getDestinationType();
1621 if (type != null)
1623 Iterator it = imageTypes;
1625 while (it.hasNext())
1627 Object o = it.next ();
1628 if (! (o instanceof ImageTypeSpecifier))
1629 throw new IllegalArgumentException ("non-ImageTypeSpecifier object");
1631 ImageTypeSpecifier t = (ImageTypeSpecifier) o;
1632 if (t.equals (type))
1634 dest = t.createBufferedImage (width, height);
1635 break;
1637 if (destType == null)
1638 throw new IIOException ("invalid destination type");
1644 if (dest == null)
1646 Rectangle srcRegion = new Rectangle ();
1647 Rectangle destRegion = new Rectangle ();
1649 computeRegions (param, width, height, null, srcRegion, destRegion);
1651 if (destRegion.isEmpty())
1652 throw new IllegalArgumentException ("destination region empty");
1654 if (destType == null)
1656 Object o = imageTypes.next();
1657 if (! (o instanceof ImageTypeSpecifier))
1658 throw new IllegalArgumentException ("non-ImageTypeSpecifier"
1659 + " object");
1661 dest = ((ImageTypeSpecifier) o).createBufferedImage
1662 (destRegion.width, destRegion.height);
1664 else
1665 dest = destType.createBufferedImage
1666 (destRegion.width, destRegion.height);
1668 return dest;
1672 * Get the metadata associated with this image. If the reader is
1673 * set to ignore metadata or does not support reading metadata, or
1674 * if no metadata is available then null is returned.
1676 * This more specific version of getImageMetadata(int) can be used
1677 * to restrict metadata retrieval to specific formats and node
1678 * names, which can limit the amount of data that needs to be
1679 * processed.
1681 * @param imageIndex the frame index
1682 * @param formatName the format of metadata requested
1683 * @param nodeNames a set of Strings specifiying node names to be
1684 * retrieved
1686 * @return a metadata object, or null
1688 * @exception IllegalStateException if input has not been set
1689 * @exception IndexOutOfBoundsException if the frame index is
1690 * out-of-bounds
1691 * @exception IllegalArgumentException if formatName is null
1692 * @exception IllegalArgumentException if nodeNames is null
1693 * @exception IOException if a read error occurs
1695 public IIOMetadata getImageMetadata (int imageIndex,
1696 String formatName,
1697 Set nodeNames)
1698 throws IOException
1700 if (formatName == null || nodeNames == null)
1701 throw new IllegalArgumentException ("null argument");
1703 return getImageMetadata (imageIndex);
1707 * Get the index at which the next image will be read. If
1708 * seekForwardOnly is true then the returned value will increase
1709 * monotonically each time an image frame is read. If
1710 * seekForwardOnly is false then the returned value will always be
1711 * 0.
1713 * @return the current frame index
1715 public int getMinIndex()
1717 return minIndex;
1721 * Get the image type specifier that most closely represents the
1722 * internal data representation used by this reader. This value
1723 * should be included in the return value of getImageTypes.
1725 * @param imageIndex the frame index
1727 * @return an image type specifier
1729 * @exception IllegalStateException if input has not been set
1730 * @exception IndexOutOfBoundsException if the frame index is
1731 * out-of-bounds
1732 * @exception IOException if a read error occurs
1734 public ImageTypeSpecifier getRawImageType (int imageIndex)
1735 throws IOException
1737 return (ImageTypeSpecifier) getImageTypes(imageIndex).next();
1741 * Calculate a source region based on the given source image
1742 * dimensions and parameters. Subsampling offsets and a source
1743 * region are taken from the given image read parameters and used to
1744 * clip the given image dimensions, returning a new rectangular
1745 * region as a result.
1747 * @param param image parameters, or null
1748 * @param srcWidth the width of the source image
1749 * @param srcHeight the height of the source image
1751 * @return a clipped rectangle
1753 protected static Rectangle getSourceRegion (ImageReadParam param,
1754 int srcWidth,
1755 int srcHeight)
1757 Rectangle clippedRegion = new Rectangle (0, 0, srcWidth, srcHeight);
1759 if (param != null)
1761 Rectangle srcRegion = param.getSourceRegion();
1763 if (srcRegion != null)
1765 clippedRegion.x = srcRegion.x > clippedRegion.x
1766 ? srcRegion.x : clippedRegion.x;
1767 clippedRegion.y = srcRegion.y > clippedRegion.y
1768 ? srcRegion.y : clippedRegion.y;
1769 clippedRegion.width = srcRegion.width > clippedRegion.width
1770 ? srcRegion.width : clippedRegion.width;
1771 clippedRegion.height = srcRegion.height > clippedRegion.height
1772 ? srcRegion.height : clippedRegion.height;
1775 int xOffset = param.getSubsamplingXOffset();
1777 clippedRegion.x += xOffset;
1778 clippedRegion.width -= xOffset;
1780 int yOffset = param.getSubsamplingYOffset();
1782 clippedRegion.y += yOffset;
1783 clippedRegion.height -= yOffset;
1785 return clippedRegion;
1789 * Get the metadata associated with the image being read. If the
1790 * reader is set to ignore metadata or does not support reading
1791 * metadata, or if no metadata is available then null is returned.
1792 * This method returns metadata associated with the entirety of the
1793 * image data, whereas getStreamMetadata() returns metadata
1794 * associated with a frame within a multi-image data stream.
1796 * This more specific version of getStreamMetadata() can be used to
1797 * restrict metadata retrieval to specific formats and node names,
1798 * which can limit the amount of data that needs to be processed.
1800 * @param formatName the format of metadata requested
1801 * @param nodeNames a set of Strings specifiying node names to be
1802 * retrieved
1804 * @return metadata associated with the image being read, or null
1806 * @exception IllegalArgumentException if formatName is null
1807 * @exception IllegalArgumentException if nodeNames is null
1808 * @exception IOException if a read error occurs
1810 public IIOMetadata getStreamMetadata (String formatName,
1811 Set nodeNames)
1812 throws IOException
1814 if (formatName == null || nodeNames == null)
1815 throw new IllegalArgumentException ("null argument");
1817 return getStreamMetadata();
1821 * Read the given frame all at once, using default image read
1822 * parameters, and return a buffered image.
1824 * The returned image will be formatted according to the
1825 * currently-preferred image type specifier.
1827 * Installed read progress listeners, update progress listeners and
1828 * warning listeners will be notified of read progress, changes in
1829 * sample sets and warnings respectively.
1831 * @param the index of the image frame to read
1833 * @return a buffered image
1835 * @exception IllegalStateException if input has not been set
1836 * @exception IndexOutOfBoundsException if the frame index is
1837 * out-of-bounds
1838 * @exception IOException if a read error occurs
1840 public BufferedImage read (int imageIndex)
1841 throws IOException
1843 return read (imageIndex, null);
1847 * Read the given frame all at once, using the given image read
1848 * parameters, and return an IIOImage. The IIOImage will contain a
1849 * buffered image as returned by getDestination.
1851 * Installed read progress listeners, update progress listeners and
1852 * warning listeners will be notified of read progress, changes in
1853 * sample sets and warnings respectively.
1855 * The source and destination band settings are checked with a call
1856 * to checkReadParamBandSettings.
1858 * @param the index of the image frame to read
1859 * @param the image read parameters
1861 * @return an IIOImage
1863 * @exception IllegalStateException if input has not been set
1864 * @exception IndexOutOfBoundsException if the frame index is
1865 * out-of-bounds
1866 * @exception IllegalArgumentException if param.getSourceBands() and
1867 * param.getDestinationBands() are incompatible
1868 * @exception IllegalArgumentException if either the source or
1869 * destination image regions are empty
1870 * @exception IOException if a read error occurs
1872 public IIOImage readAll (int imageIndex,
1873 ImageReadParam param)
1874 throws IOException
1876 checkReadParamBandSettings (param,
1877 param.getSourceBands().length,
1878 param.getDestinationBands().length);
1880 List l = new ArrayList ();
1882 for (int i = 0; i < getNumThumbnails (imageIndex); i++)
1883 l.add (readThumbnail(imageIndex, i));
1885 return new IIOImage (getDestination(param, getImageTypes(imageIndex),
1886 getWidth(imageIndex),
1887 getHeight(imageIndex)),
1889 getImageMetadata (imageIndex));
1893 * Read all image frames all at once, using the given image read
1894 * parameters iterator, and return an iterator over a collection of
1895 * IIOImages. Each IIOImage in the collection will contain a
1896 * buffered image as returned by getDestination.
1898 * Installed read progress listeners, update progress listeners and
1899 * warning listeners will be notified of read progress, changes in
1900 * sample sets and warnings respectively.
1902 * Each set of source and destination band settings are checked with
1903 * a call to checkReadParamBandSettings.
1905 * @param an iterator over the image read parameters
1907 * @return an IIOImage
1909 * @exception IllegalStateException if input has not been set
1910 * @exception IllegalArgumentException if a non-ImageReadParam is
1911 * found in params
1912 * @exception IllegalArgumentException if param.getSourceBands() and
1913 * param.getDestinationBands() are incompatible
1914 * @exception IllegalArgumentException if either the source or
1915 * destination image regions are empty
1916 * @exception IOException if a read error occurs
1918 public Iterator readAll (Iterator params)
1919 throws IOException
1921 List l = new ArrayList ();
1922 int index = 0;
1924 while (params.hasNext())
1926 if (params != null && ! (params instanceof ImageReadParam))
1927 throw new IllegalArgumentException ("non-ImageReadParam found");
1929 l.add (readAll(index++, (ImageReadParam) params.next ()));
1932 return l.iterator();
1936 * Read a rendered image. This is a more general counterpart to
1937 * read (int, ImageReadParam). All image data may not be read
1938 * before this method returns and so listeners will not necessarily
1939 * be notified.
1941 * @param the index of the image frame to read
1942 * @param the image read parameters
1944 * @return a rendered image
1946 * @exception IllegalStateException if input is null
1947 * @exception IndexOutOfBoundsException if the frame index is
1948 * out-of-bounds
1949 * @exception IllegalArgumentException if param.getSourceBands() and
1950 * param.getDestinationBands() are incompatible
1951 * @exception IllegalArgumentException if either the source or
1952 * destination image regions are empty
1953 * @exception IOException if a read error occurs
1955 public RenderedImage readAsRenderedImage (int imageIndex,
1956 ImageReadParam param)
1957 throws IOException
1959 return read (imageIndex, param);
1963 * Read the given tile into a buffered image. If the tile
1964 * coordinates are out-of-bounds an exception is thrown. If the
1965 * image is not tiled then the coordinates 0, 0 are expected and the
1966 * entire image will be read.
1968 * @param imageIndex the frame index
1969 * @param tileX the horizontal tile coordinate
1970 * @param tileY the vertical tile coordinate
1972 * @return the contents of the tile as a buffered image
1974 * @exception IllegalStateException if input is null
1975 * @exception IndexOutOfBoundsException if the frame index is
1976 * out-of-bounds
1977 * @exception IllegalArgumentException if the tile coordinates are
1978 * out-of-bounds
1979 * @exception IOException if a read error occurs
1981 public BufferedImage readTile (int imageIndex, int tileX, int tileY)
1982 throws IOException
1984 if (tileX != 0 || tileY != 0)
1985 throw new IllegalArgumentException ("tileX not 0 or tileY not 0");
1987 return read (imageIndex);
1991 * Read the given tile into a raster containing the raw image data.
1992 * If the tile coordinates are out-of-bounds an exception is thrown.
1993 * If the image is not tiled then the coordinates 0, 0 are expected
1994 * and the entire image will be read.
1996 * @param imageIndex the frame index
1997 * @param tileX the horizontal tile coordinate
1998 * @param tileY the vertical tile coordinate
2000 * @return the contents of the tile as a raster
2002 * @exception UnsupportedOperationException if rasters are not
2003 * supported
2004 * @exception IllegalStateException if input is null
2005 * @exception IndexOutOfBoundsException if the frame index is
2006 * out-of-bounds
2007 * @exception IllegalArgumentException if the tile coordinates are
2008 * out-of-bounds
2009 * @exception IOException if a read error occurs
2011 public Raster readTileRaster (int imageIndex, int tileX, int tileY)
2012 throws IOException
2014 if (!canReadRaster())
2015 throw new UnsupportedOperationException ("cannot read rasters");
2017 if (tileX != 0 || tileY != 0)
2018 throw new IllegalArgumentException ("tileX not 0 or tileY not 0");
2020 return readRaster (imageIndex, null);
2024 * Reset this reader's internal state.
2026 public void reset ()
2028 setInput (null, false);
2029 setLocale (null);
2030 removeAllIIOReadUpdateListeners ();
2031 removeAllIIOReadWarningListeners ();
2032 removeAllIIOReadProgressListeners ();
2033 clearAbortRequest ();