コード例 #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
ファイル: PPMContext.cs プロジェクト: zipgenius/sharpcompress
        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);
        }
コード例 #3
0
ファイル: ModelPPM.cs プロジェクト: RainsSoft/sharpcompress
 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);
 }
コード例 #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);
        }
コード例 #5
0
 private void InitBlock()
 {
     for (int i = 0; i < 25; i++)
     {
         SEE2Cont[i] = new SEE2Context[16];
     }
     for (int i2 = 0; i2 < 128; i2++)
     {
         binSumm[i2] = new int[64];
     }
 }
コード例 #6
0
ファイル: ModelPPM.cs プロジェクト: yaozd/sharpcompress
 private void InitBlock()
 {
     for (int i = 0; i < 25; i++)
     {
         SEE2Cont[i] = new SEE2Context[16];
     }
     for (int i2 = 0; i2 < 128; i2++)
     {
         binSumm[i2] = new int[64];
     }
 }
コード例 #7
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);
        }
コード例 #8
0
ファイル: ModelPPM.cs プロジェクト: RainsSoft/sharpcompress
        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);
        }
コード例 #9
0
ファイル: ModelPPM.cs プロジェクト: RainsSoft/sharpcompress
        public int decodeChar(SharpCompress.Compressor.LZMA.RangeCoder.Decoder decoder)
        {
            SharpCompress.Compressor.PPMd.H.State state;
            int  num;
            int  threshold;
            int  num3;
            byte symbol;

            if (this.minContext.NumStats != 1)
            {
                state         = this.tempState1.Initialize(this.Heap);
                state.Address = this.minContext.FreqData.GetStats();
                if ((threshold = (int)decoder.GetThreshold((uint)this.minContext.FreqData.SummFreq)) < (num3 = state.Freq))
                {
                    decoder.Decode(0, (uint)state.Freq);
                    symbol = (byte)state.Symbol;
                    this.minContext.update1_0(this, state.Address);
                    this.nextContext();
                    return(symbol);
                }
                this.prevSuccess = 0;
                num = this.minContext.NumStats - 1;
                do
                {
                    state.IncrementAddress();
                    if ((num3 += state.Freq) > threshold)
                    {
                        decoder.Decode((uint)(num3 - state.Freq), (uint)state.Freq);
                        symbol = (byte)state.Symbol;
                        this.minContext.update1(this, state.Address);
                        this.nextContext();
                        return(symbol);
                    }
                }while (--num > 0);
                if (threshold >= this.minContext.FreqData.SummFreq)
                {
                    return(-2);
                }
                this.hiBitsFlag = this.HB2Flag[this.foundState.Symbol];
                decoder.Decode((uint)num3, (uint)(this.minContext.FreqData.SummFreq - num3));
                for (num = 0; num < 0x100; num++)
                {
                    this.charMask[num] = -1;
                }
                this.charMask[state.Symbol] = 0;
                num = this.minContext.NumStats - 1;
                do
                {
                    state.DecrementAddress();
                    this.charMask[state.Symbol] = 0;
                }while (--num > 0);
            }
            else
            {
                SharpCompress.Compressor.PPMd.H.State rs = this.tempState1.Initialize(this.Heap);
                rs.Address      = this.minContext.getOneState().Address;
                this.hiBitsFlag = this.getHB2Flag()[this.foundState.Symbol];
                int index = rs.Freq - 1;
                int num6  = this.minContext.getArrayIndex(this, rs);
                int summ  = this.binSumm[index][num6];
                if (decoder.DecodeBit((uint)summ, 14) == 0)
                {
                    this.binSumm[index][num6] = ((summ + INTERVAL) - this.minContext.getMean(summ, 7, 2)) & 0xffff;
                    this.foundState.Address   = rs.Address;
                    symbol = (byte)rs.Symbol;
                    rs.IncrementFreq((rs.Freq < 0x80) ? 1 : 0);
                    this.prevSuccess = 1;
                    this.incRunLength(1);
                    this.nextContext();
                    return(symbol);
                }
                summ = (summ - this.minContext.getMean(summ, 7, 2)) & 0xffff;
                this.binSumm[index][num6] = summ;
                this.initEsc = PPMContext.ExpEscape[Utility.URShift(summ, 10)];
                for (num = 0; num < 0x100; num++)
                {
                    this.charMask[num] = -1;
                }
                this.charMask[rs.Symbol] = 0;
                this.prevSuccess         = 0;
            }
            while (true)
            {
                int num8;
                state = this.tempState1.Initialize(this.Heap);
                int numStats = this.minContext.NumStats;
                do
                {
                    this.orderFall++;
                    this.minContext.Address = this.minContext.getSuffix();
                    if ((this.minContext.Address <= this.subAlloc.PText) || (this.minContext.Address > this.subAlloc.HeapEnd))
                    {
                        return(-1);
                    }
                }while (this.minContext.NumStats == numStats);
                num3          = 0;
                state.Address = this.minContext.FreqData.GetStats();
                num           = 0;
                int num9 = this.minContext.NumStats - numStats;
                do
                {
                    int num11 = this.charMask[state.Symbol];
                    num3 += state.Freq & num11;
                    this.minContext.ps[num] = state.Address;
                    state.IncrementAddress();
                    num -= num11;
                }while (num != num9);
                SEE2Context context = this.minContext.makeEscFreq(this, numStats, out num8);
                num8     += num3;
                threshold = (int)decoder.GetThreshold((uint)num8);
                if (threshold < num3)
                {
                    SharpCompress.Compressor.PPMd.H.State state3 = this.tempState2.Initialize(this.Heap);
                    num3           = 0;
                    num            = 0;
                    state3.Address = this.minContext.ps[num];
                    while ((num3 += state3.Freq) <= threshold)
                    {
                        num++;
                        state3.Address = this.minContext.ps[num];
                    }
                    state.Address = state3.Address;
                    decoder.Decode((uint)(num3 - state.Freq), (uint)state.Freq);
                    context.update();
                    symbol = (byte)state.Symbol;
                    this.minContext.update2(this, state.Address);
                    this.updateModel();
                    return(symbol);
                }
                if (threshold >= num8)
                {
                    return(-2);
                }
                decoder.Decode((uint)num3, (uint)(num8 - num3));
                context.Summ += num8;
                do
                {
                    state.Address = this.minContext.ps[--num];
                    this.charMask[state.Symbol] = 0;
                }while (num != 0);
            }
        }
コード例 #10
0
ファイル: ModelPPM.cs プロジェクト: yaozd/sharpcompress
        // 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);
        }
コード例 #11
0
ファイル: ModelPPM.cs プロジェクト: yaozd/sharpcompress
        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);
        }
コード例 #12
0
ファイル: ModelPPM.cs プロジェクト: RainsSoft/sharpcompress
 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);
 }
コード例 #13
0
ファイル: ModelPPM.cs プロジェクト: RainsSoft/sharpcompress
 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);
 }