KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > imageio > plugins > png > PNGImageReaderSpi


1 /*
2  * @(#)PNGImageReaderSpi.java 1.25 03/12/19
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.png;
9
10 import java.io.IOException JavaDoc;
11 import java.util.Locale JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import javax.imageio.ImageReader JavaDoc;
14 import javax.imageio.spi.ImageReaderSpi JavaDoc;
15 import javax.imageio.metadata.IIOMetadataFormat JavaDoc;
16 import javax.imageio.metadata.IIOMetadataFormatImpl JavaDoc;
17 import javax.imageio.stream.ImageInputStream JavaDoc;
18
19 /**
20  * @version 0.5
21  */

22 public class PNGImageReaderSpi extends ImageReaderSpi JavaDoc {
23
24     private static final String JavaDoc vendorName = "Sun Microsystems, Inc.";
25
26     private static final String JavaDoc version = "1.0";
27
28     private static final String JavaDoc[] names = { "png" };
29
30     private static final String JavaDoc[] suffixes = { "png" };
31     
32     private static final String JavaDoc[] MIMETypes = { "image/png", "image/x-png" };
33
34     private static final String JavaDoc readerClassName =
35         "com.sun.imageio.plugins.png.PNGImageReader";
36
37     private static final String JavaDoc[] 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 JavaDoc getDescription(Locale JavaDoc locale) {
61         return "Standard PNG image reader";
62     }
63
64     public boolean canDecodeInput(Object JavaDoc input) throws IOException JavaDoc {
65         if (!(input instanceof ImageInputStream JavaDoc)) {
66             return false;
67         }
68
69         ImageInputStream JavaDoc stream = (ImageInputStream JavaDoc)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 JavaDoc createReaderInstance(Object JavaDoc extension) {
86         return new PNGImageReader(this);
87     }
88 }
89
Popular Tags