zombie.core.textures
Class PNGDecoder

java.lang.Object
  extended by zombie.core.textures.PNGDecoder

public class PNGDecoder
extends java.lang.Object

A PNGDecoder. The slick PNG decoder is based on this class :)

Author:
Matthias Mann

Nested Class Summary
static class PNGDecoder.Format
           
 
Field Summary
 boolean bDoMask
           
 boolean[] mask
           
 int maskID
           
 long readTotal
           
 
Constructor Summary
PNGDecoder(java.io.InputStream input, boolean bDoMask)
           
 
Method Summary
 PNGDecoder.Format decideTextureFormat(PNGDecoder.Format fmt)
          Computes the implemented format conversion for the desired format.
 void decode(java.nio.ByteBuffer buffer, int stride, PNGDecoder.Format fmt)
          Decodes the image into the specified buffer.
 void decodeFlipped(java.nio.ByteBuffer buffer, int stride, PNGDecoder.Format fmt)
          Decodes the image into the specified buffer.
 int getHeight()
           
 int getWidth()
           
 boolean hasAlpha()
          Checks if the image has transparency information either from an alpha channel or from a tRNS chunk.
 boolean hasAlphaChannel()
          Checks if the image has a real alpha channel.
 boolean isRGB()
           
 void overwriteTRNS(byte r, byte g, byte b)
          Overwrites the tRNS chunk entry to make a selected color transparent.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maskID

public int maskID

mask

public boolean[] mask

bDoMask

public boolean bDoMask

readTotal

public long readTotal
Constructor Detail

PNGDecoder

public PNGDecoder(java.io.InputStream input,
                  boolean bDoMask)
           throws java.io.IOException
Throws:
java.io.IOException
Method Detail

getHeight

public int getHeight()

getWidth

public int getWidth()

hasAlphaChannel

public boolean hasAlphaChannel()
Checks if the image has a real alpha channel. This method does not check for the presence of a tRNS chunk.

Returns:
true if the image has an alpha channel
See Also:
hasAlpha()

hasAlpha

public boolean hasAlpha()
Checks if the image has transparency information either from an alpha channel or from a tRNS chunk.

Returns:
true if the image has transparency
See Also:
hasAlphaChannel(), overwriteTRNS(byte, byte, byte)

isRGB

public boolean isRGB()

overwriteTRNS

public void overwriteTRNS(byte r,
                          byte g,
                          byte b)
Overwrites the tRNS chunk entry to make a selected color transparent.

This can only be invoked when the image has no alpha channel.

Calling this method causes hasAlpha() to return true.

Parameters:
r - the red component of the color to make transparent
g - the green component of the color to make transparent
b - the blue component of the color to make transparent
Throws:
java.lang.UnsupportedOperationException - if the tRNS chunk data can't be set
See Also:
hasAlphaChannel()

decideTextureFormat

public PNGDecoder.Format decideTextureFormat(PNGDecoder.Format fmt)
Computes the implemented format conversion for the desired format.

Parameters:
fmt - the desired format
Returns:
format which best matches the desired format
Throws:
java.lang.UnsupportedOperationException - if this PNG file can't be decoded

decode

public void decode(java.nio.ByteBuffer buffer,
                   int stride,
                   PNGDecoder.Format fmt)
            throws java.io.IOException
Decodes the image into the specified buffer. The first line is placed at the current position. After decode the buffer position is at the end of the last line.

Parameters:
buffer - the buffer
stride - the stride in bytes from start of a line to start of the next line, can be negative.
fmt - the target format into which the image should be decoded.
Throws:
java.io.IOException - if a read or data error occurred
java.lang.IllegalArgumentException - if the start position of a line falls outside the buffer
java.lang.UnsupportedOperationException - if the image can't be decoded into the desired format

decodeFlipped

public void decodeFlipped(java.nio.ByteBuffer buffer,
                          int stride,
                          PNGDecoder.Format fmt)
                   throws java.io.IOException
Decodes the image into the specified buffer. The last line is placed at the current position. After decode the buffer position is at the end of the first line.

Parameters:
buffer - the buffer
stride - the stride in bytes from start of a line to start of the next line, must be positive.
fmt - the target format into which the image should be decoded.
Throws:
java.io.IOException - if a read or data error occurred
java.lang.IllegalArgumentException - if the start position of a line falls outside the buffer
java.lang.UnsupportedOperationException - if the image can't be decoded into the desired format