CADI.Common.LogicalTarget.JPEG2000.Decode
Class BPEDecoder

java.lang.Object
  extended by CADI.Common.LogicalTarget.JPEG2000.Decode.BPEDecoder

public class BPEDecoder
extends java.lang.Object

This class receives an array of ByteStreams belonging to a code-block and decodes them obtaining the original image samples. Typically it is used in the following way:
constructor(receiveing the bytestreams)
runAll
getBlockSamples
You can also use this class to increasingly decode the coding passes: you only have to use the decodeNextCodingPass function as times as coding passes contains the code-block.
ATTENTION: In the framework of the JPEG2000 many different code-blocks have to be encoded. It is more efficient to create only one object of this class and change the code-block:
constructor(void)
swapCodeBlock
runAll
getBlockSamples
swapCodeBlock
runAll
getBlockSamples
...
(of course, the function runAll can be substituted for multiple call of the decodeNextCodingPass function) If this class is used in this last way it is easy to incorporate a multithreading support for the decoding of code-blocks.
Since version 1.3 this class uses an optimized way to calculate coefficient contexts. Although it achieves good results in terms of computational complexity, the source code is not very understandable (when computing the coefficient contexts). File BPEDecoder.java.1_2 contains the 1.2 version of this class, that has a more understandable source code. Apart of this, both classes are exactly equal.

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

Field Summary
private  Decoder blockDecoder
          Decoder to read from the inputByteStream.
private  int[][] blockSamples
          Original block samples (index meaning [y][x]).
private  ByteStream[][] CDByteStreams
          ByteStreams generated by the fractional bit plane coding (index meaning [bitPlane][0(SPP),1(MRP),2(CP)] -bitPlane==0 is MSBP-).
private  byte[][] contextMap
          Map where the contexts of the coefficients are stored.
private  int currentBitPlane
          Current bit plane encoded.
private  int currentCodingPass
          Current coding pass encoded.
private  int currentMaskBitPlane
          Current mask of the bit plane.
private  int maskBitPlaneBefore
          Mask of the currentBitPlane - 1.
private  int MSBPlane
          Most Significance Bit Plane found in the block.
private  int numBitsRunModeBreak
          Number of bits needed to flush the singificant coefficient in the stripe (used when the run mode is broken).
private  int stripeHeight
          Stripe height.
private  int subband
          Image WT subband.
private  int xSize
          Definition in SIZParameters.xSize
private  int ySize
          Definition in SIZParameters.ySize
 
Constructor Summary
BPEDecoder()
          Constructor that does not receive anything.
BPEDecoder(ByteStream[][] CDByteStreams, int[][] blockSamples, int MSBPlane, int subband)
          Constructor that receives block coded bit streams, block sizes, most significant bit plane and block subband.
 
Method Summary
private  void cleanupPass()
          Cleanup pass of JPEG2000 decoding scheme.
 void decodeNextCodingPass()
          Decodes the next coding pass.
 int[][] getBlockSamples()
           
private  void magnitudeRefinementPass()
          Magnitude refinement pass of JPEG2000 decoding scheme.
 void runAll()
          Decode the image samples (all bit planes).
private  void signDecode(int x, int y)
          Calculates the bit sign and context from a sample (called when the sample becomes significant).
private  void significancePropagationPass()
          Significance propagation pass of JPEG2000 decoding scheme.
 void swapCodeBlock(ByteStream[][] CDByteStreams, int[][] blockSamples, int MSBPlane, int subband)
          Swaps the code-block decoded by this class.
private  void updateMap(int x, int y, boolean CP)
          Turn neighbourhoods map samples of (x,y) from 0 to 1 if they can be visited in the current scan.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CDByteStreams

private ByteStream[][] CDByteStreams
ByteStreams generated by the fractional bit plane coding (index meaning [bitPlane][0(SPP),1(MRP),2(CP)] -bitPlane==0 is MSBP-).

The content must be understood as a ByteStream.


blockSamples

private int[][] blockSamples
Original block samples (index meaning [y][x]).

All values allowed.


ySize

private int ySize
Definition in SIZParameters.ySize


xSize

private int xSize
Definition in SIZParameters.xSize


subband

private int subband
Image WT subband.

Valid values: 0(LL), 1(HL), 2(LH), 3(HH).
LL HL
LH HH


MSBPlane

private int MSBPlane
Most Significance Bit Plane found in the block.

Negative values not allowed.


contextMap

