45 |
|
|
46 |
import javax.imageio.metadata.IIOMetadata; |
import javax.imageio.metadata.IIOMetadata; |
47 |
|
|
48 |
|
/** |
49 |
|
* IIOImage is a container class for components of an image file that |
50 |
|
* stores image data, image metadata and thumbnails. |
51 |
|
* |
52 |
|
* The image data can be either a RenderedImage or a Raster but not |
53 |
|
* both. Image readers that produce IIOImages will always produce |
54 |
|
* BufferedImages from the RenderedImage field. Image writers that |
55 |
|
* accept IIOImages will always accept RenderedImages and may |
56 |
|
* optionally accept Rasters. |
57 |
|
* |
58 |
|
* @author Thomas Fitzsimmons (fitzsim@redhat.com) |
59 |
|
*/ |
60 |
public class IIOImage |
public class IIOImage |
61 |
{ |
{ |
62 |
|
/** |
63 |
|
* Image data as a RenderedImage. null if this IIOImage uses the |
64 |
|
* Raster representation. |
65 |
|
*/ |
66 |
protected RenderedImage image; |
protected RenderedImage image; |
67 |
|
|
68 |
|
/** |
69 |
|
* Image metadata. |
70 |
|
*/ |
71 |
protected IIOMetadata metadata; |
protected IIOMetadata metadata; |
72 |
|
|
73 |
|
/** |
74 |
|
* Image data as a Raster. null if this IIOImage uses the |
75 |
|
* RenderedImage representation. |
76 |
|
*/ |
77 |
protected Raster raster; |
protected Raster raster; |
78 |
|
|
79 |
|
/** |
80 |
|
* A list of BufferedImage thumbnails of this image. |
81 |
|
*/ |
82 |
|
// for 1.5 these lists are List<? extends BufferedImage> |
83 |
protected List thumbnails; |
protected List thumbnails; |
84 |
|
|
85 |
|
/** |
86 |
|
* Construct an IIOImage containing raster image data, thumbnails |
87 |
|
* and metadata. |
88 |
|
* |
89 |
|
* @param raster image data |
90 |
|
* @param thumbnails a list of BufferedImage thumbnails or null |
91 |
|
* @param metadata image metadata or null |
92 |
|
* |
93 |
|
* @exception IllegalArgumentException if raster is null |
94 |
|
*/ |
95 |
public IIOImage (Raster raster, List thumbnails, IIOMetadata metadata) |
public IIOImage (Raster raster, List thumbnails, IIOMetadata metadata) |
96 |
{ |
{ |
97 |
if (raster == null) |
if (raster == null) |
102 |
this.metadata = metadata; |
this.metadata = metadata; |
103 |
} |
} |
104 |
|
|
105 |
|
/** |
106 |
|
* Construct an IIOImage containing rendered image data, thumbnails |
107 |
|
* and metadata. |
108 |
|
* |
109 |
|
* @param image rendered image data |
110 |
|
* @param thumbnails a list of BufferedImage thumbnails or null |
111 |
|
* @param metadata image metadata or null |
112 |
|
* |
113 |
|
* @exception IllegalArgumentException if image is null |
114 |
|
*/ |
115 |
public IIOImage (RenderedImage image, List thumbnails, IIOMetadata metadata) |
public IIOImage (RenderedImage image, List thumbnails, IIOMetadata metadata) |
116 |
{ |
{ |
117 |
if (image == null) |
if (image == null) |
122 |
this.metadata = metadata; |
this.metadata = metadata; |
123 |
} |
} |
124 |
|
|
125 |
|
/** |
126 |
|
* Retrieve the image metadata or null if there is no metadata |
127 |
|
* associated with this IIOImage. |
128 |
|
* |
129 |
|
* @return image metadata or null |
130 |
|
*/ |
131 |
public IIOMetadata getMetadata() |
public IIOMetadata getMetadata() |
132 |
{ |
{ |
133 |
return metadata; |
return metadata; |
134 |
} |
} |
135 |
|
|
136 |
|
/** |
137 |
|
* Retrieve the number of thumbnails in this IIOImage. |
138 |
|
* |
139 |
|
* @return the number of thumbnails |
140 |
|
*/ |
141 |
public int getNumThumbnails() |
public int getNumThumbnails() |
142 |
{ |
{ |
143 |
return thumbnails.size(); |
return thumbnails == null ? 0 : thumbnails.size(); |
144 |
} |
} |
145 |
|
|
146 |
|
/** |
147 |
|
* Retrieve the raster image data stored in this IIOImage or null if |
148 |
|
* this image stores data using the RenderedImage representation. |
149 |
|
* |
150 |
|
* @return the raster image data or null |
151 |
|
*/ |
152 |
public Raster getRaster() |
public Raster getRaster() |
153 |
{ |
{ |
154 |
return raster; |
return raster; |
155 |
} |
} |
156 |
|
|
157 |
|
/** |
158 |
|
* Retrieve the rendered image data stored in this IIOImage or null |
159 |
|
* if this image stores data using the Raster representation. |
160 |
|
* |
161 |
|
* @return the rendered image data or null |
162 |
|
*/ |
163 |
public RenderedImage getRenderedImage() |
public RenderedImage getRenderedImage() |
164 |
{ |
{ |
165 |
return image; |
return image; |
166 |
} |
} |
167 |
|
|
168 |
|
/** |
169 |
|
* Retrieve the thumbnail stored at the specified index in the |
170 |
|
* thumbnails list. |
171 |
|
* |
172 |
|
* @param index the index of the thumbnail to retrieve |
173 |
|
* |
174 |
|
* @return the buffered image thumbnail |
175 |
|
* |
176 |
|
* @exception IndexOutOfBoundsException if index is out-of-bounds |
177 |
|
* @exception ClassCastException if the object returned from the |
178 |
|
* thumbnails list is not a BufferedImage |
179 |
|
*/ |
180 |
public BufferedImage getThumbnail (int index) |
public BufferedImage getThumbnail (int index) |
181 |
{ |
{ |
182 |
|
// This throws a ClassCastException if the returned object is not |
183 |
|
// a BufferedImage or an IndexOutOfBoundsException if index is |
184 |
|
// out-of-bounds. |
185 |
return (BufferedImage) thumbnails.get (index); |
return (BufferedImage) thumbnails.get (index); |
186 |
} |
} |
187 |
|
|
188 |
|
/** |
189 |
|
* Retrieve the list of thumbnails or null if there are no |
190 |
|
* thumbnails associated with this IIOImage. The returned reference |
191 |
|
* can be used to update the thumbnails list. |
192 |
|
* |
193 |
|
* @return a list of thumbnails or null |
194 |
|
*/ |
195 |
public List getThumbnails() |
public List getThumbnails() |
196 |
{ |
{ |
197 |
return thumbnails; |
return thumbnails; |
198 |
} |
} |
199 |
|
|
200 |
|
/** |
201 |
|
* Check whether this IIOImage stores its image data as a Raster or |
202 |
|
* as a RenderedImage. |
203 |
|
* |
204 |
|
* @return true if this IIOImage uses the Raster representation, |
205 |
|
* false if it uses the RenderedImage representation. |
206 |
|
*/ |
207 |
public boolean hasRaster() |
public boolean hasRaster() |
208 |
{ |
{ |
209 |
return raster != null; |
return raster != null; |
210 |
} |
} |
211 |
|
|
212 |
|
/** |
213 |
|
* Set this IIOImage's metadata. |
214 |
|
* |
215 |
|
* @param metadata the image metadata |
216 |
|
*/ |
217 |
public void setMetadata (IIOMetadata metadata) |
public void setMetadata (IIOMetadata metadata) |
218 |
{ |
{ |
219 |
this.metadata = metadata; |
this.metadata = metadata; |
220 |
} |
} |
221 |
|
|
222 |
|
/** |
223 |
|
* Set the raster data for this image. This disposes of any |
224 |
|
* existing rendered image data stored in this IIOImage. |
225 |
|
* |
226 |
|
* @param raster the image raster data |
227 |
|
* |
228 |
|
* @exception IllegalArgumentException if raster is null |
229 |
|
*/ |
230 |
public void setRaster (Raster raster) |
public void setRaster (Raster raster) |
231 |
{ |
{ |
232 |
if (raster == null) |
if (raster == null) |
236 |
this.raster = raster; |
this.raster = raster; |
237 |
} |
} |
238 |
|
|
239 |
|
/** |
240 |
|
* Set the rendered image data for this image. This disposes of any |
241 |
|
* existing raster data stored in this IIOImage. |
242 |
|
* |
243 |
|
* @param image the rendered image data |
244 |
|
* |
245 |
|
* @exception IllegalArgumentException if image is null |
246 |
|
*/ |
247 |
public void setRenderedImage (RenderedImage image) |
public void setRenderedImage (RenderedImage image) |
248 |
{ |
{ |
249 |
if (image == null) |
if (image == null) |
253 |
this.raster = null; |
this.raster = null; |
254 |
} |
} |
255 |
|
|
256 |
|
/** |
257 |
|
* Set the list of thumbnails for this IIOImage to a new list of |
258 |
|
* BufferedImages or to null. Any existing thumbnails list is |
259 |
|
* disposed. |
260 |
|
* |
261 |
|
* @param thumbnails a new list of thumbnails or null |
262 |
|
*/ |
263 |
public void setThumbnails (List thumbnails) |
public void setThumbnails (List thumbnails) |
264 |
{ |
{ |
265 |
this.thumbnails = thumbnails; |
this.thumbnails = thumbnails; |
266 |
} |
} |
267 |
|
} |
|
} // class IIOParam |
|