author | bae |
Fri, 08 May 2009 15:38:21 +0400 | |
changeset 3447 | 7d593a130994 |
parent 2 | 90ce3da70b43 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2 |
* Copyright 2000-2005 Sun Microsystems, Inc. All Rights Reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.imageio.plugins.png; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.util.Locale; |
|
30 |
import java.util.Iterator; |
|
31 |
import javax.imageio.ImageReader; |
|
32 |
import javax.imageio.spi.ImageReaderSpi; |
|
33 |
import javax.imageio.metadata.IIOMetadataFormat; |
|
34 |
import javax.imageio.metadata.IIOMetadataFormatImpl; |
|
35 |
import javax.imageio.stream.ImageInputStream; |
|
36 |
||
37 |
public class PNGImageReaderSpi extends ImageReaderSpi { |
|
38 |
||
39 |
private static final String vendorName = "Sun Microsystems, Inc."; |
|
40 |
||
41 |
private static final String version = "1.0"; |
|
42 |
||
43 |
private static final String[] names = { "png", "PNG" }; |
|
44 |
||
45 |
private static final String[] suffixes = { "png" }; |
|
46 |
||
47 |
private static final String[] MIMETypes = { "image/png", "image/x-png" }; |
|
48 |
||
49 |
private static final String readerClassName = |
|
50 |
"com.sun.imageio.plugins.png.PNGImageReader"; |
|
51 |
||
52 |
private static final String[] writerSpiNames = { |
|
53 |
"com.sun.imageio.plugins.png.PNGImageWriterSpi" |
|
54 |
}; |
|
55 |
||
56 |
public PNGImageReaderSpi() { |
|
57 |
super(vendorName, |
|
58 |
version, |
|
59 |
names, |
|
60 |
suffixes, |
|
61 |
MIMETypes, |
|
62 |
readerClassName, |
|
3447
7d593a130994
6656625: ImageReaderSpi.STANDARD_INPUT_TYPE/ImageWriterSpi.STANDARD_OUTPUT_TYPE are mutable static (findbugs)
bae
parents:
2
diff
changeset
|
63 |
new Class[] { ImageInputStream.class }, |
2 | 64 |
writerSpiNames, |
65 |
false, |
|
66 |
null, null, |
|
67 |
null, null, |
|
68 |
true, |
|
69 |
PNGMetadata.nativeMetadataFormatName, |
|
70 |
"com.sun.imageio.plugins.png.PNGMetadataFormat", |
|
71 |
null, null |
|
72 |
); |
|
73 |
} |
|
74 |
||
75 |
public String getDescription(Locale locale) { |
|
76 |
return "Standard PNG image reader"; |
|
77 |
} |
|
78 |
||
79 |
public boolean canDecodeInput(Object input) throws IOException { |
|
80 |
if (!(input instanceof ImageInputStream)) { |
|
81 |
return false; |
|
82 |
} |
|
83 |
||
84 |
ImageInputStream stream = (ImageInputStream)input; |
|
85 |
byte[] b = new byte[8]; |
|
86 |
stream.mark(); |
|
87 |
stream.readFully(b); |
|
88 |
stream.reset(); |
|
89 |
||
90 |
return (b[0] == (byte)137 && |
|
91 |
b[1] == (byte)80 && |
|
92 |
b[2] == (byte)78 && |
|
93 |
b[3] == (byte)71 && |
|
94 |
b[4] == (byte)13 && |
|
95 |
b[5] == (byte)10 && |
|
96 |
b[6] == (byte)26 && |
|
97 |
b[7] == (byte)10); |
|
98 |
} |
|
99 |
||
100 |
public ImageReader createReaderInstance(Object extension) { |
|
101 |
return new PNGImageReader(this); |
|
102 |
} |
|
103 |
} |