Пример #1
0
        public uint Decode(RangeDecoder rangeDecoder)
        {
            uint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)_prob;

            if (rangeDecoder.Code < newBound)
            {
                rangeDecoder.Range = newBound;
                _prob += (kBitModelTotal - _prob) >> kNumMoveBits;
                if (rangeDecoder.Range < RangeDecoder.kTopValue)
                {
                    rangeDecoder.Code    = (rangeDecoder.Code << 8) | (byte)rangeDecoder._inStream.ReadByte();
                    rangeDecoder.Range <<= 8;
                }
                return(0);
            }
            else
            {
                rangeDecoder.Range -= newBound;
                rangeDecoder.Code  -= newBound;
                _prob -= (_prob) >> kNumMoveBits;
                if (rangeDecoder.Range < RangeDecoder.kTopValue)
                {
                    rangeDecoder.Code    = (rangeDecoder.Code << 8) | (byte)rangeDecoder._inStream.ReadByte();
                    rangeDecoder.Range <<= 8;
                }
                return(1);
            }
        }
        public uint Decode(RangeDecoder rangeDecoder)
        {
            uint m = 1;

            for (int bitIndex = _numBitLevels; bitIndex > 0; bitIndex--)
            {
                m = (m << 1) + _models[m].Decode(rangeDecoder);
            }
            return(m - ((uint)1 << _numBitLevels));
        }
        public uint ReverseDecode(RangeDecoder rangeDecoder)
        {
            uint m      = 1;
            uint symbol = 0;

            for (int bitIndex = 0; bitIndex < _numBitLevels; bitIndex++)
            {
                uint bit = _models[m].Decode(rangeDecoder);
                m     <<= 1;
                m      += bit;
                symbol |= (bit << bitIndex);
            }
            return(symbol);
        }
        public static uint ReverseDecode(RangeBitDecoder[] Models, UInt32 startIndex,
                                         RangeDecoder rangeDecoder, int NumBitLevels)
        {
            uint m      = 1;
            uint symbol = 0;

            for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
            {
                uint bit = Models[startIndex + m].Decode(rangeDecoder);
                m     <<= 1;
                m      += bit;
                symbol |= (bit << bitIndex);
            }
            return(symbol);
        }