jj2000.j2k.codestream.writer
Class HeaderEncoder

java.lang.Object
  |
  +--jj2000.j2k.codestream.writer.HeaderEncoder

public class HeaderEncoder
extends java.lang.Object
implements Markers, StdEntropyCoderOptions

This class writes almost of the markers and marker segments in main header and in tile-part headers. It is created by the run() method of the Encoder instance.

A marker segment includes a marker and eventually marker segment parameters. It is designed by the three letter code of the marker associated with the marker segment. JPEG 2000 part I defines 6 types of markers:

Main Header is written when Encoder instance calls encodeMainHeader whereas tile-part headers are written when the EBCOTRateAllocator instance calls encodeTilePartHeader.

See Also:
Encoder, Markers, EBCOTRateAllocator

Field Summary
protected  java.io.ByteArrayOutputStream baos
          The ByteArrayOutputStream to store header data.
private  int defimgn
          Nominal range bit of the component defining default values in QCD for main header
private  int deftilenr
          Nominal range bit of the component defining default values in QCD for tile headers
protected  ForwardWT dwt
          Reference to the DWT module
protected  EncoderSpecs encSpec
          The encoder specifications
protected  java.io.DataOutputStream hbuf
          The DataOutputStream to store header data.
protected  boolean[] isOrigSig
          An array specifying, for each component,if the data was signed or not
protected  int nComp
          The number of components in the image
protected  ImgData origSrc
          The image data reader.
protected  PostCompRateAllocator ralloc
          Reference to the rate allocator
protected  ROIScaler roiSc
          Reference to the ROI module
protected  Tiler tiler
          Reference to the tiler module
 
Fields inherited from interface jj2000.j2k.codestream.Markers
COC, COD, COM, CRG, EOC, EPH, EPH_LENGTH, ERS_SEG_MARKERS, ERS_SOP, MAX_COMP_BITDEPTH, MAX_LPPM, MAX_LPPT, PLM, PLT, POC, PPM, PPT, PRECINCT_PARTITION_DEF_SIZE, QCC, QCD, RCOM_GEN_USE, RGN, RSIZ_BASELINE, RSIZ_ER_FLAG, RSIZ_ROI, SCOX_PRECINCT_PARTITION, SCOX_USE_EPH, SCOX_USE_SOP, SIZ, SOC, SOD, SOP, SOP_LENGTH, SOT, SQCX_EXP_MASK, SQCX_EXP_SHIFT, SQCX_GB_MSK, SQCX_GB_SHIFT, SQCX_NO_QUANTIZATION, SQCX_SCALAR_DERIVED, SQCX_SCALAR_EXPOUNDED, SRGN_IMPLICIT, SSIZ_DEPTH_BITS, TLM
 
Fields inherited from interface jj2000.j2k.entropy.StdEntropyCoderOptions
FIRST_BYPASS_PASS_IDX, MAX_CB_AREA, MAX_CB_DIM, MIN_CB_DIM, NUM_EMPTY_PASSES_IN_MS_BP, NUM_NON_BYPASS_MS_BP, NUM_PASSES, OPT_BYPASS, OPT_ER_TERM, OPT_REG_TERM, OPT_RESET_MQ, OPT_SEG_MARKERS, OPT_VERT_STR_CAUSAL, STRIPE_HEIGHT
 
Constructor Summary
HeaderEncoder(ImgData origsrc, boolean[] isorigsig, ForwardWT dwt, Tiler tiler, EncoderSpecs encSpec, ROIScaler roiSc, PostCompRateAllocator ralloc)
          Initializes the header writer with the references to the coding chain.
 
Method Summary
 void encodeMainHeader()
          Write main header.
 void encodeTilePartHeader(int tileLength, int tileIdx)
          Writes tile-part header.
protected  byte[] getBuffer()
          Returns the byte-buffer used to store the codestream header.
protected  int getBufferLength()
          Returns the number of bytes used in the codestream header's buffer.
 int getLength()
          Returns the length of the header.
 void reset()
          Resets the contents of this HeaderEncoder to its initial state.
protected  void writeCOC(boolean mh, int tileIdx, int compIdx)
          Writes COC marker segment .
