![]() |
tinyimg 1.0.0
Lightweight image manipulation library for Cloudflare Workers
|
Reads a bitstream out of a byte buffer. More...
#include <util.h>
Public Attributes | |
| const uint8_t * | data |
| size_t | size |
| size_t | pos |
| uint32_t | accumulator |
| uint32_t | count |
| uint32_t | phantom |
| How many of those bits came from past the end of the buffer. | |
| int | overrun |
Reads a bitstream out of a byte buffer.
A stream is either most significant bit first (JPEG) or least significant bit first (DEFLATE, LZW, VP8L). One reader serves both, but a single stream must be read with one family of calls throughout; mixing them mid stream reads the accumulator in the wrong order.
Reading past the end yields zero bits and latches overrun, so a truncated file is detected once at the end of a scan rather than checked per symbol.
overrun means a read consumed bits that are not in the buffer, not merely that the accumulator refilled past the end. The two are different: the accumulator pulls whole bytes ahead of need, so decoding the last symbol of a stream that ends on a byte boundary refills past the end while every bit it uses is real. Latching on the refill instead reports a valid stream as truncated, which is what a bare DEFLATE stream with no trailer after it does.
| uint32_t TinyBitReader::accumulator |
Bits pulled but not yet consumed, an implementation detail.
| uint32_t TinyBitReader::count |
How many bits the accumulator holds, an implementation detail.
| const uint8_t* TinyBitReader::data |
The bytes being read.
| int TinyBitReader::overrun |
Set once a read has consumed bits that are not in the buffer.
| uint32_t TinyBitReader::phantom |
How many of those bits came from past the end of the buffer.
Always the newest bits, which both orders keep at the end reads reach last, so one comparison serves both. An implementation detail.
| size_t TinyBitReader::pos |
Next byte to pull into the accumulator.
| size_t TinyBitReader::size |
How many bytes there are.