コード例 #1
0
ファイル: Decoder.cs プロジェクト: radiomonter/Tanki_X
        public void Code(Stream inStream, Stream outStream, long inSize, long outSize, ICodeProgress progress)
        {
            if (this.m_OutWindow == null)
            {
                this.CreateDictionary();
            }
            this.m_OutWindow.Init(outStream);
            if (outSize > 0L)
            {
                this.m_OutWindow.SetLimit(outSize);
            }
            else
            {
                this.m_OutWindow.SetLimit(0x7fffffffffffffffL - this.m_OutWindow.Total);
            }
            Decoder rangeDecoder = new Decoder();

            rangeDecoder.Init(inStream);
            this.Code(this.m_DictionarySize, this.m_OutWindow, rangeDecoder);
            this.m_OutWindow.ReleaseStream();
            rangeDecoder.ReleaseStream();
            if (!rangeDecoder.IsFinished || ((inSize > 0L) && (rangeDecoder.Total != inSize)))
            {
                throw new DataErrorException();
            }
            if (this.m_OutWindow.HasPending)
            {
                throw new DataErrorException();
            }
            this.m_OutWindow = null;
        }
コード例 #2
0
ファイル: LzmaDecoder.cs プロジェクト: zhouzu/sharpcompress
        public void Code(Stream inStream, Stream outStream,
                         Int64 inSize, Int64 outSize, ICodeProgress progress)
        {
            if (_outWindow is null)
            {
                CreateDictionary();
            }
            _outWindow.Init(outStream);
            if (outSize > 0)
            {
                _outWindow.SetLimit(outSize);
            }
            else
            {
                _outWindow.SetLimit(Int64.MaxValue - _outWindow._total);
            }

            RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder();
            rangeDecoder.Init(inStream);

            Code(_dictionarySize, _outWindow, rangeDecoder);

            _outWindow.ReleaseStream();
            rangeDecoder.ReleaseStream();

            if (!rangeDecoder.IsFinished || (inSize > 0 && rangeDecoder._total != inSize))
            {
                throw new DataErrorException();
            }
            if (_outWindow.HasPending)
            {
                throw new DataErrorException();
            }
            _outWindow = null;
        }
コード例 #3
0
ファイル: LzmaStream.cs プロジェクト: RainsSoft/sharpcompress
        public LzmaStream(LzmaEncoderProperties properties, bool isLZMA2, Stream presetDictionary, Stream outputStream)
        {
            this.outWindow         = new OutWindow();
            this.rangeDecoder      = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder();
            this.position          = 0L;
            this.endReached        = false;
            this.inputPosition     = 0L;
            this.uncompressedChunk = false;
            this.needDictReset     = true;
            this.needProps         = true;
            this.props             = new byte[5];
            this.isLZMA2           = isLZMA2;
            this.availableBytes    = 0L;
            this.endReached        = true;
            if (isLZMA2)
            {
                throw new NotImplementedException();
            }
            this.encoder = new SharpCompress.Compressor.LZMA.Encoder();
            this.encoder.SetCoderProperties(properties.propIDs, properties.properties);
            MemoryStream outStream = new MemoryStream(5);

            this.encoder.WriteCoderProperties(outStream);
            this.props = outStream.ToArray();
            this.encoder.SetStreams(null, outputStream, -1L, -1L);
            if (presetDictionary != null)
            {
                this.encoder.Train(presetDictionary);
            }
        }
コード例 #4
0
        public void Code(Stream inStream, Stream outStream,
                         Int64 inSize, Int64 outSize, ICodeProgress progress)
        {
            if (_outWindow is null)
            {
                CreateDictionary();
            }
            _outWindow.Init(outStream);
            if (outSize > 0)
            {
                _outWindow.SetLimit(outSize);
            }
            else
            {
                _outWindow.SetLimit(Int64.MaxValue - _outWindow._total);
            }

            RangeCoder.Decoder rangeDecoder = new RangeCoder.Decoder();
            rangeDecoder.Init(inStream);

            Code(_dictionarySize, _outWindow, rangeDecoder);

            _outWindow.ReleaseStream();
            rangeDecoder.ReleaseStream();

            _outWindow = null;
        }
