From ab0445ec6691e8c5890cbb82b771aff836637c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 29 Aug 2026 00:54:30 +0300 Subject: [PATCH] fix(av1): motion_mode/obmc CDFs gain BLOCK_16X32/32X16 rows; rect strips index their own bsize row rect-flake-1 strip 1's motion_mode read diverged on the square-class row; with the true rows the whole HORZ block is entropy-exact (range ladder exact everywhere) -- residual pixel diff is prediction-side (warp). --- crates/ec-av1/src/cdf.rs | 12 ++++++++++-- crates/ec-av1/src/cdf_state.rs | 4 ++-- crates/ec-av1/src/decode.rs | 14 ++++++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index 729a7f52..a022a274 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -1211,11 +1211,16 @@ pub const SKIP_MODE: [[u16; 3]; 3] = [[32621, 32768, 0], [20708, 32768, 0], [812 /// `motion_mode_allowed` (spec 5.11.24's `read_motion_mode`) offers /// `OBMC_CAUSAL` rather than `WARPED_CAUSAL` -- lane-motionmode round 1 /// never reaches the three-way `motion_mode_cdf`, see `decode.rs`. -pub const OBMC: [[u16; 3]; 4] = [ +pub const OBMC: [[u16; 3]; 6] = [ [10437, 32768, 0], [17432, 32768, 0], [25817, 32768, 0], [30128, 32768, 0], + // lane-rect r2: BLOCK_16X32 (index 7) and BLOCK_32X16 (index 8) rows -- + // rect strips read their own bsize row, not the square class + // (rect-flake-1: the strip's motion_mode read diverged on this). + [14423, 32768, 0], + [15142, 32768, 0], ]; /// `default_motion_mode_cdf` (spec 9.4, `entropymode.c`), the square-bsize @@ -1225,11 +1230,14 @@ pub const OBMC: [[u16; 3]; 4] = [ /// `read_motion_mode` reads instead of [`OBMC`] whenever `motion_mode_allowed` /// (spec 5.11.24) resolves to `WARPED_CAUSAL`-eligible (`num_proj_ref >= 1` /// under `allow_warped_motion`) -- lane-warp round 1. -pub const MOTION_MODE: [[u16; 4]; 4] = [ +pub const MOTION_MODE: [[u16; 4]; 6] = [ [7651, 24760, 32768, 0], [19419, 26810, 32768, 0], [26260, 29116, 32768, 0], [29516, 30701, 32768, 0], + // lane-rect r2: BLOCK_16X32 / BLOCK_32X16 rows (indices 7/8). + [5123, 23606, 32768, 0], + [11606, 24308, 32768, 0], ]; /// `default_interintra_cdf` (spec 9.4): `interintra`, indexed by diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 75d54fec..a28cbda7 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -326,13 +326,13 @@ pub(crate) struct Cdfs { /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- /// this decoder only ever codes those four square sizes). - pub obmc: [[u16; 3]; 4], + pub obmc: [[u16; 3]; 6], /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. /// lane-warp round 1. - pub motion_mode: [[u16; 4]; 4], + pub motion_mode: [[u16; 4]; 6], /// `interintra`, indexed by `size_group_lookup[bsize]` -- see /// `cdf::INTERINTRA`'s own doc. pub interintra: [[u16; 3]; 4], diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 8ae63656..18665d47 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -6080,8 +6080,18 @@ fn decode_inter_block( // wmtype check here. let mut warped_selected = false; if motion_mode_eligible { - // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3. - let bsize_idx = (side.trailing_zeros() - 3) as usize; + // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> + // 0/1/2/3; lane-rect r2: a rect strip reads its OWN bsize row + // (libaom `motion_mode_cdf[mbmi->bsize]`: BLOCK_16X32 -> 4, + // BLOCK_32X16 -> 5 in our packed table) -- rect-flake-1's + // strip motion_mode read diverged on the square row. + let bsize_idx = if write_w == write_h { + (write_w.trailing_zeros() - 3) as usize + } else if write_w == 16 { + 4 + } else { + 5 + }; // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf` // instead of the 2-symbol `obmc_cdf` exactly when // `num_proj_ref >= 1` under `allow_warped_motion`.