Mercurial > hg > digilib-old
changeset 458:eec0d8c9c3c9
Servlet version 1.5.9h
- experimental Flashpix support with JAIDocuImage
author | robcast |
---|---|
date | Wed, 08 Feb 2006 20:30:46 +0100 |
parents | 4778d8af7913 |
children | b3519a49ae51 |
files | servlet/src/digilib/image/ImageOps.java servlet/src/digilib/image/ImageSize.java |
diffstat | 2 files changed, 99 insertions(+), 78 deletions(-) [+] |
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageOps.java Thu Feb 02 18:50:33 2006 +0100 +++ b/servlet/src/digilib/image/ImageOps.java Wed Feb 08 20:30:46 2006 +0100 @@ -1,9 +1,9 @@ /* ImageOps -- convenience methods for images - + Digital Image Library servlet components - + Copyright (C) 2004 Robert Casties (robcast@mail.berlios.de) - + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your @@ -11,11 +11,11 @@ Please read license.txt for the full details. A copy of the GPL may be found at http://www.gnu.org/copyleft/lgpl.html - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - + * Created on 13.10.2004 */ package digilib.image; @@ -28,6 +28,8 @@ import javax.imageio.ImageIO; import javax.imageio.ImageReader; import javax.imageio.stream.ImageInputStream; +import javax.media.jai.JAI; +import javax.media.jai.RenderedOp; import org.apache.log4j.Logger; import org.marcoschmidt.image.ImageInfo; @@ -39,79 +41,98 @@ /** * convenience methods for images - * + * * @author casties */ public class ImageOps { - - private static Logger logger = Logger.getLogger(ImageOps.class); - - public static int TYPE_AUTO = 0; - public static int TYPE_JPEG = 1; - public static int TYPE_PNG = 2; - - - /** Check image size and type and store in ImageFile f */ - public static boolean checkFile(ImageFile imgf) throws IOException { - // fileset to store the information - ImageFileset imgfs = imgf.getParent(); - File f = imgf.getFile(); - if (f == null) { - throw new IOException("File not found!"); - } - RandomAccessFile raf = new RandomAccessFile(f, "r"); - // set up ImageInfo object - ImageInfo iif = new ImageInfo(); - iif.setInput(raf); - iif.setCollectComments(false); - iif.setDetermineImageNumber(false); - logger.debug("identifying (ImageInfo) " + f); - // try with ImageInfo first - if (iif.check()) { - ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight()); - imgf.setSize(d); - imgf.setMimetype(iif.getMimeType()); - //logger.debug(" format:"+iif.getFormatName()); - if (imgfs != null) { - imgfs.setAspect(d); - } - raf.close(); - iif = null; - } else { - iif = null; - logger.debug("identifying (ImageIO) " + f); - /* - * else use ImageReader - */ - ImageInputStream istream = ImageIO.createImageInputStream(raf); - Iterator readers = ImageIO.getImageReaders(istream); - if ((readers == null) || (!readers.hasNext())) { - throw new FileOpException("ERROR: unknown image file format!"); - } - ImageReader reader = (ImageReader) readers.next(); - /* are there more readers? */ - logger.debug("ImageIO: this reader: " + reader.getClass()); - while (readers.hasNext()) { - logger.debug("ImageIO: next reader: " - + readers.next().getClass()); - } - reader.setInput(istream); - ImageSize d = new ImageSize(reader.getWidth(0), reader.getHeight(0)); - imgf.setSize(d); - //String t = reader.getFormatName(); - String t = FileOps.mimeForFile(f); - imgf.setMimetype(t); - //logger.debug(" format:"+t); - if (imgfs != null) { - imgfs.setAspect(d); - } - // dispose the reader to free resources - reader.dispose(); - raf.close(); - reader = null; - } - logger.debug("image size: " + imgf.getSize()); - return true; - } - + + private static Logger logger = Logger.getLogger(ImageOps.class); + + public static int TYPE_AUTO = 0; + public static int TYPE_JPEG = 1; + public static int TYPE_PNG = 2; + + + /** Check image size and type and store in ImageFile f */ + public static boolean checkFile(ImageFile imgf) throws IOException { + // fileset to store the information + ImageFileset imgfs = imgf.getParent(); + File f = imgf.getFile(); + if (f == null) { + throw new IOException("File not found!"); + } + RandomAccessFile raf = new RandomAccessFile(f, "r"); + // set up ImageInfo object + ImageInfo iif = new ImageInfo(); + iif.setInput(raf); + iif.setCollectComments(false); + iif.setDetermineImageNumber(false); + logger.debug("identifying (ImageInfo) " + f); + // try with ImageInfo first + if (iif.check()) { + ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight()); + imgf.setSize(d); + imgf.setMimetype(iif.getMimeType()); + //logger.debug(" format:"+iif.getFormatName()); + if (imgfs != null) { + imgfs.setAspect(d); + } + raf.close(); + logger.debug("image size: " + imgf.getSize()); + return true; + } + + logger.debug("identifying (ImageIO) " + f); + /* + * else try ImageReader + */ + ImageInputStream istream = ImageIO.createImageInputStream(raf); + Iterator readers = ImageIO.getImageReaders(istream); + if (readers.hasNext()) { + ImageReader reader = (ImageReader) readers.next(); + /* are there more readers? */ + logger.debug("ImageIO: this reader: " + reader.getClass()); + while (readers.hasNext()) { + logger.debug("ImageIO: next reader: " + + readers.next().getClass()); + } + try { + reader.setInput(istream); + ImageSize d = new ImageSize(reader.getWidth(0), reader.getHeight(0)); + imgf.setSize(d); + //String t = reader.getFormatName(); + String t = FileOps.mimeForFile(f); + imgf.setMimetype(t); + //logger.debug(" format:"+t); + if (imgfs != null) { + imgfs.setAspect(d); + } + return true; + } finally { + // dispose the reader to free resources + reader.dispose(); + raf.close(); + } + } + /* + * else try JAI + */ + logger.debug("identifying (JAI) " + f); + try { + RenderedOp img = JAI.create("fileload", f.getAbsolutePath()); + ImageSize d = new ImageSize(img.getWidth(), img.getHeight()); + imgf.setSize(d); + String t = FileOps.mimeForFile(f); + imgf.setMimetype(t); + //logger.debug(" format:"+t); + if (imgfs != null) { + imgfs.setAspect(d); + } + logger.debug("image size: " + imgf.getSize()); + return true; + } catch (Exception e) { + throw new FileOpException("ERROR: unknown image file format!"); + } + } + }
--- a/servlet/src/digilib/image/ImageSize.java Thu Feb 02 18:50:33 2006 +0100 +++ b/servlet/src/digilib/image/ImageSize.java Wed Feb 08 20:30:46 2006 +0100 @@ -1,5 +1,5 @@ /* - * ImageFile.java -- digilib image file class. + * ImageSize.java -- digilib image size class. * Digital Image Library servlet components * Copyright (C) 2003 Robert Casties (robcast@mail.berlios.de) * This program is free software; you can redistribute it and/or modify it under the