blob: e17a9fc07cfc46d9f003705bfd8d463e0ad56a7e [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @author Rustem V. Rafikov
19 * @version $Revision: 1.3 $
20 */
21package javax.imageio;
22
23import javax.imageio.metadata.IIOMetadata;
24import java.awt.image.RenderedImage;
25import java.awt.image.Raster;
26import java.awt.image.BufferedImage;
27import java.util.List;
28
29/**
30 * The IIOImage class combines the image, image's thumbnail and image's metadata.
31 * The image can be presented as RenderedImage or Raster object.
32 */
33public class IIOImage {
34
35 /** The image of this IIOImage. */
36 protected RenderedImage image;
37
38 /** The raster of this IIOImage. */
39 protected Raster raster;
40
41 /** The list with thumbnails associated with the image. */
42 protected List<? extends BufferedImage> thumbnails;
43
44 /** The metadata associated with the image. */
45 protected IIOMetadata metadata;
46
47 /**
48 * Instantiates a new IIOImage with the specified RenderedImage,
49 * list of thumbnails and metadata.
50 *
51 * @param image the image specified by RenderedImage.
52 * @param thumbnails the list of BufferedImage objects which
53 * represent the thumbnails of the image.
54 * @param metadata the metadata of the image.
55 */
56 public IIOImage(RenderedImage image, List<? extends BufferedImage> thumbnails, IIOMetadata metadata) {
57 if (image == null) {
58 throw new IllegalArgumentException("image should not be NULL");
59 }
60 this.raster = null;
61 this.image = image;
62 this.thumbnails = thumbnails;
63 this.metadata = metadata;
64 }
65
66 /**
67 * Instantiates a new IIOImage with the specified Raster, list of
68 * thumbnails and metadata.
69 *
70 * @param raster the Raster.
71 * @param thumbnails the list of BufferedImage objects which
72 * represent the thumbnails of Raster data.
73 * @param metadata the metadata.
74 */
75 public IIOImage(Raster raster, List<? extends BufferedImage> thumbnails, IIOMetadata metadata) {
76 if (raster == null) {
77 throw new IllegalArgumentException("raster should not be NULL");
78 }
79 this.image = null;
80 this.raster = raster;
81 this.thumbnails = thumbnails;
82 this.metadata = metadata;
83 }
84
85 /**
86 * Gets the RenderedImage object or returns null if this IIOImage
87 * object is associated with a Raster.
88 *
89 * @return the RenderedImage object or null if this IIOImage
90 * object is associated with a Raster.
91 */
92 public RenderedImage getRenderedImage() {
93 return image;
94 }
95
96 /**
97 * Sets the RenderedImage to this IIOImage object.
98 *
99 * @param image the RenderedImage to be set to this IIOImage.
100 */
101 public void setRenderedImage(RenderedImage image) {
102 if (image == null) {
103 throw new IllegalArgumentException("image should not be NULL");
104 }
105 raster = null;
106 this.image = image;
107 }
108
109 /**
110 * Returns true if the IIOImage object associated with a Raster, or
111 * false if it's associated with a RenderedImage.
112 *
113 * @return true if the IIOImage object associated with a Raster, or
114 * false if it's associated with a RenderedImage.
115 */
116 public boolean hasRaster() {
117 return raster != null;
118 }
119
120 /**
121 * Gets the Raster object or returns null if this IIOImage object is
122 * associated with a RenderedImage.
123 *
124 * @return the Raster or null if this IIOImage object
125 * is associated with a RenderedImage.
126 */
127 public Raster getRaster() {
128 return raster;
129 }
130
131 /**
132 * Sets the Raster to the IIOImage.
133 *
134 * @param raster the new Raster to the IIOImage.
135 */
136 public void setRaster(Raster raster) {
137 if (raster == null) {
138 throw new IllegalArgumentException("raster should not be NULL");
139 }
140 image = null;
141 this.raster = raster;
142 }
143
144 /**
145 * Gets the number of thumbnails for this IIOImage.
146 *
147 * @return the number of thumbnails for this IIOImage.
148 */
149 public int getNumThumbnails() {
150 return thumbnails != null ? thumbnails.size() : 0;
151 }
152
153 /**
154 * Gets the thumbnail with the specified index in the list.
155 *
156 * @param index the index of the thumbnail in the list.
157 *
158 * @return the thumbnail with the specified index in the list.
159 */
160 public BufferedImage getThumbnail(int index) {
161 if (thumbnails != null) {
162 return thumbnails.get(index);
163 }
164 throw new IndexOutOfBoundsException("no thumbnails were set");
165 }
166
167 /**
168 * Gets the list of thumbnails.
169 *
170 * @return the list of thumbnails.
171 */
172 public List<? extends BufferedImage> getThumbnails() {
173 return thumbnails;
174 }
175
176 /**
177 * Sets the list of thumbnails images to this IIOImage object.
178 *
179 * @param thumbnails the list of BufferedImage which represent
180 * thumbnails.
181 */
182 public void setThumbnails(List<? extends BufferedImage> thumbnails) {
183 this.thumbnails = thumbnails;
184 }
185
186 /**
187 * Gets the metadata of this IIOImage.
188 *
189 * @return the metadata of this IIOImage.
190 */
191 public IIOMetadata getMetadata() {
192 return metadata;
193 }
194
195 /**
196 * Sets the metadata to this IIOImage object.
197 *
198 * @param metadata the IIOMetadata, or null.
199 */
200 public void setMetadata(IIOMetadata metadata) {
201 this.metadata = metadata;
202 }
203}