private bool seek(int row, short sample)
{
if (row >= m_dir.td_imagelength)
{
/* out of range */
ErrorExt(this, m_clientdata, m_name,
"{0}: Row out of range, max {1}", row, m_dir.td_imagelength);
return false;
}
int strip;
if (m_dir.td_planarconfig == PlanarConfig.SEPARATE)
{
if (sample >= m_dir.td_samplesperpixel)
{
ErrorExt(this, m_clientdata, m_name,
"{0}: Sample out of range, max {1}", sample, m_dir.td_samplesperpixel);
return false;
}
if (m_dir.td_rowsperstrip != -1)
strip = sample * m_dir.td_stripsperimage + row / m_dir.td_rowsperstrip;
else
strip = 0;
}
else
{
if (m_dir.td_rowsperstrip != -1)
strip = row / m_dir.td_rowsperstrip;
else
strip = 0;
}
if (strip != m_curstrip)
{
/* different strip, refill */
if (!fillStrip(strip))
return false;
}
else if (row < m_row)
{
/*
* Moving backwards within the same strip: backup
* to the start and then decode forward (below).
*
* NB: If you're planning on lots of random access within a
* strip, it's better to just read and decode the entire
* strip, and then access the decoded data in a random fashion.
*/
if (!startStrip(strip))
return false;
}
if (row != m_row)
{
/*
* Seek forward to the desired row.
*/
if (!m_currentCodec.Seek(row - m_row))
return false;
m_row = row;
}
return true;
}