comparison servlet/src/digilib/image/ImageLoaderDocuImage.java @ 544:5ff500d6812a digilibPDF

more steps towards more standard java.util.concurrent design
author robcast
date Thu, 14 Oct 2010 20:47:31 +0200
parents 919e008ab1fb
children 686086d6e6d6
comparison
equal deleted inserted replaced
543:919e008ab1fb 544:5ff500d6812a
174 /* load image file */ 174 /* load image file */
175 public void loadImage(ImageFile f) throws FileOpException { 175 public void loadImage(ImageFile f) throws FileOpException {
176 logger.debug("loadImage " + f.getFile()); 176 logger.debug("loadImage " + f.getFile());
177 try { 177 try {
178 img = ImageIO.read(f.getFile()); 178 img = ImageIO.read(f.getFile());
179 if (img == null) {
180 throw new FileOpException("Unable to load File!");
181 }
182 mimeType = f.getMimetype(); 179 mimeType = f.getMimetype();
183 } catch (IOException e) { 180 } catch (IOException e) {
184 throw new FileOpException("Error reading image."); 181 throw new FileOpException("Error reading image.");
185 } 182 }
186 } 183 }
221 218
222 /* Load an image file into the Object. */ 219 /* Load an image file into the Object. */
223 public void loadSubimage(ImageFile f, Rectangle region, int prescale) 220 public void loadSubimage(ImageFile f, Rectangle region, int prescale)
224 throws FileOpException { 221 throws FileOpException {
225 logger.debug("loadSubimage"); 222 logger.debug("loadSubimage");
226 // System.gc();
227 try { 223 try {
228 if ((reader == null) || (imgFile != f.getFile())) { 224 if ((reader == null) || (imgFile != f.getFile())) {
229 getReader(f); 225 getReader(f);
230 } 226 }
231 // set up reader parameters 227 // set up reader parameters
238 logger.debug("loading.."); 234 logger.debug("loading..");
239 img = reader.read(0, readParam); 235 img = reader.read(0, readParam);
240 mimeType = f.getMimetype(); 236 mimeType = f.getMimetype();
241 logger.debug("loaded"); 237 logger.debug("loaded");
242 } catch (IOException e) { 238 } catch (IOException e) {
243 throw new FileOpException("Unable to load File!");
244 }
245 if (img == null) {
246 throw new FileOpException("Unable to load File!"); 239 throw new FileOpException("Unable to load File!");
247 } 240 }
248 } 241 }
249 242
250 /* write image of type mt to Stream */ 243 /* write image of type mt to Stream */
344 // DEBUG 337 // DEBUG
345 logger.debug("destination image type " + scaledImg.getType()); 338 logger.debug("destination image type " + scaledImg.getType());
346 logger.debug("SCALE: " + scale + " ->" + scaledImg.getWidth() + "x" 339 logger.debug("SCALE: " + scale + " ->" + scaledImg.getWidth() + "x"
347 + scaledImg.getHeight()); 340 + scaledImg.getHeight());
348 img = scaledImg; 341 img = scaledImg;
349 scaledImg = null;
350 } 342 }
351 343
352 public void blur(int radius) throws ImageOpException { 344 public void blur(int radius) throws ImageOpException {
353 // DEBUG 345 // DEBUG
354 logger.debug("blur: " + radius); 346 logger.debug("blur: " + radius);
371 if (img.getType() == BufferedImage.TYPE_3BYTE_BGR) { 363 if (img.getType() == BufferedImage.TYPE_3BYTE_BGR) {
372 blurredImg = new BufferedImage(img.getWidth(), img.getHeight(), img 364 blurredImg = new BufferedImage(img.getWidth(), img.getHeight(), img
373 .getType()); 365 .getType());
374 } 366 }
375 blurredImg = blurOp.filter(img, blurredImg); 367 blurredImg = blurOp.filter(img, blurredImg);
376 if (blurredImg == null) {
377 throw new ImageOpException("Unable to scale");
378 }
379 img = blurredImg; 368 img = blurredImg;
380 } 369 }
381 370
382 public void crop(int x_off, int y_off, int width, int height) 371 public void crop(int x_off, int y_off, int width, int height)
383 throws ImageOpException { 372 throws ImageOpException {
499 // transform image 488 // transform image
500 rotOp = new AffineTransformOp(trafo, renderHint); 489 rotOp = new AffineTransformOp(trafo, renderHint);
501 BufferedImage rotImg = rotOp.filter(img, null); 490 BufferedImage rotImg = rotOp.filter(img, null);
502 // calculate new bounding box 491 // calculate new bounding box
503 // Rectangle2D bounds = rotOp.getBounds2D(img); 492 // Rectangle2D bounds = rotOp.getBounds2D(img);
504 if (rotImg == null) {
505 throw new ImageOpException("Unable to rotate");
506 }
507 img = rotImg; 493 img = rotImg;
508 // crop new image (with self-made rounding) 494 // crop new image (with self-made rounding)
509 /* 495 /*
510 * img = rotImg.getSubimage( (int) (bounds.getX()+0.5), (int) 496 * img = rotImg.getSubimage( (int) (bounds.getX()+0.5), (int)
511 * (bounds.getY()+0.5), (int) (bounds.getWidth()+0.5), (int) 497 * (bounds.getY()+0.5), (int) (bounds.getWidth()+0.5), (int)
536 tx = getWidth(); 522 tx = getWidth();
537 } 523 }
538 AffineTransformOp mirOp = new AffineTransformOp(new AffineTransform(mx, 524 AffineTransformOp mirOp = new AffineTransformOp(new AffineTransform(mx,
539 0, 0, my, tx, ty), renderHint); 525 0, 0, my, tx, ty), renderHint);
540 BufferedImage mirImg = mirOp.filter(img, null); 526 BufferedImage mirImg = mirOp.filter(img, null);
541 if (mirImg == null) {
542 throw new ImageOpException("Unable to mirror");
543 }
544 img = mirImg; 527 img = mirImg;
545 } 528 }
546 529
547 /* 530 /*
548 * (non-Javadoc) 531 * (non-Javadoc)