Example #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);
        }
Example #2
0
 internal bool decodeInit(Stream stream, int maxOrder, int maxMemory)
 {
     if (stream != null)
     {
         this.coder = new RangeCoder(stream);
     }
     if (maxOrder == 1)
     {
         this.subAlloc.stopSubAllocator();
         return(false);
     }
     this.subAlloc.startSubAllocator(maxMemory);
     this.minContext    = new PPMContext(this.Heap);
     this.maxContext    = new PPMContext(this.Heap);
     this.foundState    = new SharpCompress.Compressor.PPMd.H.State(this.Heap);
     this.dummySEE2Cont = new SEE2Context();
     for (int i = 0; i < 0x19; i++)
     {
         for (int j = 0; j < 0x10; j++)
         {
             this.SEE2Cont[i][j] = new SEE2Context();
         }
     }
     this.startModelRare(maxOrder);
     return(this.minContext.Address != 0);
 }
Example #3
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 #4
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 #5
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);
        }
Example #6
0
        internal bool decodeInit(Unpack unpackRead, int escChar)
        {
            int  maxOrder = unpackRead.Char & 0xff;
            bool flag     = (maxOrder & 0x20) != 0;
            int  num2     = 0;

            if (flag)
            {
                num2 = unpackRead.Char;
            }
            else if (this.subAlloc.GetAllocatedMemory() == 0)
            {
                return(false);
            }
            if ((maxOrder & 0x40) != 0)
            {
                escChar = unpackRead.Char;
                unpackRead.PpmEscChar = escChar;
            }
            this.coder = new RangeCoder(unpackRead);
            if (flag)
            {
                maxOrder = (maxOrder & 0x1f) + 1;
                if (maxOrder > 0x10)
                {
                    maxOrder = 0x10 + ((maxOrder - 0x10) * 3);
                }
                if (maxOrder == 1)
                {
                    this.subAlloc.stopSubAllocator();
                    return(false);
                }
                this.subAlloc.startSubAllocator((num2 + 1) << 20);
                this.minContext    = new PPMContext(this.Heap);
                this.maxContext    = new PPMContext(this.Heap);
                this.foundState    = new SharpCompress.Compressor.PPMd.H.State(this.Heap);
                this.dummySEE2Cont = new SEE2Context();
                for (int i = 0; i < 0x19; i++)
                {
                    for (int j = 0; j < 0x10; j++)
                    {
                        this.SEE2Cont[i][j] = new SEE2Context();
                    }
                }
                this.startModelRare(maxOrder);
            }
            return(this.minContext.Address != 0);
        }
Example #7
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 #8
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);
        }
Example #9
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);
        }
Example #10
0
 internal bool decodeInit(Stream stream, int maxOrder, int maxMemory)
 {
     if (stream != null)
     {
         this.coder = new RangeCoder(stream);
     }
     if (maxOrder == 1)
     {
         this.subAlloc.stopSubAllocator();
         return false;
     }
     this.subAlloc.startSubAllocator(maxMemory);
     this.minContext = new PPMContext(this.Heap);
     this.maxContext = new PPMContext(this.Heap);
     this.foundState = new SharpCompress.Compressor.PPMd.H.State(this.Heap);
     this.dummySEE2Cont = new SEE2Context();
     for (int i = 0; i < 0x19; i++)
     {
         for (int j = 0; j < 0x10; j++)
         {
             this.SEE2Cont[i][j] = new SEE2Context();
         }
     }
     this.startModelRare(maxOrder);
     return (this.minContext.Address != 0);
 }
Example #11
0
 internal bool decodeInit(Unpack unpackRead, int escChar)
 {
     int maxOrder = unpackRead.Char & 0xff;
     bool flag = (maxOrder & 0x20) != 0;
     int num2 = 0;
     if (flag)
     {
         num2 = unpackRead.Char;
     }
     else if (this.subAlloc.GetAllocatedMemory() == 0)
     {
         return false;
     }
     if ((maxOrder & 0x40) != 0)
     {
         escChar = unpackRead.Char;
         unpackRead.PpmEscChar = escChar;
     }
     this.coder = new RangeCoder(unpackRead);
     if (flag)
     {
         maxOrder = (maxOrder & 0x1f) + 1;
         if (maxOrder > 0x10)
         {
             maxOrder = 0x10 + ((maxOrder - 0x10) * 3);
         }
         if (maxOrder == 1)
         {
             this.subAlloc.stopSubAllocator();
             return false;
         }
         this.subAlloc.startSubAllocator((num2 + 1) << 20);
         this.minContext = new PPMContext(this.Heap);
         this.maxContext = new PPMContext(this.Heap);
         this.foundState = new SharpCompress.Compressor.PPMd.H.State(this.Heap);
         this.dummySEE2Cont = new SEE2Context();
         for (int i = 0; i < 0x19; i++)
         {
             for (int j = 0; j < 0x10; j++)
             {
                 this.SEE2Cont[i][j] = new SEE2Context();
             }
         }
         this.startModelRare(maxOrder);
     }
     return (this.minContext.Address != 0);
 }
Example #12
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);
        }