Differential D9642 Diff 31357 extern/draco/draco/src/draco/compression/bit_coders/rans_bit_encoder.cc
Changeset View
Changeset View
Standalone View
Standalone View
extern/draco/draco/src/draco/compression/bit_coders/rans_bit_encoder.cc
- This file was moved from extern/draco/dracoenc/src/draco/compression/bit_coders/rans_bit_encoder.cc.
| Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | if (nbits <= remaining) { | ||||
| local_bits_ = 0; | local_bits_ = 0; | ||||
| CopyBits32(&local_bits_, 0, reversed, remaining, nbits - remaining); | CopyBits32(&local_bits_, 0, reversed, remaining, nbits - remaining); | ||||
| num_local_bits_ = nbits - remaining; | num_local_bits_ = nbits - remaining; | ||||
| } | } | ||||
| } | } | ||||
| void RAnsBitEncoder::EndEncoding(EncoderBuffer *target_buffer) { | void RAnsBitEncoder::EndEncoding(EncoderBuffer *target_buffer) { | ||||
| uint64_t total = bit_counts_[1] + bit_counts_[0]; | uint64_t total = bit_counts_[1] + bit_counts_[0]; | ||||
| if (total == 0) | if (total == 0) { | ||||
| total++; | total++; | ||||
| } | |||||
| // The probability interval [0,1] is mapped to values of [0, 256]. However, | // The probability interval [0,1] is mapped to values of [0, 256]. However, | ||||
| // the coding scheme can not deal with probabilities of 0 or 1, which is why | // the coding scheme can not deal with probabilities of 0 or 1, which is why | ||||
| // we must clamp the values to interval [1, 255]. Specifically 128 | // we must clamp the values to interval [1, 255]. Specifically 128 | ||||
| // corresponds to 0.5 exactly. And the value can be given as uint8_t. | // corresponds to 0.5 exactly. And the value can be given as uint8_t. | ||||
| const uint32_t zero_prob_raw = static_cast<uint32_t>( | const uint32_t zero_prob_raw = static_cast<uint32_t>( | ||||
| ((bit_counts_[0] / static_cast<double>(total)) * 256.0) + 0.5); | ((bit_counts_[0] / static_cast<double>(total)) * 256.0) + 0.5); | ||||
| uint8_t zero_prob = 255; | uint8_t zero_prob = 255; | ||||
| if (zero_prob_raw < 255) | if (zero_prob_raw < 255) { | ||||
| zero_prob = static_cast<uint8_t>(zero_prob_raw); | zero_prob = static_cast<uint8_t>(zero_prob_raw); | ||||
| } | |||||
| zero_prob += (zero_prob == 0); | zero_prob += (zero_prob == 0); | ||||
| // Space for 32 bit integer and some extra space. | // Space for 32 bit integer and some extra space. | ||||
| std::vector<uint8_t> buffer((bits_.size() + 8) * 8); | std::vector<uint8_t> buffer((bits_.size() + 8) * 8); | ||||
| AnsCoder ans_coder; | AnsCoder ans_coder; | ||||
| ans_write_init(&ans_coder, buffer.data()); | ans_write_init(&ans_coder, buffer.data()); | ||||
| Show All 28 Lines | |||||