NextApp Echo
App Container 1.0.5

nextapp.echoservlet.image
Class PngEncoder

java.lang.Object
  extended bynextapp.echoservlet.image.PngEncoder

public class PngEncoder
extends java.lang.Object

Encodes a java.awt.Image into PNG format. For more information on the PNG specification, see the W3C PNG page at http://www.w3.org/TR/REC-png.html.


Nested Class Summary
private static class PngEncoder.AverageFilter
          An implementation of an "Average" filter.
private  class PngEncoder.ByteTranslator
          Translates byte-based rasters.
static interface PngEncoder.Filter
          An interface for PNG filters.
private  class PngEncoder.IntTranslator
          Translates integer-based rasters.
private static class PngEncoder.PaethFilter
          An implementation of a "Paeth" filter.
private static class PngEncoder.SubFilter
          An implementation of a "Sub" filter.
(package private) static interface PngEncoder.Translator
          An interface for translators, which translate pixel data from a writable raster into an R/G/B/A ordering required by the PNG specification.
private static class PngEncoder.UpFilter
          An implementation of an "Up" filter.
 
Field Summary
static PngEncoder.Filter AVERAGE_FILTER
           
private static int AVERAGE_FILTER_TYPE
           
private static byte BIT_DEPTH
           
private static byte COLOR_TYPE_INDEXED
           
private static byte COLOR_TYPE_RGB
           
private static byte COLOR_TYPE_RGBA
           
private  int compressionLevel
           
private  boolean encodeAlpha
           
private  PngEncoder.Filter filter
           
private  int height
           
private static byte[] IDAT
           
private static byte[] IEND
           
private static byte[] IHDR
           
private  java.awt.image.BufferedImage image
           
private  int inputBpp
           
private static int[] INT_TRANSLATOR_CHANNEL_MAP
           
private  int outputBpp
           
static PngEncoder.Filter PAETH_FILTER
           
private static int PAETH_FILTER_TYPE
           
private static byte[] PLTE
           
private  java.awt.image.Raster raster
           
private static byte[] SIGNATURE
           
static PngEncoder.Filter SUB_FILTER
           
private static int SUB_FILTER_TYPE
           
private  int transferType
           
private  PngEncoder.Translator translator
           
static PngEncoder.Filter UP_FILTER
           
private static int UP_FILTER_TYPE
           
private  int width
           
 
Constructor Summary
PngEncoder(java.awt.Image image, boolean encodeAlpha, PngEncoder.Filter filter, int compressionLevel)
          Creates a PNG encoder for an image.
 
Method Summary
 void encode(java.io.OutputStream out)
          Encodes the image.
private  void writeIdatChunks(java.io.OutputStream out, java.util.zip.Checksum csum)
          Writes the IDAT (Image data) chunks to the output stream.
private  void writeIendChunk(java.io.OutputStream out, java.util.zip.Checksum csum)
          Writes the IEND (End-of-file) chunk to the output stream.
private  void writeIhdrChunk(java.io.OutputStream out, java.util.zip.Checksum csum)
          Writes the IHDR (Image Header) chunk to the output stream.
private static void writeInt(java.io.OutputStream out, int i)
          Writes an 32-bit integer value to the output stream.
private  void writePlteChunk(java.io.OutputStream out, java.util.zip.Checksum csum)
          Writes the PLTE (Palette) chunk to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SUB_FILTER

public static final PngEncoder.Filter SUB_FILTER

UP_FILTER

public static final PngEncoder.Filter UP_FILTER

AVERAGE_FILTER

public static final PngEncoder.Filter AVERAGE_FILTER

PAETH_FILTER

public static final PngEncoder.Filter PAETH_FILTER

SIGNATURE

private static final byte[] SIGNATURE

IHDR

private static final byte[] IHDR

PLTE

private static final byte[] PLTE

IDAT

private static final byte[] IDAT

IEND

private static final byte[] IEND

SUB_FILTER_TYPE

private static final int SUB_FILTER_TYPE
See Also:
Constant Field Values

UP_FILTER_TYPE

private static final int UP_FILTER_TYPE
See Also:
Constant Field Values

