public virtual bool readSOPMarker(int[] nBytes, int p, int c, int r)
{
int val;
byte[] sopArray = new byte[6];
int tIdx = src.TileIdx;
int mins = (r == 0)?0:1;
int maxs = (r == 0)?1:4;
bool precFound = false;
for (int s = mins; s < maxs; s++)
{
if (p < ppinfo[c][r].Length)
{
precFound = true;
}
}
if (!precFound)
{
return false;
}
// If SOP markers are not used, return
if (!sopUsed)
{
return false;
}
// Check if SOP is used for this packet
int pos = ehs.Pos;
if ((short) ((ehs.read() << 8) | ehs.read()) != CSJ2K.j2k.codestream.Markers.SOP)
{
ehs.seek(pos);
return false;
}
ehs.seek(pos);
// If length of SOP marker greater than remaining bytes to read for
// this tile return true
if (nBytes[tIdx] < 6)
{
return true;
}
nBytes[tIdx] -= 6;
// Read marker into array 'sopArray'
ehs.readFully(sopArray, 0, CSJ2K.j2k.codestream.Markers.SOP_LENGTH);
// Check if this is the correct marker
val = sopArray[0];
val <<= 8;
val |= sopArray[1];
if (val != CSJ2K.j2k.codestream.Markers.SOP)
{
throw new System.InvalidOperationException("Corrupted Bitstream: Could not parse SOP " + "marker !");
}
// Check if length is correct
val = (sopArray[2] & 0xff);
val <<= 8;
val |= (sopArray[3] & 0xff);
if (val != 4)
{
throw new System.InvalidOperationException("Corrupted Bitstream: Corrupted SOP marker !");
}
// Check if sequence number if ok
val = (sopArray[4] & 0xff);
val <<= 8;
val |= (sopArray[5] & 0xff);
if (!pph && val != pktIdx)
{
throw new System.InvalidOperationException("Corrupted Bitstream: SOP marker out of " + "sequence !");
}
if (pph && val != pktIdx - 1)
{
// if packed packet headers are used, packet header was read
// before SOP marker segment
throw new System.InvalidOperationException("Corrupted Bitstream: SOP marker out of " + "sequence !");
}
return false;
}