001: /***********************************************************************************************
002: * Copyright 2002 (C) Nathaniel G. Auvil. All Rights Reserved.
003: *
004: * Redistribution and use of this software and associated documentation ("Software"), with or
005: * without modification, are permitted provided that the following conditions are met:
006: *
007: * 1. Redistributions of source code must retain copyright statements and notices.
008: * Redistributions must also contain a copy of this document.
009: *
010: * 2. Redistributions in binary form must reproduce the above copyright notice, this list of
011: * conditions and the following disclaimer in the documentation and/or other materials
012: * provided with the distribution.
013: *
014: * 3. The name "jCharts" or "Nathaniel G. Auvil" must not be used to endorse or promote
015: * products derived from this Software without prior written permission of Nathaniel G.
016: * Auvil. For written permission, please contact nathaniel_auvil@users.sourceforge.net
017: *
018: * 4. Products derived from this Software may not be called "jCharts" nor may "jCharts" appear
019: * in their names without prior written permission of Nathaniel G. Auvil. jCharts is a
020: * registered trademark of Nathaniel G. Auvil.
021: *
022: * 5. Due credit should be given to the jCharts Project (http://jcharts.sourceforge.net/).
023: *
024: * THIS SOFTWARE IS PROVIDED BY Nathaniel G. Auvil AND CONTRIBUTORS ``AS IS'' AND ANY
025: * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
026: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * jCharts OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
028: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
029: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
030: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,STRICT LIABILITY, OR TORT
031: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
032: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
033: ************************************************************************************************/package org.krysalis.jcharts.encoders;
034:
035: import com.sun.image.codec.jpeg.JPEGCodec;
036: import com.sun.image.codec.jpeg.JPEGEncodeParam;
037: import com.sun.image.codec.jpeg.JPEGImageEncoder;
038: import org.krysalis.jcharts.Chart;
039: import org.krysalis.jcharts.chartData.ChartDataException;
040: import org.krysalis.jcharts.properties.PropertyException;
041:
042: import java.awt.image.BufferedImage;
043: import java.awt.image.BufferedImageOp;
044: import java.awt.image.ConvolveOp;
045: import java.awt.image.Kernel;
046: import java.io.IOException;
047: import java.io.OutputStream;
048:
049: /*************************************************************************************
050: * Provided for backwards compatibility for jdk 1.3
051: *
052: * @author Nathaniel Auvil
053: * @version $Id: JPEGEncoder13.java,v 1.2 2003/05/26 13:40:20 nathaniel_auvil Exp $
054: ************************************************************************************/
055: public class JPEGEncoder13 {
056:
057: /******************************************************************************************
058: *
059: *
060: ******************************************************************************************/
061: private JPEGEncoder13() throws Exception {
062: throw new Exception(
063: "No need to create an instance of this class!");
064: }
065:
066: /******************************************************************************************
067: * Encodes the chart to a JPEG format. If you are generating large dimension images, the file
068: * size can get quite large. You can try decreasing the quality to decrease the file size.
069: *
070: * @param outputStream
071: * @param quality float value from 0.0f(worst image quality) - 1.0f(best image quality)
072: * @throws ChartDataException
073: * @throws PropertyException
074: * @throws IOException
075: *******************************************************************************************/
076: public static void encode(Chart chart, float quality,
077: OutputStream outputStream) throws ChartDataException,
078: PropertyException, IOException {
079: BufferedImage bufferedImage = BinaryEncoderUtil.render(chart);
080:
081: float[] sharpKernel = { 0.0f, -1.0f, 0.0f, -1.0f, 5.0f, -1.0f,
082: 0.0f, -1.0f, 0.0f };
083:
084: BufferedImageOp sharpen = new ConvolveOp(new Kernel(3, 3,
085: sharpKernel), ConvolveOp.EDGE_NO_OP, null);
086: BufferedImage sharp = sharpen.filter(bufferedImage, null);
087:
088: //---create an encoder object for the BufferedImage.
089: JPEGEncodeParam jpegParam = JPEGCodec
090: .getDefaultJPEGEncodeParam(sharp);
091: jpegParam.setQuality(quality, false);
092:
093: JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(
094: outputStream, jpegParam);
095:
096: //---encode the BufferedImage.
097: jpeg.encode(bufferedImage);
098:
099: }
100: }
|