private int readTilePartHeader()
{
HeaderInfo.SOT ms = hi.NewSOT;
// SOT marker
short marker = in_Renamed.readShort();
if (marker != CSJ2K.j2k.codestream.Markers.SOT)
{
if (marker == CSJ2K.j2k.codestream.Markers.EOC)
{
isEOCFound = true;
return - 1;
}
else
{
throw new CorruptedCodestreamException("SOT tag not found " + "in tile-part start");
}
}
isEOCFound = false;
// Lsot (shall equals 10)
int lsot = in_Renamed.readUnsignedShort();
ms.lsot = lsot;
if (lsot != 10)
throw new CorruptedCodestreamException("Wrong length for " + "SOT marker segment: " + lsot);
// Isot
int tile = in_Renamed.readUnsignedShort();
ms.isot = tile;
if (tile > 65534)
{
throw new CorruptedCodestreamException("Tile index too high in " + "tile-part.");
}
// Psot
int psot = in_Renamed.readInt();
ms.psot = psot;
isPsotEqualsZero = (psot != 0)?false:true;
if (psot < 0)
{
throw new NotImplementedException("Tile length larger " + "than maximum supported");
}
// TPsot
int tilePart = in_Renamed.read();
ms.tpsot = tilePart;
if (tilePart != tilePartsRead[tile] || tilePart < 0 || tilePart > 254)
{
throw new CorruptedCodestreamException("Out of order tile-part");
}
// TNsot
int nrOfTileParts = in_Renamed.read();
ms.tnsot = nrOfTileParts;
hi.sotValue["t" + tile + "_tp" + tilePart] = ms;
if (nrOfTileParts == 0)
{
// The number of tile-part is not specified in
// this tile-part header.
// Assumes that there will be another tile-part in the codestream
// that will indicate the number of tile-parts for this tile)
int nExtraTp;
if (tileParts[tile] == 0 || tileParts[tile] == tilePartLen.Length)
{
// Then there are two tile-parts (one is the current and the
// other will indicate the number of tile-part for this tile)
nExtraTp = 2;
remainingTileParts += 1;
}
else
{
// There is already one scheduled extra tile-part. In this
// case just add place for the current one
nExtraTp = 1;
}
tileParts[tile] += nExtraTp;
nrOfTileParts = tileParts[tile];
FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Header of tile-part " + tilePart + " of tile " + tile + ", does not indicate the total" + " number of tile-parts. Assuming that there are " + nrOfTileParts + " tile-parts for this tile.");
// Increase and re-copy tilePartLen array
int[] tmpA = tilePartLen[tile];
tilePartLen[tile] = new int[nrOfTileParts];
for (int i = 0; i < nrOfTileParts - nExtraTp; i++)
{
tilePartLen[tile][i] = tmpA[i];
}
// Increase and re-copy tilePartNum array
tmpA = tilePartNum[tile];
tilePartNum[tile] = new int[nrOfTileParts];
for (int i = 0; i < nrOfTileParts - nExtraTp; i++)
{
tilePartNum[tile][i] = tmpA[i];
}
// Increase and re-copy firsPackOff array
tmpA = firstPackOff[tile];
firstPackOff[tile] = new int[nrOfTileParts];
for (int i = 0; i < nrOfTileParts - nExtraTp; i++)
{
firstPackOff[tile][i] = tmpA[i];
}
// Increase and re-copy tilePartHeadLen array
tmpA = tilePartHeadLen[tile];
tilePartHeadLen[tile] = new int[nrOfTileParts];
for (int i = 0; i < nrOfTileParts - nExtraTp; i++)
{
tilePartHeadLen[tile][i] = tmpA[i];
}
}
else
{
// The number of tile-parts is specified in the tile-part
// header
// Check if it is consistant with what was found in previous
// tile-part headers
if (tileParts[tile] == 0)
{
// First tile-part: OK
remainingTileParts += nrOfTileParts - 1;
tileParts[tile] = nrOfTileParts;
tilePartLen[tile] = new int[nrOfTileParts];
tilePartNum[tile] = new int[nrOfTileParts];
firstPackOff[tile] = new int[nrOfTileParts];
tilePartHeadLen[tile] = new int[nrOfTileParts];
}
else if (tileParts[tile] > nrOfTileParts)
{
// Already found more tile-parts than signaled here
throw new CorruptedCodestreamException("Invalid number " + "of tile-parts in" + " tile " + tile + ": " + nrOfTileParts);
}
else
{
// Signaled number of tile-part fits with number of
// previously found tile-parts
remainingTileParts += nrOfTileParts - tileParts[tile];
if (tileParts[tile] != nrOfTileParts)
{
// Increase and re-copy tilePartLen array
int[] tmpA = tilePartLen[tile];
tilePartLen[tile] = new int[nrOfTileParts];
for (int i = 0; i < tileParts[tile] - 1; i++)
{
tilePartLen[tile][i] = tmpA[i];
}
// Increase and re-copy tilePartNum array
tmpA = tilePartNum[tile];
tilePartNum[tile] = new int[nrOfTileParts];
for (int i = 0; i < tileParts[tile] - 1; i++)
{
tilePartNum[tile][i] = tmpA[i];
}
// Increase and re-copy firstPackOff array
tmpA = firstPackOff[tile];
firstPackOff[tile] = new int[nrOfTileParts];
for (int i = 0; i < tileParts[tile] - 1; i++)
{
firstPackOff[tile][i] = tmpA[i];
}
// Increase and re-copy tilePartHeadLen array
tmpA = tilePartHeadLen[tile];
tilePartHeadLen[tile] = new int[nrOfTileParts];
for (int i = 0; i < tileParts[tile] - 1; i++)
{
tilePartHeadLen[tile][i] = tmpA[i];
}
}
}
}
// Other markers
hd.resetHeaderMarkers();
hd.nTileParts[tile] = nrOfTileParts;
// Decode and store the tile-part header (i.e. until a SOD marker is
// found)
do
{
hd.extractTilePartMarkSeg(in_Renamed.readShort(), in_Renamed, tile, tilePart);
}
while ((hd.NumFoundMarkSeg & CSJ2K.j2k.codestream.reader.HeaderDecoder.SOD_FOUND) == 0);
// Read each marker segment previously found
hd.readFoundTilePartMarkSeg(tile, tilePart);
tilePartLen[tile][tilePart] = psot;
tilePartNum[tile][tilePart] = totTilePartsRead;
totTilePartsRead++;
// Add to list of which tile each successive tile-part belongs.
// This list is needed if there are PPM markers used
hd.TileOfTileParts = tile;
return tile;
}