示例#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);
            }