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