001 /*---------------- FILE HEADER ------------------------------------------
002
003 This file is part of deegree.
004 Copyright (C) 2001-2008 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 * This class offers three methods to encode a <tt>BuffererImage</tt> to a gif-, tif, bmp, jpeg-
060 * or png-image.
061 *
062 *
063 *
064 * @version $Revision: 1.6 $
065 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
066 * @author last edited by: $Author: bezema $
067 *
068 * @version 1.0. $Revision: 1.6 $, $Date: 2006/12/07 08:54:14 $
069 *
070 * @deprecated use
071 * @see org.deegree.ogcwebservices.wpvs.utils.ImageUtil instead; this class will be removed end of
072 * 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, encodeParam );
104
105 encoder.encode( img );
106 }
107
108 /**
109 *
110 *
111 * @param out
112 * @param img
113 *
114 * @throws IOException
115 */
116 public static synchronized void encodePng( OutputStream out, BufferedImage img )
117 throws IOException {
118 PNGEncodeParam encodeParam = PNGEncodeParam.getDefaultEncodeParam( img );
119
120 if ( encodeParam instanceof PNGEncodeParam.Palette ) {
121 PNGEncodeParam.Palette p = (PNGEncodeParam.Palette) encodeParam;
122 byte[] b = new byte[] { -127 };
123 p.setPaletteTransparency( b );
124 }
125
126 com.sun.media.jai.codec.ImageEncoder encoder = ImageCodec.createImageEncoder( "PNG", out, encodeParam );
127 encoder.encode( img.getData(), img.getColorModel() );
128 }
129
130 /**
131 *
132 *
133 * @param out
134 * @param img
135 *
136 * @throws IOException
137 */
138 public static synchronized void encodeTiff( OutputStream out, BufferedImage img )
139 throws IOException {
140 TIFFEncodeParam encodeParam = new TIFFEncodeParam();
141
142 com.sun.media.jai.codec.ImageEncoder encoder = ImageCodec.createImageEncoder( "TIFF", out, encodeParam );
143
144 encoder.encode( img );
145 }
146
147 /**
148 *
149 *
150 * @param out
151 * @param img
152 *
153 * @throws IOException
154 */
155 public static synchronized void encodeJpeg( OutputStream out, BufferedImage img )
156 throws IOException {
157
158 // encode JPEG
159 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( out );
160 com.sun.image.codec.jpeg.JPEGEncodeParam jpegParams = encoder.getDefaultJPEGEncodeParam( img );
161 jpegParams.setQuality( 0.95f, false );
162 encoder.setJPEGEncodeParam( jpegParams );
163
164 encoder.encode( img );
165 }
166
167 /**
168 *
169 *
170 * @param out
171 * @param img
172 * @param quality
173 *
174 * @throws IOException
175 */
176 public static synchronized void encodeJpeg( OutputStream out, BufferedImage img, float quality )
177 throws IOException {
178
179 // encode JPEG
180 JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( out );
181 com.sun.image.codec.jpeg.JPEGEncodeParam jpegParams = encoder.getDefaultJPEGEncodeParam( img );
182 jpegParams.setQuality( quality, false );
183 encoder.setJPEGEncodeParam( jpegParams );
184
185 encoder.encode( img );
186 }
187 }