KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > wbmp > WBMPImageReaderSpi


1 /*
2  * @(#)WBMPImageReaderSpi.java 1.6 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.wbmp;
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 WBMPImageReaderSpi extends ImageReaderSpi JavaDoc {
20
21     private static String JavaDoc [] writerSpiNames =
22         {"com.sun.imageio.plugins.wbmp.WBMPImageWriterSpi"};
23     private static String JavaDoc[] formatNames = {"wbmp", "WBMP"};
24     private static String JavaDoc[] entensions = {"wbmp"};
25     private static String JavaDoc[] mimeType = {"image/vnd.wap.wbmp"};
26
27     private boolean registered = false;
28
29     public WBMPImageReaderSpi() {
30         super("Sun Microsystems, Inc.",
31               "1.0",
32               formatNames,
33               entensions,
34               mimeType,
35               "com.sun.imageio.plugins.wbmp.WBMPImageReader",
36               STANDARD_INPUT_TYPE,
37               writerSpiNames,
38               true,
39               null, null, null, null,
40               true,
41               WBMPMetadata.nativeMetadataFormatName,
42               "com.sun.imageio.plugins.wbmp.WBMPMetadataFormat",
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 WBMP 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[3];
65
66         stream.mark();
67         stream.readFully(b);
68         stream.reset();
69
70         return ((b[0] == (byte)0) && // TypeField == 0
71
b[1] == 0 && // FixHeaderField == 0xxx00000; not support ext header
72
((b[2] & 0x8f) != 0 || (b[2] & 0x7f) != 0)); // First width byte
73
//XXX: b[2] & 0x8f) != 0 for the bug in Sony Ericsson encoder.
74
}
75
76     public ImageReader JavaDoc createReaderInstance(Object JavaDoc extension)
77         throws IIOException JavaDoc {
78         return new WBMPImageReader(this);
79     }
80 }
81
82
Popular Tags