Class PktEncoder

java.lang.Object
jj2000.j2k.codestream.writer.PktEncoder

public class PktEncoder extends Object
This class builds packets and keeps the state information of packet interdependencies. It also supports saving the state and reverting (restoring) to the last saved state, with the save() and restore() methods.

Each time the encodePacket() method is called a new packet is encoded, the packet header is returned by the method, and the packet body can be obtained with the getLastBodyBuf() and getLastBodyLen() methods.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    The prefix for packet encoding options: 'P'
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new packet header encoder, using the information from the 'infoSrc' object.
  • Method Summary

    Modifier and Type
    Method
    Description
    encodePacket(int ly, int c, int r, int t, CBlkRateDistStats[][] cbs, int[][] tIndx, BitOutputBuffer hbuf, byte[] bbuf, int pIdx)
    Encodes a packet and returns the buffer containing the encoded packet header.
    byte[]
    Returns the buffer of the body of the last encoded packet.
    int
    Returns the length of the body of the last encoded packet, in bytes.
    static String[][]
    Returns the parameters that are used in this class and implementing classes.
    getPrecInfo(int t, int c, int r, int p)
    Returns information about a given precinct
    int
    Gives the length to read in current packet body to get all ROI information
    boolean
    Returns true if the current packet is writable i.e.
    boolean
    Tells if there was ROI information in the last written packet
    void
    Resets the state of the object to the initial state, as if the object was just created.
    void
    Restores the last saved state of this object.
    void
    Saves the current state of this object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • OPT_PREFIX

      public static final char OPT_PREFIX
      The prefix for packet encoding options: 'P'
      See Also:
  • Constructor Details

    • PktEncoder

      public PktEncoder(CodedCBlkDataSrcEnc infoSrc, J2KImageWriteParamJava wp, Point[][][] numPrec)
      Creates a new packet header encoder, using the information from the 'infoSrc' object. The information used is the number of components, number of tiles, subband decomposition, etc.

      Note that this constructor visits all the tiles in the 'infoSrc' object. The 'infoSrc' object is left at the original tile (i.e. the current tile before calling this constructor), but any side effects of visiting the tiles is not reverted.

      Parameters:
      infoSrc - The source of information to construct the object.
      wp - The parameters for the encoding
      numPrec - Maximum number of precinct in each tile, component and resolution level.
  • Method Details

    • encodePacket

      public BitOutputBuffer encodePacket(int ly, int c, int r, int t, CBlkRateDistStats[][] cbs, int[][] tIndx, BitOutputBuffer hbuf, byte[] bbuf, int pIdx)
      Encodes a packet and returns the buffer containing the encoded packet header. The code-blocks appear in a 3D array of CBlkRateDistStats, 'cbs'. The first index is the tile index in lexicographical order, the second index is the subband index (as defined in the Subband class), and the third index is the code-block index (whithin the subband tile) in lexicographical order as well. The indexes of the new truncation points for each code-block are specified by the 3D array of int 'tIndx'. The indices of this array are the same as for cbs. The truncation point indices in 'tIndx' are the indices of the elements of the 'truncIdxs' array, of the CBlkRateDistStats class, that give the real truncation points. If a truncation point index is negative it means that the code-block has not been included in any layer yet. If the truncation point is less than or equal to the highest truncation point used in previous layers then the code-block is not included in the packet. Otherwise, if larger, the code-block is included in the packet. The body of the packet can be obtained with the getLastBodyBuf() and getLastBodyLen() methods.

      Layers must be coded in increasing order, in consecutive manner, for each tile, component and resolution level (e.g., layer 1, then layer 2, etc.). For different tile, component and/or resolution level no particular order must be followed.

      Parameters:
      ly - The layer index (starts at 1).
      c - The component index.
      r - The resolution level
      t - Index of the current tile
      cbs - The 3D array of coded code-blocks.
      tIndx - The truncation point indices for each code-block.
      hbuf - The header buffer. If null a new BitOutputBuffer is created and returned. This buffer is reset before anything is written to it.
      bbuf - The body buffer. If null a new one is created. If not large enough a new one is created.
      pIdx - The precinct index.
      Returns:
      The buffer containing the packet header.
    • getLastBodyBuf

      public byte[] getLastBodyBuf()
      Returns the buffer of the body of the last encoded packet. The length of the body can be retrieved with the getLastBodyLen() method. The length of the array returned by this method may be larger than the actual body length.
      Returns:
      The buffer of body of the last encoded packet.
      Throws:
      IllegalArgumentException - If no packet has been coded since last reset(), last restore(), or object creation.
      See Also:
    • getLastBodyLen

      public int getLastBodyLen()
      Returns the length of the body of the last encoded packet, in bytes. The body itself can be retrieved with the getLastBodyBuf() method.
      Returns:
      The length of the body of last encoded packet, in bytes.
      See Also:
    • save

      public void save()
      Saves the current state of this object. The last saved state can be restored with the restore() method.
      See Also:
    • restore

      public void restore()
      Restores the last saved state of this object. An IllegalArgumentException is thrown if no state has been saved.
      See Also:
    • reset

      public void reset()
      Resets the state of the object to the initial state, as if the object was just created.
    • isPacketWritable

      public boolean isPacketWritable()
      Returns true if the current packet is writable i.e. should be written. Returns false otherwise.
    • isROIinPkt

      public boolean isROIinPkt()
      Tells if there was ROI information in the last written packet
    • getROILen

      public int getROILen()
      Gives the length to read in current packet body to get all ROI information
    • getParameterInfo

      public static String[][] getParameterInfo()
      Returns the parameters that are used in this class and implementing classes. It returns a 2D String array. Each of the 1D arrays is for a different option, and they have 3 elements. The first element is the option name, the second one is the synopsis, the third one is a long description of what the parameter is and the fourth is its default value. The synopsis or description may be 'null', in which case it is assumed that there is no synopsis or description of the option, respectively. Null may be returned if no options are supported.
      Returns:
      the options name, their synopsis and their explanation, or null if no options are supported.
    • getPrecInfo

      public PrecInfo getPrecInfo(int t, int c, int r, int p)
      Returns information about a given precinct
      Parameters:
      t - Tile index.
      c - Component index.
      r - Resolution level index.
      p - Precinct index