From b91e4ecf7a2ec70e9d36330272eccbe02cad3cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 27 Aug 2026 05:29:11 +0300 Subject: [PATCH] fix(av1): correct the r4 chroma-granularity assumption for 8x8 leaves libaom's is_chroma_reference (av1_common_int.h) is unconditionally true for bsize >= BLOCK_8X8 (4:2:0 or not), so a split 16x16's 8x8 children each code their own chroma at 4x4 -- chroma does not stay at the parent's 8x8 granularity as the r4 doc comments claimed (never checked against a real decoder). Corrects TxbSet::Chroma4's doc and flips code_square's still-unreached side==8 branch to the chroma set a real caller will need, so the next lane does not inherit a wrong premise. No behavior change (134/0/9, unchanged): the branch has no caller yet. --- crates/ec-av1/src/cdf_state.rs | 13 +++++++++---- crates/ec-av1/src/encode.rs | 13 ++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index d598a1a0..a299ba68 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -42,10 +42,15 @@ pub(crate) enum TxbSet { Luma8, /// The 8x8 transform of a chroma plane of a 16x16 block. Chroma8, - /// The 4x4 transform of a chroma plane of an 8x8 leaf (lane-av1-rect): - /// per `get_tx_size` for chroma, this stays 8x8 at the *parent* 16x16's - /// granularity today (see `Chroma8`), so this variant is currently unused - /// but shipped for when a chroma-follows-luma split is wired. + /// The 4x4 transform of a chroma plane of an 8x8 leaf (lane-av1-rect). + /// r5 correction: libaom's `is_chroma_reference` (`av1_common_int.h`) is + /// unconditionally true for `bsize >= BLOCK_8X8`, so chroma *does* follow + /// luma all the way down to 8x8 — it is coded once per 8x8 leaf, not once + /// per parent 16x16 (that "stays at the parent's Chroma8 granularity" + /// framing this doc carried through r4 was never checked against a real + /// decoder and is wrong; only `BLOCK_4X4`/`4X8`/`8X4`, one mi-unit wide or + /// high, get the "last sub-block only" chroma-merge treatment). A real + /// writer for the straddling-16x16 case must use this variant per leaf. Chroma4, /// The 16x16 transform of a chroma plane of a 32x32 block. Chroma16, diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 34f7c8b8..072a9c63 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1058,11 +1058,14 @@ fn code_square( let (luma_set, chroma_set) = if side == BLOCK { (TxbSet::Luma32, TxbSet::Chroma16) } else if side == 8 { - // An 8x8 leaf under a straddling 16x16 (lane-av1-rect): chroma of an - // 8x8 luma leaf still codes at its parent 16x16's granularity (see - // `TxbSet::Chroma4`'s doc comment), so the chroma set stays Chroma8 - // even though luma has split down to 8x8. - (TxbSet::Luma8, TxbSet::Chroma8) + // An 8x8 leaf under a straddling 16x16 (lane-av1-rect). r5 correction: + // `TxbSet::Chroma4`'s doc now has the checked spec fact -- chroma is + // `is_chroma_reference` at every BLOCK_8X8, so it is coded per leaf at + // 4x4, not once at the parent's 8x8. No caller passes `side == 8` yet + // (this branch is still unreached), so leaving `Chroma8` here would + // silently wire the wrong table the moment one does; `Chroma4` is + // what a real caller needs. + (TxbSet::Luma8, TxbSet::Chroma4) } else { (TxbSet::Luma16, TxbSet::Chroma8) };