Ejemplo n.º 1
0
        internal static void Decode(BitReservoir br, int table, out float x, out float y, out float v, out float w)
        {
            var val = DecodeSymbol(br, table);

            v = w = x = y = 0;

            if ((val & 0x8) != 0)
            {
                if (br.Get1Bit() == 1)
                {
                    v = -_floatLookup[1];
                }
                else
                {
                    v = _floatLookup[1];
                }
            }

            if ((val & 0x4) != 0)
            {
                if (br.Get1Bit() == 1)
                {
                    w = -_floatLookup[1];
                }
                else
                {
                    w = _floatLookup[1];
                }
            }

            if ((val & 0x2) != 0)
            {
                if (br.Get1Bit() == 1)
                {
                    x = -_floatLookup[1];
                }
                else
                {
                    x = _floatLookup[1];
                }
            }

            if ((val & 0x1) != 0)
            {
                if (br.Get1Bit() == 1)
                {
                    y = -_floatLookup[1];
                }
                else
                {
                    y = _floatLookup[1];
                }
            }
        }
Ejemplo n.º 2
0
        // In C#, bit operations are faster than the tree traversal the spec is written for.
        static byte DecodeSymbol(BitReservoir br, int table)
        {
            // get the huffman node for decoding
            int maxBits;
            var node = GetNode(table, out maxBits);

            // get some bits to work with
            int readBits;
            int bits = br.TryPeekBits(maxBits, out readBits);
            if (readBits < maxBits)
            {
                bits <<= maxBits - readBits;
            }

            // try to find the correct node
            while (node != null && node.Length <= readBits)
            {
                if ((bits & node.Mask) == node.Bits)
                {
                    // found it!  Advance the read counter
                    br.SkipBits(node.Length);
                    break;
                }
                node = node.Next;
            }

            // apply the value
            if (node != null && node.Length <= readBits)
            {
                return node.Value;
            }
            else
            {
                // should we advance the reader????  need to check the spec
                return 0;
            }
        }
Ejemplo n.º 3
0
        internal static void Decode(BitReservoir br, int table, out float x, out float y)
        {
            if (table == 0 || table == 4 || table == 14)
            {
                x = y = 0;
            }
            else
            {
                var val = DecodeSymbol(br, table);

                var ix = val >> 4;
                var iy = val & 15;

                int linBits = LIN_BITS[table];
                if (linBits > 0 && ix == 15) ix += br.GetBits(linBits);
                if (ix != 0 && br.Get1Bit() != 0)
                {
                    x = -_floatLookup[ix];
                }
                else
                {
                    x = _floatLookup[ix];
                }

                if (linBits > 0 && iy == 15) iy += br.GetBits(linBits);
                if (iy != 0 && br.Get1Bit() != 0)
                {
                    y = -_floatLookup[iy];
                }
                else
                {
                    y = _floatLookup[iy];
                }
            }
        }