Mercurial > hg > digilib-old
comparison servlet/src/digilib/image/JAIDocuImage.java @ 573:beeedf90cb81 stream
Merge from HEAD
fd2ef7e461198ef4a9d9a02459be2057038d600d
author | robcast |
---|---|
date | Wed, 22 Dec 2010 09:54:34 +0100 |
parents | 50f291d808b1 fd2ef7e46119 |
children | 790cbfb58b52 |
comparison
equal
deleted
inserted
replaced
568:34701340922e | 573:beeedf90cb81 |
---|---|
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 import digilib.io.ImageInput; | 51 import digilib.io.ImageInput; |
51 | 52 |
52 /** A DocuImage implementation using Java Advanced Imaging Library. */ | 53 /** A DocuImage implementation using Java Advanced Imaging Library. */ |
54 /** | |
55 * @author casties | |
56 * | |
57 */ | |
53 public class JAIDocuImage extends ImageInfoDocuImage { | 58 public class JAIDocuImage extends ImageInfoDocuImage { |
54 | 59 |
55 protected RenderedImage img; | 60 protected RenderedImage img; |
56 | 61 |
57 protected Interpolation interpol = null; | 62 protected Interpolation interpol = null; |
173 mimeType = f.getMimetype(); | 178 mimeType = f.getMimetype(); |
174 } | 179 } |
175 } | 180 } |
176 | 181 |
177 /* Write the current image to an OutputStream. */ | 182 /* Write the current image to an OutputStream. */ |
178 public void writeImage(String mt, OutputStream ostream) | 183 public void writeImage(String mt, OutputStream ostream) throws ServletException, ImageOpException { |
179 throws FileOpException { | |
180 try { | 184 try { |
181 // setup output | 185 // setup output |
182 ParameterBlock pb3 = new ParameterBlock(); | 186 ParameterBlock pb3 = new ParameterBlock(); |
183 pb3.addSource(img); | 187 pb3.addSource(img); |
184 pb3.add(ostream); | 188 pb3.add(ostream); |
186 pb3.add("JPEG"); | 190 pb3.add("JPEG"); |
187 } else if (mt == "image/png") { | 191 } else if (mt == "image/png") { |
188 pb3.add("PNG"); | 192 pb3.add("PNG"); |
189 } else { | 193 } else { |
190 // unknown mime type | 194 // unknown mime type |
191 throw new FileOpException("Unknown mime type: " + mt); | 195 throw new ImageOpException("Unknown mime type: " + mt); |
192 } | 196 } |
193 // render output | 197 // render output |
194 JAI.create("encode", pb3); | 198 JAI.create("encode", pb3); |
195 | 199 |
196 } catch (IOException e) { | 200 } catch (RuntimeException e) { |
197 throw new FileOpException("Error writing image."); | 201 // JAI likes to throw RuntimeExceptions |
198 } | 202 throw new ServletException("Error writing image:", e); |
199 } | 203 } |
200 | 204 } |
201 /** | 205 |
202 * The width of the curent image in pixel. | 206 /* returns the current image size |
203 * | 207 * @see digilib.image.DocuImageImpl#getSize() |
204 * @return Image width in pixels. | 208 */ |
205 */ | 209 public ImageSize getSize() { |
206 public int getWidth() { | 210 ImageSize is = null; |
207 if (img != null) { | 211 // TODO: do we want to cache imgSize? |
208 return img.getWidth(); | 212 int h = 0; |
209 } | 213 int w = 0; |
210 return 0; | 214 if (img != null) { |
211 } | 215 // get size from image |
212 | 216 h = img.getHeight(); |
213 /** | 217 w = img.getWidth(); |
214 * The height of the curent image in pixel. | 218 is = new ImageSize(w, h); |
215 * | 219 } |
216 * @return Image height in pixels. | 220 return is; |
217 */ | 221 } |
218 public int getHeight() { | |
219 if (img != null) { | |
220 return img.getHeight(); | |
221 } | |
222 return 0; | |
223 } | |
224 | 222 |
225 /* scales the current image */ | 223 /* scales the current image */ |
226 public void scale(double scale, double scaleY) throws ImageOpException { | 224 public void scale(double scale, double scaleY) throws ImageOpException { |
227 logger.debug("scale"); | 225 logger.debug("scale"); |
228 if ((scale < 1) && (img.getColorModel().getPixelSize() == 1) | 226 if ((scale < 1) && (img.getColorModel().getPixelSize() == 1) |