Beispiel #1
0
 public int Decode(IBitStream stream, BitStreamCtx ctx)
 {
     int min = 0;
     int galloping = 1;
     int check;
     int u = 0;
     while (true) {
         check = (1 << galloping) - 1;
         if (stream.Read (ctx)) {
             min = check + 1;
             ++galloping;
         } else {
             if (galloping == 1) {
                 if (stream.Read(ctx)) {
                     u++;
                 }
                 return u;
             } else {
                 u += min;
                 min = 0;
                 galloping = 1;
             }
         }
     }
 }
 public long Decode(IBitStream stream, BitStreamCtx ctx)
 {
     long min = 0;
     long check;
     long u = 0;
     int galloping = 1;
     while (true) {
         check = (1L << galloping) - 1L;
         if (stream.Read (ctx)) {
             min = check + 1L;
             ++galloping;
         } else {
             if (galloping == 1) {
                 if (stream.Read (ctx)) {
                     u++;
                 }
                 return u;
             } else {
                 u += min;
                 min = 0L;
                 galloping = 1;
             }
         }
     }
 }
        public double Deserialize(IBitStream bitStream)
        {
            int value;

            bitStream.Read(out value, 0, _bitLength);
            return(value + _variable.MinValue);
        }
Beispiel #4
0
 public int Decode(IBitStream Buffer, BitStreamCtx ctx)
 {
     int u = Buffer.ReadZeros (ctx);
     //int u = Buffer.ReadOnes ();
     Buffer.Read (ctx);
     return u;
 }
Beispiel #5
0
        public double Deserialize(IBitStream bitStream)
        {
            int value;

            bitStream.Read(out value, 0, _bitLength);
            return((value * Math.Pow(10, -_variable.DecimalPlaces)) + _variable.MinValue);
        }
        public double Deserialize(IBitStream bitStream)
        {
            bool result;

            bitStream.Read(out result);
            return(result ? 1 : 0);
        }
Beispiel #7
0
 public int ArrayGet(IBitStream Buffer, int pos)
 {
     long p = pos;
     p *= this.NumBits;
     var ctx = new BitStreamCtx (p);
     int number = (int)Buffer.Read (this.NumBits, ctx);
     return number;
 }
Beispiel #8
0
 public long Decode(IBitStream Buffer, BitStreamCtx ctx)
 {
     int numbits = unary.Decode (Buffer, ctx);
     if (numbits == 0) {
         return 1L;
     } else {
         ulong number;
         if (numbits <= 32) {
             number = Buffer.Read (numbits, ctx);
         } else {
             number = Buffer.Read (32, ctx);
             number |= Buffer.Read (numbits - 32, ctx) << 32;
         }
         number = (1UL << numbits) | number;
         return (long)number;
     }
 }
Beispiel #9
0
        public long Decode(IBitStream Buffer, BitStreamCtx ctx)
        {
            int len_code = gammacoder.Decode (Buffer, ctx);
            --len_code;
            if (len_code == 0) {
                return 1L;
            } else {
                ulong number;
                if (len_code <= 32) {
                    number = Buffer.Read (len_code, ctx);
                } else {
                    number = Buffer.Read (32, ctx);
                    number |= Buffer.Read (len_code - 32, ctx) << 32;
                }
                number = (1UL << len_code) | number;
                return (long)number;

            }
        }
Beispiel #10
0
 public int Decode(IBitStream Buffer, BitStreamCtx ctx)
 {
     int len_code = gammacoder.Decode (Buffer, ctx);
     len_code--;
     if (len_code == 0) {
         return 1;
     } else {
         int output = (int)Buffer.Read (len_code, ctx);
         // Console.WriteLine ("Decode> count: {0}, output: {1}", count, output);
         return (1 << len_code) + output;
     }
 }
Beispiel #11
0
 public int Decode(IBitStream stream, int N, BitStreamCtx ctx)
 {
     int min = 0;
     int max = N - 1;
     int mid;
     do {
         mid = (min >> 1) + (max >> 1);
         if (1 == (min & 1 & max)) {
             mid++;
         }
         if (!stream.Read (ctx)) {
             max = mid;
         } else {
             min = mid + 1;
         }
     } while (min < max);
     return min;
 }
Beispiel #12
0
 public int Decode(IBitStream stream, BitStreamCtx ctx)
 {
     HuffmanInner node = this.Huffman.Root;
     while (true) {
         bool b = stream.Read (ctx);
         HuffmanNode next;
         if (b) {
             next = node.Right;
         } else {
             next = node.Left;
         }
         var leaf = next as HuffmanLeaf;
         if (leaf != null) {
             return leaf.Symbol;
         }
         node = next as HuffmanInner;
     }
 }
