Example #1
0
        internal void decodeBinSymbol(ModelPPM model)
        {
            SharpCompress.Compressor.PPMd.H.State rs = this.tempState1.Initialize(model.Heap);
            rs.Address       = this.oneState.Address;
            model.HiBitsFlag = model.getHB2Flag()[model.FoundState.Symbol];
            int index = rs.Freq - 1;
            int num2  = this.getArrayIndex(model, rs);
            int summ  = model.BinSumm[index][num2];

            if (model.Coder.GetCurrentShiftCount(ModelPPM.TOT_BITS) < summ)
            {
                model.FoundState.Address = rs.Address;
                rs.IncrementFreq((rs.Freq < 0x80) ? 1 : 0);
                model.Coder.SubRange.LowCount  = 0L;
                model.Coder.SubRange.HighCount = summ;
                summ = ((summ + ModelPPM.INTERVAL) - this.getMean(summ, 7, 2)) & 0xffff;
                model.BinSumm[index][num2] = summ;
                model.PrevSuccess          = 1;
                model.incRunLength(1);
            }
            else
            {
                model.Coder.SubRange.LowCount = summ;
                summ = (summ - this.getMean(summ, 7, 2)) & 0xffff;
                model.BinSumm[index][num2]     = summ;
                model.Coder.SubRange.HighCount = ModelPPM.BIN_SCALE;
                model.InitEsc             = ExpEscape[Utility.URShift(summ, 10)];
                model.NumMasked           = 1;
                model.CharMask[rs.Symbol] = model.EscCount;
                model.PrevSuccess         = 0;
                model.FoundState.Address  = 0;
            }
        }
Example #2
0
        private void updateModel()
        {
            StateRef ref2 = this.tempStateRef1;

            ref2.Values = this.foundState;
            SharpCompress.Compressor.PPMd.H.State state  = this.tempState3.Initialize(this.Heap);
            SharpCompress.Compressor.PPMd.H.State state2 = this.tempState4.Initialize(this.Heap);
            PPMContext context   = this.tempPPMContext3.Initialize(this.Heap);
            PPMContext successor = this.tempPPMContext4.Initialize(this.Heap);

            context.Address = this.minContext.getSuffix();
            if ((ref2.Freq < 0x1f) && (context.Address != 0))
            {
                if (context.NumStats != 1)
                {
                    state.Address = context.FreqData.GetStats();
                    if (state.Symbol != ref2.Symbol)
                    {
                        do
                        {
                            state.IncrementAddress();
                        }while (state.Symbol != ref2.Symbol);
                        state2.Address = state.Address - 6;
                        if (state.Freq >= state2.Freq)
                        {
                            SharpCompress.Compressor.PPMd.H.State.PPMDSwap(state, state2);
                            state.DecrementAddress();
                        }
                    }
                    if (state.Freq < 0x73)
                    {
                        state.IncrementFreq(2);
                        context.FreqData.IncrementSummFreq(2);
                    }
                }
                else
                {
                    state.Address = context.getOneState().Address;
                    if (state.Freq < 0x20)
                    {
                        state.IncrementFreq(1);
                    }
                }
            }
            if (this.orderFall == 0)
            {
                this.foundState.SetSuccessor(this.createSuccessors(true, state));
                this.minContext.Address = this.foundState.GetSuccessor();
                this.maxContext.Address = this.foundState.GetSuccessor();
                if (this.minContext.Address == 0)
                {
                    this.updateModelRestart();
                }
            }
            else
            {
                this.subAlloc.Heap[this.subAlloc.PText] = (byte)ref2.Symbol;
                this.subAlloc.incPText();
                successor.Address = this.subAlloc.PText;
                if (this.subAlloc.PText >= this.subAlloc.FakeUnitsStart)
                {
                    this.updateModelRestart();
                }
                else
                {
                    if (ref2.GetSuccessor() != 0)
                    {
                        if (ref2.GetSuccessor() <= this.subAlloc.PText)
                        {
                            ref2.SetSuccessor(this.createSuccessors(false, state));
                            if (ref2.GetSuccessor() == 0)
                            {
                                this.updateModelRestart();
                                return;
                            }
                        }
                        if (--this.orderFall == 0)
                        {
                            successor.Address = ref2.GetSuccessor();
                            if (this.maxContext.Address != this.minContext.Address)
                            {
                                this.subAlloc.decPText(1);
                            }
                        }
                    }
                    else
                    {
                        this.foundState.SetSuccessor(successor.Address);
                        ref2.SetSuccessor(this.minContext);
                    }
                    int numStats = this.minContext.NumStats;
                    int num5     = (this.minContext.FreqData.SummFreq - numStats) - (ref2.Freq - 1);
                    context.Address = this.maxContext.Address;
                    while (context.Address != this.minContext.Address)
                    {
                        int number = context.NumStats;
                        if (number != 1)
                        {
                            if ((number & 1) == 0)
                            {
                                context.FreqData.SetStats(this.subAlloc.expandUnits(context.FreqData.GetStats(), Utility.URShift(number, 1)));
                                if (context.FreqData.GetStats() == 0)
                                {
                                    this.updateModelRestart();
                                    return;
                                }
                            }
                            int num6 = (((2 * number) < numStats) ? 1 : 0) + (2 * ((((4 * number) <= numStats) ? 1 : 0) & ((context.FreqData.SummFreq <= (8 * number)) ? 1 : 0)));
                            context.FreqData.IncrementSummFreq(num6);
                        }
                        else
                        {
                            state.Address = this.subAlloc.allocUnits(1);
                            if (state.Address == 0)
                            {
                                this.updateModelRestart();
                                return;
                            }
                            state.SetValues(context.getOneState());
                            context.FreqData.SetStats(state);
                            if (state.Freq < 30)
                            {
                                state.IncrementFreq(state.Freq);
                            }
                            else
                            {
                                state.Freq = 120;
                            }
                            context.FreqData.SummFreq = (state.Freq + this.initEsc) + ((numStats > 3) ? 1 : 0);
                        }
                        int dSummFreq = (2 * ref2.Freq) * (context.FreqData.SummFreq + 6);
                        int num4      = num5 + context.FreqData.SummFreq;
                        if (dSummFreq < (6 * num4))
                        {
                            dSummFreq = (1 + ((dSummFreq > num4) ? 1 : 0)) + ((dSummFreq >= (4 * num4)) ? 1 : 0);
                            context.FreqData.IncrementSummFreq(3);
                        }
                        else
                        {
                            dSummFreq = ((4 + ((dSummFreq >= (9 * num4)) ? 1 : 0)) + ((dSummFreq >= (12 * num4)) ? 1 : 0)) + ((dSummFreq >= (15 * num4)) ? 1 : 0);
                            context.FreqData.IncrementSummFreq(dSummFreq);
                        }
                        state.Address = context.FreqData.GetStats() + (number * 6);
                        state.SetSuccessor(successor);
                        state.Symbol     = ref2.Symbol;
                        state.Freq       = dSummFreq;
                        context.NumStats = ++number;
                        context.Address  = context.getSuffix();
                    }
                    int num7 = ref2.GetSuccessor();
                    this.maxContext.Address = num7;
                    this.minContext.Address = num7;
                }
            }
        }
