mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 16:47:28 +01:00
std/brotli: add an encoder for quality levels 0 and 1
Adds a brotli encoder (std/brotli's encoder struct, a base.io_transformer) whose output is byte-identical to libbrotlienc v1.2.1 for quality levels 0 and 1, mirroring encode.c's BrotliEncoderCompressStream(Fast), compress_fragment.c and compress_fragment_two_pass.c, plus the entropy coding and bit stream helpers they need. Every double operation goes through std/softfloat, following the C evaluation order exactly. Parameters are quirks (encode_quirks.wuffs) that mirror BrotliEncoderSetParameter, sanitized at the first transform_io call. Each transform_io resumption corresponds to one C call with available_in equal to the readable src length; a closed src is FINISH; request_flush! and request_emit_metadata! make the next resumption a FLUSH or EMIT_METADATA call. Qualities 2 to 11 return "#unsupported encoder quality" for now. Encoder tables are generated by script/print-brotli-tables.go -encoder. Tests: round trips through the Wuffs decoder over the corpus and synthetic inputs; with -mimic, byte-exact comparisons against libbrotlienc over quality × window × mode × input chunking × flush schedule × metadata × size hint. script/manual-test-brotli-encoder-parity.c runs the full grid: 86,268 configurations, zero mismatches. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011NoosQNe7DKWnqDCBeqw1p
This commit is contained in:
17 files changed
+13990
-2772
No files matched your search
@@ -5,6 +5,7 @@ particular file format or algorithm. Those packages can be grouped into several
|
||||
categories:
|
||||
|
||||
- [Compression Decoders](/doc/std/compression-decoders.md).
|
||||
- [Compression Encoders](/doc/std/compression-encoders.md).
|
||||
- [Hashers](/doc/std/hashers.md).
|
||||
- [Image Decoders](/doc/std/image-decoders.md).
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# Compression Encoders
|
||||
|
||||
Compression encoders read from one input stream (an `io_reader` called `src`)
|
||||
and write to an output stream (an `io_writer` called `dst`). Like
|
||||
[compression decoders](/doc/std/compression-decoders.md), they implement the
|
||||
`base.io_transformer` interface, whose key method is `transform_io`. It
|
||||
incrementally compresses the source data.
|
||||
|
||||
This method is a [coroutine](/doc/note/coroutines.md), and does not require
|
||||
either all of the input or all of the output to fit in a single contiguous
|
||||
buffer. It suspends with the `$short_read` status when it has consumed all of
|
||||
`src` (and `src` is not closed) and with `$short_write` when `dst` is full. It
|
||||
returns ok once `src` is closed and all of the compressed data has been
|
||||
written. Encoder parameters (e.g. the compression quality) are set with
|
||||
`set_quirk` before the first `transform_io` call.
|
||||
|
||||
|
||||
## API Listing
|
||||
|
||||
In Wuffs syntax, the `base.io_transformer` methods are:
|
||||
|
||||
- `dst_history_retain_length() u64`
|
||||
- `get_quirk(key: u32) u64`
|
||||
- `set_quirk!(key: u32, value: u64) status`
|
||||
- `transform_io?(dst: io_writer, src: io_reader, workbuf: slice u8)`
|
||||
- `workbuf_len() range_ii_u64`
|
||||
|
||||
Encoders may have further, format-specific methods. For example, the brotli
|
||||
encoder has `request_flush`, `request_emit_metadata` and
|
||||
`max_compressed_size`.
|
||||
|
||||
|
||||
## Implementations
|
||||
|
||||
- [std/brotli](/std/brotli/README.md#encoder) (qualities 0 and 1 only).
|
||||
Reference in new issue
Block a user