Example #1
0
        internal SEE2Context makeEscFreq(ModelPPM model, int numMasked, out int escFreq)
        {
            SEE2Context psee2c;
            int         numStats  = NumStats;
            int         nonMasked = numStats - numMasked;

            if (numStats != 256)
            {
                PPMContext suff = getTempPPMContext(model.Heap);
                suff.Address = getSuffix();
                int idx1 = model.getNS2Indx()[nonMasked - 1];
                int idx2 = 0;
                idx2   += ((nonMasked < suff.NumStats - numStats) ? 1 : 0);
                idx2   += 2 * ((freqData.SummFreq < 11 * numStats) ? 1 : 0);
                idx2   += 4 * ((numMasked > nonMasked) ? 1 : 0);
                idx2   += model.HiBitsFlag;
                psee2c  = model.getSEE2Cont()[idx1][idx2];
                escFreq = psee2c.Mean;
            }
            else
            {
                psee2c  = model.DummySEE2Cont;
                escFreq = 1;
            }
            return(psee2c);
        }
        public PpmdStream(PpmdProperties properties, Stream stream, bool compress)
        {
            this.properties = properties;
            this.stream = stream;
            this.compress = compress;

            if (properties.Version == PpmdVersion.I1)
            {
                model = new I1.Model();
                if (compress)
                    model.EncodeStart(properties);
                else
                    model.DecodeStart(stream, properties);
            }
            if (properties.Version == PpmdVersion.H)
            {
                modelH = new H.ModelPPM();
                if (compress)
                    throw new NotImplementedException();
                else
                    modelH.decodeInit(stream, properties.ModelOrder, properties.AllocatorSize);
            }
            if (properties.Version == PpmdVersion.H7z)
            {
                modelH = new H.ModelPPM();
                if (compress)
                    throw new NotImplementedException();
                else
                    modelH.decodeInit(null, properties.ModelOrder, properties.AllocatorSize);
                decoder = new LZMA.RangeCoder.Decoder();
                decoder.Init(stream);
            }
        }
Example #3
0
        internal void decodeBinSymbol(ModelPPM model)
        {
            State rs = tempState1.Initialize(model.Heap);

            rs.Address       = oneState.Address; // State&
            model.HiBitsFlag = model.getHB2Flag()[model.FoundState.Symbol];
            int off1 = rs.Freq - 1;
            int off2 = getArrayIndex(model, rs);
            int bs   = model.BinSumm[off1][off2];

            if (model.Coder.GetCurrentShiftCount(ModelPPM.TOT_BITS) < bs)
            {
                model.FoundState.Address = rs.Address;
                rs.IncrementFreq((rs.Freq < 128) ? 1 : 0);
                model.Coder.SubRange.LowCount  = 0;
                model.Coder.SubRange.HighCount = bs;
                bs = ((bs + ModelPPM.INTERVAL - getMean(bs, ModelPPM.PERIOD_BITS, 2)) & 0xffff);
                model.BinSumm[off1][off2] = bs;
                model.PrevSuccess         = 1;
                model.incRunLength(1);
            }
            else
            {
                model.Coder.SubRange.LowCount = bs;
                bs = (bs - getMean(bs, ModelPPM.PERIOD_BITS, 2)) & 0xFFFF;
                model.BinSumm[off1][off2]      = bs;
                model.Coder.SubRange.HighCount = ModelPPM.BIN_SCALE;
                model.InitEsc             = ExpEscape[Utility.URShift(bs, 10)];
                model.NumMasked           = 1;
                model.CharMask[rs.Symbol] = model.EscCount;
                model.PrevSuccess         = 0;
                model.FoundState.Address  = 0;
            }
            //int a = 0;//TODO just 4 debugging
        }
Example #4
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);
        }
Example #5
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 #6
0
        private SEE2Context makeEscFreq2(ModelPPM model, int Diff)
        {
            SEE2Context psee2c;
            int         numStats = NumStats;

            if (numStats != 256)
            {
                PPMContext suff = getTempPPMContext(model.Heap);
                suff.Address = getSuffix();
                int idx1 = model.getNS2Indx()[Diff - 1];
                int idx2 = 0;
                idx2  += ((Diff < suff.NumStats - numStats) ? 1 : 0);
                idx2  += 2 * ((freqData.SummFreq < 11 * numStats) ? 1 : 0);
                idx2  += 4 * ((model.NumMasked > Diff) ? 1 : 0);
                idx2  += model.HiBitsFlag;
                psee2c = model.getSEE2Cont()[idx1][idx2];
                model.Coder.SubRange.Scale = psee2c.Mean;
            }
            else
            {
                psee2c = model.DummySEE2Cont;
                model.Coder.SubRange.Scale = 1;
            }
            return(psee2c);
        }
