Ejemplo n.º 1
0
        internal bool decodeSymbol2(ModelPPM model)
        {
            long        count;
            int         hiCnt, i = NumStats - model.NumMasked;
            SEE2Context psee2c = makeEscFreq2(model, i);
            RangeCoder  coder  = model.Coder;
            // STATE* ps[256], ** pps=ps, * p=U.Stats-1;
            State p    = tempState1.Initialize(model.Heap);
            State temp = tempState2.Initialize(model.Heap);

            p.Address = freqData.GetStats() - State.Size;
            int pps = 0;

            hiCnt = 0;

            do
            {
                do
                {
                    p.IncrementAddress(); // p++;
                } while (model.CharMask[p.Symbol] == model.EscCount);
                hiCnt    += p.Freq;
                ps[pps++] = p.Address;
            } while (--i != 0);
            coder.SubRange.incScale(hiCnt);
            count = coder.CurrentCount;
            if (count >= coder.SubRange.Scale)
            {
                return(false);
            }
            pps       = 0;
            p.Address = ps[pps];
            if (count < hiCnt)
            {
                hiCnt = 0;
                while ((hiCnt += p.Freq) <= count)
                {
                    p.Address = ps[++pps]; // p=*++pps;
                }
                coder.SubRange.HighCount = hiCnt;
                coder.SubRange.LowCount  = hiCnt - p.Freq;
                psee2c.update();
                update2(model, p.Address);
            }
            else
            {
                coder.SubRange.LowCount  = hiCnt;
                coder.SubRange.HighCount = coder.SubRange.Scale;
                i = NumStats - model.NumMasked; // ->NumMasked;
                pps--;
                do
                {
                    temp.Address = ps[++pps]; // (*++pps)
                    model.CharMask[temp.Symbol] = model.EscCount;
                } while (--i != 0);
                psee2c.incSumm((int)coder.SubRange.Scale);
                model.NumMasked = NumStats;
            }
            return(true);
        }
Ejemplo n.º 2
0
        internal bool decodeSymbol2(ModelPPM model)
        {
            int         diff    = this.NumStats - model.NumMasked;
            SEE2Context context = this.makeEscFreq2(model, diff);
            RangeCoder  coder   = model.Coder;

            SharpCompress.Compressor.PPMd.H.State state  = this.tempState1.Initialize(model.Heap);
            SharpCompress.Compressor.PPMd.H.State state2 = this.tempState2.Initialize(model.Heap);
            state.Address = this.freqData.GetStats() - 6;
            int index  = 0;
            int dScale = 0;

            do
            {
                do
                {
                    state.IncrementAddress();
                }while (model.CharMask[state.Symbol] == model.EscCount);
                dScale          += state.Freq;
                this.ps[index++] = state.Address;
            }while (--diff != 0);
            coder.SubRange.incScale(dScale);
            long currentCount = coder.CurrentCount;

            if (currentCount >= coder.SubRange.Scale)
            {
                return(false);
            }
            index         = 0;
            state.Address = this.ps[index];
            if (currentCount < dScale)
            {
                dScale = 0;
                while ((dScale += state.Freq) <= currentCount)
                {
                    state.Address = this.ps[++index];
                }
                coder.SubRange.HighCount = dScale;
                coder.SubRange.LowCount  = dScale - state.Freq;
                context.update();
                this.update2(model, state.Address);
            }
            else
            {
                coder.SubRange.LowCount  = dScale;
                coder.SubRange.HighCount = coder.SubRange.Scale;
                diff = this.NumStats - model.NumMasked;
                index--;
                do
                {
                    state2.Address = this.ps[++index];
                    model.CharMask[state2.Symbol] = model.EscCount;
                }while (--diff != 0);
                context.incSumm((int)coder.SubRange.Scale);
                model.NumMasked = this.NumStats;
            }
            return(true);
        }
