/// <summary>
        /// Reads the next symbol from input.  The symbol is encoded using the
        /// huffman tree.
        /// </summary>
        /// <param name="input">
        /// input the input source.
        /// </param>
        /// <returns>
        /// the next symbol, or -1 if not enough input is available.
        /// </returns>
        public int GetSymbol(StreamManipulator input)
        {
            int lookahead, symbol;

            if ((lookahead = input.PeekBits(9)) >= 0)
            {
                if ((symbol = tree[lookahead]) >= 0)
                {
                    input.DropBits(symbol & 15);
                    return(symbol >> 4);
                }
                int subtree = -(symbol >> 4);
                int bitlen  = symbol & 15;
                if ((lookahead = input.PeekBits(bitlen)) >= 0)
                {
                    symbol = tree[subtree | (lookahead >> 9)];
                    input.DropBits(symbol & 15);
                    return(symbol >> 4);
                }
                else
                {
                    int bits = input.GetAvailableBits();
                    lookahead = input.PeekBits(bits);
                    symbol    = tree[subtree | (lookahead >> 9)];
                    if ((symbol & 15) <= bits)
                    {
                        input.DropBits(symbol & 15);
                        return(symbol >> 4);
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }
            else
            {
                int bits = input.GetAvailableBits();
                lookahead = input.PeekBits(bits);
                symbol    = tree[lookahead];
                if (symbol >= 0 && (symbol & 15) <= bits)
                {
                    input.DropBits(symbol & 15);
                    return(symbol >> 4);
                }
                else
                {
                    return(-1);
                }
            }
        }