Mercurial > hg > digilib-old
annotate common-jai/src/main/java/digilib/image/JAIImageLoaderDocuImage.java @ 1103:d8c380faa347
fix region numbers and rg param
author | hertzhaft |
---|---|
date | Fri, 26 Oct 2012 14:17:19 +0200 |
parents | b2d97b842612 |
children |
rev | line source |
---|---|
960
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
1 /* JAIImageLoaderDocuImage -- Image class implementation using JAI's ImageLoader Plugin |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
2 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
3 Digital Image Library servlet components |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
4 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
5 Copyright (C) 2002, 2003 Robert Casties (robcast@mail.berlios.de) |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
6 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
7 This program is free software; you can redistribute it and/or modify it |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
8 under the terms of the GNU General Public License as published by the |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
9 Free Software Foundation; either version 2 of the License, or (at your |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
10 option) any later version. |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
11 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
12 Please read license.txt for the full details. A copy of the GPL |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
13 may be found at http://www.gnu.org/copyleft/lgpl.html |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
14 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
16 along with this program; if not, write to the Free Software |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
18 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
19 */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
20 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
21 package digilib.image; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
22 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
23 import java.awt.Image; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
24 import java.awt.Rectangle; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
25 import java.awt.image.renderable.ParameterBlock; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
26 import java.io.File; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
27 import java.io.IOException; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
28 import java.io.OutputStream; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
29 import java.io.RandomAccessFile; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
30 import java.util.Iterator; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
31 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
32 import javax.imageio.ImageIO; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
33 import javax.imageio.ImageReadParam; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
34 import javax.imageio.ImageReader; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
35 import javax.imageio.stream.FileImageInputStream; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
36 import javax.imageio.stream.ImageInputStream; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
37 import javax.media.jai.JAI; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
38 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
39 import digilib.io.FileOpException; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
40 import digilib.io.ImageInput; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
41 import digilib.util.ImageSize; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
42 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
43 /** DocuImage implementation using the Java Advanced Imaging API and the ImageLoader |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
44 * API of Java 1.4. |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
45 */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
46 public class JAIImageLoaderDocuImage extends JAIDocuImage { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
47 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
48 /** ImageIO image reader */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
49 protected ImageReader reader; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
50 /** current image file */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
51 protected File imgFile; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
52 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
53 /* loadSubimage is supported. */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
54 public boolean isSubimageSupported() { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
55 return true; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
56 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
57 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
58 /* returns the size of the current image */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
59 public ImageSize getSize() { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
60 ImageSize is = null; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
61 // TODO: can we cache imageSize? |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
62 int h = 0; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
63 int w = 0; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
64 try { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
65 if (img == null) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
66 // get size from ImageReader |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
67 h = reader.getHeight(0); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
68 w = reader.getWidth(0); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
69 } else { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
70 // get size from image |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
71 h = img.getHeight(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
72 w = img.getWidth(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
73 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
74 is = new ImageSize(w, h); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
75 } catch (IOException e) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
76 logger.debug("error in getSize:", e); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
77 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
78 return is; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
79 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
80 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
81 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
82 /* Load an image file into the Object. */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
83 public void loadImage(ImageInput ii) throws FileOpException { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
84 logger.debug("loadImage: "+ii); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
85 if (ii.hasImageInputStream()) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
86 img = JAI.create("ImageRead", ii.getImageInputStream()); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
87 } else if (ii.hasFile()) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
88 img = JAI.create("ImageRead", ii.getFile().getAbsolutePath()); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
89 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
90 if (img == null) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
91 throw new FileOpException("Unable to load File!"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
92 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
93 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
94 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
95 /* Get an ImageReader for the image file. */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
96 public ImageReader getReader(ImageInput input) throws IOException { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
97 logger.debug("get ImageReader for " + input); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
98 if (this.reader != null) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
99 if (this.input == input) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
100 // it was the same input |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
101 logger.debug("reusing Reader"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
102 return reader; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
103 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
104 // clean up old reader |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
105 logger.debug("cleaning Reader!"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
106 dispose(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
107 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
108 this.input = input; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
109 ImageInputStream istream = null; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
110 if (input.hasImageInputStream()) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
111 // stream input |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
112 istream = input.getImageInputStream(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
113 } else if (input.hasFile()) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
114 // file only input |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
115 RandomAccessFile rf = new RandomAccessFile(input.getFile(), "r"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
116 istream = new FileImageInputStream(rf); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
117 } else { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
118 throw new FileOpException("Unable to get data from ImageInput"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
119 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
120 Iterator<ImageReader> readers; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
121 String mt = input.getMimetype(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
122 if (mt == null) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
123 logger.debug("No mime-type. Trying automagic."); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
124 readers = ImageIO.getImageReaders(istream); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
125 } else { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
126 logger.debug("File type:" + mt); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
127 readers = ImageIO.getImageReadersByMIMEType(mt); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
128 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
129 if (!readers.hasNext()) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
130 throw new FileOpException("Can't find Reader to load File!"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
131 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
132 reader = readers.next(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
133 logger.debug("ImageIO: this reader: " + reader.getClass()); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
134 /* are there more readers? */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
135 /* while (readers.hasNext()) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
136 logger.debug("ImageIO: next reader: " + readers.next().getClass()); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
137 } */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
138 reader.setInput(istream); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
139 return reader; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
140 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
141 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
142 /* Load an image file into the Object. */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
143 public void loadSubimage(ImageInput ii, Rectangle region, int prescale) |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
144 throws FileOpException { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
145 logger.debug("loadSubimage: "+ii.getFile()); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
146 //System.gc(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
147 try { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
148 if ((reader == null) || (imgFile != ii.getFile())) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
149 getReader(ii); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
150 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
151 ImageReadParam readParam = reader.getDefaultReadParam(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
152 readParam.setSourceRegion(region); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
153 readParam.setSourceSubsampling(prescale, prescale, 0, 0); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
154 img = reader.read(0, readParam); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
155 /* JAI imageread seems to ignore the readParam :-( |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
156 ImageInputStream istream = (ImageInputStream) reader.getInput(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
157 ParameterBlockJAI pb = new ParameterBlockJAI("imageread"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
158 pb.setParameter("Input", istream); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
159 pb.setParameter("ReadParam", readParam); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
160 pb.setParameter("Reader", reader); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
161 img = JAI.create("imageread", pb); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
162 */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
163 } catch (IOException e) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
164 throw new FileOpException("Unable to load File!"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
165 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
166 if (img == null) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
167 throw new FileOpException("Unable to load File!"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
168 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
169 imgFile = ii.getFile(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
170 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
171 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
172 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
173 /* Write the current image to an OutputStream. */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
174 public void writeImage(String mt, OutputStream ostream) |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
175 throws ImageOpException, FileOpException { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
176 logger.debug("writeImage"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
177 try { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
178 // setup output |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
179 ParameterBlock pb3 = new ParameterBlock(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
180 pb3.addSource(img); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
181 pb3.add(ostream); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
182 if (mt == "image/jpeg") { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
183 pb3.add("JPEG"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
184 } else if (mt == "image/png") { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
185 pb3.add("PNG"); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
186 } else { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
187 // unknown mime type |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
188 throw new ImageOpException("Unknown mime type: " + mt); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
189 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
190 // render output |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
191 JAI.create("ImageWrite", pb3); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
192 } catch (RuntimeException e) { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
193 throw new FileOpException("Error writing image."); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
194 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
195 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
196 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
197 @Override |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
198 public Image getAwtImage() { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
199 // TODO Auto-generated method stub |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
200 return (Image) img; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
201 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
202 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
203 /* (non-Javadoc) |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
204 * @see java.lang.Object#finalize() |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
205 */ |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
206 protected void finalize() throws Throwable { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
207 dispose(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
208 super.finalize(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
209 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
210 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
211 public void dispose() { |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
212 // we must dispose the ImageReader because it keeps the filehandle open! |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
213 reader.dispose(); |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
214 reader = null; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
215 img = null; |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
216 } |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
217 |
b2d97b842612
moved DocuImage implementations with non-standard toolkits (JAI, ImgeJ) into separate Maven modules.
robcast
parents:
diff
changeset
|
218 } |