CADI.Common.LogicalTarget.JPEG2000.Decode
Class MQDecoder

java.lang.Object
  extended by CADI.Common.LogicalTarget.JPEG2000.Decode.MQDecoder
All Implemented Interfaces:
Decoder

public class MQDecoder
extends java.lang.Object
implements Decoder

This class decodes bits for the fractional bit plane decoder of JPEG2000, decoding them with the MQ decoder. This class allows the use of the following MQ options: restart, reset, bypass. Usage example:
  construct
  decodeBit
  decodeBit
  decodeBit
  swapInputByteStream
  reset
  restart
  decodeBit
  decodeBit
  ...

Version:
1.2
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  int A
          Interval range.
private  int C
          Lower down interval.
private  ByteStream inputByteStream
          Bytestream from which the MQ decoder reads data.
private  int L
          Number of bytes transferred to the outputByteStream.
private  int numContexts
          Number of contexts (defined by JPEG2000).
private  int[][] statesMPS
          State and Most Probable Symbol of each context.
private  int[][] stateSymbolInit
          MQ context state initialization (defined by JPEG2000 standard).
private  int[][] stateTrans
          MQ probability state transition (defined by JPEG2000 standard).
private  int t
          Number of bits to transfer (down counter).
private  int Tr
          Byte to transfer.
 
Constructor Summary
MQDecoder()
          Constructor that initializes internal registers of the MQ decoder but does not initialize the inputByteStream.
MQDecoder(ByteStream inputByteStream)
          Constructor that initializes internal registers of the MQ decoder.
 
Method Summary
 boolean decodeBit()
          Decode a bit using the context 18 (equivalent probabilities).
 boolean decodeBit(int context)
          Decode a bit.
private  void fillLSB()
          Fill the C register with a new byte of inputByteStream.
 void reset()
          Reset the context probabilities of the decoder, if any.
 void restart()
          Start the value of the internal variables A, C, ... of the MQ decoder filling them with the values of the inputByteStream.
 void swapInputByteStream(ByteStream inputByteStream)
          Swaps the current inputByteStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputByteStream

private ByteStream inputByteStream
Bytestream from which the MQ decoder reads data.

The content must be understood as a ByteStream.


numContexts

private final int numContexts
Number of contexts (defined by JPEG2000).

Positive number.

See Also:
Constant Field Values

stateSymbolInit

private final int[][] stateSymbolInit
MQ context state initialization (defined by JPEG2000 standard).

First array index represents the context and second is: (p.e. [2][0] is the initial state of context 2)


stateTrans

private final int[][] stateTrans
MQ probability state transition (defined by JPEG2000 standard).

First array index represents the current state and second is: (i.e. [1][0] is the transition to do when code a MPS symbol and the state of the context is 1)


A

private int A
Interval range.

From right to left: 8 register bits, 3 spacer bits, 8 partial code byte, 1 carry bit.


C

private int C
Lower down interval.

From right to left: 8 register bits, 3 spacer bits, 8 partial code byte, 1 carry bit.


t

private int t
Number of bits to transfer (down counter).

Usually it is initialized to 8, unless carry situations that it initilized to 7. Then count down until 0.


Tr

private int Tr
Byte to transfer.

Byte flushed to the outputByteStream.


L

private int L
Number of bytes transferred to the outputByteStream.

Byte flushed to the output ByteStream.


statesMPS

private int[][] statesMPS
State and Most Probable Symbol of each context.

Array index is the context and the State [context][0] or MPS [context][1]. It must correspond to some stateTrans.

Constructor Detail

MQDecoder

public MQDecoder()
Constructor that initializes internal registers of the MQ decoder but does not initialize the inputByteStream. Before using the MQ decoder the function swapInputByteStream should be called.


MQDecoder

public MQDecoder(ByteStream inputByteStream)
          throws ErrorException
Constructor that initializes internal registers of the MQ decoder.

Parameters:
inputByteStream - the input stream of bytes
Throws:
ErrorException - when end of ByteStream is reached
Method Detail

decodeBit

public boolean decodeBit()
                  throws ErrorException
Decode a bit using the context 18 (equivalent probabilities).

Specified by:
decodeBit in interface Decoder
Returns:
a boolean indicating the bit decoded
Throws:
ErrorException - when trying to read after the end of the inputByteStream

decodeBit

public boolean decodeBit(int context)
                  throws ErrorException
Decode a bit.

Specified by:
decodeBit in interface Decoder
Parameters:
context - a byte that indicates the context of the decoded bit
Returns:
a boolean indicating the bit decoded
Throws:
ErrorException - when trying to read after the end of the inputByteStream

fillLSB

private void fillLSB()
              throws ErrorException
Fill the C register with a new byte of inputByteStream. If the end of the ByteStream is reached, then this function fills the new byte with a value of 0xFF.

Throws:
ErrorException - when trying to read after the end of the inputByteStream

swapInputByteStream

public void swapInputByteStream(ByteStream inputByteStream)
Swaps the current inputByteStream. After the call of this function you should restart de MQ decoder calling the restart function (it fills the internal registers with the bytes of the new inputByteStream).

Specified by:
swapInputByteStream in interface Decoder
Parameters:
inputByteStream - the input stream of bytes

reset

public void reset()
Description copied from interface: Decoder
Reset the context probabilities of the decoder, if any.

Specified by:
reset in interface Decoder

restart

public void restart()
             throws ErrorException
Start the value of the internal variables A, C, ... of the MQ decoder filling them with the values of the inputByteStream. The context probabilities are maintained. This function should be called every time a new ByteStream is passed to the decoder.

Specified by:
restart in interface Decoder
Throws:
ErrorException - when end of ByteStream is reached


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)