void VP8Shift() { // range_ is in [0..127] interval here. int idx = (int)((uint)this.range_ >> (BITS)); int shift = kVP8Log2Range[idx]; this.range_ = kVP8NewRange[idx]; this.value_ = (bit_t)((uint)this.value_ << shift); this.missing_ += shift; }
void VP8LoadNewBytes() { Global.assert(this.buf_ != null); // Read 'BITS' bits at a time if possible. if (this.buf_ + sizeof(lbit_t) <= this.buf_end_) { // convert memory type to register type (with some zero'ing!) bit_t bits; lbit_t in_bits = *(lbit_t*)this.buf_; this.buf_ += (BITS) >> 3; #if !BIG_ENDIAN bits = (bit_t)(in_bits >> 24) | ((in_bits >> 8) & 0xff00) | ((in_bits << 8) & 0xff0000) | (in_bits << 24); #else //#error Not Implemented throw(new NotImplementedException()); #endif this.value_ |= bits << this.missing_; this.missing_ -= (BITS); } else { this.VP8LoadFinalBytes(); // no need to be inlined } }
//------------------------------------------------------------------------------ // VP8BitReader // Initialize the bit reader and the boolean decoder. void VP8InitBitReader(byte* start, byte* end) { Global.assert(start != null); Global.assert((start <= end) != null); this.range_ = MK(255 - 1); this.buf_ = start; this.buf_end_ = end; this.value_ = 0; this.missing_ = 8; // to load the very first 8bits this.eof_ = 0; }
/// <summary> /// Special case for the tail /// </summary> void VP8LoadFinalBytes() { Global.assert(this.buf_ != null); // Only read 8bits at a time if (this.buf_ < this.buf_end_) { this.value_ |= (bit_t)(*this.buf_++) << ((BITS) - 8 + this.missing_); this.missing_ -= 8; } else { this.eof_ = 1; } }
bool VP8BitUpdate(bit_t split) { bit_t value_split = split | (MASK); if (this.missing_ > 0) { // Make sure we have a least BITS bits in 'value_' this.VP8LoadNewBytes(); } if (this.value_ > value_split) { this.range_ -= value_split + 1; this.value_ -= value_split + 1; return true; } else { this.range_ = value_split; return false; } }