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.png;
06:
07: import java.awt.image.IndexColorModel;
08: import java.awt.image.RenderedImage;
09: import java.io.IOException;
10: import java.io.OutputStream;
11: import java.util.logging.Level;
12: import java.util.logging.Logger;
13:
14: import org.geotools.image.ImageWorker;
15: import org.vfny.geoserver.global.WMS;
16: import org.vfny.geoserver.wms.WmsException;
17: import org.vfny.geoserver.wms.responses.DefaultRasterMapProducer;
18:
19: /**
20: * Handles a GetMap request that spects a map in GIF format.
21: *
22: * @author Simone Giannecchini
23: * @author Didier Richard
24: * @version $Id
25: */
26: public class PNGMapProducer extends DefaultRasterMapProducer {
27: /** Logger */
28: private static final Logger LOGGER = org.geotools.util.logging.Logging
29: .getLogger("org.vfny.geoserver.wms.responses.map.png");
30:
31: /** PNG Native Acceleration Mode * */
32: protected Boolean PNGNativeAcc;
33:
34: public PNGMapProducer(String format, String mime_type, WMS wms) {
35: super (format, mime_type, wms);
36: this .PNGNativeAcc = wms.getGeoServer()
37: .getPNGNativeAcceleration();
38: }
39:
40: /**
41: * Transforms the rendered image into the appropriate format, streaming to
42: * the output stream.
43: * @param image
44: * The image to be formatted.
45: * @param outStream
46: * The stream to write to.
47: *
48: * @throws WmsException
49: * not really.
50: * @throws IOException
51: * if encoding to <code>outStream</code> fails.
52: */
53: public void formatImageOutputStream(RenderedImage image,
54: OutputStream outStream) throws WmsException, IOException {
55: // /////////////////////////////////////////////////////////////////
56: //
57: // Reformatting this image for png
58: //
59: // /////////////////////////////////////////////////////////////////
60: if (LOGGER.isLoggable(Level.FINE)) {
61: LOGGER.fine("Writing png image ...");
62: }
63:
64: if (this .format.equalsIgnoreCase("image/png8")
65: || (this .mapContext.getPaletteInverter() != null)) {
66: image = forceIndexed8Bitmask(image);
67: }
68:
69: new ImageWorker(image).writePNG(outStream, "FILTERED", 0.5f,
70: PNGNativeAcc.booleanValue(),
71: image.getColorModel() instanceof IndexColorModel);
72:
73: if (LOGGER.isLoggable(Level.FINE)) {
74: LOGGER.fine("Writing png image ... done!");
75: }
76: }
77:
78: public String getContentDisposition() {
79: // can be null
80: return null;
81: }
82: }
|