1 7 8 package com.sun.imageio.plugins.jpeg; 9 10 import java.util.Locale ; 11 import javax.imageio.spi.ImageReaderSpi ; 12 import javax.imageio.stream.ImageInputStream ; 13 import javax.imageio.spi.IIORegistry ; 14 import javax.imageio.spi.ServiceRegistry ; 15 import java.io.IOException ; 16 import javax.imageio.ImageReader ; 17 import javax.imageio.IIOException ; 18 19 public class JPEGImageReaderSpi extends ImageReaderSpi { 20 21 private static String [] 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 registry, 47 Class <?> category) { 48 if (registered) { 49 return; 50 } 51 try { 52 java.security.AccessController.doPrivileged( 53 new sun.security.action.LoadLibraryAction("jpeg")); 54 } catch (Throwable e) { registry.deregisterServiceProvider(this); 60 return; 61 } 62 63 registered = true; 64 } 65 66 public String getDescription(Locale locale) { 67 return "Standard JPEG Image Reader"; 68 } 69 70 public boolean canDecodeInput(Object source) throws IOException { 71 if (!(source instanceof ImageInputStream )) { 72 return false; 73 } 74 ImageInputStream iis = (ImageInputStream ) source; 75 iis.mark(); 76 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 createReaderInstance(Object extension) 88 throws IIOException { 89 return new JPEGImageReader(this); 90 } 91 92 } 93 | Popular Tags |