예제 #1
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;
                }
            }
        }
예제 #2
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();
 }
예제 #3
0
        internal bool decodeSymbol1(ModelPPM model)
        {
            int        num2;
            RangeCoder coder = model.Coder;

            coder.SubRange.Scale = this.freqData.SummFreq;
            SharpCompress.Compressor.PPMd.H.State state = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
            state.Address = this.freqData.GetStats();
            long currentCount = coder.CurrentCount;

            if (currentCount >= coder.SubRange.Scale)
            {
                return(false);
            }
            if (currentCount < (num2 = state.Freq))
            {
                coder.SubRange.HighCount = num2;
                model.PrevSuccess        = ((2 * num2) > coder.SubRange.Scale) ? 1 : 0;
                model.incRunLength(model.PrevSuccess);
                num2 += 4;
                model.FoundState.Address = state.Address;
                model.FoundState.Freq    = num2;
                this.freqData.IncrementSummFreq(4);
                if (num2 > 0x7c)
                {
                    this.rescale(model);
                }
                coder.SubRange.LowCount = 0L;
                return(true);
            }
            if (model.FoundState.Address == 0)
            {
                return(false);
            }
            model.PrevSuccess = 0;
            int numStats = this.NumStats;
            int num      = numStats - 1;

            while ((num2 += state.IncrementAddress().Freq) <= currentCount)
            {
                if (--num == 0)
                {
                    model.HiBitsFlag             = model.getHB2Flag()[model.FoundState.Symbol];
                    coder.SubRange.LowCount      = num2;
                    model.CharMask[state.Symbol] = model.EscCount;
                    model.NumMasked          = numStats;
                    num                      = numStats - 1;
                    model.FoundState.Address = 0;
                    do
                    {
                        model.CharMask[state.DecrementAddress().Symbol] = model.EscCount;
                    }while (--num != 0);
                    coder.SubRange.HighCount = coder.SubRange.Scale;
                    return(true);
                }
            }
            coder.SubRange.LowCount  = num2 - state.Freq;
            coder.SubRange.HighCount = num2;
            this.update1(model, state.Address);
            return(true);
        }
예제 #4
0
 internal bool decodeSymbol1(ModelPPM model)
 {
     int num2;
     RangeCoder coder = model.Coder;
     coder.SubRange.Scale = this.freqData.SummFreq;
     SharpCompress.Compressor.PPMd.H.State state = new SharpCompress.Compressor.PPMd.H.State(model.Heap);
     state.Address = this.freqData.GetStats();
     long currentCount = coder.CurrentCount;
     if (currentCount >= coder.SubRange.Scale)
     {
         return false;
     }
     if (currentCount < (num2 = state.Freq))
     {
         coder.SubRange.HighCount = num2;
         model.PrevSuccess = ((2 * num2) > coder.SubRange.Scale) ? 1 : 0;
         model.incRunLength(model.PrevSuccess);
         num2 += 4;
         model.FoundState.Address = state.Address;
         model.FoundState.Freq = num2;
         this.freqData.IncrementSummFreq(4);
         if (num2 > 0x7c)
         {
             this.rescale(model);
         }
         coder.SubRange.LowCount = 0L;
         return true;
     }
     if (model.FoundState.Address == 0)
     {
         return false;
     }
     model.PrevSuccess = 0;
     int numStats = this.NumStats;
     int num = numStats - 1;
     while ((num2 += state.IncrementAddress().Freq) <= currentCount)
     {
         if (--num == 0)
         {
             model.HiBitsFlag = model.getHB2Flag()[model.FoundState.Symbol];
             coder.SubRange.LowCount = num2;
             model.CharMask[state.Symbol] = model.EscCount;
             model.NumMasked = numStats;
             num = numStats - 1;
             model.FoundState.Address = 0;
             do
             {
                 model.CharMask[state.DecrementAddress().Symbol] = model.EscCount;
             }
             while (--num != 0);
             coder.SubRange.HighCount = coder.SubRange.Scale;
             return true;
         }
     }
     coder.SubRange.LowCount = num2 - state.Freq;
     coder.SubRange.HighCount = num2;
     this.update1(model, state.Address);
     return true;
 }
예제 #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();
        }