Example #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);
            }
        }
Example #4
0
 internal void rescale(ModelPPM model)
 {
     StateRef ref2;
     int numStats = this.NumStats;
     int num2 = this.NumStats - 1;
     SharpCompress.Compressor.PPMd.H.State state = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
     SharpCompress.Compressor.PPMd.H.State state2 = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
     SharpCompress.Compressor.PPMd.H.State state3 = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
     state2.Address = model.FoundState.Address;
     while (state2.Address != this.freqData.GetStats())
     {
         state3.Address = state2.Address - 6;
         SharpCompress.Compressor.PPMd.H.State.PPMDSwap(state2, state3);
         state2.DecrementAddress();
     }
     state3.Address = this.freqData.GetStats();
     state3.IncrementFreq(4);
     this.freqData.IncrementSummFreq(4);
     int number = this.freqData.SummFreq - state2.Freq;
     int num3 = (model.OrderFall != 0) ? 1 : 0;
     state2.Freq = Utility.URShift((int) (state2.Freq + num3), 1);
     this.freqData.SummFreq = state2.Freq;
     do
     {
         state2.IncrementAddress();
         number -= state2.Freq;
         state2.Freq = Utility.URShift((int) (state2.Freq + num3), 1);
         this.freqData.IncrementSummFreq(state2.Freq);
         state3.Address = state2.Address - 6;
         if (state2.Freq > state3.Freq)
         {
             state.Address = state2.Address;
             ref2 = new StateRef();
             ref2.Values = state;
             SharpCompress.Compressor.PPMd.H.State ptr = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
             SharpCompress.Compressor.PPMd.H.State state5 = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
             do
             {
                 ptr.Address = state.Address - 6;
                 state.SetValues(ptr);
                 state.DecrementAddress();
                 state5.Address = state.Address - 6;
             }
             while ((state.Address != this.freqData.GetStats()) && (ref2.Freq > state5.Freq));
             state.SetValues(ref2);
         }
     }
     while (--num2 != 0);
     if (state2.Freq == 0)
     {
         do
         {
             num2++;
             state2.DecrementAddress();
         }
         while (state2.Freq == 0);
         number += num2;
         this.NumStats -= num2;
         if (this.NumStats == 1)
         {
             ref2 = new StateRef();
             state3.Address = this.freqData.GetStats();
             ref2.Values = state3;
             do
             {
                 ref2.DecrementFreq(Utility.URShift(ref2.Freq, 1));
                 number = Utility.URShift(number, 1);
             }
             while (number > 1);
             model.SubAlloc.freeUnits(this.freqData.GetStats(), Utility.URShift((int) (numStats + 1), 1));
             this.oneState.SetValues(ref2);
             model.FoundState.Address = this.oneState.Address;
             return;
         }
     }
     number -= Utility.URShift(number, 1);
     this.freqData.IncrementSummFreq(number);
     int oldNU = Utility.URShift((int) (numStats + 1), 1);
     int newNU = Utility.URShift((int) (this.NumStats + 1), 1);
     if (oldNU != newNU)
     {
         this.freqData.SetStats(model.SubAlloc.shrinkUnits(this.freqData.GetStats(), oldNU, newNU));
     }
     model.FoundState.Address = this.freqData.GetStats();
 }
