예제 #1
0
            public int DecodeBit(short[] probs, int index)
            {
                short prob;
                int   newBound;

                prob     = probs[index];
                newBound = (Range >> kNumBitModelTotalBits) * prob;
                if ((Code ^ unchecked ((int)0x80000000)) < (newBound ^ unchecked ((int)0x80000000)))
                {
                    Range        = newBound;
                    probs[index] = (short)(prob + ((kBitModelTotal - prob) >> kNumMoveBits));
                    if ((Range & kTopMask) == 0)
                    {
                        Code  = (Code << 8) | ULZMACommon.ReadByte(Stream);
                        Range = Range << 8;
                    }
                    return(0);
                }
                else
                {
                    Range        = Range - newBound;
                    Code         = Code - newBound;
                    probs[index] = (short)(prob - ((prob) >> kNumMoveBits));
                    if ((Range & kTopMask) == 0)
                    {
                        Code  = (Code << 8) | ULZMACommon.ReadByte(Stream);
                        Range = Range << 8;
                    }
                    return(1);
                }
            }
예제 #2
0
            public void Init()
            {
                int i;

                Code  = 0;
                Range = -1;
                for (i = 0; i < 5; i++)
                {
                    Code = (Code << 8) | ULZMACommon.ReadByte(Stream);
                }
            }
예제 #3
0
            public int DecodeDirectBits(int numTotalBits)
            {
                int i, t;
                int result = 0;

                for (i = numTotalBits; i >= 1; i--)
                {
                    Range  = Range >> 1;
                    t      = ((Code - Range) >> 31);
                    Code   = Code - Range & (t - 1);
                    result = (result << 1) | (1 - t);
                    if ((Range & kTopMask) == 0)
                    {
                        Code  = (Code << 8) | ULZMACommon.ReadByte(Stream);
                        Range = Range << 8;
                    }
                }
                return(result);
            }
예제 #4
0
            public void ShiftLow()
            {
                int LowHi;
                int temp;

                LowHi = (int)(Low >> 32);
                if (LowHi != 0 || Low < (Int64)0xFF000000)
                {
                    Position = Position + cacheSize;
                    temp     = cache;
                    do
                    {
                        ULZMACommon.WriteByte(Stream, (byte)(temp + LowHi));
                        temp = 0xFF;
                        cacheSize--;
                    } while (cacheSize != 0);
                    cache = (int)(Low >> 24);
                }
                cacheSize++;
                Low = (Low & (int)0xFFFFFF) << 8;
            }