Example #7
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);
        }
Example #8
0
        internal int getArrayIndex(ModelPPM Model, SharpCompress.Compressor.PPMd.H.State rs)
        {
            PPMContext context = this.getTempPPMContext(Model.SubAlloc.Heap);

            context.Address = this.getSuffix();
            int num = 0;

            num += Model.PrevSuccess;
            num += Model.getNS2BSIndx()[context.NumStats - 1];
            num += Model.HiBitsFlag + (2 * Model.getHB2Flag()[rs.Symbol]);
            return(num + (Utility.URShift(Model.RunLength, 0x1a) & 0x20));
        }
Example #9
0
 internal void update1_0(ModelPPM model, int p)
 {
     model.FoundState.Address = p;
     model.PrevSuccess        = 2 * model.FoundState.Freq > freqData.SummFreq ? 1 : 0;
     model.incRunLength(model.PrevSuccess);
     freqData.IncrementSummFreq(4);
     model.FoundState.IncrementFreq(4);
     if (model.FoundState.Freq > ModelPPM.MAX_FREQ)
     {
         rescale(model);
     }
 }
Example #10
0
 internal void update1_0(ModelPPM model, int p)
 {
     model.FoundState.Address = p;
     model.PrevSuccess        = ((2 * model.FoundState.Freq) > this.freqData.SummFreq) ? 1 : 0;
     model.incRunLength(model.PrevSuccess);
     this.freqData.IncrementSummFreq(4);
     model.FoundState.IncrementFreq(4);
     if (model.FoundState.Freq > 0x7c)
     {
         this.rescale(model);
     }
 }
Example #11
0
        internal int getArrayIndex(ModelPPM Model, State rs)
        {
            PPMContext tempSuffix = getTempPPMContext(Model.SubAlloc.Heap);

            tempSuffix.Address = getSuffix();
            int ret = 0;

            ret += Model.PrevSuccess;
            ret += Model.getNS2BSIndx()[tempSuffix.NumStats - 1];
            ret += Model.HiBitsFlag + 2 * Model.getHB2Flag()[rs.Symbol];
            ret += ((Utility.URShift(Model.RunLength, 26)) & 0x20);
            return(ret);
        }
Example #12
0
 internal void update2(ModelPPM model, int p)
 {
     SharpCompress.Compressor.PPMd.H.State state = this.tempState5.Initialize(model.Heap);
     state.Address            = p;
     model.FoundState.Address = p;
     model.FoundState.IncrementFreq(4);
     this.freqData.IncrementSummFreq(4);
     if (state.Freq > 0x7c)
     {
         this.rescale(model);
     }
     model.incEscCount(1);
     model.RunLength = model.InitRL;
 }
Example #13
0
        internal int createChild(ModelPPM model, State pStats, StateRef firstState)
        {
            PPMContext pc = getTempPPMContext(model.SubAlloc.Heap);

            pc.Address = model.SubAlloc.allocContext();
            if (pc != null)
            {
                pc.NumStats = 1;
                pc.setOneState(firstState);
                pc.setSuffix(this);
                pStats.SetSuccessor(pc);
            }
            return(pc.Address);
        }
Example #14
0
        internal int createChild(ModelPPM model, SharpCompress.Compressor.PPMd.H.State pStats, StateRef firstState)
        {
            PPMContext successor = this.getTempPPMContext(model.SubAlloc.Heap);

            successor.Address = model.SubAlloc.allocContext();
            if (successor != null)
            {
                successor.NumStats = 1;
                successor.setOneState(firstState);
                successor.setSuffix(this);
                pStats.SetSuccessor(successor);
            }
            return(successor.Address);
        }
Example #15
0
        internal void update2(ModelPPM model, int p)
        {
            State temp = tempState5.Initialize(model.Heap);

            temp.Address             = p;
            model.FoundState.Address = p;
            model.FoundState.IncrementFreq(4);
            freqData.IncrementSummFreq(4);
            if (temp.Freq > ModelPPM.MAX_FREQ)
            {
                rescale(model);
            }
            model.incEscCount(1);
            model.RunLength = model.InitRL;
        }