コード例 #5
0
ファイル: LzmaDecoder.cs プロジェクト: zhouzu/sharpcompress
        private void CreateDictionary()
        {
            if (_dictionarySize < 0)
            {
                throw new InvalidParamException();
            }
            _outWindow = new OutWindow();
            int blockSize = Math.Max(_dictionarySize, (1 << 12));

            _outWindow.Create(blockSize);
        }
コード例 #6
0
ファイル: Decoder.cs プロジェクト: radiomonter/Tanki_X
        private void CreateDictionary()
        {
            if (this.m_DictionarySize < 0)
            {
                throw new InvalidParamException();
            }
            this.m_OutWindow = new OutWindow();
            int windowSize = Math.Max(this.m_DictionarySize, 0x1000);

            this.m_OutWindow.Create(windowSize);
        }
コード例 #7
0
 void SetDictionarySize(uint dictionarySize)
 {
     if (m_DictionarySize != dictionarySize)
     {
         m_DictionarySize      = dictionarySize;
         m_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);
         uint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));
         //m_OutWindow.Create(blockSize);
         OutWindow.GetInstance().Create(blockSize);
     }
 }
コード例 #8
0
ファイル: LzmaStream.cs プロジェクト: RainsSoft/sharpcompress
 public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize, Stream presetDictionary, bool isLZMA2)
 {
     this.outWindow         = new OutWindow();
     this.rangeDecoder      = new SharpCompress.Compressor.LZMA.RangeCoder.Decoder();
     this.position          = 0L;
     this.endReached        = false;
     this.inputPosition     = 0L;
     this.uncompressedChunk = false;
     this.needDictReset     = true;
     this.needProps         = true;
     this.props             = new byte[5];
     this.inputStream       = inputStream;
     this.inputSize         = inputSize;
     this.outputSize        = outputSize;
     this.isLZMA2           = isLZMA2;
     if (!isLZMA2)
     {
         this.dictionarySize = BitConverter.ToInt32(properties, 1);
         this.outWindow.Create(this.dictionarySize);
         if (presetDictionary != null)
         {
             this.outWindow.Train(presetDictionary);
         }
         this.rangeDecoder.Init(inputStream);
         this.decoder = new SharpCompress.Compressor.LZMA.Decoder();
         this.decoder.SetDecoderProperties(properties);
         this.props             = properties;
         this.availableBytes    = (outputSize < 0L) ? 0x7fffffffffffffffL : outputSize;
         this.rangeDecoderLimit = inputSize;
     }
     else
     {
         this.dictionarySize = 2 | (properties[0] & 1);
         this.dictionarySize = this.dictionarySize << ((properties[0] >> 1) + 11);
         this.outWindow.Create(this.dictionarySize);
         if (presetDictionary != null)
         {
             this.outWindow.Train(presetDictionary);
             this.needDictReset = false;
         }
         this.props          = new byte[1];
         this.availableBytes = 0L;
     }
 }
コード例 #9
0
 public LzmaStream(byte[] properties, Stream inputStream, long inputSize, long outputSize, Stream presetDictionary, bool isLZMA2)
 {
     this.outWindow     = new OutWindow();
     this.rangeDecoder  = new Decoder();
     this.needDictReset = true;
     this.needProps     = true;
     this.props         = new byte[5];
     this.inputStream   = inputStream;
     this.inputSize     = inputSize;
     this.outputSize    = outputSize;
     this.isLZMA2       = isLZMA2;
     if (isLZMA2)
     {
         this.dictionarySize = 2 | (properties[0] & 1);
         this.dictionarySize = this.dictionarySize << (((properties[0] >> 1) + 11) & 0x1f);
         this.outWindow.Create(this.dictionarySize);
         if (presetDictionary != null)
         {
             this.outWindow.Train(presetDictionary);
             this.needDictReset = false;
         }
         this.props          = new byte[1];
         this.availableBytes = 0L;
     }
     else
     {
         this.dictionarySize = BitConverter.ToInt32(properties, 1);
         this.outWindow.Create(this.dictionarySize);
         if (presetDictionary != null)
         {
             this.outWindow.Train(presetDictionary);
         }
         this.rangeDecoder.Init(inputStream);
         this.decoder = new Decoder();
         this.decoder.SetDecoderProperties(properties);
         this.props             = properties;
         this.availableBytes    = (outputSize >= 0L) ? outputSize : 0x7fffffffffffffffL;
         this.rangeDecoderLimit = inputSize;
     }
 }
