Mercurial > hg > digilib-old
comparison servlet/src/digilib/image/JAIImageLoaderDocuImage.java @ 570:fd2ef7e46119
more cleanup, set version to 1.8.2
| author | robcast |
|---|---|
| date | Tue, 21 Dec 2010 20:24:09 +0100 |
| parents | 919e008ab1fb |
| children | aee436f0549d |
comparison
equal
deleted
inserted
replaced
| 569:1f666c2b4578 | 570:fd2ef7e46119 |
|---|---|
| 33 import javax.imageio.ImageReadParam; | 33 import javax.imageio.ImageReadParam; |
| 34 import javax.imageio.ImageReader; | 34 import javax.imageio.ImageReader; |
| 35 import javax.imageio.stream.FileImageInputStream; | 35 import javax.imageio.stream.FileImageInputStream; |
| 36 import javax.imageio.stream.ImageInputStream; | 36 import javax.imageio.stream.ImageInputStream; |
| 37 import javax.media.jai.JAI; | 37 import javax.media.jai.JAI; |
| 38 import javax.servlet.ServletException; | |
| 38 | 39 |
| 39 import digilib.io.FileOpException; | 40 import digilib.io.FileOpException; |
| 40 import digilib.io.ImageFile; | 41 import digilib.io.ImageFile; |
| 41 | 42 |
| 42 /** DocuImage implementation using the Java Advanced Imaging API and the ImageLoader | 43 /** DocuImage implementation using the Java Advanced Imaging API and the ImageLoader |
| 52 /* loadSubimage is supported. */ | 53 /* loadSubimage is supported. */ |
| 53 public boolean isSubimageSupported() { | 54 public boolean isSubimageSupported() { |
| 54 return true; | 55 return true; |
| 55 } | 56 } |
| 56 | 57 |
| 57 public int getHeight() { | 58 /* returns the size of the current image */ |
| 58 int h = 0; | 59 public ImageSize getSize() { |
| 59 try { | 60 ImageSize is = null; |
| 60 if (img == null) { | 61 // TODO: can we cache imageSize? |
| 61 h = reader.getHeight(0); | 62 int h = 0; |
| 62 } else { | 63 int w = 0; |
| 63 h = img.getHeight(); | 64 try { |
| 64 } | 65 if (img == null) { |
| 65 } catch (IOException e) { | 66 // get size from ImageReader |
| 66 logger.debug("error in getHeight", e); | 67 h = reader.getHeight(0); |
| 67 } | 68 w = reader.getWidth(0); |
| 68 return h; | 69 } else { |
| 69 } | 70 // get size from image |
| 71 h = img.getHeight(); | |
| 72 w = img.getWidth(); | |
| 73 } | |
| 74 is = new ImageSize(w, h); | |
| 75 } catch (IOException e) { | |
| 76 logger.debug("error in getSize:", e); | |
| 77 } | |
| 78 return is; | |
| 79 } | |
| 70 | 80 |
| 71 public int getWidth() { | |
| 72 int w = 0; | |
| 73 try { | |
| 74 if (img == null) { | |
| 75 w = reader.getWidth(0); | |
| 76 } else { | |
| 77 w = img.getWidth(); | |
| 78 } | |
| 79 } catch (IOException e) { | |
| 80 logger.debug("error in getHeight", e); | |
| 81 } | |
| 82 return w; | |
| 83 } | |
| 84 | 81 |
| 85 /* Load an image file into the Object. */ | 82 /* Load an image file into the Object. */ |
| 86 public void loadImage(ImageFile f) throws FileOpException { | 83 public void loadImage(ImageFile f) throws FileOpException { |
| 87 logger.debug("loadImage: "+f.getFile()); | 84 logger.debug("loadImage: "+f.getFile()); |
| 88 //System.gc(); | 85 //System.gc(); |
| 145 } | 142 } |
| 146 | 143 |
| 147 | 144 |
| 148 /* Write the current image to an OutputStream. */ | 145 /* Write the current image to an OutputStream. */ |
| 149 public void writeImage(String mt, OutputStream ostream) | 146 public void writeImage(String mt, OutputStream ostream) |
| 150 throws FileOpException { | 147 throws ImageOpException, ServletException { |
| 151 logger.debug("writeImage"); | 148 logger.debug("writeImage"); |
| 152 try { | 149 try { |
| 153 // setup output | 150 // setup output |
| 154 ParameterBlock pb3 = new ParameterBlock(); | 151 ParameterBlock pb3 = new ParameterBlock(); |
| 155 pb3.addSource(img); | 152 pb3.addSource(img); |
| 158 pb3.add("JPEG"); | 155 pb3.add("JPEG"); |
| 159 } else if (mt == "image/png") { | 156 } else if (mt == "image/png") { |
| 160 pb3.add("PNG"); | 157 pb3.add("PNG"); |
| 161 } else { | 158 } else { |
| 162 // unknown mime type | 159 // unknown mime type |
| 163 throw new FileOpException("Unknown mime type: " + mt); | 160 throw new ImageOpException("Unknown mime type: " + mt); |
| 164 } | 161 } |
| 165 // render output | 162 // render output |
| 166 JAI.create("ImageWrite", pb3); | 163 JAI.create("ImageWrite", pb3); |
| 167 } catch (IOException e) { | 164 } catch (RuntimeException e) { |
| 168 throw new FileOpException("Error writing image."); | 165 throw new ServletException("Error writing image."); |
| 169 } | 166 } |
| 170 } | 167 } |
| 171 | 168 |
| 172 @Override | 169 @Override |
| 173 public Image getAwtImage() { | 170 public Image getAwtImage() { |
