01: /*
02: * $RCSfile: ImageEncoderImpl.java,v $
03: *
04: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
05: *
06: * Use is subject to license terms.
07: *
08: * $Revision: 1.1 $
09: * $Date: 2005/02/11 04:55:31 $
10: * $State: Exp $
11: */
12: package com.sun.media.jai.codec;
13:
14: import java.awt.image.ColorModel;
15: import java.awt.image.Raster;
16: import java.awt.image.RenderedImage;
17: import java.io.IOException;
18: import java.io.OutputStream;
19: import com.sun.media.jai.codecimpl.SingleTileRenderedImage;
20:
21: /**
22: * A partial implementation of the ImageEncoder interface useful for
23: * subclassing.
24: *
25: * <p><b> This class is not a committed part of the JAI API. It may
26: * be removed or changed in future releases of JAI.</b>
27: */
28: public abstract class ImageEncoderImpl implements ImageEncoder {
29:
30: /** The OutputStream associcted with this ImageEncoder. */
31: protected OutputStream output;
32:
33: /** The ImageEncodeParam object associcted with this ImageEncoder. */
34: protected ImageEncodeParam param;
35:
36: /**
37: * Constructs an ImageEncoderImpl with a given OutputStream
38: * and ImageEncoderParam instance.
39: */
40: public ImageEncoderImpl(OutputStream output, ImageEncodeParam param) {
41: this .output = output;
42: this .param = param;
43: }
44:
45: /**
46: * Returns the current parameters as an instance of the
47: * ImageEncodeParam interface. Concrete implementations of this
48: * interface will return corresponding concrete implementations of
49: * the ImageEncodeParam interface. For example, a JPEGImageEncoder
50: * will return an instance of JPEGEncodeParam.
51: */
52: public ImageEncodeParam getParam() {
53: return param;
54: }
55:
56: /**
57: * Sets the current parameters to an instance of the
58: * ImageEncodeParam interface. Concrete implementations
59: * of ImageEncoder may throw a RuntimeException if the
60: * params argument is not an instance of the appropriate
61: * subclass or subinterface. For example, a JPEGImageEncoder
62: * will expect param to be an instance of JPEGEncodeParam.
63: */
64: public void setParam(ImageEncodeParam param) {
65: this .param = param;
66: }
67:
68: /** Returns the OutputStream associated with this ImageEncoder. */
69: public OutputStream getOutputStream() {
70: return output;
71: }
72:
73: /**
74: * Encodes a Raster with a given ColorModel and writes the output
75: * to the OutputStream associated with this ImageEncoder.
76: */
77: public void encode(Raster ras, ColorModel cm) throws IOException {
78: RenderedImage im = new SingleTileRenderedImage(ras, cm);
79: encode(im);
80: }
81:
82: /**
83: * Encodes a RenderedImage and writes the output to the
84: * OutputStream associated with this ImageEncoder.
85: */
86: public abstract void encode(RenderedImage im) throws IOException;
87: }
|