コード例 #10
0
        void Init(System.IO.Stream inStream, System.IO.Stream outStream)
        {
            m_RangeDecoder.Init(inStream);
            //m_OutWindow.Init(outStream);
            OutWindow.GetInstance().Init(outStream);

            uint i;

            for (i = 0; i < Base.kNumStates; i++)
            {
                for (uint j = 0; j <= m_PosStateMask; j++)
                {
                    uint index = (i << Base.kNumPosStatesBitsMax) + j;
                    m_IsMatchDecoders[index].Init();
                    m_IsRep0LongDecoders[index].Init();
                }
                m_IsRepDecoders[i].Init();
                m_IsRepG0Decoders[i].Init();
                m_IsRepG1Decoders[i].Init();
                m_IsRepG2Decoders[i].Init();
            }

            m_LiteralDecoder.Init();
            //LiteralDecoder.GetInstance().Init();
            for (i = 0; i < Base.kNumLenToPosStates; i++)
            {
                m_PosSlotDecoder[i].Init();
            }
            // m_PosSpecDecoder.Init();
            for (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)
            {
                m_PosDecoders[i].Init();
            }

            m_LenDecoder.Init();
            m_RepLenDecoder.Init();
            m_PosAlignDecoder.Init();
        }
コード例 #11
0
ファイル: LzmaDecoder.cs プロジェクト: zhouzu/sharpcompress
        internal bool Code(int dictionarySize, OutWindow outWindow, RangeCoder.Decoder rangeDecoder)
        {
            int dictionarySizeCheck = Math.Max(dictionarySize, 1);

            outWindow.CopyPending();

            while (outWindow.HasSpace)
            {
                uint posState = (uint)outWindow._total & _posStateMask;
                if (_isMatchDecoders[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].Decode(rangeDecoder) == 0)
                {
                    byte b;
                    byte prevByte = outWindow.GetByte(0);
                    if (!_state.IsCharState())
                    {
                        b = _literalDecoder.DecodeWithMatchByte(rangeDecoder,
                                                                (uint)outWindow._total, prevByte,
                                                                outWindow.GetByte((int)_rep0));
                    }
                    else
                    {
                        b = _literalDecoder.DecodeNormal(rangeDecoder, (uint)outWindow._total, prevByte);
                    }
                    outWindow.PutByte(b);
                    _state.UpdateChar();
                }
                else
                {
                    uint len;
                    if (_isRepDecoders[_state._index].Decode(rangeDecoder) == 1)
                    {
                        if (_isRepG0Decoders[_state._index].Decode(rangeDecoder) == 0)
                        {
                            if (
                                _isRep0LongDecoders[(_state._index << Base.K_NUM_POS_STATES_BITS_MAX) + posState].Decode(
                                    rangeDecoder) == 0)
                            {
                                _state.UpdateShortRep();
                                outWindow.PutByte(outWindow.GetByte((int)_rep0));
                                continue;
                            }
                        }
                        else
                        {
                            UInt32 distance;
                            if (_isRepG1Decoders[_state._index].Decode(rangeDecoder) == 0)
                            {
                                distance = _rep1;
                            }
                            else
                            {
                                if (_isRepG2Decoders[_state._index].Decode(rangeDecoder) == 0)
                                {
                                    distance = _rep2;
                                }
                                else
                                {
                                    distance = _rep3;
                                    _rep3    = _rep2;
                                }
                                _rep2 = _rep1;
                            }
                            _rep1 = _rep0;
                            _rep0 = distance;
                        }
                        len = _repLenDecoder.Decode(rangeDecoder, posState) + Base.K_MATCH_MIN_LEN;
                        _state.UpdateRep();
                    }
                    else
                    {
                        _rep3 = _rep2;
                        _rep2 = _rep1;
                        _rep1 = _rep0;
                        len   = Base.K_MATCH_MIN_LEN + _lenDecoder.Decode(rangeDecoder, posState);
                        _state.UpdateMatch();
                        uint posSlot = _posSlotDecoder[Base.GetLenToPosState(len)].Decode(rangeDecoder);
                        if (posSlot >= Base.K_START_POS_MODEL_INDEX)
                        {
                            int numDirectBits = (int)((posSlot >> 1) - 1);
                            _rep0 = ((2 | (posSlot & 1)) << numDirectBits);
                            if (posSlot < Base.K_END_POS_MODEL_INDEX)
                            {
                                _rep0 += BitTreeDecoder.ReverseDecode(_posDecoders,
                                                                      _rep0 - posSlot - 1, rangeDecoder, numDirectBits);
                            }
                            else
                            {
                                _rep0 += (rangeDecoder.DecodeDirectBits(
                                              numDirectBits - Base.K_NUM_ALIGN_BITS) << Base.K_NUM_ALIGN_BITS);
                                _rep0 += _posAlignDecoder.ReverseDecode(rangeDecoder);
                            }
                        }
                        else
                        {
                            _rep0 = posSlot;
                        }
                    }
                    if (_rep0 >= outWindow._total || _rep0 >= dictionarySizeCheck)
                    {
                        if (_rep0 == 0xFFFFFFFF)
                        {
                            return(true);
                        }
                        throw new DataErrorException();
                    }
                    outWindow.CopyBlock((int)_rep0, (int)len);
                }
            }
            return(false);
        }
