001/* -----------------
002 * ImageEncoder.java
003 * -----------------
004 * (C) Copyright 2004-2008, by Richard Atkinson and Contributors.
005 *
006 * Original Author:  Richard Atkinson;
007 * Contributor(s):   -;
008 */
009
010package jahuwaldt.image.encoders;
011
012import java.awt.image.BufferedImage;
013import java.io.IOException;
014import java.io.OutputStream;
015
016/**
017 * Interface for abstracting different types of image encoders.
018 *
019 * @author Richard Atkinson
020 */
021public interface ImageEncoder {
022
023    /**
024     * Encodes an image in a particular format.
025     *
026     * @param bufferedImage  The image to be encoded.
027     *
028     * @return The byte[] that is the encoded image.
029     *
030     * @throws IOException
031     */
032    public byte[] encode(BufferedImage bufferedImage) throws IOException;
033
034
035    /**
036     * Encodes an image in a particular format and writes it to an OutputStream.
037     *
038     * @param bufferedImage  The image to be encoded.
039     * @param outputStream  The OutputStream to write the encoded image to.
040     * @throws IOException
041     */
042    public void encode(BufferedImage bufferedImage, OutputStream outputStream)
043        throws IOException;
044
045    /**
046     * Get the quality of the image encoding.
047     *
048     * @return A float representing the quality.
049     */
050    public float getQuality();
051
052    /**
053     * Set the quality of the image encoding (not supported by all
054     * ImageEncoders).
055     *
056     * @param quality  A float representing the quality.
057     */
058    public void setQuality(float quality);
059
060    /**
061     * Get whether the encoder should encode alpha transparency.
062     *
063     * @return Whether the encoder is encoding alpha transparency.
064     */
065    public boolean isEncodingAlpha();
066
067    /**
068     * Set whether the encoder should encode alpha transparency (not
069     * supported by all ImageEncoders).
070     *
071     * @param encodingAlpha  Whether the encoder should encode alpha
072     *                       transparency.
073     */
074    public void setEncodingAlpha(boolean encodingAlpha);
075
076}