Example #16
0
        public PpmdStream(PpmdProperties properties, Stream stream, bool compress)
        {
            this.properties = properties;
            this.stream     = stream;
            this.compress   = compress;

            if (properties.Version == PpmdVersion.I1)
            {
                model = new I1.Model();
                if (compress)
                {
                    model.EncodeStart(properties);
                }
                else
                {
                    model.DecodeStart(stream, properties);
                }
            }
            if (properties.Version == PpmdVersion.H)
            {
                modelH = new H.ModelPPM();
                if (compress)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    modelH.decodeInit(stream, properties.ModelOrder, properties.AllocatorSize);
                }
            }
            if (properties.Version == PpmdVersion.H7z)
            {
                modelH = new H.ModelPPM();
                if (compress)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    modelH.decodeInit(null, properties.ModelOrder, properties.AllocatorSize);
                }
                decoder = new LZMA.RangeCoder.Decoder();
                decoder.Init(stream);
            }
        }
Example #17
0
 internal void update1(ModelPPM model, int p)
 {
     model.FoundState.Address = p;
     model.FoundState.IncrementFreq(4);
     this.freqData.IncrementSummFreq(4);
     SharpCompress.Compressor.PPMd.H.State state  = this.tempState3.Initialize(model.Heap);
     SharpCompress.Compressor.PPMd.H.State state2 = this.tempState4.Initialize(model.Heap);
     state.Address  = p;
     state2.Address = p - 6;
     if (state.Freq > state2.Freq)
     {
         SharpCompress.Compressor.PPMd.H.State.PPMDSwap(state, state2);
         model.FoundState.Address = state2.Address;
         if (state2.Freq > 0x7c)
         {
             this.rescale(model);
         }
     }
 }
Example #18
0
        //	public static void ppmdSwap(ModelPPM model, StatePtr state1, StatePtr state2)
        //	{
        //		byte[] bytes = model.getSubAlloc().getHeap();
        //		int p1 = state1.Address;
        //		int p2 = state2.Address;
        //
        //		for (int i = 0; i < StatePtr.size; i++) {
        //			byte temp = bytes[p1+i];
        //			bytes[p1+i] = bytes[p2+i];
        //			bytes[p2+i] = temp;
        //		}
        //		state1.Address=p1);
        //		state2.Address=p2);
        //	}

        internal void update1(ModelPPM model, int p)
        {
            model.FoundState.Address = p;
            model.FoundState.IncrementFreq(4);
            freqData.IncrementSummFreq(4);
            State p0 = tempState3.Initialize(model.Heap);
            State p1 = tempState4.Initialize(model.Heap);

            p0.Address = p;
            p1.Address = p - State.Size;
            if (p0.Freq > p1.Freq)
            {
                State.PPMDSwap(p0, p1);
                model.FoundState.Address = p1.Address;
                if (p1.Freq > ModelPPM.MAX_FREQ)
                {
                    rescale(model);
                }
            }
        }
Example #19
0
        private SEE2Context makeEscFreq2(ModelPPM model, int Diff)
        {
            SEE2Context context;
            int         numStats = this.NumStats;

            if (numStats != 0x100)
            {
                PPMContext context2 = this.getTempPPMContext(model.Heap);
                context2.Address = this.getSuffix();
                int index = model.getNS2Indx()[Diff - 1];
                int num3  = 0;
                num3   += (Diff < (context2.NumStats - numStats)) ? 1 : 0;
                num3   += 2 * ((this.freqData.SummFreq < (11 * numStats)) ? 1 : 0);
                num3   += 4 * ((model.NumMasked > Diff) ? 1 : 0);
                num3   += model.HiBitsFlag;
                context = model.getSEE2Cont()[index][num3];
                model.Coder.SubRange.Scale = context.Mean;
                return(context);
            }
            context = model.DummySEE2Cont;
            model.Coder.SubRange.Scale = 1L;
            return(context);
        }
Example #20
0
        internal SEE2Context makeEscFreq(ModelPPM model, int numMasked, out int escFreq)
        {
            SEE2Context context;
            int         numStats = this.NumStats;
            int         num2     = numStats - numMasked;

            if (numStats != 0x100)
            {
                PPMContext context2 = this.getTempPPMContext(model.Heap);
                context2.Address = this.getSuffix();
                int index = model.getNS2Indx()[num2 - 1];
                int num4  = 0;
                num4   += (num2 < (context2.NumStats - numStats)) ? 1 : 0;
                num4   += 2 * ((this.freqData.SummFreq < (11 * numStats)) ? 1 : 0);
                num4   += 4 * ((numMasked > num2) ? 1 : 0);
                num4   += model.HiBitsFlag;
                context = model.getSEE2Cont()[index][num4];
                escFreq = context.Mean;
                return(context);
            }
            context = model.DummySEE2Cont;
            escFreq = 1;
            return(context);
        }
