protected internal virtual void writeCOC(bool mh, int tileIdx, int compIdx)
{
AnWTFilter[][] filt;
bool precinctPartitionUsed;
int tmp;
int mrl = 0, a = 0;
int ppx = 0, ppy = 0;
Progression[] prog;
if (mh)
{
mrl = ((System.Int32) encSpec.dls.getCompDef(compIdx));
// Get precinct size for specified component
ppx = encSpec.pss.getPPX(- 1, compIdx, mrl);
ppy = encSpec.pss.getPPY(- 1, compIdx, mrl);
prog = (Progression[]) (encSpec.pocs.getCompDef(compIdx));
}
else
{
mrl = ((System.Int32) encSpec.dls.getTileCompVal(tileIdx, compIdx));
// Get precinct size for specified component/tile
ppx = encSpec.pss.getPPX(tileIdx, compIdx, mrl);
ppy = encSpec.pss.getPPY(tileIdx, compIdx, mrl);
prog = (Progression[]) (encSpec.pocs.getTileCompVal(tileIdx, compIdx));
}
if (ppx != CSJ2K.j2k.codestream.Markers.PRECINCT_PARTITION_DEF_SIZE || ppy != CSJ2K.j2k.codestream.Markers.PRECINCT_PARTITION_DEF_SIZE)
{
precinctPartitionUsed = true;
}
else
{
precinctPartitionUsed = false;
}
if (precinctPartitionUsed)
{
// If precinct partition is used we add one byte per resolution
// level i.e. mrl+1 (+1 for resolution 0).
a = mrl + 1;
}
// COC marker
hbuf.Write((System.Int16) CSJ2K.j2k.codestream.Markers.COC);
// Lcoc (marker segment length (in bytes))
// Basic: Lcoc(2 bytes)+Scoc(1)+ Ccoc(1 or 2)+SPcod(5+a)
int markSegLen = 8 + ((nComp < 257)?1:2) + a;
// Rounded to the nearest even value greater or equals
hbuf.Write((System.Int16) markSegLen);
// Ccoc
if (nComp < 257)
{
hbuf.Write((System.Byte) compIdx);
}
else
{
hbuf.Write((System.Int16) compIdx);
}
// Scod (coding style parameter)
tmp = 0;
if (precinctPartitionUsed)
{
tmp = CSJ2K.j2k.codestream.Markers.SCOX_PRECINCT_PARTITION;
}
hbuf.Write((System.Byte) tmp);
// SPcoc
// Number of decomposition levels
hbuf.Write((System.Byte) mrl);
// Code-block width and height
if (mh)
{
// main header, get component default values
tmp = encSpec.cblks.getCBlkWidth(ModuleSpec.SPEC_COMP_DEF, - 1, compIdx);
hbuf.Write((System.Byte) (MathUtil.log2(tmp) - 2));
tmp = encSpec.cblks.getCBlkHeight(ModuleSpec.SPEC_COMP_DEF, - 1, compIdx);
hbuf.Write((System.Byte) (MathUtil.log2(tmp) - 2));
}
else
{
// tile header, get tile component values
tmp = encSpec.cblks.getCBlkWidth(ModuleSpec.SPEC_TILE_COMP, tileIdx, compIdx);
hbuf.Write((System.Byte) (MathUtil.log2(tmp) - 2));
tmp = encSpec.cblks.getCBlkHeight(ModuleSpec.SPEC_TILE_COMP, tileIdx, compIdx);
hbuf.Write((System.Byte) (MathUtil.log2(tmp) - 2));
}
// Entropy coding mode options
tmp = 0;
if (mh)
{
// Main header
// Lazy coding mode ?
if (((System.String) encSpec.bms.getCompDef(compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_BYPASS;
}
// MQ reset after each coding pass ?
if (((System.String) encSpec.mqrs.getCompDef(compIdx)).ToUpper().Equals("on".ToUpper()))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_RESET_MQ;
}
// MQ termination after each arithmetically coded coding pass ?
if (((System.String) encSpec.rts.getCompDef(compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_TERM_PASS;
}
// Vertically stripe-causal context mode ?
if (((System.String) encSpec.css.getCompDef(compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_VERT_STR_CAUSAL;
}
// Predictable termination ?
if (((System.String) encSpec.tts.getCompDef(compIdx)).Equals("predict"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_PRED_TERM;
}
// Error resilience segmentation symbol insertion ?
if (((System.String) encSpec.sss.getCompDef(compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_SEG_SYMBOLS;
}
}
else
{
// Tile Header
if (((System.String) encSpec.bms.getTileCompVal(tileIdx, compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_BYPASS;
}
// MQ reset after each coding pass ?
if (((System.String) encSpec.mqrs.getTileCompVal(tileIdx, compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_RESET_MQ;
}
// MQ termination after each arithmetically coded coding pass ?
if (((System.String) encSpec.rts.getTileCompVal(tileIdx, compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_TERM_PASS;
}
// Vertically stripe-causal context mode ?
if (((System.String) encSpec.css.getTileCompVal(tileIdx, compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_VERT_STR_CAUSAL;
}
// Predictable termination ?
if (((System.String) encSpec.tts.getTileCompVal(tileIdx, compIdx)).Equals("predict"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_PRED_TERM;
}
// Error resilience segmentation symbol insertion ?
if (((System.String) encSpec.sss.getTileCompVal(tileIdx, compIdx)).Equals("on"))
{
tmp |= CSJ2K.j2k.entropy.StdEntropyCoderOptions.OPT_SEG_SYMBOLS;
}
}
hbuf.Write((System.Byte) tmp);
// Wavelet transform
// Wavelet Filter
if (mh)
{
filt = ((AnWTFilter[][]) encSpec.wfs.getCompDef(compIdx));
hbuf.Write((System.Byte) filt[0][0].FilterType);
}
else
{
filt = ((AnWTFilter[][]) encSpec.wfs.getTileCompVal(tileIdx, compIdx));
hbuf.Write((System.Byte) filt[0][0].FilterType);
}
// Precinct partition
if (precinctPartitionUsed)
{
// Write the precinct size for each resolution level + 1
// (resolution 0) if precinct partition is used.
System.Collections.Generic.List<System.Int32>[] v = null;
if (mh)
{
v = (System.Collections.Generic.List<System.Int32>[])encSpec.pss.getCompDef(compIdx);
}
else
{
v = (System.Collections.Generic.List<System.Int32>[])encSpec.pss.getTileCompVal(tileIdx, compIdx);
}
for (int r = mrl; r >= 0; r--)
{
if (r >= v[1].Count)
{
tmp = ((System.Int32) v[1][v[1].Count - 1]);
}
else
{
tmp = ((System.Int32) v[1][r]);
}
int yExp = (MathUtil.log2(tmp) << 4) & 0x00F0;
if (r >= v[0].Count)
{
tmp = ((System.Int32) v[0][v[0].Count - 1]);
}
else
{
tmp = ((System.Int32) v[0][r]);
}
int xExp = MathUtil.log2(tmp) & 0x000F;
hbuf.Write((System.Byte) (yExp | xExp));
}
}
}