private int FindNextLine()
{
// Set maximum and current bit index into the compressed data.
int bitIndexMax = data.Length * 8 - 1;
int bitIndexMax12 = bitIndexMax - 12;
int bitIndex = bytePointer * 8 + bitPointer;
// Loop while at least 12 bits are available.
while (bitIndex <= bitIndexMax12) {
// Get the next 12 bits.
int next12Bits = NextNBits(12);
bitIndex += 12;
// Loop while the 12 bits are not unity, i.e., while the EOL
// has not been reached, and there is at least one bit left.
while (next12Bits != 1 && bitIndex < bitIndexMax) {
next12Bits =
((next12Bits & 0x000007ff) << 1)
| (NextLesserThan8Bits(1) & 0x00000001);
bitIndex++;
}
if (next12Bits == 1) { // now positioned just after EOL
if (oneD == 1) { // two-dimensional coding
if (bitIndex < bitIndexMax) {
// check next bit against type of line being sought
return NextLesserThan8Bits(1);
}
} else {
return 1;
}
}
}
// EOL not found.
throw new Exception();
}