public bool DecodeBool(int context)
{
bool v;
int range_times_prob, lut_index;
range_times_prob =
(range * probabilities[context]) >> 16;
v = (code - low >= range_times_prob);
lut_index = probabilities[context] >> 8 | (v ? 256 : 0);
probabilities[context] += lut[lut_index];
if(v) {
low += range_times_prob;
range -= range_times_prob;
} else {
range = range_times_prob;
}
while(range <= 0x4000) {
low <<= 1;
range <<= 1;
code <<= 1;
code |= (shift >> (7-cntr))&1;
cntr++;
if(cntr == 8) {
offset++;
if(offset < size) {
shift = data[offset];
} else {
shift = (byte)0xff;
}
low &= 0xffff;
code &= 0xffff;
if(code < low) {
code |= (1<<16);
}
cntr = 0;
}
}
return v;
}
/* Maybe we should rewrite this namespace blocks. * I'm not sure */ public void DecodeCoeffs(ref short[] c) { if(buf == null) return; int[] bounds = {0,0,0}; if(par.no_ac) { Unpack u = new Unpack(buf); if(numX * numY == 1) { bounds[1] = c.Length; bounds[2] = frame.Width; DecodeCodeBlock(ref c,u,bounds); return; } for(int y = 0; y < numY; y++) { for(int x = 0; x < numX; x++) { if(u.DecodeBool()) continue; if(par.codeblock_mode_index != 0) qi += u.DecodeSint(); CalculateBounds(bounds,x,y); DecodeCodeBlock(ref c,u,bounds); } } } else { Arithmetic a = new Arithmetic(buf); if(numX * numY == 1) { bounds[1] = c.Length; bounds[2] = frame.Width; DecodeCodeBlock(ref c, a, bounds); return; } for(int y = 0; y < numY; y++) { for(int x = 0; x < numX; x++) { if(a.DecodeBool(Context.ZERO_CODEBLOCK)) continue; if(par.codeblock_mode_index != 0) qi += a.DecodeSint(Context.QUANTISER_CONT, Context.QUANTISER_VALUE, Context.QUANTISER_SIGN); CalculateBounds(bounds, x, y); DecodeCodeBlock(ref c, a, bounds); } } } }