564
|
1 /**
|
|
2 *
|
|
3 */
|
|
4 package digilib.image;
|
|
5
|
|
6 import java.io.IOException;
|
|
7 import java.io.RandomAccessFile;
|
|
8
|
|
9 import org.marcoschmidt.image.ImageInfo;
|
|
10
|
566
|
11 import digilib.io.ImageInput;
|
596
|
12 import digilib.util.ImageSize;
|
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
|
590
|
21 /* Check image size and type and store in ImageFile f */
|
588
|
22 public ImageInput identify(ImageInput ii) throws IOException {
|
590
|
23 logger.debug("identifying (ImageInfo) " + ii);
|
564
|
24 // set up ImageInfo object
|
|
25 ImageInfo iif = new ImageInfo();
|
590
|
26 if (ii.hasImageInputStream()) {
|
|
27 iif.setInput(ii.getImageInputStream());
|
|
28 } else if (ii.hasFile()) {
|
|
29 RandomAccessFile raf = new RandomAccessFile(ii.getFile(), "r");
|
|
30 iif.setInput(raf);
|
|
31 } else {
|
|
32 return null;
|
|
33 }
|
564
|
34 iif.setCollectComments(false);
|
|
35 iif.setDetermineImageNumber(false);
|
|
36 // try with ImageInfo first
|
|
37 if (iif.check()) {
|
|
38 ImageSize d = new ImageSize(iif.getWidth(), iif.getHeight());
|
588
|
39 ii.setSize(d);
|
|
40 ii.setMimetype(iif.getMimeType());
|
|
41 logger.debug("image size: " + ii.getSize());
|
|
42 return ii;
|
564
|
43 }
|
|
44 return null;
|
|
45 }
|
|
46
|
|
47
|
|
48 }
|