forge
Explore
Log in

Don't you dare go Hollow

ec-av1: 4:4:4 luma byte-exact, chroma WIP (lane-av1-444)

Browse files at this commit

d6b7cc75bf1a2565bc3fe06442e70f467362c1dcAhmet Kaan GümüşParent: 1419a79
Sequence header refuses only 4:2:2 now (ss_x != ss_y); 4:4:4 and 4:2:0
proceed. Chroma plane size, tx size, CFL window, loop-filter chroma step
and the 8x8 leaf's chroma unit follow ss_x/ss_y; an 8x8 leaf at 4:4:4
reads 8x8 chroma. Restoration chroma unit size follows ss_x.

Square profile-1 recipe: luma IDENTICAL vs aomdec+ffmpeg both frames
(0/16384 diffs); chroma 37389/98304 diffs, first at U (112,0) inside the
64x64 block at (64,0) which takes the single-TU arm but codes four
TX_32X32 chroma units at 4:4:4 (av1_get_max_uv_txsize). 420 square arm
still IDENTICAL. 4:2:2 stays a named refusal. Full suite not run.
crates/ec-av1/src/decode.rsmodified+535 -369
@@ -102,6 +102,9 @@ pub(crate) struct FrameCtx {
102102 /// (like [`FrameCtx::bit_depth`]), so a mono frame decoded on a thread
103103 /// that last saw a 4:2:0 one never inherits the wrong plane count.
104104 pub(crate) mono_chrome: std::cell::Cell<bool>,
105+ /// lane-av1-444: sequence subsampling_x/y. 1,1 is 4:2:0; 0,0 is 4:4:4.
106+ pub(crate) subsampling_x: std::cell::Cell<u8>,
107+ pub(crate) subsampling_y: std::cell::Cell<u8>,
105108 pub(crate) superres: std::cell::Cell<(u32, u32)>,
106109 pub(crate) cdef_transmitted: std::cell::Cell<bool>,
107110 pub(crate) cdef_sb_cols: std::cell::Cell<usize>,
@@ -200,6 +203,8 @@ impl FrameCtx {
200203 cdef_bits: std::cell::Cell::new(0),
201204 bit_depth: std::cell::Cell::new(8),
202205 mono_chrome: std::cell::Cell::new(false),
206+ subsampling_x: std::cell::Cell::new(1),
207+ subsampling_y: std::cell::Cell::new(1),
203208 superres: std::cell::Cell::new((0, 8)),
204209 cdef_transmitted: std::cell::Cell::new(false),
205210 cdef_sb_cols: std::cell::Cell::new(0),
@@ -296,6 +301,8 @@ pub(crate) fn filter_ctx_copy(fctx: &FrameCtx) -> FrameCtx {
296301 let out = FrameCtx::new();
297302 out.bit_depth.set(fctx.bit_depth.get());
298303 out.mono_chrome.set(fctx.mono_chrome.get());
304+ out.subsampling_x.set(fctx.subsampling_x.get());
305+ out.subsampling_y.set(fctx.subsampling_y.get());
299306 out.interp_filter.set(fctx.interp_filter.get());
300307 out.grain_bit_depth.set(fctx.grain_bit_depth.get());
301308 out.superres.set(fctx.superres.get());
@@ -618,6 +625,29 @@ pub(crate) fn set_mono(mono_chrome: bool, fctx: &crate::decode::FrameCtx) {
618625 fctx.mono_chrome.with(|c| c.set(mono_chrome));
619626 }
620627
628+/// Sequence subsampling. Set once per frame from stream.rs, like set_mono.
629+pub(crate) fn set_subsampling(ss_x: u8, ss_y: u8, fctx: &crate::decode::FrameCtx) {
630+ fctx.subsampling_x.set(ss_x);
631+ fctx.subsampling_y.set(ss_y);
632+}
633+
634+#[inline]
635+pub(crate) fn ss_x(fctx: &crate::decode::FrameCtx) -> usize {
636+ fctx.subsampling_x.get() as usize
637+}
638+
639+#[inline]
640+pub(crate) fn ss_y(fctx: &crate::decode::FrameCtx) -> usize {
641+ fctx.subsampling_y.get() as usize
642+}
643+
644+/// libaom ROUND_POWER_OF_TWO. At ss=1 equals div_ceil(dim, 2); at ss=0 is dim.
645+#[inline]
646+pub(crate) fn round_ss(dim: usize, ss: usize) -> usize {
647+ (dim + ((1usize << ss) >> 1)) >> ss
648+}
649+
650+
621651 /// This frame's superres state: `(upscaled_width, superres_denom)`, or
622652 /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs
623653 /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid,
@@ -2333,17 +2363,14 @@ pub(crate) struct CflSrc {
23332363 py: usize,
23342364 bw: usize,
23352365 bh: usize,
2336- /// Which averager the parse site asked for -- [`cfl_ac_q3_rect`] and
2337- /// [`cfl_ac_q3`] are not the same function at `bw == bh`.
2338- rect: bool,
23392366 }
23402367
23412368 fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc {
2342- CflSrc { px, py, bw: side, bh: side, rect: false }
2369+ CflSrc { px, py, bw: side, bh: side }
23432370 }
23442371
23452372 fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc {
2346- CflSrc { px, py, bw, bh, rect: true }
2373+ CflSrc { px, py, bw, bh }
23472374 }
23482375
23492376 /// lane-wave1 step (i): the pixel-writing half of block decoding, recorded
@@ -3578,11 +3605,7 @@ fn exec_intra(
35783605 // written for this block -- at parse time it would have been the previous
35793606 // frame's samples.
35803607 let ac = cfl.map(|(alpha, src)| {
3581- let sig = if src.rect {
3582- cfl_ac_q3_rect(&*y, src.px, src.py, src.bw, src.bh)
3583- } else {
3584- cfl_ac_q3(&*y, src.px, src.py, src.bw)
3585- };
3608+ let sig = cfl_ac_ss(&*y, src.px, src.py, src.bw, src.bh, ss_x(fctx), ss_y(fctx));
35863609 (alpha, sig)
35873610 });
35883611 let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));
@@ -6757,7 +6780,9 @@ fn read_coeffs_rect(
67576780 // mask rather than a hardware divide.
67586781 let stride = w + 4;
67596782 let n = stride * (h + 4);
6760- debug_assert!(w.is_power_of_two() && n <= 36 * 36);
6783+ if !(w.is_power_of_two() && n <= 36 * 36) {
6784+ panic!("rect coeff scratch w={w} h={h} n={n}");
6785+ }
67616786 let (mut b96, mut b256, mut b768);
67626787 // Byte levels, same `0..=15` bound [`read_coeffs`] states.
67636788 let levels: &mut [u8] = if n <= 96 {
@@ -7653,8 +7678,8 @@ impl Neighbours {
76537678 // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is
76547679 // half its luma one (min 4 px, the smallest transform), capped at
76557680 // TX_32X32 -- independent of this block's luma `tx_depth`.
7656- let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8;
7657- let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8;
7681+ let uv_tx_w = (((w_mi * MI) >> ss_x(fctx)).max(4).min(32)) as u8;
7682+ let uv_tx_h = (((h_mi * MI) >> ss_y(fctx)).max(4).min(32)) as u8;
76587683 if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
76597684 eprintln!("EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");
76607685 }
@@ -9453,7 +9478,7 @@ fn read_intra_mode_rect(
94539478 // BLOCK_4X8, both floored at the 4-px transform. Halving the short
94549479 // axis to 2 read HALF the colour-index symbols of a 1:4 strip's
94559480 // chroma palette and desynced the tile from there.
9456- let (cw, ch) = ((bw / 2).max(4), (bh / 2).max(4));
9481+ let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4));
94579482 let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));
94589483 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
94599484 hit!(PALETTE_UV_HITS);
@@ -9640,8 +9665,8 @@ fn decode_rect_split(
96409665 ) -> Result<()> {
96419666 let (mi_r, mi_c) = at_mi;
96429667 let (px, py) = (mi_c * MI, mi_r * MI);
9643- let (cpx, cpy) = (px / 2, py / 2);
9644- let (chroma_w, chroma_h) = (bw / 2, bh / 2);
9668+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
9669+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
96459670 // The chroma transform is picked before any symbol is read, so an
96469671 // unsupported chroma shape refuses before this strip desyncs the tile.
96479672 let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) {
@@ -9694,7 +9719,11 @@ fn decode_rect_split(
96949719 // caller -- a new strip size would otherwise hit the `expect` below and
96959720 // panic instead of refusing by name -- and so stays in
96969721 // `refusal_inventory::REFUSALS`.
9697- if !m.skip && chroma.is_none() {
9722+ // A 4:4:4 64-axis strip's chroma plane block is larger than one adjusted
9723+ // UV transform (TX_64X32 adjusts to TX_32X32). Those sizes are tiled
9724+ // below; everything else still needs a single-unit table.
9725+ let chroma_tiled = matches!((chroma_w, chroma_h), (64, 32) | (32, 64) | (64, 16) | (16, 64));
9726+ if !m.skip && chroma.is_none() && !chroma_tiled {
96989727 return Err(unsupported(
96999728 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
97009729 ));
@@ -10051,6 +10080,80 @@ fn decode_rect_split(
1005110080 }
1005210081 let [ug, vg] = last;
1005310082 (ug, vg)
10083+ } else if chroma_tiled {
10084+ eprintln!("EC_TILE chroma={chroma_w}x{chroma_h}");
10085+ let (uw, uh, set, scan): (usize, usize, TxbSet, &[u16]) = match (chroma_w, chroma_h) {
10086+ (64, 32) | (32, 64) => (32, 32, TxbSet::Chroma32, default_scan(32)),
10087+ (64, 16) => (32, 16, TxbSet::ChromaRect32x16, &SCAN_32X16),
10088+ (16, 64) => (16, 32, TxbSet::ChromaRect32x16, &SCAN_16X32),
10089+ _ => unreachable!("chroma_tiled"),
10090+ };
10091+ let (nw, nh) = (chroma_w / uw, chroma_h / uh);
10092+ let bigger = chroma_w * chroma_h > uw * uh;
10093+ let default_tx = TxType::DctDct;
10094+ let mut last = [Grid::Zero(uw * uh), Grid::Zero(uw * uh)];
10095+ for plane_idx in 1..=2 {
10096+ for cu_row in 0..nh {
10097+ for cu_col in 0..nw {
10098+ let luma_span_x = uw << ss_x(fctx);
10099+ let luma_span_y = uh << ss_y(fctx);
10100+ let cu_mi = (
10101+ mi_r + cu_row * (luma_span_y / MI),
10102+ mi_c + cu_col * (luma_span_x / MI),
10103+ );
10104+ let cu_around = neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y);
10105+ let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh);
10106+ let cfl = m.alpha.map(|(au, av)| {
10107+ let alpha = if plane_idx == 1 { au } else { av };
10108+ (
10109+ alpha,
10110+ cfl_src_rect(
10111+ px + cu_col * luma_span_x,
10112+ py + cu_row * luma_span_y,
10113+ luma_span_x,
10114+ luma_span_y,
10115+ ),
10116+ )
10117+ });
10118+ // 32x32 does not fit read_coeffs_rect's scratch (768). The
10119+ // square reader is the path every other 32x32 chroma unit uses.
10120+ let levels = if uw == uh {
10121+ let plane = if plane_idx == 1 { &mut *u } else { &mut *v };
10122+ read_plane(
10123+ dec, cdfs, set, scan, plane_idx, cu_around[plane_idx],
10124+ m.mode, m.uv_predict_mode, m.angle_delta_uv, reach,
10125+ plane, cu_x, cu_y, uw, uw, base_q_idx, cfl, None,
10126+ bigger.then_some(3), m.smooth_neighbor_uv, fctx,
10127+ )?
10128+ } else {
10129+ let skip_ctx = usize::from(cu_around[plane_idx].0)
10130+ + usize::from(cu_around[plane_idx].1)
10131+ + usize::from(bigger) * 3;
10132+ let mut coding = cdfs.txb(set, m.uv_predict_mode);
10133+ let (levels, tx_type) = read_coeffs_rect(
10134+ dec, &mut coding, scan, uw, uh, skip_ctx,
10135+ dc_sign_ctx(cu_around[plane_idx].2), default_tx,
10136+ )?;
10137+ let residual = dequant_and_inverse_typed_wh(
10138+ &levels, uw, uh, crate::decode::bit_depth(fctx),
10139+ block_q_idx(fctx),
10140+ plane_q_delta(plane_idx, fctx).0,
10141+ plane_q_delta(plane_idx, fctx).1,
10142+ tx_type,
10143+ );
10144+ push_intra_rect(
10145+ plane_idx, cu_x, cu_y, uw, uh,
10146+ m.uv_predict_mode, m.angle_delta_uv, reach, &residual,
10147+ cfl, None, m.smooth_neighbor_uv, fctx,
10148+ );
10149+ levels
10150+ };
10151+ neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, plane_idx, &levels);
10152+ last[plane_idx - 1] = levels;
10153+ }
10154+ }
10155+ }
10156+ (last[0].clone(), last[1].clone())
1005410157 } else {
1005510158 let (chroma_set, chroma_scan) = chroma.expect("refused above when None");
1005610159 // `av1_get_ext_tx_set_type`: a chroma transform whose square-up size
@@ -10741,7 +10844,7 @@ fn decode_intra_rect_in_inter(
1074110844 PaletteY { size: n, colors, map }
1074210845 });
1074310846 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
10744- let (cw, ch) = ((bw / 2).max(4), (bh / 2).max(4));
10847+ let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4));
1074510848 let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));
1074610849 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
1074710850 hit!(PALETTE_UV_HITS);
@@ -11063,8 +11166,8 @@ fn decode_block_rect(
1106311166 return Ok(());
1106411167 }
1106511168 let (tx_w, tx_h) = (bw, bh);
11066- let (cpx, cpy) = (px / 2, py / 2);
11067- let (chroma_w, chroma_h) = (bw / 2, bh / 2);
11169+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
11170+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
1106811171 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
1106911172 if crate::envflags::env_flag!("EC_AV1_TRACE") {
1107011173 let (rng, _) = dec.debug_state();
@@ -11152,10 +11255,25 @@ fn decode_block_rect(
1115211255 // (`TxbSet::LumaRect32x16`/`ChromaRect16x8`, see those variants' own
1115311256 // doc comments); the scan order and 2D context tables are the real
1115411257 // rect ones (`SCAN_32X16`/etc, `base_ctx_rect`/`br_ctx_rect`).
11155- let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw == 32 {
11156- (&SCAN_32X16, &SCAN_16X8)
11258+ let luma_scan: &[u16] = if bw > bh { &SCAN_32X16 } else { &SCAN_16X32 };
11259+ // Chroma tx follows the plane block, not a hardcoded half. At 4:2:0 a
11260+ // 32x16 strip's chroma is 16x8 (ChromaRect16x8); at 4:4:4 it is 32x16
11261+ // (ChromaRect32x16, DCT-only — ADST is undefined on a 32-point axis).
11262+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) {
11263+ (32, 16) => (TxbSet::ChromaRect32x16, &SCAN_32X16),
11264+ (16, 32) => (TxbSet::ChromaRect32x16, &SCAN_16X32),
11265+ (16, 8) => (TxbSet::ChromaRect16x8, &SCAN_16X8),
11266+ (8, 16) => (TxbSet::ChromaRect16x8, &SCAN_8X16),
11267+ _ => {
11268+ return Err(unsupported(
11269+ "a rectangular chroma transform whose size has no coefficient table",
11270+ ))
11271+ }
11272+ };
11273+ let chroma_default_tx = if chroma_w.max(chroma_h) >= 32 {
11274+ TxType::DctDct
1115711275 } else {
11158- (&SCAN_16X32, &SCAN_8X16)
11276+ default_intra_tx_type(uv_predict_mode as u8)
1115911277 };
1116011278 // lane-rectwire r3: real coefficients desync a pixel-exact gate
1116111279 // (rectwire-flake-1.obu, seed 55) -- both 32x16 strips of frame 0's
@@ -11235,9 +11353,9 @@ fn decode_block_rect(
1123511353 if let Some((ub, _)) = &palette_uv_bufs {
1123611354 set_palette_pred(ub.clone(), fctx);
1123711355 }
11238- let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
11356+ let u_default_tx = chroma_default_tx;
1123911357 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
11240- let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode);
11358+ let mut u_coding = cdfs.txb(chroma_set, uv_predict_mode);
1124111359 let (u_levels, u_tx_type) = read_chroma_coeffs_rect(
1124211360 dec,
1124311361 &mut u_coding,
@@ -11279,9 +11397,9 @@ fn decode_block_rect(
1127911397 if let Some((_, vb)) = &palette_uv_bufs {
1128011398 set_palette_pred(vb.clone(), fctx);
1128111399 }
11282- let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
11400+ let v_default_tx = chroma_default_tx;
1128311401 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
11284- let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode);
11402+ let mut v_coding = cdfs.txb(chroma_set, uv_predict_mode);
1128511403 let (v_levels, v_tx_type) = read_chroma_coeffs_rect(
1128611404 dec,
1128711405 &mut v_coding,
@@ -11551,8 +11669,8 @@ fn decode_leaf_rect(
1155111669 }
1155211670 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
1155311671 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
11554- let (cpx, cpy) = (px / 2, py / 2);
11555- let (chroma_w, chroma_h) = (bw / 2, bh / 2);
11672+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
11673+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
1155611674 let (luma_levels, u_levels, v_levels);
1155711675 if skip {
1155811676 luma_levels = Grid::Zero(bw * bh);
@@ -11587,11 +11705,14 @@ fn decode_leaf_rect(
1158711705 // `use_reduced_set` branch returns `EXT_TX_SET_DTT4_IDTX` at
1158811706 // `tx_size_sqr_up == TX_16X16` regardless of the true, non-square
1158911707 // `tx_size`) and its chroma half (8x4/4x8, `TxbSet::ChromaRect8x4`).
11590- let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw == 16 {
11708+ let (luma_scan, chroma_scan): (&[u16], &[u16]) = if ss_x(fctx) == 0 {
11709+ if bw == 16 { (&SCAN_16X8, &SCAN_16X8) } else { (&SCAN_8X16, &SCAN_8X16) }
11710+ } else if bw == 16 {
1159111711 (&SCAN_16X8, &SCAN_8X4)
1159211712 } else {
1159311713 (&SCAN_8X16, &SCAN_4X8)
1159411714 };
11715+ let chroma_rect_set = if ss_x(fctx) == 0 { TxbSet::ChromaRect16x8 } else { TxbSet::ChromaRect8x4 };
1159511716 let around = neighbours.around_mi_rect(leaf_mi, bw, bh);
1159611717 let luma_set = if reduced_tx_set {
1159711718 TxbSet::LumaRect16x8
@@ -11621,7 +11742,7 @@ fn decode_leaf_rect(
1162111742 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
1162211743 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
1162311744 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
11624- let mut u_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
11745+ let mut u_coding = cdfs.txb(chroma_rect_set, uv_predict_mode);
1162511746 let (u_l, u_tx_type) = read_chroma_coeffs_rect(
1162611747 dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx,
1162711748 dc_sign_ctx(around[1].2), u_default_tx, fctx,
@@ -11640,7 +11761,7 @@ fn decode_leaf_rect(
1164011761 );
1164111762 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
1164211763 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
11643- let mut v_coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
11764+ let mut v_coding = cdfs.txb(chroma_rect_set, uv_predict_mode);
1164411765 let (v_l, v_tx_type) = read_chroma_coeffs_rect(
1164511766 dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx,
1164611767 dc_sign_ctx(around[2].2), v_default_tx, fctx,
@@ -11936,8 +12057,8 @@ fn decode_block_rect4(
1193612057 neighbours.record_mode_mi(mi_r, mi_c, mi_w, mi_h, mode);
1193712058 neighbours.record_uv_mode_mi(mi_r, mi_c, mi_w, mi_h, uv_predict_mode);
1193812059 let (px, py) = (mi_c * MI, mi_r * MI);
11939- let (cpx, cpy) = (px / 2, py / 2);
11940- let (chroma_w, chroma_h) = (bw / 2, bh / 2);
12060+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
12061+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
1194112062 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
1194212063 let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw > bh {
1194312064 (&SCAN_32X8, &SCAN_16X4)
@@ -12549,8 +12670,8 @@ fn decode_rect4_16_strip(
1254912670 };
1255012671 let (pw, ph) = if horz { (16, 8) } else { (8, 16) };
1255112672 let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI);
12552- let (cpx, cpy) = (ppx / 2, ppy / 2);
12553- let (cw, ch) = (pw / 2, ph / 2);
12673+ let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx));
12674+ let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx));
1255412675 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
1255512676 if (V_PRED..=D67_PRED).contains(&uv_predict_mode) {
1255612677 hit!(RECT4_16_CHROMA_DIR_HITS);
@@ -12932,8 +13053,8 @@ fn decode_block_rect64(
1293213053 return Ok(());
1293313054 }
1293413055 let (tx_w, tx_h) = (bw, bh);
12935- let (cpx, cpy) = (px / 2, py / 2);
12936- let (chroma_w, chroma_h) = (bw / 2, bh / 2);
13056+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
13057+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
1293713058 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
1293813059 if let Some(ref pyv) = palette_y {
1293913060 let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect();
@@ -13112,145 +13233,99 @@ fn decode_block_rect64(
1311213233 leftcol,
1311313234 );
1311413235 }
13115- // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no
13116- // corner crop needed (see doc comment).
13117- let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
13118- // The chroma plane is never truncated (both axes <= 32 after
13119- // subsampling). Under a 1:4 strip it is a true 32x8/8x32:
13120- // `get_txsize_entropy_ctx(TX_32X8)` = (TX_8X8 + TX_32X32 + 1) >> 1 =
13121- // TX_16X16 and `txsize_log2_minus4[TX_32X8]` = 4 (256 positions),
13122- // both identical to TX_16X16 -- so [`TxbSet::Chroma16`] is the exact
13123- // set, and only the scan is new (lane-tx64x16).
13124- let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (bw, bh) {
13125- (64, 16) => (TxbSet::Chroma16, &SCAN_32X8),
13126- (16, 64) => (TxbSet::Chroma16, &SCAN_8X32),
13127- (64, _) => (TxbSet::ChromaRect32x16, &SCAN_32X16),
13128- _ => (TxbSet::ChromaRect32x16, &SCAN_16X32),
13129- };
13130- let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
13131- let mut u_coding = cdfs.txb(chroma_set, uv_predict_mode);
13132- if coeff_trace_on() {
13133- let (rng, _) = dec.debug_state();
13134- eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}");
13135- }
13136- let (u_levels, u_tx_type) = read_chroma_coeffs_rect(
13137- dec,
13138- &mut u_coding,
13139- chroma_scan,
13140- chroma_w,
13141- chroma_h,
13142- u_skip_ctx,
13143- dc_sign_ctx(around[1].2),
13144- TxType::DctDct,
13145- fctx,
13146- )?;
13147- if coeff_trace_on() {
13148- let (rng, _) = dec.debug_state();
13149- eprintln!("EC_COEFF_VAL plane=1 row={mi_r} col={mi_c} rng={rng}");
13150- }
13151- {
13152- let cur = block_q_idx(fctx);
13153- if cur != i32::from(base_q_idx) {
13154- hit!(RECT64_QIDX_DRIFT_HITS);
13155- }
13156- if crate::envflags::env_flag!("EC_AV1_TRACE") {
13157- eprintln!(
13158- "TRACE rect64_dequant plane=1 base_q_idx={base_q_idx} current_q_idx={cur}"
13159- );
13160- }
13161- }
13162- let u_residual = dequant_and_inverse_typed_wh(
13163- &u_levels,
13164- chroma_w,
13165- chroma_h,
13166- crate::decode::bit_depth(fctx),
13167- block_q_idx(fctx),
13168- plane_q_delta(1, fctx).0,
13169- plane_q_delta(1, fctx).1,
13170- u_tx_type,
13171- );
13172- // lane-t900 r34: the UV-palette prediction override, exactly as the
13173- // `skip` arm above installs it. The [`PALETTE_PRED`] slot is a
13174- // set-then-take, so it must be filled again right before each plane's
13175- // own reconstruct; leaving this out of the non-skip arm predicted a
13176- // palette block's chroma off its block edges (measured: testsrc2
13177- // 128x128 10-bit cq55 `--tile-columns=1`, the 32x64 strip at px=96 --
13178- // luma exact, both chroma planes wrong over its whole 16x32).
13179- if let Some((ub, _)) = &palette_uv_bufs {
13180- set_palette_pred(ub.clone(), fctx);
13181- }
13182- push_intra_rect(1,
13183- cpx,
13184- cpy,
13185- chroma_w,
13186- chroma_h,
13187- uv_predict_mode,
13188- angle_delta_uv,
13189- reach,
13190- &u_residual,
13191- alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
13192- None,
13193- smooth_neighbor_uv, fctx,
13194- );
13195- let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
13196- let mut v_coding = cdfs.txb(chroma_set, uv_predict_mode);
13197- if coeff_trace_on() {
13198- let (rng, _) = dec.debug_state();
13199- eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}");
13200- }
13201- let (v_levels, v_tx_type) = read_chroma_coeffs_rect(
13202- dec,
13203- &mut v_coding,
13204- chroma_scan,
13205- chroma_w,
13206- chroma_h,
13207- v_skip_ctx,
13208- dc_sign_ctx(around[2].2),
13209- TxType::DctDct,
13210- fctx,
13211- )?;
13212- if coeff_trace_on() {
13213- let (rng, _) = dec.debug_state();
13214- eprintln!("EC_COEFF_VAL plane=2 row={mi_r} col={mi_c} rng={rng}");
13215- }
13216- {
13217- let cur = block_q_idx(fctx);
13218- if cur != i32::from(base_q_idx) {
13219- hit!(RECT64_QIDX_DRIFT_HITS);
13236+ // CHROMA. At 4:2:0 the plane block is already one adjusted UV
13237+ // transform (<=32 on each axis). At 4:4:4 a 64-axis strip's chroma
13238+ // is larger than that, so it is tiled into 32-capped units.
13239+ let _ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
13240+ let (uw, uh) = (chroma_w.min(32), chroma_h.min(32));
13241+ let (nw, nh) = (chroma_w / uw, chroma_h / uh);
13242+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (uw, uh) {
13243+ (32, 32) => (TxbSet::Chroma32, default_scan(32)),
13244+ (32, 16) => (TxbSet::ChromaRect32x16, &SCAN_32X16),
13245+ (16, 32) => (TxbSet::ChromaRect32x16, &SCAN_16X32),
13246+ (32, 8) => (TxbSet::Chroma16, &SCAN_32X8),
13247+ (8, 32) => (TxbSet::Chroma16, &SCAN_8X32),
13248+ _ => {
13249+ return Err(unsupported(
13250+ "a 64-axis strip whose chroma unit has no coefficient table",
13251+ ))
1322013252 }
13221- if crate::envflags::env_flag!("EC_AV1_TRACE") {
13222- eprintln!(
13223- "TRACE rect64_dequant plane=2 base_q_idx={base_q_idx} current_q_idx={cur}"
13224- );
13253+ };
13254+ let bigger = nw * nh > 1;
13255+ let mut u_levels = vec![0i32; chroma_w * chroma_h];
13256+ let mut v_levels = vec![0i32; chroma_w * chroma_h];
13257+ for plane_idx in 1..=2 {
13258+ for cu_row in 0..nh {
13259+ for cu_col in 0..nw {
13260+ let cu_around = if nw == 1 && nh == 1 {
13261+ around
13262+ } else {
13263+ let lsx = uw << ss_x(fctx);
13264+ let lsy = uh << ss_y(fctx);
13265+ let cu_mi = (
13266+ mi_r + cu_row * (lsy / MI),
13267+ mi_c + cu_col * (lsx / MI),
13268+ );
13269+ neighbours.around_mi_rect(cu_mi, lsx, lsy)
13270+ };
13271+ let lsx = uw << ss_x(fctx);
13272+ let lsy = uh << ss_y(fctx);
13273+ let cfl = alpha.map(|(au, av)| {
13274+ let a = if plane_idx == 1 { au } else { av };
13275+ (a, cfl_src_rect(px + cu_col * lsx, py + cu_row * lsy, lsx, lsy))
13276+ });
13277+ let levels = if uw == uh {
13278+ let plane = if plane_idx == 1 { &mut *u } else { &mut *v };
13279+ if let Some((ub, vb)) = &palette_uv_bufs {
13280+ set_palette_pred((if plane_idx == 1 { ub } else { vb }).clone(), fctx);
13281+ }
13282+ read_plane(
13283+ dec, cdfs, chroma_set, chroma_scan, plane_idx, cu_around[plane_idx],
13284+ mode, uv_predict_mode, angle_delta_uv, reach, plane,
13285+ cpx + cu_col * uw, cpy + cu_row * uh, uw, uw, base_q_idx,
13286+ cfl, None, bigger.then_some(3), smooth_neighbor_uv, fctx,
13287+ )?
13288+ } else {
13289+ let skip_ctx = usize::from(cu_around[plane_idx].0)
13290+ + usize::from(cu_around[plane_idx].1)
13291+ + usize::from(bigger) * 3;
13292+ let mut coding = cdfs.txb(chroma_set, uv_predict_mode);
13293+ let (levels, tx_type) = read_chroma_coeffs_rect(
13294+ dec, &mut coding, chroma_scan, uw, uh, skip_ctx,
13295+ dc_sign_ctx(cu_around[plane_idx].2), TxType::DctDct, fctx,
13296+ )?;
13297+ let residual = dequant_and_inverse_typed_wh(
13298+ &levels, uw, uh, crate::decode::bit_depth(fctx),
13299+ block_q_idx(fctx),
13300+ plane_q_delta(plane_idx, fctx).0,
13301+ plane_q_delta(plane_idx, fctx).1,
13302+ tx_type,
13303+ );
13304+ if let Some((ub, vb)) = &palette_uv_bufs {
13305+ set_palette_pred((if plane_idx == 1 { ub } else { vb }).clone(), fctx);
13306+ }
13307+ push_intra_rect(
13308+ plane_idx, cpx + cu_col * uw, cpy + cu_row * uh, uw, uh,
13309+ uv_predict_mode, angle_delta_uv, reach, &residual,
13310+ cfl, None, smooth_neighbor_uv, fctx,
13311+ );
13312+ levels
13313+ };
13314+ let dst = if plane_idx == 1 { &mut u_levels } else { &mut v_levels };
13315+ for row in 0..uh {
13316+ let d = (cu_row * uh + row) * chroma_w + cu_col * uw;
13317+ dst[d..d + uw].copy_from_slice(&levels[row * uw..][..uw]);
13318+ }
13319+ if bigger {
13320+ neighbours.record_mi_chroma(
13321+ (mi_r + cu_row * (lsy / MI), mi_c + cu_col * (lsx / MI)),
13322+ lsx, lsy, plane_idx, &levels,
13323+ );
13324+ }
13325+ }
1322513326 }
1322613327 }
13227- let v_residual = dequant_and_inverse_typed_wh(
13228- &v_levels,
13229- chroma_w,
13230- chroma_h,
13231- crate::decode::bit_depth(fctx),
13232- block_q_idx(fctx),
13233- plane_q_delta(2, fctx).0,
13234- plane_q_delta(2, fctx).1,
13235- v_tx_type,
13236- );
13237- if let Some((_, vb)) = &palette_uv_bufs {
13238- set_palette_pred(vb.clone(), fctx);
13239- }
13240- push_intra_rect(2,
13241- cpx,
13242- cpy,
13243- chroma_w,
13244- chroma_h,
13245- uv_predict_mode,
13246- angle_delta_uv,
13247- reach,
13248- &v_residual,
13249- alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
13250- None,
13251- smooth_neighbor_uv, fctx,
13252- );
13253- neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
13328+ neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
1325413329 hit!(RECT_COEFF_HITS);
1325513330 }
1325613331 let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
@@ -13619,9 +13694,9 @@ fn read_intra_mode(
1361913694 let on = palette_onscreen_uv(
1362013695 (side, side),
1362113696 palette_onscreen(mi_r, mi_c, side, side, fctx),
13622- (side / 2, side / 2),
13697+ (side >> ss_x(fctx), side >> ss_y(fctx)),
1362313698 );
13624- let map = decode_color_index_map(dec, cdfs, n, side / 2, on, true);
13699+ let map = decode_color_index_map(dec, cdfs, n, side >> ss_x(fctx), on, true);
1362513700 hit!(PALETTE_UV_HITS);
1362613701 if trace {
1362713702 eprintln!(
@@ -13692,6 +13767,38 @@ fn cfl_ac_q3(y: &PlaneBuf<'_>, px: usize, py: usize, side: usize) -> Vec<i32> {
1369213767 /// (lane-av1cfl) builds a CfL candidate's AC signal from its own `u8`
1369313768 /// reconstruction through THIS function rather than a second transcription of
1369413769 /// `cfl_luma_subsampling_420_lbd_c` + `subtract_average_c`.
13770+/// CfL AC at the frame's subsampling. 4:2:0 keeps the 2x2 average; 4:4:4
13771+/// copies each luma sample shifted to Q3 (`cfl_luma_subsampling_444_lbd`).
13772+fn cfl_ac_ss(
13773+ y: &PlaneBuf<'_>,
13774+ px: usize,
13775+ py: usize,
13776+ bw: usize,
13777+ bh: usize,
13778+ ss_x: usize,
13779+ ss_y: usize,
13780+) -> Vec<i32> {
13781+ if ss_x == 0 && ss_y == 0 {
13782+ let mut ac = vec![0i32; bw * bh];
13783+ let mut sum = 0i32;
13784+ for row in 0..bh {
13785+ for col in 0..bw {
13786+ let q3 = i32::from(y.data[(py + row) * y.width + px + col]) << 3;
13787+ ac[row * bw + col] = q3;
13788+ sum += q3;
13789+ }
13790+ }
13791+ let num_pel = (bw * bh) as i32;
13792+ let avg = (sum + num_pel / 2) >> num_pel.trailing_zeros();
13793+ ac.iter_mut().for_each(|v| *v -= avg);
13794+ ac
13795+ } else if bw == bh {
13796+ cfl_ac_q3(y, px, py, bw)
13797+ } else {
13798+ cfl_ac_q3_rect(y, px, py, bw, bh)
13799+ }
13800+}
13801+
1369513802 pub(crate) fn cfl_ac_q3_at(
1369613803 px: usize,
1369713804 py: usize,
@@ -14377,6 +14484,15 @@ fn decode_block(
1437714484 // multi-transform-unit path below.
1437814485 let (luma_set, chroma_set, luma_tx, chroma_tx, scans) = if lossless(fctx) {
1437914486 (TxbSet::Luma4, TxbSet::Chroma4, 4, 4, (scan4, scan4))
14487+ } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
14488+ let tx = if side >= 64 { 32 } else { side };
14489+ let (set, scan): (TxbSet, &[u16]) = match tx {
14490+ 32 => (TxbSet::Chroma32, scan32),
14491+ 16 => (TxbSet::Chroma16, scan16),
14492+ 8 => (TxbSet::Chroma8, scan8),
14493+ _ => (TxbSet::Chroma4, scan4),
14494+ };
14495+ (luma_set, set, luma_tx, tx, (scans.0, scan))
1438014496 } else {
1438114497 (luma_set, chroma_set, luma_tx, chroma_tx, scans)
1438214498 };
@@ -14511,8 +14627,8 @@ fn decode_block(
1451114627 };
1451214628 let luma_scan = scan_for(coeff_tx_side, scan32, scan16, scan8, scan4);
1451314629 let reach = Reach::of(side, px, py, y.width, y.height, fctx);
14514- let (cpx, cpy) = (px / 2, py / 2);
14515- let chroma_side = side / 2;
14630+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
14631+ let chroma_side = side >> ss_x(fctx);
1451614632 // spec 7.11.3.4 with `use_intrabc`: the reference is the *current*
1451714633 // frame's own pre-loop-filter reconstruction (all loop filters are off
1451814634 // whenever `allow_intrabc`, frame.rs:194/210/252/272) at the full-pel
@@ -14524,19 +14640,19 @@ fn decode_block(
1452414640 let mut yb = vec![0u16; side * side];
1452514641 mc::predict_with_filter(
1452614642 &y.data, y.width, y.true_width, y.true_height,
14527- mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),
14643+ mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0),
1452814644 side, side, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
1452914645 );
1453014646 let mut ub = vec![0u16; chroma_side * chroma_side];
1453114647 mc::predict_with_filter(
1453214648 &u.data, u.width, u.true_width, u.true_height,
14533- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
14649+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),
1453414650 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
1453514651 );
1453614652 let mut vb = vec![0u16; chroma_side * chroma_side];
1453714653 mc::predict_with_filter(
1453814654 &v.data, v.width, v.true_width, v.true_height,
14539- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
14655+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),
1454014656 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
1454114657 );
1454214658 (yb, ub, vb)
@@ -14685,7 +14801,7 @@ fn decode_block(
1468514801 let cn = (chroma_side / chroma_tx).max(1);
1468614802 for cu_row in 0..cn {
1468714803 for cu_col in 0..cn {
14688- let luma_span = chroma_tx * 2;
14804+ let luma_span = chroma_tx << ss_x(fctx);
1468914805 let cu_r = if cn == 1 {
1469014806 reach
1469114807 } else {
@@ -14774,6 +14890,10 @@ fn decode_block(
1477414890 if let Some((ub, _)) = &palette_uv_bufs {
1477514891 set_palette_pred(ub.clone(), fctx);
1477614892 }
14893+ // lane-av1-444: a 64x64 block takes this arm (`logical_tx == side`).
14894+ // At 4:4:4 its chroma plane is 64x64 and libaom codes four TX_32X32
14895+ // units. This read is still one unit (`chroma_side` x `chroma_tx`).
14896+ // Luma of that block matches; chroma does not. See lanes/av1444.report.md.
1477714897 let u_grid = read_plane(
1477814898 dec,
1477914899 cdfs,
@@ -14964,7 +15084,7 @@ fn decode_block(
1496415084 // The chroma context arrays are indexed in LUMA mi, so this
1496515085 // unit's anchor is its own luma quadrant: `chroma_tx` chroma
1496615086 // pixels span `2 * chroma_tx` luma ones.
14967- let luma_span = chroma_tx * 2;
15087+ let luma_span = chroma_tx << ss_x(fctx);
1496815088 let cu_mi = (
1496915089 mi_r + cu_row * (luma_span / MI),
1497015090 mi_c + cu_col * (luma_span / MI),
@@ -15267,8 +15387,8 @@ fn decode_block_128rect(
1526715387 TxbSet::Chroma32
1526815388 };
1526915389 let chroma_scan = default_scan(chroma_tx);
15270- let (cpx, cpy) = (px / 2, py / 2);
15271- let (chroma_w, chroma_h) = (bw / 2, bh / 2);
15390+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
15391+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
1527215392 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
1527315393 let (nch_x, nch_y) = (bw / 64, bh / 64);
1527415394 // The frame's own mi grid (`av1_calc_mi_size`, 8-px aligned): libaom's
@@ -15288,7 +15408,7 @@ fn decode_block_128rect(
1528815408 let mut units: Vec<(usize, (usize, usize), Grid)> = Vec::new();
1528915409 // The chroma context arrays are indexed in LUMA mi; every chroma unit of
1529015410 // every chunk shares this luma span (2 chroma pixels per luma unit).
15291- let luma_span = chroma_tx * 2;
15411+ let luma_span = chroma_tx << ss_x(fctx);
1529215412 for ch_row in 0..nch_y {
1529315413 for ch_col in 0..nch_x {
1529415414 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {
@@ -15363,8 +15483,8 @@ fn decode_block_128rect(
1536315483 let cn = (32 / chroma_tx).max(1);
1536415484 // libaom's per-chunk `unit_width/height` (plane-mi units of the
1536515485 // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`.
15366- let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> 1;
15367- let unit_h = ((ch_row + 1) * 16).min(max_h_mi) >> 1;
15486+ let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> ss_x(fctx);
15487+ let unit_h = ((ch_row + 1) * 16).min(max_h_mi) >> ss_y(fctx);
1536815488 let stepc = (chroma_tx / 4).max(1);
1536915489 // `decode_token_recon_block` codes a mu chunk PLANE-MAJOR: every U
1537015490 // unit of the chunk, then every V unit. At one unit per plane per
@@ -15382,8 +15502,8 @@ fn decode_block_128rect(
1538215502 let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx;
1538315503 let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx;
1538415504 let cu_mi = (
15385- mi_r + ch_row * 16 + ci_row * (chroma_tx / 2),
15386- mi_c + ch_col * 16 + ci_col * (chroma_tx / 2),
15505+ mi_r + ch_row * 16 + ci_row * ((chroma_tx << ss_y(fctx)) / 4),
15506+ mi_c + ch_col * 16 + ci_col * ((chroma_tx << ss_x(fctx)) / 4),
1538715507 );
1538815508 let cu_r = tu_reach(
1538915509 bw,
@@ -15695,7 +15815,15 @@ fn decode_leaf8(
1569515815 };
1569615816 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
1569715817 let reach = Reach::of(8, px, py, y.width, y.height, fctx);
15698- let (cpx, cpy) = (px / 2, py / 2);
15818+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
15819+ // 4:4:4: this 8x8 block's chroma plane block is 8x8 (same scan as luma,
15820+ // `scans.0`). 4:2:0 stays the 4x4 unit this leaf was written for.
15821+ let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
15822+ let (csz, cset, cscan) = if chroma_444 {
15823+ (8usize, TxbSet::Chroma8, scans.0)
15824+ } else {
15825+ (4usize, TxbSet::Chroma4, scans.1)
15826+ };
1569915827 // spec 7.11.3.4 with `use_intrabc`, same as `decode_block`: predict from
1570015828 // the CURRENT frame's own pre-loop-filter reconstruction (every loop
1570115829 // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at
@@ -15705,19 +15833,19 @@ fn decode_leaf8(
1570515833 let mut yb = vec![0u16; 8 * 8];
1570615834 mc::predict_with_filter(
1570715835 &y.data, y.width, y.true_width, y.true_height,
15708- mv_to_q4(px, dv_col, true), mv_to_q4(py, dv_row, true),
15836+ mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0),
1570915837 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
1571015838 );
1571115839 let mut ub = vec![0u16; 4 * 4];
1571215840 mc::predict_with_filter(
1571315841 &u.data, u.width, u.true_width, u.true_height,
15714- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
15842+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),
1571515843 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
1571615844 );
1571715845 let mut vb = vec![0u16; 4 * 4];
1571815846 mc::predict_with_filter(
1571915847 &v.data, v.width, v.true_width, v.true_height,
15720- mv_to_q4(cpx, dv_col, false), mv_to_q4(cpy, dv_row, false),
15848+ mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)),
1572115849 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
1572215850 );
1572315851 (yb, ub, vb)
@@ -15803,11 +15931,11 @@ fn decode_leaf8(
1580315931 push_intra(1,
1580415932 cpx,
1580515933 cpy,
15806- 4,
15934+ csz,
1580715935 uv_predict_mode,
1580815936 angle_delta_uv,
1580915937 reach,
15810- &ZERO_RESIDUAL[..16],
15938+ &ZERO_RESIDUAL[..csz * csz],
1581115939 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1581215940 None,
1581315941 smooth_neighbor_uv, fctx,
@@ -15820,18 +15948,18 @@ fn decode_leaf8(
1582015948 push_intra(2,
1582115949 cpx,
1582215950 cpy,
15823- 4,
15951+ csz,
1582415952 uv_predict_mode,
1582515953 angle_delta_uv,
1582615954 reach,
15827- &ZERO_RESIDUAL[..16],
15955+ &ZERO_RESIDUAL[..csz * csz],
1582815956 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1582915957 None,
1583015958 smooth_neighbor_uv, fctx,
1583115959 );
1583215960 luma_grid = Grid::Zero(64);
15833- u_grid = Grid::Zero(16);
15834- v_grid = Grid::Zero(16);
15961+ u_grid = Grid::Zero(csz * csz);
15962+ v_grid = Grid::Zero(csz * csz);
1583515963 } else if resolved != 4 {
1583615964 let around = neighbours.around_mi(leaf_mi, 8);
1583715965 if let Some(buf) = &palette_y_buf {
@@ -15880,8 +16008,8 @@ fn decode_leaf8(
1588016008 u_grid = read_plane(
1588116009 dec,
1588216010 cdfs,
15883- TxbSet::Chroma4,
15884- scans.1,
16011+ cset,
16012+ cscan,
1588516013 1,
1588616014 around[1],
1588716015 mode,
@@ -15891,8 +16019,8 @@ fn decode_leaf8(
1589116019 u,
1589216020 cpx,
1589316021 cpy,
15894- 4,
15895- TX4,
16022+ csz,
16023+ csz,
1589616024 base_q_idx,
1589716025 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1589816026 None,
@@ -15907,8 +16035,8 @@ fn decode_leaf8(
1590716035 v_grid = read_plane(
1590816036 dec,
1590916037 cdfs,
15910- TxbSet::Chroma4,
15911- scans.1,
16038+ cset,
16039+ cscan,
1591216040 2,
1591316041 around[2],
1591416042 mode,
@@ -15918,8 +16046,8 @@ fn decode_leaf8(
1591816046 v,
1591916047 cpx,
1592016048 cpy,
15921- 4,
15922- TX4,
16049+ csz,
16050+ csz,
1592316051 base_q_idx,
1592416052 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1592516053 None,
@@ -16019,8 +16147,8 @@ fn decode_leaf8(
1601916147 u_grid = read_plane(
1602016148 dec,
1602116149 cdfs,
16022- TxbSet::Chroma4,
16023- scans.1,
16150+ cset,
16151+ cscan,
1602416152 1,
1602516153 chroma_around[1],
1602616154 mode,
@@ -16030,8 +16158,8 @@ fn decode_leaf8(
1603016158 u,
1603116159 cpx,
1603216160 cpy,
16033- 4,
16034- TX4,
16161+ csz,
16162+ csz,
1603516163 base_q_idx,
1603616164 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
1603716165 None,
@@ -16044,8 +16172,8 @@ fn decode_leaf8(
1604416172 v_grid = read_plane(
1604516173 dec,
1604616174 cdfs,
16047- TxbSet::Chroma4,
16048- scans.1,
16175+ cset,
16176+ cscan,
1604916177 2,
1605016178 chroma_around[2],
1605116179 mode,
@@ -16055,8 +16183,8 @@ fn decode_leaf8(
1605516183 v,
1605616184 cpx,
1605716185 cpy,
16058- 4,
16059- TX4,
16186+ csz,
16187+ csz,
1606016188 base_q_idx,
1606116189 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
1606216190 None,
@@ -16398,7 +16526,7 @@ fn decode_leaf_split4(
1639816526 let mut yb = vec![0u16; 16];
1639916527 mc::predict_with_filter(
1640016528 &y.data, y.width, y.true_width, y.true_height,
16401- mv_to_q4(px, dv.1, true), mv_to_q4(py, dv.0, true),
16529+ mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0),
1640216530 4, 4, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
1640316531 );
1640416532 set_palette_pred(yb.clone(), fctx);
@@ -16502,7 +16630,7 @@ fn decode_leaf_split4(
1650216630 (Grid::Zero(16), Grid::Zero(16))
1650316631 } else {
1650416632 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
16505- let (cpx, cpy) = (gpx / 2, gpy / 2);
16633+ let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
1650616634 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);
1650716635 let (uv_mode, angle_delta_uv, alpha) =
1650816636 last_uv.expect("i==3 always sets has_chroma, so chroma is always Some");
@@ -16547,13 +16675,13 @@ fn decode_leaf_split4(
1654716675 let mut ub = vec![0u16; 16];
1654816676 mc::predict_with_filter(
1654916677 &u.data, u.width, u.true_width, u.true_height,
16550- mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false),
16678+ mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)),
1655116679 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
1655216680 );
1655316681 let mut vb = vec![0u16; 16];
1655416682 mc::predict_with_filter(
1655516683 &v.data, v.width, v.true_width, v.true_height,
16556- mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false),
16684+ mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)),
1655716685 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
1655816686 );
1655916687 let chroma_around = neighbours.around_mi(leaf_mi, 8);
@@ -16799,7 +16927,7 @@ fn decode_leaf_rect8(
1679916927 let mut yb = vec![0u16; tw * th];
1680016928 mc::predict_with_filter(
1680116929 &y.data, y.width, y.true_width, y.true_height,
16802- mv_to_q4(tu_px, dv.1, true), mv_to_q4(tu_py, dv.0, true),
16930+ mv_to_q4(tu_px, dv.1, 0), mv_to_q4(tu_py, dv.0, 0),
1680316931 tw, th, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
1680416932 );
1680516933 set_palette_pred(yb, fctx);
@@ -17118,7 +17246,7 @@ fn decode_leaf_rect8(
1711817246 (Grid::Zero(16), Grid::Zero(16))
1711917247 } else {
1712017248 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
17121- let (cpx, cpy) = (gpx / 2, gpy / 2);
17249+ let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
1712217250 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);
1712317251 let (uv_mode, angle_delta_uv, alpha) =
1712417252 last_uv.expect("i==1 always sets has_chroma, so chroma is always Some");
@@ -17163,13 +17291,13 @@ fn decode_leaf_rect8(
1716317291 let mut ub = vec![0u16; 16];
1716417292 mc::predict_with_filter(
1716517293 &u.data, u.width, u.true_width, u.true_height,
17166- mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false),
17294+ mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)),
1716717295 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
1716817296 );
1716917297 let mut vb = vec![0u16; 16];
1717017298 mc::predict_with_filter(
1717117299 &v.data, v.width, v.true_width, v.true_height,
17172- mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false),
17300+ mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)),
1717317301 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
1717417302 );
1717517303 let chroma_around = neighbours.around_mi(leaf_mi, 8);
@@ -17937,10 +18065,10 @@ fn deblock_span(
1793718065 deblock_plane_span(y, 0, lf, n, frame_width, frame_height, y_lo, y_hi, horz, fctx);
1793818066 }
1793918067 if lf.level[2] != 0 {
17940- deblock_plane_span(u, 1, lf, n, frame_width, frame_height, y_lo / 2, y_hi / 2, horz, fctx);
18068+ deblock_plane_span(u, 1, lf, n, frame_width, frame_height, y_lo >> ss_y(fctx), y_hi >> ss_y(fctx), horz, fctx);
1794118069 }
1794218070 if lf.level[3] != 0 {
17943- deblock_plane_span(v, 2, lf, n, frame_width, frame_height, y_lo / 2, y_hi / 2, horz, fctx);
18071+ deblock_plane_span(v, 2, lf, n, frame_width, frame_height, y_lo >> ss_y(fctx), y_hi >> ss_y(fctx), horz, fctx);
1794418072 }
1794518073 }
1794618074
@@ -17959,8 +18087,9 @@ fn deblock_span(
1795918087 /// block (different tx size, ref frame, skip flag and delta_lf) as soon as
1796018088 /// the group is split into 4x4 luma blocks (class
1796118089 /// `context-read-from-one-cell`).
17962-fn plane_to_mi(chroma: bool, coord: usize) -> usize {
17963- if chroma { (coord / 2) | 1 } else { coord / 4 }
18090+fn plane_to_mi(chroma: bool, coord: usize, ss: usize) -> usize {
18091+ // scale | ((coord << scale) >> 2). ss=1 is (coord/2)|1; ss=0 is coord/4.
18092+ if chroma { ss | ((coord << ss) >> 2) } else { coord / 4 }
1796418093 }
1796518094
1796618095 /// This plane's own transform width in pixels at the covering block, spec
@@ -19630,7 +19759,7 @@ impl<'a> EdgeCtx<'a> {
1963019759 chroma,
1963119760 seg_lf_active,
1963219761 delta_idx: if plane_idx == 0 { dir } else { plane_idx + 1 },
19633- step: if chroma { 2 } else { 1 },
19762+ step: if chroma { 1 << (if dir == 0 { ss_x(fctx) } else { ss_y(fctx) }) } else { 1 },
1963419763 base0,
1963519764 lvl,
1963619765 }
@@ -19659,7 +19788,10 @@ impl<'a> EdgeCtx<'a> {
1965919788 /// entirely. Returns `None` when this 4-pixel edge group is not filtered.
1966019789 #[inline(always)]
1966119790 fn edge_params(c: &EdgeCtx, x0: usize, y0: usize) -> Option<(u8, i32)> {
19662- let (mi_r, mi_c) = (plane_to_mi(c.chroma, y0), plane_to_mi(c.chroma, x0));
19791+ let (mi_r, mi_c) = (
19792+ plane_to_mi(c.chroma, y0, if c.chroma { ss_y(c.fctx) } else { 0 }),
19793+ plane_to_mi(c.chroma, x0, if c.chroma { ss_x(c.fctx) } else { 0 }),
19794+ );
1966319795 let cur_tx = if c.dir == 0 {
1966419796 tx_px_at(c.n, c.chroma, mi_r, mi_c)
1966519797 } else {
@@ -19731,10 +19863,11 @@ fn edge_params_body(
1973119863 (usize::from(cur_org[0]), usize::from(cur_dim[1]))
1973219864 };
1973319865 let pu_edge = if c.chroma {
19734- let plane_dim = (dim_mi * MI / 2).max(4);
19866+ let ss = if c.dir == 0 { ss_x(c.fctx) } else { ss_y(c.fctx) };
19867+ let plane_dim = ((dim_mi * MI) >> ss).max(4);
1973519868 (if c.dir == 0 { x0 } else { y0 }) % plane_dim == 0
1973619869 } else {
19737- plane_to_mi(false, if c.dir == 0 { x0 } else { y0 }) == org_px
19870+ plane_to_mi(false, if c.dir == 0 { x0 } else { y0 }, 0) == org_px
1973819871 };
1973919872 if !pu_edge
1974019873 && cur_ref != 0
@@ -21383,16 +21516,16 @@ fn replay_inner(
2138321516 width: tw,
2138421517 height: th,
2138521518 y: crop(&y, tw, th),
21386- u: crop(&u, tw.div_ceil(2), th.div_ceil(2)),
21387- v: crop(&v, tw.div_ceil(2), th.div_ceil(2)),
21519+ u: crop(&u, round_ss(tw, ss_x(fctx)), round_ss(th, ss_y(fctx))),
21520+ v: crop(&v, round_ss(tw, ss_x(fctx)), round_ss(th, ss_y(fctx))),
2138821521 });
2138921522 });
2139021523 let out = Picture {
2139121524 width: fw,
2139221525 height: fh,
2139321526 y: crop(&y, fw, fh),
21394- u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)),
21395- v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)),
21527+ u: crop(&u, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
21528+ v: crop(&v, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
2139621529 };
2139721530 // The working planes outlive the crop: either they ARE the
2139821531 // deblocked planes this candidate's successors reuse, or they go
@@ -21440,7 +21573,7 @@ pub(crate) fn replay_restoration(
2144021573 let r = slot.as_mut()?;
2144121574 let (cdefed, deblocked) = r.final_luma.as_ref()?;
2144221575 let (fw, fh) = (r.frame_width, r.frame_height);
21443- let mut grid = crate::restoration::RestorationGrid::new(lr, fw as u32, fh as u32);
21576+ let mut grid = crate::restoration::RestorationGrid::with_ss(lr, fw as u32, fh as u32, fctx.subsampling_x.get(), fctx.subsampling_y.get());
2144421577 let (horz, vert) = (grid.horz_units[0], grid.vert_units[0]);
2144521578 if horz == 0 || units.len() != horz * vert {
2144621579 return None;
@@ -21651,18 +21784,19 @@ fn cdef_band(
2165121784 w[(mi_r / 2) * unit_cols + mi_c / 2] = mark;
2165221785 }
2165321786 if enable_primary_uv || enable_secondary_uv {
21654- let (cox, coy) = (ox / 2, oy / 2);
21787+ let (cox, coy) = (ox >> ss_x(fctx), oy >> ss_y(fctx));
21788+ let (csize_x, csize_y) = (8 >> ss_x(fctx), 8 >> ss_y(fctx));
2165521789 for (plane, src_p) in [(&mut *u, src_u), (&mut *v, src_v)] {
2165621790 let (tw, th) = (plane.true_width, plane.true_height);
2165721791 let stride = plane.width;
21658- cdef_gather(src_p, stride, tw, th, cox, coy, 4, 4, &mut win_uv);
21792+ cdef_gather(src_p, stride, tw, th, cox, coy, csize_x, csize_y, &mut win_uv);
2165921793 cdef_filter_block(
2166021794 &win_uv,
2166121795 plane,
2166221796 cox,
2166321797 coy,
21664- 4,
21665- 4,
21798+ csize_x,
21799+ csize_y,
2166621800 t_uv,
2166721801 uv_sec_strength,
2166821802 uv_dir,
@@ -22376,9 +22510,9 @@ fn apply_loop_restoration(
2237622510 &u.data,
2237722511 &deblocked_u.data,
2237822512 u.width,
22379- frame_w.div_ceil(2),
22380- frame_h.div_ceil(2),
22381- 1,
22513+ round_ss(frame_w, ss_x(fctx)),
22514+ round_ss(frame_h, ss_y(fctx)),
22515+ ss_y(fctx) as u32,
2238222516 lr.frame_restoration_type[1],
2238322517 lr.loop_restoration_size[1],
2238422518 grid,
@@ -22391,9 +22525,9 @@ fn apply_loop_restoration(
2239122525 &v.data,
2239222526 &deblocked_v.data,
2239322527 v.width,
22394- frame_w.div_ceil(2),
22395- frame_h.div_ceil(2),
22396- 1,
22528+ round_ss(frame_w, ss_x(fctx)),
22529+ round_ss(frame_h, ss_y(fctx)),
22530+ ss_y(fctx) as u32,
2239722531 lr.frame_restoration_type[2],
2239822532 lr.loop_restoration_size[2],
2239922533 grid,
@@ -22857,27 +22991,29 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
2285722991 tile_x1: width,
2285822992 tile_y1: height,
2285922993 };
22994+ let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
22995+ let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
2286022996 let mut u = PlaneBuf {
22861- data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),
22862- width: width / 2,
22863- height: height / 2,
22864- true_width: true_width / 2,
22865- true_height: true_height / 2,
22997+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
22998+ width: cw,
22999+ height: ch,
23000+ true_width: ctw,
23001+ true_height: cth,
2286623002 tile_x0: 0,
2286723003 tile_y0: 0,
22868- tile_x1: width / 2,
22869- tile_y1: height / 2,
23004+ tile_x1: cw,
23005+ tile_y1: ch,
2287023006 };
2287123007 let mut v = PlaneBuf {
22872- data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),
22873- width: width / 2,
22874- height: height / 2,
22875- true_width: true_width / 2,
22876- true_height: true_height / 2,
23008+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
23009+ width: cw,
23010+ height: ch,
23011+ true_width: ctw,
23012+ true_height: cth,
2287723013 tile_x0: 0,
2287823014 tile_y0: 0,
22879- tile_x1: width / 2,
22880- tile_y1: height / 2,
23015+ tile_x1: cw,
23016+ tile_y1: ch,
2288123017 };
2288223018
2288323019 let scan32 = default_scan(TX32);
@@ -22896,10 +23032,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
2289623032 // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is
2289723033 // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width --
2289823034 // loop restoration runs after the superres upscale.
22899- let mut lr_grid = crate::restoration::RestorationGrid::new(
23035+ let mut lr_grid = crate::restoration::RestorationGrid::with_ss(
2290023036 lr,
2290123037 superres(fctx).map_or(frame_width, |(w, _)| w),
2290223038 frame_height,
23039+ fctx.subsampling_x.get(),
23040+ fctx.subsampling_y.get(),
2290323041 );
2290423042
2290523043 // lane-tiles r2: each tile gets its own fresh `SymbolDecoder` over its
@@ -24903,7 +25041,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
2490325041 tile_x1: out_w,
2490425042 tile_y1: in_h,
2490525043 };
24906- let (cw, ch, cuw) = (fw.div_ceil(2), fh.div_ceil(2), uw.div_ceil(2));
25044+ let (cw, ch, cuw) = (round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx)), round_ss(uw, ss_x(fctx)));
2490725045 y = up(&y, fw, fh, uw);
2490825046 u = up(&u, cw, ch, cuw);
2490925047 v = up(&v, cw, ch, cuw);
@@ -24990,8 +25128,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
2499025128 width: true_width,
2499125129 height: true_height,
2499225130 y: yc,
24993- u: crop(&u, true_width.div_ceil(2), true_height.div_ceil(2)),
24994- v: crop(&v, true_width.div_ceil(2), true_height.div_ceil(2)),
25131+ u: crop(&u, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))),
25132+ v: crop(&v, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))),
2499525133 })
2499625134 } else {
2499725135 None
@@ -25002,8 +25140,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
2500225140 width: fw,
2500325141 height: fh,
2500425142 y: crop_owned(y, fw, fh),
25005- u: crop_owned(u, fw.div_ceil(2), fh.div_ceil(2)),
25006- v: crop_owned(v, fw.div_ceil(2), fh.div_ceil(2)),
25143+ u: crop_owned(u, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
25144+ v: crop_owned(v, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
2500725145 },
2500825146 result_cdfs,
2500925147 ))
@@ -25276,8 +25414,9 @@ fn read_intrabc_dv(
2527625414 /// A 1/8-pel motion vector component converted to the 1/16-pel offset
2527725415 /// [`mc::predict`] takes, duplicating [`crate::encode`]'s private `mv_to_q4`
2527825416 /// (its own doc comment explains the `*2`/`*1` luma/chroma split).
25279-fn mv_to_q4(pos: usize, mv_component: i32, luma: bool) -> i32 {
25280- (pos as i32) * 16 + mv_component * if luma { 2 } else { 1 }
25417+fn mv_to_q4(pos: usize, mv_component: i32, ss: usize) -> i32 {
25418+ // orig_pos += mv * (1 << (1 - ss)). Luma always passes 0.
25419+ (pos as i32) * 16 + mv_component * (1i32 << (1 - ss as i32))
2528125420 }
2528225421
2528325422 impl PlaneBuf<'_> {
@@ -25825,8 +25964,18 @@ impl<'p> RefPix<'p> {
2582525964 dims[i].and(pics[i]).map(|g| {
2582625965 (
2582725966 whole_plane(&g.y, g.width, g.height),
25828- whole_plane(&g.u, g.width / 2, g.height / 2),
25829- whole_plane(&g.v, g.width / 2, g.height / 2),
25967+ {
25968+ // Reference pictures carry no subsampling field. A
25969+ // 4:4:4 chroma plane is luma-sized; 4:2:0 is the quarter.
25970+ let full = g.u.len() == g.width * g.height;
25971+ let (cw, ch) = if full { (g.width, g.height) } else { (g.width / 2, g.height / 2) };
25972+ whole_plane(&g.u, cw, ch)
25973+ },
25974+ {
25975+ let full = g.v.len() == g.width * g.height;
25976+ let (cw, ch) = if full { (g.width, g.height) } else { (g.width / 2, g.height / 2) };
25977+ whole_plane(&g.v, cw, ch)
25978+ },
2583025979 )
2583125980 })
2583225981 });
@@ -26384,8 +26533,8 @@ fn obmc_neighbour_pred(
2638426533 refplane.width,
2638526534 refplane.true_width,
2638626535 refplane.true_height,
26387- mv_to_q4(x, mv.1, luma),
26388- mv_to_q4(y, mv.0, luma),
26536+ mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
26537+ mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
2638926538 w,
2639026539 h,
2639126540 h_kind,
@@ -26398,8 +26547,8 @@ fn obmc_neighbour_pred(
2639826547 refplane.width,
2639926548 refplane.true_width,
2640026549 refplane.true_height,
26401- mv_to_q4(x, mv.1, luma),
26402- mv_to_q4(y, mv.0, luma),
26550+ mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
26551+ mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
2640326552 x_scale_fp,
2640426553 w,
2640526554 h,
@@ -27440,10 +27589,10 @@ fn decode_inter_block(
2744027589 fctx.inter_last_mc.with(|c| c.set(None));
2744127590 let has_chroma = strip_chroma.is_none_or(|s| s.has_chroma);
2744227591 let (cpx, cpy) = match strip_chroma {
27443- Some(s) if s.has_chroma => (s.pair_mi.1 * MI / 2, s.pair_mi.0 * MI / 2),
27444- _ => (px / 2, py / 2),
27592+ Some(s) if s.has_chroma => (s.pair_mi.1 * MI >> ss_x(fctx), s.pair_mi.0 * MI >> ss_y(fctx)),
27593+ _ => (px >> ss_x(fctx), py >> ss_y(fctx)),
2744527594 };
27446- let chroma_side = side / 2;
27595+ let chroma_side = side >> ss_x(fctx);
2744727596 let (write_chroma_w, write_chroma_h) = match strip_chroma {
2744827597 Some(s) if s.has_chroma => {
2744927598 if s.horz {
@@ -27452,8 +27601,21 @@ fn decode_inter_block(
2745227601 (4, 8)
2745327602 }
2745427603 }
27455- _ => (write_w / 2, write_h / 2),
27604+ _ => (write_w >> ss_x(fctx), write_h >> ss_y(fctx)),
2745627605 };
27606+ let (chroma_set, chroma_tx, scan_chroma) =
27607+ if ss_x(fctx) == 0 && ss_y(fctx) == 0 && strip_chroma.is_none() {
27608+ let tx = if side >= 64 { 32 } else { side };
27609+ let set = match tx {
27610+ 32 => TxbSet::Chroma32,
27611+ 16 => TxbSet::Chroma16,
27612+ 8 => TxbSet::Chroma8,
27613+ _ => TxbSet::Chroma4,
27614+ };
27615+ (set, tx, scan_luma)
27616+ } else {
27617+ (chroma_set, chroma_tx, scan_chroma)
27618+ };
2745727619 // lane-midcut r3 (same rule as lane-t900 r5's `warp_plane_allowed`, one
2745827620 // copy kept at the merge): `av1_init_warp_params` (libaom reconinter.c)
2745927621 // bails per PLANE at `block_width < 8 || block_height < 8` -- on the
@@ -28242,8 +28404,8 @@ fn decode_inter_block(
2824228404 py0.width,
2824328405 py0.true_width,
2824428406 py0.true_height,
28245- mv_to_q4(px, mv0.1, true),
28246- mv_to_q4(py, mv0.0, true),
28407+ mv_to_q4(px, mv0.1, 0),
28408+ mv_to_q4(py, mv0.0, 0),
2824728409 scale0,
2824828410 side,
2824928411 side,
@@ -28269,8 +28431,8 @@ fn decode_inter_block(
2826928431 py1.width,
2827028432 py1.true_width,
2827128433 py1.true_height,
28272- mv_to_q4(px, mv1.1, true),
28273- mv_to_q4(py, mv1.0, true),
28434+ mv_to_q4(px, mv1.1, 0),
28435+ mv_to_q4(py, mv1.0, 0),
2827428436 scale1,
2827528437 side,
2827628438 side,
@@ -28318,8 +28480,8 @@ fn decode_inter_block(
2831828480 pu0.width,
2831928481 pu0.true_width,
2832028482 pu0.true_height,
28321- mv_to_q4(cpx, mv0.1, false),
28322- mv_to_q4(cpy, mv0.0, false),
28483+ mv_to_q4(cpx, mv0.1, ss_x(fctx)),
28484+ mv_to_q4(cpy, mv0.0, ss_x(fctx)),
2832328485 scale0,
2832428486 chroma_side,
2832528487 chroma_side,
@@ -28337,7 +28499,7 @@ fn decode_inter_block(
2833728499 crate::warp::warp_affine_compound(
2833828500 wp, &pu0.data, pu0.true_width as i32, pu0.true_height as i32,
2833928501 pu0.width as i32, &mut inter0_u, cpx as i32, cpy as i32,
28340- chroma_side as i32, chroma_side as i32, chroma_side as i32, 1, 1, fctx,
28502+ chroma_side as i32, chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
2834128503 );
2834228504 }
2834328505 }
@@ -28347,8 +28509,8 @@ fn decode_inter_block(
2834728509 pu1.width,
2834828510 pu1.true_width,
2834928511 pu1.true_height,
28350- mv_to_q4(cpx, mv1.1, false),
28351- mv_to_q4(cpy, mv1.0, false),
28512+ mv_to_q4(cpx, mv1.1, ss_x(fctx)),
28513+ mv_to_q4(cpy, mv1.0, ss_x(fctx)),
2835228514 scale1,
2835328515 chroma_side,
2835428516 chroma_side,
@@ -28366,7 +28528,7 @@ fn decode_inter_block(
2836628528 crate::warp::warp_affine_compound(
2836728529 wp, &pu1.data, pu1.true_width as i32, pu1.true_height as i32,
2836828530 pu1.width as i32, &mut inter1_u, cpx as i32, cpy as i32,
28369- chroma_side as i32, chroma_side as i32, chroma_side as i32, 1, 1, fctx,
28531+ chroma_side as i32, chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
2837028532 );
2837128533 }
2837228534 }
@@ -28379,7 +28541,7 @@ fn decode_inter_block(
2837928541 side,
2838028542 chroma_side,
2838128543 chroma_side,
28382- true,
28544+ ss_x(fctx) == 1 && ss_y(fctx) == 1,
2838328545 &mut pred_u, fctx,
2838428546 );
2838528547 } else {
@@ -28392,8 +28554,8 @@ fn decode_inter_block(
2839228554 pv0.width,
2839328555 pv0.true_width,
2839428556 pv0.true_height,
28395- mv_to_q4(cpx, mv0.1, false),
28396- mv_to_q4(cpy, mv0.0, false),
28557+ mv_to_q4(cpx, mv0.1, ss_x(fctx)),
28558+ mv_to_q4(cpy, mv0.0, ss_x(fctx)),
2839728559 scale0,
2839828560 chroma_side,
2839928561 chroma_side,
@@ -28411,7 +28573,7 @@ fn decode_inter_block(
2841128573 crate::warp::warp_affine_compound(
2841228574 wp, &pv0.data, pv0.true_width as i32, pv0.true_height as i32,
2841328575 pv0.width as i32, &mut inter0_v, cpx as i32, cpy as i32,
28414- chroma_side as i32, chroma_side as i32, chroma_side as i32, 1, 1, fctx,
28576+ chroma_side as i32, chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
2841528577 );
2841628578 }
2841728579 }
@@ -28421,8 +28583,8 @@ fn decode_inter_block(
2842128583 pv1.width,
2842228584 pv1.true_width,
2842328585 pv1.true_height,
28424- mv_to_q4(cpx, mv1.1, false),
28425- mv_to_q4(cpy, mv1.0, false),
28586+ mv_to_q4(cpx, mv1.1, ss_x(fctx)),
28587+ mv_to_q4(cpy, mv1.0, ss_x(fctx)),
2842628588 scale1,
2842728589 chroma_side,
2842828590 chroma_side,
@@ -28440,7 +28602,7 @@ fn decode_inter_block(
2844028602 crate::warp::warp_affine_compound(
2844128603 wp, &pv1.data, pv1.true_width as i32, pv1.true_height as i32,
2844228604 pv1.width as i32, &mut inter1_v, cpx as i32, cpy as i32,
28443- chroma_side as i32, chroma_side as i32, chroma_side as i32, 1, 1, fctx,
28605+ chroma_side as i32, chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
2844428606 );
2844528607 }
2844628608 }
@@ -28453,7 +28615,7 @@ fn decode_inter_block(
2845328615 side,
2845428616 chroma_side,
2845528617 chroma_side,
28456- true,
28618+ ss_x(fctx) == 1 && ss_y(fctx) == 1,
2845728619 &mut pred_v, fctx,
2845828620 );
2845928621 } else {
@@ -29561,8 +29723,8 @@ fn decode_inter_block(
2956129723 py_ref.width,
2956229724 py_ref.true_width,
2956329725 py_ref.true_height,
29564- mv_to_q4(px, mv.1, true),
29565- mv_to_q4(py, mv.0, true),
29726+ mv_to_q4(px, mv.1, 0),
29727+ mv_to_q4(py, mv.0, 0),
2956629728 side,
2956729729 side,
2956829730 write_w,
@@ -29576,8 +29738,8 @@ fn decode_inter_block(
2957629738 pu_ref.width,
2957729739 pu_ref.true_width,
2957829740 pu_ref.true_height,
29579- mv_to_q4(cpx, mv.1, false),
29580- mv_to_q4(cpy, mv.0, false),
29741+ mv_to_q4(cpx, mv.1, ss_x(fctx)),
29742+ mv_to_q4(cpy, mv.0, ss_x(fctx)),
2958129743 chroma_side,
2958229744 chroma_side,
2958329745 write_chroma_w,
@@ -29591,8 +29753,8 @@ fn decode_inter_block(
2959129753 pv_ref.width,
2959229754 pv_ref.true_width,
2959329755 pv_ref.true_height,
29594- mv_to_q4(cpx, mv.1, false),
29595- mv_to_q4(cpy, mv.0, false),
29756+ mv_to_q4(cpx, mv.1, ss_x(fctx)),
29757+ mv_to_q4(cpy, mv.0, ss_x(fctx)),
2959629758 chroma_side,
2959729759 chroma_side,
2959829760 write_chroma_w,
@@ -29607,8 +29769,8 @@ fn decode_inter_block(
2960729769 py_ref.width,
2960829770 py_ref.true_width,
2960929771 py_ref.true_height,
29610- mv_to_q4(px, mv.1, true),
29611- mv_to_q4(py, mv.0, true),
29772+ mv_to_q4(px, mv.1, 0),
29773+ mv_to_q4(py, mv.0, 0),
2961229774 luma_scale,
2961329775 side,
2961429776 side,
@@ -29623,8 +29785,8 @@ fn decode_inter_block(
2962329785 pu_ref.width,
2962429786 pu_ref.true_width,
2962529787 pu_ref.true_height,
29626- mv_to_q4(cpx, mv.1, false),
29627- mv_to_q4(cpy, mv.0, false),
29788+ mv_to_q4(cpx, mv.1, ss_x(fctx)),
29789+ mv_to_q4(cpy, mv.0, ss_x(fctx)),
2962829790 luma_scale,
2962929791 chroma_side,
2963029792 chroma_side,
@@ -29639,8 +29801,8 @@ fn decode_inter_block(
2963929801 pv_ref.width,
2964029802 pv_ref.true_width,
2964129803 pv_ref.true_height,
29642- mv_to_q4(cpx, mv.1, false),
29643- mv_to_q4(cpy, mv.0, false),
29804+ mv_to_q4(cpx, mv.1, ss_x(fctx)),
29805+ mv_to_q4(cpy, mv.0, ss_x(fctx)),
2964429806 luma_scale,
2964529807 chroma_side,
2964629808 chroma_side,
@@ -29684,12 +29846,12 @@ fn decode_inter_block(
2968429846 crate::warp::warp_affine(
2968529847 params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32,
2968629848 pu_ref.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32,
29687- chroma_side as i32, chroma_side as i32, 1, 1, fctx,
29849+ chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
2968829850 );
2968929851 crate::warp::warp_affine(
2969029852 params, &pv_ref.data, pv_ref.true_width as i32, pv_ref.true_height as i32,
2969129853 pv_ref.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_side as i32,
29692- chroma_side as i32, chroma_side as i32, 1, 1, fctx,
29854+ chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
2969329855 );
2969429856 }
2969529857 }
@@ -29736,8 +29898,8 @@ fn decode_inter_block(
2973629898 src.width,
2973729899 src.true_width,
2973829900 src.true_height,
29739- mv_to_q4(cpx, prev_mv.1, false),
29740- mv_to_q4(cpy, prev_mv.0, false),
29901+ mv_to_q4(cpx, prev_mv.1, ss_x(fctx)),
29902+ mv_to_q4(cpy, prev_mv.0, ss_x(fctx)),
2974129903 prev_scale,
2974229904 piece_w,
2974329905 piece_h,
@@ -31284,7 +31446,7 @@ fn decode_inter_sub8_split4(
3128431446 hit!(SUB8_INTER_SPLIT_HITS);
3128531447 let (gr, gc) = group_mi;
3128631448 let (gpx, gpy) = (gc * MI, gr * MI);
31287- let (cpx, cpy) = (gpx / 2, gpy / 2);
31449+ let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
3128831450 // Per-sub-block state the group's chroma prediction needs (spec
3128931451 // 7.11.3.1's candRow/candCol loop reads each sub-block's OWN mv/ref/
3129031452 // filters), indexed `dr * 2 + dc`.
@@ -31577,8 +31739,8 @@ fn decode_inter_sub8_split4(
3157731739 sref_y.width,
3157831740 sref_y.true_width,
3157931741 sref_y.true_height,
31580- mv_to_q4(px, mv.1, true),
31581- mv_to_q4(py, mv.0, true),
31742+ mv_to_q4(px, mv.1, 0),
31743+ mv_to_q4(py, mv.0, 0),
3158231744 luma_scale,
3158331745 B4,
3158431746 B4,
@@ -31713,8 +31875,8 @@ fn decode_inter_sub8_split4(
3171331875 plane.width,
3171431876 plane.true_width,
3171531877 plane.true_height,
31716- mv_to_q4(ox, mv.1, false),
31717- mv_to_q4(oy, mv.0, false),
31878+ mv_to_q4(ox, mv.1, ss_x(fctx)),
31879+ mv_to_q4(oy, mv.0, ss_x(fctx)),
3171831880 piece_scale,
3171931881 pw,
3172031882 ph,
@@ -32194,7 +32356,7 @@ fn decode_intra_sub8_leaf(
3219432356 // chroma-reference block's own type. Same body as [`decode_leaf_rect8`]'s
3219532357 // post-loop chroma.
3219632358 let (gpx, gpy) = (gc * MI, gr * MI);
32197- let (cpx, cpy) = (gpx / 2, gpy / 2);
32359+ let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
3219832360 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);
3219932361 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(gr, gc, r, c);
3220032362 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
@@ -32324,7 +32486,7 @@ fn decode_inter_sub8_rect2(
3232432486 }
3232532487 let (gr, gc) = group_mi;
3232632488 let (gpx, gpy) = (gc * MI, gr * MI);
32327- let (cpx, cpy) = (gpx / 2, gpy / 2);
32489+ let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
3232832490 // Per-sub-block state the group's one chroma unit predicts from.
3232932491 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =
3233032492 [None; 2];
@@ -32632,8 +32794,8 @@ fn decode_inter_sub8_rect2(
3263232794 sref_y.width,
3263332795 sref_y.true_width,
3263432796 sref_y.true_height,
32635- mv_to_q4(px, mv.1, true),
32636- mv_to_q4(py, mv.0, true),
32797+ mv_to_q4(px, mv.1, 0),
32798+ mv_to_q4(py, mv.0, 0),
3263732799 luma_scale,
3263832800 bw,
3263932801 bh,
@@ -32819,8 +32981,8 @@ fn decode_inter_sub8_rect2(
3281932981 plane.width,
3282032982 plane.true_width,
3282132983 plane.true_height,
32822- mv_to_q4(ox, mv.1, false),
32823- mv_to_q4(oy, mv.0, false),
32984+ mv_to_q4(ox, mv.1, ss_x(fctx)),
32985+ mv_to_q4(oy, mv.0, ss_x(fctx)),
3282432986 piece_scale,
3282532987 piece_w,
3282632988 piece_h,
@@ -33074,7 +33236,7 @@ fn decode_inter_block8(
3307433236 const SIZE_GROUP_8: usize = 1;
3307533237
3307633238 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
33077- let (cpx, cpy) = (px / 2, py / 2);
33239+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
3307833240 // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
3307933241 // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
3308033242 // read back by the luma residual read and the tail's neighbour/loop-filter
@@ -33534,8 +33696,8 @@ fn decode_inter_block8(
3353433696 py0.width,
3353533697 py0.true_width,
3353633698 py0.true_height,
33537- mv_to_q4(px, mv0.1, true),
33538- mv_to_q4(py, mv0.0, true),
33699+ mv_to_q4(px, mv0.1, 0),
33700+ mv_to_q4(py, mv0.0, 0),
3353933701 scale0,
3354033702 SIDE,
3354133703 SIDE,
@@ -33556,8 +33718,8 @@ fn decode_inter_block8(
3355633718 py1.width,
3355733719 py1.true_width,
3355833720 py1.true_height,
33559- mv_to_q4(px, mv1.1, true),
33560- mv_to_q4(py, mv1.0, true),
33721+ mv_to_q4(px, mv1.1, 0),
33722+ mv_to_q4(py, mv1.0, 0),
3356133723 scale1,
3356233724 SIDE,
3356333725 SIDE,
@@ -33596,8 +33758,8 @@ fn decode_inter_block8(
3359633758 pu0.width,
3359733759 pu0.true_width,
3359833760 pu0.true_height,
33599- mv_to_q4(cpx, mv0.1, false),
33600- mv_to_q4(cpy, mv0.0, false),
33761+ mv_to_q4(cpx, mv0.1, ss_x(fctx)),
33762+ mv_to_q4(cpy, mv0.0, ss_x(fctx)),
3360133763 scale0,
3360233764 CHROMA_SIDE,
3360333765 CHROMA_SIDE,
@@ -33611,8 +33773,8 @@ fn decode_inter_block8(
3361133773 pu1.width,
3361233774 pu1.true_width,
3361333775 pu1.true_height,
33614- mv_to_q4(cpx, mv1.1, false),
33615- mv_to_q4(cpy, mv1.0, false),
33776+ mv_to_q4(cpx, mv1.1, ss_x(fctx)),
33777+ mv_to_q4(cpy, mv1.0, ss_x(fctx)),
3361633778 scale1,
3361733779 CHROMA_SIDE,
3361833780 CHROMA_SIDE,
@@ -33629,7 +33791,7 @@ fn decode_inter_block8(
3362933791 SIDE,
3363033792 CHROMA_SIDE,
3363133793 CHROMA_SIDE,
33632- true,
33794+ ss_x(fctx) == 1 && ss_y(fctx) == 1,
3363333795 &mut pred_u, fctx,
3363433796 );
3363533797 } else {
@@ -33642,8 +33804,8 @@ fn decode_inter_block8(
3364233804 pv0.width,
3364333805 pv0.true_width,
3364433806 pv0.true_height,
33645- mv_to_q4(cpx, mv0.1, false),
33646- mv_to_q4(cpy, mv0.0, false),
33807+ mv_to_q4(cpx, mv0.1, ss_x(fctx)),
33808+ mv_to_q4(cpy, mv0.0, ss_x(fctx)),
3364733809 scale0,
3364833810 CHROMA_SIDE,
3364933811 CHROMA_SIDE,
@@ -33657,8 +33819,8 @@ fn decode_inter_block8(
3365733819 pv1.width,
3365833820 pv1.true_width,
3365933821 pv1.true_height,
33660- mv_to_q4(cpx, mv1.1, false),
33661- mv_to_q4(cpy, mv1.0, false),
33822+ mv_to_q4(cpx, mv1.1, ss_x(fctx)),
33823+ mv_to_q4(cpy, mv1.0, ss_x(fctx)),
3366233824 scale1,
3366333825 CHROMA_SIDE,
3366433826 CHROMA_SIDE,
@@ -33675,7 +33837,7 @@ fn decode_inter_block8(
3367533837 SIDE,
3367633838 CHROMA_SIDE,
3367733839 CHROMA_SIDE,
33678- true,
33840+ ss_x(fctx) == 1 && ss_y(fctx) == 1,
3367933841 &mut pred_v, fctx,
3368033842 );
3368133843 } else {
@@ -34311,8 +34473,8 @@ fn decode_inter_block8(
3431134473 plane.width,
3431234474 plane.true_width,
3431334475 plane.true_height,
34314- mv_to_q4(x, mv.1, luma),
34315- mv_to_q4(y, mv.0, luma),
34476+ mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
34477+ mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
3431634478 dim,
3431734479 dim,
3431834480 h_filter,
@@ -34325,8 +34487,8 @@ fn decode_inter_block8(
3432534487 plane.width,
3432634488 plane.true_width,
3432734489 plane.true_height,
34328- mv_to_q4(x, mv.1, luma),
34329- mv_to_q4(y, mv.0, luma),
34490+ mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
34491+ mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
3433034492 luma_scale,
3433134493 dim,
3433234494 dim,
@@ -34358,12 +34520,12 @@ fn decode_inter_block8(
3435834520 crate::warp::warp_affine(
3435934521 params, &sref_u.data, sref_u.true_width as i32, sref_u.true_height as i32,
3436034522 sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, CHROMA_SIDE as i32,
34361- CHROMA_SIDE as i32, CHROMA_SIDE as i32, 1, 1, fctx,
34523+ CHROMA_SIDE as i32, CHROMA_SIDE as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
3436234524 );
3436334525 crate::warp::warp_affine(
3436434526 params, &sref_v.data, sref_v.true_width as i32, sref_v.true_height as i32,
3436534527 sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, CHROMA_SIDE as i32,
34366- CHROMA_SIDE as i32, CHROMA_SIDE as i32, 1, 1, fctx,
34528+ CHROMA_SIDE as i32, CHROMA_SIDE as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
3436734529 );
3436834530 }
3436934531 }
@@ -35515,27 +35677,29 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3551535677 tile_x1: width,
3551635678 tile_y1: height,
3551735679 };
35680+ let (cw, ch) = (width >> ss_x(fctx), height >> ss_y(fctx));
35681+ let (ctw, cth) = (true_width >> ss_x(fctx), true_height >> ss_y(fctx));
3551835682 let mut u = PlaneBuf {
35519- data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),
35520- width: width / 2,
35521- height: height / 2,
35522- true_width: true_width / 2,
35523- true_height: true_height / 2,
35683+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
35684+ width: cw,
35685+ height: ch,
35686+ true_width: ctw,
35687+ true_height: cth,
3552435688 tile_x0: 0,
3552535689 tile_y0: 0,
35526- tile_x1: width / 2,
35527- tile_y1: height / 2,
35690+ tile_x1: cw,
35691+ tile_y1: ch,
3552835692 };
3552935693 let mut v = PlaneBuf {
35530- data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),
35531- width: width / 2,
35532- height: height / 2,
35533- true_width: true_width / 2,
35534- true_height: true_height / 2,
35694+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
35695+ width: cw,
35696+ height: ch,
35697+ true_width: ctw,
35698+ true_height: cth,
3553535699 tile_x0: 0,
3553635700 tile_y0: 0,
35537- tile_x1: width / 2,
35538- tile_y1: height / 2,
35701+ tile_x1: cw,
35702+ tile_y1: ch,
3553935703 };
3554035704
3554135705 let scan32 = default_scan(TX32);
@@ -35565,10 +35729,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3556535729 // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is
3556635730 // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width --
3556735731 // loop restoration runs after the superres upscale.
35568- let mut lr_grid = crate::restoration::RestorationGrid::new(
35732+ let mut lr_grid = crate::restoration::RestorationGrid::with_ss(
3556935733 lr,
3557035734 superres(fctx).map_or(frame_width, |(w, _)| w),
3557135735 frame_height,
35736+ fctx.subsampling_x.get(),
35737+ fctx.subsampling_y.get(),
3557235738 );
3557335739
3557435740 // lane-pipefilt: the loop filters of superblock row r run as soon as row
@@ -38226,7 +38392,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3822638392 tile_x1: out_w,
3822738393 tile_y1: in_h,
3822838394 };
38229- let (cw, ch, cuw) = (fw.div_ceil(2), fh.div_ceil(2), uw.div_ceil(2));
38395+ let (cw, ch, cuw) = (round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx)), round_ss(uw, ss_x(fctx)));
3823038396 y = up(&y, fw, fh, uw);
3823138397 u = up(&u, cw, ch, cuw);
3823238398 v = up(&v, cw, ch, cuw);
@@ -38304,8 +38470,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3830438470 width: true_width,
3830538471 height: true_height,
3830638472 y: crop(&y, true_width, true_height),
38307- u: crop(&u, true_width.div_ceil(2), true_height.div_ceil(2)),
38308- v: crop(&v, true_width.div_ceil(2), true_height.div_ceil(2)),
38473+ u: crop(&u, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))),
38474+ v: crop(&v, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))),
3830938475 })
3831038476 } else {
3831138477 None
@@ -38316,8 +38482,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
3831638482 width: fw,
3831738483 height: fh,
3831838484 y: crop_owned(y, fw, fh),
38319- u: crop_owned(u, fw.div_ceil(2), fh.div_ceil(2)),
38320- v: crop_owned(v, fw.div_ceil(2), fh.div_ceil(2)),
38485+ u: crop_owned(u, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
38486+ v: crop_owned(v, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
3832138487 },
3832238488 result_cdfs,
3832338489 motion_field,
@@ -40358,8 +40524,8 @@ mod tests {
4035840524 ref_y.width,
4035940525 ref_y.true_width,
4036040526 ref_y.true_height,
40361- mv_to_q4(px, left_mv.1, true),
40362- mv_to_q4(py, left_mv.0, true),
40527+ mv_to_q4(px, left_mv.1, 0),
40528+ mv_to_q4(py, left_mv.0, 0),
4036340529 side,
4036440530 side,
4036540531 &mut want_near, fctx,
@@ -40370,8 +40536,8 @@ mod tests {
4037040536 ref_y.width,
4037140537 ref_y.true_width,
4037240538 ref_y.true_height,
40373- mv_to_q4(px, above_mv.1, true),
40374- mv_to_q4(py, above_mv.0, true),
40539+ mv_to_q4(px, above_mv.1, 0),
40540+ mv_to_q4(py, above_mv.0, 0),
4037540541 side,
4037640542 side,
4037740543 &mut want_nearest, fctx,
crates/ec-av1/src/refusal_inventory.rsmodified+115 -32
@@ -78,7 +78,7 @@ const REFUSALS: &[&str] = &[
7878 // hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused
7979 // at the sequence header. Gate:
8080 // `a_non_420_subsampled_sequence_header_is_refused_by_name`.
81- "a chroma format other than 4:2:0 (subsampling_x/y != 1/1): every chroma extent in this decoder is hardcoded to 4:2:0 and the probe emits 4:2:0 planes only, so a 4:4:4/4:2:2 stream would decode silently wrong pixels",
81+ "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported",
8282 // lane-av1txr-r2: the third member of the same silent-garbage family.
8383 // `using_qmatrix`/`qm_y`/`qm_u`/`qm_v` are parsed by `ec-av1-syntax` but
8484 // read by NOTHING on the decode path -- dequantisation is `base_q_idx` +
@@ -356,7 +356,7 @@ const PROVEN: &[(&str, &str)] = &[
356356 // profile-0 CONTROL still decodes -- the refusal is exercised, not merely
357357 // present.
358358 (
359- "a chroma format other than 4:2:0 (subsampling_x/y != 1/1): every chroma extent in this decoder is hardcoded to 4:2:0 and the probe emits 4:2:0 planes only, so a 4:4:4/4:2:2 stream would decode silently wrong pixels",
359+ "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported",
360360 "a_non_420_subsampled_sequence_header_is_refused_by_name",
361361 ),
362362 // lane-av1txr-r2: the gate encodes the same source twice with real aomenc
@@ -584,7 +584,11 @@ mod tests {
584584 .chain(REFUSALS)
585585 .map(|&s| s.to_owned())
586586 .collect();
587- assert!(found.len() >= 30, "the refusal scan found only {} reasons -- it is broken, not the decoder", found.len());
587+ assert!(
588+ found.len() >= 30,
589+ "the refusal scan found only {} reasons -- it is broken, not the decoder",
590+ found.len()
591+ );
588592
589593 let added: Vec<&String> = found.difference(&listed).collect();
590594 assert!(
@@ -630,9 +634,14 @@ mod tests {
630634 let mut found: BTreeSet<String> = BTreeSet::new();
631635 for (i, _) in src.match_indices("\"SKIP ") {
632636 let rest = &src[i + "\"SKIP ".len()..];
633- let Some(colon) = rest.find(':') else { continue };
637+ let Some(colon) = rest.find(':') else {
638+ continue;
639+ };
634640 let name = &rest[..colon];
635- if !name.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') {
641+ if !name
642+ .chars()
643+ .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_')
644+ {
636645 continue;
637646 }
638647 // The tail of the message says what was skipped. Only "{e}" -- the
@@ -645,7 +654,10 @@ mod tests {
645654 }
646655 }
647656 let listed: BTreeSet<&str> = GATES_THAT_SKIP_ON_A_DECODE_ERROR.iter().copied().collect();
648- let added: Vec<&String> = found.iter().filter(|n| !listed.contains(n.as_str())).collect();
657+ let added: Vec<&String> = found
658+ .iter()
659+ .filter(|n| !listed.contains(n.as_str()))
660+ .collect();
649661 assert!(
650662 added.is_empty(),
651663 "these gates turn a decode error into a printed SKIP and are not declared: \
@@ -718,9 +730,18 @@ mod tests {
718730 fn every_partition_value_of_an_enumerated_alphabet_has_an_arm() {
719731 // (the refusal in the fallback arm, the alphabet its CDF codes)
720732 let blocks: [(&str, usize); 4] = [
721- ("a 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1),
722- ("an INTER 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1),
723- ("a 128x128 superblock partition value outside the 8-symbol alphabet", crate::cdf::PARTITION_W128[0].len() - 1),
733+ (
734+ "a 32x32 partition type this decoder does not code",
735+ crate::cdf::PARTITION_W32[0].len() - 1,
736+ ),
737+ (
738+ "an INTER 32x32 partition type this decoder does not code",
739+ crate::cdf::PARTITION_W32[0].len() - 1,
740+ ),
741+ (
742+ "a 128x128 superblock partition value outside the 8-symbol alphabet",
743+ crate::cdf::PARTITION_W128[0].len() - 1,
744+ ),
724745 // lane-t900 r24: the key-frame superblock root. Its `part` is
725746 // either a `partition_w64` symbol or, at a frame edge, one of the
726747 // three gathered outcomes (PARTITION_HORZ, PARTITION_VERT,
@@ -774,7 +795,10 @@ mod tests {
774795 "the `match` at decode.rs:{} refuses {reason:?} but has no arm for {:?} -- that \
775796 is a real gap in its {alphabet}-value alphabet, not a dead refusal",
776797 i + 1,
777- missing.iter().map(|v| PARTITION_NAMES[*v]).collect::<Vec<_>>()
798+ missing
799+ .iter()
800+ .map(|v| PARTITION_NAMES[*v])
801+ .collect::<Vec<_>>()
778802 );
779803 }
780804 assert_eq!(
@@ -828,7 +852,11 @@ mod tests {
828852 .next()
829853 .unwrap_or("")
830854 .to_owned();
831- assert!(!var.is_empty(), "the chain at decode.rs:{} tests nothing", head + 1);
855+ assert!(
856+ !var.is_empty(),
857+ "the chain at decode.rs:{} tests nothing",
858+ head + 1
859+ );
832860
833861 // Walk up collecting every branch head of this chain, each read to
834862 // the line that opens its body.
@@ -838,7 +866,8 @@ mod tests {
838866 loop {
839867 i -= 1;
840868 let t = lines[i].trim_start();
841- if indent(lines[i]) != outer || !(t.starts_with("} else if ") || t.starts_with("if "))
869+ if indent(lines[i]) != outer
870+ || !(t.starts_with("} else if ") || t.starts_with("if "))
842871 {
843872 if i == 0 {
844873 break;
@@ -888,7 +917,10 @@ mod tests {
888917 "the chain at decode.rs:{} refuses {reason:?} but no branch names {:?} -- that \
889918 is a real gap in its {alphabet}-value alphabet, not a dead refusal",
890919 head + 1,
891- missing.iter().map(|v| PARTITION_NAMES[*v]).collect::<Vec<_>>()
920+ missing
921+ .iter()
922+ .map(|v| PARTITION_NAMES[*v])
923+ .collect::<Vec<_>>()
892924 );
893925 }
894926 assert_eq!(found, chains.len());
@@ -991,11 +1023,18 @@ mod tests {
9911023 values.insert(((1u64 << length) - 2) as u32);
9921024 }
9931025 let max = *values.iter().max().unwrap();
994- assert_eq!(max, (1u32 << 20) - 2, "the enumeration misses the spec's own ceiling");
1026+ assert_eq!(
1027+ max,
1028+ (1u32 << 20) - 2,
1029+ "the enumeration misses the spec's own ceiling"
1030+ );
9951031 // A coefficient is masked to 20 bits (spec 5.11.39), and the base and
9961032 // base-range syntax contribute at most 15 of that before the tail, so
9971033 // this is the largest tail a legal coefficient can need.
998- assert!(max >= 0xF_FFFF - 15, "the ceiling is below the largest legal tail");
1034+ assert!(
1035+ max >= 0xF_FFFF - 15,
1036+ "the ceiling is below the largest legal tail"
1037+ );
9991038 for value in values {
10001039 match roundtrip(value) {
10011040 Ok(read) => assert_eq!(read, value, "the Golomb tail {value} read back as {read}"),
@@ -1051,7 +1090,11 @@ mod tests {
10511090 ];
10521091 assert_eq!(alphabets[0].1, 13, "the y_mode alphabet changed size");
10531092 for group in &crate::cdf::Y_MODE {
1054- assert_eq!(group.len() - 1, alphabets[0].1, "the y_mode rows disagree on width");
1093+ assert_eq!(
1094+ group.len() - 1,
1095+ alphabets[0].1,
1096+ "the y_mode rows disagree on width"
1097+ );
10551098 }
10561099
10571100 let src = include_str!("decode.rs");
@@ -1059,12 +1102,17 @@ mod tests {
10591102 let mut sites = 0usize;
10601103 for (i, line) in lines.iter().enumerate() {
10611104 let t = line.trim();
1062- let Some(rest) = t.strip_prefix("if mode >= ") else { continue };
1105+ let Some(rest) = t.strip_prefix("if mode >= ") else {
1106+ continue;
1107+ };
10631108 let Some(threshold) = rest.trim_end_matches(" {").parse::<usize>().ok() else {
10641109 continue;
10651110 };
10661111 // Only the guards carrying THIS refusal.
1067- if !lines[i..(i + 4).min(lines.len())].join("\n").contains(REFUSAL) {
1112+ if !lines[i..(i + 4).min(lines.len())]
1113+ .join("\n")
1114+ .contains(REFUSAL)
1115+ {
10681116 continue;
10691117 }
10701118 sites += 1;
@@ -1094,7 +1142,10 @@ mod tests {
10941142 i + 1
10951143 );
10961144 }
1097- assert_eq!(sites, 3, "the intra-mode guard is at three sites, found {sites}");
1145+ assert_eq!(
1146+ sites, 3,
1147+ "the intra-mode guard is at three sites, found {sites}"
1148+ );
10981149 }
10991150
11001151 /// lane-t900 r31, ENUMERATION for "a HORZ/VERT intra strip in a
@@ -1154,7 +1205,10 @@ mod tests {
11541205 }
11551206 }
11561207 }
1157- assert!(with_128 > 0, "enumeration is vacuous -- no 128-sided footprint was tried");
1208+ assert!(
1209+ with_128 > 0,
1210+ "enumeration is vacuous -- no 128-sided footprint was tried"
1211+ );
11581212 assert_eq!(
11591213 allowed_at_128, 0,
11601214 "a footprint with a 128-pixel side passed av1_allow_palette's bound -- the \
@@ -1266,11 +1320,17 @@ mod tests {
12661320 // (3) The two tables, read out of decode_rect_split's own text: every
12671321 // `(w, h) =>` / `(w, h) |` match arm head between the table's `let`
12681322 // and the guard that follows it.
1269- let body_at = src.find("fn decode_rect_split(").expect("decode_rect_split is gone");
1323+ let body_at = src
1324+ .find("fn decode_rect_split(")
1325+ .expect("decode_rect_split is gone");
12701326 let body = &src[body_at..];
12711327 let slice = |from: &str, to: &str| -> &str {
1272- let a = body.find(from).unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split"));
1273- let b = body[a..].find(to).unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split"));
1328+ let a = body
1329+ .find(from)
1330+ .unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split"));
1331+ let b = body[a..]
1332+ .find(to)
1333+ .unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split"));
12741334 &body[a..a + b]
12751335 };
12761336 let arm_shapes = |text: &str| -> BTreeSet<(usize, usize)> {
@@ -1343,7 +1403,10 @@ mod tests {
13431403 }
13441404 }
13451405 }
1346- assert_eq!(checked, 40, "the strip domain is not the ten rect shapes x four depths");
1406+ assert_eq!(
1407+ checked, 40,
1408+ "the strip domain is not the ten rect shapes x four depths"
1409+ );
13471410 }
13481411
13491412 /// lane-t900 r33, ENUMERATION for "CfL, filter intra or a palette on a
@@ -1453,9 +1516,15 @@ mod tests {
14531516 }
14541517 continue;
14551518 }
1456- let Some(rest) = line.strip_prefix('(') else { continue };
1457- let Some((pair, _)) = rest.split_once(") =>") else { continue };
1458- let Some((a, b)) = pair.split_once(',') else { continue };
1519+ let Some(rest) = line.strip_prefix('(') else {
1520+ continue;
1521+ };
1522+ let Some((pair, _)) = rest.split_once(") =>") else {
1523+ continue;
1524+ };
1525+ let Some((a, b)) = pair.split_once(',') else {
1526+ continue;
1527+ };
14591528 let bw: usize = a.trim().parse().expect("arm bw");
14601529 let bh: usize = b.trim().parse().expect("arm bh");
14611530 assert!(
@@ -1467,9 +1536,18 @@ mod tests {
14671536 seen.push((bw, bh));
14681537 arms += 1;
14691538 }
1470- assert!(arms >= 10, "only {arms} arms parsed -- the table's shape changed");
1471- assert!(saw_none_fallback, "filter_intra_size_class_rect lost its `_ => None` fallback");
1472- assert!(saw_square_delegate, "filter_intra_size_class_rect lost its square-delegate arm");
1539+ assert!(
1540+ arms >= 10,
1541+ "only {arms} arms parsed -- the table's shape changed"
1542+ );
1543+ assert!(
1544+ saw_none_fallback,
1545+ "filter_intra_size_class_rect lost its `_ => None` fallback"
1546+ );
1547+ assert!(
1548+ saw_square_delegate,
1549+ "filter_intra_size_class_rect lost its square-delegate arm"
1550+ );
14731551 // The guard arm delegates square strips to `filter_intra_size_class`;
14741552 // drive the delegate directly, so a widening there turns THIS test red
14751553 // (the numeric walk never reaches the guard arm).
@@ -1519,7 +1597,10 @@ mod tests {
15191597 );
15201598 }
15211599 }
1522- assert_eq!(sites, 8, "the call-site audit found {sites} sites, not the 8 it enumerated");
1600+ assert_eq!(
1601+ sites, 8,
1602+ "the call-site audit found {sites} sites, not the 8 it enumerated"
1603+ );
15231604 }
15241605
15251606 /// Every entry of [`PROVEN`] must still name a live refusal and a test
@@ -1538,7 +1619,9 @@ mod tests {
15381619 "{reason:?} is listed as proven but is no longer a decode-path refusal -- drop it from PROVEN (the capability landed) or fix the string"
15391620 );
15401621 assert!(
1541- sources.iter().any(|src| src.contains(&format!("fn {gate}("))),
1622+ sources
1623+ .iter()
1624+ .any(|src| src.contains(&format!("fn {gate}("))),
15421625 "{reason:?} names the proving test {gate}, which exists in neither stream.rs \
15431626 nor decode.rs"
15441627 );
crates/ec-av1/src/restoration.rsmodified+223 -68
@@ -63,7 +63,12 @@ fn inverse_recenter(r: u32, v: u32) -> u32 {
6363 /// `aom_read_primitive_refsubexpfin` (`inv_recenter_finite_nonneg` composed
6464 /// with `read_primitive_subexpfin`): a value in `[0, n)` recentred around
6565 /// `reference`.
66-fn decode_unsigned_subexp_with_ref_msac(dec: &mut SymbolDecoder, n: u32, k: u32, reference: u32) -> u32 {
66+fn decode_unsigned_subexp_with_ref_msac(
67+ dec: &mut SymbolDecoder,
68+ n: u32,
69+ k: u32,
70+ reference: u32,
71+) -> u32 {
6772 let v = decode_subexp_msac(dec, n, k);
6873 if (reference << 1) <= n {
6974 inverse_recenter(reference, v)
@@ -74,7 +79,13 @@ fn decode_unsigned_subexp_with_ref_msac(dec: &mut SymbolDecoder, n: u32, k: u32,
7479
7580 /// Signed wrapper, matching the way `read_wiener_filter`/`read_sgrproj_filter`
7681 /// call `aom_read_primitive_refsubexpfin(rb, max-min+1, k, ref-min)+min`.
77-fn decode_signed_subexp_with_ref_msac(dec: &mut SymbolDecoder, low: i32, high: i32, k: u32, reference: i32) -> i32 {
82+fn decode_signed_subexp_with_ref_msac(
83+ dec: &mut SymbolDecoder,
84+ low: i32,
85+ high: i32,
86+ k: u32,
87+ reference: i32,
88+) -> i32 {
7889 let n = (high - low) as u32;
7990 let r = (reference - low).clamp(0, n as i32) as u32;
8091 decode_unsigned_subexp_with_ref_msac(dec, n, k, r) as i32 + low
@@ -274,7 +285,11 @@ fn read_wiener_direction(dec: &mut SymbolDecoder, chroma: bool, reference: &[i32
274285
275286 /// `read_wiener_filter` (decodeframe.c ~1595): both directions, updating
276287 /// `reference` in place (the running per-plane, per-tile reference state).
277-fn read_wiener_filter(dec: &mut SymbolDecoder, chroma: bool, reference: &mut WienerInfo) -> WienerInfo {
288+fn read_wiener_filter(
289+ dec: &mut SymbolDecoder,
290+ chroma: bool,
291+ reference: &mut WienerInfo,
292+) -> WienerInfo {
278293 let vfilter = read_wiener_direction(dec, chroma, &reference.vfilter);
279294 let hfilter = read_wiener_direction(dec, chroma, &reference.hfilter);
280295 let info = WienerInfo { vfilter, hfilter };
@@ -400,6 +415,16 @@ pub(crate) struct RestorationGrid {
400415
401416 impl RestorationGrid {
402417 pub(crate) fn new(lr: &LoopRestorationParams, frame_width: u32, frame_height: u32) -> Self {
418+ Self::with_ss(lr, frame_width, frame_height, 1, 1)
419+ }
420+
421+ pub(crate) fn with_ss(
422+ lr: &LoopRestorationParams,
423+ frame_width: u32,
424+ frame_height: u32,
425+ ss_x: u8,
426+ ss_y: u8,
427+ ) -> Self {
403428 let mut horz_units = [1usize; 3];
404429 let mut vert_units = [1usize; 3];
405430 let mut units: [Vec<UnitFilter>; 3] = [Vec::new(), Vec::new(), Vec::new()];
@@ -410,7 +435,10 @@ impl RestorationGrid {
410435 let (pw, ph) = if plane == 0 {
411436 (frame_width, frame_height)
412437 } else {
413- ((frame_width + 1) / 2, (frame_height + 1) / 2)
438+ (
439+ (frame_width + u32::from(ss_x)) >> ss_x,
440+ (frame_height + u32::from(ss_y)) >> ss_y,
441+ )
414442 };
415443 let unit_size = lr.loop_restoration_size[plane];
416444 horz_units[plane] = count_units(pw, unit_size);
@@ -462,7 +490,8 @@ pub(crate) fn read_lr(
462490 reference: &mut [(WienerInfo, SgrprojInfo); 3],
463491 mi_row: u32,
464492 mi_col: u32,
465- sb_mi: u32, fctx: &crate::decode::FrameCtx,
493+ sb_mi: u32,
494+ fctx: &crate::decode::FrameCtx,
466495 ) {
467496 if !lr.uses_lr {
468497 return;
@@ -472,7 +501,11 @@ pub(crate) fn read_lr(
472501 if ftype == RestorationType::None {
473502 continue;
474503 }
475- let mi_size = if plane == 0 { 4u32 } else { 2u32 };
504+ let mi_size = if plane == 0 {
505+ 4u32
506+ } else {
507+ 4u32 >> (crate::decode::ss_x(fctx) as u32)
508+ };
476509 let unit_size = lr.loop_restoration_size[plane];
477510 let horz_units = grid.horz_units[plane] as u32;
478511 let vert_units = grid.vert_units[plane] as u32;
@@ -636,8 +669,16 @@ fn lr_sample(
636669 ) -> i32 {
637670 let col_c = col.clamp(0, plane_w as i64 - 1) as usize;
638671 i32::from(
639- lr_src_row(cdef, deblocked, stride, plane_w, plane_h, stripe_v_start, stripe_v_end, row)
640- [col_c],
672+ lr_src_row(
673+ cdef,
674+ deblocked,
675+ stride,
676+ plane_w,
677+ plane_h,
678+ stripe_v_start,
679+ stripe_v_end,
680+ row,
681+ )[col_c],
641682 )
642683 }
643684
@@ -671,7 +712,11 @@ fn lr_src_row<'a>(
671712 let dist = stripe_v_start as i64 - 1 - row;
672713 (
673714 deblocked,
674- if dist == 0 { stripe_v_start - 1 } else { stripe_v_start.saturating_sub(2) },
715+ if dist == 0 {
716+ stripe_v_start - 1
717+ } else {
718+ stripe_v_start.saturating_sub(2)
719+ },
675720 )
676721 }
677722 } else if stripe_v_end == plane_h {
@@ -712,7 +757,8 @@ fn apply_wiener_stripe(
712757 h_end: usize,
713758 v_start: usize,
714759 v_end: usize,
715- info: &WienerInfo, fctx: &crate::decode::FrameCtx,
760+ info: &WienerInfo,
761+ fctx: &crate::decode::FrameCtx,
716762 ) {
717763 let w = h_end - h_start;
718764 let h = v_end - v_start;
@@ -738,8 +784,16 @@ fn apply_wiener_stripe(
738784 // stripe substitution is resolved once per row by `lr_src_row`, and only
739785 // a unit touching the plane's left or right edge needs the clamped copy.
740786 let hf = &info.hfilter;
741- let t16: [i16; 8] =
742- [hf[0] as i16, hf[1] as i16, hf[2] as i16, hf[3] as i16, hf[4] as i16, hf[5] as i16, hf[6] as i16, 0];
787+ let t16: [i16; 8] = [
788+ hf[0] as i16,
789+ hf[1] as i16,
790+ hf[2] as i16,
791+ hf[3] as i16,
792+ hf[4] as i16,
793+ hf[5] as i16,
794+ hf[6] as i16,
795+ 0,
796+ ];
743797 // lane-mc: the intermediate is `i16` now. Both bounds are inside that
744798 // range at 8- and 10-bit (12-bit is refused in stream.rs), so the
745799 // kernel's saturating store composes with this clamp instead of changing
@@ -748,7 +802,9 @@ fn apply_wiener_stripe(
748802 let mut hbuf = WIENER_ROW_SCRATCH.with(|c| std::mem::take(&mut *c.borrow_mut()));
749803 for r in 0..rows {
750804 let row = v_start as i64 - 3 + r as i64;
751- let src = lr_src_row(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row);
805+ let src = lr_src_row(
806+ cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row,
807+ );
752808 let lo = h_start as i64 - 3;
753809 let out = &mut inter[r * w..r * w + w];
754810 if lo >= 0 && lo as usize + w + 7 <= plane_w {
@@ -815,31 +871,27 @@ thread_local! {
815871 // `~/.cache/aom-oracle/src/av1/common/restoration.c` to rule out any other
816872 // transcription slip.
817873 const SGR_X_BY_XPLUS1: [i32; 256] = [
818- 1, 128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239,
819- 240, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 247, 247,
820- 248, 248, 248, 248, 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250,
821- 250, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 252, 252, 252, 252,
822- 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253,
823- 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253,
824- 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 254, 254, 254,
825- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
826- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
827- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
828- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
829- 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
830- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
831- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
832- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
833- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
834- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
835- 256,
874+ 1, 128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239, 240, 241, 242, 243,
875+ 243, 244, 244, 245, 245, 246, 246, 247, 247, 247, 247, 248, 248, 248, 248, 249, 249, 249, 249,
876+ 249, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 252,
877+ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253,
878+ 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253,
879+ 253, 253, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
880+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
881+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
882+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255,
883+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
884+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
885+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
886+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
887+ 255, 255, 255, 255, 255, 255, 255, 255, 256,
836888 ];
837889
838890 /// `av1_one_by_x` (`restoration.c`): `round(4096/n)` for `n` in `1..=25`
839891 /// (`MAX_NELEM`, `(2*MAX_RADIUS+1)^2`), indexed `[n-1]`.
840892 const SGR_ONE_BY_X: [i32; 25] = [
841- 4096, 2048, 1365, 1024, 819, 683, 585, 512, 455, 410, 372, 341, 315, 293, 273, 256, 241, 228, 216, 205, 195, 186,
842- 178, 171, 164,
893+ 4096, 2048, 1365, 1024, 819, 683, 585, 512, 455, 410, 372, 341, 315, 293, 273, 256, 241, 228,
894+ 216, 205, 195, 186, 178, 171, 164,
843895 ];
844896
845897 const SGRPROJ_MTABLE_BITS: u32 = 20;
@@ -877,7 +929,8 @@ fn compute_ab(
877929 // stripe, ~70 KB each at a 64-wide unit), i.e. an allocation whose every
878930 // page then faulted in on first touch. Every entry is written below, so
879931 // the resize's fill value is never read.
880- ab: &mut Vec<(i32, i64)>, fctx: &crate::decode::FrameCtx,
932+ ab: &mut Vec<(i32, i64)>,
933+ fctx: &crate::decode::FrameCtx,
881934 ) {
882935 let gw = w + 2;
883936 let gh = h + 2;
@@ -927,8 +980,9 @@ fn compute_ab(
927980 let i = gi as i64 - 1;
928981 {
929982 let mut accumulate = |row: i64, add: bool| {
930- let src =
931- lr_src_row(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row);
983+ let src = lr_src_row(
984+ cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row,
985+ );
932986 fill_clamped_row(src, plane_w, base_col, &mut samp);
933987 if add {
934988 for ((c_a, c_b), &px) in col_a.iter_mut().zip(col_b.iter_mut()).zip(samp.iter())
@@ -967,7 +1021,15 @@ fn compute_ab(
9671021 a_row[gj] = a;
9681022 b_row[gj] = b;
9691023 }
970- ab_row(a_row, b_row, n, s, bd_shift, one_by_x, &mut ab[gi * gw..gi * gw + gw]);
1024+ ab_row(
1025+ a_row,
1026+ b_row,
1027+ n,
1028+ s,
1029+ bd_shift,
1030+ one_by_x,
1031+ &mut ab[gi * gw..gi * gw + gw],
1032+ );
9711033 let dump_gj = 6i64 - h_start as i64 + 1;
9721034 if dump && v_start as i64 + i == 60 && r == 1 && (0..gw as i64).contains(&dump_gj) {
9731035 let gj = dump_gj as usize;
@@ -1006,14 +1068,22 @@ fn ab_point(a: i32, b: i32, n: i32, s: i32, bd_shift: u32, one_by_x: i64) -> (i3
10061068 let b_s = round2_u31(b, bd_shift);
10071069 let p = (a_s * n - b_s * b_s).max(0);
10081070 let a_val = SGR_X_BY_XPLUS1[z_index(p, s)];
1009- let b_val = round2((256 - a_val) as i64 * i64::from(b) * one_by_x, SGRPROJ_RECIP_BITS);
1071+ let b_val = round2(
1072+ (256 - a_val) as i64 * i64::from(b) * one_by_x,
1073+ SGRPROJ_RECIP_BITS,
1074+ );
10101075 (a_val, b_val)
10111076 }
10121077
10131078 /// One grid row's `(A, B)` pairs: [`ab_point`] per element, eight at a time
10141079 /// under AVX2 (the kernel is that arithmetic lane-wise, same widths).
10151080 fn ab_row(
1016- a_row: &[i32], b_row: &[i32], n: i32, s: i32, bd_shift: u32, one_by_x: i64,
1081+ a_row: &[i32],
1082+ b_row: &[i32],
1083+ n: i32,
1084+ s: i32,
1085+ bd_shift: u32,
1086+ one_by_x: i64,
10171087 out: &mut [(i32, i64)],
10181088 ) {
10191089 let mut done = 0usize;
@@ -1054,7 +1124,12 @@ mod sgr_simd {
10541124 #[target_feature(enable = "avx2")]
10551125 #[allow(clippy::too_many_arguments)]
10561126 pub unsafe fn ab_row_avx2(
1057- a_row: &[i32], b_row: &[i32], n: i32, s: i32, bd_shift: u32, one_by_x: i32,
1127+ a_row: &[i32],
1128+ b_row: &[i32],
1129+ n: i32,
1130+ s: i32,
1131+ bd_shift: u32,
1132+ one_by_x: i32,
10581133 out: &mut [(i32, i64)],
10591134 ) -> usize {
10601135 let len = out.len().min(a_row.len()).min(b_row.len());
@@ -1070,8 +1145,16 @@ mod sgr_simd {
10701145 let sh_b = _mm_cvtsi32_si128(SGRPROJ_RECIP_BITS as i32);
10711146 let sh_a = _mm_cvtsi32_si128(2 * bd_shift as i32);
10721147 let sh_bd = _mm_cvtsi32_si128(bd_shift as i32);
1073- let rnd_a = _mm256_set1_epi32(if bd_shift == 0 { 0 } else { 1 << (2 * bd_shift - 1) });
1074- let rnd_bd = _mm256_set1_epi32(if bd_shift == 0 { 0 } else { 1 << (bd_shift - 1) });
1148+ let rnd_a = _mm256_set1_epi32(if bd_shift == 0 {
1149+ 0
1150+ } else {
1151+ 1 << (2 * bd_shift - 1)
1152+ });
1153+ let rnd_bd = _mm256_set1_epi32(if bd_shift == 0 {
1154+ 0
1155+ } else {
1156+ 1 << (bd_shift - 1)
1157+ });
10751158 let mut av = [0i32; 8];
10761159 let mut bv = [0i32; 8];
10771160 let mut gj = 0usize;
@@ -1115,7 +1198,11 @@ mod sgr_simd {
11151198 /// width narrower).
11161199 #[inline]
11171200 fn round2_u31(value: i32, shift: u32) -> i32 {
1118- if shift == 0 { value } else { (value + (1 << (shift - 1))) >> shift }
1201+ if shift == 0 {
1202+ value
1203+ } else {
1204+ (value + (1 << (shift - 1))) >> shift
1205+ }
11191206 }
11201207
11211208 /// Copies one source row's `out.len()` samples starting at `base_col` into a
@@ -1150,7 +1237,8 @@ fn apply_sgrproj_stripe(
11501237 h_end: usize,
11511238 v_start: usize,
11521239 v_end: usize,
1153- info: &SgrprojInfo, fctx: &crate::decode::FrameCtx,
1240+ info: &SgrprojInfo,
1241+ fctx: &crate::decode::FrameCtx,
11541242 ) {
11551243 let w = h_end - h_start;
11561244 let h = v_end - v_start;
@@ -1166,10 +1254,16 @@ fn apply_sgrproj_stripe(
11661254 (std::mem::take(&mut m.0), std::mem::take(&mut m.1))
11671255 });
11681256 if r0 > 0 {
1169- compute_ab(cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r0, s0, &mut buf0, fctx);
1257+ compute_ab(
1258+ cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r0, s0,
1259+ &mut buf0, fctx,
1260+ );
11701261 }
11711262 if r1 > 0 {
1172- compute_ab(cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r1, s1, &mut buf1, fctx);
1263+ compute_ab(
1264+ cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r1, s1,
1265+ &mut buf1, fctx,
1266+ );
11731267 }
11741268 let ab0 = (r0 > 0).then_some(&buf0);
11751269 let ab1 = (r1 > 0).then_some(&buf1);
@@ -1185,7 +1279,9 @@ fn apply_sgrproj_stripe(
11851279 let bytes: Vec<i32> = (59..=61)
11861280 .flat_map(|row| {
11871281 (5..=7).map(move |col| {
1188- lr_sample(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, col)
1282+ lr_sample(
1283+ cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, col,
1284+ )
11891285 })
11901286 })
11911287 .collect();
@@ -1265,7 +1361,8 @@ fn apply_sgrproj_stripe(
12651361 let (a_ur, b_ur) = ab[idx(i - 1, j + 1)];
12661362 let (a_dl, b_dl) = ab[idx(i + 1, j - 1)];
12671363 let (a_dr, b_dr) = ab[idx(i + 1, j + 1)];
1268- let a = (a_c + a_u + a_d + a_l + a_r) as i64 * 4 + (a_ul + a_ur + a_dl + a_dr) as i64 * 3;
1364+ let a = (a_c + a_u + a_d + a_l + a_r) as i64 * 4
1365+ + (a_ul + a_ur + a_dl + a_dr) as i64 * 3;
12691366 let b = (b_c + b_u + b_d + b_l + b_r) * 4 + (b_ul + b_ur + b_dl + b_dr) * 3;
12701367 let flt1 = round2(a * dgd + b, SGRPROJ_SGR_BITS + 5 - SGRPROJ_RST_BITS);
12711368 v += xq[1] as i64 * (flt1 - u);
@@ -1278,9 +1375,15 @@ fn apply_sgrproj_stripe(
12781375 "EC_LR_CALL_DUMP combine: c={:?} u_tap(row60)={:?} d={:?} l={:?} r={:?} \
12791376 ul={:?} ur={:?} dl={:?} dr={:?} dense a={a} b={b} dgd={dgd} \
12801377 u={u} flt1={flt1} xq={xq:?} v_before_final_round={v}",
1281- ab[idx(i, j)], ab[idx(i - 1, j)], ab[idx(i + 1, j)], ab[idx(i, j - 1)],
1282- ab[idx(i, j + 1)], ab[idx(i - 1, j - 1)], ab[idx(i - 1, j + 1)],
1283- ab[idx(i + 1, j - 1)], ab[idx(i + 1, j + 1)]
1378+ ab[idx(i, j)],
1379+ ab[idx(i - 1, j)],
1380+ ab[idx(i + 1, j)],
1381+ ab[idx(i, j - 1)],
1382+ ab[idx(i, j + 1)],
1383+ ab[idx(i - 1, j - 1)],
1384+ ab[idx(i - 1, j + 1)],
1385+ ab[idx(i + 1, j - 1)],
1386+ ab[idx(i + 1, j + 1)]
12841387 );
12851388 }
12861389 }
@@ -1311,7 +1414,8 @@ fn filter_restoration_unit(
13111414 v_start: usize,
13121415 v_end: usize,
13131416 ss_y: u32,
1314- filter: UnitFilter, fctx: &crate::decode::FrameCtx,
1417+ filter: UnitFilter,
1418+ fctx: &crate::decode::FrameCtx,
13151419 ) {
13161420 let full_stripe_height = 64usize >> ss_y;
13171421 let runit_offset = 8usize >> ss_y;
@@ -1333,10 +1437,32 @@ fn filter_restoration_unit(
13331437 }
13341438 match filter {
13351439 UnitFilter::Wiener(info) => apply_wiener_stripe(
1336- out, cdef, deblocked, stride, plane_w, plane_h, h_start, h_end, stripe_v_start, stripe_v_end, &info, fctx,
1440+ out,
1441+ cdef,
1442+ deblocked,
1443+ stride,
1444+ plane_w,
1445+ plane_h,
1446+ h_start,
1447+ h_end,
1448+ stripe_v_start,
1449+ stripe_v_end,
1450+ &info,
1451+ fctx,
13371452 ),
13381453 UnitFilter::Sgrproj(info) => apply_sgrproj_stripe(
1339- out, cdef, deblocked, stride, plane_w, plane_h, h_start, h_end, stripe_v_start, stripe_v_end, &info, fctx,
1454+ out,
1455+ cdef,
1456+ deblocked,
1457+ stride,
1458+ plane_w,
1459+ plane_h,
1460+ h_start,
1461+ h_end,
1462+ stripe_v_start,
1463+ stripe_v_end,
1464+ &info,
1465+ fctx,
13401466 ),
13411467 UnitFilter::None => {}
13421468 }
@@ -1395,12 +1521,16 @@ pub(crate) fn apply_loop_restoration_plane(
13951521 let out = unsafe { so.get() };
13961522 for rrow in r_lo..r_hi {
13971523 lr_unit_row(
1398- out, cdef, deblocked, stride, plane_w, plane_h, ss_y, unit_size, grid,
1399- plane, rrow, &rows, fctx,
1524+ out, cdef, deblocked, stride, plane_w, plane_h, ss_y, unit_size, grid, plane,
1525+ rrow, &rows, fctx,
14001526 );
14011527 }
14021528 });
1403- debug_assert_eq!(rows.len(), grid.vert_units[plane], "RU row walk must match RestorationGrid::new's count_units");
1529+ debug_assert_eq!(
1530+ rows.len(),
1531+ grid.vert_units[plane],
1532+ "RU row walk must match RestorationGrid::new's count_units"
1533+ );
14041534 return;
14051535 };
14061536 for rrow in r_lo..r_hi.min(rows.len()) {
@@ -1435,7 +1565,11 @@ pub(crate) fn lr_unit_rows(
14351565 let mut y0 = 0u32;
14361566 while y0 < plane_h as u32 {
14371567 let remaining_h = plane_h as u32 - y0;
1438- let uh = if remaining_h < ext_size { remaining_h } else { unit_size };
1568+ let uh = if remaining_h < ext_size {
1569+ remaining_h
1570+ } else {
1571+ unit_size
1572+ };
14391573 let v_start = (y0 as i64 - voffset as i64).max(0) as u32;
14401574 let mut v_end = y0 + uh;
14411575 if v_end < plane_h as u32 {
@@ -1471,7 +1605,11 @@ fn lr_unit_row(
14711605 let mut rcol = 0usize;
14721606 while x0 < plane_w as u32 {
14731607 let remaining_w = plane_w as u32 - x0;
1474- let uw = if remaining_w < ext_size { remaining_w } else { unit_size };
1608+ let uw = if remaining_w < ext_size {
1609+ remaining_w
1610+ } else {
1611+ unit_size
1612+ };
14751613 let filter = grid.get(plane, rrow, rcol);
14761614 if filter != UnitFilter::None {
14771615 filter_restoration_unit(
@@ -1486,7 +1624,8 @@ fn lr_unit_row(
14861624 v_start as usize,
14871625 v_end as usize,
14881626 ss_y,
1489- filter, fctx,
1627+ filter,
1628+ fctx,
14901629 );
14911630 }
14921631 x0 += uw;
@@ -1510,7 +1649,15 @@ mod tests {
15101649 /// `SGRPROJ_PRJ_MAX-MIN+1`.
15111650 #[test]
15121651 fn subexp_roundtrips_every_value() {
1513- for &(num_syms, k) in &[(16u32, 1u32), (32, 2), (64, 3), (96, 4), (128, 4), (3, 1), (1, 3)] {
1652+ for &(num_syms, k) in &[
1653+ (16u32, 1u32),
1654+ (32, 2),
1655+ (64, 3),
1656+ (96, 4),
1657+ (128, 4),
1658+ (3, 1),
1659+ (1, 3),
1660+ ] {
15141661 for v in 0..num_syms {
15151662 let mut enc = SymbolEncoder::new();
15161663 write_subexp(&mut enc, num_syms, k, v);
@@ -1548,10 +1695,10 @@ mod tests {
15481695 #[test]
15491696 fn signed_subexp_with_ref_roundtrips() {
15501697 let cases: [(i32, i32, u32); 4] = [
1551- (-5, 11, 1), // Wiener tap0
1552- (-23, 9, 2), // Wiener tap1
1553- (-17, 47, 3), // Wiener tap2
1554- (-96, 32, 4), // SGR xqd0
1698+ (-5, 11, 1), // Wiener tap0
1699+ (-23, 9, 2), // Wiener tap1
1700+ (-17, 47, 3), // Wiener tap2
1701+ (-96, 32, 4), // SGR xqd0
15551702 ];
15561703 for (low, high, k) in cases {
15571704 let n = (high - low) as u32;
@@ -1563,8 +1710,12 @@ mod tests {
15631710 write_unsigned_subexp_with_ref(&mut enc, n, k, r, coded_v);
15641711 let payload = enc.finish();
15651712 let mut dec = SymbolDecoder::new(&payload);
1566- let got = decode_signed_subexp_with_ref_msac(&mut dec, low, high, k, reference_v);
1567- assert_eq!(got, v, "low={low} high={high} k={k} reference={reference_v} v={v}");
1713+ let got =
1714+ decode_signed_subexp_with_ref_msac(&mut dec, low, high, k, reference_v);
1715+ assert_eq!(
1716+ got, v,
1717+ "low={low} high={high} k={k} reference={reference_v} v={v}"
1718+ );
15681719 }
15691720 }
15701721 }
@@ -1595,7 +1746,11 @@ mod tests {
15951746 let mut dec = SymbolDecoder::new(&payload);
15961747 let mut rref = WienerInfo::default();
15971748 for u in &units {
1598- assert_eq!(read_wiener_filter(&mut dec, chroma, &mut rref), *u, "chroma={chroma}");
1749+ assert_eq!(
1750+ read_wiener_filter(&mut dec, chroma, &mut rref),
1751+ *u,
1752+ "chroma={chroma}"
1753+ );
15991754 }
16001755 }
16011756 }
crates/ec-av1/src/stream.rsmodified+6 -4
@@ -1662,10 +1662,11 @@ fn decode_frame(
16621662 // unaffected. Gates: `a_non_420_subsampled_sequence_header_is_refused_by_
16631663 // name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:4
16641664 // stream).
1665- if seq.subsampling_x != 1 || seq.subsampling_y != 1 {
1665+ // lane-av1-444: 4:4:4 (ss 0,0) is decoded. 4:2:2 (ss_x != ss_y) is not.
1666+ if seq.subsampling_x != seq.subsampling_y {
16661667 return Err(Error::unsupported(
16671668 "AV1 decode_stream",
1668- "a chroma format other than 4:2:0 (subsampling_x/y != 1/1): every chroma extent in this decoder is hardcoded to 4:2:0 and the probe emits 4:2:0 planes only, so a 4:4:4/4:2:2 stream would decode silently wrong pixels",
1669+ "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported",
16691670 ));
16701671 }
16711672 // lane-av1txr-r2: `quantization_params.using_qmatrix` (spec 5.9.12) is
@@ -1739,6 +1740,7 @@ fn decode_frame(
17391740 // the bit depth so a mono frame decoded on a thread that last saw a
17401741 // 4:2:0 one never inherits the wrong plane count.
17411742 crate::decode::set_mono(seq.mono_chrome, fctx);
1743+ crate::decode::set_subsampling(seq.subsampling_x, seq.subsampling_y, fctx);
17421744 // lane-av1txr: spec 5.9.2 `disable_cdf_update` -- a frame that sets it
17431745 // codes every tile symbol against the CDFs it started with, so the tile
17441746 // readers must not adapt (libaom `decodeframe.c:2909`:
@@ -2153,11 +2155,11 @@ pub(crate) mod tests {
21532155 #[test]
21542156 fn a_non_420_subsampled_sequence_header_is_refused_by_name() {
21552157 const NAME: &str = "a_non_420_subsampled_sequence_header_is_refused_by_name";
2156- const REFUSAL: &str = "a chroma format other than 4:2:0";
2158+ const REFUSAL: &str = "a chroma format of 4:2:2";
21572159 let fctx = &crate::decode::FrameCtx::new();
21582160 let picture = test_card(64, 64);
21592161 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
2160- for (profile, label, sx, sy) in [(1u8, "4:4:4", 0u8, 0u8), (2, "4:2:2", 1, 0)] {
2162+ for (profile, label, sx, sy) in [(2u8, "4:2:2", 1u8, 0u8)] {
21612163 let color = ec_av1_syntax::ColorConfig {
21622164 num_planes: 3,
21632165 subsampling_x: sx,
lanes/av1444.report.mdadded+99 -0
@@ -0,0 +1,99 @@
1+# Lane av1444: AV1 4:4:4 (WIP)
2+
3+Branch `lane-av1-444`, base `7f8d6cf6`. Worktree
4+`/home/user/Documents/Code/Rust/edith_codecs-av1444`. Private
5+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1444`,
6+`TMPDIR=$HOME/.cache/av1444-tmp`. Not pushed.
7+
8+Status: **WIP**. 4:4:4 is no longer refused. Luma of a square profile-1
9+keyframe is byte-exact vs aomdec and ffmpeg. Chroma is not. 4:2:2 stays a
10+named refusal. Full suite was not run.
11+
12+Commit: blocked by the global pre-commit hook
13+(`format-staged.py` runs `rustfmt <file>` with no `--edition`). That rustfmt
14+rejects the pre-existing `let` chains in `decode.rs` (`edition = "2024"`).
15+`rustfmt --edition 2024 --check` wants a wholesale reformat of `decode.rs`,
16+so the hook was not bypassed and the reformat was not applied. Changes are
17+staged, not committed. `git status` in the worktree is the source of truth.
18+
19+## What changed
20+
21+- `stream.rs`: the sequence-header refusal now fires only when
22+ `subsampling_x != subsampling_y` (4:2:2). 4:4:4 (`0,0`) and 4:2:0 (`1,1`)
23+ proceed. `set_subsampling` publishes the header values onto `FrameCtx`
24+ once per frame, same slot as `set_mono`.
25+- `decode.rs`: chroma plane size, tx size, CFL window, loop-filter chroma
26+ step, and the 8x8 leaf's chroma unit follow `ss_x`/`ss_y`. At 4:4:4 an
27+ 8x8 leaf's chroma is 8x8 (`TxbSet::Chroma8`, `scans.0`), not the hardcoded
28+ 4x4. A square block below 64 uses chroma tx = block side. A 64 block still
29+ takes the single-TU arm (see the divergence below).
30+- `restoration.rs`: chroma restoration unit size is no longer hardcoded
31+ half-res. Not witnessed (the proof stream disables restoration).
32+- `refusal_inventory.rs`: the old "any non-4:2:0" string is replaced by the
33+ 4:2:2 string. Gate `a_non_420_subsampled_sequence_header_is_refused_by_name`
34+ asserts that 4:2:2 string only. The gate was not re-run in this wrap-up.
35+
36+## Byte-exactness
37+
38+Oracle: `~/.cache/aom-oracle/build/aomenc` + `aomdec`, cross-checked with
39+ffmpeg 8.x raw `yuv444p` / `yuv420p`. aomdec `--rawvideo` and ffmpeg
40+`-pix_fmt yuv444p` were identical on the 444 witness, so the mismatch below
41+is ours.
42+
43+Recipe (both profiles): `testsrc2=128x128`, 2 frames, `--cpu-used=8
44+--usage=2 --end-usage=q --cq-level=40 --min-partition-size=16
45+--enable-rect-partitions=0 --enable-cdef=0 --enable-restoration=0
46+--loopfilter-control=0 --threads=1 --obu`. Profile 1 adds `--profile=1` and
47+yuv444p input. Probe: `decode_probe` 8-bit dump (low byte of each plane).
48+
49+| stream | vs | result |
50+| --- | --- | --- |
51+| profile 0, filters off, square | ffmpeg `yuv420p` | IDENTICAL (98304 B, 2 frames) |
52+| profile 1, filters off, square | aomdec and ffmpeg `yuv444p` | luma IDENTICAL both frames (0 diffs / 16384). chroma NOT. 37389 diffs / 98304. First chroma mismatch: frame 0 U (112, 0), ours 192 vs oracle 167 |
53+| profile 1 with rect partitions (earlier `sq8.obu`) | — | panics in `decode_rect4_16_strip` → `reconstruct_rect` (`len 64, index 64`). Not a witness |
54+
55+`av1-profile1-444.ivf` was not re-decoded. It contains the rect/1:4 shapes
56+this tree still mishandles, so it will not be byte-exact.
57+
58+## Exact divergence
59+
60+First profile-1 block is an 8x8 leaf at mi (0, 0). Before the leaf fix that
61+leaf read 4x4 chroma, under-consumed symbols, and luma diverged at pixel 8.
62+After the fix, luma of both frames matches and U/V match until x=112.
63+
64+x=112 sits inside the 64x64 block at pixel (64, 0) (`EC_BLOCK side=64
65+at=(0, 4)`, `chroma_in=32`). That block takes `decode_block`'s
66+`logical_tx == side` arm (side 64, one luma TU whose coefficient grid is
67+32). The arm then reads **one** chroma unit with reconstruct side
68+`chroma_side` (64 at 4:4:4) and coeff tx `chroma_tx` (32). libaom codes
69+**four** TX_32X32 chroma units for a 64x64 uv plane block at 4:4:4
70+(`av1_get_max_uv_txsize` of a 64x64 uv bsize is TX_32X32, 2x2). The
71+multi-TU arm already loops `cn = chroma_side / chroma_tx` units, but a
72+64 block never enters it because `logical_tx == side`. Comment is on the
73+U `read_plane` in that arm.
74+
75+Quadrant diffs inside that 64x64, U plane, frame 0: (0,0) 764/1024,
76+(1,0) 896/1024, (0,1) 973/1024, (1,1) 1024/1024. Row 0 of the block matches
77+for the first 48 samples, then goes flat-wrong. That is a wrong chroma
78+unit, not a luma desync.
79+
80+## Still refused or unproven
81+
82+| shape | disposition |
83+| --- | --- |
84+| 4:2:2 (`ss_x != ss_y`) | refused by name. Gate re-scoped, not re-run |
85+| 4:4:4 64x64 chroma (and any block that takes the single-TU arm with `chroma_side != chroma_tx`) | decodes, not byte-exact. Next edit: when `ss==0` and `chroma_side > chroma_tx`, use the existing `cn` loop instead of one `read_plane` |
86+| 1:4 strips (`decode_rect4_16`) | panic, not a named refusal. Not in the square witness |
87+| sub-8 group chroma (`Chroma4` / size 4 in the 4x4-group tails) | still hardcoded 4:2:0. Square witness did not hit this first |
88+| loop filter, CDEF, restoration on | threaded with `ss_*`, not witnessed (proof stream disables them) |
89+| 10-bit 4:4:4 | not encoded, not compared |
90+| `av1-profile1-444.ivf` | not re-run |
91+| full `cargo test -p ec-av1` | not run. Do not claim green |
92+
93+## Next
94+
95+1. In `decode_block`, when `logical_tx == side` but `chroma_side > chroma_tx`, code chroma as `cn` x `cn` units (the multi-TU loop already does this). Re-run the square profile-1 recipe. Luma must stay identical; chroma must go to 0 diffs.
96+2. Then turn filters back on one at a time.
97+3. Then a 10-bit profile-2 444 stream (`yuv444p10le`).
98+4. Then the existing `av1-profile1-444.ivf`, after the 1:4 path no longer panics.
99+5. Full suite, `--test-threads=1`, `TMPDIR` on `$HOME`.