0N/A/*
2362N/A * Copyright (c) 2000, 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.image.BufferedImage;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.RenderedImage;
0N/Aimport java.util.List;
0N/Aimport javax.imageio.metadata.IIOMetadata;
0N/A
0N/A/**
0N/A * A simple container class to aggregate an image, a set of
0N/A * thumbnail (preview) images, and an object representing metadata
0N/A * associated with the image.
0N/A *
0N/A * <p> The image data may take the form of either a
0N/A * <code>RenderedImage</code>, or a <code>Raster</code>. Reader
0N/A * methods that return an <code>IIOImage</code> will always return a
0N/A * <code>BufferedImage</code> using the <code>RenderedImage</code>
0N/A * reference. Writer methods that accept an <code>IIOImage</code>
0N/A * will always accept a <code>RenderedImage</code>, and may optionally
0N/A * accept a <code>Raster</code>.
0N/A *
0N/A * <p> Exactly one of <code>getRenderedImage</code> and
0N/A * <code>getRaster</code> will return a non-<code>null</code> value.
0N/A * Subclasses are responsible for ensuring this behavior.
0N/A *
0N/A * @see ImageReader#readAll(int, ImageReadParam)
0N/A * @see ImageReader#readAll(java.util.Iterator)
0N/A * @see ImageWriter#write(javax.imageio.metadata.IIOMetadata,
0N/A * IIOImage, ImageWriteParam)
0N/A * @see ImageWriter#write(IIOImage)
0N/A * @see ImageWriter#writeToSequence(IIOImage, ImageWriteParam)
0N/A * @see ImageWriter#writeInsert(int, IIOImage, ImageWriteParam)
0N/A *
0N/A */
0N/Apublic class IIOImage {
0N/A
0N/A /**
0N/A * The <code>RenderedImage</code> being referenced.
0N/A */
0N/A protected RenderedImage image;
0N/A
0N/A /**
0N/A * The <code>Raster</code> being referenced.
0N/A */
0N/A protected Raster raster;
0N/A
0N/A /**
0N/A * A <code>List</code> of <code>BufferedImage</code> thumbnails,
0N/A * or <code>null</code>. Non-<code>BufferedImage</code> objects
0N/A * must not be stored in this <code>List</code>.
0N/A */
0N/A protected List<? extends BufferedImage> thumbnails = null;
0N/A
0N/A /**
0N/A * An <code>IIOMetadata</code> object containing metadata
0N/A * associated with the image.
0N/A */
0N/A protected IIOMetadata metadata;
0N/A
0N/A /**
0N/A * Constructs an <code>IIOImage</code> containing a
0N/A * <code>RenderedImage</code>, and thumbnails and metadata
0N/A * associated with it.
0N/A *
0N/A * <p> All parameters are stored by reference.
0N/A *
0N/A * <p> The <code>thumbnails</code> argument must either be
0N/A * <code>null</code> or contain only <code>BufferedImage</code>
0N/A * objects.
0N/A *
0N/A * @param image a <code>RenderedImage</code>.
0N/A * @param thumbnails a <code>List</code> of <code>BufferedImage</code>s,
0N/A * or <code>null</code>.
0N/A * @param metadata an <code>IIOMetadata</code> object, or
0N/A * <code>null</code>.
0N/A *
0N/A * @exception IllegalArgumentException if <code>image</code> is
0N/A * <code>null</code>.
0N/A */
0N/A public IIOImage(RenderedImage image,
0N/A List<? extends BufferedImage> thumbnails,
0N/A IIOMetadata metadata) {
0N/A if (image == null) {
0N/A throw new IllegalArgumentException("image == null!");
0N/A }
0N/A this.image = image;
0N/A this.raster = null;
0N/A this.thumbnails = thumbnails;
0N/A this.metadata = metadata;
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <code>IIOImage</code> containing a
0N/A * <code>Raster</code>, and thumbnails and metadata
0N/A * associated with it.
0N/A *
0N/A * <p> All parameters are stored by reference.
0N/A *
0N/A * @param raster a <code>Raster</code>.
0N/A * @param thumbnails a <code>List</code> of <code>BufferedImage</code>s,
0N/A * or <code>null</code>.
0N/A * @param metadata an <code>IIOMetadata</code> object, or
0N/A * <code>null</code>.
0N/A *
0N/A * @exception IllegalArgumentException if <code>raster</code> is
0N/A * <code>null</code>.
0N/A */
0N/A public IIOImage(Raster raster,
0N/A List<? extends BufferedImage> thumbnails,
0N/A IIOMetadata metadata) {
0N/A if (raster == null) {
0N/A throw new IllegalArgumentException("raster == null!");
0N/A }
0N/A this.raster = raster;
0N/A this.image = null;
0N/A this.thumbnails = thumbnails;
0N/A this.metadata = metadata;
0N/A }
0N/A
0N/A /**
0N/A * Returns the currently set <code>RenderedImage</code>, or
0N/A * <code>null</code> if only a <code>Raster</code> is available.
0N/A *
0N/A * @return a <code>RenderedImage</code>, or <code>null</code>.
0N/A *
0N/A * @see #setRenderedImage
0N/A */
0N/A public RenderedImage getRenderedImage() {
0N/A synchronized(this) {
0N/A return image;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the current <code>RenderedImage</code>. The value is
0N/A * stored by reference. Any existing <code>Raster</code> is
0N/A * discarded.
0N/A *
0N/A * @param image a <code>RenderedImage</code>.
0N/A *
0N/A * @exception IllegalArgumentException if <code>image</code> is
0N/A * <code>null</code>.
0N/A *
0N/A * @see #getRenderedImage
0N/A */
0N/A public void setRenderedImage(RenderedImage image) {
0N/A synchronized(this) {
0N/A if (image == null) {
0N/A throw new IllegalArgumentException("image == null!");
0N/A }
0N/A this.image = image;
0N/A this.raster = null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if this <code>IIOImage</code> stores
0N/A * a <code>Raster</code> rather than a <code>RenderedImage</code>.
0N/A *
0N/A * @return <code>true</code> if a <code>Raster</code> is
0N/A * available.
0N/A */
0N/A public boolean hasRaster() {
0N/A synchronized(this) {
0N/A return (raster != null);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the currently set <code>Raster</code>, or
0N/A * <code>null</code> if only a <code>RenderedImage</code> is
0N/A * available.
0N/A *
0N/A * @return a <code>Raster</code>, or <code>null</code>.
0N/A *
0N/A * @see #setRaster
0N/A */
0N/A public Raster getRaster() {
0N/A synchronized(this) {
0N/A return raster;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the current <code>Raster</code>. The value is
0N/A * stored by reference. Any existing <code>RenderedImage</code> is
0N/A * discarded.
0N/A *
0N/A * @param raster a <code>Raster</code>.
0N/A *
0N/A * @exception IllegalArgumentException if <code>raster</code> is
0N/A * <code>null</code>.
0N/A *
0N/A * @see #getRaster
0N/A */
0N/A public void setRaster(Raster raster) {
0N/A synchronized(this) {
0N/A if (raster == null) {
0N/A throw new IllegalArgumentException("raster == null!");
0N/A }
0N/A this.raster = raster;
0N/A this.image = null;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of thumbnails stored in this
0N/A * <code>IIOImage</code>.
0N/A *
0N/A * @return the number of thumbnails, as an <code>int</code>.
0N/A */
0N/A public int getNumThumbnails() {
0N/A return thumbnails == null ? 0 : thumbnails.size();
0N/A }
0N/A
0N/A /**
0N/A * Returns a thumbnail associated with the main image.
0N/A *
0N/A * @param index the index of the desired thumbnail image.
0N/A *
0N/A * @return a thumbnail image, as a <code>BufferedImage</code>.
0N/A *
0N/A * @exception IndexOutOfBoundsException if the supplied index is
0N/A * negative or larger than the largest valid index.
0N/A * @exception ClassCastException if a
0N/A * non-<code>BufferedImage</code> object is encountered in the
0N/A * list of thumbnails at the given index.
0N/A *
0N/A * @see #getThumbnails
0N/A * @see #setThumbnails
0N/A */
0N/A public BufferedImage getThumbnail(int index) {
0N/A if (thumbnails == null) {
0N/A throw new IndexOutOfBoundsException("No thumbnails available!");
0N/A }
0N/A return (BufferedImage)thumbnails.get(index);
0N/A }
0N/A
0N/A /**
0N/A * Returns the current <code>List</code> of thumbnail
0N/A * <code>BufferedImage</code>s, or <code>null</code> if none is
0N/A * set. A live reference is returned.
0N/A *
0N/A * @return the current <code>List</code> of
0N/A * <code>BufferedImage</code> thumbnails, or <code>null</code>.
0N/A *
0N/A * @see #getThumbnail(int)
0N/A * @see #setThumbnails
0N/A */
0N/A public List<? extends BufferedImage> getThumbnails() {
0N/A return thumbnails;
0N/A }
0N/A
0N/A /**
0N/A * Sets the list of thumbnails to a new <code>List</code> of
0N/A * <code>BufferedImage</code>s, or to <code>null</code>. The
0N/A * reference to the previous <code>List</code> is discarded.
0N/A *
0N/A * <p> The <code>thumbnails</code> argument must either be
0N/A * <code>null</code> or contain only <code>BufferedImage</code>
0N/A * objects.
0N/A *
0N/A * @param thumbnails a <code>List</code> of
0N/A * <code>BufferedImage</code> thumbnails, or <code>null</code>.
0N/A *
0N/A * @see #getThumbnail(int)
0N/A * @see #getThumbnails
0N/A */
0N/A public void setThumbnails(List<? extends BufferedImage> thumbnails) {
0N/A this.thumbnails = thumbnails;
0N/A }
0N/A
0N/A /**
0N/A * Returns a reference to the current <code>IIOMetadata</code>
0N/A * object, or <code>null</code> is none is set.
0N/A *
0N/A * @return an <code>IIOMetadata</code> object, or <code>null</code>.
0N/A *
0N/A * @see #setMetadata
0N/A */
0N/A public IIOMetadata getMetadata() {
0N/A return metadata;
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>IIOMetadata</code> to a new object, or
0N/A * <code>null</code>.
0N/A *
0N/A * @param metadata an <code>IIOMetadata</code> object, or
0N/A * <code>null</code>.
0N/A *
0N/A * @see #getMetadata
0N/A */
0N/A public void setMetadata(IIOMetadata metadata) {
0N/A this.metadata = metadata;
0N/A }
0N/A}