protected  void writeCOD(boolean mh, int tileIdx)
          Writes COD marker segment.
private  void writeCOM()
          Write a COM marker segment adding some comments to the codestream.
protected  void writeMainQCC(int compIdx)
          Writes QCC marker segment in main header.
protected  void writeMainQCD()
          Writes QCD marker segment in main header.
protected  void writePOC(boolean mh, int tileIdx)
          Writes POC marker segment.
private  void writeRGN(int tIdx)
          Writes the RGN marker segment in the tile header.
private  void writeSIZ()
          Writes SIZ marker segment of the codestream header.
private  void writeSOC()
          Start Of Codestream marker (SOC) signalling the beginning of a codestream.
protected  void writeTileQCC(int t, int compIdx)
          Writes QCC marker segment in tile header.
protected  void writeTileQCD(int tIdx)
          Writes QCD marker segment in tile header.
 void writeTo(BinaryDataOutput out)
          Writes the header to the specified BinaryDataOutput.
 void writeTo(java.io.OutputStream out)
          Writes the header to the specified OutputStream.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

defimgn

private int defimgn
Nominal range bit of the component defining default values in QCD for main header

deftilenr

private int deftilenr
Nominal range bit of the component defining default values in QCD for tile headers

nComp

protected int nComp
The number of components in the image

baos

protected java.io.ByteArrayOutputStream baos
The ByteArrayOutputStream to store header data. This handler is kept in order to use methods not accessible from a general DataOutputStream. For the other methods, it's better to use variable hbuf.
See Also:
hbuf

hbuf

protected java.io.DataOutputStream hbuf
The DataOutputStream to store header data. This kind of object is useful to write short, int, .... It's constructor takes baos as parameter.
See Also:
baos

origSrc

protected ImgData origSrc
The image data reader. Source of original data info

isOrigSig

protected boolean[] isOrigSig
An array specifying, for each component,if the data was signed or not

ralloc

protected PostCompRateAllocator ralloc
Reference to the rate allocator

dwt

protected ForwardWT dwt
Reference to the DWT module

tiler

protected Tiler tiler
Reference to the tiler module

roiSc

protected ROIScaler roiSc
Reference to the ROI module

encSpec

protected EncoderSpecs encSpec
The encoder specifications
Constructor Detail

HeaderEncoder

public HeaderEncoder(ImgData origsrc,
                     boolean[] isorigsig,
                     ForwardWT dwt,
                     Tiler tiler,
                     EncoderSpecs encSpec,
                     ROIScaler roiSc,
                     PostCompRateAllocator ralloc)
Initializes the header writer with the references to the coding chain.
Parameters:
origsrc - The original image data (before any component mixing, tiling, etc.)
isorigsig - An array specifying for each component if it was originally signed or not.
dwt - The discrete wavelet transform module.
tiler - The tiler module.
encSpec - The encoder specifications
roiSc - The ROI scaler module.
ralloc - The post compression rate allocator.
Method Detail

reset

public void reset()
Resets the contents of this HeaderEncoder to its initial state. It erases all the data in the header buffer and reactualizes the headerLength field of the bit stream writer.

getBuffer

protected byte[] getBuffer()
Returns the byte-buffer used to store the codestream header.
Returns:
A byte array countaining codestream header

getLength

public int getLength()
Returns the length of the header.
Returns:
The length of the header in bytes

writeTo

public void writeTo(BinaryDataOutput out)
             throws java.io.IOException
Writes the header to the specified BinaryDataOutput.
Parameters:
out - Where to write the header.

getBufferLength

protected int getBufferLength()
Returns the number of bytes used in the codestream header's buffer.
Returns:
Header length in buffer (without any header overhead)

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException
Writes the header to the specified OutputStream.
Parameters:
out - Where to write the header.

writeSOC

private void writeSOC()
               throws java.io.IOException
Start Of Codestream marker (SOC) signalling the beginning of a codestream.

writeSIZ

private void writeSIZ()
               throws java.io.IOException
Writes SIZ marker segment of the codestream header. It is a fixed information marker segment containing informations about image and tile sizes. It is required in the main header immediately after SOC marker segment.

