Esempio n. 1
0
 public Motion(Parameters p, Buffer[] bufs, Block[][] frames)
 {
     par = p;
     refs = frames;
     vecs = new Vector[par.x_num_blocks * par.y_num_blocks];
     tmp_ref = new Block[refs.Length];
     ar = new Arithmetic[9];
     for(int i = 0; i < 9; i++)
         if(bufs[i] != null) ar[i] = new Arithmetic(bufs[i]);
 }
Esempio n. 2
0
 public void main()
 {
     //TODO dialogue to ask string
     string[] a = new string[0];
     FileStream input = TryOpen(a);
     byte[] d = new byte[input.Length];
     input.Read(d, 0, (int)input.Length);
     input.Close();
     input.Dispose();
     Arithmetic ar = new Arithmetic(d);
     TestArithmetic(ar);
 }
Esempio n. 3
0
 private void TestArithmetic(Arithmetic a)
 {
     byte[] d = new byte[a.BytesLeft()];
     for(int i = 0; i < d.Length; i++) {
         byte c = 0;
         for(int j = 0; j < 8; j++) {
         c = (byte)((c << 1) | a.DecodeBit(j));
         }
         d[i] = c;
     }
     String s = System.Text.Encoding.Default.GetString(d);
     Console.WriteLine(s);
 }
Esempio n. 4
0
 /* 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);
             }
         }
     }
 }
Esempio n. 5
0
        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++;
            }
        }
Esempio n. 6
0
 private void DecodeCodeBlock(ref short[] c, Arithmetic a, int[] bounds)
 {
     int qo = QuantOffset(qi);
     int qf = QuantFactor(qi);
     for(int i = bounds[0]+offset; i < bounds[1]; i += frame.Width*stride) {
         DecodeLineGeneric(ref c, a, i, bounds[2], qf, qo);
     }
 }