1 7 8 package com.sun.imageio.plugins.bmp; 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 BMPImageReaderSpi extends ImageReaderSpi { 20 21 private static String [] writerSpiNames = 22 {"com.sun.imageio.plugins.bmp.BMPImageWriterSpi"}; 23 private static String [] formatNames = {"bmp", "BMP"}; 24 private static String [] entensions = {"bmp"}; 25 private static String [] 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 registry, 47 Class <?> category) { 48 if (registered) { 49 return; 50 } 51 registered = true; 52 } 53 54 public String getDescription(Locale locale) { 55 return "Standard BMP Image Reader"; 56 } 57 58 public boolean canDecodeInput(Object source) throws IOException { 59 if (!(source instanceof ImageInputStream )) { 60 return false; 61 } 62 63 ImageInputStream stream = (ImageInputStream )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 createReaderInstance(Object extension) 73 throws IIOException { 74 return new BMPImageReader(this); 75 } 76 } 77 78 | Popular Tags |