コード例 #12
0
        internal bool Code(int dictionarySize, OutWindow outWindow, RangeCoder.Decoder rangeDecoder)
        {
            int dictionarySizeCheck = Math.Max(dictionarySize, 1);

            outWindow.CopyPending();

            while (outWindow.HasSpace)
            {
                uint posState = (uint)outWindow.Total & m_PosStateMask;
                if (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(rangeDecoder) == 0)
                {
                    byte b;
                    byte prevByte = outWindow.GetByte(0);
                    if (!state.IsCharState())
                    {
                        b = m_LiteralDecoder.DecodeWithMatchByte(rangeDecoder,
                                                                 (uint)outWindow.Total, prevByte,
                                                                 outWindow.GetByte((int)rep0));
                    }
                    else
                    {
                        b = m_LiteralDecoder.DecodeNormal(rangeDecoder, (uint)outWindow.Total, prevByte);
                    }
                    outWindow.PutByte(b);
                    state.UpdateChar();
                }
                else
                {
                    uint len;
                    if (m_IsRepDecoders[state.Index].Decode(rangeDecoder) == 1)
                    {
                        if (m_IsRepG0Decoders[state.Index].Decode(rangeDecoder) == 0)
                        {
                            if (
                                m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(
                                    rangeDecoder) == 0)
                            {
                                state.UpdateShortRep();
                                outWindow.PutByte(outWindow.GetByte((int)rep0));
                                continue;
                            }
                        }
                        else
                        {
                            UInt32 distance;
                            if (m_IsRepG1Decoders[state.Index].Decode(rangeDecoder) == 0)
                            {
                                distance = rep1;
                            }
                            else
                            {
                                if (m_IsRepG2Decoders[state.Index].Decode(rangeDecoder) == 0)
                                {
                                    distance = rep2;
                                }
                                else
                                {
                                    distance = rep3;
                                    rep3     = rep2;
                                }
                                rep2 = rep1;
                            }
                            rep1 = rep0;
                            rep0 = distance;
                        }
                        len = m_RepLenDecoder.Decode(rangeDecoder, posState) + Base.kMatchMinLen;
                        state.UpdateRep();
                    }
                    else
                    {
                        rep3 = rep2;
                        rep2 = rep1;
                        rep1 = rep0;
                        len  = Base.kMatchMinLen + m_LenDecoder.Decode(rangeDecoder, posState);
                        state.UpdateMatch();
                        uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(rangeDecoder);
                        if (posSlot >= Base.kStartPosModelIndex)
                        {
                            int numDirectBits = (int)((posSlot >> 1) - 1);
                            rep0 = ((2 | (posSlot & 1)) << numDirectBits);
                            if (posSlot < Base.kEndPosModelIndex)
                            {
                                rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,
                                                                     rep0 - posSlot - 1, rangeDecoder, numDirectBits);
                            }
                            else
                            {
                                rep0 += (rangeDecoder.DecodeDirectBits(
                                             numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);
                                rep0 += m_PosAlignDecoder.ReverseDecode(rangeDecoder);
                            }
                        }
                        else
                        {
                            rep0 = posSlot;
                        }
                    }
                    if (rep0 >= outWindow.Total || rep0 >= dictionarySizeCheck)
                    {
                        if (rep0 == 0xFFFFFFFF)
                        {
                            return(true);
                        }
                        throw new DataErrorException();
                    }
                    outWindow.CopyBlock((int)rep0, (int)len);
                }
            }
            return(false);
        }
