1 /* 2 3 Copyright 2001,2003 The Apache Software Foundation 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 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 package org.apache.batik.ext.awt.image.codec; 19 20 import java.awt.image.Raster; 21 import java.awt.image.RenderedImage; 22 import java.io.IOException; 23 24 /** 25 * An interface describing objects that transform an InputStream into a 26 * BufferedImage or Raster. 27 * 28 */ 29 public interface ImageDecoder { 30 31 /** 32 * Returns the current parameters as an instance of the 33 * ImageDecodeParam interface. Concrete implementations of this 34 * interface will return corresponding concrete implementations of 35 * the ImageDecodeParam interface. For example, a JPEGImageDecoder 36 * will return an instance of JPEGDecodeParam. 37 */ 38 ImageDecodeParam getParam(); 39 40 /** 41 * Sets the current parameters to an instance of the 42 * ImageDecodeParam interface. Concrete implementations 43 * of ImageDecoder may throw a RuntimeException if the 44 * param argument is not an instance of the appropriate 45 * subclass or subinterface. For example, a JPEGImageDecoder 46 * will expect param to be an instance of JPEGDecodeParam. 47 */ 48 void setParam(ImageDecodeParam param); 49 50 /** Returns the SeekableStream associated with this ImageDecoder. */ 51 SeekableStream getInputStream(); 52 53 /** Returns the number of pages present in the current stream. */ 54 int getNumPages() throws IOException; 55 56 /** 57 * Returns a Raster that contains the decoded contents of the 58 * SeekableStream associated with this ImageDecoder. Only 59 * the first page of a multi-page image is decoded. 60 */ 61 Raster decodeAsRaster() throws IOException; 62 63 /** 64 * Returns a Raster that contains the decoded contents of the 65 * SeekableStream associated with this ImageDecoder. 66 * The given page of a multi-page image is decoded. If 67 * the page does not exist, an IOException will be thrown. 68 * Page numbering begins at zero. 69 * 70 * @param page The page to be decoded. 71 */ 72 Raster decodeAsRaster(int page) throws IOException; 73 74 /** 75 * Returns a RenderedImage that contains the decoded contents of the 76 * SeekableStream associated with this ImageDecoder. Only 77 * the first page of a multi-page image is decoded. 78 */ 79 RenderedImage decodeAsRenderedImage() throws IOException; 80 81 /** 82 * Returns a RenderedImage that contains the decoded contents of the 83 * SeekableStream associated with this ImageDecoder. 84 * The given page of a multi-page image is decoded. If 85 * the page does not exist, an IOException will be thrown. 86 * Page numbering begins at zero. 87 * 88 * @param page The page to be decoded. 89 */ 90 RenderedImage decodeAsRenderedImage(int page) throws IOException; 91 } 92