Path: blob/master/src/java.desktop/share/classes/javax/imageio/ImageTranscoder.java
41152 views
/*1* Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.imageio;2627import javax.imageio.metadata.IIOMetadata;2829/**30* An interface providing metadata transcoding capability.31*32* <p> Any image may be transcoded (written to a different format33* than the one it was originally stored in) simply by performing34* a read operation followed by a write operation. However, loss35* of data may occur in this process due to format differences.36*37* <p> In general, the best results will be achieved when38* format-specific metadata objects can be created to encapsulate as39* much information about the image and its associated metadata as40* possible, in terms that are understood by the specific41* {@code ImageWriter} used to perform the encoding.42*43* <p> An {@code ImageTranscoder} may be used to convert the44* {@code IIOMetadata} objects supplied by the45* {@code ImageReader} (representing per-stream and per-image46* metadata) into corresponding objects suitable for encoding by a47* particular {@code ImageWriter}. In the case where the methods48* of this interface are being called directly on an49* {@code ImageWriter}, the output will be suitable for that50* writer.51*52* <p> The internal details of converting an {@code IIOMetadata}53* object into a writer-specific format will vary according to the54* context of the operation. Typically, an {@code ImageWriter}55* will inspect the incoming object to see if it implements additional56* interfaces with which the writer is familiar. This might be the57* case, for example, if the object was obtained by means of a read58* operation on a reader plug-in written by the same vendor as the59* writer. In this case, the writer may access the incoming object by60* means of its plug-in specific interfaces. In this case, the61* re-encoding may be close to lossless if the image file format is62* kept constant. If the format is changing, the writer may still63* attempt to preserve as much information as possible.64*65* <p> If the incoming object does not implement any additional66* interfaces known to the writer, the writer has no choice but to67* access it via the standard {@code IIOMetadata} interfaces such68* as the tree view provided by {@code IIOMetadata.getAsTree}.69* In this case, there is likely to be significant loss of70* information.71*72* <p> An independent {@code ImageTranscoder} essentially takes73* on the same role as the writer plug-in in the above examples. It74* must be familiar with the private interfaces used by both the75* reader and writer plug-ins, and manually instantiate an object that76* will be usable by the writer. The resulting metadata objects may77* be used by the writer directly.78*79* <p> No independent implementations of {@code ImageTranscoder}80* are provided as part of the standard API. Instead, the intention81* of this interface is to provide a way for implementations to be82* created and discovered by applications as the need arises.83*84*/85public interface ImageTranscoder {8687/**88* Returns an {@code IIOMetadata} object that may be used for89* encoding and optionally modified using its document interfaces90* or other interfaces specific to the writer plug-in that will be91* used for encoding.92*93* <p> An optional {@code ImageWriteParam} may be supplied94* for cases where it may affect the structure of the stream95* metadata.96*97* <p> If the supplied {@code ImageWriteParam} contains98* optional setting values not understood by this writer or99* transcoder, they will be ignored.100*101* @param inData an {@code IIOMetadata} object representing102* stream metadata, used to initialize the state of the returned103* object.104* @param param an {@code ImageWriteParam} that will be used to105* encode the image, or {@code null}.106*107* @return an {@code IIOMetadata} object, or108* {@code null} if the plug-in does not provide metadata109* encoding capabilities.110*111* @exception IllegalArgumentException if {@code inData} is112* {@code null}.113*/114IIOMetadata convertStreamMetadata(IIOMetadata inData,115ImageWriteParam param);116117/**118* Returns an {@code IIOMetadata} object that may be used for119* encoding and optionally modified using its document interfaces120* or other interfaces specific to the writer plug-in that will be121* used for encoding.122*123* <p> An optional {@code ImageWriteParam} may be supplied124* for cases where it may affect the structure of the image125* metadata.126*127* <p> If the supplied {@code ImageWriteParam} contains128* optional setting values not understood by this writer or129* transcoder, they will be ignored.130*131* @param inData an {@code IIOMetadata} object representing132* image metadata, used to initialize the state of the returned133* object.134* @param imageType an {@code ImageTypeSpecifier} indicating135* the layout and color information of the image with which the136* metadata will be associated.137* @param param an {@code ImageWriteParam} that will be used to138* encode the image, or {@code null}.139*140* @return an {@code IIOMetadata} object,141* or {@code null} if the plug-in does not provide142* metadata encoding capabilities.143*144* @exception IllegalArgumentException if either of145* {@code inData} or {@code imageType} is146* {@code null}.147*/148IIOMetadata convertImageMetadata(IIOMetadata inData,149ImageTypeSpecifier imageType,150ImageWriteParam param);151}152153154