コード例 #13
0
ファイル: Decoder.cs プロジェクト: radiomonter/Tanki_X
        internal bool Code(int dictionarySize, OutWindow outWindow, Decoder rangeDecoder)
        {
            int num = Math.Max(dictionarySize, 1);

            outWindow.CopyPending();
            while (outWindow.HasSpace)
            {
                uint num5;
                uint posState = ((uint)outWindow.Total) & this.m_PosStateMask;
                if (this.m_IsMatchDecoders[(this.state.Index << 4) + posState].Decode(rangeDecoder) == 0)
                {
                    byte @byte = outWindow.GetByte(0);
                    byte b     = this.state.IsCharState() ? this.m_LiteralDecoder.DecodeNormal(rangeDecoder, (uint)outWindow.Total, @byte) : this.m_LiteralDecoder.DecodeWithMatchByte(rangeDecoder, (uint)outWindow.Total, @byte, outWindow.GetByte((int)this.rep0));
                    outWindow.PutByte(b);
                    this.state.UpdateChar();
                    continue;
                }
                if (this.m_IsRepDecoders[this.state.Index].Decode(rangeDecoder) != 1)
                {
                    this.rep3 = this.rep2;
                    this.rep2 = this.rep1;
                    this.rep1 = this.rep0;
                    num5      = 2 + this.m_LenDecoder.Decode(rangeDecoder, posState);
                    this.state.UpdateMatch();
                    uint num7 = this.m_PosSlotDecoder[Base.GetLenToPosState(num5)].Decode(rangeDecoder);
                    if (num7 < 4)
                    {
                        this.rep0 = num7;
                    }
                    else
                    {
                        int numBitLevels = ((int)(num7 >> 1)) - 1;
                        this.rep0 = (uint)((2 | (num7 & 1)) << (numBitLevels & 0x1f));
                        if (num7 < 14)
                        {
                            this.rep0 += BitTreeDecoder.ReverseDecode(this.m_PosDecoders, (this.rep0 - num7) - 1, rangeDecoder, numBitLevels);
                        }
                        else
                        {
                            this.rep0 += rangeDecoder.DecodeDirectBits(numBitLevels - 4) << 4;
                            this.rep0 += this.m_PosAlignDecoder.ReverseDecode(rangeDecoder);
                        }
                    }
                }
                else
                {
                    if (this.m_IsRepG0Decoders[this.state.Index].Decode(rangeDecoder) == 0)
                    {
                        if (this.m_IsRep0LongDecoders[(this.state.Index << 4) + posState].Decode(rangeDecoder) == 0)
                        {
                            this.state.UpdateShortRep();
                            outWindow.PutByte(outWindow.GetByte((int)this.rep0));
                            continue;
                        }
                    }
                    else
                    {
                        uint num6;
                        if (this.m_IsRepG1Decoders[this.state.Index].Decode(rangeDecoder) == 0)
                        {
                            num6 = this.rep1;
                        }
                        else
                        {
                            if (this.m_IsRepG2Decoders[this.state.Index].Decode(rangeDecoder) == 0)
                            {
                                num6 = this.rep2;
                            }
                            else
                            {
                                num6      = this.rep3;
                                this.rep3 = this.rep2;
                            }
                            this.rep2 = this.rep1;
                        }
                        this.rep1 = this.rep0;
                        this.rep0 = num6;
                    }
                    num5 = this.m_RepLenDecoder.Decode(rangeDecoder, posState) + 2;
                    this.state.UpdateRep();
                }
                if ((this.rep0 >= outWindow.Total) || (this.rep0 >= num))
                {
                    if (this.rep0 != uint.MaxValue)
                    {
                        throw new DataErrorException();
                    }
                    return(true);
                }
                outWindow.CopyBlock((int)this.rep0, (int)num5);
            }
            return(false);
        }
