blob: 979ef77ce74cfe7df959d1abec793ae93d4d8707 [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * @author Rustem V. Rafikov
19 * @version $Revision: 1.3 $
20 */
21package javax.imageio.spi;
22
23import javax.imageio.stream.ImageInputStream;
24import javax.imageio.ImageTypeSpecifier;
25import javax.imageio.ImageWriter;
26import java.awt.image.RenderedImage;
27import java.io.IOException;
28
29/**
30 * The ImageWriterSpi abstract class is a service provider
31 * interface (SPI) for ImageWriters.
32 */
33public abstract class ImageWriterSpi extends ImageReaderWriterSpi {
34
35 /** The STANDARD_OUTPUT_TYPE contains ImageInputStream.class. */
36 public static final Class[] STANDARD_OUTPUT_TYPE = new Class[] {ImageInputStream.class};
37
38 /** The output types. */
39 protected Class[] outputTypes;
40
41 /** The reader spi names. */
42 protected String[] readerSpiNames;
43
44 /**
45 * Instantiates a new ImageWriterSpi.
46 */
47 protected ImageWriterSpi() {
48 throw new UnsupportedOperationException("Not supported yet");
49 }
50
51 /**
52 * Instantiates a new ImageWriterSpi with the specified parameters.
53 *
54 * @param vendorName the vendor name.
55 * @param version the version.
56 * @param names the format names.
57 * @param suffixes the array of strings representing the file suffixes.
58 * @param MIMETypes the an array of strings representing MIME types.
59 * @param pluginClassName the plugin class name.
60 * @param outputTypes the output types.
61 * @param readerSpiNames the array of strings with class names of all
62 * associated ImageReaders.
63 * @param supportsStandardStreamMetadataFormat the value indicating
64 * if stream metadata can be described by standard metadata format.
65 * @param nativeStreamMetadataFormatName the native stream metadata
66 * format name, returned by getNativeStreamMetadataFormatName.
67 * @param nativeStreamMetadataFormatClassName the native stream
68 * metadata format class name, returned by getNativeStreamMetadataFormat.
69 * @param extraStreamMetadataFormatNames the extra stream metadata
70 * format names, returned by getExtraStreamMetadataFormatNames.
71 * @param extraStreamMetadataFormatClassNames the extra stream metadata
72 * format class names, returned by getStreamMetadataFormat.
73 * @param supportsStandardImageMetadataFormat the value indicating
74 * if image metadata can be described by standard metadata format.
75 * @param nativeImageMetadataFormatName the native image metadata
76 * format name, returned by getNativeImageMetadataFormatName.
77 * @param nativeImageMetadataFormatClassName the native image
78 * metadata format class name, returned by getNativeImageMetadataFormat.
79 * @param extraImageMetadataFormatNames the extra image metadata
80 * format names, returned by getExtraImageMetadataFormatNames.
81 * @param extraImageMetadataFormatClassNames the extra image metadata
82 * format class names, returned by getImageMetadataFormat.
83 */
84 public ImageWriterSpi(String vendorName, String version, String[] names,
85 String[] suffixes, String[] MIMETypes,
86 String pluginClassName,
87 Class[] outputTypes, String[] readerSpiNames,
88 boolean supportsStandardStreamMetadataFormat,
89 String nativeStreamMetadataFormatName,
90 String nativeStreamMetadataFormatClassName,
91 String[] extraStreamMetadataFormatNames,
92 String[] extraStreamMetadataFormatClassNames,
93 boolean supportsStandardImageMetadataFormat,
94 String nativeImageMetadataFormatName,
95 String nativeImageMetadataFormatClassName,
96 String[] extraImageMetadataFormatNames,
97 String[] extraImageMetadataFormatClassNames) {
98 super(vendorName, version, names, suffixes, MIMETypes, pluginClassName,
99 supportsStandardStreamMetadataFormat, nativeStreamMetadataFormatName,
100 nativeStreamMetadataFormatClassName, extraStreamMetadataFormatNames,
101 extraStreamMetadataFormatClassNames, supportsStandardImageMetadataFormat,
102 nativeImageMetadataFormatName, nativeImageMetadataFormatClassName,
103 extraImageMetadataFormatNames, extraImageMetadataFormatClassNames);
104
105 if (outputTypes == null || outputTypes.length == 0) {
106 throw new NullPointerException("output types array cannot be NULL or empty");
107 }
108
109 this.outputTypes = outputTypes;
110 this.readerSpiNames = readerSpiNames;
111 }
112
113 /**
114 * Returns true if the format of the writer's output is lossless.
115 * The default implementation returns true.
116 *
117 * @return true, if a format is lossless, false otherwise.
118 */
119 public boolean isFormatLossless() {
120 return true;
121 }
122
123 /**
124 * Gets an array of Class objects whose types
125 * can be used as output for this writer.
126 *
127 * @return the output types.
128 */
129 public Class[] getOutputTypes() {
130 return outputTypes;
131 }
132
133 /**
134 * Checks whether or not the ImageWriter implementation associated
135 * with this service provider can encode an image with
136 * the specified type.
137 *
138 * @param type the ImageTypeSpecifier.
139 *
140 * @return true, if an image with the specified type can be
141 * encoded, false otherwise.
142 */
143 public abstract boolean canEncodeImage(ImageTypeSpecifier type);
144
145 /**
146 * Checks whether or not the ImageWriter implementation associated
147 * with this service provider can encode the specified RenderedImage.
148 *
149 * @param im the RenderedImage.
150 *
151 * @return true, if RenderedImage can be encoded,
152 * false otherwise.
153 */
154 public boolean canEncodeImage(RenderedImage im) {
155 return canEncodeImage(ImageTypeSpecifier.createFromRenderedImage(im));
156 }
157
158 /**
159 * Returns an instance of the ImageWriter implementation for
160 * this service provider.
161 *
162 * @return the ImageWriter.
163 *
164 * @throws IOException Signals that an I/O exception has occurred.
165 */
166 public ImageWriter createWriterInstance() throws IOException {
167 return createWriterInstance(null);
168 }
169
170 /**
171 * Returns an instance of the ImageWriter implementation for
172 * this service provider.
173 *
174 * @param extension the a plugin specific extension object, or null.
175 *
176 * @return the ImageWriter.
177 *
178 * @throws IOException Signals that an I/O exception has occurred.
179 */
180 public abstract ImageWriter createWriterInstance(Object extension) throws IOException;
181
182 /**
183 * Checks whether or not the specified ImageWriter object
184 * is an instance of the ImageWriter associated with this
185 * service provider or not.
186 *
187 * @param writer the ImageWriter.
188 *
189 * @return true, if the specified ImageWriter object
190 * is an instance of the ImageWriter associated with this
191 * service provider, false otherwise.
192 */
193 public boolean isOwnWriter(ImageWriter writer) {
194 throw new UnsupportedOperationException("Not supported yet");
195 }
196
197 /**
198 * Gets an array of strings with names of the ImageReaderSpi
199 * classes that support the internal metadata representation
200 * used by the ImageWriter of this service provider, or null if
201 * there are no such ImageReaders.
202 *
203 * @return an array of strings with names of the ImageWriterSpi
204 * classes.
205 */
206 public String[] getImageReaderSpiNames() {
207 return readerSpiNames;
208 }
209}