comparison servlet/src/digilib/image/JAIImageLoaderDocuImage.java @ 181:afe7ff98bb71

Servlet version 1.18b1 - new transfer mode "rawfile" with mime-type application/octet-stream - finally proper logging with Log4J! - therefore a lot of debugging-prints changed - the Util class is now useless - ServletOps and FileOps are now purely static
author robcast
date Fri, 21 Nov 2003 00:17:31 +0100
parents e743b853efca
children f8c82fea551a
comparison
equal deleted inserted replaced
180:bd87f802bea1 181:afe7ff98bb71
59 h = reader.getHeight(0); 59 h = reader.getHeight(0);
60 } else { 60 } else {
61 h = img.getHeight(); 61 h = img.getHeight();
62 } 62 }
63 } catch (IOException e) { 63 } catch (IOException e) {
64 e.printStackTrace(); 64 logger.debug("error in getHeight", e);
65 } 65 }
66 return h; 66 return h;
67 } 67 }
68 68
69 public int getWidth() { 69 public int getWidth() {
73 w = reader.getWidth(0); 73 w = reader.getWidth(0);
74 } else { 74 } else {
75 w = img.getWidth(); 75 w = img.getWidth();
76 } 76 }
77 } catch (IOException e) { 77 } catch (IOException e) {
78 e.printStackTrace(); 78 logger.debug("error in getHeight", e);
79 } 79 }
80 return w; 80 return w;
81 } 81 }
82 82
83 /* Load an image file into the Object. */ 83 /* Load an image file into the Object. */
84 public void loadImage(ImageFile f) throws FileOpException { 84 public void loadImage(ImageFile f) throws FileOpException {
85 System.gc(); 85 System.gc();
86 img = JAI.create("ImageRead", f.getFile().getAbsolutePath()); 86 img = JAI.create("ImageRead", f.getFile().getAbsolutePath());
87 if (img == null) { 87 if (img == null) {
88 util.dprintln(3, "ERROR(loadImage): unable to load file");
89 throw new FileOpException("Unable to load File!"); 88 throw new FileOpException("Unable to load File!");
90 } 89 }
91 } 90 }
92 91
93 /* Get an ImageReader for the image file. */ 92 /* Get an ImageReader for the image file. */
98 //Iterator readers = ImageIO.getImageReaders(istream); 97 //Iterator readers = ImageIO.getImageReaders(istream);
99 Iterator readers = ImageIO.getImageReadersByMIMEType(f.getMimetype()); 98 Iterator readers = ImageIO.getImageReadersByMIMEType(f.getMimetype());
100 reader = (ImageReader) readers.next(); 99 reader = (ImageReader) readers.next();
101 reader.setInput(istream); 100 reader.setInput(istream);
102 if (reader == null) { 101 if (reader == null) {
103 util.dprintln(3, "ERROR(loadImage): unable to load file");
104 throw new FileOpException("Unable to load File!"); 102 throw new FileOpException("Unable to load File!");
105 } 103 }
106 } 104 }
107 105
108 /* Load an image file into the Object. */ 106 /* Load an image file into the Object. */
124 pb.setParameter("ReadParam", readParam); 122 pb.setParameter("ReadParam", readParam);
125 pb.setParameter("Reader", reader); 123 pb.setParameter("Reader", reader);
126 img = JAI.create("imageread", pb); 124 img = JAI.create("imageread", pb);
127 */ 125 */
128 } catch (IOException e) { 126 } catch (IOException e) {
129 util.dprintln(3, "ERROR(loadImage): unable to load file");
130 throw new FileOpException("Unable to load File!"); 127 throw new FileOpException("Unable to load File!");
131 } 128 }
132 if (img == null) { 129 if (img == null) {
133 util.dprintln(3, "ERROR(loadImage): unable to load file");
134 throw new FileOpException("Unable to load File!"); 130 throw new FileOpException("Unable to load File!");
135 } 131 }
136 imgFile = f.getFile(); 132 imgFile = f.getFile();
137 } 133 }
138 134
149 pb3.add("JPEG"); 145 pb3.add("JPEG");
150 } else if (mt == "image/png") { 146 } else if (mt == "image/png") {
151 pb3.add("PNG"); 147 pb3.add("PNG");
152 } else { 148 } else {
153 // unknown mime type 149 // unknown mime type
154 util.dprintln(2, "ERROR(writeImage): Unknown mime type " + mt);
155 throw new FileOpException("Unknown mime type: " + mt); 150 throw new FileOpException("Unknown mime type: " + mt);
156 } 151 }
157 // render output 152 // render output
158 JAI.create("ImageWrite", pb3); 153 JAI.create("ImageWrite", pb3);
159 } catch (IOException e) { 154 } catch (IOException e) {
163 158
164 /* (non-Javadoc) 159 /* (non-Javadoc)
165 * @see java.lang.Object#finalize() 160 * @see java.lang.Object#finalize()
166 */ 161 */
167 protected void finalize() throws Throwable { 162 protected void finalize() throws Throwable {
168 //System.out.println("FIN de JAIImageLoaderDocuImage!");
169 // we must dispose the ImageReader because it keeps the filehandle open! 163 // we must dispose the ImageReader because it keeps the filehandle open!
170 reader.dispose(); 164 reader.dispose();
171 reader = null; 165 reader = null;
172 img = null; 166 img = null;
173 super.finalize(); 167 super.finalize();