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.legend.gif;
06:
07: import java.awt.image.BufferedImage;
08: import java.awt.image.RenderedImage;
09: import java.io.IOException;
10: import java.io.OutputStream;
11:
12: import org.geotools.image.ImageWorker;
13: import org.vfny.geoserver.ServiceException;
14: import org.vfny.geoserver.wms.responses.DefaultRasterLegendProducer;
15: import org.vfny.geoserver.wms.responses.ImageUtils;
16:
17: /**
18: * Producer of legend graphics in image/gif format.
19: *
20: * @author Gabriel Roldan, Axios Engineering
21: * @version $Id: GifLegendGraphicProducer.java 7728 2007-11-09 01:53:31Z groldan $
22: */
23: public class GifLegendGraphicProducer extends
24: DefaultRasterLegendProducer {
25: /** DOCUMENT ME! */
26: static final String MIME_TYPE = "image/gif";
27:
28: /**
29: * Creates a new producer of legends in gif format.
30: */
31: public GifLegendGraphicProducer() {
32: super ();
33: }
34:
35: /**
36: * Encodes on the fly the image generated on {@linkPlain
37: * DefaultRasterLegendProducer#produceLegendGraphic(GetLegendGraphicRequest)}
38: * to <code>out</code> in "image/gif" format.
39: *
40: * @see org.vfny.geoserver.wms.responses.GetLegendGraphicProducer#writeTo(java.io.OutputStream)
41: */
42: public void writeTo(OutputStream out) throws IOException,
43: ServiceException {
44: //GR: shall we add a palette parameter to GetLegendGraphic too?
45: final BufferedImage legendGraphic = getLegendGraphic();
46: RenderedImage forcedIndexed8Bitmask = ImageUtils
47: .forceIndexed8Bitmask(legendGraphic, null);
48: ImageWorker imageWorker = new ImageWorker(forcedIndexed8Bitmask);
49: imageWorker.writeGIF(out, "LZW", 0.75f);
50: }
51:
52: /**
53: * Returns the "image/gif" mime type since that is the only output format
54: * this producer specializes on.
55: *
56: * @return <code>"image/gif"</code>
57: *
58: * @throws IllegalStateException if <code>super.getLegendGraphic() ==
59: * null</code>, to respect the workflow.
60: *
61: * @see org.vfny.geoserver.wms.responses.GetLegendGraphicProducer#getContentType()
62: */
63: public String getContentType() throws IllegalStateException {
64: if (super .getLegendGraphic() == null) {
65: throw new IllegalStateException(
66: "the image was not still produced");
67: }
68:
69: return MIME_TYPE;
70: }
71: }
|