private byte[][] contextMap
Map where the contexts of the coefficients are stored. This map is used to extract the context of coefficient when they have to be encoded. It works in the following way: at the begining all the contextMap is initialized to 0. When a coefficient is found significant, it updates all its neighboors to the next context status and so on. Thanks to this mechanism, less operations have to be performed when a looking for the context of a coefficient although the source code is not so... clean (see function updateMap).

The value means the context of the sample. Valid contexts are: 0 - 8 when the coefficient is still non-significant, 15 - 17 when the coefficient is significant and it is going to be refined. These values can be positive or negative to indicate if they have to be visited by the significancePropoagationPass or cleanupPass functions. SPP only visits coefficients with contexts > 0 and <= 8, CP only visits coefficients with contexts >= -8 <= 0.


currentBitPlane

private int currentBitPlane
Current bit plane encoded.

0 is the Less Significant Bit Plane.


currentCodingPass

private int currentCodingPass
Current coding pass encoded.

0 is the SPP, 1 is MRP, and 2 is CP.


currentMaskBitPlane

private int currentMaskBitPlane
Current mask of the bit plane.

The content is 2^currentBitPlane


maskBitPlaneBefore

private int maskBitPlaneBefore
Mask of the currentBitPlane - 1.

The content is 2^(currentBitPlane-1)


blockDecoder

private Decoder blockDecoder
Decoder to read from the inputByteStream.

This Decoder must be compatible with the abstract class Decoder.


stripeHeight

private final int stripeHeight
Stripe height.

Negative values not allowed for this field.

See Also:
Constant Field Values

numBitsRunModeBreak

private final int numBitsRunModeBreak
Number of bits needed to flush the singificant coefficient in the stripe (used when the run mode is broken).

This should be log_2(stripeHeight)

Constructor Detail

BPEDecoder

public BPEDecoder()
           throws ErrorException
Constructor that does not receive anything. Before use the functions of decodeNextCodingPass the function swapCodeBlock must be used.

Throws:
ErrorException

BPEDecoder

public BPEDecoder(ByteStream[][] CDByteStreams,
                  int[][] blockSamples,
                  int MSBPlane,
                  int subband)
           throws ErrorException
Constructor that receives block coded bit streams, block sizes, most significant bit plane and block subband. This information is absolutely necessary to decode bitstream.

Parameters:
CDByteStreams - definition in CDByteStreams
blockSamples - definition in blockSamples
MSBPlane - definition in MSBPlane
subband - definition in subband
Throws:
ErrorException - problems with the inputByteStream
Method Detail

swapCodeBlock

public void swapCodeBlock(ByteStream[][] CDByteStreams,
                          int[][] blockSamples,
                          int MSBPlane,
                          int subband)
                   throws ErrorException
Swaps the code-block decoded by this class. Some initializations performed.

Parameters:
CDByteStreams - definition in CDByteStreams
blockSamples - definition in blockSamples
MSBPlane - definition in MSBPlane
subband - definition in subband
Throws:
ErrorException - problems with the inputByteStream

runAll

public void runAll()
            throws WarningException,
                   ErrorException
Decode the image samples (all bit planes).

Throws:
WarningException - when reached the last coding pass
ErrorException - problems with the inputByteStream

decodeNextCodingPass

public void decodeNextCodingPass()
                          throws WarningException,
                                 ErrorException
Decodes the next coding pass.

Throws:
WarningException - when reached the last coding pass
ErrorException - problems with the inputByteStream

signDecode

private void signDecode(int x,
                        int y)
                 throws ErrorException
Calculates the bit sign and context from a sample (called when the sample becomes significant).

Parameters:
x - position of the sample
y - position of the sample
Throws:
ErrorException - when end of bitstream is reached

significancePropagationPass

private void significancePropagationPass()
                                  throws ErrorException
Significance propagation pass of JPEG2000 decoding scheme.

Throws:
ErrorException - when end of bitstream reached

magnitudeRefinementPass

private void magnitudeRefinementPass()
                              throws ErrorException
Magnitude refinement pass of JPEG2000 decoding scheme.
This pass searchs the significance samples that in the current bit plane have a refinement bit.

Throws:
ErrorException - when end of bitstream reached

cleanupPass

private void cleanupPass()
                  throws ErrorException
Cleanup pass of JPEG2000 decoding scheme.

Throws:
ErrorException - when end of bitstream reached

updateMap

private void updateMap(int x,
                       int y,
                       boolean CP)
Turn neighbourhoods map samples of (x,y) from 0 to 1 if they can be visited in the current scan.

Parameters:
x - x position of the sample
y - y position of the sample
CP - indicates if the updating is performed by the Cleanup Pass (true, otherwise false)

getBlockSamples

public int[][] getBlockSamples()
Returns:
blockSamples definition in blockSamples


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)