Mercurial > hg > digilib-old
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 569:1f666c2b4578 | 570:fd2ef7e46119 |
|---|---|
| 38 import javax.media.jai.KernelJAI; | 38 import javax.media.jai.KernelJAI; |
| 39 import javax.media.jai.ParameterBlockJAI; | 39 import javax.media.jai.ParameterBlockJAI; |
| 40 import javax.media.jai.RenderedOp; | 40 import javax.media.jai.RenderedOp; |
| 41 import javax.media.jai.operator.TransposeDescriptor; | 41 import javax.media.jai.operator.TransposeDescriptor; |
| 42 import javax.media.jai.operator.TransposeType; | 42 import javax.media.jai.operator.TransposeType; |
| 43 import javax.servlet.ServletException; | |
| 43 | 44 |
| 44 import com.sun.media.jai.codec.ImageCodec; | 45 import com.sun.media.jai.codec.ImageCodec; |
| 45 | 46 |
| 46 import digilib.io.FileOpException; | 47 import digilib.io.FileOpException; |
| 47 import digilib.io.FileOps; | 48 import digilib.io.FileOps; |
| 48 import digilib.io.ImageFile; | 49 import digilib.io.ImageFile; |
| 49 import digilib.io.ImageFileset; | 50 import digilib.io.ImageFileset; |
| 50 | 51 |
| 51 /** A DocuImage implementation using Java Advanced Imaging Library. */ | 52 /** A DocuImage implementation using Java Advanced Imaging Library. */ |
| 53 /** | |
| 54 * @author casties | |
| 55 * | |
| 56 */ | |
| 52 public class JAIDocuImage extends ImageInfoDocuImage { | 57 public class JAIDocuImage extends ImageInfoDocuImage { |
| 53 | 58 |
| 54 protected RenderedImage img; | 59 protected RenderedImage img; |
| 55 | 60 |
| 56 protected Interpolation interpol = null; | 61 protected Interpolation interpol = null; |
| 172 mimeType = f.getMimetype(); | 177 mimeType = f.getMimetype(); |
| 173 } | 178 } |
| 174 } | 179 } |
| 175 | 180 |
| 176 /* Write the current image to an OutputStream. */ | 181 /* Write the current image to an OutputStream. */ |
| 177 public void writeImage(String mt, OutputStream ostream) | 182 public void writeImage(String mt, OutputStream ostream) throws ServletException, ImageOpException { |
| 178 throws FileOpException { | |
| 179 try { | 183 try { |
| 180 // setup output | 184 // setup output |
| 181 ParameterBlock pb3 = new ParameterBlock(); | 185 ParameterBlock pb3 = new ParameterBlock(); |
| 182 pb3.addSource(img); | 186 pb3.addSource(img); |
| 183 pb3.add(ostream); | 187 pb3.add(ostream); |
| 185 pb3.add("JPEG"); | 189 pb3.add("JPEG"); |
| 186 } else if (mt == "image/png") { | 190 } else if (mt == "image/png") { |
| 187 pb3.add("PNG"); | 191 pb3.add("PNG"); |
| 188 } else { | 192 } else { |
| 189 // unknown mime type | 193 // unknown mime type |
| 190 throw new FileOpException("Unknown mime type: " + mt); | 194 throw new ImageOpException("Unknown mime type: " + mt); |
| 191 } | 195 } |
| 192 // render output | 196 // render output |
| 193 JAI.create("encode", pb3); | 197 JAI.create("encode", pb3); |
| 194 | 198 |
| 195 } catch (IOException e) { | 199 } catch (RuntimeException e) { |
| 196 throw new FileOpException("Error writing image."); | 200 // JAI likes to throw RuntimeExceptions |
| 197 } | 201 throw new ServletException("Error writing image:", e); |
| 198 } | 202 } |
| 199 | 203 } |
| 200 /** | 204 |
| 201 * The width of the curent image in pixel. | 205 /* returns the current image size |
| 202 * | 206 * @see digilib.image.DocuImageImpl#getSize() |
| 203 * @return Image width in pixels. | 207 */ |
| 204 */ | 208 public ImageSize getSize() { |
| 205 public int getWidth() { | 209 ImageSize is = null; |
| 206 if (img != null) { | 210 // TODO: do we want to cache imgSize? |
| 207 return img.getWidth(); | 211 int h = 0; |
| 208 } | 212 int w = 0; |
| 209 return 0; | 213 if (img != null) { |
| 210 } | 214 // get size from image |
| 211 | 215 h = img.getHeight(); |
| 212 /** | 216 w = img.getWidth(); |
| 213 * The height of the curent image in pixel. | 217 is = new ImageSize(w, h); |
| 214 * | 218 } |
| 215 * @return Image height in pixels. | 219 return is; |
| 216 */ | 220 } |
| 217 public int getHeight() { | |
| 218 if (img != null) { | |
| 219 return img.getHeight(); | |
| 220 } | |
| 221 return 0; | |
| 222 } | |
| 223 | 221 |
| 224 /* scales the current image */ | 222 /* scales the current image */ |
| 225 public void scale(double scale, double scaleY) throws ImageOpException { | 223 public void scale(double scale, double scaleY) throws ImageOpException { |
| 226 logger.debug("scale"); | 224 logger.debug("scale"); |
| 227 if ((scale < 1) && (img.getColorModel().getPixelSize() == 1) | 225 if ((scale < 1) && (img.getColorModel().getPixelSize() == 1) |
