/* 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); } } } }
private void DecodeLineGeneric(ref short[] c, Arithmetic a, int lineOffset, int blockWidth, int qf, int qo) { int y = (lineOffset - offset)/(stride*frame.Width); int x = ((lineOffset)%(frame.Width))/stride; int parentLine = (y/2)*(2*frame.Width*stride); int parentOffset = (orient == 1 ? stride : (orient == 2 ? stride*frame.Width : stride*frame.Width + stride)); for(int i = lineOffset; i < blockWidth + lineOffset; i += stride) { bool zparent = true, znhood = true; if(level > 0) { zparent = (c[parentLine + parentOffset+(x/2)*stride*2] == 0); } if(x > 0) znhood = (znhood && c[i-stride] == 0); if(y > 0) znhood = (znhood && c[i-stride*frame.Width] == 0); if(x > 0 && y > 0) znhood = (znhood && c[i-stride-stride*frame.Width] == 0); int cont = 0, sign = 0; if(zparent) { cont = (znhood ? Context.ZPZN_F1 : Context.ZPNN_F1); } else { cont = (znhood ? Context.NPZN_F1 : Context.NPNN_F1); } int v = a.DecodeUint(cont, Context.COEFF_DATA); if(orient == 1 && y > 0) { sign = c[i - frame.Width*stride]; } else if(orient == 2 && x > 0) { sign = c[i - stride]; } sign = (sign > 0 ? Context.SIGN_POS : (sign < 0 ? Context.SIGN_NEG : Context.SIGN_ZERO)); if(v > 0) { v = (v * qf + qo + 2) >> 2; v = (a.DecodeBool(sign) ? -v : v); } c[i] = (short)v; x++; } }