001 /*---------------- FILE HEADER ------------------------------------------
002
003 This file is part of deegree.
004 Copyright (C) 2001-2006 by:
005 EXSE, Department of Geography, University of Bonn
006 http://www.giub.uni-bonn.de/deegree/
007 lat/lon GmbH
008 http://www.lat-lon.de
009
010 This library is free software; you can redistribute it and/or
011 modify it under the terms of the GNU Lesser General Public
012 License as published by the Free Software Foundation; either
013 version 2.1 of the License, or (at your option) any later version.
014
015 This library is distributed in the hope that it will be useful,
016 but WITHOUT ANY WARRANTY; without even the implied warranty of
017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
018 Lesser General Public License for more details.
019
020 You should have received a copy of the GNU Lesser General Public
021 License along with this library; if not, write to the Free Software
022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023
024 Contact:
025
026 Andreas Poth
027 lat/lon GmbH
028 Aennchenstr. 19
029 53115 Bonn
030 Germany
031 E-Mail: poth@lat-lon.de
032
033 Prof. Dr. Klaus Greve
034 Department of Geography
035 University of Bonn
036 Meckenheimer Allee 166
037 53115 Bonn
038 Germany
039 E-Mail: greve@giub.uni-bonn.de
040
041
042 ---------------------------------------------------------------------------*/
043 package org.deegree.graphics;
044
045 import java.awt.image.BufferedImage;
046 import java.io.IOException;
047 import java.io.OutputStream;
048
049 import Acme.JPM.Encoders.GifEncoder;
050
051 import com.sun.image.codec.jpeg.JPEGCodec;
052 import com.sun.image.codec.jpeg.JPEGImageEncoder;
053 import com.sun.media.jai.codec.BMPEncodeParam;
054 import com.sun.media.jai.codec.ImageCodec;
055 import com.sun.media.jai.codec.PNGEncodeParam;
056 import com.sun.media.jai.codec.TIFFEncodeParam;
057
058
059 /**
060 * This class offers three methods to encode a <tt>BuffererImage</tt> to
061 * a gif-, tif, bmp, jpeg- or png-image.
062 *
063 *
064 *
065 * @version $Revision: 1.6 $
066 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
067 * @author last edited by: $Author: bezema $
068 *
069 * @version 1.0. $Revision: 1.6 $, $Date: 2006/12/07 08:54:14 $
070 *
071 * @deprecated use @see org.deegree.ogcwebservices.wpvs.utils.ImageUtil instead;
072 * this class will be removed end of 2007
073 *
074 * @since 2.0
075 */
076 public final class Encoders {
077 /**
078 *
079 *
080 * @param out
081 * @param img
082 *
083 * @throws IOException
084 */
085 public static synchronized void encodeGif( OutputStream out, BufferedImage img )
086 throws IOException {
087 GifEncoder encoder = new GifEncoder( img, out );
088 encoder.encode();
089 }
090
091 /**
092 *
093 *
094 * @param out
095 * @param img
096 *
097 * @throws IOException
098 */
099 public static synchronized void encodeBmp( OutputStream out, BufferedImage img )
100 throws IOException {
101 BMPEncodeParam encodeParam = new BMPEncodeParam();
102
103 com.sun.media.jai.codec.ImageEncoder encoder = ImageCodec.createImageEncoder( "BMP", out,
104 encodeParam );
105
106 encoder.encode( img );
107 }
108
109 /**
110 *
111 *
112 * @param out
113 * @param img
114 *
115 * @throws IOException
116 */
117 public static synchronized void encodePng( OutputStream out, BufferedImage img )
118 throws IOException {
119 PNGEncodeParam encodeParam = PNGEncodeParam.getDefaultEncodeParam( img );
120
121 if ( encodeParam instanceof PNGEncodeParam.Palette ) {
122 PNGEncodeParam.Palette p = (PNGEncodeParam.Palette)encodeParam;
123 byte[] b = new byte[]{-127};
124 p.setPaletteTransparency(b);
125 }
126
127 com.sun.media.jai.codec.ImageEncoder encoder =
128 ImageCodec.createImageEncoder("PNG", out, encodeParam);
129 encoder.encode( img.getData(), img.getColorModel() );
130 }
131
132 /**
133 *
134 *
135 * @param out
136 * @param img
137 *
138 * @throws IOException
139 */
140 public static synchronized void encodeTiff( OutputStream out, BufferedImage img )
141 throws IOException {
142 TIFFEncodeParam encodeParam = new TIFFEncodeParam();
143
144 com.sun.media.jai.codec.ImageEncoder encoder = ImageCodec.createImageEncoder( "TIFF", out,
145 encodeParam );
146
147 encoder.encode( img );
148 }
149
150 /**
151 *
152 *
153 * @param out
154 * @param img
155 *
156 * @throws IOException
157 */
158 public static synchronized void encodeJpeg( OutputStream out, BufferedImage img )
159 throws IOException {
160
161 // encode JPEG
162 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( out );
163 com.sun.image.codec.jpeg.JPEGEncodeParam jpegParams = encoder.getDefaultJPEGEncodeParam(
164 img );
165 jpegParams.setQuality( 0.95f, false );
166 encoder.setJPEGEncodeParam( jpegParams );
167
168 encoder.encode( img );
169 }
170
171 /**
172 *
173 *
174 * @param out
175 * @param img
176 * @param quality
177 *
178 * @throws IOException
179 */
180 public static synchronized void encodeJpeg( OutputStream out, BufferedImage img, float quality )
181 throws IOException {
182
183 // encode JPEG
184 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( out );
185 com.sun.image.codec.jpeg.JPEGEncodeParam jpegParams = encoder.getDefaultJPEGEncodeParam(
186 img );
187 jpegParams.setQuality( quality, false );
188 encoder.setJPEGEncodeParam( jpegParams );
189
190 encoder.encode( img );
191 }
192 }
193 /* ********************************************************************
194 Changes to this class. What the people have been up to:
195 $Log: Encoders.java,v $
196 Revision 1.6 2006/12/07 08:54:14 bezema
197 little javadoc update
198
199 Revision 1.5 2006/07/11 09:37:16 poth
200 marked class as deprecated
201
202
203 ********************************************************************** */