• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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  */
21 
22 package javax.imageio;
23 
24 import javax.imageio.metadata.IIOMetadata;
25 import java.awt.image.RenderedImage;
26 import java.awt.image.Raster;
27 import java.awt.image.BufferedImage;
28 import java.util.List;
29 
30 /**
31  * 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
35  */
36 public class IIOImage {
37 
38     /**
39      * The image of this IIOImage.
40      */
41     protected RenderedImage image;
42 
43     /**
44      * The raster of this IIOImage.
45      */
46     protected Raster raster;
47 
48     /**
49      * The list with thumbnails associated with the image.
50      */
51     protected List<? extends BufferedImage> thumbnails;
52 
53     /**
54      * The metadata associated with the image.
55      */
56     protected IIOMetadata metadata;
57 
58     /**
59      * Instantiates a new IIOImage with the specified RenderedImage, list of
60      * thumbnails and metadata.
61      *
62      * @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.
69      */
IIOImage(RenderedImage image, List<? extends BufferedImage> thumbnails, IIOMetadata metadata)70     public IIOImage(RenderedImage image, List<? extends BufferedImage> thumbnails,
71             IIOMetadata metadata) {
72         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     /**
82      * Instantiates a new IIOImage with the specified Raster, list of thumbnails
83      * and metadata.
84      *
85      * @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.
92      */
IIOImage(Raster raster, List<? extends BufferedImage> thumbnails, IIOMetadata metadata)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     /**
104      * Gets the RenderedImage object or returns null if this IIOImage object is
105      * associated with a Raster.
106      *
107      * @return the RenderedImage object or null if this IIOImage object is
108      *         associated with a Raster.
109      */
getRenderedImage()110     public RenderedImage getRenderedImage() {
111         return image;
112     }
113 
114     /**
115      * Sets the RenderedImage to this IIOImage object.
116      *
117      * @param image
118      *            the RenderedImage to be set to this IIOImage.
119      */
setRenderedImage(RenderedImage image)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     /**
129      * Returns true if the IIOImage object associated with a Raster, or false if
130      * it's associated with a RenderedImage.
131      *
132      * @return true, if the IIOImage object associated with a Raster, or false
133      *         if it's associated with a RenderedImage.
134      */
hasRaster()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      *
143      * @return the Raster or null if this IIOImage object is associated with a
144      *         RenderedImage.
145      */
getRaster()146     public Raster getRaster() {
147         return raster;
148     }
149 
150     /**
151      * Sets the Raster to the IIOImage.
152      *
153      * @param raster
154      *            the new Raster to the IIOImage.
155      */
setRaster(Raster raster)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      */
getNumThumbnails()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      *
176      * @param index
177      *            the index of the thumbnail in the list.
178      * @return the thumbnail with the specified index in the list.
179      */
getThumbnail(int index)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      */
getThumbnails()192     public List<? extends BufferedImage> getThumbnails() {
193         return thumbnails;
194     }
195 
196     /**
197      * Sets the list of thumbnails images to this IIOImage object.
198      *
199      * @param thumbnails
200      *            the list of BufferedImage which represent thumbnails.
201      */
setThumbnails(List<? extends BufferedImage> thumbnails)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      */
getMetadata()211     public IIOMetadata getMetadata() {
212         return metadata;
213     }
214 
215     /**
216      * Sets the metadata to this IIOImage object.
217      *
218      * @param metadata
219      *            the IIOMetadata, or null.
220      */
setMetadata(IIOMetadata metadata)221     public void setMetadata(IIOMetadata metadata) {
222         this.metadata = metadata;
223     }
224 }
225