Example #21
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 #22
0
        internal bool decodeSymbol1(ModelPPM model)
        {

            RangeCoder coder = model.Coder;
            coder.SubRange.Scale = freqData.SummFreq;
            State p = new State(model.Heap);
            p.Address = freqData.GetStats();
            int i, HiCnt;
            long count = coder.CurrentCount;
            if (count >= coder.SubRange.Scale)
            {
                return false;
            }
            if (count < (HiCnt = p.Freq))
            {
                coder.SubRange.HighCount = HiCnt;
                model.PrevSuccess = (2 * HiCnt > coder.SubRange.Scale) ? 1 : 0;
                model.incRunLength(model.PrevSuccess);
                HiCnt += 4;
                model.FoundState.Address = p.Address;
                model.FoundState.Freq = HiCnt;
                freqData.IncrementSummFreq(4);
                if (HiCnt > ModelPPM.MAX_FREQ)
                {
                    rescale(model);
                }
                coder.SubRange.LowCount = 0;
                return true;
            }
            else
            {
                if (model.FoundState.Address == 0)
                {
                    return (false);
                }
            }
            model.PrevSuccess = 0;
            int numStats = NumStats;
            i = numStats - 1;
            while ((HiCnt += p.IncrementAddress().Freq) <= count)
            {
                if (--i == 0)
                {
                    model.HiBitsFlag = model.getHB2Flag()[model.FoundState.Symbol];
                    coder.SubRange.LowCount = HiCnt;
                    model.CharMask[p.Symbol] = model.EscCount;
                    model.NumMasked = numStats;
                    i = numStats - 1;
                    model.FoundState.Address = 0;
                    do
                    {
                        model.CharMask[p.DecrementAddress().Symbol] = model.EscCount;
                    }
                    while (--i != 0);
                    coder.SubRange.HighCount = coder.SubRange.Scale;
                    return (true);
                }
            }
            coder.SubRange.LowCount = HiCnt - p.Freq;
            coder.SubRange.HighCount = HiCnt;
            update1(model, p.Address);
            return (true);
        }
Example #23
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 #24
0
 private SEE2Context makeEscFreq2(ModelPPM model, int Diff)
 {
     SEE2Context psee2c;
     int numStats = NumStats;
     if (numStats != 256)
     {
         PPMContext suff = getTempPPMContext(model.Heap);
         suff.Address = getSuffix();
         int idx1 = model.getNS2Indx()[Diff - 1];
         int idx2 = 0;
         idx2 += ((Diff < suff.NumStats - numStats) ? 1 : 0);
         idx2 += 2 * ((freqData.SummFreq < 11 * numStats) ? 1 : 0);
         idx2 += 4 * ((model.NumMasked > Diff) ? 1 : 0);
         idx2 += model.HiBitsFlag;
         psee2c = model.getSEE2Cont()[idx1][idx2];
         model.Coder.SubRange.Scale = psee2c.Mean;
     }
     else
     {
         psee2c = model.DummySEE2Cont;
         model.Coder.SubRange.Scale = 1;
     }
     return psee2c;
 }
Example #25
0
 internal SEE2Context makeEscFreq(ModelPPM model, int numMasked, out int escFreq)
 {
     SEE2Context psee2c;
     int numStats = NumStats;
     int nonMasked = numStats - numMasked;
     if (numStats != 256)
     {
         PPMContext suff = getTempPPMContext(model.Heap);
         suff.Address = getSuffix();
         int idx1 = model.getNS2Indx()[nonMasked - 1];
         int idx2 = 0;
         idx2 += ((nonMasked < suff.NumStats - numStats) ? 1 : 0);
         idx2 += 2 * ((freqData.SummFreq < 11 * numStats) ? 1 : 0);
         idx2 += 4 * ((numMasked > nonMasked) ? 1 : 0);
         idx2 += model.HiBitsFlag;
         psee2c = model.getSEE2Cont()[idx1][idx2];
         escFreq = psee2c.Mean;
     }
     else
     {
         psee2c = model.DummySEE2Cont;
         escFreq = 1;
     }
     return psee2c;
 }