Beispiel #13
0
 public long Decode(IBitStream stream, BitStreamCtx ctx)
 {
     long min = 0;
     long check;
     int galloping = 1;
     while (true) {
         check = (1L << galloping) - 1L;
         if (stream.Read (ctx)) {
             min = check + 1L;
             ++galloping;
         } else {
             if (min == 0L) {
                 return this.SecondCoding.Decode (stream, 2, ctx);
             } else {
                 return min + this.SecondCoding.Decode (stream, min, ctx);
             }
         }
     }
 }
Beispiel #14
0
 public int Decode(IBitStream Buffer, BitStreamCtx ctx)
 {
     // int numbits = unary.Decode (Buffer, ctx);
     // the idea is to replace unary coder by explicit inline code such that (hopefully)
     // both "code" and "numbits" are stored into registers
     var M = (int)Math.Min (32, Buffer.CountBits - ctx.Offset);
     var code = (uint)Buffer.Read (M, ctx);
     if ((code & 0x1) == 1) {
         ctx.Offset -= M - 1;
         return 1;
     }
     if (code == 0) {
         throw new ArgumentException ("Integers larger than 31 bits are not supported by EliasGamma32");
     }
     int numbits = 0;
     // Console.WriteLine ("xxxxxxxxxxxxxxxxxxxxxxxxxxxxx ");
     // Console.WriteLine ("xxxxx start-read> offset: {0},\t numbits: {1},\t code: {2}", ctx.Offset, numbits, BitAccess.ToAsciiString (code));
     while ((code & 0xFF) == 0) {
         numbits += 8;
         code >>= 8;
     }
     if ((code & 0xF) == 0) {
         numbits += 4;
         code >>= 4;
     }
     while ((code & 0x1) == 0) {
         numbits += 1;
         code >>= 1;
     }
     code >>= 1;
     // Console.WriteLine ("xxxxx unary-read> offset: {0},\t numbits: {1},\t code: {2}", ctx.Offset, numbits, BitAccess.ToAsciiString (code));
     if (numbits >= 16) {
         int in_cache = M - 1 - numbits;
         code |= ((uint)Buffer.Read (numbits - in_cache, ctx)) << in_cache;
     } else {
         ctx.Offset -= M - ((numbits << 1) + 1);
         code &= (1u << numbits) - 1;
     }
     // Console.WriteLine ("xxxxx final-read0> offset: {0},\t numbits: {1},\t code: {3},\t number: {2}", ctx.Offset, numbits, code, BitAccess.ToAsciiString (code));
     code |= (1u << numbits);
     // Console.WriteLine ("xxxxx final-read1> offset: {0},\t numbits: {1},\t code: {3},\t number: {2}", ctx.Offset, numbits, code, BitAccess.ToAsciiString (code));
     return (int)code;
 }
Beispiel #15
0
 public void Build(IBitStream B, short blockSize)
 {
     this.N = (int)B.CountBits;
     this.BlockSize = (short)blockSize;
     this.InitClasses();
     this.Offsets = new BitStream32 ();
     IList<int> _L = new ListIFS (15, B);
     IList<int> L;
     if ((B.CountBits % 15) == 0) {
         L = _L;
     } else {
         int D = _L.Count;
         int C = 15 * D;
         var ctx = new BitStreamCtx(0);
         ctx.Seek(C);
         int last_block = (int)B.Read(((int)B.CountBits) - C, ctx);
         L = new ListGen<int>(delegate(int a) {
             if (a == D) {
                 return last_block;
             } else {
                 return _L[a];
             }
         }, D+1);
     }
     this.AbsRank = new int[(int)Math.Ceiling(((float)L.Count) / this.BlockSize)];
     this.AbsOffset = new int[ this.AbsRank.Count ];
     int I = 0;
     int acc = 0;
     for (int i = 0; i < L.Count; i++) {
         var u = (short)L[i];
         var klass = GetClass(u);
         this.EncodeClass(klass);
         if (i % this.BlockSize == 0) {
             this.AbsRank[I] = acc;
             this.AbsOffset[I] = (int)this.Offsets.CountBits;
             I++;
         }
         var numbits = NumBits[klass];
         if (numbits > 0) {
             int offset = this.GetOffset (u, klass);
             this.Offsets.Write (offset, numbits);
         }
         acc += klass;
     }
 }
Beispiel #16
0
 public int Decode(IBitStream Buffer, BitStreamCtx ctx)
 {
     int skip = this.SkipCoder.Decode (Buffer, ctx);
     int output = (int)Buffer.Read (this.Power, ctx);
     return (skip << this.Power) | output;
 }
Beispiel #17
0
 public int ArrayGet(IBitStream Buffer, int pos)
 {
     var ctx = new BitStreamCtx ((uint)(pos * this.NumBits));
     int number = (int)Buffer.Read (this.NumBits, ctx);
     return number;
 }
Beispiel #18
0
 public int Decode(IBitStream Buffer, BitStreamCtx ctx)
 {
     int number = (int)Buffer.Read (this.NumBits, ctx);
     return number;
 }