std/vp8: parse the first partition

This commit, part of a series, is inspired by pull request PR #168 by
Damian Kaczmarek (with AI assistance), with some modifications. There
were many stylistic changes but also:

- decoder.workbuf_len was fixed to account for all of the partitions,
  not just the first two (the first partition and the first 'other'
  partition). The PR's vp8 code, after an update to handle multiple
  other partitions (which then implied random access to the partitioned
  source bytes), assumed that enough workbuf was available (which it
  often is, test/c/std/webp.c tests pass the entire g_work_slice_u8).
  But strictly speaking, this isn't guaranteed unless workbuf_len
  reports (after decode_image_config is called) what's needed.
- Calculating that workbuf_len (at decode_image_config time) lead to
  introducing a new base.QUIRK_SOURCE_LENGTH quirk, to pass that
  contextual information from std/webp to std/vp8. This calculation
  belongs in std/vp8, not std/webp (or a future std/webm).
- Added support (and a test) for the case when the source bytes are
  streamed and some (but not yet all) of the partition data in args.src
  can be copied to args.workbuf.

Updates PR #168
This commit is contained in:
Nigel Tao committed 2026-05-29 14:36:04 +10:00
1 parent e45d0b9091
commit b51fcb811a
8 files changed
+1911 -8

No files matched your search

+10 -1
View File
@@ -27,7 +27,9 @@ pri status "#internal error: inconsistent Huffman code"
pri status "#internal error: inconsistent dst buffer"
pri status "#internal error: inconsistent n_bits"
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0
// TODO: reference vp8.DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE, although the
// worst case for VP8L is bigger than for VP8.
pub const DECODER_WORKBUF_LEN_MAX_INCL_WORST_CASE : base.u64 = 0x4C00_0000
pub struct decoder? implements base.image_decoder(
pixfmt : base.u32,
@@ -239,6 +241,13 @@ pri func decoder.do_decode_image_config_limited?(dst: nptr base.image_config, sr
}
this.sub_chunk_has_padding = (this.sub_chunk_length & 1) <> 0
if this.is_vp8_lossy {
this.vp8.set_quirk!(
key: base.QUIRK_SOURCE_LENGTH,
value: ((this.sub_chunk_length as base.u64) << 1) | 1)
}
while true {
io_limit (io: args.src, limit: this.sub_chunk_length as base.u64) {
r_mark = args.src.mark()