CADI.Server.LogicalTarget.JPEG2000.Codestream
Class PacketHeadersEncoder

java.lang.Object
  extended by CADI.Server.LogicalTarget.JPEG2000.Codestream.PacketHeadersEncoder

public class PacketHeadersEncoder
extends java.lang.Object

This class implements the packet headers encoder. This class is implemented to store only information of those packets which have been initialize, so only information about these packets will be required.

Before any call to the encodePacketHeader(long, int[][][][]) method (to encode the packet header of a precinct) is is necessary the setZeroBitPlanesAndFirstLayer(long, int[][][], int[][][]) method had been called in order to set the first layer and number of zero bit planes for this precinct. Otherwise, an exception will be thrown.

Each call to the encodePacketHeader(long, int[][][][]) method generates the packet header belonging to the next quality layer for the precinct passed as the first function's parameter.

Usage: example:
  construct
  [setParameters]
  setZeroBitPlanesAndFirstLayer
  encodePacketHeader

Version:
1.2.0 2008/12/27
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  boolean emptyHeaderBit
          It refers to the zero length packet coding (empty packets).
 int[][][] firstLayer
          Definition in PacketHeaderDataEncoder.firstLayer.
private  int[][][] lBlock
          Definition in PacketHeaderDataEncoder.lBlock.
private  PacketHeaderDataOutputStream packetHeaderDataOutputStream
          ByteStream to built each packet header
private  java.util.Map<java.lang.Long,PacketHeaderDataEncoder> packetHeaders
          This object is used to save the packet headers data objects.
private  TagTreeEncoder[] TTInclusionInformation
          Definition in PacketHeaderDataEncoder.TTInclusionInformation.
private  TagTreeEncoder[] TTZeroBitPlanes
          Definition in PacketHeaderDataEncoder.TTZeroBitPlanes.
 
Constructor Summary
PacketHeadersEncoder()
          Constructor.
PacketHeadersEncoder(boolean emptyHeaderBit)
          Constructor.
 
Method Summary
private  void encodeCodingPasses(int value)
          Gives a codeword to the value.
private  int encodeLengths(int lblock, int[] dataCodingPasses)
          Calculate and codify the Lblock value and length of codeword segment
 byte[] encodePacketHeader(long inClassIdentifier, int[][][][] codingPassesAdded)
          Encodes the packet header data in a byte array for the precinct which is referenced to as layer - component - resolution level - precinct, and whose coding passed are passed in the codingPassesAdded variable.
 int getLastEncodedLayer(long inClassIdentifier)
          Returns the last encoded layer.
 byte[] getPacketHeaderBuffer()
          Returns a byte array with the las packet header which has been encoded.
 int getPacketHeaderLength()
          Returns the length of the last encoded packet (in bytes).
 boolean isSet(long inClassIdentifier)
          Check whether zero bit planes and first layer has been set for a precinct.
 void list(java.io.PrintStream out)
          Prints the Packet Headers Encoder data out to the specified output stream.
 void reset()
          Sets attributes to its initial values.
 void setParameters(boolean emptyHeaderBit)
          Set the emptyHeaderBit attribute.
 void setZeroBitPlanesAndFirstLayer(long inClassIdentifier, int[][][] zeroBitPlanes, int[][][] firstLayer)
          Sets the zero bit planes and first layer for a precinct.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

emptyHeaderBit

private boolean emptyHeaderBit
It refers to the zero length packet coding (empty packets). There are two possibilities:   1- emptyHeaderBit = true: a 0 value at first bit in packet header.   2- emptyHeaderBit = false: a 1 value at first bit in packet header, and then a 0 value for each packet in the inclusion information.


packetHeaders

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


packetHeaderDataOutputStream

private PacketHeaderDataOutputStream packetHeaderDataOutputStream
ByteStream to built each packet header


TTInclusionInformation

private TagTreeEncoder[] TTInclusionInformation
Definition in PacketHeaderDataEncoder.TTInclusionInformation.


TTZeroBitPlanes

private TagTreeEncoder[] TTZeroBitPlanes
Definition in PacketHeaderDataEncoder.TTZeroBitPlanes.


