private int DecodeBlackCodeWord() {
int current, entry, bits, isT, code = -1;
int runLength = 0;
bool isWhite = false;
while (!isWhite) {
current = NextLesserThan8Bits(4);
entry = initBlack[current];
// Get the 3 fields from the entry
isT = entry & 0x0001;
bits = (entry >> 1) & 0x000f;
code = (entry >> 5) & 0x07ff;
if (code == 100) {
current = NextNBits(9);
entry = black[current];
// Get the 3 fields from the entry
isT = entry & 0x0001;
bits = (entry >> 1) & 0x000f;
code = (entry >> 5) & 0x07ff;
if (bits == 12) {
// Additional makeup codes
UpdatePointer(5);
current = NextLesserThan8Bits(4);
entry = additionalMakeup[current];
bits = (entry >> 1) & 0x07; // 3 bits 0000 0111
code = (entry >> 4) & 0x0fff; // 12 bits
runLength += code;
UpdatePointer(4 - bits);
} else if (bits == 15) {
// EOL code
throw new Exception("EOL code word encountered in Black run.");
} else {
runLength += code;
UpdatePointer(9 - bits);
if (isT == 0) {
isWhite = true;
}
}
} else if (code == 200) {
// Is a Terminating code
current = NextLesserThan8Bits(2);
entry = twoBitBlack[current];
code = (entry >> 5) & 0x07ff;
runLength += code;
bits = (entry >> 1) & 0x0f;
UpdatePointer(2 - bits);
isWhite = true;
} else {
// Is a Terminating code
runLength += code;
UpdatePointer(4 - bits);
isWhite = true;
}
}
return runLength;
}