1 |
/* ImageReader.java -- Decodes raster images. |
/* ImageReader.java -- Decodes raster images. |
2 |
Copyright (C) 2004 Free Software Foundation, Inc. |
Copyright (C) 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
38 |
|
|
39 |
package javax.imageio; |
package javax.imageio; |
40 |
|
|
41 |
|
import java.awt.image.BufferedImage; |
42 |
|
import java.awt.image.Raster; |
43 |
|
import java.io.IOException; |
44 |
|
import java.util.ArrayList; |
45 |
|
import java.util.Iterator; |
46 |
|
import java.util.List; |
47 |
|
import java.util.Locale; |
48 |
|
|
49 |
|
import javax.imageio.event.IIOReadProgressListener; |
50 |
|
import javax.imageio.event.IIOReadUpdateListener; |
51 |
|
import javax.imageio.event.IIOReadWarningListener; |
52 |
|
import javax.imageio.metadata.IIOMetadata; |
53 |
|
import javax.imageio.spi.ImageReaderSpi; |
54 |
|
|
55 |
public abstract class ImageReader |
public abstract class ImageReader |
56 |
{ |
{ |
57 |
// FIXME: Incomplete. This class is merely present in order to allow |
protected Locale[] availableLocales; |
58 |
// compilation of the javax.imageio.spi package, for which GNU |
protected boolean ignoreMetadata; |
59 |
// Classpath does provide an implementation. |
protected Object input; |
60 |
|
protected Locale locale; |
61 |
|
protected int minIndex; |
62 |
|
protected ImageReaderSpi originatingProvider; |
63 |
|
protected List progressListeners; |
64 |
|
protected boolean seekForwardOnly; |
65 |
|
protected List updateListeners = new ArrayList(); |
66 |
|
protected List warningListeners = new ArrayList(); |
67 |
|
protected List warningLocales = new ArrayList(); |
68 |
|
|
69 |
|
protected ImageReader(ImageReaderSpi originatingProvider) |
70 |
|
{ |
71 |
|
this.originatingProvider = originatingProvider; |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
|
public void addIIOReadProgressListener(IIOReadProgressListener listener) |
76 |
|
{ |
77 |
|
if (listener == null) |
78 |
|
return; |
79 |
|
|
80 |
|
progressListeners.add(listener); |
81 |
|
} |
82 |
|
|
83 |
|
public void addIIOReadUpdateListener(IIOReadUpdateListener listener) |
84 |
|
{ |
85 |
|
if (listener == null) |
86 |
|
return; |
87 |
|
|
88 |
|
updateListeners.add(listener); |
89 |
|
} |
90 |
|
|
91 |
|
public void addIIOReadWarningListener(IIOReadWarningListener listener) |
92 |
|
{ |
93 |
|
if (listener == null) |
94 |
|
return; |
95 |
|
|
96 |
|
warningListeners.add(listener); |
97 |
|
} |
98 |
|
|
99 |
|
public boolean canReadRaster() |
100 |
|
{ |
101 |
|
return false; |
102 |
|
} |
103 |
|
|
104 |
|
public void dispose() |
105 |
|
{ |
106 |
|
// The default implementation does nothing. |
107 |
|
} |
108 |
|
|
109 |
|
public float getAspectRatio(int imageIndex) |
110 |
|
throws IOException |
111 |
|
{ |
112 |
|
return (float) (getWidth(imageIndex) / getHeight(imageIndex)); |
113 |
|
} |
114 |
|
|
115 |
|
public Locale[] getAvailableLocales() |
116 |
|
{ |
117 |
|
if (availableLocales == null) |
118 |
|
return null; |
119 |
|
|
120 |
|
return (Locale[]) availableLocales.clone(); |
121 |
|
} |
122 |
|
|
123 |
|
public ImageReadParam getDefaultReadParam() |
124 |
|
{ |
125 |
|
return new ImageReadParam(); |
126 |
|
} |
127 |
|
|
128 |
|
public String getFormatName() |
129 |
|
throws IOException |
130 |
|
{ |
131 |
|
return originatingProvider.getFormatNames()[0]; |
132 |
|
} |
133 |
|
|
134 |
|
public abstract int getHeight(int imageIndex) |
135 |
|
throws IOException; |
136 |
|
|
137 |
|
public abstract IIOMetadata getImageMetadata(int imageIndex) |
138 |
|
throws IOException; |
139 |
|
|
140 |
|
public abstract Iterator getImageTypes(int imageIndex) |
141 |
|
throws IOException; |
142 |
|
|
143 |
|
public Object getInput() |
144 |
|
{ |
145 |
|
return input; |
146 |
|
} |
147 |
|
|
148 |
|
public Locale getLocale() |
149 |
|
{ |
150 |
|
return locale; |
151 |
|
} |
152 |
|
|
153 |
|
public abstract int getNumImages(boolean allowSearch) |
154 |
|
throws IOException; |
155 |
|
|
156 |
|
public int getNumThumbnails(int imageIndex) |
157 |
|
throws IOException |
158 |
|
{ |
159 |
|
return 0; |
160 |
|
} |
161 |
|
|
162 |
|
public ImageReaderSpi getOriginatingProvider() |
163 |
|
{ |
164 |
|
return originatingProvider; |
165 |
|
} |
166 |
|
|
167 |
|
public abstract IIOMetadata getStreamMetadata() |
168 |
|
throws IOException; |
169 |
|
|
170 |
|
public int getTileGridXOffset(int imageIndex) |
171 |
|
throws IOException |
172 |
|
{ |
173 |
|
return 0; |
174 |
|
} |
175 |
|
|
176 |
|
public int getTileGridYOffset(int imageIndex) |
177 |
|
throws IOException |
178 |
|
{ |
179 |
|
return 0; |
180 |
|
} |
181 |
|
|
182 |
|
public int getTileHeight(int imageIndex) |
183 |
|
throws IOException |
184 |
|
{ |
185 |
|
return getHeight(imageIndex); |
186 |
|
} |
187 |
|
|
188 |
|
public int getTileWidth(int imageIndex) |
189 |
|
throws IOException |
190 |
|
{ |
191 |
|
return getWidth(imageIndex); |
192 |
|
} |
193 |
|
|
194 |
|
public abstract int getWidth(int imageIndex) |
195 |
|
throws IOException; |
196 |
|
|
197 |
|
public boolean hasThumbnails(int imageIndex) |
198 |
|
throws IOException |
199 |
|
{ |
200 |
|
return getNumThumbnails(imageIndex) > 0; |
201 |
|
} |
202 |
|
|
203 |
|
public boolean isIgnoringMetadata() |
204 |
|
{ |
205 |
|
return ignoreMetadata; |
206 |
|
} |
207 |
|
|
208 |
|
public boolean isImageTiled(int imageIndex) |
209 |
|
throws IOException |
210 |
|
{ |
211 |
|
return false; |
212 |
|
} |
213 |
|
|
214 |
|
public boolean isRandomAccessEasy(int imageIndex) |
215 |
|
throws IOException |
216 |
|
{ |
217 |
|
return false; |
218 |
|
} |
219 |
|
|
220 |
|
public boolean isSeekForwardOnly() |
221 |
|
{ |
222 |
|
return seekForwardOnly; |
223 |
|
} |
224 |
|
|
225 |
|
protected void processImageComplete() |
226 |
|
{ |
227 |
|
Iterator it = progressListeners.iterator(); |
228 |
|
|
229 |
|
while (it.hasNext()) |
230 |
|
{ |
231 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
232 |
|
listener.imageComplete (this); |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
|
protected void processImageProgress(float percentageDone) |
237 |
|
{ |
238 |
|
Iterator it = progressListeners.iterator(); |
239 |
|
|
240 |
|
while (it.hasNext()) |
241 |
|
{ |
242 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
243 |
|
listener.imageProgress(this, percentageDone); |
244 |
|
} |
245 |
|
} |
246 |
|
|
247 |
|
protected void processImageStarted(int imageIndex) |
248 |
|
{ |
249 |
|
Iterator it = progressListeners.iterator(); |
250 |
|
|
251 |
|
while (it.hasNext()) |
252 |
|
{ |
253 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
254 |
|
listener.imageStarted(this, imageIndex); |
255 |
|
} |
256 |
|
} |
257 |
|
|
258 |
|
protected void processImageUpdate(BufferedImage image, int minX, int minY, |
259 |
|
int width, int height, int periodX, |
260 |
|
int periodY, int[] bands) |
261 |
|
{ |
262 |
|
Iterator it = updateListeners.iterator(); |
263 |
|
|
264 |
|
while (it.hasNext()) |
265 |
|
{ |
266 |
|
IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next(); |
267 |
|
listener.imageUpdate(this, image, minX, minY, width, height, periodX, |
268 |
|
periodY, bands); |
269 |
|
} |
270 |
|
} |
271 |
|
|
272 |
|
protected void processPassComplete(BufferedImage image) |
273 |
|
{ |
274 |
|
Iterator it = updateListeners.iterator(); |
275 |
|
|
276 |
|
while (it.hasNext()) |
277 |
|
{ |
278 |
|
IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next(); |
279 |
|
listener.passComplete(this, image); |
280 |
|
} |
281 |
|
} |
282 |
|
|
283 |
|
protected void processPassStarted(BufferedImage image, int pass, int minPass, |
284 |
|
int maxPass, int minX, int minY, |
285 |
|
int periodX, int periodY, int[] bands) |
286 |
|
{ |
287 |
|
Iterator it = updateListeners.iterator(); |
288 |
|
|
289 |
|
while (it.hasNext()) |
290 |
|
{ |
291 |
|
IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next(); |
292 |
|
listener.passStarted(this, image, pass, minPass, maxPass, minX, minY, |
293 |
|
periodX, periodY, bands); |
294 |
|
} |
295 |
|
} |
296 |
|
|
297 |
|
protected void processReadAborted() |
298 |
|
{ |
299 |
|
Iterator it = progressListeners.iterator(); |
300 |
|
|
301 |
|
while (it.hasNext()) |
302 |
|
{ |
303 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
304 |
|
listener.readAborted(this); |
305 |
|
} |
306 |
|
} |
307 |
|
|
308 |
|
protected void processSequenceComplete() |
309 |
|
{ |
310 |
|
Iterator it = progressListeners.iterator(); |
311 |
|
|
312 |
|
while (it.hasNext()) |
313 |
|
{ |
314 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
315 |
|
listener.sequenceComplete(this); |
316 |
|
} |
317 |
|
} |
318 |
|
|
319 |
|
protected void processSequenceStarted(int minIndex) |
320 |
|
{ |
321 |
|
Iterator it = progressListeners.iterator(); |
322 |
|
|
323 |
|
while (it.hasNext()) |
324 |
|
{ |
325 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
326 |
|
listener.sequenceStarted(this, minIndex); |
327 |
|
} |
328 |
|
} |
329 |
|
|
330 |
|
protected void processThumbnailComplete() |
331 |
|
{ |
332 |
|
Iterator it = progressListeners.iterator(); |
333 |
|
|
334 |
|
while (it.hasNext()) |
335 |
|
{ |
336 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
337 |
|
listener.thumbnailComplete(this); |
338 |
|
} |
339 |
|
} |
340 |
|
|
341 |
|
protected void processThumbnailPassComplete(BufferedImage thumbnail) |
342 |
|
{ |
343 |
|
Iterator it = updateListeners.iterator(); |
344 |
|
|
345 |
|
while (it.hasNext()) |
346 |
|
{ |
347 |
|
IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next(); |
348 |
|
listener.thumbnailPassComplete(this, thumbnail); |
349 |
|
} |
350 |
|
} |
351 |
|
|
352 |
|
protected void processThumbnailPassStarted(BufferedImage thumbnail, int pass, |
353 |
|
int minPass, int maxPass, int minX, |
354 |
|
int minY, int periodX, int periodY, |
355 |
|
int[] bands) |
356 |
|
{ |
357 |
|
Iterator it = updateListeners.iterator(); |
358 |
|
|
359 |
|
while (it.hasNext()) |
360 |
|
{ |
361 |
|
IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next(); |
362 |
|
listener.thumbnailPassStarted(this, thumbnail, pass, minPass, maxPass, |
363 |
|
minX, minY, periodX, periodY, bands); |
364 |
|
} |
365 |
|
} |
366 |
|
|
367 |
|
protected void processThumbnailProgress(float percentageDone) |
368 |
|
{ |
369 |
|
Iterator it = progressListeners.iterator(); |
370 |
|
|
371 |
|
while (it.hasNext()) |
372 |
|
{ |
373 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
374 |
|
listener.thumbnailProgress(this, percentageDone); |
375 |
|
} |
376 |
|
} |
377 |
|
|
378 |
|
protected void processThumbnailStarted(int imageIndex, int thumbnailIndex) |
379 |
|
{ |
380 |
|
Iterator it = progressListeners.iterator(); |
381 |
|
|
382 |
|
while (it.hasNext()) |
383 |
|
{ |
384 |
|
IIOReadProgressListener listener = (IIOReadProgressListener) it.next(); |
385 |
|
listener.thumbnailStarted(this, imageIndex, thumbnailIndex); |
386 |
|
} |
387 |
|
} |
388 |
|
|
389 |
|
protected void processThumbnailUpdate(BufferedImage image, int minX, int minY, |
390 |
|
int width, int height, int periodX, |
391 |
|
int periodY, int[] bands) |
392 |
|
{ |
393 |
|
Iterator it = updateListeners.iterator(); |
394 |
|
|
395 |
|
while (it.hasNext()) |
396 |
|
{ |
397 |
|
IIOReadUpdateListener listener = (IIOReadUpdateListener) it.next(); |
398 |
|
listener.thumbnailUpdate(this, image, minX, minY, width, height, |
399 |
|
periodX, periodY, bands); |
400 |
|
} |
401 |
|
} |
402 |
|
|
403 |
|
protected void processWarningOccurred(String warning) |
404 |
|
{ |
405 |
|
Iterator it = warningListeners.iterator(); |
406 |
|
|
407 |
|
while (it.hasNext()) |
408 |
|
{ |
409 |
|
IIOReadWarningListener listener = (IIOReadWarningListener) it.next(); |
410 |
|
listener.warningOccurred(this, warning); |
411 |
|
} |
412 |
|
} |
413 |
|
|
414 |
|
public abstract BufferedImage read(int imageIndex, ImageReadParam param) |
415 |
|
throws IOException; |
416 |
|
|
417 |
|
public boolean readerSupportsThumbnails() |
418 |
|
{ |
419 |
|
return false; |
420 |
|
} |
421 |
|
|
422 |
|
public Raster readRaster(int imageIndex, ImageReadParam param) |
423 |
|
throws IOException |
424 |
|
{ |
425 |
|
throw new UnsupportedOperationException(); |
426 |
|
} |
427 |
|
|
428 |
|
public BufferedImage readThumbnail(int imageIndex, int thumbnailIndex) |
429 |
|
throws IOException |
430 |
|
{ |
431 |
|
throw new UnsupportedOperationException(); |
432 |
|
} |
433 |
|
|
434 |
|
public void removeAllIIOReadProgressListeners() |
435 |
|
{ |
436 |
|
progressListeners.clear(); |
437 |
|
} |
438 |
|
|
439 |
|
public void removeAllIIOReadUpdateListeners() |
440 |
|
{ |
441 |
|
updateListeners.clear(); |
442 |
|
} |
443 |
|
|
444 |
|
public void removeAllIIOReadWarningListeners() |
445 |
|
{ |
446 |
|
warningListeners.clear(); |
447 |
|
} |
448 |
|
|
449 |
|
public void removeIIOReadProgressListener(IIOReadProgressListener listener) |
450 |
|
{ |
451 |
|
if (listener == null) |
452 |
|
return; |
453 |
|
|
454 |
|
progressListeners.remove(listener); |
455 |
|
} |
456 |
|
|
457 |
|
public void removeIIOReadUpdateListener(IIOReadUpdateListener listener) |
458 |
|
{ |
459 |
|
if (listener == null) |
460 |
|
return; |
461 |
|
|
462 |
|
updateListeners.remove(listener); |
463 |
|
} |
464 |
|
|
465 |
|
public void removeIIOReadWarningListener(IIOReadWarningListener listener) |
466 |
|
{ |
467 |
|
if (listener == null) |
468 |
|
return; |
469 |
|
|
470 |
|
warningListeners.remove(listener); |
471 |
|
} |
472 |
|
|
473 |
|
public void setLocale(Locale locale) |
474 |
|
{ |
475 |
|
if (locale != null) |
476 |
|
{ |
477 |
|
// Check if its a valid locale. |
478 |
|
boolean found = false; |
479 |
|
|
480 |
|
if (availableLocales != null) |
481 |
|
for (int i = availableLocales.length - 1; i >= 0; --i) |
482 |
|
if (availableLocales[i].equals(locale)) |
483 |
|
found = true; |
484 |
|
|
485 |
|
if (! found) |
486 |
|
throw new IllegalArgumentException("looale not available"); |
487 |
|
} |
488 |
|
|
489 |
|
this.locale = locale; |
490 |
|
} |
491 |
} |
} |