564
|
1 /**
|
|
2 *
|
|
3 */
|
|
4 package digilib.image;
|
|
5
|
|
6 import java.io.File;
|
|
7 import java.io.IOException;
|
|
8 import java.io.RandomAccessFile;
|
|
9
|
|
10 import org.marcoschmidt.image.ImageInfo;
|
|
11
|
|
12 import digilib.io.ImageFile;
|
566
|
13 import digilib.io.ImageInput;
|
564
|
14
|
|
15 /** Simple abstract implementation of the <code>DocuImage</code> interface.
|
|
16 * Implements only the identify method using the ImageInfo class.
|
|
17 * @author casties
|
|
18 *
|
|
19 */
|
|
20 public abstract class ImageInfoDocuImage extends DocuImageImpl {
|
|
21
|
|
22 /** Check image size and type and store in ImageFile f */
|
566
|
23 public ImageInput identify(ImageFile imgf) throws IOException {
|
564
|
24 // fileset to store the information
|
|
25 File f = imgf.getFile();
|
|
26 if (f == null) {
|
|
27 throw new IOException("File not found!");
|
|
28 }
|
|
29 RandomAccessFile raf = new RandomAccessFile(f, "r");
|
|
30 // set up ImageInfo object
|
|
31 ImageInfo iif = new ImageInfo();
|
|
32 iif.setInput(raf);
|
|
33 iif.setCollectComments(false);
|
|
34 iif.setDetermineImageNumber(false);
|
|
35 logger.debug("identifying (ImageInfo) " + f);
|
|
36 // try with ImageInfo first
|
|
37 if (iif.check()) {
|
|
38 ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight());
|
|
39 imgf.setSize(d);
|
|
40 imgf.setMimetype(iif.getMimeType());
|
|
41 //logger.debug(" format:"+iif.getFormatName());
|
|
42 raf.close();
|
|
43 logger.debug("image size: " + imgf.getSize());
|
|
44 return imgf;
|
|
45 } else {
|
|
46 raf.close();
|
|
47 }
|
|
48 return null;
|
|
49 }
|
|
50
|
|
51
|
|
52 }
|