Example #26
0
 internal void update1(ModelPPM model, int p)
 {
     model.FoundState.Address = p;
     model.FoundState.IncrementFreq(4);
     this.freqData.IncrementSummFreq(4);
     SharpCompress.Compressor.PPMd.H.State state = this.tempState3.Initialize(model.Heap);
     SharpCompress.Compressor.PPMd.H.State state2 = this.tempState4.Initialize(model.Heap);
     state.Address = p;
     state2.Address = p - 6;
     if (state.Freq > state2.Freq)
     {
         SharpCompress.Compressor.PPMd.H.State.PPMDSwap(state, state2);
         model.FoundState.Address = state2.Address;
         if (state2.Freq > 0x7c)
         {
             this.rescale(model);
         }
     }
 }
Example #27
0
 private SEE2Context makeEscFreq2(ModelPPM model, int Diff)
 {
     SEE2Context context;
     int numStats = this.NumStats;
     if (numStats != 0x100)
     {
         PPMContext context2 = this.getTempPPMContext(model.Heap);
         context2.Address = this.getSuffix();
         int index = model.getNS2Indx()[Diff - 1];
         int num3 = 0;
         num3 += (Diff < (context2.NumStats - numStats)) ? 1 : 0;
         num3 += 2 * ((this.freqData.SummFreq < (11 * numStats)) ? 1 : 0);
         num3 += 4 * ((model.NumMasked > Diff) ? 1 : 0);
         num3 += model.HiBitsFlag;
         context = model.getSEE2Cont()[index][num3];
         model.Coder.SubRange.Scale = context.Mean;
         return context;
     }
     context = model.DummySEE2Cont;
     model.Coder.SubRange.Scale = 1L;
     return context;
 }
Example #28
0
        //	public static void ppmdSwap(ModelPPM model, StatePtr state1, StatePtr state2)
        //	{
        //		byte[] bytes = model.getSubAlloc().getHeap();
        //		int p1 = state1.Address;
        //		int p2 = state2.Address;
        //		
        //		for (int i = 0; i < StatePtr.size; i++) {
        //			byte temp = bytes[p1+i];
        //			bytes[p1+i] = bytes[p2+i];
        //			bytes[p2+i] = temp;
        //		}
        //		state1.Address=p1);
        //		state2.Address=p2);
        //	}

        internal void update1(ModelPPM model, int p)
        {
            model.FoundState.Address = p;
            model.FoundState.IncrementFreq(4);
            freqData.IncrementSummFreq(4);
            State p0 = tempState3.Initialize(model.Heap);
            State p1 = tempState4.Initialize(model.Heap);
            p0.Address = p;
            p1.Address = p - State.Size;
            if (p0.Freq > p1.Freq)
            {
                State.PPMDSwap(p0, p1);
                model.FoundState.Address = p1.Address;
                if (p1.Freq > ModelPPM.MAX_FREQ)
                    rescale(model);
            }
        }
Example #29
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);
        }
Example #30
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;
 }
Example #31
0
 internal void decodeBinSymbol(ModelPPM model)
 {
     State rs = tempState1.Initialize(model.Heap);
     rs.Address = oneState.Address; // State&
     model.HiBitsFlag = model.getHB2Flag()[model.FoundState.Symbol];
     int off1 = rs.Freq - 1;
     int off2 = getArrayIndex(model, rs);
     int bs = model.BinSumm[off1][off2];
     if (model.Coder.GetCurrentShiftCount(ModelPPM.TOT_BITS) < bs)
     {
         model.FoundState.Address = rs.Address;
         rs.IncrementFreq((rs.Freq < 128) ? 1 : 0);
         model.Coder.SubRange.LowCount = 0;
         model.Coder.SubRange.HighCount = bs;
         bs = ((bs + ModelPPM.INTERVAL - getMean(bs, ModelPPM.PERIOD_BITS, 2)) & 0xffff);
         model.BinSumm[off1][off2] = bs;
         model.PrevSuccess = 1;
         model.incRunLength(1);
     }
     else
     {
         model.Coder.SubRange.LowCount = bs;
         bs = (bs - getMean(bs, ModelPPM.PERIOD_BITS, 2)) & 0xFFFF;
         model.BinSumm[off1][off2] = bs;
         model.Coder.SubRange.HighCount = ModelPPM.BIN_SCALE;
         model.InitEsc = ExpEscape[Utility.URShift(bs, 10)];
         model.NumMasked = 1;
         model.CharMask[rs.Symbol] = model.EscCount;
         model.PrevSuccess = 0;
         model.FoundState.Address = 0;
     }
     //int a = 0;//TODO just 4 debugging
 }
