CADI.Common.LogicalTarget.JPEG2000.Codestream
Class PacketHeadersDecoder

java.lang.Object
  extended by CADI.Common.LogicalTarget.JPEG2000.Codestream.PacketHeadersDecoder

public class PacketHeadersDecoder
extends java.lang.Object

This class performs the packet header decoding.

Usage: example:
  construct
  [reset]
  packetHeaderDecoding

Version:
1.1.0 2008/12/05
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  boolean EPH
          Indicates whether the End of Packet marker is in the codestream and it must be read.
private  int[][][] firstLayer
          Definition in PacketHeaderDataDecoder.firstLayer.
private  int[][][][][][] imageStructure
          Is the image structure.
private  int[][][] lBlock
          Definition in PacketHeaderDataDecoder.lBlock.
private  int Nsop
          Packet sequence number.
private  int NsopInHeader
           
private  java.util.Hashtable<java.lang.Long,PacketHeaderDataDecoder> packetHeaders
          This object is used to save the packet headers data objects.
private  PacketHeaderDataInputStream PHDataInputStream
          Is a input stream where bits of packet headers will be read from.
private  boolean SOP
          Indicates whether the Start of Packet marker is in the codestream and it must be read.
private  TagTreeDecoder[] TTInclusionInformation
          Definition in PacketHeaderDataDecoder.TTInclusionInformation.
private  TagTreeDecoder[] TTZeroBitPlanes
          Definition in PacketHeaderDataDecoder.TTZeroBitPlanes.
private  int[][][] zeroBitPlanes
           
 
Constructor Summary
PacketHeadersDecoder(int[][][][][][] imageStructure)
          Constructor.
PacketHeadersDecoder(int[][][][][][] imageStructure, boolean sop, boolean eph)
          Constructor.
 
Method Summary
private  int DecodeCodingPasses()
          Decodify the coding passes
private  int DecodeLblock()
          Decodify the Lblock value
private  int[] DecodeLengths(int lblock, int codingPasses)
          Decodify the length of codeword segment
private  int getBit()
          Returns the bit readed from the file.
 int[][][] getZeroBitPlanes(long inClassIdentifier)
          Returns the zero bit planes for a tile-component-resolution-precinct.
 void list(java.io.PrintStream out)
          Prints this Packet headers Decoder's fields to the specified output stream.
 int[][][][] packetHeaderDecoding(BufferedDataInputStream PHDataInputStream, long inClassIdentifier, int z, int rLevel, int precinct)
          Decodes the packet header for a precinct of a given layer, z, rLevel, precinct
private  void readEPH(BufferedDataInputStream PHDataInputStream)
          To read EPH marker if it is used
private  void readSOP(BufferedDataInputStream PHDataInputStream)
          To position the file pointer just before the first PacketHeader
 void reset()
          Sets the internal attributes (states) to its initial values.
 java.lang.String toString()
          (non-Javadoc)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

imageStructure

private int[][][][][][] imageStructure
Is the image structure. Indices means:
  z: image component
  resolutionLevel: 0 is the LL subband, and 1, 2, ... represents next starting with the little one
  precinct: precinct in the resolution level
  subband: 0 - HL, 1 - LH, 2 - HH (ifresolutionLevel == 0 --> 0 - LL)
  yBlock: block row in the subband
  xBlock: block column in the subband


PHDataInputStream

private PacketHeaderDataInputStream PHDataInputStream
Is a input stream where bits of packet headers will be read from.


SOP

private boolean SOP
Indicates whether the Start of Packet marker is in the codestream and it must be read.


EPH

private boolean EPH
Indicates whether the End of Packet marker is in the codestream and it must be read.


packetHeaders

private java.util.Hashtable<java.lang.Long,PacketHeaderDataDecoder> packetHeaders
This object is used to save the packet headers data objects. It uses the inClassIdentififer (see JPIPMessageHeader.inClassIdentifier) as a key.


TTInclusionInformation

private TagTreeDecoder[] TTInclusionInformation
Definition in PacketHeaderDataDecoder.TTInclusionInformation.


TTZeroBitPlanes

private TagTreeDecoder[] TTZeroBitPlanes
Definition in PacketHeaderDataDecoder.TTZeroBitPlanes.


lBlock

private int[][][] lBlock
Definition in PacketHeaderDataDecoder.lBlock.


firstLayer

