コード例 #1
0
        /////////////////////////////////////////////////////////////////////
        // Reads the next symbol from input.  The symbol is encoded using the huffman tree.
        /////////////////////////////////////////////////////////////////////

        private Int32 ReadSymbol
        (
            InflateTree Tree
        )
        {
            // fill the buffer to a maximum of 32 bits
            for (; BitCount <= 24; BitCount += 8)
            {
                // read next byte from read buffer
                Int32 OneByte = ReadByte();

                // end of file
                if (OneByte < 0)
                {
                    break;
                }

                // append to the bit buffer
                BitBuffer |= (UInt32)(OneByte << BitCount);
            }

            // loop through the decode tree
            Int32 Next, Mask;

            for (Mask = Tree.ActiveBitMask, Next = Tree.ActiveTree[(Int32)BitBuffer & (Mask - 1)];
                 Next > 0 && Mask < 0x10000; Next = (BitBuffer & Mask) == 0 ? Tree.ActiveTree[Next] : Tree.ActiveTree[Next + 1], Mask <<= 1)
            {
                ;
            }

            // error
            if (Next >= 0)
            {
                throw new ApplicationException("Error decoding the compressed bit stream (decoding tree error)");
            }

            // invert the symbol plus bit count
            Next = ~Next;

            // extract the number of bits
            Int32 Bits = Next & 15;

            // remove the bits from the bit buffer
            BitBuffer >>= Bits;
            BitCount   -= Bits;

            // error
            if (BitCount < 0)
            {
                throw new ApplicationException("Error decoding the compressed bit stream (premature end of file)");
            }

            // exit with symbol
            return(Next >> 4);
        }
コード例 #2
0
ファイル: InflateMethod.cs プロジェクト: relaxar/UZipDotNet
 /// <summary>
 /// Initializes a new instance of the <see cref="InflateMethod"/> class.
 /// </summary>
 protected InflateMethod()
 {
     // allocate buffers
     _readBuffer           = new byte[ReadBufSize];
     _writeBuffer          = new byte[WriteBufSize];
     _bitLengthArray       = new byte[MaxBitLengthCodes];
     _literalDistanceArray = new byte[MaxLiteralCodes + MaxDistanceCodes];
     _bitLengthTree        = new InflateTree(TreeType.BitLen);
     _literalTree          = new InflateTree(TreeType.Literal);
     _distanceTree         = new InflateTree(TreeType.Distance);
 }
コード例 #3
0
        ////////////////////////////////////////////////////////////////////
        // Constructor
        ////////////////////////////////////////////////////////////////////

        public InflateMethod()
        {
            // allocate buffers
            ReadBuffer           = new Byte[ReadBufSize];
            WriteBuffer          = new Byte[WriteBufSize];
            BitLengthArray       = new Byte[MaxBitLengthCodes];
            LiteralDistanceArray = new Byte[MaxLiteralCodes + MaxDistanceCodes];
            BitLengthTree        = new InflateTree(TreeType.BitLen);
            LiteralTree          = new InflateTree(TreeType.Literal);
            DistanceTree         = new InflateTree(TreeType.Distance);
            return;
        }
コード例 #4
0
ファイル: InflateMethod.cs プロジェクト: relaxar/UZipDotNet
        /// <summary>
        /// Reads the next symbol from input.  The symbol is encoded using the huffman tree.
        /// </summary>
        /// <param name="tree">The tree.</param>
        /// <returns></returns>
        /// <exception cref="UZipDotNet.Exception">
        /// Error decoding the compressed bit stream (decoding tree error)
        /// or
        /// Error decoding the compressed bit stream (premature end of file)
        /// </exception>
        private int ReadSymbol(InflateTree tree)
        {
            // fill the buffer to a maximum of 32 bits
            for (; _bitCount <= 24; _bitCount += 8)
            {
                // read next byte from read buffer
                int oneByte = ReadByte();

                // end of file
                if (oneByte < 0)
                {
                    break;
                }

                // append to the bit buffer
                _bitBuffer |= (uint)(oneByte << _bitCount);
            }

            // loop through the decode tree
            int next, mask;

            for (mask = tree.ActiveBitMask, next = tree.ActiveTree[(int)_bitBuffer & (mask - 1)];
                 next > 0 && mask < 0x10000;
                 next = (_bitBuffer & mask) == 0 ? tree.ActiveTree[next] : tree.ActiveTree[next + 1], mask <<= 1)
            {
            }

            // error
            if (next >= 0)
            {
                throw new Exception("Error decoding the compressed bit stream (decoding tree error)");
            }

            // invert the symbol plus bit count
            next = ~next;

            // extract the number of bits
            int bits = next & 15;

            // remove the bits from the bit buffer
            _bitBuffer >>= bits;
            _bitCount   -= bits;

            // error
            if (_bitCount < 0)
            {
                throw new Exception("Error decoding the compressed bit stream (premature end of file)");
            }

            // exit with symbol
            return(next >> 4);
        }
コード例 #5
0
ファイル: InflateMethod.cs プロジェクト: Sacristan/UZipDotNet
        /// <summary>
        /// Reads the next symbol from input.  The symbol is encoded using the huffman tree.
        /// </summary>
        /// <param name="tree">The tree.</param>
        /// <returns></returns>
        /// <exception cref="UZipDotNet.Exception">
        /// Error decoding the compressed bit stream (decoding tree error)
        /// or
        /// Error decoding the compressed bit stream (premature end of file)
        /// </exception>
        private int ReadSymbol(InflateTree tree)
        {
            // fill the buffer to a maximum of 32 bits
            for (; _bitCount <= 24; _bitCount += 8)
            {
                // read next byte from read buffer
                int oneByte = ReadByte();

                // end of file
                if (oneByte < 0) break;

                // append to the bit buffer
                _bitBuffer |= (uint)(oneByte << _bitCount);
            }

            // loop through the decode tree
            int next, mask;
            for (mask = tree.ActiveBitMask, next = tree.ActiveTree[(int) _bitBuffer & (mask - 1)];
                next > 0 && mask < 0x10000;
                next = (_bitBuffer & mask) == 0 ? tree.ActiveTree[next] : tree.ActiveTree[next + 1], mask <<= 1)
            {
            }

            // error
            if (next >= 0) throw new Exception("Error decoding the compressed bit stream (decoding tree error)");

            // invert the symbol plus bit count
            next = ~next;

            // extract the number of bits
            int bits = next & 15;

            // remove the bits from the bit buffer
            _bitBuffer >>= bits;
            _bitCount -= bits;

            // error
            if (_bitCount < 0) throw new Exception("Error decoding the compressed bit stream (premature end of file)");

            // exit with symbol
            return (next >> 4);
        }
コード例 #6
0
ファイル: InflateMethod.cs プロジェクト: Sacristan/UZipDotNet
 /// <summary>
 /// Initializes a new instance of the <see cref="InflateMethod"/> class.
 /// </summary>
 protected InflateMethod()
 {
     // allocate buffers
     _readBuffer = new byte[ReadBufSize];
     _writeBuffer = new byte[WriteBufSize];
     _bitLengthArray = new byte[MaxBitLengthCodes];
     _literalDistanceArray = new byte[MaxLiteralCodes + MaxDistanceCodes];
     _bitLengthTree = new InflateTree(TreeType.BitLen);
     _literalTree = new InflateTree(TreeType.Literal);
     _distanceTree = new InflateTree(TreeType.Distance);
 }