KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > jpeg > JPEGImageReaderSpi


1 /*
2  * @(#)JPEGImageReaderSpi.java 1.8 04/05/05
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.jpeg;
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 JPEGImageReaderSpi extends ImageReaderSpi JavaDoc {
20
21     private static String JavaDoc [] writerSpiNames =
22         {"com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi"};
23
24     private boolean registered = false;
25     
26     public JPEGImageReaderSpi() {
27         super(JPEG.vendor,
28               JPEG.version,
29               JPEG.names,
30               JPEG.suffixes,
31               JPEG.MIMETypes,
32               "com.sun.imageio.plugins.jpeg.JPEGImageReader",
33               STANDARD_INPUT_TYPE,
34               writerSpiNames,
35               true,
36               JPEG.nativeStreamMetadataFormatName,
37               JPEG.nativeStreamMetadataFormatClassName,
38               null, null,
39               true,
40               JPEG.nativeImageMetadataFormatName,
41               JPEG.nativeImageMetadataFormatClassName,
42               null, null
43               );
44     }
45
46     public void onRegistration(ServiceRegistry JavaDoc registry,
47                                Class JavaDoc<?> category) {
48         if (registered) {
49             return;
50         }
51         try {
52             java.security.AccessController.doPrivileged(
53                 new sun.security.action.LoadLibraryAction("jpeg"));
54             // Stuff it all into one lib for first pass
55
//java.security.AccessController.doPrivileged(
56
//new sun.security.action.LoadLibraryAction("imageioIJG"));
57
} catch (Throwable JavaDoc e) { // Fail on any Throwable
58
// if it can't be loaded, deregister and return
59
registry.deregisterServiceProvider(this);
60             return;
61         }
62
63         registered = true;
64     }
65
66     public String JavaDoc getDescription(Locale JavaDoc locale) {
67         return "Standard JPEG Image Reader";
68     }
69
70     public boolean canDecodeInput(Object JavaDoc source) throws IOException JavaDoc {
71         if (!(source instanceof ImageInputStream JavaDoc)) {
72             return false;
73         }
74         ImageInputStream JavaDoc iis = (ImageInputStream JavaDoc) source;
75         iis.mark();
76         // If the first two bytes are a JPEG SOI marker, it's probably
77
// a JPEG file. If they aren't, it definitely isn't a JPEG file.
78
int byte1 = iis.read();
79         int byte2 = iis.read();
80         iis.reset();
81         if ((byte1 == 0xFF) && (byte2 == JPEG.SOI)) {
82             return true;
83         }
84         return false;
85     }
86     
87     public ImageReader JavaDoc createReaderInstance(Object JavaDoc extension)
88         throws IIOException JavaDoc {
89         return new JPEGImageReader(this);
90     }
91
92 }
93
Popular Tags