blob: e9e5130cfabe76470ba24692e6eae64c0f64dbb5 [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 */
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080021
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070022package javax.imageio;
23
24import javax.imageio.metadata.IIOMetadata;
25import java.awt.image.RenderedImage;
26import java.awt.image.Raster;
27import java.awt.image.BufferedImage;
28import java.util.List;
29
30/**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080031 * The IIOImage class combines the image, image's thumbnail and image's
32 * metadata. The image can be presented as RenderedImage or Raster object.
33 *
34 * @since Android 1.0
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070035 */
36public class IIOImage {
37
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080038 /**
39 * The image of this IIOImage.
40 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070041 protected RenderedImage image;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080042
43 /**
44 * The raster of this IIOImage.
45 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070046 protected Raster raster;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080047
48 /**
49 * The list with thumbnails associated with the image.
50 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070051 protected List<? extends BufferedImage> thumbnails;
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080052
53 /**
54 * The metadata associated with the image.
55 */
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070056 protected IIOMetadata metadata;
57
58 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080059 * Instantiates a new IIOImage with the specified RenderedImage, list of
60 * thumbnails and metadata.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070061 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080062 * @param image
63 * the image specified by RenderedImage.
64 * @param thumbnails
65 * the list of BufferedImage objects which represent the
66 * thumbnails of the image.
67 * @param metadata
68 * the metadata of the image.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070069 */
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080070 public IIOImage(RenderedImage image, List<? extends BufferedImage> thumbnails,
71 IIOMetadata metadata) {
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070072 if (image == null) {
73 throw new IllegalArgumentException("image should not be NULL");
74 }
75 this.raster = null;
76 this.image = image;
77 this.thumbnails = thumbnails;
78 this.metadata = metadata;
79 }
80
81 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080082 * Instantiates a new IIOImage with the specified Raster, list of thumbnails
83 * and metadata.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070084 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -080085 * @param raster
86 * the Raster.
87 * @param thumbnails
88 * the list of BufferedImage objects which represent the
89 * thumbnails of Raster data.
90 * @param metadata
91 * the metadata.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070092 */
93 public IIOImage(Raster raster, List<? extends BufferedImage> thumbnails, IIOMetadata metadata) {
94 if (raster == null) {
95 throw new IllegalArgumentException("raster should not be NULL");
96 }
97 this.image = null;
98 this.raster = raster;
99 this.thumbnails = thumbnails;
100 this.metadata = metadata;
101 }
102
103 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800104 * Gets the RenderedImage object or returns null if this IIOImage object is
105 * associated with a Raster.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700106 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800107 * @return the RenderedImage object or null if this IIOImage object is
108 * associated with a Raster.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700109 */
110 public RenderedImage getRenderedImage() {
111 return image;
112 }
113
114 /**
115 * Sets the RenderedImage to this IIOImage object.
116 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800117 * @param image
118 * the RenderedImage to be set to this IIOImage.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700119 */
120 public void setRenderedImage(RenderedImage image) {
121 if (image == null) {
122 throw new IllegalArgumentException("image should not be NULL");
123 }
124 raster = null;
125 this.image = image;
126 }
127
128 /**
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800129 * Returns true if the IIOImage object associated with a Raster, or false if
130 * it's associated with a RenderedImage.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700131 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800132 * @return true, if the IIOImage object associated with a Raster, or false
133 * if it's associated with a RenderedImage.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700134 */
135 public boolean hasRaster() {
136 return raster != null;
137 }
138
139 /**
140 * Gets the Raster object or returns null if this IIOImage object is
141 * associated with a RenderedImage.
142 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800143 * @return the Raster or null if this IIOImage object is associated with a
144 * RenderedImage.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700145 */
146 public Raster getRaster() {
147 return raster;
148 }
149
150 /**
151 * Sets the Raster to the IIOImage.
152 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800153 * @param raster
154 * the new Raster to the IIOImage.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700155 */
156 public void setRaster(Raster raster) {
157 if (raster == null) {
158 throw new IllegalArgumentException("raster should not be NULL");
159 }
160 image = null;
161 this.raster = raster;
162 }
163
164 /**
165 * Gets the number of thumbnails for this IIOImage.
166 *
167 * @return the number of thumbnails for this IIOImage.
168 */
169 public int getNumThumbnails() {
170 return thumbnails != null ? thumbnails.size() : 0;
171 }
172
173 /**
174 * Gets the thumbnail with the specified index in the list.
175 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800176 * @param index
177 * the index of the thumbnail in the list.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700178 * @return the thumbnail with the specified index in the list.
179 */
180 public BufferedImage getThumbnail(int index) {
181 if (thumbnails != null) {
182 return thumbnails.get(index);
183 }
184 throw new IndexOutOfBoundsException("no thumbnails were set");
185 }
186
187 /**
188 * Gets the list of thumbnails.
189 *
190 * @return the list of thumbnails.
191 */
192 public List<? extends BufferedImage> getThumbnails() {
193 return thumbnails;
194 }
195
196 /**
197 * Sets the list of thumbnails images to this IIOImage object.
198 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800199 * @param thumbnails
200 * the list of BufferedImage which represent thumbnails.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700201 */
202 public void setThumbnails(List<? extends BufferedImage> thumbnails) {
203 this.thumbnails = thumbnails;
204 }
205
206 /**
207 * Gets the metadata of this IIOImage.
208 *
209 * @return the metadata of this IIOImage.
210 */
211 public IIOMetadata getMetadata() {
212 return metadata;
213 }
214
215 /**
216 * Sets the metadata to this IIOImage object.
217 *
The Android Open Source Projecte09fd9e2008-12-17 18:05:43 -0800218 * @param metadata
219 * the IIOMetadata, or null.
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -0700220 */
221 public void setMetadata(IIOMetadata metadata) {
222 this.metadata = metadata;
223 }
224}