Ejemplo n.º 1
0
        // Decode a code using huffman table h.
        static int Decode(Huffman h, BitReader br)
        {
            int   code  = 0;          // len bits being decoded
            int   first = 0;          // first code of length len
            int   index = 0;          // index of first code of length len in symbol table
            short next  = 1;

            while (true)
            {
                code |= br.ReadBits(1) ^ 1;                 // invert code
                int count = h.Count[next++];
                if (code < first + count)
                {
                    return(h.Symbol[index + (code - first)]);
                }

                index  += count;
                first  += count;
                first <<= 1;
                code  <<= 1;
            }
        }
Ejemplo n.º 2
0
		// Decode a code using huffman table h.
		static int Decode(Huffman h, BitReader br)
		{
			var code = 0; // len bits being decoded
			var first = 0; // first code of length len
			var index = 0; // index of first code of length len in symbol table
			short next = 1;
			while (true)
			{
				code |= br.ReadBits(1) ^ 1; // invert code
				int count = h.Count[next++];
				if (code < first + count)
					return h.Symbol[index + (code - first)];

				index += count;
				first += count;
				first <<= 1;
				code <<= 1;
			}
		}