it.tidalwave.imageio.decoder
Class HuffmannDecoder

java.lang.Object
  extended by it.tidalwave.imageio.decoder.HuffmannDecoder

public class HuffmannDecoder
extends java.lang.Object

This class is capable to decode bit strings encoded with a Huffman table. PENDING: give a short description of what a Huffman table is.
This class is able to create itself from a description in an array of bytes or shorts, following some common schemes used in many RAW formats.

Version:
CVS $Id: HuffmannDecoder.java,v 1.2 2006/02/08 19:50:52 fabriziogiudici Exp $
Author:
Fabrizio Giudici

Field Summary
 HuffmannDecoder[] branch
          The two pointers (index 0 and 1) to the lower tree level.
 
Method Summary
static HuffmannDecoder createDecoder(byte[] source, int start)
          Creates a decode tree according the specification in source.
static HuffmannDecoder createDecoder(short[] source)
          Creates a decode tree according the specification in source.
static HuffmannDecoder createDecoderWithJpegHack(byte[] source, int start)
          Creates a decode tree according the specification in source.
 int decode(javax.imageio.stream.ImageInputStream br)
          Reads an encoded value from a BitReader and returns the decoded value.
 java.lang.String toString()
           
 java.lang.String toString(java.lang.String prefix)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

branch

public HuffmannDecoder[] branch
The two pointers (index 0 and 1) to the lower tree level.

Method Detail

createDecoder

public static HuffmannDecoder createDecoder(short[] source)
Creates a decode tree according the specification in source. The first 16 bytes specify how many codes should be 1-bit, 2-bit 3-bit, etc. Bytes after that are the leaf values. For example, if the source is { 0,1,4,2,3,1,2,0,0,0,0,0,0,0,0,0, 0x04,0x03,0x05,0x06,0x02,0x07,0x01,0x08,0x09,0x00,0x0a,0x0b,0xff }, then the code is 00 0x04 010 0x03 011 0x05 100 0x06 101 0x02 1100 0x07 1101 0x01 11100 0x08 11101 0x09 11110 0x00 111110 0x0a 1111110 0x0b 1111111 0xff

Parameters:
source - the coded version as an array of shorts
Returns:
the HuffmannDecoder

createDecoder

public static HuffmannDecoder createDecoder(byte[] source,
                                            int start)
Creates a decode tree according the specification in source. See createDecoder(short[]) for more information.

Parameters:
source - the coded version as an array of bytes
start - the offset in the source to the first byte to use
Returns:
the HuffmannDecoder

createDecoderWithJpegHack

public static HuffmannDecoder createDecoderWithJpegHack(byte[] source,
                                                        int start)
Creates a decode tree according the specification in source. See createDecoder(short[]) for more information. This version should be used for Hufmman tables used in Lossless JPEG compression - they have some specific issues.

Parameters:
source - the coded version as an array of bytes
start - the offset in the source to the first byte to use
Returns:
the HuffmannDecoder

decode

public int decode(javax.imageio.stream.ImageInputStream br)
           throws java.io.IOException
Reads an encoded value from a BitReader and returns the decoded value.

Parameters:
br - the bit reader
Returns:
the decoded value
Throws:
java.io.IOException - if an I/O exception occurs

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

toString

public java.lang.String toString(java.lang.String prefix)