Example #5
0
        internal void rescale(ModelPPM model)
        {
            StateRef ref2;
            int      numStats = this.NumStats;
            int      num2     = this.NumStats - 1;

            SharpCompress.Compressor.PPMd.H.State state  = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
            SharpCompress.Compressor.PPMd.H.State state2 = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
            SharpCompress.Compressor.PPMd.H.State state3 = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
            state2.Address = model.FoundState.Address;
            while (state2.Address != this.freqData.GetStats())
            {
                state3.Address = state2.Address - 6;
                SharpCompress.Compressor.PPMd.H.State.PPMDSwap(state2, state3);
                state2.DecrementAddress();
            }
            state3.Address = this.freqData.GetStats();
            state3.IncrementFreq(4);
            this.freqData.IncrementSummFreq(4);
            int number = this.freqData.SummFreq - state2.Freq;
            int num3   = (model.OrderFall != 0) ? 1 : 0;

            state2.Freq            = Utility.URShift((int)(state2.Freq + num3), 1);
            this.freqData.SummFreq = state2.Freq;
            do
            {
                state2.IncrementAddress();
                number     -= state2.Freq;
                state2.Freq = Utility.URShift((int)(state2.Freq + num3), 1);
                this.freqData.IncrementSummFreq(state2.Freq);
                state3.Address = state2.Address - 6;
                if (state2.Freq > state3.Freq)
                {
                    state.Address = state2.Address;
                    ref2          = new StateRef();
                    ref2.Values   = state;
                    SharpCompress.Compressor.PPMd.H.State ptr    = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
                    SharpCompress.Compressor.PPMd.H.State state5 = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
                    do
                    {
                        ptr.Address = state.Address - 6;
                        state.SetValues(ptr);
                        state.DecrementAddress();
                        state5.Address = state.Address - 6;
                    }while ((state.Address != this.freqData.GetStats()) && (ref2.Freq > state5.Freq));
                    state.SetValues(ref2);
                }
            }while (--num2 != 0);
            if (state2.Freq == 0)
            {
                do
                {
                    num2++;
                    state2.DecrementAddress();
                }while (state2.Freq == 0);
                number        += num2;
                this.NumStats -= num2;
                if (this.NumStats == 1)
                {
                    ref2           = new StateRef();
                    state3.Address = this.freqData.GetStats();
                    ref2.Values    = state3;
                    do
                    {
                        ref2.DecrementFreq(Utility.URShift(ref2.Freq, 1));
                        number = Utility.URShift(number, 1);
                    }while (number > 1);
                    model.SubAlloc.freeUnits(this.freqData.GetStats(), Utility.URShift((int)(numStats + 1), 1));
                    this.oneState.SetValues(ref2);
                    model.FoundState.Address = this.oneState.Address;
                    return;
                }
            }
            number -= Utility.URShift(number, 1);
            this.freqData.IncrementSummFreq(number);
            int oldNU = Utility.URShift((int)(numStats + 1), 1);
            int newNU = Utility.URShift((int)(this.NumStats + 1), 1);

            if (oldNU != newNU)
            {
                this.freqData.SetStats(model.SubAlloc.shrinkUnits(this.freqData.GetStats(), oldNU, newNU));
            }
            model.FoundState.Address = this.freqData.GetStats();
        }