Class PngEncoder

java.lang.Object
  |
  +--PngEncoder

public class PngEncoder
extends java.lang.Object


Field Summary
(package private)  int bytesPerPixel
           
static int chunksize
           
static int compress
           
protected  java.util.zip.CRC32 crc
           
protected  long crcValue
           
(package private)  byte[] deflatebuff
           
(package private)  int defpos
           
static boolean ENCODE_ALPHA
          Constant specifying that alpha channel should be encoded.
 boolean encodeAlpha
           
static int filter
           
static int FILTER_LAST
           
static int FILTER_NONE
          Constants for filters
static int FILTER_SUB
           
static int FILTER_UP
           
protected  int height
           
(package private)  byte[] lastline
           
(package private)  byte[] line
           
 java.lang.String message
           
static boolean NO_ALPHA
          Constant specifying that alpha channel should not be encoded.
protected  java.io.OutputStream out
           
(package private)  int[] pixels
           
(package private)  byte[] raw
           
(package private)  java.util.zip.Deflater scrunch
           
 javax.swing.JLabel status
           
protected  int width
           
 
Constructor Summary
PngEncoder(int width, int height, java.io.OutputStream out)
          Class constructor specifying Size of image, and stream to write to.
 
Method Summary
 void addSlice(java.awt.image.BufferedImage image, javax.swing.JLabel status, java.lang.String message)
          Write a slice of image data to the output stream.
 void clean()
           
 void finish()
           
 void start()
          Writes the current image to the output stream in PNG format, specifying whether to encode alpha or not.
protected  void writeByte(int b)
          Write a single byte into the output.
protected  void writeBytes(byte[] data)
          Write an array of bytes output stream Note: This routine has the side effect of updating the crc.
protected  void writeBytes(byte[] data, int nBytes)
          Write an array of bytes into the pngBytes array, specifying number of bytes to write.
protected  void writeDat(byte[] data, int size)
          Write an IDAT chunk.
protected  void writeEnd()
          Write a PNG "IEND" chunk into the pngBytes array.
protected  void writeHeader()
          Write a PNG "IHDR" chunk to the output.
protected  void writeInt2(int n)
          Write a two-byte integer into the output.
protected  void writeInt4(int n)
          Write a four-byte integer into the output.
protected  void writeInt4nocrc(int n)
          Write a four-byte integer into the output.
protected  void writeString(java.lang.String s)
          Write a string into the output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENCODE_ALPHA

public static final boolean ENCODE_ALPHA
Constant specifying that alpha channel should be encoded.

See Also:
Constant Field Values

NO_ALPHA

public static final boolean NO_ALPHA
Constant specifying that alpha channel should not be encoded.

See Also:
Constant Field Values

FILTER_NONE

public static final int FILTER_NONE
Constants for filters

See Also:
Constant Field Values

FILTER_SUB

public static final int FILTER_SUB
See Also:
Constant Field Values

FILTER_UP

public static final int FILTER_UP
See Also:
Constant Field Values

FILTER_LAST

public static final int FILTER_LAST
See Also:
Constant Field Values

compress

public static int compress

filter

public static int filter

chunksize

public static int chunksize

out

protected java.io.OutputStream out

width

protected int width

height

protected int height

crc

protected java.util.zip.CRC32 crc

crcValue

protected long crcValue

encodeAlpha

public boolean encodeAlpha

status

public javax.swing.JLabel status

message

public java.lang.String message

bytesPerPixel

int bytesPerPixel

lastline

byte[] lastline

raw

byte[] raw

line

byte[] line

pixels

int[] pixels

deflatebuff

byte[] deflatebuff

defpos

int defpos

scrunch

java.util.zip.Deflater scrunch
Constructor Detail

PngEncoder

public PngEncoder(int width,
                  int height,
                  java.io.OutputStream out)
Class constructor specifying Size of image, and stream to write to.

See Also:
Image
Method Detail

writeBytes

protected void writeBytes(byte[] data)
                   throws java.io.IOException
Write an array of bytes output stream Note: This routine has the side effect of updating the crc.

Parameters:
data - The data to be written .
java.io.IOException

writeBytes

protected void writeBytes(byte[] data,
                          int nBytes)
                   throws java.io.IOException
Write an array of bytes into the pngBytes array, specifying number of bytes to write. Note: This routine has the side effect of updating the crc.

Parameters:
data - The data to be written.
nBytes - The number of bytes to be written.
java.io.IOException

writeInt2

protected void writeInt2(int n)
                  throws java.io.IOException
Write a two-byte integer into the output.

Parameters:
n - The integer to be written.
java.io.IOException

writeInt4

protected void writeInt4(int n)
                  throws java.io.IOException
Write a four-byte integer into the output.

Parameters:
n - The integer to be written.
java.io.IOException

writeInt4nocrc

protected void writeInt4nocrc(int n)
                       throws java.io.IOException
Write a four-byte integer into the output. Do not update crc.

Parameters:
n - The integer to be written.
java.io.IOException

writeByte

protected void writeByte(int b)
                  throws java.io.IOException
Write a single byte into the output.

java.io.IOException

writeString

protected void writeString(java.lang.String s)
                    throws java.io.IOException
Write a string into the output. This uses the getBytes method, so the encoding used will be its default.

java.io.IOException
See Also:
String.getBytes()

writeHeader

protected void writeHeader()
                    throws java.io.IOException
Write a PNG "IHDR" chunk to the output.

java.io.IOException

start

public void start()
           throws java.io.IOException
Writes the current image to the output stream in PNG format, specifying whether to encode alpha or not.

Returns:
an array of bytes, or null if there was a problem
java.io.IOException

addSlice

public void addSlice(java.awt.image.BufferedImage image,
                     javax.swing.JLabel status,
                     java.lang.String message)
              throws java.io.IOException,
                     CookKillException
Write a slice of image data to the output stream. This may write one or more PNG "IDAT" chunks.

java.io.IOException
CookKillException

finish

public void finish()
            throws java.io.IOException
java.io.IOException

clean

public void clean()

writeDat

protected void writeDat(byte[] data,
                        int size)
                 throws java.io.IOException
Write an IDAT chunk.

Parameters:
data - the (compressed) data to be written.
size - The number of bytes.
java.io.IOException

writeEnd

protected void writeEnd()
                 throws java.io.IOException
Write a PNG "IEND" chunk into the pngBytes array.

java.io.IOException