Ejemplo n.º 3
0
        public int decodeChar(SharpCompress.Compressor.LZMA.RangeCoder.Decoder decoder)
        {
            SharpCompress.Compressor.PPMd.H.State state;
            int  num;
            int  threshold;
            int  num3;
            byte symbol;

            if (this.minContext.NumStats != 1)
            {
                state         = this.tempState1.Initialize(this.Heap);
                state.Address = this.minContext.FreqData.GetStats();
                if ((threshold = (int)decoder.GetThreshold((uint)this.minContext.FreqData.SummFreq)) < (num3 = state.Freq))
                {
                    decoder.Decode(0, (uint)state.Freq);
                    symbol = (byte)state.Symbol;
                    this.minContext.update1_0(this, state.Address);
                    this.nextContext();
                    return(symbol);
                }
                this.prevSuccess = 0;
                num = this.minContext.NumStats - 1;
                do
                {
                    state.IncrementAddress();
                    if ((num3 += state.Freq) > threshold)
                    {
                        decoder.Decode((uint)(num3 - state.Freq), (uint)state.Freq);
                        symbol = (byte)state.Symbol;
                        this.minContext.update1(this, state.Address);
                        this.nextContext();
                        return(symbol);
                    }
                }while (--num > 0);
                if (threshold >= this.minContext.FreqData.SummFreq)
                {
                    return(-2);
                }
                this.hiBitsFlag = this.HB2Flag[this.foundState.Symbol];
                decoder.Decode((uint)num3, (uint)(this.minContext.FreqData.SummFreq - num3));
                for (num = 0; num < 0x100; num++)
                {
                    this.charMask[num] = -1;
                }
                this.charMask[state.Symbol] = 0;
                num = this.minContext.NumStats - 1;
                do
                {
                    state.DecrementAddress();
                    this.charMask[state.Symbol] = 0;
                }while (--num > 0);
            }
            else
            {
                SharpCompress.Compressor.PPMd.H.State rs = this.tempState1.Initialize(this.Heap);
                rs.Address      = this.minContext.getOneState().Address;
                this.hiBitsFlag = this.getHB2Flag()[this.foundState.Symbol];
                int index = rs.Freq - 1;
                int num6  = this.minContext.getArrayIndex(this, rs);
                int summ  = this.binSumm[index][num6];
                if (decoder.DecodeBit((uint)summ, 14) == 0)
                {
                    this.binSumm[index][num6] = ((summ + INTERVAL) - this.minContext.getMean(summ, 7, 2)) & 0xffff;
                    this.foundState.Address   = rs.Address;
                    symbol = (byte)rs.Symbol;
                    rs.IncrementFreq((rs.Freq < 0x80) ? 1 : 0);
                    this.prevSuccess = 1;
                    this.incRunLength(1);
                    this.nextContext();
                    return(symbol);
                }
                summ = (summ - this.minContext.getMean(summ, 7, 2)) & 0xffff;
                this.binSumm[index][num6] = summ;
                this.initEsc = PPMContext.ExpEscape[Utility.URShift(summ, 10)];
                for (num = 0; num < 0x100; num++)
                {
                    this.charMask[num] = -1;
                }
                this.charMask[rs.Symbol] = 0;
                this.prevSuccess         = 0;
            }
            while (true)
            {
                int num8;
                state = this.tempState1.Initialize(this.Heap);
                int numStats = this.minContext.NumStats;
                do
                {
                    this.orderFall++;
                    this.minContext.Address = this.minContext.getSuffix();
                    if ((this.minContext.Address <= this.subAlloc.PText) || (this.minContext.Address > this.subAlloc.HeapEnd))
                    {
                        return(-1);
                    }
                }while (this.minContext.NumStats == numStats);
                num3          = 0;
                state.Address = this.minContext.FreqData.GetStats();
                num           = 0;
                int num9 = this.minContext.NumStats - numStats;
                do
                {
                    int num11 = this.charMask[state.Symbol];
                    num3 += state.Freq & num11;
                    this.minContext.ps[num] = state.Address;
                    state.IncrementAddress();
                    num -= num11;
                }while (num != num9);
                SEE2Context context = this.minContext.makeEscFreq(this, numStats, out num8);
                num8     += num3;
                threshold = (int)decoder.GetThreshold((uint)num8);
                if (threshold < num3)
                {
                    SharpCompress.Compressor.PPMd.H.State state3 = this.tempState2.Initialize(this.Heap);
                    num3           = 0;
                    num            = 0;
                    state3.Address = this.minContext.ps[num];
                    while ((num3 += state3.Freq) <= threshold)
                    {
                        num++;
                        state3.Address = this.minContext.ps[num];
                    }
                    state.Address = state3.Address;
                    decoder.Decode((uint)(num3 - state.Freq), (uint)state.Freq);
                    context.update();
                    symbol = (byte)state.Symbol;
                    this.minContext.update2(this, state.Address);
                    this.updateModel();
                    return(symbol);
                }
                if (threshold >= num8)
                {
                    return(-2);
                }
                decoder.Decode((uint)num3, (uint)(num8 - num3));
                context.Summ += num8;
                do
                {
                    state.Address = this.minContext.ps[--num];
                    this.charMask[state.Symbol] = 0;
                }while (num != 0);
            }
        }