class

CrImage::WEBP::BitWriter

Inherits Reference / Object

BitWriter provides low-level utility for writing variable-length bit sequences to a byte stream in little-endian order. It accumulates bits in a buffer and flushes complete bytes to the output.

This is used for writing VP8L bitstreams and Huffman-encoded data.

Constructors

Instance methods

align_byte

Align to byte boundary by padding with zeros. Rounds up to next multiple of 8 bits.

Source
to_slice

Get the accumulated bytes as a Bytes slice Note: This does NOT align to byte boundary automatically Call align_byte explicitly if needed before calling this

Source
write_bits(value : UInt64, n : Number) : Nil

Write n bits from value in little-endian order. n must be between 0 and 64. value must fit within n bits.

Source
write_bytes(bytes : Bytes) : Nil

Write a byte array directly to the buffer. Each byte is written as 8 bits.

Source
write_code(code : HuffmanCode) : Nil

Write a Huffman code with bit reversal. WebP uses reversed Huffman codes, so we reverse the bits before writing.

Source