writeCOD

protected void writeCOD(boolean mh,
                        int tileIdx)
                 throws java.io.IOException
Writes COD marker segment. COD is a functional marker segment containing the code style default (coding style, decomposition, layering) used for compressing all the components in an image.

The values can be overriden for an individual component by a COC marker in either the main or the tile header.

Parameters:
mh - Flag indicating whether this marker belongs to the main header
tileIdx - Tile index if the marker belongs to a tile-part header
See Also:
writeCOC(boolean, int, int)

writeCOC

protected void writeCOC(boolean mh,
                        int tileIdx,
                        int compIdx)
                 throws java.io.IOException
Writes COC marker segment . It is a functional marker containing the coding style for one component (coding style, decomposition, layering).

Its values overrides any value previously set in COD in the main header or in the tile header.

Parameters:
mh - Flag indicating whether the main header is to be written
tileIdx - Tile index
compIdx - index of the component which need use of the COC marker segment.
See Also:
writeCOD(boolean, int)

writeMainQCD

protected void writeMainQCD()
                     throws java.io.IOException
Writes QCD marker segment in main header. QCD is a functional marker segment countaining the quantization default used for compressing all the components in an image. The values can be overriden for an individual component by a QCC marker in either the main or the tile header.

writeMainQCC

protected void writeMainQCC(int compIdx)
                     throws java.io.IOException
Writes QCC marker segment in main header. It is a functional marker segment countaining the quantization used for compressing the specified component in an image. The values override for the specified component what was defined by a QCC marker in either the main or the tile header.
Parameters:
compIdx - Index of the component which needs QCC marker segment.

writeTileQCD

protected void writeTileQCD(int tIdx)
                     throws java.io.IOException
Writes QCD marker segment in tile header. QCD is a functional marker segment countaining the quantization default used for compressing all the components in an image. The values can be overriden for an individual component by a QCC marker in either the main or the tile header.
Parameters:
tIdx - Tile index

writeTileQCC

protected void writeTileQCC(int t,
                            int compIdx)
                     throws java.io.IOException
Writes QCC marker segment in tile header. It is a functional marker segment countaining the quantization used for compressing the specified component in an image. The values override for the specified component what was defined by a QCC marker in either the main or the tile header.
Parameters:
t - Tile index
compIdx - Index of the component which needs QCC marker segment.

writePOC

protected void writePOC(boolean mh,
                        int tileIdx)
                 throws java.io.IOException
Writes POC marker segment. POC is a functional marker segment containing the bounds and progression order for any progression order other than default in the codestream.
Parameters:
mh - Flag indicating whether the main header is to be written
tileIdx - Tile index

encodeMainHeader

public void encodeMainHeader()
                      throws java.io.IOException
Write main header. JJ2000 main header corresponds to the following sequence of marker segments:
  1. SOC
  2. SIZ
  3. COD
  4. COC (if needed)
  5. QCD
  6. QCC (if needed)
  7. POC (if needed)

writeCOM

private void writeCOM()
               throws java.io.IOException
Write a COM marker segment adding some comments to the codestream.

This marker is currently written in main header and indicates the JJ2000 encoder's version that has created the codestream.


writeRGN

private void writeRGN(int tIdx)
               throws java.io.IOException
Writes the RGN marker segment in the tile header. It describes the scaling value in each tile component

May be used in tile or main header. If used in main header, it refers to a ROI of the whole image, regardless of tiling. When used in tile header, only the particular tile is affected.

Parameters:
tIdx - The tile index
Throws:
java.io.IOException - If an I/O error occurs while reading from the encoder header stream

encodeTilePartHeader

public void encodeTilePartHeader(int tileLength,
                                 int tileIdx)
                          throws java.io.IOException
Writes tile-part header. JJ2000 tile-part header corresponds to the following sequence of marker segments:
  1. SOT
  2. COD (if needed)
  3. COC (if needed)
  4. QCD (if needed)
  5. QCC (if needed)
  6. RGN (if needed)
  7. POC (if needed)
  8. SOD
Parameters:
length - The length of the current tile-part.
tileIdx - Index of the tile to write