コード例 #14
0
        public void Code(System.IO.Stream inStream, System.IO.Stream outStream,
                         Int64 inSize, Int64 outSize, ICodeProgress progress)
        {
            Init(inStream, outStream);

            Base.State state = new Base.State();
            state.Init();
            uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;

            UInt64 nowPos64  = 0;
            UInt64 outSize64 = (UInt64)outSize;

            if (nowPos64 < outSize64)
            {
                if (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)
                {
                    throw new DataErrorException();
                }
                state.UpdateChar();
                byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);
                //byte b = LiteralDecoder.GetInstance().DecodeNormal(m_RangeDecoder,0,0);
                //m_OutWindow.PutByte(b);
                OutWindow.GetInstance().PutByte(b);
                nowPos64++;
            }
            while (nowPos64 < outSize64)
            {
                // UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);
                // while(nowPos64 < next)
                {
                    uint posState = (uint)nowPos64 & m_PosStateMask;
                    if (m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)
                    {
                        byte b;
                        //byte prevByte = m_OutWindow.GetByte(0);
                        byte prevByte = OutWindow.GetInstance().GetByte(0);
                        if (!state.IsCharState())
                        {
                            b = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,
                                                                     (uint)nowPos64, prevByte, OutWindow.GetInstance().GetByte(rep0));
                            //b = LiteralDecoder.GetInstance().DecodeWithMatchByte(m_RangeDecoder,
                            //   (uint)nowPos64, prevByte, OutWindow.GetInstance().GetByte(rep0));
                        }
                        //(uint)nowPos64, prevByte, m_OutWindow.GetByte(rep0));
                        else
                        {
                            b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);
                            //b = LiteralDecoder.GetInstance().DecodeNormal(m_RangeDecoder, (uint)nowPos64, prevByte);
                        }

                        //m_OutWindow.PutByte(b);
                        OutWindow.GetInstance().PutByte(b);
                        state.UpdateChar();
                        nowPos64++;
                    }
                    else
                    {
                        uint len;
                        if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)
                        {
                            if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)
                            {
                                if (m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) == 0)
                                {
                                    state.UpdateShortRep();
                                    //m_OutWindow.PutByte(m_OutWindow.GetByte(rep0));
                                    OutWindow.GetInstance().PutByte(OutWindow.GetInstance().GetByte(rep0));
                                    nowPos64++;
                                    continue;
                                }
                            }
                            else
                            {
                                UInt32 distance;
                                if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)
                                {
                                    distance = rep1;
                                }
                                else
                                {
                                    if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)
                                    {
                                        distance = rep2;
                                    }
                                    else
                                    {
                                        distance = rep3;
                                        rep3     = rep2;
                                    }
                                    rep2 = rep1;
                                }
                                rep1 = rep0;
                                rep0 = distance;
                            }
                            len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;
                            state.UpdateRep();
                        }
                        else
                        {
                            rep3 = rep2;
                            rep2 = rep1;
                            rep1 = rep0;
                            len  = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);
                            state.UpdateMatch();
                            uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);
                            if (posSlot >= Base.kStartPosModelIndex)
                            {
                                int numDirectBits = (int)((posSlot >> 1) - 1);
                                rep0 = ((2 | (posSlot & 1)) << numDirectBits);
                                if (posSlot < Base.kEndPosModelIndex)
                                {
                                    rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,
                                                                         rep0 - posSlot - 1, m_RangeDecoder, numDirectBits);
                                }
                                else
                                {
                                    rep0 += (m_RangeDecoder.DecodeDirectBits(
                                                 numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);
                                    rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);
                                }
                            }
                            else
                            {
                                rep0 = posSlot;
                            }
                        }
                        if (rep0 >= nowPos64 || rep0 >= m_DictionarySizeCheck)
                        {
                            if (rep0 == 0xFFFFFFFF)
                            {
                                break;
                            }
                            throw new DataErrorException();
                        }
                        //m_OutWindow.CopyBlock(rep0, len);
                        OutWindow.GetInstance().CopyBlock(rep0, len);
                        nowPos64 += len;
                    }
                }
            }
            //m_OutWindow.Flush();
            //m_OutWindow.ReleaseStream();
            OutWindow.GetInstance().Flush();
            OutWindow.GetInstance().ReleaseStream();
            m_RangeDecoder.ReleaseStream();
        }