lBlock

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


firstLayer

public int[][][] firstLayer
Definition in PacketHeaderDataEncoder.firstLayer.

Constructor Detail

PacketHeadersEncoder

public PacketHeadersEncoder()
Constructor.


PacketHeadersEncoder

public PacketHeadersEncoder(boolean emptyHeaderBit)
Constructor.

Parameters:
emptyHeaderBit - definition in emptyHeaderBit.
Method Detail

setParameters

public void setParameters(boolean emptyHeaderBit)
Set the emptyHeaderBit attribute.

Parameters:
emptyHeaderBit - definition in emptyHeaderBit.

setZeroBitPlanesAndFirstLayer

public void setZeroBitPlanesAndFirstLayer(long inClassIdentifier,
                                          int[][][] zeroBitPlanes,
                                          int[][][] firstLayer)
                                   throws ErrorException
Sets the zero bit planes and first layer for a precinct.

This method must be used only when objects are build using the default constructor. Moreover, it has to be called once before the #encodePacketHeader(long, int, int, int, int[][][][]) method was called for each precinct.

If it is called more than once, an exception will be thrown. Therefore, in order to avoid it, it is recommended to perform a call to the isSet(long) method to check if state data has been set.

Parameters:
zeroBitPlanes -
firstLayer -
Throws:
ErrorException

isSet

public boolean isSet(long inClassIdentifier)
Check whether zero bit planes and first layer has been set for a precinct.

Parameters:
inClassIdentifier - definition in JPIPMessageHeader.inClassIdentifier.
Returns:
true if data has been set. Otherwise, returns false.

encodePacketHeader

public byte[] encodePacketHeader(long inClassIdentifier,
                                 int[][][][] codingPassesAdded)
                          throws ErrorException,
                                 java.lang.IllegalAccessException
Encodes the packet header data in a byte array for the precinct which is referenced to as layer - component - resolution level - precinct, and whose coding passed are passed in the codingPassesAdded variable.

The buffer where the packet header are encoded can be retrieved through the getPacketHeaderBuffer method.

Parameters:
inClassIdentifier - definition in JPIPMessageHeader.inClassIdentifier.
codingPassesAdded - is a multi-dimensional array with the lengths of each coding-pass which will be included in this packet. Indexes means:
  subband: is the subband in the precinct   yBlock: is the yBlock in the subband   xBlock: is the xBlock in the subband   coding pass: coding passes to be added in this packet
Returns:
an one-dimensional array of bytes with the encoded packet header.
Throws:
ErrorException - when an error ocurrs in PacketHeadingCoding
java.lang.IllegalAccessException

reset

public void reset()
Sets attributes to its initial values.


getPacketHeaderBuffer

public byte[] getPacketHeaderBuffer()
Returns a byte array with the las packet header which has been encoded. The length of the byte array may be larger than the real length of the encoded packet header. Its real length can be obtained with the getLastPacketHeaderLength method.

Returns:
an one-dimensional array with the encoded packet header.

getPacketHeaderLength

public int getPacketHeaderLength()
Returns the length of the last encoded packet (in bytes).

Returns:
the length of the last encoded packet.

getLastEncodedLayer

public int getLastEncodedLayer(long inClassIdentifier)
Returns the last encoded layer.

Parameters:
inClassIdentifier - definition in JPIPMessageHeader.inClassIdentifier.
Returns:
last encoded layer.

toString

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

list

public void list(java.io.PrintStream out)
Prints the Packet Headers Encoder data out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.

encodeCodingPasses

private void encodeCodingPasses(int value)
                         throws ErrorException,
                                java.io.IOException
Gives a codeword to the value.

Parameters:
value - value to be coded.
Throws:
ErrorException - when passed value is not valid
java.io.IOException

encodeLengths

private int encodeLengths(int lblock,
                          int[] dataCodingPasses)
                   throws java.io.IOException
Calculate and codify the Lblock value and length of codeword segment

Parameters:
lblock - current value
dataCodingPasses - bytes contributed to a packet by the code-block
Returns:
Lblock updated
Throws:
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)