1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
* Created on Nov 17, 2003
*
*/
package jake2.imageio;
import java.io.IOException;
import java.util.Locale;
import javax.imageio.ImageReader;
import javax.imageio.spi.ImageReaderSpi;
import javax.imageio.stream.ImageInputStream;
/**
* @author cwei
*
* put the own ImageReaderSpi class name in the file (relative to classpath):
* <code>
* META-INF/services/javax.imageio.spi.ImageReaderSpi
* </code>
*/
public class PCXImageReaderSpi extends ImageReaderSpi {
static final String vendorName = "jteam@in-chemnitz.de";
static final String version = "1.0_beta";
static final String[] names = { "quake2 pcx" };
static final String[] suffixes = { "pcx" };
static final String[] MIMETypes = { "image/x-quake2-pcx" };
static final String readerClassName = "jake2.imageio.PCXImageReader";
static final String[] writerSpiNames = null; // { "jake2.imageio.PCXImageWriterSpi" };
// Metadata formats, more information below
static final boolean supportsStandardStreamMetadataFormat = false;
static final String nativeStreamMetadataFormatName = null;
static final String nativeStreamMetadataFormatClassName = null;
static final String[] extraStreamMetadataFormatNames = null;
static final String[] extraStreamMetadataFormatClassNames = null;
static final boolean supportsStandardImageMetadataFormat = false;
static final String nativeImageMetadataFormatName =
"jake2.imageio.PCXMetaData_1.0";
static final String nativeImageMetadataFormatClassName = null; // "jake2.imageio.PCXMetadata";
static final String[] extraImageMetadataFormatNames = null;
static final String[] extraImageMetadataFormatClassNames = null;
public PCXImageReaderSpi() {
super(
vendorName,
version,
names,
suffixes,
MIMETypes,
readerClassName,
ImageReaderSpi.STANDARD_INPUT_TYPE,
// Accept ImageInputStreams
writerSpiNames,
supportsStandardStreamMetadataFormat,
nativeStreamMetadataFormatName,
nativeStreamMetadataFormatClassName,
extraStreamMetadataFormatNames,
extraStreamMetadataFormatClassNames,
supportsStandardImageMetadataFormat,
nativeImageMetadataFormatName,
nativeImageMetadataFormatClassName,
extraImageMetadataFormatNames,
extraImageMetadataFormatClassNames);
}
public boolean canDecodeInput(Object source) throws IOException {
if (!(source instanceof ImageInputStream)) {
return false;
}
ImageInputStream stream = (ImageInputStream)source;
byte[] buffer = new byte[PCX.HEADER_SIZE];
try {
stream.mark();
stream.readFully(buffer);
stream.reset();
// buffer will be converted to members and header checked
PCX.Header pcx = new PCX.Header(buffer);
} catch (IllegalArgumentException e) {
return false;
}
return true;
}
public ImageReader createReaderInstance(Object extension)
throws IOException {
return new PCXImageReader(this);
}
/**
* @see javax.imageio.spi.IIOServiceProvider#getDescription(java.util.Locale)
*/
public String getDescription(Locale locale) {
return "id-software's Quake2 pcx format";
}
}
|