Example #32
0
        internal void rescale(ModelPPM model)
        {
            int OldNS = NumStats, i = NumStats - 1, Adder, EscFreq;
            // STATE* p1, * p;
            State p1 = new State(model.Heap);
            State p = new State(model.Heap);
            State temp = new State(model.Heap);

            for (p.Address = model.FoundState.Address; p.Address != freqData.GetStats(); p.DecrementAddress())
            {
                temp.Address = p.Address - State.Size;
                State.PPMDSwap(p, temp);
            }
            temp.Address = freqData.GetStats();
            temp.IncrementFreq(4);
            freqData.IncrementSummFreq(4);
            EscFreq = freqData.SummFreq - p.Freq;
            Adder = (model.OrderFall != 0) ? 1 : 0;
            p.Freq = Utility.URShift((p.Freq + Adder), 1);
            freqData.SummFreq = p.Freq;
            do
            {
                p.IncrementAddress();
                EscFreq -= p.Freq;
                p.Freq = Utility.URShift((p.Freq + Adder), 1);
                freqData.IncrementSummFreq(p.Freq);
                temp.Address = p.Address - State.Size;
                if (p.Freq > temp.Freq)
                {
                    p1.Address = p.Address;
                    StateRef tmp = new StateRef();
                    tmp.Values = p1;
                    State temp2 = new State(model.Heap);
                    State temp3 = new State(model.Heap);
                    do
                    {
                        // p1[0]=p1[-1];
                        temp2.Address = p1.Address - State.Size;
                        p1.SetValues(temp2);
                        p1.DecrementAddress();
                        temp3.Address = p1.Address - State.Size;
                    }
                    while (p1.Address != freqData.GetStats() && tmp.Freq > temp3.Freq);
                    p1.SetValues(tmp);
                }
            }
            while (--i != 0);
            if (p.Freq == 0)
            {
                do
                {
                    i++;
                    p.DecrementAddress();
                }
                while (p.Freq == 0);
                EscFreq += i;
                NumStats = NumStats - i;
                if (NumStats == 1)
                {
                    StateRef tmp = new StateRef();
                    temp.Address = freqData.GetStats();
                    tmp.Values = temp;
                    // STATE tmp=*U.Stats;
                    do
                    {
                        // tmp.Freq-=(tmp.Freq >> 1)
                        tmp.DecrementFreq(Utility.URShift(tmp.Freq, 1));
                        EscFreq = Utility.URShift(EscFreq, 1);
                    }
                    while (EscFreq > 1);
                    model.SubAlloc.freeUnits(freqData.GetStats(), Utility.URShift((OldNS + 1), 1));
                    oneState.SetValues(tmp);
                    model.FoundState.Address = oneState.Address;
                    return;
                }
            }
            EscFreq -= Utility.URShift(EscFreq, 1);
            freqData.IncrementSummFreq(EscFreq);
            int n0 = Utility.URShift((OldNS + 1), 1), n1 = Utility.URShift((NumStats + 1), 1);
            if (n0 != n1)
            {
                freqData.SetStats(model.SubAlloc.shrinkUnits(freqData.GetStats(), n0, n1));
            }
            model.FoundState.Address = freqData.GetStats();
        }
Example #33
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;
 }
Example #34
0
 internal int getArrayIndex(ModelPPM Model, SharpCompress.Compressor.PPMd.H.State rs)
 {
     PPMContext context = this.getTempPPMContext(Model.SubAlloc.Heap);
     context.Address = this.getSuffix();
     int num = 0;
     num += Model.PrevSuccess;
     num += Model.getNS2BSIndx()[context.NumStats - 1];
     num += Model.HiBitsFlag + (2 * Model.getHB2Flag()[rs.Symbol]);
     return (num + (Utility.URShift(Model.RunLength, 0x1a) & 0x20));
 }
