コード例 #1
0
        // Debug
        //    public void dumpHeap() {
        //        subAlloc.dumpHeap();
        //    }

        internal bool decodeInit(Stream stream, int maxOrder, int maxMemory)
        {
            if (stream != null)
            {
                Coder = new RangeCoder(stream);
            }

            if (maxOrder == 1)
            {
                SubAlloc.stopSubAllocator();
                return(false);
            }
            SubAlloc.startSubAllocator(maxMemory);
            minContext = new PPMContext(Heap);

            //medContext = new PPMContext(Heap);
            maxContext    = new PPMContext(Heap);
            FoundState    = new State(Heap);
            dummySEE2Cont = new SEE2Context();
            for (int i = 0; i < 25; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    SEE2Cont[i][j] = new SEE2Context();
                }
            }
            startModelRare(maxOrder);

            return(minContext.Address != 0);
        }
コード例 #2
0
        internal bool decodeInit(Unpack unpackRead, int escChar)
        {
            int  MaxOrder = unpackRead.Char & 0xff;
            bool reset    = ((MaxOrder & 0x20) != 0);

            int MaxMB = 0;

            if (reset)
            {
                MaxMB = unpackRead.Char;
            }
            else
            {
                if (SubAlloc.GetAllocatedMemory() == 0)
                {
                    return(false);
                }
            }
            if ((MaxOrder & 0x40) != 0)
            {
                escChar = unpackRead.Char;
                unpackRead.PpmEscChar = escChar;
            }
            Coder = new RangeCoder(unpackRead);
            if (reset)
            {
                MaxOrder = (MaxOrder & 0x1f) + 1;
                if (MaxOrder > 16)
                {
                    MaxOrder = 16 + (MaxOrder - 16) * 3;
                }
                if (MaxOrder == 1)
                {
                    SubAlloc.stopSubAllocator();
                    return(false);
                }
                SubAlloc.startSubAllocator((MaxMB + 1) << 20);
                minContext = new PPMContext(Heap);

                //medContext = new PPMContext(Heap);
                maxContext    = new PPMContext(Heap);
                FoundState    = new State(Heap);
                dummySEE2Cont = new SEE2Context();
                for (int i = 0; i < 25; i++)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        SEE2Cont[i][j] = new SEE2Context();
                    }
                }
                startModelRare(MaxOrder);
            }
            return(minContext.Address != 0);
        }
コード例 #3
0
        internal bool DecodeInit(IRarUnpack unpackRead, int escChar)
        {
            int  maxOrder = unpackRead.Char & 0xff;
            bool reset    = ((maxOrder & 0x20) != 0);

            int maxMb = 0;

            if (reset)
            {
                maxMb = unpackRead.Char;
            }
            else
            {
                if (SubAlloc.GetAllocatedMemory() == 0)
                {
                    return(false);
                }
            }
            if ((maxOrder & 0x40) != 0)
            {
                escChar = unpackRead.Char;
                unpackRead.PpmEscChar = escChar;
            }
            Coder = new RangeCoder(unpackRead);
            if (reset)
            {
                maxOrder = (maxOrder & 0x1f) + 1;
                if (maxOrder > 16)
                {
                    maxOrder = 16 + (maxOrder - 16) * 3;
                }
                if (maxOrder == 1)
                {
                    SubAlloc.StopSubAllocator();
                    return(false);
                }
                SubAlloc.StartSubAllocator((maxMb + 1) << 20);
                _minContext = new PpmContext(Heap);

                //medContext = new PPMContext(Heap);
                _maxContext    = new PpmContext(Heap);
                FoundState     = new State(Heap);
                _dummySee2Cont = new See2Context();
                for (int i = 0; i < 25; i++)
                {
                    for (int j = 0; j < 16; j++)
                    {
                        _see2Cont[i][j] = new See2Context();
                    }
                }
                StartModelRare(maxOrder);
            }
            return(_minContext.Address != 0);
        }
コード例 #4
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);
            }
            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);
        }
コード例 #5
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);
        }