01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.vfny.geoserver.wms.responses.map.jpeg;
06:
07: import org.geotools.image.ImageWorker;
08: import org.vfny.geoserver.global.WMS;
09: import org.vfny.geoserver.wms.responses.DefaultRasterMapProducer;
10: import java.awt.image.BufferedImage;
11: import java.awt.image.IndexColorModel;
12: import java.awt.image.RenderedImage;
13: import java.io.IOException;
14: import java.io.OutputStream;
15: import java.util.logging.Level;
16: import java.util.logging.Logger;
17:
18: /**
19: * Map producer for JPEG image format.
20: *
21: * @author Simone Giannecchini
22: * @since 1.4.x
23: *
24: */
25: public final class JPEGMapProducer extends DefaultRasterMapProducer {
26: protected RenderedImage prepareImage(int width, int height,
27: IndexColorModel palette, boolean transparent) {
28: //there is no transparency in JPEG anyway :-)
29: transparent = false;
30: return super .prepareImage(width, height, palette, transparent);
31: }
32:
33: /** Logger. */
34: private final static Logger LOGGER = org.geotools.util.logging.Logging
35: .getLogger(JPEGMapProducer.class.toString());
36:
37: /** JPEG Native Acceleration Mode * */
38: private Boolean JPEGNativeAcc;
39:
40: public JPEGMapProducer(String outputFormat, WMS wms) {
41: super (outputFormat, wms);
42: /**
43: * TODO To check Native Acceleration mode use the following variable
44: */
45: this .JPEGNativeAcc = wms.getGeoServer()
46: .getJPEGNativeAcceleration();
47: }
48:
49: public void formatImageOutputStream(RenderedImage image,
50: OutputStream outStream) throws IOException {
51: if (LOGGER.isLoggable(Level.FINE)) {
52: LOGGER.fine("About to write a JPEG image.");
53: }
54:
55: new ImageWorker(image).writeJPEG(outStream, "JPEG", 0.75f,
56: JPEGNativeAcc.booleanValue());
57:
58: if (LOGGER.isLoggable(Level.FINE)) {
59: LOGGER.fine("Writing a JPEG done!!!");
60: }
61: }
62:
63: public String getContentDisposition() {
64: // can be null
65: return null;
66: }
67: }
|