Example #35
0
        internal void rescale(ModelPPM model)
        {
            int OldNS = NumStats, i = NumStats - 1, Adder, EscFreq;
            // STATE* p1, * p;
            State p1   = new State(model.Heap);
            State p    = new State(model.Heap);
            State temp = new State(model.Heap);

            for (p.Address = model.FoundState.Address; p.Address != freqData.GetStats(); p.DecrementAddress())
            {
                temp.Address = p.Address - State.Size;
                State.PPMDSwap(p, temp);
            }
            temp.Address = freqData.GetStats();
            temp.IncrementFreq(4);
            freqData.IncrementSummFreq(4);
            EscFreq           = freqData.SummFreq - p.Freq;
            Adder             = (model.OrderFall != 0) ? 1 : 0;
            p.Freq            = Utility.URShift((p.Freq + Adder), 1);
            freqData.SummFreq = p.Freq;
            do
            {
                p.IncrementAddress();
                EscFreq -= p.Freq;
                p.Freq   = Utility.URShift((p.Freq + Adder), 1);
                freqData.IncrementSummFreq(p.Freq);
                temp.Address = p.Address - State.Size;
                if (p.Freq > temp.Freq)
                {
                    p1.Address = p.Address;
                    StateRef tmp = new StateRef();
                    tmp.Values = p1;
                    State temp2 = new State(model.Heap);
                    State temp3 = new State(model.Heap);
                    do
                    {
                        // p1[0]=p1[-1];
                        temp2.Address = p1.Address - State.Size;
                        p1.SetValues(temp2);
                        p1.DecrementAddress();
                        temp3.Address = p1.Address - State.Size;
                    } while (p1.Address != freqData.GetStats() && tmp.Freq > temp3.Freq);
                    p1.SetValues(tmp);
                }
            } while (--i != 0);
            if (p.Freq == 0)
            {
                do
                {
                    i++;
                    p.DecrementAddress();
                } while (p.Freq == 0);
                EscFreq += i;
                NumStats = NumStats - i;
                if (NumStats == 1)
                {
                    StateRef tmp = new StateRef();
                    temp.Address = freqData.GetStats();
                    tmp.Values   = temp;
                    // STATE tmp=*U.Stats;
                    do
                    {
                        // tmp.Freq-=(tmp.Freq >> 1)
                        tmp.DecrementFreq(Utility.URShift(tmp.Freq, 1));
                        EscFreq = Utility.URShift(EscFreq, 1);
                    } while (EscFreq > 1);
                    model.SubAlloc.freeUnits(freqData.GetStats(), Utility.URShift((OldNS + 1), 1));
                    oneState.SetValues(tmp);
                    model.FoundState.Address = oneState.Address;
                    return;
                }
            }
            EscFreq -= Utility.URShift(EscFreq, 1);
            freqData.IncrementSummFreq(EscFreq);
            int n0 = Utility.URShift((OldNS + 1), 1), n1 = Utility.URShift((NumStats + 1), 1);

            if (n0 != n1)
            {
                freqData.SetStats(model.SubAlloc.shrinkUnits(freqData.GetStats(), n0, n1));
            }
            model.FoundState.Address = freqData.GetStats();
        }
Example #36
0
 internal void update1_0(ModelPPM model, int p)
 {
     model.FoundState.Address = p;
     model.PrevSuccess = ((2 * model.FoundState.Freq) > this.freqData.SummFreq) ? 1 : 0;
     model.incRunLength(model.PrevSuccess);
     this.freqData.IncrementSummFreq(4);
     model.FoundState.IncrementFreq(4);
     if (model.FoundState.Freq > 0x7c)
     {
         this.rescale(model);
     }
 }
Example #37
0
 internal int createChild(ModelPPM model, SharpCompress.Compressor.PPMd.H.State pStats, StateRef firstState)
 {
     PPMContext successor = this.getTempPPMContext(model.SubAlloc.Heap);
     successor.Address = model.SubAlloc.allocContext();
     if (successor != null)
     {
         successor.NumStats = 1;
         successor.setOneState(firstState);
         successor.setSuffix(this);
         pStats.SetSuccessor(successor);
     }
     return successor.Address;
 }
Example #38
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 #39
0
 internal void update1_0(ModelPPM model, int p)
 {
     model.FoundState.Address = p;
     model.PrevSuccess = 2 * model.FoundState.Freq > freqData.SummFreq ? 1 : 0;
     model.incRunLength(model.PrevSuccess);
     freqData.IncrementSummFreq(4);
     model.FoundState.IncrementFreq(4);
     if (model.FoundState.Freq > ModelPPM.MAX_FREQ)
         rescale(model);
 }
Example #40
0
 internal void update2(ModelPPM model, int p)
 {
     SharpCompress.Compressor.PPMd.H.State state = this.tempState5.Initialize(model.Heap);
     state.Address = p;
     model.FoundState.Address = p;
     model.FoundState.IncrementFreq(4);
     this.freqData.IncrementSummFreq(4);
     if (state.Freq > 0x7c)
     {
         this.rescale(model);
     }
     model.incEscCount(1);
     model.RunLength = model.InitRL;
 }
Example #41
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);
        }
