From ce4a89886625ee388d7ef75780e44f0ac9d9c359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 26 Sep 2026 14:09:27 +0300 Subject: [PATCH] ec-av1: correct the ref_chroma_shape doc's 4:2:0 claims Re-review found two false claims in the doc comment (and the matching report bullet): 1. "zero 4:2:0 shapes differ" was wrong as an argument. The floor arm is byte-identical to the parent -- that is the real and sufficient point -- but it does differ from the *true* 4:2:0 shape (the producer's `round_ss` ceil crops) on every odd dimension. Now stated as: the floor under-declares in 12160 of the 16256 grid pairs with w >= 2 (12288 of all 16384 including the w == 1 column), and at h == 1 -- the 127 pairs with w >= 2 -- it differs from the parent only by correcting it, since the parent claimed zero rows for a plane holding round_ss(w, 1) samples. 2. The w == 1 "the counts genuinely coincide, so no length test can separate them" claim was false: a 4:2:0 count at w == 1, h >= 2 collides with neither the 4:4:4 nor the 4:2:2 count (measured: zero collisions). The length test does route it into the 4:2:0 arm; the floor fallback simply cannot express `(1, round_ss(h, 1))`. Reworded as an open 4:2:0 odd-dimension gap: pre-existing, parent-identical, and not taken here because a ceil fallback would depart from the parent on every odd-dimension 4:2:0 shape with no in-tree coverage to justify it. No behaviour change. `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors. --- crates/ec-av1/src/decode.rs | 32 ++++++++++++++++++++++++-------- lanes/av1422stripwrite.report.md | 25 +++++++++++++++++++------ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 9cc5d2a0..1bade313 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -30419,14 +30419,30 @@ fn whole_plane(data: &[u16], width: usize, height: usize) -> PlaneBuf<'_> { /// **Ambiguity, measured rather than argued away:** the inference reads a /// format off a length, so it is only as good as the lengths being /// distinct. Brute-forced against the producer's own `round_ss` crops over -/// every `w, h` in `1..=128`, the three counts are distinct and routed -/// correctly for **every `w >= 2 && h >= 2`**, and every misread is -/// confined to `w == 1` or `h == 1` (a 1-row chroma plane reads as 4:2:2, -/// a 1-column one as 4:4:4 -- the counts genuinely coincide there, so no -/// length test can separate them). No stream this decoder accepts reaches -/// either; the pinned fixture's chroma is 128x144. The 4:2:0 arm is -/// deliberately left at the old `(w / 2, h / 2)`: over the same sweep, -/// **zero** 4:2:0 shapes differ from what the old two-way test produced. +/// every `w, h` in `1..=128`, the 4:4:4 and 4:2:2 counts are distinct from +/// each other and from the 4:2:0 count, and both route correctly for +/// **every `w >= 2 && h >= 2`**. No stream this decoder accepts reaches a +/// 1-pixel chroma plane; the pinned fixture's chroma is 128x144. +/// +/// **Open gap, 4:2:0 at odd dimensions (pre-existing).** The 4:2:0 arm is +/// left at the old `(width / 2, height / 2)` floor, which is byte-identical +/// to what the two-way test this replaces produced -- that was the point, +/// since no 4:2:0 stream changed shape. It is nevertheless the wrong shape +/// for an odd-dimension 4:2:0 reference: the producer stored +/// `round_ss(w, 1) x round_ss(h, 1)`, so the floor arm under-declares. +/// Measured over the `1..=128` square: the floor under-declares in +/// 12160 of the 16256 pairs with `w >= 2` (12288 of all 16384, the extra +/// 128 being the `w == 1` column, where the arm declares a 0-wide plane). +/// It is a *shape* error, not a misroute: a 4:2:0 count at `w == 1` and +/// `h >= 2` collides with neither the 4:4:4 nor the 4:2:2 count, so the +/// length test does put it in the right arm -- the floor fallback simply +/// cannot express `(1, round_ss(h, 1))`. It is left alone because it +/// predates this lane, is identical to the parent, and no in-tree coverage +/// exercises an odd-dimension 4:2:0 reference. A ceil fallback +/// (`(round_ss(w, 1), round_ss(h, 1))`) would close it, at the cost of +/// departing from the parent on every odd-dimension 4:2:0 shape with +/// nothing in the tree to justify the change; that call belongs to a lane +/// that can bring odd-dimension 4:2:0 fixtures with it. fn ref_chroma_shape(len: usize, width: usize, height: usize) -> (usize, usize) { let half_w = round_ss(width, 1); if len == width * height { diff --git a/lanes/av1422stripwrite.report.md b/lanes/av1422stripwrite.report.md index f713d864..308e82d9 100644 --- a/lanes/av1422stripwrite.report.md +++ b/lanes/av1422stripwrite.report.md @@ -142,12 +142,25 @@ REVERTED). verbatim — the only thing between them is the inserted 4:2:2 test, which can only fire on a count a 4:2:0 or 4:4:4 plane does not have. *Brute-forced:* against the producer's own `round_ss` crops - (`decode.rs:25806`) over every `w, h` in `1..=128`, all three formats - route correctly for **every `w >= 2 && h >= 2`**, every misread is - confined to `w == 1` or `h == 1` (where the counts genuinely coincide, - so no length test can separate them — not reachable by a decodable - frame), and **zero** 4:2:0 shapes differ from what the old two-way test - produced. + (`decode.rs:25806`) over every `w, h` in `1..=128`, the 4:4:4 and 4:2:2 + counts are distinct from each other and from the 4:2:0 count and both + route correctly for **every `w >= 2 && h >= 2`**; nothing a decodable + frame produces falls outside that (the pinned fixture's chroma is + 128x144). + *4:2:0 at odd dimensions — an open, pre-existing gap, not a clean bill.* + The floor arm is byte-identical to the parent, but it is the wrong shape + for an odd-dimension 4:2:0 reference: the producer stored + `round_ss(w, 1) x round_ss(h, 1)`, so the floor under-declares. Over the + `1..=128` square that is 12160 of the 16256 pairs with `w >= 2` (12288 of + all 16384; the extra 128 are the `w == 1` column, where the arm declares + a 0-wide plane), and it differs from the parent's floor at `h == 1` for + the 127 pairs with `w >= 2` — there only by *correcting* the parent, + which claimed zero rows. At `w == 1` and `h >= 2` the 4:2:0 count + collides with neither other count, so the length test puts it in the + right arm; the floor fallback simply cannot express + `(1, round_ss(h, 1))`. A ceil fallback would close the whole gap, at + the cost of departing from the parent on every odd-dimension 4:2:0 + shape with no in-tree coverage to justify it. Recorded, not taken. *Gated:* `cargo test -p ec-av1 --lib -- lossless decodes_sample_exact 444 reference_chroma` in its own target dir `~/.cache/cargo-target-av1422stripwrite-gate` — see below for what that