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 {
102 /// (like [`FrameCtx::bit_depth`]), so a mono frame decoded on a thread102 /// (like [`FrameCtx::bit_depth`]), so a mono frame decoded on a thread
103 /// that last saw a 4:2:0 one never inherits the wrong plane count.103 /// that last saw a 4:2:0 one never inherits the wrong plane count.
104 pub(crate) mono_chrome: std::cell::Cell<bool>,104 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>,
105 pub(crate) superres: std::cell::Cell<(u32, u32)>,108 pub(crate) superres: std::cell::Cell<(u32, u32)>,
106 pub(crate) cdef_transmitted: std::cell::Cell<bool>,109 pub(crate) cdef_transmitted: std::cell::Cell<bool>,
107 pub(crate) cdef_sb_cols: std::cell::Cell<usize>,110 pub(crate) cdef_sb_cols: std::cell::Cell<usize>,
@@ -200,6 +203,8 @@ impl FrameCtx {
200 cdef_bits: std::cell::Cell::new(0),203 cdef_bits: std::cell::Cell::new(0),
201 bit_depth: std::cell::Cell::new(8),204 bit_depth: std::cell::Cell::new(8),
202 mono_chrome: std::cell::Cell::new(false),205 mono_chrome: std::cell::Cell::new(false),
206+ subsampling_x: std::cell::Cell::new(1),
207+ subsampling_y: std::cell::Cell::new(1),
203 superres: std::cell::Cell::new((0, 8)),208 superres: std::cell::Cell::new((0, 8)),
204 cdef_transmitted: std::cell::Cell::new(false),209 cdef_transmitted: std::cell::Cell::new(false),
205 cdef_sb_cols: std::cell::Cell::new(0),210 cdef_sb_cols: std::cell::Cell::new(0),
@@ -296,6 +301,8 @@ pub(crate) fn filter_ctx_copy(fctx: &FrameCtx) -> FrameCtx {
296 let out = FrameCtx::new();301 let out = FrameCtx::new();
297 out.bit_depth.set(fctx.bit_depth.get());302 out.bit_depth.set(fctx.bit_depth.get());
298 out.mono_chrome.set(fctx.mono_chrome.get());303 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());
299 out.interp_filter.set(fctx.interp_filter.get());306 out.interp_filter.set(fctx.interp_filter.get());
300 out.grain_bit_depth.set(fctx.grain_bit_depth.get());307 out.grain_bit_depth.set(fctx.grain_bit_depth.get());
301 out.superres.set(fctx.superres.get());308 out.superres.set(fctx.superres.get());
@@ -618,6 +625,29 @@ pub(crate) fn set_mono(mono_chrome: bool, fctx: &crate::decode::FrameCtx) {
618 fctx.mono_chrome.with(|c| c.set(mono_chrome));625 fctx.mono_chrome.with(|c| c.set(mono_chrome));
619 }626 }
620 627
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+
621 /// This frame's superres state: `(upscaled_width, superres_denom)`, or651 /// This frame's superres state: `(upscaled_width, superres_denom)`, or
622 /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs652 /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs
623 /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid,653 /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid,
@@ -2333,17 +2363,14 @@ pub(crate) struct CflSrc {
2333 py: usize,2363 py: usize,
2334 bw: usize,2364 bw: usize,
2335 bh: usize,2365 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,
2339 }2366 }
2340 2367
2341 fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc {2368 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 }
2343 }2370 }
2344 2371
2345 fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc {2372 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 }
2347 }2374 }
2348 2375
2349 /// lane-wave1 step (i): the pixel-writing half of block decoding, recorded2376 /// lane-wave1 step (i): the pixel-writing half of block decoding, recorded
@@ -3578,11 +3605,7 @@ fn exec_intra(
3578 // written for this block -- at parse time it would have been the previous3605 // written for this block -- at parse time it would have been the previous
3579 // frame's samples.3606 // frame's samples.
3580 let ac = cfl.map(|(alpha, src)| {3607 let ac = cfl.map(|(alpha, src)| {
3581- let sig = if src.rect {3608+ let sig = cfl_ac_ss(&*y, src.px, src.py, src.bw, src.bh, ss_x(fctx), ss_y(fctx));
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- };
3586 (alpha, sig)3609 (alpha, sig)
3587 });3610 });
3588 let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));3611 let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));
@@ -6757,7 +6780,9 @@ fn read_coeffs_rect(
6757 // mask rather than a hardware divide.6780 // mask rather than a hardware divide.
6758 let stride = w + 4;6781 let stride = w + 4;
6759 let n = stride * (h + 4);6782 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+ }
6761 let (mut b96, mut b256, mut b768);6786 let (mut b96, mut b256, mut b768);
6762 // Byte levels, same `0..=15` bound [`read_coeffs`] states.6787 // Byte levels, same `0..=15` bound [`read_coeffs`] states.
6763 let levels: &mut [u8] = if n <= 96 {6788 let levels: &mut [u8] = if n <= 96 {
@@ -7653,8 +7678,8 @@ impl Neighbours {
7653 // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is7678 // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is
7654 // half its luma one (min 4 px, the smallest transform), capped at7679 // half its luma one (min 4 px, the smallest transform), capped at
7655 // TX_32X32 -- independent of this block's luma `tx_depth`.7680 // 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;7681+ let uv_tx_w = (((w_mi * MI) >> ss_x(fctx)).max(4).min(32)) as u8;
7657- let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8;7682+ let uv_tx_h = (((h_mi * MI) >> ss_y(fctx)).max(4).min(32)) as u8;
7658 if crate::envflags::env_flag!("EC_TXGRID_TRACE") {7683 if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
7659 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}");7684 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}");
7660 }7685 }
@@ -9453,7 +9478,7 @@ fn read_intra_mode_rect(
9453 // BLOCK_4X8, both floored at the 4-px transform. Halving the short9478 // BLOCK_4X8, both floored at the 4-px transform. Halving the short
9454 // axis to 2 read HALF the colour-index symbols of a 1:4 strip's9479 // axis to 2 read HALF the colour-index symbols of a 1:4 strip's
9455 // chroma palette and desynced the tile from there.9480 // 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));
9457 let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));9482 let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));
9458 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);9483 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
9459 hit!(PALETTE_UV_HITS);9484 hit!(PALETTE_UV_HITS);
@@ -9640,8 +9665,8 @@ fn decode_rect_split(
9640 ) -> Result<()> {9665 ) -> Result<()> {
9641 let (mi_r, mi_c) = at_mi;9666 let (mi_r, mi_c) = at_mi;
9642 let (px, py) = (mi_c * MI, mi_r * MI);9667 let (px, py) = (mi_c * MI, mi_r * MI);
9643- let (cpx, cpy) = (px / 2, py / 2);9668+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
9644- let (chroma_w, chroma_h) = (bw / 2, bh / 2);9669+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
9645 // The chroma transform is picked before any symbol is read, so an9670 // The chroma transform is picked before any symbol is read, so an
9646 // unsupported chroma shape refuses before this strip desyncs the tile.9671 // unsupported chroma shape refuses before this strip desyncs the tile.
9647 let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) {9672 let chroma: Option<(TxbSet, &[u16])> = match (chroma_w, chroma_h) {
@@ -9694,7 +9719,11 @@ fn decode_rect_split(
9694 // caller -- a new strip size would otherwise hit the `expect` below and9719 // caller -- a new strip size would otherwise hit the `expect` below and
9695 // panic instead of refusing by name -- and so stays in9720 // panic instead of refusing by name -- and so stays in
9696 // `refusal_inventory::REFUSALS`.9721 // `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 {
9698 return Err(unsupported(9727 return Err(unsupported(
9699 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",9728 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
9700 ));9729 ));
@@ -10051,6 +10080,80 @@ fn decode_rect_split(
10051 }10080 }
10052 let [ug, vg] = last;10081 let [ug, vg] = last;
10053 (ug, vg)10082 (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())
10054 } else {10157 } else {
10055 let (chroma_set, chroma_scan) = chroma.expect("refused above when None");10158 let (chroma_set, chroma_scan) = chroma.expect("refused above when None");
10056 // `av1_get_ext_tx_set_type`: a chroma transform whose square-up size10159 // `av1_get_ext_tx_set_type`: a chroma transform whose square-up size
@@ -10741,7 +10844,7 @@ fn decode_intra_rect_in_inter(
10741 PaletteY { size: n, colors, map }10844 PaletteY { size: n, colors, map }
10742 });10845 });
10743 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {10846 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));
10745 let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));10848 let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));
10746 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);10849 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
10747 hit!(PALETTE_UV_HITS);10850 hit!(PALETTE_UV_HITS);
@@ -11063,8 +11166,8 @@ fn decode_block_rect(
11063 return Ok(());11166 return Ok(());
11064 }11167 }
11065 let (tx_w, tx_h) = (bw, bh);11168 let (tx_w, tx_h) = (bw, bh);
11066- let (cpx, cpy) = (px / 2, py / 2);11169+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
11067- let (chroma_w, chroma_h) = (bw / 2, bh / 2);11170+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
11068 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);11171 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
11069 if crate::envflags::env_flag!("EC_AV1_TRACE") {11172 if crate::envflags::env_flag!("EC_AV1_TRACE") {
11070 let (rng, _) = dec.debug_state();11173 let (rng, _) = dec.debug_state();
@@ -11152,10 +11255,25 @@ fn decode_block_rect(
11152 // (`TxbSet::LumaRect32x16`/`ChromaRect16x8`, see those variants' own11255 // (`TxbSet::LumaRect32x16`/`ChromaRect16x8`, see those variants' own
11153 // doc comments); the scan order and 2D context tables are the real11256 // doc comments); the scan order and 2D context tables are the real
11154 // rect ones (`SCAN_32X16`/etc, `base_ctx_rect`/`br_ctx_rect`).11257 // rect ones (`SCAN_32X16`/etc, `base_ctx_rect`/`br_ctx_rect`).
11155- let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw == 32 {11258+ let luma_scan: &[u16] = if bw > bh { &SCAN_32X16 } else { &SCAN_16X32 };
11156- (&SCAN_32X16, &SCAN_16X8)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
11157 } else {11275 } else {
11158- (&SCAN_16X32, &SCAN_8X16)11276+ default_intra_tx_type(uv_predict_mode as u8)
11159 };11277 };
11160 // lane-rectwire r3: real coefficients desync a pixel-exact gate11278 // lane-rectwire r3: real coefficients desync a pixel-exact gate
11161 // (rectwire-flake-1.obu, seed 55) -- both 32x16 strips of frame 0's11279 // (rectwire-flake-1.obu, seed 55) -- both 32x16 strips of frame 0's
@@ -11235,9 +11353,9 @@ fn decode_block_rect(
11235 if let Some((ub, _)) = &palette_uv_bufs {11353 if let Some((ub, _)) = &palette_uv_bufs {
11236 set_palette_pred(ub.clone(), fctx);11354 set_palette_pred(ub.clone(), fctx);
11237 }11355 }
11238- let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);11356+ let u_default_tx = chroma_default_tx;
11239 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);11357 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);
11241 let (u_levels, u_tx_type) = read_chroma_coeffs_rect(11359 let (u_levels, u_tx_type) = read_chroma_coeffs_rect(
11242 dec,11360 dec,
11243 &mut u_coding,11361 &mut u_coding,
@@ -11279,9 +11397,9 @@ fn decode_block_rect(
11279 if let Some((_, vb)) = &palette_uv_bufs {11397 if let Some((_, vb)) = &palette_uv_bufs {
11280 set_palette_pred(vb.clone(), fctx);11398 set_palette_pred(vb.clone(), fctx);
11281 }11399 }
11282- let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);11400+ let v_default_tx = chroma_default_tx;
11283 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);11401 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);
11285 let (v_levels, v_tx_type) = read_chroma_coeffs_rect(11403 let (v_levels, v_tx_type) = read_chroma_coeffs_rect(
11286 dec,11404 dec,
11287 &mut v_coding,11405 &mut v_coding,
@@ -11551,8 +11669,8 @@ fn decode_leaf_rect(
11551 }11669 }
11552 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);11670 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
11553 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);11671 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
11554- let (cpx, cpy) = (px / 2, py / 2);11672+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
11555- let (chroma_w, chroma_h) = (bw / 2, bh / 2);11673+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
11556 let (luma_levels, u_levels, v_levels);11674 let (luma_levels, u_levels, v_levels);
11557 if skip {11675 if skip {
11558 luma_levels = Grid::Zero(bw * bh);11676 luma_levels = Grid::Zero(bw * bh);
@@ -11587,11 +11705,14 @@ fn decode_leaf_rect(
11587 // `use_reduced_set` branch returns `EXT_TX_SET_DTT4_IDTX` at11705 // `use_reduced_set` branch returns `EXT_TX_SET_DTT4_IDTX` at
11588 // `tx_size_sqr_up == TX_16X16` regardless of the true, non-square11706 // `tx_size_sqr_up == TX_16X16` regardless of the true, non-square
11589 // `tx_size`) and its chroma half (8x4/4x8, `TxbSet::ChromaRect8x4`).11707 // `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 {
11591 (&SCAN_16X8, &SCAN_8X4)11711 (&SCAN_16X8, &SCAN_8X4)
11592 } else {11712 } else {
11593 (&SCAN_8X16, &SCAN_4X8)11713 (&SCAN_8X16, &SCAN_4X8)
11594 };11714 };
11715+ let chroma_rect_set = if ss_x(fctx) == 0 { TxbSet::ChromaRect16x8 } else { TxbSet::ChromaRect8x4 };
11595 let around = neighbours.around_mi_rect(leaf_mi, bw, bh);11716 let around = neighbours.around_mi_rect(leaf_mi, bw, bh);
11596 let luma_set = if reduced_tx_set {11717 let luma_set = if reduced_tx_set {
11597 TxbSet::LumaRect16x811718 TxbSet::LumaRect16x8
@@ -11621,7 +11742,7 @@ fn decode_leaf_rect(
11621 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));11742 let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
11622 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);11743 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
11623 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);11744 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);
11625 let (u_l, u_tx_type) = read_chroma_coeffs_rect(11746 let (u_l, u_tx_type) = read_chroma_coeffs_rect(
11626 dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx,11747 dec, &mut u_coding, chroma_scan, chroma_w, chroma_h, u_skip_ctx,
11627 dc_sign_ctx(around[1].2), u_default_tx, fctx,11748 dc_sign_ctx(around[1].2), u_default_tx, fctx,
@@ -11640,7 +11761,7 @@ fn decode_leaf_rect(
11640 );11761 );
11641 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);11762 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
11642 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);11763 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);
11644 let (v_l, v_tx_type) = read_chroma_coeffs_rect(11765 let (v_l, v_tx_type) = read_chroma_coeffs_rect(
11645 dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx,11766 dec, &mut v_coding, chroma_scan, chroma_w, chroma_h, v_skip_ctx,
11646 dc_sign_ctx(around[2].2), v_default_tx, fctx,11767 dc_sign_ctx(around[2].2), v_default_tx, fctx,
@@ -11936,8 +12057,8 @@ fn decode_block_rect4(
11936 neighbours.record_mode_mi(mi_r, mi_c, mi_w, mi_h, mode);12057 neighbours.record_mode_mi(mi_r, mi_c, mi_w, mi_h, mode);
11937 neighbours.record_uv_mode_mi(mi_r, mi_c, mi_w, mi_h, uv_predict_mode);12058 neighbours.record_uv_mode_mi(mi_r, mi_c, mi_w, mi_h, uv_predict_mode);
11938 let (px, py) = (mi_c * MI, mi_r * MI);12059 let (px, py) = (mi_c * MI, mi_r * MI);
11939- let (cpx, cpy) = (px / 2, py / 2);12060+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
11940- let (chroma_w, chroma_h) = (bw / 2, bh / 2);12061+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
11941 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);12062 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
11942 let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw > bh {12063 let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw > bh {
11943 (&SCAN_32X8, &SCAN_16X4)12064 (&SCAN_32X8, &SCAN_16X4)
@@ -12549,8 +12670,8 @@ fn decode_rect4_16_strip(
12549 };12670 };
12550 let (pw, ph) = if horz { (16, 8) } else { (8, 16) };12671 let (pw, ph) = if horz { (16, 8) } else { (8, 16) };
12551 let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI);12672 let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI);
12552- let (cpx, cpy) = (ppx / 2, ppy / 2);12673+ let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx));
12553- let (cw, ch) = (pw / 2, ph / 2);12674+ let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx));
12554 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };12675 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
12555 if (V_PRED..=D67_PRED).contains(&uv_predict_mode) {12676 if (V_PRED..=D67_PRED).contains(&uv_predict_mode) {
12556 hit!(RECT4_16_CHROMA_DIR_HITS);12677 hit!(RECT4_16_CHROMA_DIR_HITS);
@@ -12932,8 +13053,8 @@ fn decode_block_rect64(
12932 return Ok(());13053 return Ok(());
12933 }13054 }
12934 let (tx_w, tx_h) = (bw, bh);13055 let (tx_w, tx_h) = (bw, bh);
12935- let (cpx, cpy) = (px / 2, py / 2);13056+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
12936- let (chroma_w, chroma_h) = (bw / 2, bh / 2);13057+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
12937 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);13058 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
12938 if let Some(ref pyv) = palette_y {13059 if let Some(ref pyv) = palette_y {
12939 let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect();13060 let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect();
@@ -13112,145 +13233,99 @@ fn decode_block_rect64(
13112 leftcol,13233 leftcol,
13113 );13234 );
13114 }13235 }
13115- // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no13236+ // CHROMA. At 4:2:0 the plane block is already one adjusted UV
13116- // corner crop needed (see doc comment).13237+ // transform (<=32 on each axis). At 4:4:4 a 64-axis strip's chroma
13117- let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));13238+ // is larger than that, so it is tiled into 32-capped units.
13118- // The chroma plane is never truncated (both axes <= 32 after13239+ let _ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
13119- // subsampling). Under a 1:4 strip it is a true 32x8/8x32:13240+ let (uw, uh) = (chroma_w.min(32), chroma_h.min(32));
13120- // `get_txsize_entropy_ctx(TX_32X8)` = (TX_8X8 + TX_32X32 + 1) >> 1 =13241+ let (nw, nh) = (chroma_w / uw, chroma_h / uh);
13121- // TX_16X16 and `txsize_log2_minus4[TX_32X8]` = 4 (256 positions),13242+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (uw, uh) {
13122- // both identical to TX_16X16 -- so [`TxbSet::Chroma16`] is the exact13243+ (32, 32) => (TxbSet::Chroma32, default_scan(32)),
13123- // set, and only the scan is new (lane-tx64x16).13244+ (32, 16) => (TxbSet::ChromaRect32x16, &SCAN_32X16),
13124- let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (bw, bh) {13245+ (16, 32) => (TxbSet::ChromaRect32x16, &SCAN_16X32),
13125- (64, 16) => (TxbSet::Chroma16, &SCAN_32X8),13246+ (32, 8) => (TxbSet::Chroma16, &SCAN_32X8),
13126- (16, 64) => (TxbSet::Chroma16, &SCAN_8X32),13247+ (8, 32) => (TxbSet::Chroma16, &SCAN_8X32),
13127- (64, _) => (TxbSet::ChromaRect32x16, &SCAN_32X16),13248+ _ => {
13128- _ => (TxbSet::ChromaRect32x16, &SCAN_16X32),13249+ return Err(unsupported(
13129- };13250+ "a 64-axis strip whose chroma unit has no coefficient table",
13130- let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);13251+ ))
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);
13220 }13252 }
13221- if crate::envflags::env_flag!("EC_AV1_TRACE") {13253+ };
13222- eprintln!(13254+ let bigger = nw * nh > 1;
13223- "TRACE rect64_dequant plane=2 base_q_idx={base_q_idx} current_q_idx={cur}"13255+ let mut u_levels = vec![0i32; chroma_w * chroma_h];
13224- );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+ }
13225 }13326 }
13226 }13327 }
13227- let v_residual = dequant_and_inverse_typed_wh(13328+ neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[&luma_levels[..], &u_levels[..], &v_levels[..]]);
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[..]]);
13254 hit!(RECT_COEFF_HITS);13329 hit!(RECT_COEFF_HITS);
13255 }13330 }
13256 let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));13331 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(
13619 let on = palette_onscreen_uv(13694 let on = palette_onscreen_uv(
13620 (side, side),13695 (side, side),
13621 palette_onscreen(mi_r, mi_c, side, side, fctx),13696 palette_onscreen(mi_r, mi_c, side, side, fctx),
13622- (side / 2, side / 2),13697+ (side >> ss_x(fctx), side >> ss_y(fctx)),
13623 );13698 );
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);
13625 hit!(PALETTE_UV_HITS);13700 hit!(PALETTE_UV_HITS);
13626 if trace {13701 if trace {
13627 eprintln!(13702 eprintln!(
@@ -13692,6 +13767,38 @@ fn cfl_ac_q3(y: &PlaneBuf<'_>, px: usize, py: usize, side: usize) -> Vec<i32> {
13692 /// (lane-av1cfl) builds a CfL candidate's AC signal from its own `u8`13767 /// (lane-av1cfl) builds a CfL candidate's AC signal from its own `u8`
13693 /// reconstruction through THIS function rather than a second transcription of13768 /// reconstruction through THIS function rather than a second transcription of
13694 /// `cfl_luma_subsampling_420_lbd_c` + `subtract_average_c`.13769 /// `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+
13695 pub(crate) fn cfl_ac_q3_at(13802 pub(crate) fn cfl_ac_q3_at(
13696 px: usize,13803 px: usize,
13697 py: usize,13804 py: usize,
@@ -14377,6 +14484,15 @@ fn decode_block(
14377 // multi-transform-unit path below.14484 // multi-transform-unit path below.
14378 let (luma_set, chroma_set, luma_tx, chroma_tx, scans) = if lossless(fctx) {14485 let (luma_set, chroma_set, luma_tx, chroma_tx, scans) = if lossless(fctx) {
14379 (TxbSet::Luma4, TxbSet::Chroma4, 4, 4, (scan4, scan4))14486 (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))
14380 } else {14496 } else {
14381 (luma_set, chroma_set, luma_tx, chroma_tx, scans)14497 (luma_set, chroma_set, luma_tx, chroma_tx, scans)
14382 };14498 };
@@ -14511,8 +14627,8 @@ fn decode_block(
14511 };14627 };
14512 let luma_scan = scan_for(coeff_tx_side, scan32, scan16, scan8, scan4);14628 let luma_scan = scan_for(coeff_tx_side, scan32, scan16, scan8, scan4);
14513 let reach = Reach::of(side, px, py, y.width, y.height, fctx);14629 let reach = Reach::of(side, px, py, y.width, y.height, fctx);
14514- let (cpx, cpy) = (px / 2, py / 2);14630+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
14515- let chroma_side = side / 2;14631+ let chroma_side = side >> ss_x(fctx);
14516 // spec 7.11.3.4 with `use_intrabc`: the reference is the *current*14632 // spec 7.11.3.4 with `use_intrabc`: the reference is the *current*
14517 // frame's own pre-loop-filter reconstruction (all loop filters are off14633 // frame's own pre-loop-filter reconstruction (all loop filters are off
14518 // whenever `allow_intrabc`, frame.rs:194/210/252/272) at the full-pel14634 // whenever `allow_intrabc`, frame.rs:194/210/252/272) at the full-pel
@@ -14524,19 +14640,19 @@ fn decode_block(
14524 let mut yb = vec![0u16; side * side];14640 let mut yb = vec![0u16; side * side];
14525 mc::predict_with_filter(14641 mc::predict_with_filter(
14526 &y.data, y.width, y.true_width, y.true_height,14642 &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),
14528 side, side, mc::InterpFilterKind::Bilinear, &mut yb, fctx,14644 side, side, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
14529 );14645 );
14530 let mut ub = vec![0u16; chroma_side * chroma_side];14646 let mut ub = vec![0u16; chroma_side * chroma_side];
14531 mc::predict_with_filter(14647 mc::predict_with_filter(
14532 &u.data, u.width, u.true_width, u.true_height,14648 &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)),
14534 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut ub, fctx,14650 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
14535 );14651 );
14536 let mut vb = vec![0u16; chroma_side * chroma_side];14652 let mut vb = vec![0u16; chroma_side * chroma_side];
14537 mc::predict_with_filter(14653 mc::predict_with_filter(
14538 &v.data, v.width, v.true_width, v.true_height,14654 &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)),
14540 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut vb, fctx,14656 chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
14541 );14657 );
14542 (yb, ub, vb)14658 (yb, ub, vb)
@@ -14685,7 +14801,7 @@ fn decode_block(
14685 let cn = (chroma_side / chroma_tx).max(1);14801 let cn = (chroma_side / chroma_tx).max(1);
14686 for cu_row in 0..cn {14802 for cu_row in 0..cn {
14687 for cu_col in 0..cn {14803 for cu_col in 0..cn {
14688- let luma_span = chroma_tx * 2;14804+ let luma_span = chroma_tx << ss_x(fctx);
14689 let cu_r = if cn == 1 {14805 let cu_r = if cn == 1 {
14690 reach14806 reach
14691 } else {14807 } else {
@@ -14774,6 +14890,10 @@ fn decode_block(
14774 if let Some((ub, _)) = &palette_uv_bufs {14890 if let Some((ub, _)) = &palette_uv_bufs {
14775 set_palette_pred(ub.clone(), fctx);14891 set_palette_pred(ub.clone(), fctx);
14776 }14892 }
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.
14777 let u_grid = read_plane(14897 let u_grid = read_plane(
14778 dec,14898 dec,
14779 cdfs,14899 cdfs,
@@ -14964,7 +15084,7 @@ fn decode_block(
14964 // The chroma context arrays are indexed in LUMA mi, so this15084 // The chroma context arrays are indexed in LUMA mi, so this
14965 // unit's anchor is its own luma quadrant: `chroma_tx` chroma15085 // unit's anchor is its own luma quadrant: `chroma_tx` chroma
14966 // pixels span `2 * chroma_tx` luma ones.15086 // pixels span `2 * chroma_tx` luma ones.
14967- let luma_span = chroma_tx * 2;15087+ let luma_span = chroma_tx << ss_x(fctx);
14968 let cu_mi = (15088 let cu_mi = (
14969 mi_r + cu_row * (luma_span / MI),15089 mi_r + cu_row * (luma_span / MI),
14970 mi_c + cu_col * (luma_span / MI),15090 mi_c + cu_col * (luma_span / MI),
@@ -15267,8 +15387,8 @@ fn decode_block_128rect(
15267 TxbSet::Chroma3215387 TxbSet::Chroma32
15268 };15388 };
15269 let chroma_scan = default_scan(chroma_tx);15389 let chroma_scan = default_scan(chroma_tx);
15270- let (cpx, cpy) = (px / 2, py / 2);15390+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
15271- let (chroma_w, chroma_h) = (bw / 2, bh / 2);15391+ let (chroma_w, chroma_h) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
15272 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);15392 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
15273 let (nch_x, nch_y) = (bw / 64, bh / 64);15393 let (nch_x, nch_y) = (bw / 64, bh / 64);
15274 // The frame's own mi grid (`av1_calc_mi_size`, 8-px aligned): libaom's15394 // The frame's own mi grid (`av1_calc_mi_size`, 8-px aligned): libaom's
@@ -15288,7 +15408,7 @@ fn decode_block_128rect(
15288 let mut units: Vec<(usize, (usize, usize), Grid)> = Vec::new();15408 let mut units: Vec<(usize, (usize, usize), Grid)> = Vec::new();
15289 // The chroma context arrays are indexed in LUMA mi; every chroma unit of15409 // The chroma context arrays are indexed in LUMA mi; every chroma unit of
15290 // every chunk shares this luma span (2 chroma pixels per luma unit).15410 // 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);
15292 for ch_row in 0..nch_y {15412 for ch_row in 0..nch_y {
15293 for ch_col in 0..nch_x {15413 for ch_col in 0..nch_x {
15294 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {15414 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {
@@ -15363,8 +15483,8 @@ fn decode_block_128rect(
15363 let cn = (32 / chroma_tx).max(1);15483 let cn = (32 / chroma_tx).max(1);
15364 // libaom's per-chunk `unit_width/height` (plane-mi units of the15484 // libaom's per-chunk `unit_width/height` (plane-mi units of the
15365 // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`.15485 // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`.
15366- let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> 1;15486+ let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> ss_x(fctx);
15367- let unit_h = ((ch_row + 1) * 16).min(max_h_mi) >> 1;15487+ let unit_h = ((ch_row + 1) * 16).min(max_h_mi) >> ss_y(fctx);
15368 let stepc = (chroma_tx / 4).max(1);15488 let stepc = (chroma_tx / 4).max(1);
15369 // `decode_token_recon_block` codes a mu chunk PLANE-MAJOR: every U15489 // `decode_token_recon_block` codes a mu chunk PLANE-MAJOR: every U
15370 // unit of the chunk, then every V unit. At one unit per plane per15490 // unit of the chunk, then every V unit. At one unit per plane per
@@ -15382,8 +15502,8 @@ fn decode_block_128rect(
15382 let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx;15502 let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx;
15383 let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx;15503 let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx;
15384 let cu_mi = (15504 let cu_mi = (
15385- mi_r + ch_row * 16 + ci_row * (chroma_tx / 2),15505+ mi_r + ch_row * 16 + ci_row * ((chroma_tx << ss_y(fctx)) / 4),
15386- mi_c + ch_col * 16 + ci_col * (chroma_tx / 2),15506+ mi_c + ch_col * 16 + ci_col * ((chroma_tx << ss_x(fctx)) / 4),
15387 );15507 );
15388 let cu_r = tu_reach(15508 let cu_r = tu_reach(
15389 bw,15509 bw,
@@ -15695,7 +15815,15 @@ fn decode_leaf8(
15695 };15815 };
15696 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);15816 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
15697 let reach = Reach::of(8, px, py, y.width, y.height, fctx);15817 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+ };
15699 // spec 7.11.3.4 with `use_intrabc`, same as `decode_block`: predict from15827 // spec 7.11.3.4 with `use_intrabc`, same as `decode_block`: predict from
15700 // the CURRENT frame's own pre-loop-filter reconstruction (every loop15828 // the CURRENT frame's own pre-loop-filter reconstruction (every loop
15701 // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at15829 // filter is off whenever `allow_intrabc`, frame.rs:194/210/252/272) at
@@ -15705,19 +15833,19 @@ fn decode_leaf8(
15705 let mut yb = vec![0u16; 8 * 8];15833 let mut yb = vec![0u16; 8 * 8];
15706 mc::predict_with_filter(15834 mc::predict_with_filter(
15707 &y.data, y.width, y.true_width, y.true_height,15835 &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),
15709 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx,15837 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
15710 );15838 );
15711 let mut ub = vec![0u16; 4 * 4];15839 let mut ub = vec![0u16; 4 * 4];
15712 mc::predict_with_filter(15840 mc::predict_with_filter(
15713 &u.data, u.width, u.true_width, u.true_height,15841 &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)),
15715 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,15843 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
15716 );15844 );
15717 let mut vb = vec![0u16; 4 * 4];15845 let mut vb = vec![0u16; 4 * 4];
15718 mc::predict_with_filter(15846 mc::predict_with_filter(
15719 &v.data, v.width, v.true_width, v.true_height,15847 &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)),
15721 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,15849 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
15722 );15850 );
15723 (yb, ub, vb)15851 (yb, ub, vb)
@@ -15803,11 +15931,11 @@ fn decode_leaf8(
15803 push_intra(1, 15931 push_intra(1,
15804 cpx,15932 cpx,
15805 cpy,15933 cpy,
15806- 4,15934+ csz,
15807 uv_predict_mode,15935 uv_predict_mode,
15808 angle_delta_uv,15936 angle_delta_uv,
15809 reach,15937 reach,
15810- &ZERO_RESIDUAL[..16],15938+ &ZERO_RESIDUAL[..csz * csz],
15811 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),15939 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
15812 None,15940 None,
15813 smooth_neighbor_uv, fctx,15941 smooth_neighbor_uv, fctx,
@@ -15820,18 +15948,18 @@ fn decode_leaf8(
15820 push_intra(2, 15948 push_intra(2,
15821 cpx,15949 cpx,
15822 cpy,15950 cpy,
15823- 4,15951+ csz,
15824 uv_predict_mode,15952 uv_predict_mode,
15825 angle_delta_uv,15953 angle_delta_uv,
15826 reach,15954 reach,
15827- &ZERO_RESIDUAL[..16],15955+ &ZERO_RESIDUAL[..csz * csz],
15828 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),15956 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
15829 None,15957 None,
15830 smooth_neighbor_uv, fctx,15958 smooth_neighbor_uv, fctx,
15831 );15959 );
15832 luma_grid = Grid::Zero(64);15960 luma_grid = Grid::Zero(64);
15833- u_grid = Grid::Zero(16);15961+ u_grid = Grid::Zero(csz * csz);
15834- v_grid = Grid::Zero(16);15962+ v_grid = Grid::Zero(csz * csz);
15835 } else if resolved != 4 {15963 } else if resolved != 4 {
15836 let around = neighbours.around_mi(leaf_mi, 8);15964 let around = neighbours.around_mi(leaf_mi, 8);
15837 if let Some(buf) = &palette_y_buf {15965 if let Some(buf) = &palette_y_buf {
@@ -15880,8 +16008,8 @@ fn decode_leaf8(
15880 u_grid = read_plane(16008 u_grid = read_plane(
15881 dec,16009 dec,
15882 cdfs,16010 cdfs,
15883- TxbSet::Chroma4,16011+ cset,
15884- scans.1,16012+ cscan,
15885 1,16013 1,
15886 around[1],16014 around[1],
15887 mode,16015 mode,
@@ -15891,8 +16019,8 @@ fn decode_leaf8(
15891 u,16019 u,
15892 cpx,16020 cpx,
15893 cpy,16021 cpy,
15894- 4,16022+ csz,
15895- TX4,16023+ csz,
15896 base_q_idx,16024 base_q_idx,
15897 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),16025 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
15898 None,16026 None,
@@ -15907,8 +16035,8 @@ fn decode_leaf8(
15907 v_grid = read_plane(16035 v_grid = read_plane(
15908 dec,16036 dec,
15909 cdfs,16037 cdfs,
15910- TxbSet::Chroma4,16038+ cset,
15911- scans.1,16039+ cscan,
15912 2,16040 2,
15913 around[2],16041 around[2],
15914 mode,16042 mode,
@@ -15918,8 +16046,8 @@ fn decode_leaf8(
15918 v,16046 v,
15919 cpx,16047 cpx,
15920 cpy,16048 cpy,
15921- 4,16049+ csz,
15922- TX4,16050+ csz,
15923 base_q_idx,16051 base_q_idx,
15924 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),16052 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
15925 None,16053 None,
@@ -16019,8 +16147,8 @@ fn decode_leaf8(
16019 u_grid = read_plane(16147 u_grid = read_plane(
16020 dec,16148 dec,
16021 cdfs,16149 cdfs,
16022- TxbSet::Chroma4,16150+ cset,
16023- scans.1,16151+ cscan,
16024 1,16152 1,
16025 chroma_around[1],16153 chroma_around[1],
16026 mode,16154 mode,
@@ -16030,8 +16158,8 @@ fn decode_leaf8(
16030 u,16158 u,
16031 cpx,16159 cpx,
16032 cpy,16160 cpy,
16033- 4,16161+ csz,
16034- TX4,16162+ csz,
16035 base_q_idx,16163 base_q_idx,
16036 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),16164 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
16037 None,16165 None,
@@ -16044,8 +16172,8 @@ fn decode_leaf8(
16044 v_grid = read_plane(16172 v_grid = read_plane(
16045 dec,16173 dec,
16046 cdfs,16174 cdfs,
16047- TxbSet::Chroma4,16175+ cset,
16048- scans.1,16176+ cscan,
16049 2,16177 2,
16050 chroma_around[2],16178 chroma_around[2],
16051 mode,16179 mode,
@@ -16055,8 +16183,8 @@ fn decode_leaf8(
16055 v,16183 v,
16056 cpx,16184 cpx,
16057 cpy,16185 cpy,
16058- 4,16186+ csz,
16059- TX4,16187+ csz,
16060 base_q_idx,16188 base_q_idx,
16061 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),16189 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
16062 None,16190 None,
@@ -16398,7 +16526,7 @@ fn decode_leaf_split4(
16398 let mut yb = vec![0u16; 16];16526 let mut yb = vec![0u16; 16];
16399 mc::predict_with_filter(16527 mc::predict_with_filter(
16400 &y.data, y.width, y.true_width, y.true_height,16528 &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),
16402 4, 4, mc::InterpFilterKind::Bilinear, &mut yb, fctx,16530 4, 4, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
16403 );16531 );
16404 set_palette_pred(yb.clone(), fctx);16532 set_palette_pred(yb.clone(), fctx);
@@ -16502,7 +16630,7 @@ fn decode_leaf_split4(
16502 (Grid::Zero(16), Grid::Zero(16))16630 (Grid::Zero(16), Grid::Zero(16))
16503 } else {16631 } else {
16504 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);16632 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));
16506 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);16634 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);
16507 let (uv_mode, angle_delta_uv, alpha) =16635 let (uv_mode, angle_delta_uv, alpha) =
16508 last_uv.expect("i==3 always sets has_chroma, so chroma is always Some");16636 last_uv.expect("i==3 always sets has_chroma, so chroma is always Some");
@@ -16547,13 +16675,13 @@ fn decode_leaf_split4(
16547 let mut ub = vec![0u16; 16];16675 let mut ub = vec![0u16; 16];
16548 mc::predict_with_filter(16676 mc::predict_with_filter(
16549 &u.data, u.width, u.true_width, u.true_height,16677 &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)),
16551 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,16679 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
16552 );16680 );
16553 let mut vb = vec![0u16; 16];16681 let mut vb = vec![0u16; 16];
16554 mc::predict_with_filter(16682 mc::predict_with_filter(
16555 &v.data, v.width, v.true_width, v.true_height,16683 &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)),
16557 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,16685 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
16558 );16686 );
16559 let chroma_around = neighbours.around_mi(leaf_mi, 8);16687 let chroma_around = neighbours.around_mi(leaf_mi, 8);
@@ -16799,7 +16927,7 @@ fn decode_leaf_rect8(
16799 let mut yb = vec![0u16; tw * th];16927 let mut yb = vec![0u16; tw * th];
16800 mc::predict_with_filter(16928 mc::predict_with_filter(
16801 &y.data, y.width, y.true_width, y.true_height,16929 &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),
16803 tw, th, mc::InterpFilterKind::Bilinear, &mut yb, fctx,16931 tw, th, mc::InterpFilterKind::Bilinear, &mut yb, fctx,
16804 );16932 );
16805 set_palette_pred(yb, fctx);16933 set_palette_pred(yb, fctx);
@@ -17118,7 +17246,7 @@ fn decode_leaf_rect8(
17118 (Grid::Zero(16), Grid::Zero(16))17246 (Grid::Zero(16), Grid::Zero(16))
17119 } else {17247 } else {
17120 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);17248 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));
17122 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);17250 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);
17123 let (uv_mode, angle_delta_uv, alpha) =17251 let (uv_mode, angle_delta_uv, alpha) =
17124 last_uv.expect("i==1 always sets has_chroma, so chroma is always Some");17252 last_uv.expect("i==1 always sets has_chroma, so chroma is always Some");
@@ -17163,13 +17291,13 @@ fn decode_leaf_rect8(
17163 let mut ub = vec![0u16; 16];17291 let mut ub = vec![0u16; 16];
17164 mc::predict_with_filter(17292 mc::predict_with_filter(
17165 &u.data, u.width, u.true_width, u.true_height,17293 &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)),
17167 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,17295 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
17168 );17296 );
17169 let mut vb = vec![0u16; 16];17297 let mut vb = vec![0u16; 16];
17170 mc::predict_with_filter(17298 mc::predict_with_filter(
17171 &v.data, v.width, v.true_width, v.true_height,17299 &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)),
17173 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,17301 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
17174 );17302 );
17175 let chroma_around = neighbours.around_mi(leaf_mi, 8);17303 let chroma_around = neighbours.around_mi(leaf_mi, 8);
@@ -17937,10 +18065,10 @@ fn deblock_span(
17937 deblock_plane_span(y, 0, lf, n, frame_width, frame_height, y_lo, y_hi, horz, fctx);18065 deblock_plane_span(y, 0, lf, n, frame_width, frame_height, y_lo, y_hi, horz, fctx);
17938 }18066 }
17939 if lf.level[2] != 0 {18067 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);
17941 }18069 }
17942 if lf.level[3] != 0 {18070 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);
17944 }18072 }
17945 }18073 }
17946 18074
@@ -17959,8 +18087,9 @@ fn deblock_span(
17959 /// block (different tx size, ref frame, skip flag and delta_lf) as soon as18087 /// block (different tx size, ref frame, skip flag and delta_lf) as soon as
17960 /// the group is split into 4x4 luma blocks (class18088 /// the group is split into 4x4 luma blocks (class
17961 /// `context-read-from-one-cell`).18089 /// `context-read-from-one-cell`).
17962-fn plane_to_mi(chroma: bool, coord: usize) -> usize {18090+fn plane_to_mi(chroma: bool, coord: usize, ss: usize) -> usize {
17963- if chroma { (coord / 2) | 1 } else { coord / 4 }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 }
17964 }18093 }
17965 18094
17966 /// This plane's own transform width in pixels at the covering block, spec18095 /// This plane's own transform width in pixels at the covering block, spec
@@ -19630,7 +19759,7 @@ impl<'a> EdgeCtx<'a> {
19630 chroma,19759 chroma,
19631 seg_lf_active,19760 seg_lf_active,
19632 delta_idx: if plane_idx == 0 { dir } else { plane_idx + 1 },19761 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 },
19634 base0,19763 base0,
19635 lvl,19764 lvl,
19636 }19765 }
@@ -19659,7 +19788,10 @@ impl<'a> EdgeCtx<'a> {
19659 /// entirely. Returns `None` when this 4-pixel edge group is not filtered.19788 /// entirely. Returns `None` when this 4-pixel edge group is not filtered.
19660 #[inline(always)]19789 #[inline(always)]
19661 fn edge_params(c: &EdgeCtx, x0: usize, y0: usize) -> Option<(u8, i32)> {19790 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+ );
19663 let cur_tx = if c.dir == 0 {19795 let cur_tx = if c.dir == 0 {
19664 tx_px_at(c.n, c.chroma, mi_r, mi_c)19796 tx_px_at(c.n, c.chroma, mi_r, mi_c)
19665 } else {19797 } else {
@@ -19731,10 +19863,11 @@ fn edge_params_body(
19731 (usize::from(cur_org[0]), usize::from(cur_dim[1]))19863 (usize::from(cur_org[0]), usize::from(cur_dim[1]))
19732 };19864 };
19733 let pu_edge = if c.chroma {19865 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);
19735 (if c.dir == 0 { x0 } else { y0 }) % plane_dim == 019868 (if c.dir == 0 { x0 } else { y0 }) % plane_dim == 0
19736 } else {19869 } else {
19737- plane_to_mi(false, if c.dir == 0 { x0 } else { y0 }) == org_px19870+ plane_to_mi(false, if c.dir == 0 { x0 } else { y0 }, 0) == org_px
19738 };19871 };
19739 if !pu_edge19872 if !pu_edge
19740 && cur_ref != 019873 && cur_ref != 0
@@ -21383,16 +21516,16 @@ fn replay_inner(
21383 width: tw,21516 width: tw,
21384 height: th,21517 height: th,
21385 y: crop(&y, tw, th),21518 y: crop(&y, tw, th),
21386- u: crop(&u, tw.div_ceil(2), th.div_ceil(2)),21519+ u: crop(&u, round_ss(tw, ss_x(fctx)), round_ss(th, ss_y(fctx))),
21387- v: crop(&v, tw.div_ceil(2), th.div_ceil(2)),21520+ v: crop(&v, round_ss(tw, ss_x(fctx)), round_ss(th, ss_y(fctx))),
21388 });21521 });
21389 });21522 });
21390 let out = Picture {21523 let out = Picture {
21391 width: fw,21524 width: fw,
21392 height: fh,21525 height: fh,
21393 y: crop(&y, fw, fh),21526 y: crop(&y, fw, fh),
21394- u: crop(&u, fw.div_ceil(2), fh.div_ceil(2)),21527+ u: crop(&u, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
21395- v: crop(&v, fw.div_ceil(2), fh.div_ceil(2)),21528+ v: crop(&v, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
21396 };21529 };
21397 // The working planes outlive the crop: either they ARE the21530 // The working planes outlive the crop: either they ARE the
21398 // deblocked planes this candidate's successors reuse, or they go21531 // deblocked planes this candidate's successors reuse, or they go
@@ -21440,7 +21573,7 @@ pub(crate) fn replay_restoration(
21440 let r = slot.as_mut()?;21573 let r = slot.as_mut()?;
21441 let (cdefed, deblocked) = r.final_luma.as_ref()?;21574 let (cdefed, deblocked) = r.final_luma.as_ref()?;
21442 let (fw, fh) = (r.frame_width, r.frame_height);21575 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());
21444 let (horz, vert) = (grid.horz_units[0], grid.vert_units[0]);21577 let (horz, vert) = (grid.horz_units[0], grid.vert_units[0]);
21445 if horz == 0 || units.len() != horz * vert {21578 if horz == 0 || units.len() != horz * vert {
21446 return None;21579 return None;
@@ -21651,18 +21784,19 @@ fn cdef_band(
21651 w[(mi_r / 2) * unit_cols + mi_c / 2] = mark;21784 w[(mi_r / 2) * unit_cols + mi_c / 2] = mark;
21652 }21785 }
21653 if enable_primary_uv || enable_secondary_uv {21786 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));
21655 for (plane, src_p) in [(&mut *u, src_u), (&mut *v, src_v)] {21789 for (plane, src_p) in [(&mut *u, src_u), (&mut *v, src_v)] {
21656 let (tw, th) = (plane.true_width, plane.true_height);21790 let (tw, th) = (plane.true_width, plane.true_height);
21657 let stride = plane.width;21791 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);
21659 cdef_filter_block(21793 cdef_filter_block(
21660 &win_uv,21794 &win_uv,
21661 plane,21795 plane,
21662 cox,21796 cox,
21663 coy,21797 coy,
21664- 4,21798+ csize_x,
21665- 4,21799+ csize_y,
21666 t_uv,21800 t_uv,
21667 uv_sec_strength,21801 uv_sec_strength,
21668 uv_dir,21802 uv_dir,
@@ -22376,9 +22510,9 @@ fn apply_loop_restoration(
22376 &u.data,22510 &u.data,
22377 &deblocked_u.data,22511 &deblocked_u.data,
22378 u.width,22512 u.width,
22379- frame_w.div_ceil(2),22513+ round_ss(frame_w, ss_x(fctx)),
22380- frame_h.div_ceil(2),22514+ round_ss(frame_h, ss_y(fctx)),
22381- 1,22515+ ss_y(fctx) as u32,
22382 lr.frame_restoration_type[1],22516 lr.frame_restoration_type[1],
22383 lr.loop_restoration_size[1],22517 lr.loop_restoration_size[1],
22384 grid,22518 grid,
@@ -22391,9 +22525,9 @@ fn apply_loop_restoration(
22391 &v.data,22525 &v.data,
22392 &deblocked_v.data,22526 &deblocked_v.data,
22393 v.width,22527 v.width,
22394- frame_w.div_ceil(2),22528+ round_ss(frame_w, ss_x(fctx)),
22395- frame_h.div_ceil(2),22529+ round_ss(frame_h, ss_y(fctx)),
22396- 1,22530+ ss_y(fctx) as u32,
22397 lr.frame_restoration_type[2],22531 lr.frame_restoration_type[2],
22398 lr.loop_restoration_size[2],22532 lr.loop_restoration_size[2],
22399 grid,22533 grid,
@@ -22857,27 +22991,29 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
22857 tile_x1: width,22991 tile_x1: width,
22858 tile_y1: height,22992 tile_y1: height,
22859 };22993 };
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));
22860 let mut u = PlaneBuf {22996 let mut u = PlaneBuf {
22861- data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),22997+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
22862- width: width / 2,22998+ width: cw,
22863- height: height / 2,22999+ height: ch,
22864- true_width: true_width / 2,23000+ true_width: ctw,
22865- true_height: true_height / 2,23001+ true_height: cth,
22866 tile_x0: 0,23002 tile_x0: 0,
22867 tile_y0: 0,23003 tile_y0: 0,
22868- tile_x1: width / 2,23004+ tile_x1: cw,
22869- tile_y1: height / 2,23005+ tile_y1: ch,
22870 };23006 };
22871 let mut v = PlaneBuf {23007 let mut v = PlaneBuf {
22872- data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),23008+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
22873- width: width / 2,23009+ width: cw,
22874- height: height / 2,23010+ height: ch,
22875- true_width: true_width / 2,23011+ true_width: ctw,
22876- true_height: true_height / 2,23012+ true_height: cth,
22877 tile_x0: 0,23013 tile_x0: 0,
22878 tile_y0: 0,23014 tile_y0: 0,
22879- tile_x1: width / 2,23015+ tile_x1: cw,
22880- tile_y1: height / 2,23016+ tile_y1: ch,
22881 };23017 };
22882 23018
22883 let scan32 = default_scan(TX32);23019 let scan32 = default_scan(TX32);
@@ -22896,10 +23032,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
22896 // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is23032 // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is
22897 // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width --23033 // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width --
22898 // loop restoration runs after the superres upscale.23034 // 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(
22900 lr,23036 lr,
22901 superres(fctx).map_or(frame_width, |(w, _)| w),23037 superres(fctx).map_or(frame_width, |(w, _)| w),
22902 frame_height,23038 frame_height,
23039+ fctx.subsampling_x.get(),
23040+ fctx.subsampling_y.get(),
22903 );23041 );
22904 23042
22905 // lane-tiles r2: each tile gets its own fresh `SymbolDecoder` over its23043 // 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(
24903 tile_x1: out_w,25041 tile_x1: out_w,
24904 tile_y1: in_h,25042 tile_y1: in_h,
24905 };25043 };
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)));
24907 y = up(&y, fw, fh, uw);25045 y = up(&y, fw, fh, uw);
24908 u = up(&u, cw, ch, cuw);25046 u = up(&u, cw, ch, cuw);
24909 v = up(&v, cw, ch, cuw);25047 v = up(&v, cw, ch, cuw);
@@ -24990,8 +25128,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
24990 width: true_width,25128 width: true_width,
24991 height: true_height,25129 height: true_height,
24992 y: yc,25130 y: yc,
24993- u: crop(&u, 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))),
24994- v: crop(&v, true_width.div_ceil(2), true_height.div_ceil(2)),25132+ v: crop(&v, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))),
24995 })25133 })
24996 } else {25134 } else {
24997 None25135 None
@@ -25002,8 +25140,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
25002 width: fw,25140 width: fw,
25003 height: fh,25141 height: fh,
25004 y: crop_owned(y, fw, fh),25142 y: crop_owned(y, fw, fh),
25005- u: crop_owned(u, 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))),
25006- v: crop_owned(v, fw.div_ceil(2), fh.div_ceil(2)),25144+ v: crop_owned(v, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
25007 },25145 },
25008 result_cdfs,25146 result_cdfs,
25009 ))25147 ))
@@ -25276,8 +25414,9 @@ fn read_intrabc_dv(
25276 /// A 1/8-pel motion vector component converted to the 1/16-pel offset25414 /// A 1/8-pel motion vector component converted to the 1/16-pel offset
25277 /// [`mc::predict`] takes, duplicating [`crate::encode`]'s private `mv_to_q4`25415 /// [`mc::predict`] takes, duplicating [`crate::encode`]'s private `mv_to_q4`
25278 /// (its own doc comment explains the `*2`/`*1` luma/chroma split).25416 /// (its own doc comment explains the `*2`/`*1` luma/chroma split).
25279-fn mv_to_q4(pos: usize, mv_component: i32, luma: bool) -> i32 {25417+fn mv_to_q4(pos: usize, mv_component: i32, ss: usize) -> i32 {
25280- (pos as i32) * 16 + mv_component * if luma { 2 } else { 1 }25418+ // orig_pos += mv * (1 << (1 - ss)). Luma always passes 0.
25419+ (pos as i32) * 16 + mv_component * (1i32 << (1 - ss as i32))
25281 }25420 }
25282 25421
25283 impl PlaneBuf<'_> {25422 impl PlaneBuf<'_> {
@@ -25825,8 +25964,18 @@ impl<'p> RefPix<'p> {
25825 dims[i].and(pics[i]).map(|g| {25964 dims[i].and(pics[i]).map(|g| {
25826 (25965 (
25827 whole_plane(&g.y, g.width, g.height),25966 whole_plane(&g.y, g.width, g.height),
25828- whole_plane(&g.u, g.width / 2, g.height / 2),25967+ {
25829- whole_plane(&g.v, g.width / 2, g.height / 2),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+ },
25830 )25979 )
25831 })25980 })
25832 });25981 });
@@ -26384,8 +26533,8 @@ fn obmc_neighbour_pred(
26384 refplane.width,26533 refplane.width,
26385 refplane.true_width,26534 refplane.true_width,
26386 refplane.true_height,26535 refplane.true_height,
26387- mv_to_q4(x, mv.1, luma),26536+ mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
26388- mv_to_q4(y, mv.0, luma),26537+ mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
26389 w,26538 w,
26390 h,26539 h,
26391 h_kind,26540 h_kind,
@@ -26398,8 +26547,8 @@ fn obmc_neighbour_pred(
26398 refplane.width,26547 refplane.width,
26399 refplane.true_width,26548 refplane.true_width,
26400 refplane.true_height,26549 refplane.true_height,
26401- mv_to_q4(x, mv.1, luma),26550+ mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
26402- mv_to_q4(y, mv.0, luma),26551+ mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
26403 x_scale_fp,26552 x_scale_fp,
26404 w,26553 w,
26405 h,26554 h,
@@ -27440,10 +27589,10 @@ fn decode_inter_block(
27440 fctx.inter_last_mc.with(|c| c.set(None));27589 fctx.inter_last_mc.with(|c| c.set(None));
27441 let has_chroma = strip_chroma.is_none_or(|s| s.has_chroma);27590 let has_chroma = strip_chroma.is_none_or(|s| s.has_chroma);
27442 let (cpx, cpy) = match strip_chroma {27591 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),27592+ Some(s) if s.has_chroma => (s.pair_mi.1 * MI >> ss_x(fctx), s.pair_mi.0 * MI >> ss_y(fctx)),
27444- _ => (px / 2, py / 2),27593+ _ => (px >> ss_x(fctx), py >> ss_y(fctx)),
27445 };27594 };
27446- let chroma_side = side / 2;27595+ let chroma_side = side >> ss_x(fctx);
27447 let (write_chroma_w, write_chroma_h) = match strip_chroma {27596 let (write_chroma_w, write_chroma_h) = match strip_chroma {
27448 Some(s) if s.has_chroma => {27597 Some(s) if s.has_chroma => {
27449 if s.horz {27598 if s.horz {
@@ -27452,8 +27601,21 @@ fn decode_inter_block(
27452 (4, 8)27601 (4, 8)
27453 }27602 }
27454 }27603 }
27455- _ => (write_w / 2, write_h / 2),27604+ _ => (write_w >> ss_x(fctx), write_h >> ss_y(fctx)),
27456 };27605 };
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+ };
27457 // lane-midcut r3 (same rule as lane-t900 r5's `warp_plane_allowed`, one27619 // lane-midcut r3 (same rule as lane-t900 r5's `warp_plane_allowed`, one
27458 // copy kept at the merge): `av1_init_warp_params` (libaom reconinter.c)27620 // copy kept at the merge): `av1_init_warp_params` (libaom reconinter.c)
27459 // bails per PLANE at `block_width < 8 || block_height < 8` -- on the27621 // bails per PLANE at `block_width < 8 || block_height < 8` -- on the
@@ -28242,8 +28404,8 @@ fn decode_inter_block(
28242 py0.width,28404 py0.width,
28243 py0.true_width,28405 py0.true_width,
28244 py0.true_height,28406 py0.true_height,
28245- mv_to_q4(px, mv0.1, true),28407+ mv_to_q4(px, mv0.1, 0),
28246- mv_to_q4(py, mv0.0, true),28408+ mv_to_q4(py, mv0.0, 0),
28247 scale0,28409 scale0,
28248 side,28410 side,
28249 side,28411 side,
@@ -28269,8 +28431,8 @@ fn decode_inter_block(
28269 py1.width,28431 py1.width,
28270 py1.true_width,28432 py1.true_width,
28271 py1.true_height,28433 py1.true_height,
28272- mv_to_q4(px, mv1.1, true),28434+ mv_to_q4(px, mv1.1, 0),
28273- mv_to_q4(py, mv1.0, true),28435+ mv_to_q4(py, mv1.0, 0),
28274 scale1,28436 scale1,
28275 side,28437 side,
28276 side,28438 side,
@@ -28318,8 +28480,8 @@ fn decode_inter_block(
28318 pu0.width,28480 pu0.width,
28319 pu0.true_width,28481 pu0.true_width,
28320 pu0.true_height,28482 pu0.true_height,
28321- mv_to_q4(cpx, mv0.1, false),28483+ mv_to_q4(cpx, mv0.1, ss_x(fctx)),
28322- mv_to_q4(cpy, mv0.0, false),28484+ mv_to_q4(cpy, mv0.0, ss_x(fctx)),
28323 scale0,28485 scale0,
28324 chroma_side,28486 chroma_side,
28325 chroma_side,28487 chroma_side,
@@ -28337,7 +28499,7 @@ fn decode_inter_block(
28337 crate::warp::warp_affine_compound(28499 crate::warp::warp_affine_compound(
28338 wp, &pu0.data, pu0.true_width as i32, pu0.true_height as i32,28500 wp, &pu0.data, pu0.true_width as i32, pu0.true_height as i32,
28339 pu0.width as i32, &mut inter0_u, cpx as i32, cpy as i32,28501 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,
28341 );28503 );
28342 }28504 }
28343 }28505 }
@@ -28347,8 +28509,8 @@ fn decode_inter_block(
28347 pu1.width,28509 pu1.width,
28348 pu1.true_width,28510 pu1.true_width,
28349 pu1.true_height,28511 pu1.true_height,
28350- mv_to_q4(cpx, mv1.1, false),28512+ mv_to_q4(cpx, mv1.1, ss_x(fctx)),
28351- mv_to_q4(cpy, mv1.0, false),28513+ mv_to_q4(cpy, mv1.0, ss_x(fctx)),
28352 scale1,28514 scale1,
28353 chroma_side,28515 chroma_side,
28354 chroma_side,28516 chroma_side,
@@ -28366,7 +28528,7 @@ fn decode_inter_block(
28366 crate::warp::warp_affine_compound(28528 crate::warp::warp_affine_compound(
28367 wp, &pu1.data, pu1.true_width as i32, pu1.true_height as i32,28529 wp, &pu1.data, pu1.true_width as i32, pu1.true_height as i32,
28368 pu1.width as i32, &mut inter1_u, cpx as i32, cpy as i32,28530 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,
28370 );28532 );
28371 }28533 }
28372 }28534 }
@@ -28379,7 +28541,7 @@ fn decode_inter_block(
28379 side,28541 side,
28380 chroma_side,28542 chroma_side,
28381 chroma_side,28543 chroma_side,
28382- true,28544+ ss_x(fctx) == 1 && ss_y(fctx) == 1,
28383 &mut pred_u, fctx,28545 &mut pred_u, fctx,
28384 );28546 );
28385 } else {28547 } else {
@@ -28392,8 +28554,8 @@ fn decode_inter_block(
28392 pv0.width,28554 pv0.width,
28393 pv0.true_width,28555 pv0.true_width,
28394 pv0.true_height,28556 pv0.true_height,
28395- mv_to_q4(cpx, mv0.1, false),28557+ mv_to_q4(cpx, mv0.1, ss_x(fctx)),
28396- mv_to_q4(cpy, mv0.0, false),28558+ mv_to_q4(cpy, mv0.0, ss_x(fctx)),
28397 scale0,28559 scale0,
28398 chroma_side,28560 chroma_side,
28399 chroma_side,28561 chroma_side,
@@ -28411,7 +28573,7 @@ fn decode_inter_block(
28411 crate::warp::warp_affine_compound(28573 crate::warp::warp_affine_compound(
28412 wp, &pv0.data, pv0.true_width as i32, pv0.true_height as i32,28574 wp, &pv0.data, pv0.true_width as i32, pv0.true_height as i32,
28413 pv0.width as i32, &mut inter0_v, cpx as i32, cpy as i32,28575 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,
28415 );28577 );
28416 }28578 }
28417 }28579 }
@@ -28421,8 +28583,8 @@ fn decode_inter_block(
28421 pv1.width,28583 pv1.width,
28422 pv1.true_width,28584 pv1.true_width,
28423 pv1.true_height,28585 pv1.true_height,
28424- mv_to_q4(cpx, mv1.1, false),28586+ mv_to_q4(cpx, mv1.1, ss_x(fctx)),
28425- mv_to_q4(cpy, mv1.0, false),28587+ mv_to_q4(cpy, mv1.0, ss_x(fctx)),
28426 scale1,28588 scale1,
28427 chroma_side,28589 chroma_side,
28428 chroma_side,28590 chroma_side,
@@ -28440,7 +28602,7 @@ fn decode_inter_block(
28440 crate::warp::warp_affine_compound(28602 crate::warp::warp_affine_compound(
28441 wp, &pv1.data, pv1.true_width as i32, pv1.true_height as i32,28603 wp, &pv1.data, pv1.true_width as i32, pv1.true_height as i32,
28442 pv1.width as i32, &mut inter1_v, cpx as i32, cpy as i32,28604 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,
28444 );28606 );
28445 }28607 }
28446 }28608 }
@@ -28453,7 +28615,7 @@ fn decode_inter_block(
28453 side,28615 side,
28454 chroma_side,28616 chroma_side,
28455 chroma_side,28617 chroma_side,
28456- true,28618+ ss_x(fctx) == 1 && ss_y(fctx) == 1,
28457 &mut pred_v, fctx,28619 &mut pred_v, fctx,
28458 );28620 );
28459 } else {28621 } else {
@@ -29561,8 +29723,8 @@ fn decode_inter_block(
29561 py_ref.width,29723 py_ref.width,
29562 py_ref.true_width,29724 py_ref.true_width,
29563 py_ref.true_height,29725 py_ref.true_height,
29564- mv_to_q4(px, mv.1, true),29726+ mv_to_q4(px, mv.1, 0),
29565- mv_to_q4(py, mv.0, true),29727+ mv_to_q4(py, mv.0, 0),
29566 side,29728 side,
29567 side,29729 side,
29568 write_w,29730 write_w,
@@ -29576,8 +29738,8 @@ fn decode_inter_block(
29576 pu_ref.width,29738 pu_ref.width,
29577 pu_ref.true_width,29739 pu_ref.true_width,
29578 pu_ref.true_height,29740 pu_ref.true_height,
29579- mv_to_q4(cpx, mv.1, false),29741+ mv_to_q4(cpx, mv.1, ss_x(fctx)),
29580- mv_to_q4(cpy, mv.0, false),29742+ mv_to_q4(cpy, mv.0, ss_x(fctx)),
29581 chroma_side,29743 chroma_side,
29582 chroma_side,29744 chroma_side,
29583 write_chroma_w,29745 write_chroma_w,
@@ -29591,8 +29753,8 @@ fn decode_inter_block(
29591 pv_ref.width,29753 pv_ref.width,
29592 pv_ref.true_width,29754 pv_ref.true_width,
29593 pv_ref.true_height,29755 pv_ref.true_height,
29594- mv_to_q4(cpx, mv.1, false),29756+ mv_to_q4(cpx, mv.1, ss_x(fctx)),
29595- mv_to_q4(cpy, mv.0, false),29757+ mv_to_q4(cpy, mv.0, ss_x(fctx)),
29596 chroma_side,29758 chroma_side,
29597 chroma_side,29759 chroma_side,
29598 write_chroma_w,29760 write_chroma_w,
@@ -29607,8 +29769,8 @@ fn decode_inter_block(
29607 py_ref.width,29769 py_ref.width,
29608 py_ref.true_width,29770 py_ref.true_width,
29609 py_ref.true_height,29771 py_ref.true_height,
29610- mv_to_q4(px, mv.1, true),29772+ mv_to_q4(px, mv.1, 0),
29611- mv_to_q4(py, mv.0, true),29773+ mv_to_q4(py, mv.0, 0),
29612 luma_scale,29774 luma_scale,
29613 side,29775 side,
29614 side,29776 side,
@@ -29623,8 +29785,8 @@ fn decode_inter_block(
29623 pu_ref.width,29785 pu_ref.width,
29624 pu_ref.true_width,29786 pu_ref.true_width,
29625 pu_ref.true_height,29787 pu_ref.true_height,
29626- mv_to_q4(cpx, mv.1, false),29788+ mv_to_q4(cpx, mv.1, ss_x(fctx)),
29627- mv_to_q4(cpy, mv.0, false),29789+ mv_to_q4(cpy, mv.0, ss_x(fctx)),
29628 luma_scale,29790 luma_scale,
29629 chroma_side,29791 chroma_side,
29630 chroma_side,29792 chroma_side,
@@ -29639,8 +29801,8 @@ fn decode_inter_block(
29639 pv_ref.width,29801 pv_ref.width,
29640 pv_ref.true_width,29802 pv_ref.true_width,
29641 pv_ref.true_height,29803 pv_ref.true_height,
29642- mv_to_q4(cpx, mv.1, false),29804+ mv_to_q4(cpx, mv.1, ss_x(fctx)),
29643- mv_to_q4(cpy, mv.0, false),29805+ mv_to_q4(cpy, mv.0, ss_x(fctx)),
29644 luma_scale,29806 luma_scale,
29645 chroma_side,29807 chroma_side,
29646 chroma_side,29808 chroma_side,
@@ -29684,12 +29846,12 @@ fn decode_inter_block(
29684 crate::warp::warp_affine(29846 crate::warp::warp_affine(
29685 params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32,29847 params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32,
29686 pu_ref.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32,29848 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,
29688 );29850 );
29689 crate::warp::warp_affine(29851 crate::warp::warp_affine(
29690 params, &pv_ref.data, pv_ref.true_width as i32, pv_ref.true_height as i32,29852 params, &pv_ref.data, pv_ref.true_width as i32, pv_ref.true_height as i32,
29691 pv_ref.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_side as i32,29853 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,
29693 );29855 );
29694 }29856 }
29695 }29857 }
@@ -29736,8 +29898,8 @@ fn decode_inter_block(
29736 src.width,29898 src.width,
29737 src.true_width,29899 src.true_width,
29738 src.true_height,29900 src.true_height,
29739- mv_to_q4(cpx, prev_mv.1, false),29901+ mv_to_q4(cpx, prev_mv.1, ss_x(fctx)),
29740- mv_to_q4(cpy, prev_mv.0, false),29902+ mv_to_q4(cpy, prev_mv.0, ss_x(fctx)),
29741 prev_scale,29903 prev_scale,
29742 piece_w,29904 piece_w,
29743 piece_h,29905 piece_h,
@@ -31284,7 +31446,7 @@ fn decode_inter_sub8_split4(
31284 hit!(SUB8_INTER_SPLIT_HITS);31446 hit!(SUB8_INTER_SPLIT_HITS);
31285 let (gr, gc) = group_mi;31447 let (gr, gc) = group_mi;
31286 let (gpx, gpy) = (gc * MI, gr * MI);31448 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));
31288 // Per-sub-block state the group's chroma prediction needs (spec31450 // Per-sub-block state the group's chroma prediction needs (spec
31289 // 7.11.3.1's candRow/candCol loop reads each sub-block's OWN mv/ref/31451 // 7.11.3.1's candRow/candCol loop reads each sub-block's OWN mv/ref/
31290 // filters), indexed `dr * 2 + dc`.31452 // filters), indexed `dr * 2 + dc`.
@@ -31577,8 +31739,8 @@ fn decode_inter_sub8_split4(
31577 sref_y.width,31739 sref_y.width,
31578 sref_y.true_width,31740 sref_y.true_width,
31579 sref_y.true_height,31741 sref_y.true_height,
31580- mv_to_q4(px, mv.1, true),31742+ mv_to_q4(px, mv.1, 0),
31581- mv_to_q4(py, mv.0, true),31743+ mv_to_q4(py, mv.0, 0),
31582 luma_scale,31744 luma_scale,
31583 B4,31745 B4,
31584 B4,31746 B4,
@@ -31713,8 +31875,8 @@ fn decode_inter_sub8_split4(
31713 plane.width,31875 plane.width,
31714 plane.true_width,31876 plane.true_width,
31715 plane.true_height,31877 plane.true_height,
31716- mv_to_q4(ox, mv.1, false),31878+ mv_to_q4(ox, mv.1, ss_x(fctx)),
31717- mv_to_q4(oy, mv.0, false),31879+ mv_to_q4(oy, mv.0, ss_x(fctx)),
31718 piece_scale,31880 piece_scale,
31719 pw,31881 pw,
31720 ph,31882 ph,
@@ -32194,7 +32356,7 @@ fn decode_intra_sub8_leaf(
32194 // chroma-reference block's own type. Same body as [`decode_leaf_rect8`]'s32356 // chroma-reference block's own type. Same body as [`decode_leaf_rect8`]'s
32195 // post-loop chroma.32357 // post-loop chroma.
32196 let (gpx, gpy) = (gc * MI, gr * MI);32358 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));
32198 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);32360 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);
32199 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(gr, gc, r, c);32361 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(gr, gc, r, c);
32200 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };32362 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
@@ -32324,7 +32486,7 @@ fn decode_inter_sub8_rect2(
32324 }32486 }
32325 let (gr, gc) = group_mi;32487 let (gr, gc) = group_mi;
32326 let (gpx, gpy) = (gc * MI, gr * MI);32488 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));
32328 // Per-sub-block state the group's one chroma unit predicts from.32490 // Per-sub-block state the group's one chroma unit predicts from.
32329 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =32491 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =
32330 [None; 2];32492 [None; 2];
@@ -32632,8 +32794,8 @@ fn decode_inter_sub8_rect2(
32632 sref_y.width,32794 sref_y.width,
32633 sref_y.true_width,32795 sref_y.true_width,
32634 sref_y.true_height,32796 sref_y.true_height,
32635- mv_to_q4(px, mv.1, true),32797+ mv_to_q4(px, mv.1, 0),
32636- mv_to_q4(py, mv.0, true),32798+ mv_to_q4(py, mv.0, 0),
32637 luma_scale,32799 luma_scale,
32638 bw,32800 bw,
32639 bh,32801 bh,
@@ -32819,8 +32981,8 @@ fn decode_inter_sub8_rect2(
32819 plane.width,32981 plane.width,
32820 plane.true_width,32982 plane.true_width,
32821 plane.true_height,32983 plane.true_height,
32822- mv_to_q4(ox, mv.1, false),32984+ mv_to_q4(ox, mv.1, ss_x(fctx)),
32823- mv_to_q4(oy, mv.0, false),32985+ mv_to_q4(oy, mv.0, ss_x(fctx)),
32824 piece_scale,32986 piece_scale,
32825 piece_w,32987 piece_w,
32826 piece_h,32988 piece_h,
@@ -33074,7 +33236,7 @@ fn decode_inter_block8(
33074 const SIZE_GROUP_8: usize = 1;33236 const SIZE_GROUP_8: usize = 1;
33075 33237
33076 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);33238 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));
33078 // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took33240 // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
33079 // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --33241 // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
33080 // read back by the luma residual read and the tail's neighbour/loop-filter33242 // read back by the luma residual read and the tail's neighbour/loop-filter
@@ -33534,8 +33696,8 @@ fn decode_inter_block8(
33534 py0.width,33696 py0.width,
33535 py0.true_width,33697 py0.true_width,
33536 py0.true_height,33698 py0.true_height,
33537- mv_to_q4(px, mv0.1, true),33699+ mv_to_q4(px, mv0.1, 0),
33538- mv_to_q4(py, mv0.0, true),33700+ mv_to_q4(py, mv0.0, 0),
33539 scale0,33701 scale0,
33540 SIDE,33702 SIDE,
33541 SIDE,33703 SIDE,
@@ -33556,8 +33718,8 @@ fn decode_inter_block8(
33556 py1.width,33718 py1.width,
33557 py1.true_width,33719 py1.true_width,
33558 py1.true_height,33720 py1.true_height,
33559- mv_to_q4(px, mv1.1, true),33721+ mv_to_q4(px, mv1.1, 0),
33560- mv_to_q4(py, mv1.0, true),33722+ mv_to_q4(py, mv1.0, 0),
33561 scale1,33723 scale1,
33562 SIDE,33724 SIDE,
33563 SIDE,33725 SIDE,
@@ -33596,8 +33758,8 @@ fn decode_inter_block8(
33596 pu0.width,33758 pu0.width,
33597 pu0.true_width,33759 pu0.true_width,
33598 pu0.true_height,33760 pu0.true_height,
33599- mv_to_q4(cpx, mv0.1, false),33761+ mv_to_q4(cpx, mv0.1, ss_x(fctx)),
33600- mv_to_q4(cpy, mv0.0, false),33762+ mv_to_q4(cpy, mv0.0, ss_x(fctx)),
33601 scale0,33763 scale0,
33602 CHROMA_SIDE,33764 CHROMA_SIDE,
33603 CHROMA_SIDE,33765 CHROMA_SIDE,
@@ -33611,8 +33773,8 @@ fn decode_inter_block8(
33611 pu1.width,33773 pu1.width,
33612 pu1.true_width,33774 pu1.true_width,
33613 pu1.true_height,33775 pu1.true_height,
33614- mv_to_q4(cpx, mv1.1, false),33776+ mv_to_q4(cpx, mv1.1, ss_x(fctx)),
33615- mv_to_q4(cpy, mv1.0, false),33777+ mv_to_q4(cpy, mv1.0, ss_x(fctx)),
33616 scale1,33778 scale1,
33617 CHROMA_SIDE,33779 CHROMA_SIDE,
33618 CHROMA_SIDE,33780 CHROMA_SIDE,
@@ -33629,7 +33791,7 @@ fn decode_inter_block8(
33629 SIDE,33791 SIDE,
33630 CHROMA_SIDE,33792 CHROMA_SIDE,
33631 CHROMA_SIDE,33793 CHROMA_SIDE,
33632- true,33794+ ss_x(fctx) == 1 && ss_y(fctx) == 1,
33633 &mut pred_u, fctx,33795 &mut pred_u, fctx,
33634 );33796 );
33635 } else {33797 } else {
@@ -33642,8 +33804,8 @@ fn decode_inter_block8(
33642 pv0.width,33804 pv0.width,
33643 pv0.true_width,33805 pv0.true_width,
33644 pv0.true_height,33806 pv0.true_height,
33645- mv_to_q4(cpx, mv0.1, false),33807+ mv_to_q4(cpx, mv0.1, ss_x(fctx)),
33646- mv_to_q4(cpy, mv0.0, false),33808+ mv_to_q4(cpy, mv0.0, ss_x(fctx)),
33647 scale0,33809 scale0,
33648 CHROMA_SIDE,33810 CHROMA_SIDE,
33649 CHROMA_SIDE,33811 CHROMA_SIDE,
@@ -33657,8 +33819,8 @@ fn decode_inter_block8(
33657 pv1.width,33819 pv1.width,
33658 pv1.true_width,33820 pv1.true_width,
33659 pv1.true_height,33821 pv1.true_height,
33660- mv_to_q4(cpx, mv1.1, false),33822+ mv_to_q4(cpx, mv1.1, ss_x(fctx)),
33661- mv_to_q4(cpy, mv1.0, false),33823+ mv_to_q4(cpy, mv1.0, ss_x(fctx)),
33662 scale1,33824 scale1,
33663 CHROMA_SIDE,33825 CHROMA_SIDE,
33664 CHROMA_SIDE,33826 CHROMA_SIDE,
@@ -33675,7 +33837,7 @@ fn decode_inter_block8(
33675 SIDE,33837 SIDE,
33676 CHROMA_SIDE,33838 CHROMA_SIDE,
33677 CHROMA_SIDE,33839 CHROMA_SIDE,
33678- true,33840+ ss_x(fctx) == 1 && ss_y(fctx) == 1,
33679 &mut pred_v, fctx,33841 &mut pred_v, fctx,
33680 );33842 );
33681 } else {33843 } else {
@@ -34311,8 +34473,8 @@ fn decode_inter_block8(
34311 plane.width,34473 plane.width,
34312 plane.true_width,34474 plane.true_width,
34313 plane.true_height,34475 plane.true_height,
34314- mv_to_q4(x, mv.1, luma),34476+ mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
34315- mv_to_q4(y, mv.0, luma),34477+ mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
34316 dim,34478 dim,
34317 dim,34479 dim,
34318 h_filter,34480 h_filter,
@@ -34325,8 +34487,8 @@ fn decode_inter_block8(
34325 plane.width,34487 plane.width,
34326 plane.true_width,34488 plane.true_width,
34327 plane.true_height,34489 plane.true_height,
34328- mv_to_q4(x, mv.1, luma),34490+ mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }),
34329- mv_to_q4(y, mv.0, luma),34491+ mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }),
34330 luma_scale,34492 luma_scale,
34331 dim,34493 dim,
34332 dim,34494 dim,
@@ -34358,12 +34520,12 @@ fn decode_inter_block8(
34358 crate::warp::warp_affine(34520 crate::warp::warp_affine(
34359 params, &sref_u.data, sref_u.true_width as i32, sref_u.true_height as i32,34521 params, &sref_u.data, sref_u.true_width as i32, sref_u.true_height as i32,
34360 sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, CHROMA_SIDE as i32,34522 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,
34362 );34524 );
34363 crate::warp::warp_affine(34525 crate::warp::warp_affine(
34364 params, &sref_v.data, sref_v.true_width as i32, sref_v.true_height as i32,34526 params, &sref_v.data, sref_v.true_width as i32, sref_v.true_height as i32,
34365 sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, CHROMA_SIDE as i32,34527 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,
34367 );34529 );
34368 }34530 }
34369 }34531 }
@@ -35515,27 +35677,29 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
35515 tile_x1: width,35677 tile_x1: width,
35516 tile_y1: height,35678 tile_y1: height,
35517 };35679 };
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));
35518 let mut u = PlaneBuf {35682 let mut u = PlaneBuf {
35519- data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),35683+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
35520- width: width / 2,35684+ width: cw,
35521- height: height / 2,35685+ height: ch,
35522- true_width: true_width / 2,35686+ true_width: ctw,
35523- true_height: true_height / 2,35687+ true_height: cth,
35524 tile_x0: 0,35688 tile_x0: 0,
35525 tile_y0: 0,35689 tile_y0: 0,
35526- tile_x1: width / 2,35690+ tile_x1: cw,
35527- tile_y1: height / 2,35691+ tile_y1: ch,
35528 };35692 };
35529 let mut v = PlaneBuf {35693 let mut v = PlaneBuf {
35530- data: std::borrow::Cow::Owned(fresh_plane(width * height / 4)),35694+ data: std::borrow::Cow::Owned(fresh_plane(cw * ch)),
35531- width: width / 2,35695+ width: cw,
35532- height: height / 2,35696+ height: ch,
35533- true_width: true_width / 2,35697+ true_width: ctw,
35534- true_height: true_height / 2,35698+ true_height: cth,
35535 tile_x0: 0,35699 tile_x0: 0,
35536 tile_y0: 0,35700 tile_y0: 0,
35537- tile_x1: width / 2,35701+ tile_x1: cw,
35538- tile_y1: height / 2,35702+ tile_y1: ch,
35539 };35703 };
35540 35704
35541 let scan32 = default_scan(TX32);35705 let scan32 = default_scan(TX32);
@@ -35565,10 +35729,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
35565 // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is35729 // spec 7.16/libaom `av1_alloc_restoration_struct`: the unit grid is
35566 // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width --35730 // sized from `av1_get_upsampled_plane_size`, i.e. the UPSCALED width --
35567 // loop restoration runs after the superres upscale.35731 // 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(
35569 lr,35733 lr,
35570 superres(fctx).map_or(frame_width, |(w, _)| w),35734 superres(fctx).map_or(frame_width, |(w, _)| w),
35571 frame_height,35735 frame_height,
35736+ fctx.subsampling_x.get(),
35737+ fctx.subsampling_y.get(),
35572 );35738 );
35573 35739
35574 // lane-pipefilt: the loop filters of superblock row r run as soon as row35740 // 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(
38226 tile_x1: out_w,38392 tile_x1: out_w,
38227 tile_y1: in_h,38393 tile_y1: in_h,
38228 };38394 };
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)));
38230 y = up(&y, fw, fh, uw);38396 y = up(&y, fw, fh, uw);
38231 u = up(&u, cw, ch, cuw);38397 u = up(&u, cw, ch, cuw);
38232 v = up(&v, cw, ch, cuw);38398 v = up(&v, cw, ch, cuw);
@@ -38304,8 +38470,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
38304 width: true_width,38470 width: true_width,
38305 height: true_height,38471 height: true_height,
38306 y: crop(&y, true_width, true_height),38472 y: crop(&y, true_width, true_height),
38307- u: crop(&u, 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))),
38308- v: crop(&v, true_width.div_ceil(2), true_height.div_ceil(2)),38474+ v: crop(&v, round_ss(true_width, ss_x(fctx)), round_ss(true_height, ss_y(fctx))),
38309 })38475 })
38310 } else {38476 } else {
38311 None38477 None
@@ -38316,8 +38482,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
38316 width: fw,38482 width: fw,
38317 height: fh,38483 height: fh,
38318 y: crop_owned(y, fw, fh),38484 y: crop_owned(y, fw, fh),
38319- u: crop_owned(u, 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))),
38320- v: crop_owned(v, fw.div_ceil(2), fh.div_ceil(2)),38486+ v: crop_owned(v, round_ss(fw, ss_x(fctx)), round_ss(fh, ss_y(fctx))),
38321 },38487 },
38322 result_cdfs,38488 result_cdfs,
38323 motion_field,38489 motion_field,
@@ -40358,8 +40524,8 @@ mod tests {
40358 ref_y.width,40524 ref_y.width,
40359 ref_y.true_width,40525 ref_y.true_width,
40360 ref_y.true_height,40526 ref_y.true_height,
40361- mv_to_q4(px, left_mv.1, true),40527+ mv_to_q4(px, left_mv.1, 0),
40362- mv_to_q4(py, left_mv.0, true),40528+ mv_to_q4(py, left_mv.0, 0),
40363 side,40529 side,
40364 side,40530 side,
40365 &mut want_near, fctx,40531 &mut want_near, fctx,
@@ -40370,8 +40536,8 @@ mod tests {
40370 ref_y.width,40536 ref_y.width,
40371 ref_y.true_width,40537 ref_y.true_width,
40372 ref_y.true_height,40538 ref_y.true_height,
40373- mv_to_q4(px, above_mv.1, true),40539+ mv_to_q4(px, above_mv.1, 0),
40374- mv_to_q4(py, above_mv.0, true),40540+ mv_to_q4(py, above_mv.0, 0),
40375 side,40541 side,
40376 side,40542 side,
40377 &mut want_nearest, fctx,40543 &mut want_nearest, fctx,
crates/ec-av1/src/refusal_inventory.rsmodified+115 -32
@@ -78,7 +78,7 @@ const REFUSALS: &[&str] = &[
78 // hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused78 // hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused
79 // at the sequence header. Gate:79 // at the sequence header. Gate:
80 // `a_non_420_subsampled_sequence_header_is_refused_by_name`.80 // `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",
82 // lane-av1txr-r2: the third member of the same silent-garbage family.82 // lane-av1txr-r2: the third member of the same silent-garbage family.
83 // `using_qmatrix`/`qm_y`/`qm_u`/`qm_v` are parsed by `ec-av1-syntax` but83 // `using_qmatrix`/`qm_y`/`qm_u`/`qm_v` are parsed by `ec-av1-syntax` but
84 // read by NOTHING on the decode path -- dequantisation is `base_q_idx` +84 // read by NOTHING on the decode path -- dequantisation is `base_q_idx` +
@@ -356,7 +356,7 @@ const PROVEN: &[(&str, &str)] = &[
356 // profile-0 CONTROL still decodes -- the refusal is exercised, not merely356 // profile-0 CONTROL still decodes -- the refusal is exercised, not merely
357 // present.357 // present.
358 (358 (
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",
360 "a_non_420_subsampled_sequence_header_is_refused_by_name",360 "a_non_420_subsampled_sequence_header_is_refused_by_name",
361 ),361 ),
362 // lane-av1txr-r2: the gate encodes the same source twice with real aomenc362 // lane-av1txr-r2: the gate encodes the same source twice with real aomenc
@@ -584,7 +584,11 @@ mod tests {
584 .chain(REFUSALS)584 .chain(REFUSALS)
585 .map(|&s| s.to_owned())585 .map(|&s| s.to_owned())
586 .collect();586 .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+ );
588 592
589 let added: Vec<&String> = found.difference(&listed).collect();593 let added: Vec<&String> = found.difference(&listed).collect();
590 assert!(594 assert!(
@@ -630,9 +634,14 @@ mod tests {
630 let mut found: BTreeSet<String> = BTreeSet::new();634 let mut found: BTreeSet<String> = BTreeSet::new();
631 for (i, _) in src.match_indices("\"SKIP ") {635 for (i, _) in src.match_indices("\"SKIP ") {
632 let rest = &src[i + "\"SKIP ".len()..];636 let rest = &src[i + "\"SKIP ".len()..];
633- let Some(colon) = rest.find(':') else { continue };637+ let Some(colon) = rest.find(':') else {
638+ continue;
639+ };
634 let name = &rest[..colon];640 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+ {
636 continue;645 continue;
637 }646 }
638 // The tail of the message says what was skipped. Only "{e}" -- the647 // The tail of the message says what was skipped. Only "{e}" -- the
@@ -645,7 +654,10 @@ mod tests {
645 }654 }
646 }655 }
647 let listed: BTreeSet<&str> = GATES_THAT_SKIP_ON_A_DECODE_ERROR.iter().copied().collect();656 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();
649 assert!(661 assert!(
650 added.is_empty(),662 added.is_empty(),
651 "these gates turn a decode error into a printed SKIP and are not declared: \663 "these gates turn a decode error into a printed SKIP and are not declared: \
@@ -718,9 +730,18 @@ mod tests {
718 fn every_partition_value_of_an_enumerated_alphabet_has_an_arm() {730 fn every_partition_value_of_an_enumerated_alphabet_has_an_arm() {
719 // (the refusal in the fallback arm, the alphabet its CDF codes)731 // (the refusal in the fallback arm, the alphabet its CDF codes)
720 let blocks: [(&str, usize); 4] = [732 let blocks: [(&str, usize); 4] = [
721- ("a 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1),733+ (
722- ("an INTER 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1),734+ "a 32x32 partition type this decoder does not code",
723- ("a 128x128 superblock partition value outside the 8-symbol alphabet", crate::cdf::PARTITION_W128[0].len() - 1),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+ ),
724 // lane-t900 r24: the key-frame superblock root. Its `part` is745 // lane-t900 r24: the key-frame superblock root. Its `part` is
725 // either a `partition_w64` symbol or, at a frame edge, one of the746 // either a `partition_w64` symbol or, at a frame edge, one of the
726 // three gathered outcomes (PARTITION_HORZ, PARTITION_VERT,747 // three gathered outcomes (PARTITION_HORZ, PARTITION_VERT,
@@ -774,7 +795,10 @@ mod tests {
774 "the `match` at decode.rs:{} refuses {reason:?} but has no arm for {:?} -- that \795 "the `match` at decode.rs:{} refuses {reason:?} but has no arm for {:?} -- that \
775 is a real gap in its {alphabet}-value alphabet, not a dead refusal",796 is a real gap in its {alphabet}-value alphabet, not a dead refusal",
776 i + 1,797 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<_>>()
778 );802 );
779 }803 }
780 assert_eq!(804 assert_eq!(
@@ -828,7 +852,11 @@ mod tests {
828 .next()852 .next()
829 .unwrap_or("")853 .unwrap_or("")
830 .to_owned();854 .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+ );
832 860
833 // Walk up collecting every branch head of this chain, each read to861 // Walk up collecting every branch head of this chain, each read to
834 // the line that opens its body.862 // the line that opens its body.
@@ -838,7 +866,8 @@ mod tests {
838 loop {866 loop {
839 i -= 1;867 i -= 1;
840 let t = lines[i].trim_start();868 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 "))
842 {871 {
843 if i == 0 {872 if i == 0 {
844 break;873 break;
@@ -888,7 +917,10 @@ mod tests {
888 "the chain at decode.rs:{} refuses {reason:?} but no branch names {:?} -- that \917 "the chain at decode.rs:{} refuses {reason:?} but no branch names {:?} -- that \
889 is a real gap in its {alphabet}-value alphabet, not a dead refusal",918 is a real gap in its {alphabet}-value alphabet, not a dead refusal",
890 head + 1,919 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<_>>()
892 );924 );
893 }925 }
894 assert_eq!(found, chains.len());926 assert_eq!(found, chains.len());
@@ -991,11 +1023,18 @@ mod tests {
991 values.insert(((1u64 << length) - 2) as u32);1023 values.insert(((1u64 << length) - 2) as u32);
992 }1024 }
993 let max = *values.iter().max().unwrap();1025 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+ );
995 // A coefficient is masked to 20 bits (spec 5.11.39), and the base and1031 // A coefficient is masked to 20 bits (spec 5.11.39), and the base and
996 // base-range syntax contribute at most 15 of that before the tail, so1032 // base-range syntax contribute at most 15 of that before the tail, so
997 // this is the largest tail a legal coefficient can need.1033 // 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+ );
999 for value in values {1038 for value in values {
1000 match roundtrip(value) {1039 match roundtrip(value) {
1001 Ok(read) => assert_eq!(read, value, "the Golomb tail {value} read back as {read}"),1040 Ok(read) => assert_eq!(read, value, "the Golomb tail {value} read back as {read}"),
@@ -1051,7 +1090,11 @@ mod tests {
1051 ];1090 ];
1052 assert_eq!(alphabets[0].1, 13, "the y_mode alphabet changed size");1091 assert_eq!(alphabets[0].1, 13, "the y_mode alphabet changed size");
1053 for group in &crate::cdf::Y_MODE {1092 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+ );
1055 }1098 }
1056 1099
1057 let src = include_str!("decode.rs");1100 let src = include_str!("decode.rs");
@@ -1059,12 +1102,17 @@ mod tests {
1059 let mut sites = 0usize;1102 let mut sites = 0usize;
1060 for (i, line) in lines.iter().enumerate() {1103 for (i, line) in lines.iter().enumerate() {
1061 let t = line.trim();1104 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+ };
1063 let Some(threshold) = rest.trim_end_matches(" {").parse::<usize>().ok() else {1108 let Some(threshold) = rest.trim_end_matches(" {").parse::<usize>().ok() else {
1064 continue;1109 continue;
1065 };1110 };
1066 // Only the guards carrying THIS refusal.1111 // 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+ {
1068 continue;1116 continue;
1069 }1117 }
1070 sites += 1;1118 sites += 1;
@@ -1094,7 +1142,10 @@ mod tests {
1094 i + 11142 i + 1
1095 );1143 );
1096 }1144 }
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+ );
1098 }1149 }
1099 1150
1100 /// lane-t900 r31, ENUMERATION for "a HORZ/VERT intra strip in a1151 /// lane-t900 r31, ENUMERATION for "a HORZ/VERT intra strip in a
@@ -1154,7 +1205,10 @@ mod tests {
1154 }1205 }
1155 }1206 }
1156 }1207 }
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+ );
1158 assert_eq!(1212 assert_eq!(
1159 allowed_at_128, 0,1213 allowed_at_128, 0,
1160 "a footprint with a 128-pixel side passed av1_allow_palette's bound -- the \1214 "a footprint with a 128-pixel side passed av1_allow_palette's bound -- the \
@@ -1266,11 +1320,17 @@ mod tests {
1266 // (3) The two tables, read out of decode_rect_split's own text: every1320 // (3) The two tables, read out of decode_rect_split's own text: every
1267 // `(w, h) =>` / `(w, h) |` match arm head between the table's `let`1321 // `(w, h) =>` / `(w, h) |` match arm head between the table's `let`
1268 // and the guard that follows it.1322 // 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");
1270 let body = &src[body_at..];1326 let body = &src[body_at..];
1271 let slice = |from: &str, to: &str| -> &str {1327 let slice = |from: &str, to: &str| -> &str {
1272- let a = body.find(from).unwrap_or_else(|| panic!("{from:?} is gone from decode_rect_split"));1328+ let a = body
1273- let b = body[a..].find(to).unwrap_or_else(|| panic!("{to:?} is gone from decode_rect_split"));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"));
1274 &body[a..a + b]1334 &body[a..a + b]
1275 };1335 };
1276 let arm_shapes = |text: &str| -> BTreeSet<(usize, usize)> {1336 let arm_shapes = |text: &str| -> BTreeSet<(usize, usize)> {
@@ -1343,7 +1403,10 @@ mod tests {
1343 }1403 }
1344 }1404 }
1345 }1405 }
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+ );
1347 }1410 }
1348 1411
1349 /// lane-t900 r33, ENUMERATION for "CfL, filter intra or a palette on a1412 /// lane-t900 r33, ENUMERATION for "CfL, filter intra or a palette on a
@@ -1453,9 +1516,15 @@ mod tests {
1453 }1516 }
1454 continue;1517 continue;
1455 }1518 }
1456- let Some(rest) = line.strip_prefix('(') else { continue };1519+ let Some(rest) = line.strip_prefix('(') else {
1457- let Some((pair, _)) = rest.split_once(") =>") else { continue };1520+ continue;
1458- let Some((a, b)) = pair.split_once(',') else { 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+ };
1459 let bw: usize = a.trim().parse().expect("arm bw");1528 let bw: usize = a.trim().parse().expect("arm bw");
1460 let bh: usize = b.trim().parse().expect("arm bh");1529 let bh: usize = b.trim().parse().expect("arm bh");
1461 assert!(1530 assert!(
@@ -1467,9 +1536,18 @@ mod tests {
1467 seen.push((bw, bh));1536 seen.push((bw, bh));
1468 arms += 1;1537 arms += 1;
1469 }1538 }
1470- assert!(arms >= 10, "only {arms} arms parsed -- the table's shape changed");1539+ assert!(
1471- assert!(saw_none_fallback, "filter_intra_size_class_rect lost its `_ => None` fallback");1540+ arms >= 10,
1472- assert!(saw_square_delegate, "filter_intra_size_class_rect lost its square-delegate arm");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+ );
1473 // The guard arm delegates square strips to `filter_intra_size_class`;1551 // The guard arm delegates square strips to `filter_intra_size_class`;
1474 // drive the delegate directly, so a widening there turns THIS test red1552 // drive the delegate directly, so a widening there turns THIS test red
1475 // (the numeric walk never reaches the guard arm).1553 // (the numeric walk never reaches the guard arm).
@@ -1519,7 +1597,10 @@ mod tests {
1519 );1597 );
1520 }1598 }
1521 }1599 }
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+ );
1523 }1604 }
1524 1605
1525 /// Every entry of [`PROVEN`] must still name a live refusal and a test1606 /// Every entry of [`PROVEN`] must still name a live refusal and a test
@@ -1538,7 +1619,9 @@ mod tests {
1538 "{reason:?} is listed as proven but is no longer a decode-path refusal -- drop it from PROVEN (the capability landed) or fix the string"1619 "{reason:?} is listed as proven but is no longer a decode-path refusal -- drop it from PROVEN (the capability landed) or fix the string"
1539 );1620 );
1540 assert!(1621 assert!(
1541- sources.iter().any(|src| src.contains(&format!("fn {gate}("))),1622+ sources
1623+ .iter()
1624+ .any(|src| src.contains(&format!("fn {gate}("))),
1542 "{reason:?} names the proving test {gate}, which exists in neither stream.rs \1625 "{reason:?} names the proving test {gate}, which exists in neither stream.rs \
1543 nor decode.rs"1626 nor decode.rs"
1544 );1627 );
crates/ec-av1/src/restoration.rsmodified+223 -68
@@ -63,7 +63,12 @@ fn inverse_recenter(r: u32, v: u32) -> u32 {
63 /// `aom_read_primitive_refsubexpfin` (`inv_recenter_finite_nonneg` composed63 /// `aom_read_primitive_refsubexpfin` (`inv_recenter_finite_nonneg` composed
64 /// with `read_primitive_subexpfin`): a value in `[0, n)` recentred around64 /// with `read_primitive_subexpfin`): a value in `[0, n)` recentred around
65 /// `reference`.65 /// `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 {
67 let v = decode_subexp_msac(dec, n, k);72 let v = decode_subexp_msac(dec, n, k);
68 if (reference << 1) <= n {73 if (reference << 1) <= n {
69 inverse_recenter(reference, v)74 inverse_recenter(reference, v)
@@ -74,7 +79,13 @@ fn decode_unsigned_subexp_with_ref_msac(dec: &mut SymbolDecoder, n: u32, k: u32,
74 79
75 /// Signed wrapper, matching the way `read_wiener_filter`/`read_sgrproj_filter`80 /// Signed wrapper, matching the way `read_wiener_filter`/`read_sgrproj_filter`
76 /// call `aom_read_primitive_refsubexpfin(rb, max-min+1, k, ref-min)+min`.81 /// 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 {
78 let n = (high - low) as u32;89 let n = (high - low) as u32;
79 let r = (reference - low).clamp(0, n as i32) as u32;90 let r = (reference - low).clamp(0, n as i32) as u32;
80 decode_unsigned_subexp_with_ref_msac(dec, n, k, r) as i32 + low91 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
274 285
275 /// `read_wiener_filter` (decodeframe.c ~1595): both directions, updating286 /// `read_wiener_filter` (decodeframe.c ~1595): both directions, updating
276 /// `reference` in place (the running per-plane, per-tile reference state).287 /// `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 {
278 let vfilter = read_wiener_direction(dec, chroma, &reference.vfilter);293 let vfilter = read_wiener_direction(dec, chroma, &reference.vfilter);
279 let hfilter = read_wiener_direction(dec, chroma, &reference.hfilter);294 let hfilter = read_wiener_direction(dec, chroma, &reference.hfilter);
280 let info = WienerInfo { vfilter, hfilter };295 let info = WienerInfo { vfilter, hfilter };
@@ -400,6 +415,16 @@ pub(crate) struct RestorationGrid {
400 415
401 impl RestorationGrid {416 impl RestorationGrid {
402 pub(crate) fn new(lr: &LoopRestorationParams, frame_width: u32, frame_height: u32) -> Self {417 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 {
403 let mut horz_units = [1usize; 3];428 let mut horz_units = [1usize; 3];
404 let mut vert_units = [1usize; 3];429 let mut vert_units = [1usize; 3];
405 let mut units: [Vec<UnitFilter>; 3] = [Vec::new(), Vec::new(), Vec::new()];430 let mut units: [Vec<UnitFilter>; 3] = [Vec::new(), Vec::new(), Vec::new()];
@@ -410,7 +435,10 @@ impl RestorationGrid {
410 let (pw, ph) = if plane == 0 {435 let (pw, ph) = if plane == 0 {
411 (frame_width, frame_height)436 (frame_width, frame_height)
412 } else {437 } 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+ )
414 };442 };
415 let unit_size = lr.loop_restoration_size[plane];443 let unit_size = lr.loop_restoration_size[plane];
416 horz_units[plane] = count_units(pw, unit_size);444 horz_units[plane] = count_units(pw, unit_size);
@@ -462,7 +490,8 @@ pub(crate) fn read_lr(
462 reference: &mut [(WienerInfo, SgrprojInfo); 3],490 reference: &mut [(WienerInfo, SgrprojInfo); 3],
463 mi_row: u32,491 mi_row: u32,
464 mi_col: u32,492 mi_col: u32,
465- sb_mi: u32, fctx: &crate::decode::FrameCtx,493+ sb_mi: u32,
494+ fctx: &crate::decode::FrameCtx,
466 ) {495 ) {
467 if !lr.uses_lr {496 if !lr.uses_lr {
468 return;497 return;
@@ -472,7 +501,11 @@ pub(crate) fn read_lr(
472 if ftype == RestorationType::None {501 if ftype == RestorationType::None {
473 continue;502 continue;
474 }503 }
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+ };
476 let unit_size = lr.loop_restoration_size[plane];509 let unit_size = lr.loop_restoration_size[plane];
477 let horz_units = grid.horz_units[plane] as u32;510 let horz_units = grid.horz_units[plane] as u32;
478 let vert_units = grid.vert_units[plane] as u32;511 let vert_units = grid.vert_units[plane] as u32;
@@ -636,8 +669,16 @@ fn lr_sample(
636 ) -> i32 {669 ) -> i32 {
637 let col_c = col.clamp(0, plane_w as i64 - 1) as usize;670 let col_c = col.clamp(0, plane_w as i64 - 1) as usize;
638 i32::from(671 i32::from(
639- lr_src_row(cdef, deblocked, stride, plane_w, plane_h, stripe_v_start, stripe_v_end, row)672+ lr_src_row(
640- [col_c],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],
641 )682 )
642 }683 }
643 684
@@ -671,7 +712,11 @@ fn lr_src_row<'a>(
671 let dist = stripe_v_start as i64 - 1 - row;712 let dist = stripe_v_start as i64 - 1 - row;
672 (713 (
673 deblocked,714 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+ },
675 )720 )
676 }721 }
677 } else if stripe_v_end == plane_h {722 } else if stripe_v_end == plane_h {
@@ -712,7 +757,8 @@ fn apply_wiener_stripe(
712 h_end: usize,757 h_end: usize,
713 v_start: usize,758 v_start: usize,
714 v_end: usize,759 v_end: usize,
715- info: &WienerInfo, fctx: &crate::decode::FrameCtx,760+ info: &WienerInfo,
761+ fctx: &crate::decode::FrameCtx,
716 ) {762 ) {
717 let w = h_end - h_start;763 let w = h_end - h_start;
718 let h = v_end - v_start;764 let h = v_end - v_start;
@@ -738,8 +784,16 @@ fn apply_wiener_stripe(
738 // stripe substitution is resolved once per row by `lr_src_row`, and only784 // stripe substitution is resolved once per row by `lr_src_row`, and only
739 // a unit touching the plane's left or right edge needs the clamped copy.785 // a unit touching the plane's left or right edge needs the clamped copy.
740 let hf = &info.hfilter;786 let hf = &info.hfilter;
741- let t16: [i16; 8] =787+ 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];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+ ];
743 // lane-mc: the intermediate is `i16` now. Both bounds are inside that797 // lane-mc: the intermediate is `i16` now. Both bounds are inside that
744 // range at 8- and 10-bit (12-bit is refused in stream.rs), so the798 // range at 8- and 10-bit (12-bit is refused in stream.rs), so the
745 // kernel's saturating store composes with this clamp instead of changing799 // kernel's saturating store composes with this clamp instead of changing
@@ -748,7 +802,9 @@ fn apply_wiener_stripe(
748 let mut hbuf = WIENER_ROW_SCRATCH.with(|c| std::mem::take(&mut *c.borrow_mut()));802 let mut hbuf = WIENER_ROW_SCRATCH.with(|c| std::mem::take(&mut *c.borrow_mut()));
749 for r in 0..rows {803 for r in 0..rows {
750 let row = v_start as i64 - 3 + r as i64;804 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+ );
752 let lo = h_start as i64 - 3;808 let lo = h_start as i64 - 3;
753 let out = &mut inter[r * w..r * w + w];809 let out = &mut inter[r * w..r * w + w];
754 if lo >= 0 && lo as usize + w + 7 <= plane_w {810 if lo >= 0 && lo as usize + w + 7 <= plane_w {
@@ -815,31 +871,27 @@ thread_local! {
815 // `~/.cache/aom-oracle/src/av1/common/restoration.c` to rule out any other871 // `~/.cache/aom-oracle/src/av1/common/restoration.c` to rule out any other
816 // transcription slip.872 // transcription slip.
817 const SGR_X_BY_XPLUS1: [i32; 256] = [873 const SGR_X_BY_XPLUS1: [i32; 256] = [
818- 1, 128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239,874+ 1, 128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239, 240, 241, 242, 243,
819- 240, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 247, 247,875+ 243, 244, 244, 245, 245, 246, 246, 247, 247, 247, 247, 248, 248, 248, 248, 249, 249, 249, 249,
820- 248, 248, 248, 248, 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250,876+ 249, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 252,
821- 250, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 252, 252, 252, 252,877+ 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253,
822- 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253,878+ 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253,
823- 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,
824- 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 254, 254, 254,880+ 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,
825- 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,
826- 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,
827- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,883+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
828- 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254,884+ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
829- 254, 254, 254, 254, 254, 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,
830- 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,
831- 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,
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,
836 ];888 ];
837 889
838 /// `av1_one_by_x` (`restoration.c`): `round(4096/n)` for `n` in `1..=25`890 /// `av1_one_by_x` (`restoration.c`): `round(4096/n)` for `n` in `1..=25`
839 /// (`MAX_NELEM`, `(2*MAX_RADIUS+1)^2`), indexed `[n-1]`.891 /// (`MAX_NELEM`, `(2*MAX_RADIUS+1)^2`), indexed `[n-1]`.
840 const SGR_ONE_BY_X: [i32; 25] = [892 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,893+ 4096, 2048, 1365, 1024, 819, 683, 585, 512, 455, 410, 372, 341, 315, 293, 273, 256, 241, 228,
842- 178, 171, 164,894+ 216, 205, 195, 186, 178, 171, 164,
843 ];895 ];
844 896
845 const SGRPROJ_MTABLE_BITS: u32 = 20;897 const SGRPROJ_MTABLE_BITS: u32 = 20;
@@ -877,7 +929,8 @@ fn compute_ab(
877 // stripe, ~70 KB each at a 64-wide unit), i.e. an allocation whose every929 // stripe, ~70 KB each at a 64-wide unit), i.e. an allocation whose every
878 // page then faulted in on first touch. Every entry is written below, so930 // page then faulted in on first touch. Every entry is written below, so
879 // the resize's fill value is never read.931 // 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,
881 ) {934 ) {
882 let gw = w + 2;935 let gw = w + 2;
883 let gh = h + 2;936 let gh = h + 2;
@@ -927,8 +980,9 @@ fn compute_ab(
927 let i = gi as i64 - 1;980 let i = gi as i64 - 1;
928 {981 {
929 let mut accumulate = |row: i64, add: bool| {982 let mut accumulate = |row: i64, add: bool| {
930- let src =983+ let src = lr_src_row(
931- lr_src_row(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row);984+ cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row,
985+ );
932 fill_clamped_row(src, plane_w, base_col, &mut samp);986 fill_clamped_row(src, plane_w, base_col, &mut samp);
933 if add {987 if add {
934 for ((c_a, c_b), &px) in col_a.iter_mut().zip(col_b.iter_mut()).zip(samp.iter())988 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(
967 a_row[gj] = a;1021 a_row[gj] = a;
968 b_row[gj] = b;1022 b_row[gj] = b;
969 }1023 }
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+ );
971 let dump_gj = 6i64 - h_start as i64 + 1;1033 let dump_gj = 6i64 - h_start as i64 + 1;
972 if dump && v_start as i64 + i == 60 && r == 1 && (0..gw as i64).contains(&dump_gj) {1034 if dump && v_start as i64 + i == 60 && r == 1 && (0..gw as i64).contains(&dump_gj) {
973 let gj = dump_gj as usize;1035 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
1006 let b_s = round2_u31(b, bd_shift);1068 let b_s = round2_u31(b, bd_shift);
1007 let p = (a_s * n - b_s * b_s).max(0);1069 let p = (a_s * n - b_s * b_s).max(0);
1008 let a_val = SGR_X_BY_XPLUS1[z_index(p, s)];1070 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+ );
1010 (a_val, b_val)1075 (a_val, b_val)
1011 }1076 }
1012 1077
1013 /// One grid row's `(A, B)` pairs: [`ab_point`] per element, eight at a time1078 /// One grid row's `(A, B)` pairs: [`ab_point`] per element, eight at a time
1014 /// under AVX2 (the kernel is that arithmetic lane-wise, same widths).1079 /// under AVX2 (the kernel is that arithmetic lane-wise, same widths).
1015 fn ab_row(1080 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,
1017 out: &mut [(i32, i64)],1087 out: &mut [(i32, i64)],
1018 ) {1088 ) {
1019 let mut done = 0usize;1089 let mut done = 0usize;
@@ -1054,7 +1124,12 @@ mod sgr_simd {
1054 #[target_feature(enable = "avx2")]1124 #[target_feature(enable = "avx2")]
1055 #[allow(clippy::too_many_arguments)]1125 #[allow(clippy::too_many_arguments)]
1056 pub unsafe fn ab_row_avx2(1126 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,
1058 out: &mut [(i32, i64)],1133 out: &mut [(i32, i64)],
1059 ) -> usize {1134 ) -> usize {
1060 let len = out.len().min(a_row.len()).min(b_row.len());1135 let len = out.len().min(a_row.len()).min(b_row.len());
@@ -1070,8 +1145,16 @@ mod sgr_simd {
1070 let sh_b = _mm_cvtsi32_si128(SGRPROJ_RECIP_BITS as i32);1145 let sh_b = _mm_cvtsi32_si128(SGRPROJ_RECIP_BITS as i32);
1071 let sh_a = _mm_cvtsi32_si128(2 * bd_shift as i32);1146 let sh_a = _mm_cvtsi32_si128(2 * bd_shift as i32);
1072 let sh_bd = _mm_cvtsi32_si128(bd_shift as i32);1147 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) });1148+ let rnd_a = _mm256_set1_epi32(if bd_shift == 0 {
1074- let rnd_bd = _mm256_set1_epi32(if bd_shift == 0 { 0 } else { 1 << (bd_shift - 1) });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+ });
1075 let mut av = [0i32; 8];1158 let mut av = [0i32; 8];
1076 let mut bv = [0i32; 8];1159 let mut bv = [0i32; 8];
1077 let mut gj = 0usize;1160 let mut gj = 0usize;
@@ -1115,7 +1198,11 @@ mod sgr_simd {
1115 /// width narrower).1198 /// width narrower).
1116 #[inline]1199 #[inline]
1117 fn round2_u31(value: i32, shift: u32) -> i32 {1200 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+ }
1119 }1206 }
1120 1207
1121 /// Copies one source row's `out.len()` samples starting at `base_col` into a1208 /// Copies one source row's `out.len()` samples starting at `base_col` into a
@@ -1150,7 +1237,8 @@ fn apply_sgrproj_stripe(
1150 h_end: usize,1237 h_end: usize,
1151 v_start: usize,1238 v_start: usize,
1152 v_end: usize,1239 v_end: usize,
1153- info: &SgrprojInfo, fctx: &crate::decode::FrameCtx,1240+ info: &SgrprojInfo,
1241+ fctx: &crate::decode::FrameCtx,
1154 ) {1242 ) {
1155 let w = h_end - h_start;1243 let w = h_end - h_start;
1156 let h = v_end - v_start;1244 let h = v_end - v_start;
@@ -1166,10 +1254,16 @@ fn apply_sgrproj_stripe(
1166 (std::mem::take(&mut m.0), std::mem::take(&mut m.1))1254 (std::mem::take(&mut m.0), std::mem::take(&mut m.1))
1167 });1255 });
1168 if r0 > 0 {1256 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+ );
1170 }1261 }
1171 if r1 > 0 {1262 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+ );
1173 }1267 }
1174 let ab0 = (r0 > 0).then_some(&buf0);1268 let ab0 = (r0 > 0).then_some(&buf0);
1175 let ab1 = (r1 > 0).then_some(&buf1);1269 let ab1 = (r1 > 0).then_some(&buf1);
@@ -1185,7 +1279,9 @@ fn apply_sgrproj_stripe(
1185 let bytes: Vec<i32> = (59..=61)1279 let bytes: Vec<i32> = (59..=61)
1186 .flat_map(|row| {1280 .flat_map(|row| {
1187 (5..=7).map(move |col| {1281 (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+ )
1189 })1285 })
1190 })1286 })
1191 .collect();1287 .collect();
@@ -1265,7 +1361,8 @@ fn apply_sgrproj_stripe(
1265 let (a_ur, b_ur) = ab[idx(i - 1, j + 1)];1361 let (a_ur, b_ur) = ab[idx(i - 1, j + 1)];
1266 let (a_dl, b_dl) = ab[idx(i + 1, j - 1)];1362 let (a_dl, b_dl) = ab[idx(i + 1, j - 1)];
1267 let (a_dr, b_dr) = ab[idx(i + 1, j + 1)];1363 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;
1269 let b = (b_c + b_u + b_d + b_l + b_r) * 4 + (b_ul + b_ur + b_dl + b_dr) * 3;1366 let b = (b_c + b_u + b_d + b_l + b_r) * 4 + (b_ul + b_ur + b_dl + b_dr) * 3;
1270 let flt1 = round2(a * dgd + b, SGRPROJ_SGR_BITS + 5 - SGRPROJ_RST_BITS);1367 let flt1 = round2(a * dgd + b, SGRPROJ_SGR_BITS + 5 - SGRPROJ_RST_BITS);
1271 v += xq[1] as i64 * (flt1 - u);1368 v += xq[1] as i64 * (flt1 - u);
@@ -1278,9 +1375,15 @@ fn apply_sgrproj_stripe(
1278 "EC_LR_CALL_DUMP combine: c={:?} u_tap(row60)={:?} d={:?} l={:?} r={:?} \1375 "EC_LR_CALL_DUMP combine: c={:?} u_tap(row60)={:?} d={:?} l={:?} r={:?} \
1279 ul={:?} ur={:?} dl={:?} dr={:?} dense a={a} b={b} dgd={dgd} \1376 ul={:?} ur={:?} dl={:?} dr={:?} dense a={a} b={b} dgd={dgd} \
1280 u={u} flt1={flt1} xq={xq:?} v_before_final_round={v}",1377 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)],1378+ ab[idx(i, j)],
1282- ab[idx(i, j + 1)], ab[idx(i - 1, j - 1)], ab[idx(i - 1, j + 1)],1379+ ab[idx(i - 1, j)],
1283- ab[idx(i + 1, j - 1)], ab[idx(i + 1, j + 1)]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)]
1284 );1387 );
1285 }1388 }
1286 }1389 }
@@ -1311,7 +1414,8 @@ fn filter_restoration_unit(
1311 v_start: usize,1414 v_start: usize,
1312 v_end: usize,1415 v_end: usize,
1313 ss_y: u32,1416 ss_y: u32,
1314- filter: UnitFilter, fctx: &crate::decode::FrameCtx,1417+ filter: UnitFilter,
1418+ fctx: &crate::decode::FrameCtx,
1315 ) {1419 ) {
1316 let full_stripe_height = 64usize >> ss_y;1420 let full_stripe_height = 64usize >> ss_y;
1317 let runit_offset = 8usize >> ss_y;1421 let runit_offset = 8usize >> ss_y;
@@ -1333,10 +1437,32 @@ fn filter_restoration_unit(
1333 }1437 }
1334 match filter {1438 match filter {
1335 UnitFilter::Wiener(info) => apply_wiener_stripe(1439 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,
1337 ),1452 ),
1338 UnitFilter::Sgrproj(info) => apply_sgrproj_stripe(1453 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,
1340 ),1466 ),
1341 UnitFilter::None => {}1467 UnitFilter::None => {}
1342 }1468 }
@@ -1395,12 +1521,16 @@ pub(crate) fn apply_loop_restoration_plane(
1395 let out = unsafe { so.get() };1521 let out = unsafe { so.get() };
1396 for rrow in r_lo..r_hi {1522 for rrow in r_lo..r_hi {
1397 lr_unit_row(1523 lr_unit_row(
1398- out, cdef, deblocked, stride, plane_w, plane_h, ss_y, unit_size, grid,1524+ out, cdef, deblocked, stride, plane_w, plane_h, ss_y, unit_size, grid, plane,
1399- plane, rrow, &rows, fctx,1525+ rrow, &rows, fctx,
1400 );1526 );
1401 }1527 }
1402 });1528 });
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+ );
1404 return;1534 return;
1405 };1535 };
1406 for rrow in r_lo..r_hi.min(rows.len()) {1536 for rrow in r_lo..r_hi.min(rows.len()) {
@@ -1435,7 +1565,11 @@ pub(crate) fn lr_unit_rows(
1435 let mut y0 = 0u32;1565 let mut y0 = 0u32;
1436 while y0 < plane_h as u32 {1566 while y0 < plane_h as u32 {
1437 let remaining_h = plane_h as u32 - y0;1567 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+ };
1439 let v_start = (y0 as i64 - voffset as i64).max(0) as u32;1573 let v_start = (y0 as i64 - voffset as i64).max(0) as u32;
1440 let mut v_end = y0 + uh;1574 let mut v_end = y0 + uh;
1441 if v_end < plane_h as u32 {1575 if v_end < plane_h as u32 {
@@ -1471,7 +1605,11 @@ fn lr_unit_row(
1471 let mut rcol = 0usize;1605 let mut rcol = 0usize;
1472 while x0 < plane_w as u32 {1606 while x0 < plane_w as u32 {
1473 let remaining_w = plane_w as u32 - x0;1607 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+ };
1475 let filter = grid.get(plane, rrow, rcol);1613 let filter = grid.get(plane, rrow, rcol);
1476 if filter != UnitFilter::None {1614 if filter != UnitFilter::None {
1477 filter_restoration_unit(1615 filter_restoration_unit(
@@ -1486,7 +1624,8 @@ fn lr_unit_row(
1486 v_start as usize,1624 v_start as usize,
1487 v_end as usize,1625 v_end as usize,
1488 ss_y,1626 ss_y,
1489- filter, fctx,1627+ filter,
1628+ fctx,
1490 );1629 );
1491 }1630 }
1492 x0 += uw;1631 x0 += uw;
@@ -1510,7 +1649,15 @@ mod tests {
1510 /// `SGRPROJ_PRJ_MAX-MIN+1`.1649 /// `SGRPROJ_PRJ_MAX-MIN+1`.
1511 #[test]1650 #[test]
1512 fn subexp_roundtrips_every_value() {1651 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+ ] {
1514 for v in 0..num_syms {1661 for v in 0..num_syms {
1515 let mut enc = SymbolEncoder::new();1662 let mut enc = SymbolEncoder::new();
1516 write_subexp(&mut enc, num_syms, k, v);1663 write_subexp(&mut enc, num_syms, k, v);
@@ -1548,10 +1695,10 @@ mod tests {
1548 #[test]1695 #[test]
1549 fn signed_subexp_with_ref_roundtrips() {1696 fn signed_subexp_with_ref_roundtrips() {
1550 let cases: [(i32, i32, u32); 4] = [1697 let cases: [(i32, i32, u32); 4] = [
1551- (-5, 11, 1), // Wiener tap01698+ (-5, 11, 1), // Wiener tap0
1552- (-23, 9, 2), // Wiener tap11699+ (-23, 9, 2), // Wiener tap1
1553- (-17, 47, 3), // Wiener tap21700+ (-17, 47, 3), // Wiener tap2
1554- (-96, 32, 4), // SGR xqd01701+ (-96, 32, 4), // SGR xqd0
1555 ];1702 ];
1556 for (low, high, k) in cases {1703 for (low, high, k) in cases {
1557 let n = (high - low) as u32;1704 let n = (high - low) as u32;
@@ -1563,8 +1710,12 @@ mod tests {
1563 write_unsigned_subexp_with_ref(&mut enc, n, k, r, coded_v);1710 write_unsigned_subexp_with_ref(&mut enc, n, k, r, coded_v);
1564 let payload = enc.finish();1711 let payload = enc.finish();
1565 let mut dec = SymbolDecoder::new(&payload);1712 let mut dec = SymbolDecoder::new(&payload);
1566- let got = decode_signed_subexp_with_ref_msac(&mut dec, low, high, k, reference_v);1713+ let got =
1567- assert_eq!(got, v, "low={low} high={high} k={k} reference={reference_v} v={v}");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+ );
1568 }1719 }
1569 }1720 }
1570 }1721 }
@@ -1595,7 +1746,11 @@ mod tests {
1595 let mut dec = SymbolDecoder::new(&payload);1746 let mut dec = SymbolDecoder::new(&payload);
1596 let mut rref = WienerInfo::default();1747 let mut rref = WienerInfo::default();
1597 for u in &units {1748 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+ );
1599 }1754 }
1600 }1755 }
1601 }1756 }
crates/ec-av1/src/stream.rsmodified+6 -4
@@ -1662,10 +1662,11 @@ fn decode_frame(
1662 // unaffected. Gates: `a_non_420_subsampled_sequence_header_is_refused_by_1662 // unaffected. Gates: `a_non_420_subsampled_sequence_header_is_refused_by_
1663 // name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:41663 // name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:4
1664 // stream).1664 // 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 {
1666 return Err(Error::unsupported(1667 return Err(Error::unsupported(
1667 "AV1 decode_stream",1668 "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",
1669 ));1670 ));
1670 }1671 }
1671 // lane-av1txr-r2: `quantization_params.using_qmatrix` (spec 5.9.12) is1672 // lane-av1txr-r2: `quantization_params.using_qmatrix` (spec 5.9.12) is
@@ -1739,6 +1740,7 @@ fn decode_frame(
1739 // the bit depth so a mono frame decoded on a thread that last saw a1740 // the bit depth so a mono frame decoded on a thread that last saw a
1740 // 4:2:0 one never inherits the wrong plane count.1741 // 4:2:0 one never inherits the wrong plane count.
1741 crate::decode::set_mono(seq.mono_chrome, fctx);1742 crate::decode::set_mono(seq.mono_chrome, fctx);
1743+ crate::decode::set_subsampling(seq.subsampling_x, seq.subsampling_y, fctx);
1742 // lane-av1txr: spec 5.9.2 `disable_cdf_update` -- a frame that sets it1744 // lane-av1txr: spec 5.9.2 `disable_cdf_update` -- a frame that sets it
1743 // codes every tile symbol against the CDFs it started with, so the tile1745 // codes every tile symbol against the CDFs it started with, so the tile
1744 // readers must not adapt (libaom `decodeframe.c:2909`:1746 // readers must not adapt (libaom `decodeframe.c:2909`:
@@ -2153,11 +2155,11 @@ pub(crate) mod tests {
2153 #[test]2155 #[test]
2154 fn a_non_420_subsampled_sequence_header_is_refused_by_name() {2156 fn a_non_420_subsampled_sequence_header_is_refused_by_name() {
2155 const NAME: &str = "a_non_420_subsampled_sequence_header_is_refused_by_name";2157 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";
2157 let fctx = &crate::decode::FrameCtx::new();2159 let fctx = &crate::decode::FrameCtx::new();
2158 let picture = test_card(64, 64);2160 let picture = test_card(64, 64);
2159 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();2161 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)] {
2161 let color = ec_av1_syntax::ColorConfig {2163 let color = ec_av1_syntax::ColorConfig {
2162 num_planes: 3,2164 num_planes: 3,
2163 subsampling_x: sx,2165 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`.