Example #42
0
 internal void update2(ModelPPM model, int p)
 {
     State temp = tempState5.Initialize(model.Heap);
     temp.Address = p;
     model.FoundState.Address = p;
     model.FoundState.IncrementFreq(4);
     freqData.IncrementSummFreq(4);
     if (temp.Freq > ModelPPM.MAX_FREQ)
     {
         rescale(model);
     }
     model.incEscCount(1);
     model.RunLength = model.InitRL;
 }
Example #43
0
 internal int getArrayIndex(ModelPPM Model, State rs)
 {
     PPMContext tempSuffix = getTempPPMContext(Model.SubAlloc.Heap);
     tempSuffix.Address = getSuffix();
     int ret = 0;
     ret += Model.PrevSuccess;
     ret += Model.getNS2BSIndx()[tempSuffix.NumStats - 1];
     ret += Model.HiBitsFlag + 2 * Model.getHB2Flag()[rs.Symbol];
     ret += ((Utility.URShift(Model.RunLength, 26)) & 0x20);
     return ret;
 }
Example #44
0
 internal SEE2Context makeEscFreq(ModelPPM model, int numMasked, out int escFreq)
 {
     SEE2Context context;
     int numStats = this.NumStats;
     int num2 = numStats - numMasked;
     if (numStats != 0x100)
     {
         PPMContext context2 = this.getTempPPMContext(model.Heap);
         context2.Address = this.getSuffix();
         int index = model.getNS2Indx()[num2 - 1];
         int num4 = 0;
         num4 += (num2 < (context2.NumStats - numStats)) ? 1 : 0;
         num4 += 2 * ((this.freqData.SummFreq < (11 * numStats)) ? 1 : 0);
         num4 += 4 * ((numMasked > num2) ? 1 : 0);
         num4 += model.HiBitsFlag;
         context = model.getSEE2Cont()[index][num4];
         escFreq = context.Mean;
         return context;
     }
     context = model.DummySEE2Cont;
     escFreq = 1;
     return context;
 }
Example #45
0
        internal bool decodeSymbol1(ModelPPM model)
        {
            RangeCoder coder = model.Coder;

            coder.SubRange.Scale = freqData.SummFreq;
            State p = new State(model.Heap);

            p.Address = freqData.GetStats();
            int  i, HiCnt;
            long count = coder.CurrentCount;

            if (count >= coder.SubRange.Scale)
            {
                return(false);
            }
            if (count < (HiCnt = p.Freq))
            {
                coder.SubRange.HighCount = HiCnt;
                model.PrevSuccess        = (2 * HiCnt > coder.SubRange.Scale) ? 1 : 0;
                model.incRunLength(model.PrevSuccess);
                HiCnt += 4;
                model.FoundState.Address = p.Address;
                model.FoundState.Freq    = HiCnt;
                freqData.IncrementSummFreq(4);
                if (HiCnt > ModelPPM.MAX_FREQ)
                {
                    rescale(model);
                }
                coder.SubRange.LowCount = 0;
                return(true);
            }
            else
            {
                if (model.FoundState.Address == 0)
                {
                    return(false);
                }
            }
            model.PrevSuccess = 0;
            int numStats = NumStats;

            i = numStats - 1;
            while ((HiCnt += p.IncrementAddress().Freq) <= count)
            {
                if (--i == 0)
                {
                    model.HiBitsFlag         = model.getHB2Flag()[model.FoundState.Symbol];
                    coder.SubRange.LowCount  = HiCnt;
                    model.CharMask[p.Symbol] = model.EscCount;
                    model.NumMasked          = numStats;
                    i = numStats - 1;
                    model.FoundState.Address = 0;
                    do
                    {
                        model.CharMask[p.DecrementAddress().Symbol] = model.EscCount;
                    } while (--i != 0);
                    coder.SubRange.HighCount = coder.SubRange.Scale;
                    return(true);
                }
            }
            coder.SubRange.LowCount  = HiCnt - p.Freq;
            coder.SubRange.HighCount = HiCnt;
            update1(model, p.Address);
            return(true);
        }
Example #46
0
 internal int createChild(ModelPPM model, State pStats, StateRef firstState)
 {
     PPMContext pc = getTempPPMContext(model.SubAlloc.Heap);
     pc.Address = model.SubAlloc.allocContext();
     if (pc != null)
     {
         pc.NumStats = 1;
         pc.setOneState(firstState);
         pc.setSuffix(this);
         pStats.SetSuccessor(pc);
     }
     return pc.Address;
 }