view servlet/src/digilib/image/ImageInfoDocuImage.java @ 596:2b58d2783ef0 stream

small cleanup
author robcast
date Sun, 09 Jan 2011 21:51:07 +0100
parents 69bc69381ac4
children a23c4c15a6a8
line wrap: on
line source

/**
 * 
 */
package digilib.image;

import java.io.IOException;
import java.io.RandomAccessFile;

import org.marcoschmidt.image.ImageInfo;

import digilib.io.ImageInput;
import digilib.util.ImageSize;

/** Simple abstract implementation of the <code>DocuImage</code> interface.
 * Implements only the identify method using the ImageInfo class.
 * @author casties
 *
 */
public abstract class ImageInfoDocuImage extends DocuImageImpl {

    /* Check image size and type and store in ImageFile f */
    public ImageInput identify(ImageInput ii) throws IOException {
        logger.debug("identifying (ImageInfo) " + ii);
        // set up ImageInfo object
        ImageInfo iif = new ImageInfo();
        if (ii.hasImageInputStream()) {
            iif.setInput(ii.getImageInputStream());
        } else if (ii.hasFile()) {
            RandomAccessFile raf = new RandomAccessFile(ii.getFile(), "r");
            iif.setInput(raf);
        } else {
            return null;
        }
        iif.setCollectComments(false);
        iif.setDetermineImageNumber(false);
        // try with ImageInfo first
        if (iif.check()) {
            ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight());
            ii.setSize(d);
            ii.setMimetype(iif.getMimeType());
            logger.debug("image size: " + ii.getSize());
            return ii;
        }
        return null;
    }
        

}