AVERAGE_FILTER_TYPE

private static final int AVERAGE_FILTER_TYPE
See Also:
Constant Field Values

PAETH_FILTER_TYPE

private static final int PAETH_FILTER_TYPE
See Also:
Constant Field Values

BIT_DEPTH

private static final byte BIT_DEPTH
See Also:
Constant Field Values

COLOR_TYPE_INDEXED

private static final byte COLOR_TYPE_INDEXED
See Also:
Constant Field Values

COLOR_TYPE_RGB

private static final byte COLOR_TYPE_RGB
See Also:
Constant Field Values

COLOR_TYPE_RGBA

private static final byte COLOR_TYPE_RGBA
See Also:
Constant Field Values

INT_TRANSLATOR_CHANNEL_MAP

private static final int[] INT_TRANSLATOR_CHANNEL_MAP

image

private java.awt.image.BufferedImage image

encodeAlpha

private boolean encodeAlpha

filter

private PngEncoder.Filter filter

compressionLevel

private int compressionLevel

width

private int width

height

private int height

transferType

private int transferType

raster

private java.awt.image.Raster raster

inputBpp

private int inputBpp

outputBpp

private int outputBpp

translator

private PngEncoder.Translator translator
Constructor Detail

PngEncoder

public PngEncoder(java.awt.Image image,
                  boolean encodeAlpha,
                  PngEncoder.Filter filter,
                  int compressionLevel)
Creates a PNG encoder for an image.

Parameters:
image - The image to be encoded.
encodeAlpha - True if the image's alpha channel should be encoded.
filter - The filter to be applied to the image data, one of the following values: If a null value is specified, no filtering will be performed.
compressionLevel - The deflater compression level that will be used for compressing the image data. Valid values range from 0 to 9. Higher values result in smaller files and therefore decrease network traffic, but require more CPU time to encode. The normal compromise value is 3.
Method Detail

writeInt

private static void writeInt(java.io.OutputStream out,
                             int i)
                      throws java.io.IOException
Writes an 32-bit integer value to the output stream.

Parameters:
out - The OutputStream to write the integer value to.
i - The integer to write tot he output stream.
Throws:
java.io.IOException

encode

public void encode(java.io.OutputStream out)
            throws java.io.IOException
Encodes the image.

Parameters:
out - An OutputStream to which the encoded image will be written.
Throws:
java.io.IOException - if a problem is encountered writing the output.

writeIdatChunks

private void writeIdatChunks(java.io.OutputStream out,
                             java.util.zip.Checksum csum)
                      throws java.io.IOException
Writes the IDAT (Image data) chunks to the output stream.

Parameters:
out - The OutputStream to write the chunk to.
csum - The Checksum that is updated as data is written to the passed-in OutputStream.
Throws:
java.io.IOException - if a problem is encountered writing the output.

writeIendChunk

private void writeIendChunk(java.io.OutputStream out,
                            java.util.zip.Checksum csum)
                     throws java.io.IOException
Writes the IEND (End-of-file) chunk to the output stream.

Parameters:
out - The OutputStream to write the chunk to.
csum - The Checksum that is updated as data is written to the passed-in OutputStream.
Throws:
java.io.IOException - if a problem is encountered writing the output.

writeIhdrChunk

private void writeIhdrChunk(java.io.OutputStream out,
                            java.util.zip.Checksum csum)
                     throws java.io.IOException
Writes the IHDR (Image Header) chunk to the output stream.

Parameters:
out - The OutputStream to write the chunk to.
csum - The Checksum that is updated as data is written to the passed-in OutputStream.
Throws:
java.io.IOException - if a problem is encountered writing the output.

writePlteChunk

private void writePlteChunk(java.io.OutputStream out,
                            java.util.zip.Checksum csum)
                     throws java.io.IOException
Writes the PLTE (Palette) chunk to the output stream.

Parameters:
out - The OutputStream to write the chunk to.
csum - The Checksum that is updated as data is written to the passed-in OutputStream.
Throws:
java.io.IOException - if a problem is encountered writing the output.

NextApp Echo
App Container 1.0.5