KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > ext > awt > image > codec > ImageEncoderImpl


1 /*
2
3    Copyright 2001 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.ColorModel JavaDoc;
21 import java.awt.image.Raster JavaDoc;
22 import java.awt.image.RenderedImage JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.OutputStream JavaDoc;
25
26 /**
27  * A partial implementation of the ImageEncoder interface useful for
28  * subclassing.
29  *
30  * <p><b> This class is not a committed part of the JAI API. It may
31  * be removed or changed in future releases of JAI.</b>
32  */

33 public abstract class ImageEncoderImpl implements ImageEncoder {
34     
35     /** The OutputStream associcted with this ImageEncoder. */
36     protected OutputStream JavaDoc output;
37
38     /** The ImageEncodeParam object associcted with this ImageEncoder. */
39     protected ImageEncodeParam param;
40
41     /**
42      * Constructs an ImageEncoderImpl with a given OutputStream
43      * and ImageEncoderParam instance.
44      */

45     public ImageEncoderImpl(OutputStream JavaDoc output,
46                             ImageEncodeParam param) {
47         this.output = output;
48         this.param = param;
49     }
50
51     /**
52      * Returns the current parameters as an instance of the
53      * ImageEncodeParam interface. Concrete implementations of this
54      * interface will return corresponding concrete implementations of
55      * the ImageEncodeParam interface. For example, a JPEGImageEncoder
56      * will return an instance of JPEGEncodeParam.
57      */

58     public ImageEncodeParam getParam() {
59         return param;
60     }
61
62     /**
63      * Sets the current parameters to an instance of the
64      * ImageEncodeParam interface. Concrete implementations
65      * of ImageEncoder may throw a RuntimeException if the
66      * params argument is not an instance of the appropriate
67      * subclass or subinterface. For example, a JPEGImageEncoder
68      * will expect param to be an instance of JPEGEncodeParam.
69      */

70     public void setParam(ImageEncodeParam param) {
71         this.param = param;
72     }
73
74     /** Returns the OutputStream associated with this ImageEncoder. */
75     public OutputStream JavaDoc getOutputStream() {
76         return output;
77     }
78     
79     /**
80      * Encodes a Raster with a given ColorModel and writes the output
81      * to the OutputStream associated with this ImageEncoder.
82      */

83     public void encode(Raster JavaDoc ras, ColorModel JavaDoc cm) throws IOException JavaDoc {
84         RenderedImage JavaDoc im = new SingleTileRenderedImage(ras, cm);
85         encode(im);
86     }
87
88     /**
89      * Encodes a RenderedImage and writes the output to the
90      * OutputStream associated with this ImageEncoder.
91      */

92     public abstract void encode(RenderedImage JavaDoc im) throws IOException JavaDoc;
93 }
94
Popular Tags