1/* 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 */ 21 22package javax.imageio.spi; 23 24import javax.imageio.stream.ImageInputStream; 25import javax.imageio.ImageTypeSpecifier; 26import javax.imageio.ImageWriter; 27import java.awt.image.RenderedImage; 28import java.io.IOException; 29 30/** 31 * The ImageWriterSpi abstract class is a service provider interface (SPI) for 32 * ImageWriters. 33 * 34 * @since Android 1.0 35 */ 36public abstract class ImageWriterSpi extends ImageReaderWriterSpi { 37 38 /** 39 * The STANDARD_OUTPUT_TYPE contains ImageInputStream.class. 40 */ 41 public static final Class[] STANDARD_OUTPUT_TYPE = new Class[] { 42 ImageInputStream.class 43 }; 44 45 /** 46 * The output types. 47 */ 48 protected Class[] outputTypes; 49 50 /** 51 * The reader SPI names. 52 */ 53 protected String[] readerSpiNames; 54 55 /** 56 * Instantiates a new ImageWriterSpi. 57 */ 58 protected ImageWriterSpi() { 59 throw new UnsupportedOperationException("Not supported yet"); 60 } 61 62 /** 63 * Instantiates a new ImageWriterSpi with the specified parameters. 64 * 65 * @param vendorName 66 * the vendor name. 67 * @param version 68 * the version. 69 * @param names 70 * the format names. 71 * @param suffixes 72 * the array of strings representing the file suffixes. 73 * @param MIMETypes 74 * the an array of strings representing MIME types. 75 * @param pluginClassName 76 * the plug-in class name. 77 * @param outputTypes 78 * the output types. 79 * @param readerSpiNames 80 * the array of strings with class names of all associated 81 * ImageReaders. 82 * @param supportsStandardStreamMetadataFormat 83 * the value indicating if stream metadata can be described by 84 * standard metadata format. 85 * @param nativeStreamMetadataFormatName 86 * the native stream metadata format name, returned by 87 * getNativeStreamMetadataFormatName. 88 * @param nativeStreamMetadataFormatClassName 89 * the native stream metadata format class name, returned by 90 * getNativeStreamMetadataFormat. 91 * @param extraStreamMetadataFormatNames 92 * the extra stream metadata format names, returned by 93 * getExtraStreamMetadataFormatNames. 94 * @param extraStreamMetadataFormatClassNames 95 * the extra stream metadata format class names, returned by 96 * getStreamMetadataFormat. 97 * @param supportsStandardImageMetadataFormat 98 * the value indicating if image metadata can be described by 99 * standard metadata format. 100 * @param nativeImageMetadataFormatName 101 * the native image metadata format name, returned by 102 * getNativeImageMetadataFormatName. 103 * @param nativeImageMetadataFormatClassName 104 * the native image metadata format class name, returned by 105 * getNativeImageMetadataFormat. 106 * @param extraImageMetadataFormatNames 107 * the extra image metadata format names, returned by 108 * getExtraImageMetadataFormatNames. 109 * @param extraImageMetadataFormatClassNames 110 * the extra image metadata format class names, returned by 111 * getImageMetadataFormat. 112 */ 113 public ImageWriterSpi(String vendorName, String version, String[] names, String[] suffixes, 114 String[] MIMETypes, String pluginClassName, Class[] outputTypes, 115 String[] readerSpiNames, boolean supportsStandardStreamMetadataFormat, 116 String nativeStreamMetadataFormatName, String nativeStreamMetadataFormatClassName, 117 String[] extraStreamMetadataFormatNames, String[] extraStreamMetadataFormatClassNames, 118 boolean supportsStandardImageMetadataFormat, String nativeImageMetadataFormatName, 119 String nativeImageMetadataFormatClassName, String[] extraImageMetadataFormatNames, 120 String[] extraImageMetadataFormatClassNames) { 121 super(vendorName, version, names, suffixes, MIMETypes, pluginClassName, 122 supportsStandardStreamMetadataFormat, nativeStreamMetadataFormatName, 123 nativeStreamMetadataFormatClassName, extraStreamMetadataFormatNames, 124 extraStreamMetadataFormatClassNames, supportsStandardImageMetadataFormat, 125 nativeImageMetadataFormatName, nativeImageMetadataFormatClassName, 126 extraImageMetadataFormatNames, extraImageMetadataFormatClassNames); 127 128 if (outputTypes == null || outputTypes.length == 0) { 129 throw new NullPointerException("output types array cannot be NULL or empty"); 130 } 131 132 this.outputTypes = outputTypes; 133 this.readerSpiNames = readerSpiNames; 134 } 135 136 /** 137 * Returns true if the format of the writer's output is lossless. The 138 * default implementation returns true. 139 * 140 * @return true, if a format is lossless, false otherwise. 141 */ 142 public boolean isFormatLossless() { 143 return true; 144 } 145 146 /** 147 * Gets an array of Class objects whose types can be used as output for this 148 * writer. 149 * 150 * @return the output types. 151 */ 152 public Class[] getOutputTypes() { 153 return outputTypes; 154 } 155 156 /** 157 * Checks whether or not the ImageWriter implementation associated with this 158 * service provider can encode an image with the specified type. 159 * 160 * @param type 161 * the ImageTypeSpecifier. 162 * @return true, if an image with the specified type can be encoded, false 163 * otherwise. 164 */ 165 public abstract boolean canEncodeImage(ImageTypeSpecifier type); 166 167 /** 168 * Checks whether or not the ImageWriter implementation associated with this 169 * service provider can encode the specified RenderedImage. 170 * 171 * @param im 172 * the RenderedImage. 173 * @return true, if RenderedImage can be encoded, false otherwise. 174 */ 175 public boolean canEncodeImage(RenderedImage im) { 176 return canEncodeImage(ImageTypeSpecifier.createFromRenderedImage(im)); 177 } 178 179 /** 180 * Returns an instance of the ImageWriter implementation for this service 181 * provider. 182 * 183 * @return the ImageWriter. 184 * @throws IOException 185 * if an I/O exception has occurred. 186 */ 187 public ImageWriter createWriterInstance() throws IOException { 188 return createWriterInstance(null); 189 } 190 191 /** 192 * Returns an instance of the ImageWriter implementation for this service 193 * provider. 194 * 195 * @param extension 196 * the a plug-in specific extension object, or null. 197 * @return the ImageWriter. 198 * @throws IOException 199 * if an I/O exception has occurred. 200 */ 201 public abstract ImageWriter createWriterInstance(Object extension) throws IOException; 202 203 /** 204 * Checks whether or not the specified ImageWriter object is an instance of 205 * the ImageWriter associated with this service provider or not. 206 * 207 * @param writer 208 * the ImageWriter. 209 * @return true, if the specified ImageWriter object is an instance of the 210 * ImageWriter associated with this service provider, false 211 * otherwise. 212 */ 213 public boolean isOwnWriter(ImageWriter writer) { 214 throw new UnsupportedOperationException("Not supported yet"); 215 } 216 217 /** 218 * Gets an array of strings with names of the ImageReaderSpi classes that 219 * support the internal metadata representation used by the ImageWriter of 220 * this service provider, or null if there are no such ImageReaders. 221 * 222 * @return the array of strings with names of the ImageWriterSpi classes. 223 */ 224 public String[] getImageReaderSpiNames() { 225 return readerSpiNames; 226 } 227} 228