protected static int jpeg_huff_decode(ref bitread_working_state state, int get_buffer, int bits_left, d_derived_tbl htbl, int min_bits)
{
/* HUFF_DECODE has determined that the code is at least min_bits */
/* bits long, so fetch that many bits in one swoop. */
int l = min_bits;
if (!CHECK_BIT_BUFFER(ref state, l, ref get_buffer, ref bits_left))
return -1;
int code = GET_BITS(l, get_buffer, ref bits_left);
/* Collect the rest of the Huffman code one bit at a time. */
/* This is per Figure F.16 in the JPEG spec. */
while (code > htbl.maxcode[l])
{
code <<= 1;
if (!CHECK_BIT_BUFFER(ref state, 1, ref get_buffer, ref bits_left))
return -1;
code |= GET_BITS(1, get_buffer, ref bits_left);
l++;
}
/* Unload the local registers */
state.get_buffer = get_buffer;
state.bits_left = bits_left;
/* With garbage input we may reach the sentinel value l = 17. */
if (l > 16)
{
state.cinfo.WARNMS(J_MESSAGE_CODE.JWRN_HUFF_BAD_CODE);
/* fake a zero as the safest result */
return 0;
}
return htbl.pub.Huffval[code + htbl.valoffset[l]];
}
}