private int[][][] firstLayer
Definition in PacketHeaderDataDecoder.firstLayer.


zeroBitPlanes

private int[][][] zeroBitPlanes

Nsop

private int Nsop
Packet sequence number. The first packet in a coded tile is assigned the value 0. When the maximum number -65535- is reached, the number rolls over to zero.

Valid values between 0 to 65535.


NsopInHeader

private int NsopInHeader
Constructor Detail

PacketHeadersDecoder

public PacketHeadersDecoder(int[][][][][][] imageStructure)
Constructor.

This constructor assumes Start Of Packet (SOP) and End of Packet Headers (EPH) are not used.

Parameters:
imageStructure - definition in imageStructure

PacketHeadersDecoder

public PacketHeadersDecoder(int[][][][][][] imageStructure,
                            boolean sop,
                            boolean eph)
Constructor.

Parameters:
imageStructure - definition in imageStructure
sop - definition in SOP
eph - definition in EPH
Method Detail

reset

public void reset()
           throws ErrorException
Sets the internal attributes (states) to its initial values.

Throws:
ErrorException - when the internal attributes cannot be reseted.

packetHeaderDecoding

public int[][][][] packetHeaderDecoding(BufferedDataInputStream PHDataInputStream,
                                        long inClassIdentifier,
                                        int z,
                                        int rLevel,
                                        int precinct)
                                 throws ErrorException,
                                        java.io.EOFException,
                                        java.io.IOException
Decodes the packet header for a precinct of a given layer, z, rLevel, precinct

Parameters:
PHDataInputStream - a input stream where packet header is read from.
inClassIdentifier - definition in JPIPMessageHeader.inClassIdentifier.
layer - Layer
z - Component
rLevel - Resolution level
precinct - Precinct
Returns:
A vector which will contain the data length for a given subband, yBlock, xBlock and coding pass The index are: [subband][yBlock][xBlock][codingPasses] = data length
Throws:
ErrorException - when the packet header is corrupted
java.io.EOFException - if the end of the input stream has been reached.
java.io.IOException - if a I/O error has ocurred.

getZeroBitPlanes

public int[][][] getZeroBitPlanes(long inClassIdentifier)
                           throws java.lang.IllegalAccessException
Returns the zero bit planes for a tile-component-resolution-precinct.

Parameters:
inClassIdentifier -
Returns:
definition in PacketHeaderDataDecoder.zeroBitPlanes
Throws:
java.lang.IllegalAccessException

toString

public java.lang.String toString()
(non-Javadoc)

Overrides:
toString in class java.lang.Object
See Also:
Object.toString()

list

public void list(java.io.PrintStream out)
Prints this Packet headers Decoder's fields to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

DecodeLblock

private int DecodeLblock()
                  throws java.io.EOFException,
                         java.io.IOException
Decodify the Lblock value

Returns:
lblock value
Throws:
ErrorException - when the packet header is corrupted
java.io.EOFException
java.io.IOException

DecodeLengths

private int[] DecodeLengths(int lblock,
                            int codingPasses)
                     throws java.io.EOFException,
                            java.io.IOException
Decodify the length of codeword segment

Parameters:
lblock - current value
codingPasses - coding passes number of the codeblock
Returns:
length of code-block
Throws:
ErrorException - when the packet header is corrupted
java.io.EOFException
java.io.IOException

DecodeCodingPasses

private int DecodeCodingPasses()
                        throws java.io.EOFException,
                               java.io.IOException
Decodify the coding passes

Returns:
coding passes
Throws:
ErrorException - when the packet header is corrupted
java.io.EOFException
java.io.IOException

readSOP

private void readSOP(BufferedDataInputStream PHDataInputStream)
              throws ErrorException,
                     java.io.EOFException,
                     java.io.IOException
To position the file pointer just before the first PacketHeader

Throws:
ErrorException - when the file cannot be load
java.io.EOFException
java.io.IOException

readEPH

private void readEPH(BufferedDataInputStream PHDataInputStream)
              throws ErrorException,
                     java.io.EOFException,
                     java.io.IOException
To read EPH marker if it is used

Throws:
ErrorException - when the file cannot be load
java.io.EOFException
java.io.IOException

getBit

private int getBit()
            throws java.io.EOFException,
                   java.io.IOException
Returns the bit readed from the file.

Returns:
an integer that represents the bit readed from the file
Throws:
java.io.EOFException
java.io.IOException


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)