Mercurial > hg > digilib-old
diff servlet/src/digilib/image/JAIDocuImage.java @ 570:fd2ef7e46119
more cleanup, set version to 1.8.2
author | robcast |
---|---|
date | Tue, 21 Dec 2010 20:24:09 +0100 |
parents | 4c51d71aef13 |
children | beeedf90cb81 |
line wrap: on
line diff
--- a/servlet/src/digilib/image/JAIDocuImage.java Tue Dec 21 09:52:16 2010 +0100 +++ b/servlet/src/digilib/image/JAIDocuImage.java Tue Dec 21 20:24:09 2010 +0100 @@ -40,6 +40,7 @@ import javax.media.jai.RenderedOp; import javax.media.jai.operator.TransposeDescriptor; import javax.media.jai.operator.TransposeType; +import javax.servlet.ServletException; import com.sun.media.jai.codec.ImageCodec; @@ -49,6 +50,10 @@ import digilib.io.ImageFileset; /** A DocuImage implementation using Java Advanced Imaging Library. */ +/** + * @author casties + * + */ public class JAIDocuImage extends ImageInfoDocuImage { protected RenderedImage img; @@ -174,8 +179,7 @@ } /* Write the current image to an OutputStream. */ - public void writeImage(String mt, OutputStream ostream) - throws FileOpException { + public void writeImage(String mt, OutputStream ostream) throws ServletException, ImageOpException { try { // setup output ParameterBlock pb3 = new ParameterBlock(); @@ -187,39 +191,33 @@ pb3.add("PNG"); } else { // unknown mime type - throw new FileOpException("Unknown mime type: " + mt); + throw new ImageOpException("Unknown mime type: " + mt); } // render output JAI.create("encode", pb3); - } catch (IOException e) { - throw new FileOpException("Error writing image."); + } catch (RuntimeException e) { + // JAI likes to throw RuntimeExceptions + throw new ServletException("Error writing image:", e); } } - /** - * The width of the curent image in pixel. - * - * @return Image width in pixels. - */ - public int getWidth() { - if (img != null) { - return img.getWidth(); - } - return 0; - } - - /** - * The height of the curent image in pixel. - * - * @return Image height in pixels. - */ - public int getHeight() { - if (img != null) { - return img.getHeight(); - } - return 0; - } + /* returns the current image size + * @see digilib.image.DocuImageImpl#getSize() + */ + public ImageSize getSize() { + ImageSize is = null; + // TODO: do we want to cache imgSize? + int h = 0; + int w = 0; + if (img != null) { + // get size from image + h = img.getHeight(); + w = img.getWidth(); + is = new ImageSize(w, h); + } + return is; + } /* scales the current image */ public void scale(double scale, double scaleY) throws ImageOpException {