1 7 8 package com.sun.imageio.plugins.png; 9 10 import java.io.IOException ; 11 import java.util.Locale ; 12 import java.util.Iterator ; 13 import javax.imageio.ImageReader ; 14 import javax.imageio.spi.ImageReaderSpi ; 15 import javax.imageio.metadata.IIOMetadataFormat ; 16 import javax.imageio.metadata.IIOMetadataFormatImpl ; 17 import javax.imageio.stream.ImageInputStream ; 18 19 22 public class PNGImageReaderSpi extends ImageReaderSpi { 23 24 private static final String vendorName = "Sun Microsystems, Inc."; 25 26 private static final String version = "1.0"; 27 28 private static final String [] names = { "png" }; 29 30 private static final String [] suffixes = { "png" }; 31 32 private static final String [] MIMETypes = { "image/png", "image/x-png" }; 33 34 private static final String readerClassName = 35 "com.sun.imageio.plugins.png.PNGImageReader"; 36 37 private static final String [] writerSpiNames = { 38 "com.sun.imageio.plugins.png.PNGImageWriterSpi" 39 }; 40 41 public PNGImageReaderSpi() { 42 super(vendorName, 43 version, 44 names, 45 suffixes, 46 MIMETypes, 47 readerClassName, 48 STANDARD_INPUT_TYPE, 49 writerSpiNames, 50 false, 51 null, null, 52 null, null, 53 true, 54 PNGMetadata.nativeMetadataFormatName, 55 "com.sun.imageio.plugins.png.PNGMetadataFormat", 56 null, null 57 ); 58 } 59 60 public String getDescription(Locale locale) { 61 return "Standard PNG image reader"; 62 } 63 64 public boolean canDecodeInput(Object input) throws IOException { 65 if (!(input instanceof ImageInputStream )) { 66 return false; 67 } 68 69 ImageInputStream stream = (ImageInputStream )input; 70 byte[] b = new byte[8]; 71 stream.mark(); 72 stream.readFully(b); 73 stream.reset(); 74 75 return (b[0] == (byte)137 && 76 b[1] == (byte)80 && 77 b[2] == (byte)78 && 78 b[3] == (byte)71 && 79 b[4] == (byte)13 && 80 b[5] == (byte)10 && 81 b[6] == (byte)26 && 82 b[7] == (byte)10); 83 } 84 85 public ImageReader createReaderInstance(Object extension) { 86 return new PNGImageReader(this); 87 } 88 } 89 | Popular Tags |