Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/ydp/jai/ImageEncoderImpl.java


1   /*
2    * The contents of this file are subject to the  JAVA ADVANCED IMAGING
3    * SAMPLE INPUT-OUTPUT CODECS AND WIDGET HANDLING SOURCE CODE  License
4    * Version 1.0 (the "License"); You may not use this file except in
5    * compliance with the License. You may obtain a copy of the License at
6    * http://www.sun.com/software/imaging/JAI/index.html
7    *
8    * Software distributed under the License is distributed on an "AS IS"
9    * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
10   * the License for the specific language governing rights and limitations
11   * under the License. 
12   *
13   * The Original Code is JAVA ADVANCED IMAGING SAMPLE INPUT-OUTPUT CODECS
14   * AND WIDGET HANDLING SOURCE CODE. 
15   * The Initial Developer of the Original Code is: Sun Microsystems, Inc..
16   * Portions created by: _______________________________________
17   * are Copyright (C): _______________________________________
18   * All Rights Reserved.
19   * Contributor(s): _______________________________________
20   */
21  
22  package org.ydp.jai;
23  
24  import java.awt.image.ColorModel;
25  import java.awt.image.Raster;
26  import java.awt.image.RenderedImage;
27  import java.io.IOException;
28  import java.io.OutputStream;
29  
30  /**
31   * A partial implementation of the ImageEncoder interface useful for
32   * subclassing.
33   *
34   * <p><b> This class is not a committed part of the JAI API.  It may
35   * be removed or changed in future releases of JAI.</b>
36   */
37  public abstract class ImageEncoderImpl implements ImageEncoder {
38      
39      /** The OutputStream associcted with this ImageEncoder. */
40      protected OutputStream output;
41  
42      /** The ImageEncodeParam object associcted with this ImageEncoder. */
43      protected ImageEncodeParam param;
44  
45      /**
46       * Constructs an ImageEncoderImpl with a given OutputStream
47       * and ImageEncoderParam instance.
48       */
49      public ImageEncoderImpl(OutputStream output,
50                              ImageEncodeParam param) {
51          this.output = output;
52          this.param = param;
53      }
54  
55      /**
56       * Returns the current parameters as an instance of the
57       * ImageEncodeParam interface.  Concrete implementations of this
58       * interface will return corresponding concrete implementations of
59       * the ImageEncodeParam interface.  For example, a JPEGImageEncoder
60       * will return an instance of JPEGEncodeParam.
61       */
62      public ImageEncodeParam getParam() {
63          return param;
64      }
65  
66      /**
67       * Sets the current parameters to an instance of the 
68       * ImageEncodeParam interface.  Concrete implementations
69       * of ImageEncoder may throw a RuntimeException if the
70       * params argument is not an instance of the appropriate
71       * subclass or subinterface.  For example, a JPEGImageEncoder
72       * will expect param to be an instance of JPEGEncodeParam.
73       */
74      public void setParam(ImageEncodeParam param) {
75          this.param = param;
76      }
77  
78      /** Returns the OutputStream associated with this ImageEncoder. */
79      public OutputStream getOutputStream() {
80          return output;
81      }
82      
83      /**
84       * Encodes a Raster with a given ColorModel and writes the output
85       * to the OutputStream associated with this ImageEncoder.
86       */
87      public void encode(Raster ras, ColorModel cm) throws IOException {
88          RenderedImage im = new SingleTileRenderedImage(ras, cm);
89          encode(im);
90      }
91  
92      /**
93       * Encodes a RenderedImage and writes the output to the
94       * OutputStream associated with this ImageEncoder.
95       */
96      public abstract void encode(RenderedImage im) throws IOException;
97  }