KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > bmp > BMPImageReaderSpi


1 /*
2  * @(#)BMPImageReaderSpi.java 1.5 04/05/05 05:42:00
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.imageio.plugins.bmp;
9
10 import java.util.Locale JavaDoc;
11 import javax.imageio.spi.ImageReaderSpi JavaDoc;
12 import javax.imageio.stream.ImageInputStream JavaDoc;
13 import javax.imageio.spi.IIORegistry JavaDoc;
14 import javax.imageio.spi.ServiceRegistry JavaDoc;
15 import java.io.IOException JavaDoc;
16 import javax.imageio.ImageReader JavaDoc;
17 import javax.imageio.IIOException JavaDoc;
18
19 public class BMPImageReaderSpi extends ImageReaderSpi JavaDoc {
20
21     private static String JavaDoc [] writerSpiNames =
22         {"com.sun.imageio.plugins.bmp.BMPImageWriterSpi"};
23     private static String JavaDoc[] formatNames = {"bmp", "BMP"};
24     private static String JavaDoc[] entensions = {"bmp"};
25     private static String JavaDoc[] mimeType = {"image/bmp"};
26
27     private boolean registered = false;
28
29     public BMPImageReaderSpi() {
30         super("Sun Microsystems, Inc.",
31               "1.0",
32               formatNames,
33               entensions,
34               mimeType,
35               "com.sun.imageio.plugins.bmp.BMPImageReader",
36               STANDARD_INPUT_TYPE,
37               writerSpiNames,
38               false,
39               null, null, null, null,
40               true,
41               BMPMetadata.nativeMetadataFormatName,
42               "com.sun.imageio.plugins.bmp.BMPMetadataFormat",
43               null, null);
44     }
45
46     public void onRegistration(ServiceRegistry JavaDoc registry,
47                                Class JavaDoc<?> category) {
48         if (registered) {
49             return;
50         }
51         registered = true;
52     }
53
54     public String JavaDoc getDescription(Locale JavaDoc locale) {
55         return "Standard BMP Image Reader";
56     }
57
58     public boolean canDecodeInput(Object JavaDoc source) throws IOException JavaDoc {
59         if (!(source instanceof ImageInputStream JavaDoc)) {
60             return false;
61         }
62
63         ImageInputStream JavaDoc stream = (ImageInputStream JavaDoc)source;
64         byte[] b = new byte[2];
65         stream.mark();
66         stream.readFully(b);
67         stream.reset();
68
69         return (b[0] == 0x42) && (b[1] == 0x4d);
70     }
71
72     public ImageReader JavaDoc createReaderInstance(Object JavaDoc extension)
73         throws IIOException JavaDoc {
74         return new BMPImageReader(this);
75     }
76 }
77
78
Popular Tags