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,
086: BufferedImage img) 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,
100: BufferedImage img) throws IOException {
101: BMPEncodeParam encodeParam = new BMPEncodeParam();
102:
103: com.sun.media.jai.codec.ImageEncoder encoder = ImageCodec
104: .createImageEncoder("BMP", out, 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,
118: BufferedImage img) throws IOException {
119: PNGEncodeParam encodeParam = PNGEncodeParam
120: .getDefaultEncodeParam(img);
121:
122: if (encodeParam instanceof PNGEncodeParam.Palette) {
123: PNGEncodeParam.Palette p = (PNGEncodeParam.Palette) encodeParam;
124: byte[] b = new byte[] { -127 };
125: p.setPaletteTransparency(b);
126: }
127:
128: com.sun.media.jai.codec.ImageEncoder encoder = ImageCodec
129: .createImageEncoder("PNG", out, encodeParam);
130: encoder.encode(img.getData(), img.getColorModel());
131: }
132:
133: /**
134: *
135: *
136: * @param out
137: * @param img
138: *
139: * @throws IOException
140: */
141: public static synchronized void encodeTiff(OutputStream out,
142: BufferedImage img) throws IOException {
143: TIFFEncodeParam encodeParam = new TIFFEncodeParam();
144:
145: com.sun.media.jai.codec.ImageEncoder encoder = ImageCodec
146: .createImageEncoder("TIFF", out, encodeParam);
147:
148: encoder.encode(img);
149: }
150:
151: /**
152: *
153: *
154: * @param out
155: * @param img
156: *
157: * @throws IOException
158: */
159: public static synchronized void encodeJpeg(OutputStream out,
160: BufferedImage img) throws IOException {
161:
162: // encode JPEG
163: JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
164: com.sun.image.codec.jpeg.JPEGEncodeParam jpegParams = encoder
165: .getDefaultJPEGEncodeParam(img);
166: jpegParams.setQuality(0.95f, false);
167: encoder.setJPEGEncodeParam(jpegParams);
168:
169: encoder.encode(img);
170: }
171:
172: /**
173: *
174: *
175: * @param out
176: * @param img
177: * @param quality
178: *
179: * @throws IOException
180: */
181: public static synchronized void encodeJpeg(OutputStream out,
182: BufferedImage img, float quality) throws IOException {
183:
184: // encode JPEG
185: JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
186: com.sun.image.codec.jpeg.JPEGEncodeParam jpegParams = encoder
187: .getDefaultJPEGEncodeParam(img);
188: jpegParams.setQuality(quality, false);
189: encoder.setJPEGEncodeParam(jpegParams);
190:
191: encoder.encode(img);
192: }
193: }
|