Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 private PPMContext getTempPPMContext(byte[] Memory)
 {
     if (tempPPMContext == null)
     {
         tempPPMContext = new PPMContext(null);
     }
     return(tempPPMContext.Initialize(Memory));
 }
Ejemplo n.º 5
0
        public ModelPPM()
        {
            InitBlock();
            minContext = null;
            maxContext = null;

            //medContext = null;
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
 internal void setSuffix(PPMContext suffix)
 {
     setSuffix(suffix.Address);
 }
Ejemplo n.º 10
0
        private void updateModel()
        {
            //System.out.println("ModelPPM.updateModel()");
            // STATE fs = *FoundState, *p = NULL;
            StateRef fs = tempStateRef1;

            fs.Values = FoundState;
            State p         = tempState3.Initialize(Heap);
            State tempState = tempState4.Initialize(Heap);

            PPMContext pc        = tempPPMContext3.Initialize(Heap);
            PPMContext successor = tempPPMContext4.Initialize(Heap);

            int ns1, ns, cf, sf, s0;

            pc.Address = minContext.getSuffix();
            if (fs.Freq < MAX_FREQ / 4 && pc.Address != 0)
            {
                if (pc.NumStats != 1)
                {
                    p.Address = pc.FreqData.GetStats();
                    if (p.Symbol != fs.Symbol)
                    {
                        do
                        {
                            p.IncrementAddress();
                        }while (p.Symbol != fs.Symbol);
                        tempState.Address = p.Address - State.Size;
                        if (p.Freq >= tempState.Freq)
                        {
                            State.PPMDSwap(p, tempState);
                            p.DecrementAddress();
                        }
                    }
                    if (p.Freq < MAX_FREQ - 9)
                    {
                        p.IncrementFreq(2);
                        pc.FreqData.IncrementSummFreq(2);
                    }
                }
                else
                {
                    p.Address = pc.getOneState().Address;
                    if (p.Freq < 32)
                    {
                        p.IncrementFreq(1);
                    }
                }
            }
            if (orderFall == 0)
            {
                FoundState.SetSuccessor(createSuccessors(true, p));
                minContext.Address = FoundState.GetSuccessor();
                maxContext.Address = FoundState.GetSuccessor();
                if (minContext.Address == 0)
                {
                    updateModelRestart();
                    return;
                }
                return;
            }
            SubAlloc.Heap[SubAlloc.PText] = (byte)fs.Symbol;
            SubAlloc.incPText();
            successor.Address = SubAlloc.PText;
            if (SubAlloc.PText >= SubAlloc.FakeUnitsStart)
            {
                updateModelRestart();
                return;
            }

            //        // Debug
            //        subAlloc.dumpHeap();
            if (fs.GetSuccessor() != 0)
            {
                if (fs.GetSuccessor() <= SubAlloc.PText)
                {
                    fs.SetSuccessor(createSuccessors(false, p));
                    if (fs.GetSuccessor() == 0)
                    {
                        updateModelRestart();
                        return;
                    }
                }
                if (--orderFall == 0)
                {
                    successor.Address = fs.GetSuccessor();
                    if (maxContext.Address != minContext.Address)
                    {
                        SubAlloc.decPText(1);
                    }
                }
            }
            else
            {
                FoundState.SetSuccessor(successor.Address);
                fs.SetSuccessor(minContext);
            }

            //        // Debug
            //        subAlloc.dumpHeap();
            ns = minContext.NumStats;
            s0 = minContext.FreqData.SummFreq - (ns) - (fs.Freq - 1);
            for (pc.Address = maxContext.Address; pc.Address != minContext.Address; pc.Address = pc.getSuffix())
            {
                if ((ns1 = pc.NumStats) != 1)
                {
                    if ((ns1 & 1) == 0)
                    {
                        //System.out.println(ns1);
                        pc.FreqData.SetStats(SubAlloc.expandUnits(pc.FreqData.GetStats(), Utility.URShift(ns1, 1)));
                        if (pc.FreqData.GetStats() == 0)
                        {
                            updateModelRestart();
                            return;
                        }
                    }

                    // bug fixed
                    //				int sum = ((2 * ns1 < ns) ? 1 : 0) +
                    //                        2 * ((4 * ((ns1 <= ns) ? 1 : 0)) & ((pc.getFreqData()
                    //								.getSummFreq() <= 8 * ns1) ? 1 : 0));
                    int sum = ((2 * ns1 < ns) ? 1 : 0) +
                              2 * (((4 * ns1 <= ns) ? 1 : 0) & ((pc.FreqData.SummFreq <= 8 * ns1) ? 1 : 0));
                    pc.FreqData.IncrementSummFreq(sum);
                }
                else
                {
                    p.Address = SubAlloc.allocUnits(1);
                    if (p.Address == 0)
                    {
                        updateModelRestart();
                        return;
                    }
                    p.SetValues(pc.getOneState());
                    pc.FreqData.SetStats(p);
                    if (p.Freq < MAX_FREQ / 4 - 1)
                    {
                        p.IncrementFreq(p.Freq);
                    }
                    else
                    {
                        p.Freq = MAX_FREQ - 4;
                    }
                    pc.FreqData.SummFreq = (p.Freq + initEsc + (ns > 3 ? 1 : 0));
                }
                cf = 2 * fs.Freq * (pc.FreqData.SummFreq + 6);
                sf = s0 + pc.FreqData.SummFreq;
                if (cf < 6 * sf)
                {
                    cf = 1 + (cf > sf ? 1 : 0) + (cf >= 4 * sf ? 1 : 0);
                    pc.FreqData.IncrementSummFreq(3);
                }
                else
                {
                    cf = 4 + (cf >= 9 * sf ? 1 : 0) + (cf >= 12 * sf ? 1 : 0) + (cf >= 15 * sf ? 1 : 0);
                    pc.FreqData.IncrementSummFreq(cf);
                }
                p.Address = pc.FreqData.GetStats() + ns1 * State.Size;
                p.SetSuccessor(successor);
                p.Symbol    = fs.Symbol;
                p.Freq      = cf;
                pc.NumStats = ++ns1;
            }

            int address = fs.GetSuccessor();

            maxContext.Address = address;
            minContext.Address = address;

            //TODO-----debug
            //		int pos = minContext.getFreqData().getStats();
            //		State a = new State(getHeap());
            //		a.Address=pos);
            //		pos+=State.size;
            //		a.Address=pos);
            //--dbg end
        }
Ejemplo n.º 11
0
        private int createSuccessors(bool Skip, State p1)
        {
            //State upState = tempState1.Initialize(null);
            StateRef upState   = tempStateRef2;
            State    tempState = tempState1.Initialize(Heap);

            // PPM_CONTEXT* pc=MinContext, * UpBranch=FoundState->Successor;
            PPMContext pc = tempPPMContext1.Initialize(Heap);

            pc.Address = minContext.Address;
            PPMContext upBranch = tempPPMContext2.Initialize(Heap);

            upBranch.Address = FoundState.GetSuccessor();

            // STATE * p, * ps[MAX_O], ** pps=ps;
            State p   = tempState2.Initialize(Heap);
            int   pps = 0;

            bool noLoop = false;

            if (!Skip)
            {
                ps[pps++] = FoundState.Address; // *pps++ = FoundState;
                if (pc.getSuffix() == 0)
                {
                    noLoop = true;
                }
            }
            if (!noLoop)
            {
                bool loopEntry = false;
                if (p1.Address != 0)
                {
                    p.Address  = p1.Address;
                    pc.Address = pc.getSuffix(); // =pc->Suffix;
                    loopEntry  = true;
                }
                do
                {
                    if (!loopEntry)
                    {
                        pc.Address = pc.getSuffix(); // pc=pc->Suffix;
                        if (pc.NumStats != 1)
                        {
                            p.Address = pc.FreqData.GetStats(); // p=pc->U.Stats
                            if (p.Symbol != FoundState.Symbol)
                            {
                                do
                                {
                                    p.IncrementAddress();
                                }while (p.Symbol != FoundState.Symbol);
                            }
                        }
                        else
                        {
                            p.Address = pc.getOneState().Address; // p=&(pc->OneState);
                        }
                    } // LOOP_ENTRY:
                    loopEntry = false;
                    if (p.GetSuccessor() != upBranch.Address)
                    {
                        pc.Address = p.GetSuccessor(); // =p->Successor;
                        break;
                    }
                    ps[pps++] = p.Address;
                }while (pc.getSuffix() != 0);
            } // NO_LOOP:
            if (pps == 0)
            {
                return(pc.Address);
            }
            upState.Symbol = Heap[upBranch.Address]; // UpState.Symbol=*(byte*)

            // UpBranch;
            // UpState.Successor=(PPM_CONTEXT*) (((byte*) UpBranch)+1);
            upState.SetSuccessor(upBranch.Address + 1); //TODO check if +1 necessary
            if (pc.NumStats != 1)
            {
                if (pc.Address <= SubAlloc.PText)
                {
                    return(0);
                }
                p.Address = pc.FreqData.GetStats();
                if (p.Symbol != upState.Symbol)
                {
                    do
                    {
                        p.IncrementAddress();
                    }while (p.Symbol != upState.Symbol);
                }
                int cf = p.Freq - 1;
                int s0 = pc.FreqData.SummFreq - pc.NumStats - cf;

                // UpState.Freq=1+((2*cf <= s0)?(5*cf > s0):((2*cf+3*s0-1)/(2*s0)));
                upState.Freq = 1 + ((2 * cf <= s0) ? (5 * cf > s0 ? 1 : 0) : ((2 * cf + 3 * s0 - 1) / (2 * s0)));
            }
            else
            {
                upState.Freq = pc.getOneState().Freq; // UpState.Freq=pc->OneState.Freq;
            }
            do
            {
                // pc = pc->createChild(this,*--pps,UpState);
                tempState.Address = ps[--pps];
                pc.Address        = pc.createChild(this, tempState, upState);
                if (pc.Address == 0)
                {
                    return(0);
                }
            }while (pps != 0);
            return(pc.Address);
        }
Ejemplo n.º 12
0
 public virtual void SetSuccessor(PPMContext successor)
 {
     SetSuccessor(successor.Address);
 }
Ejemplo n.º 13
0
 internal void SetSuccessor(PPMContext successor)
 {
     SetSuccessor(successor.Address);
 }