MCPcopy Create free account
hub / github.com/Tencent/libpag / writeUBits

Method writeUBits

src/codec/utils/EncodeStream.cpp:196–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196void EncodeStream::writeUBits(uint32_t value, uint8_t numBits) {
197 static const uint8_t bitMasks[9] = {0, 1, 3, 7, 15, 31, 63, 127, 255};
198 auto bytesToWrite = BitsToBytes(_bitPosition + numBits) - _position;
199 if (!checkCapacity(bytesToWrite)) {
200 return;
201 }
202 while (numBits > 0) {
203 auto bytePosition = static_cast<uint32_t>(_bitPosition / 8);
204 auto bitPosition = static_cast<uint32_t>(_bitPosition % 8);
205 auto& byte = bytes[bytePosition];
206 byte &= bitMasks[bitPosition];
207 auto bitLength = std::min(8 - bitPosition, static_cast<uint32_t>(numBits));
208 auto bits = static_cast<uint8_t>(value) & bitMasks[bitLength];
209 byte |= (bits << bitPosition);
210 value >>= bitLength;
211 numBits -= bitLength;
212 _bitPosition += bitLength;
213 }
214 bitPositionChanged(0);
215}
216
217uint8_t GetBitLength(uint32_t data) {
218 uint8_t length = 32;

Callers 3

WritePathInternalFunction · 0.80
WriteKeyframesFunction · 0.80
WriteDashesFunction · 0.80

Calls 1

BitsToBytesFunction · 0.70

Tested by

no test coverage detected