jj2000.j2k.util
Class CodestreamManipulator

java.lang.Object
  |
  +--jj2000.j2k.util.CodestreamManipulator

public class CodestreamManipulator
extends java.lang.Object

This class takes a legal JPEG 2000 codestream and performs some manipulation on it. Currently the manipulations supported are: Tile-parts


Field Summary
private  byte[] mainHeader
          The main header
private static int MAX_TPSOT
          The maximum number of a tile part index (TPsot)
private  int maxtp
          The maximum number of tile parts in any tile
private  int nt
          The number of tiles in the image
private  java.lang.String outname
          The name of the outfile
private  byte[][][] packetData
          Buffers containing the packet data
private  byte[][][] packetHeaders
          Buffers contaning the packet headers
private  java.lang.Integer[] positions
          The positions of the SOT, SOP and EPH markers
private  boolean ppmUsed
          Flag indicating whether packed packet headers in main header is used
private  int[] ppt
          The number of packets per tile
private  int pptp
          The number of packets per tile-part
private  boolean pptUsed
          Flag indicating whether packed packet headers in tile headers is used
private  byte[][][] sopMarkSeg
          Buffers containing the SOP marker segments
private  boolean tempEph
          Flag indicating whether EPH marker was only intended for parsing in This class and should be removed
private  boolean tempSop
          Flag indicating whether SOP marker was only intended for parsing in This class and should be removed
private  byte[][] tileHeaders
          Buffers containing the original tile headers
private  byte[][][] tileParts
          Buffers containing the tile parts
private static int TP_HEAD_LEN
          The length of a SOT plus a SOD marker
 
Constructor Summary
CodestreamManipulator(java.lang.String outname, int nt, int pptp, boolean ppm, boolean ppt, boolean tempSop, boolean tempEph)
          Instantiates a codestream manipulator..
 
Method Summary
private  void createTileParts()
          This method creates the tileparts from the buffered tile headers, packet headers and packet data
 int doCodestreamManipulation()
          This method performs the actual manipulation of the codestream which is the reparsing for tile parts and packed packet headers
private  void parseAndFind(BufferedRandomAccessFile fi)
          This method parses the codestream for SOT, SOP and EPH markers and removes header header bits signalling SOP and EPH markers if packed packet headers are used
private  void readAndBuffer(BufferedRandomAccessFile fi)
          This method reads and buffers the tile headers, packet headers and packet data.
private  void writeNewCodestream(BufferedRandomAccessFile fi)
          This method writes the new codestream to the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ppmUsed

private boolean ppmUsed
Flag indicating whether packed packet headers in main header is used


pptUsed

private boolean pptUsed
Flag indicating whether packed packet headers in tile headers is used


tempSop

private boolean tempSop
Flag indicating whether SOP marker was only intended for parsing in This class and should be removed


tempEph

private boolean tempEph
Flag indicating whether EPH marker was only intended for parsing in This class and should be removed


nt

private int nt
The number of tiles in the image


pptp

private int pptp
The number of packets per tile-part


outname

private java.lang.String outname
The name of the outfile


TP_HEAD_LEN

private static int TP_HEAD_LEN
The length of a SOT plus a SOD marker


MAX_TPSOT

private static int MAX_TPSOT
The maximum number of a tile part index (TPsot)


maxtp

private int maxtp
The maximum number of tile parts in any tile


ppt

private int[] ppt
The number of packets per tile


positions

private java.lang.Integer[] positions
The positions of the SOT, SOP and EPH markers


mainHeader

private byte[] mainHeader
The main header


tileParts

private byte[][][] tileParts
Buffers containing the tile parts


tileHeaders

private byte[][] tileHeaders
Buffers containing the original tile headers


packetHeaders

private byte[][][] packetHeaders
Buffers contaning the packet headers


packetData

private byte[][][] packetData
Buffers containing the packet data


sopMarkSeg

private byte[][][] sopMarkSeg
Buffers containing the SOP marker segments

Constructor Detail

CodestreamManipulator

public CodestreamManipulator(java.lang.String outname,
                             int nt,
                             int pptp,
                             boolean ppm,
                             boolean ppt,
                             boolean tempSop,
                             boolean tempEph)
Instantiates a codestream manipulator..

Parameters:
outname - The name of the original outfile
nt - The number of tiles in the image
pptp - Packets per tile-part. If zero, no division into tileparts is performed
ppm - Flag indicating that PPM marker is used
ppt - Flag indicating that PPT marker is used
tempSop - Flag indicating whether SOP merker should be removed
tempEph - Flag indicating whether EPH merker should be removed
Method Detail

doCodestreamManipulation

public int doCodestreamManipulation()
                             throws java.io.IOException
This method performs the actual manipulation of the codestream which is the reparsing for tile parts and packed packet headers

Returns:
The number of bytes that the file has increased by
Throws:
java.io.IOException - If an I/O error ocurred.

parseAndFind

private void parseAndFind(BufferedRandomAccessFile fi)
                   throws java.io.IOException
This method parses the codestream for SOT, SOP and EPH markers and removes header header bits signalling SOP and EPH markers if packed packet headers are used

Parameters:
fi - The file to parse the markers from
Throws:
java.io.IOException - If an I/O error ocurred.

readAndBuffer

private void readAndBuffer(BufferedRandomAccessFile fi)
                    throws java.io.IOException
This method reads and buffers the tile headers, packet headers and packet data.

Parameters:
fi - The file to read the headers and data from
Throws:
java.io.IOException - If an I/O error ocurred.

createTileParts

private void createTileParts()
                      throws java.io.IOException
This method creates the tileparts from the buffered tile headers, packet headers and packet data

Throws:
java.io.IOException - If an I/O error ocurred.

writeNewCodestream

private void writeNewCodestream(BufferedRandomAccessFile fi)
                         throws java.io.IOException
This method writes the new codestream to the file.

Parameters:
fi - The file to write the new codestream to
Throws:
java.io.IOException - If an I/O error ocurred.