jj2000.j2k.entropy.encoder
Class BitToByteOutput

java.lang.Object
  |
  +--jj2000.j2k.entropy.encoder.BitToByteOutput

class BitToByteOutput
extends java.lang.Object

This class provides an adapter to perform bit based output on byte based output objects that inherit from a 'ByteOutputBuffer' class. This class implements the bit stuffing policy needed for the 'selective arithmetic coding bypass' mode of the entropy coder. This class also delays the output of a trailing 0xFF, since they are synthetized be the decoder.


Field Summary
(package private)  int bbuf
          The bit buffer
(package private)  int bpos
          The position of the next bit to put in the bit buffer.
(package private)  boolean delFF
          Flag that indicates if an FF has been delayed
private  boolean isPredTerm
          Whether or not predictable termination is requested.
(package private)  int nb
          The number of written bytes (excluding the bit buffer)
(package private)  ByteOutputBuffer out
          The byte based output
(package private) static int PAD_SEQ
          The alternating sequence of 0's and 1's used for byte padding
 
Constructor Summary
(package private) BitToByteOutput(ByteOutputBuffer out)
          Instantiates a new 'BitToByteOutput' object that uses 'out' as the underlying byte based output.
 
Method Summary
(package private)  void flush()
          Writes the contents of the bit buffer and byte aligns the output by filling bits with an alternating sequence of 0's and 1's.
(package private)  int length()
          Returns the length, in bytes, of the output bit stream as written by this object.
(package private)  void reset()
          Resets the bit buffer to empty, without writing anything to the underlying byte output, and resets the byte count.
(package private)  void setPredTerm(boolean isPredTerm)
          Set the flag according to whether or not the predictable termination is requested.
 int terminate()
          Terminates the bit stream by calling 'flush()' and then 'reset()'.
(package private)  void writeBit(int bit)
          Write a bit to the output.
(package private)  void writeBits(int[] symbuf, int nsym)
          Writes to the bit stream the symbols contained in the 'symbuf' buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isPredTerm

private boolean isPredTerm
Whether or not predictable termination is requested. This value is important when the last byte before termination is an 0xFF


PAD_SEQ

static final int PAD_SEQ
The alternating sequence of 0's and 1's used for byte padding

See Also:
Constant Field Values

delFF

boolean delFF
Flag that indicates if an FF has been delayed


out

ByteOutputBuffer out
The byte based output


bbuf

int bbuf
The bit buffer


bpos

int bpos
The position of the next bit to put in the bit buffer. When it is 7 the bit buffer 'bbuf' is empty. The value should always be between 7 and 0 (i.e. if it gets to -1, the bit buffer should be immediately written to the byte output).


nb

int nb
The number of written bytes (excluding the bit buffer)

Constructor Detail

BitToByteOutput

BitToByteOutput(ByteOutputBuffer out)
Instantiates a new 'BitToByteOutput' object that uses 'out' as the underlying byte based output.

Parameters:
out - The underlying byte based output
Method Detail

writeBits

final void writeBits(int[] symbuf,
                     int nsym)
Writes to the bit stream the symbols contained in the 'symbuf' buffer. The least significant bit of each element in 'symbuf'is written.

Parameters:
symbuf - The symbols to write
nsym - The number of symbols in symbuf

writeBit

final void writeBit(int bit)
Write a bit to the output. The least significant bit of 'bit' is written to the output.

Parameters:
bit -

flush

void flush()
Writes the contents of the bit buffer and byte aligns the output by filling bits with an alternating sequence of 0's and 1's.


terminate

public int terminate()
Terminates the bit stream by calling 'flush()' and then 'reset()'. Finally, it returns the number of bytes effectively written.

Returns:
The number of bytes effectively written.

reset

void reset()
Resets the bit buffer to empty, without writing anything to the underlying byte output, and resets the byte count. The underlying byte output is NOT reset.


length

int length()
Returns the length, in bytes, of the output bit stream as written by this object. If the output bit stream does not have an integer number of bytes in length then it is rounded to the next integer.

Returns:
The length, in bytes, of the output bit stream.

setPredTerm

void setPredTerm(boolean isPredTerm)
Set the flag according to whether or not the predictable termination is requested.

Parameters:
isPredTerm - Whether or not predictable termination is requested.