public PrecinctSizeSpec(int nt, int nc, byte type, BlkImgDataSrc imgsrc, IntegerSpec dls, ParameterList pl)
: base(nt, nc, type)
{
this.dls = dls;
// The precinct sizes are stored in a 2 elements vector array, the
// first element containing a vector for the precincts width for each
// resolution level and the second element containing a vector for the
// precincts height for each resolution level. The precincts sizes are
// specified from the highest resolution level to the lowest one
// (i.e. 0). If there are less elements than the number of
// decomposition levels, the last element is used for all remaining
// resolution levels (i.e. if the precincts sizes are specified only
// for resolutions levels 5, 4 and 3, then the precincts size for
// resolution levels 2, 1 and 0 will be the same as the size used for
// resolution level 3).
// Boolean used to know if we were previously reading a precinct's
// size or if we were reading something else.
bool wasReadingPrecinctSize = false;
System.String param = pl.getParameter(optName);
// Set precinct sizes to default i.e. 2^15 =
// Markers.PRECINCT_PARTITION_DEF_SIZE
System.Collections.Generic.List<System.Int32>[] tmpv = new List<int>[2];
tmpv[0] = new List<int>(10); // ppx
tmpv[0].Add((System.Int32) CSJ2K.j2k.codestream.Markers.PRECINCT_PARTITION_DEF_SIZE);
tmpv[1] = new List<int>(10); // ppy
tmpv[1].Add((System.Int32) CSJ2K.j2k.codestream.Markers.PRECINCT_PARTITION_DEF_SIZE);
setDefault(tmpv);
if (param == null)
{
// No precinct size specified in the command line so we do not try
// to parse it.
return ;
}
// Precinct partition is used : parse arguments
SupportClass.Tokenizer stk = new SupportClass.Tokenizer(param);
byte curSpecType = SPEC_DEF; // Specification type of the
// current parameter
bool[] tileSpec = null; // Tiles concerned by the specification
bool[] compSpec = null; // Components concerned by the specification
int ci, ti; //i, xIdx removed
bool endOfParamList = false;
System.String word = null; // current word
System.Int32 w, h;
System.String errMsg = null;
while ((stk.HasMoreTokens() || wasReadingPrecinctSize) && !endOfParamList)
{
System.Collections.Generic.List<System.Int32>[] v = new List<int>[2]; // v[0] : ppx, v[1] : ppy
// We do not read the next token if we were reading a precinct's
// size argument as we have already read the next token into word.
if (!wasReadingPrecinctSize)
{
word = stk.NextToken();
}
wasReadingPrecinctSize = false;
switch (word[0])
{
case 't': // Tiles specification
tileSpec = parseIdx(word, nTiles);
if (curSpecType == SPEC_COMP_DEF)
{
curSpecType = SPEC_TILE_COMP;
}
else
{
curSpecType = SPEC_TILE_DEF;
}
break;
case 'c': // Components specification
compSpec = parseIdx(word, nComp);
if (curSpecType == SPEC_TILE_DEF)
{
curSpecType = SPEC_TILE_COMP;
}
else
{
curSpecType = SPEC_COMP_DEF;
}
break;
default:
if (!System.Char.IsDigit(word[0]))
{
errMsg = "Bad construction for parameter: " + word;
throw new System.ArgumentException(errMsg);
}
// Initialises Vector objects
v[0] = new List<int>(10); // ppx
v[1] = new List<int>(10); // ppy
while (true)
{
// Now get the precinct dimensions
try
{
// Get precinct width
w = System.Int32.Parse(word);
// Get next word in argument list
try
{
word = stk.NextToken();
}
catch (System.ArgumentOutOfRangeException e)
{
errMsg = "'" + optName + "' option : could not " + "parse the precinct's width";
throw new System.ArgumentException(errMsg);
}
// Get precinct height
h = System.Int32.Parse(word);
if (w != (1 << MathUtil.log2(w)) || h != (1 << MathUtil.log2(h)))
{
errMsg = "Precinct dimensions must be powers of 2";
throw new System.ArgumentException(errMsg);
}
}
catch (System.FormatException e)
{
errMsg = "'" + optName + "' option : the argument '" + word + "' could not be parsed.";
throw new System.ArgumentException(errMsg);
}
// Store packet's dimensions in Vector arrays
v[0].Add(w);
v[1].Add(h);
// Try to get the next token
if (stk.HasMoreTokens())
{
word = stk.NextToken();
if (!System.Char.IsDigit(word[0]))
{
// The next token does not start with a digit so
// it is not a precinct's size argument. We set
// the wasReadingPrecinctSize booleen such that we
// know that we don't have to read another token
// and check for the end of the parameters list.
wasReadingPrecinctSize = true;
if (curSpecType == SPEC_DEF)
{
setDefault(v);
}
else if (curSpecType == SPEC_TILE_DEF)
{
for (ti = tileSpec.Length - 1; ti >= 0; ti--)
{
if (tileSpec[ti])
{
setTileDef(ti, v);
}
}
}
else if (curSpecType == SPEC_COMP_DEF)
{
for (ci = compSpec.Length - 1; ci >= 0; ci--)
{
if (compSpec[ci])
{
setCompDef(ci, v);
}
}
}
else
{
for (ti = tileSpec.Length - 1; ti >= 0; ti--)
{
for (ci = compSpec.Length - 1; ci >= 0; ci--)
{
if (tileSpec[ti] && compSpec[ci])
{
setTileCompVal(ti, ci, v);
}
}
}
}
// Re-initialize
curSpecType = SPEC_DEF;
tileSpec = null;
compSpec = null;
// Go back to 'normal' parsing
break;
}
else
{
// Next token starts with a digit so read it
}
}
else
{
// We have reached the end of the parameters list so
// we store the last precinct's sizes and we stop
if (curSpecType == SPEC_DEF)
{
setDefault(v);
}
else if (curSpecType == SPEC_TILE_DEF)
{
for (ti = tileSpec.Length - 1; ti >= 0; ti--)
{
if (tileSpec[ti])
{
setTileDef(ti, v);
}
}
}
else if (curSpecType == SPEC_COMP_DEF)
{
for (ci = compSpec.Length - 1; ci >= 0; ci--)
{
if (compSpec[ci])
{
setCompDef(ci, v);
}
}
}
else
{
for (ti = tileSpec.Length - 1; ti >= 0; ti--)
{
for (ci = compSpec.Length - 1; ci >= 0; ci--)
{
if (tileSpec[ti] && compSpec[ci])
{
setTileCompVal(ti, ci, v);
}
}
}
}
endOfParamList = true;
break;
}
} // while (true)
break;
} // switch
} // while
}