forge
Explore
Log in

Don't you dare go Hollow

ec-av1: continue 4:4:4 rect chroma port

Browse files at this commit

8b574e66322f6f3c6f18fe484fc10b9a728a2170Ahmet Kaan GümüşParent: a236cd3
crates/ec-av1/src/decode.rsmodified+487 -154
@@ -8285,7 +8285,14 @@ impl Neighbours {
82858285 /// coded a smooth `uv_mode` -- libaom's `intra_edge_filter_type` for
82868286 /// planes 1/2. Falls back to the coarse [`SUB`] slot on whichever axis no
82878287 /// block has recorded the exact neighbouring mi.
8288- fn smooth_uv_neighbour(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {
8288+ fn smooth_uv_neighbour(
8289+ &self,
8290+ mi_r: usize,
8291+ mi_c: usize,
8292+ r: usize,
8293+ c: usize,
8294+ fctx: &crate::decode::FrameCtx,
8295+ ) -> bool {
82898296 // lane-kf900 r2: libaom reads the chroma neighbours off the CHROMA
82908297 // REFERENCE block, not off the mi that carries the chroma syntax.
82918298 // `set_mi_row_col` (`blockd.h`) takes
@@ -8302,7 +8309,14 @@ impl Neighbours {
83028309 // false for type 1, TRUE for type 0) and upsampled an edge libaom
83038310 // leaves alone -- +1 on rows 2/3 of that block and every chroma block
83048311 // predicting from it (class `context-read-from-one-cell`).
8305- self.smooth_uv_neighbour_unsnapped(mi_r & !1, mi_c & !1, r, c)
8312+ // lane-av1-444: the snap is the SEQUENCE's subsampling, hardcoded
8313+ // `& !1` before -- at subsampling 0/0 libaom's `mi_row & 0` snaps
8314+ // nothing, and the hardcoded snap read a 4x4 leaf's smooth
8315+ // neighbour two mi away (frame 0 of `av1-profile1-444.ivf`, leaf
8316+ // mi(5,15): left neighbour SMOOTH_V at mi(5,14), read at mi(4,13)).
8317+ let snap_y = (1usize << ss_y(fctx)) - 1;
8318+ let snap_x = (1usize << ss_x(fctx)) - 1;
8319+ self.smooth_uv_neighbour_unsnapped(mi_r & !snap_y, mi_c & !snap_x, r, c)
83068320 }
83078321
83088322 /// [`Self::smooth_uv_neighbour`] without the chroma-reference snap, i.e.
@@ -9113,17 +9127,21 @@ pub(crate) fn palette_onscreen_dims(
91139127 }
91149128
91159129 /// [`palette_onscreen`] carried into the chroma plane: `>> subsampling` plus
9116-/// the SAME sub-8 bump the caller's own `(bw / 2).max(4)` applies to the block
9117-/// dimensions (`is_chroma_sub8_x/y`, blockd.h:1533) -- both must move together
9118-/// or a cut 8-wide block reads its chroma map at the wrong width.
9130+/// the SAME sub-8 bump the caller's own `(bw >> ss).max(4)` applies to the
9131+/// block dimensions (`is_chroma_sub8_x/y`, blockd.h:1533) -- both must move
9132+/// together or a cut 8-wide block reads its chroma map at the wrong width.
9133+/// lane-av1-444: the shifts are the sequence's own subsampling (a 4:4:4
9134+/// intra-in-inter palette read its chroma map at the 4:2:0 extent and
9135+/// panicked feeding the 4:2:0-sized prediction to a full-size reconstruct).
91199136 pub(crate) fn palette_onscreen_uv(
91209137 luma: (usize, usize),
91219138 on: (usize, usize),
91229139 chroma: (usize, usize),
9140+ ss: (usize, usize),
91239141 ) -> (usize, usize) {
91249142 (
9125- (on.0 >> 1) + (chroma.0 - (luma.0 >> 1)),
9126- (on.1 >> 1) + (chroma.1 - (luma.1 >> 1)),
9143+ (on.0 >> ss.0) + (chroma.0 - (luma.0 >> ss.0)),
9144+ (on.1 >> ss.1) + (chroma.1 - (luma.1 >> ss.1)),
91279145 )
91289146 }
91299147
@@ -9479,7 +9497,7 @@ fn read_intra_mode_rect(
94799497 // axis to 2 read HALF the colour-index symbols of a 1:4 strip's
94809498 // chroma palette and desynced the tile from there.
94819499 let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4));
9482- let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));
9500+ let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch), (ss_x(fctx), ss_y(fctx)));
94839501 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
94849502 hit!(PALETTE_UV_HITS);
94859503 PaletteUv { size: n, u_colors, v_colors, map }
@@ -10844,7 +10862,7 @@ fn decode_intra_rect_in_inter(
1084410862 });
1084510863 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
1084610864 let (cw, ch) = ((bw >> ss_x(fctx)).max(4), (bh >> ss_y(fctx)).max(4));
10847- let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch));
10865+ let on = palette_onscreen_uv((bw, bh), palette_onscreen(mi_r, mi_c, bw, bh, fctx), (cw, ch), (ss_x(fctx), ss_y(fctx)));
1084810866 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
1084910867 hit!(PALETTE_UV_HITS);
1085010868 hit!(INTRA_IN_INTER_PALETTE_UV_HITS);
@@ -10868,7 +10886,7 @@ fn decode_intra_rect_in_inter(
1086810886 if smooth_neighbor {
1086910887 hit!(SMOOTH_LUMA_HITS);
1087010888 }
10871- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);
10889+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
1087210890 let depth = if fctx.tx_select_inter.with(std::cell::Cell::get) {
1087310891 // The frame's own `TXFM_CONTEXT` bands -- [`tx_size_context_txfm_rect`].
1087410892 let ctx = tx_size_context_txfm_rect(neighbours, (mi_r, mi_c), bw.min(64), bh.min(64), fctx);
@@ -11054,7 +11072,7 @@ fn decode_block_rect(
1105411072 // (spec `get_intra_edge_filter_type`) reads the CHROMA neighbour's
1105511073 // `uv_mode`, not the luma one.
1105611074 let smooth_neighbor_uv =
11057- neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);
11075+ neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
1105811076 // lane-rectsplit r1: `predict_filter_intra` now takes the block's own
1105911077 // `bw`x`bh` (`av1_filter_intra_predictor_c` walks its 4x2 patches over a
1106011078 // rectangle just as happily), so a `use_filter_intra` strip at this level
@@ -11590,7 +11608,7 @@ fn decode_leaf_rect(
1159011608 // lane-cfl r1, same defect as [`decode_leaf_8x8`]: chroma's intra-edge
1159111609 // filter type is the NEIGHBOUR's `uv_mode` (libaom `get_filt_type`), not
1159211610 // a constant `false`.
11593- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);
11611+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
1159411612 let depth = if tx_select {
1159511613 // lane-t900 r2 (sibling sweep): the in-inter `TXFM_CONTEXT` band read
1159611614 // every other rect reader now does -- a no-op on a key frame.
@@ -11918,7 +11936,7 @@ fn decode_block_rect4(
1191811936 // edge-filter strength was read from the wrong neighbour (measured:
1191911937 // seed 43, the last 8x32 strip at luma (152,32), chroma-only mismatch
1192011938 // with luma bit-exact).
11921- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);
11939+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
1192211940 if filter_intra.is_some() {
1192311941 hit!(FILTER_INTRA_RECT_HITS);
1192411942 if bw > bh {
@@ -12714,7 +12732,7 @@ fn decode_rect4_16_strip(
1271412732 // `av1_use_intra_edge_upsample` on (blk_wh 12 <= 16) for a
1271512733 // directional chroma strip, moving 4 samples by 1.
1271612734 let smooth_neighbor_uv =
12717- neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c);
12735+ neighbours.smooth_uv_neighbour(pair_mi.0, pair_mi.1, r, c, fctx);
1271812736 if smooth_neighbor_uv != neighbours.smooth_uv_neighbour_unsnapped(lmi.0, lmi.1, r, c)
1271912737 {
1272012738 hit!(RECT4_16_UV_PAIR_FILT_HITS);
@@ -12951,7 +12969,7 @@ fn decode_block_rect64(
1295112969 hit!(SMOOTH_LUMA_HITS);
1295212970 }
1295312971 let smooth_neighbor_uv =
12954- neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);
12972+ neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
1295512973 if filter_intra.is_some() {
1295612974 // `filter_intra_size_class_rect` already returns `None` for both
1295712975 // `(64, 32)` and `(32, 64)` (`av1_filter_intra_allowed_bsize` caps at
@@ -13730,6 +13748,7 @@ fn read_intra_mode(
1373013748 (side, side),
1373113749 palette_onscreen(mi_r, mi_c, side, side, fctx),
1373213750 (side >> ss_x(fctx), side >> ss_y(fctx)),
13751+ (ss_x(fctx), ss_y(fctx)),
1373313752 );
1373413753 let map = decode_color_index_map(dec, cdfs, n, side >> ss_x(fctx), on, true);
1373513754 hit!(PALETTE_UV_HITS);
@@ -14252,6 +14271,13 @@ impl PlaneBuf<'_> {
1425214271 buf
1425314272 } else {
1425414273 let (above, left, corner) = self.edges(x, y, side, reach);
14274+ if crate::envflags::env_flag!("EC_DEBUG_EDGES") {
14275+ eprintln!(
14276+ "EDGES_SQ x={x} y={y} side={side} mode={mode} above={:?} left={:?} corner={corner:?}",
14277+ above.as_deref(),
14278+ left.as_deref(),
14279+ );
14280+ }
1425514281 let mut prediction = vec![0u16; side * side];
1425614282 if let Some(fi_mode) = filter_intra {
1425714283 crate::intra::predict_filter_intra(
@@ -14571,7 +14597,7 @@ fn decode_block(
1457114597 hit!(SMOOTH_LUMA_HITS);
1457214598 }
1457314599 let smooth_neighbor_uv =
14574- neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);
14600+ neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
1457514601 if crate::envflags::env_flag!("EC_AV1_TRACE") {
1457614602 eprintln!(
1457714603 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
@@ -15448,7 +15474,7 @@ fn decode_block_128rect(
1544815474 if smooth_neighbor {
1544915475 hit!(SMOOTH_LUMA_HITS);
1545015476 }
15451- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);
15477+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c, fctx);
1545215478 // spec 5.11.16 `read_tx_size`: read for every intra block, skipped or
1545315479 // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc).
1545415480 // lane-lossless128: a LOSSLESS frame codes no tx-size symbol at all --
@@ -15812,7 +15838,7 @@ fn decode_leaf8(
1581215838 // The `uv_mode` neighbours are mi-exact (`uv_mode_col`/`uv_mode_row`),
1581315839 // with the coarse [`SUB`] slot as the fallback when no block recorded
1581415840 // that exact mi cell.
15815- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);
15841+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
1581615842 if smooth_neighbor {
1581715843 hit!(SMOOTH_LUMA_HITS);
1581815844 }
@@ -16531,6 +16557,194 @@ fn read_intra_mode_sub8(
1653116557 }
1653216558 Ok((skip, mode, angle_delta_y, chroma, filter_intra, None))
1653316559 }
16560+/// 4:4:4 sub-8x8 key-frame leaf chroma (lane-av1-444). At subsampling 0/0
16561+/// `is_chroma_reference` (av1_common_int.h:1459) is unconditional, so EVERY
16562+/// 4x4 / 4x8 / 8x4 leaf codes its own full-resolution chroma unit right
16563+/// after its own luma (`read_intra_mode_sub8` already read this leaf's own
16564+/// `uv_mode`), not the one shared 4x4 unit [`decode_leaf_split4`] /
16565+/// [`decode_leaf_rect8`]'s group tails decode at 4:2:0. Mirrors those tails
16566+/// arm for arm at leaf scale: a skipped leaf keeps its CfL contribution, an
16567+/// intrabc leaf predicts a frame copy at its DV with the luma `tx_type`
16568+/// inherited through [`INTRABC_CHROMA_TX`] (the caller arms it right after
16569+/// the luma read). The chroma position, reach and entropy-context span are
16570+/// the leaf's own (ss 0/0); the 4x8/8x4 unit reads the same
16571+/// `ChromaRect8x4` tables [`decode_rect_split`] proves for that shape.
16572+/// Records the leaf's own `uv_mode` map entry and chroma above/left state,
16573+/// and returns the (u, v) grids for the caller's coarse slots.
16574+#[allow(clippy::too_many_arguments)]
16575+fn sub8_leaf_chroma444(
16576+ dec: &mut SymbolDecoder,
16577+ cdfs: &mut Cdfs,
16578+ neighbours: &mut Neighbours,
16579+ lmi: (usize, usize),
16580+ bw: usize,
16581+ bh: usize,
16582+ uv_mode: usize,
16583+ alpha: Option<(i32, i32)>,
16584+ skip: bool,
16585+ intrabc_dv: Option<(i32, i32)>,
16586+ y: &PlaneBuf<'static>,
16587+ u: &mut PlaneBuf<'static>,
16588+ v: &mut PlaneBuf<'static>,
16589+ scan4: &[u16],
16590+ base_q_idx: u8,
16591+ smooth_neighbor_uv: bool,
16592+ fctx: &crate::decode::FrameCtx,
16593+) -> Result<(Grid, Grid)> {
16594+ let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
16595+ let (w_mi, h_mi) = (bw / MI, bh / MI);
16596+ neighbours.record_uv_mode_mi(lmi.0, lmi.1, w_mi, h_mi, uv_predict_mode);
16597+ let (px, py) = (lmi.1 * MI, lmi.0 * MI);
16598+ let square = (bw, bh) == (4, 4);
16599+ // `Reach::of_rect` has no 4x4 table (`rect_reach_tables` starts at 4x8);
16600+ // the square unit takes the leaf's own `Reach::of`, as its luma does.
16601+ let reach = if square {
16602+ Reach::of(4, px, py, y.width, y.height, fctx)
16603+ } else {
16604+ Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx)
16605+ };
16606+ let grids = if skip {
16607+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
16608+ if square {
16609+ push_intra(1, px, py, 4, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
16610+ push_intra(2, px, py, 4, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
16611+ } else {
16612+ push_intra_rect(1, px, py, bw, bh, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..bw * bh], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx);
16613+ push_intra_rect(2, px, py, bw, bh, uv_predict_mode, 0, reach, &ZERO_RESIDUAL[..bw * bh], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx);
16614+ }
16615+ // The same arm-without-clear route the 4:2:0 tails count: a skipped
16616+ // leaf reads no coefficient, so an armed intrabc slot is dropped.
16617+ if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() {
16618+ hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
16619+ fctx.intrabc_chroma_tx.with(|c| c.set(None));
16620+ }
16621+ (Grid::Zero(bw * bh), Grid::Zero(bw * bh))
16622+ } else if let Some(dv) = intrabc_dv {
16623+ // Frame copy at the DV; the residual still reads the ordinary chroma
16624+ // tables with the inherited luma `tx_type` (see the 4:2:0 tails).
16625+ let mut ub = vec![0u16; bw * bh];
16626+ mc::predict_with_filter(
16627+ &u.data, u.width, u.true_width, u.true_height,
16628+ mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0),
16629+ bw, bh, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
16630+ );
16631+ let mut vb = vec![0u16; bw * bh];
16632+ mc::predict_with_filter(
16633+ &v.data, v.width, v.true_width, v.true_height,
16634+ mv_to_q4(px, dv.1, 0), mv_to_q4(py, dv.0, 0),
16635+ bw, bh, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
16636+ );
16637+ let around = neighbours.around_mi_rect(lmi, bw, bh);
16638+ let pair = if square {
16639+ set_palette_pred(ub, fctx);
16640+ let ug = read_plane(
16641+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], DC_PRED, DC_PRED,
16642+ 0, reach, u, px, py, 4, TX4, base_q_idx,
16643+ None, None, None, smooth_neighbor_uv, fctx,
16644+ )?;
16645+ set_palette_pred(vb, fctx);
16646+ let vg = read_plane(
16647+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], DC_PRED, DC_PRED,
16648+ 0, reach, v, px, py, 4, TX4, base_q_idx,
16649+ None, None, None, smooth_neighbor_uv, fctx,
16650+ )?;
16651+ (ug, vg)
16652+ } else {
16653+ let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };
16654+ let default_tx =
16655+ fctx.intrabc_chroma_tx.with(std::cell::Cell::get).unwrap_or(TxType::DctDct);
16656+ let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh));
16657+ for (plane_idx, buf) in [(1usize, ub), (2usize, vb)] {
16658+ let skip_ctx =
16659+ usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);
16660+ let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, DC_PRED);
16661+ let (levels, tx_type) = read_coeffs_rect(
16662+ dec, &mut coding, scan, bw, bh, skip_ctx,
16663+ dc_sign_ctx(around[plane_idx].2), default_tx,
16664+ )?;
16665+ let residual = dequant_and_inverse_typed_wh(
16666+ &levels, bw, bh, crate::decode::bit_depth(fctx), block_q_idx(fctx),
16667+ plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1,
16668+ tx_type,
16669+ );
16670+ set_palette_pred(buf, fctx);
16671+ push_intra_rect(
16672+ plane_idx, px, py, bw, bh, DC_PRED, 0, reach, &residual,
16673+ None, None, smooth_neighbor_uv, fctx,
16674+ );
16675+ if plane_idx == 1 { out.0 = levels; } else { out.1 = levels; }
16676+ }
16677+ out
16678+ };
16679+ fctx.intrabc_chroma_tx.with(|c| c.set(None));
16680+ pair
16681+ } else {
16682+ let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh));
16683+ let around = neighbours.around_mi_rect(lmi, bw, bh);
16684+ if square {
16685+ let ug = read_plane(
16686+ dec, cdfs, TxbSet::Chroma4, scan4, 1, around[1], uv_mode, uv_predict_mode,
16687+ 0, reach, u, px, py, 4, TX4, base_q_idx,
16688+ alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx,
16689+ )?;
16690+ let vg = read_plane(
16691+ dec, cdfs, TxbSet::Chroma4, scan4, 2, around[2], uv_mode, uv_predict_mode,
16692+ 0, reach, v, px, py, 4, TX4, base_q_idx,
16693+ alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx,
16694+ )?;
16695+ (ug, vg)
16696+ } else {
16697+ // `av1_get_max_uv_txsize(BLOCK_4X8/8X4)` at ss 0/0 is the rect
16698+ // transform itself; its `tx_type` is mode-derived with the
16699+ // <32 set (`decode_rect_split`'s own rule for this shape).
16700+ let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };
16701+ let default_tx = default_intra_tx_type(uv_predict_mode as u8);
16702+ let mut out = (Grid::Zero(bw * bh), Grid::Zero(bw * bh));
16703+ for plane_idx in 1..=2usize {
16704+ let skip_ctx =
16705+ usize::from(around[plane_idx].0) + usize::from(around[plane_idx].1);
16706+ let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode);
16707+ let (levels, tx_type) = read_coeffs_rect(
16708+ dec, &mut coding, scan, bw, bh, skip_ctx,
16709+ dc_sign_ctx(around[plane_idx].2), default_tx,
16710+ )?;
16711+ let residual = dequant_and_inverse_typed_wh(
16712+ &levels, bw, bh, crate::decode::bit_depth(fctx), block_q_idx(fctx),
16713+ plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1,
16714+ tx_type,
16715+ );
16716+ let cfl = alpha
16717+ .zip(ac)
16718+ .map(|((au, av), ac)| (if plane_idx == 1 { au } else { av }, ac));
16719+ push_intra_rect(
16720+ plane_idx, px, py, bw, bh, uv_predict_mode, 0, reach, &residual,
16721+ cfl, None, smooth_neighbor_uv, fctx,
16722+ );
16723+ if plane_idx == 1 { out.0 = levels; } else { out.1 = levels; }
16724+ }
16725+ out
16726+ }
16727+ };
16728+ // libaom `av1_set_entropy_contexts` stamps above/left PER TRANSFORM UNIT:
16729+ // the leaf's own chroma span, not the 8x8 group's.
16730+ let (u_grid, v_grid) = grids;
16731+ let u_state = neighbour_state(&u_grid);
16732+ let v_state = neighbour_state(&v_grid);
16733+ for cell in 0..h_mi {
16734+ if lmi.0 + cell < neighbours.mi_rows {
16735+ neighbours.left[lmi.0 + cell][1] = u_state;
16736+ neighbours.left[lmi.0 + cell][2] = v_state;
16737+ }
16738+ }
16739+ for cell in 0..w_mi {
16740+ if lmi.1 + cell < neighbours.mi_cols {
16741+ neighbours.above[lmi.1 + cell][1] = u_state;
16742+ neighbours.above[lmi.1 + cell][2] = v_state;
16743+ }
16744+ }
16745+ Ok((u_grid, v_grid))
16746+}
16747+
1653416748
1653516749 /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves
1653616750 /// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s
@@ -16576,7 +16790,7 @@ fn decode_leaf_split4(
1657616790 }
1657716791 // See `decode_leaf8`'s own `smooth_neighbor_uv`: the chroma edge-filter
1657816792 // type is the chroma neighbours' `uv_mode`, mi-exact where recorded.
16579- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);
16793+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
1658016794 let mut leaf_modes = [0usize; 4];
1658116795 let mut leaf_skips = [false; 4];
1658216796 let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None;
@@ -16584,6 +16798,14 @@ fn decode_leaf_split4(
1658416798 // leaf is an intrabc block -- its prediction/reconstruction below is a
1658516799 // frame copy at this DV, not an intra one.
1658616800 let mut last_intrabc: Option<(i32, i32)> = None;
16801+ // 4:4:4 (lane-av1-444): `is_chroma_reference` (av1_common_int.h:1459) is
16802+ // unconditional at subsampling 0/0, so EVERY 4x4 leaf reads its own
16803+ // `uv_mode` and codes its own full-resolution 4x4 chroma unit right
16804+ // after its luma -- there is no shared group unit at all.
16805+ let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
16806+ // The last leaf's own `uv_predict_mode`, for the coarse above/left slots
16807+ // the 4:2:0 tail fills from the group's single unit.
16808+ let mut last_uv444 = DC_PRED;
1658716809 for i in 0..4usize {
1658816810 let (dr, dc) = (i / 2, i % 2);
1658916811 let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc);
@@ -16601,7 +16823,7 @@ fn decode_leaf_split4(
1660116823 } else {
1660216824 leaf_modes[i - 1]
1660316825 };
16604- let has_chroma = i == 3;
16826+ let has_chroma = chroma_444 || i == 3;
1660516827 let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1);
1660616828 let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8(
1660716829 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,
@@ -16675,24 +16897,35 @@ fn decode_leaf_split4(
1667516897 neighbours.fill_lf_grid(lmi, 1, 4, 0, fctx);
1667616898 record_intrabc_mi(lmi.0, lmi.1, 1, Some(dv), neighbours, fctx);
1667716899 if has_chroma {
16678- last_uv = Some((DC_PRED, 0, None));
1667916900 // An intrabc block is an INTER block for `av1_get_tx_type`, so
16680- // the group's chroma inherits the LUMA's coded transform type
16901+ // the chroma inherits the LUMA's coded transform type
1668116902 // (`xd->tx_type_map` at the co-located luma position) -- the
1668216903 // luma `read_plane` above just set [`LUMA_TX_TYPE`]. Armed for
16683- // exactly this group's two chroma reads.
16904+ // exactly this leaf's two chroma reads.
1668416905 fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get))));
16685- // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE
16686- // leaf's own block -- libaom codes one chroma unit under the
16687- // last sub-block only (`is_chroma_reference`), so its prediction
16688- // is that leaf's `uv_mode` (CfL alpha and all) unless THAT leaf
16689- // is the intrabc one. Arming this from a non-chroma-reference
16690- // leaf's DV made `warped.obu`'s 8x8 group at mi(40,62) copy
16691- // frame bytes at mi(41,62)'s vector where aomdec predicts
16692- // `uv_mode=UV_CFL_PRED`: luma stayed byte-exact and only chroma
16693- // moved (class chroma-keyed-at-a-non-chroma-leaf). Mirrors
16694- // [`decode_leaf_rect8`]'s own placement.
16695- last_intrabc = Some(dv);
16906+ if chroma_444 {
16907+ // lane-av1-444: this leaf codes its OWN 4x4 chroma unit
16908+ // right here (frame copy at the DV); no group tail.
16909+ sub8_leaf_chroma444(
16910+ dec, cdfs, neighbours, lmi, 4, 4, DC_PRED, None, skip,
16911+ Some(dv), y, u, v, scan4, base_q_idx,
16912+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
16913+ )?;
16914+ last_uv444 = DC_PRED;
16915+ } else {
16916+ last_uv = Some((DC_PRED, 0, None));
16917+ // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE
16918+ // leaf's own block -- libaom codes one chroma unit under the
16919+ // last sub-block only (`is_chroma_reference`), so its prediction
16920+ // is that leaf's `uv_mode` (CfL alpha and all) unless THAT leaf
16921+ // is the intrabc one. Arming this from a non-chroma-reference
16922+ // leaf's DV made `warped.obu`'s 8x8 group at mi(40,62) copy
16923+ // frame bytes at mi(41,62)'s vector where aomdec predicts
16924+ // `uv_mode=UV_CFL_PRED`: luma stayed byte-exact and only chroma
16925+ // moved (class chroma-keyed-at-a-non-chroma-leaf). Mirrors
16926+ // [`decode_leaf_rect8`]'s own placement.
16927+ last_intrabc = Some(dv);
16928+ }
1669616929 }
1669716930 continue;
1669816931 }
@@ -16733,13 +16966,34 @@ fn decode_leaf_split4(
1673316966 neighbours.fill_skip_grid(lmi, 1, skip);
1673416967 neighbours.fill_lf_grid(lmi, 1, 4, 0, fctx);
1673516968 if has_chroma {
16736- last_uv = chroma;
16969+ if chroma_444 {
16970+ // lane-av1-444: the leaf's own 4x4 chroma unit, coded right
16971+ // after its luma (no shared group unit at ss 0/0).
16972+ let (uv_mode, _, alpha) =
16973+ chroma.expect("4:4:4 reads uv_mode on every leaf");
16974+ sub8_leaf_chroma444(
16975+ dec, cdfs, neighbours, lmi, 4, 4, uv_mode, alpha, skip,
16976+ None, y, u, v, scan4, base_q_idx,
16977+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
16978+ )?;
16979+ last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
16980+ } else {
16981+ last_uv = chroma;
16982+ }
1673716983 }
1673816984 }
1673916985 // lane-av1mono: as [`decode_leaf_rect8`] -- a monochrome frame has no
1674016986 // chroma to reconstruct and no uv_mode was read.
1674116987 let (u_grid, v_grid): (Grid, Grid) = if mono(fctx) {
1674216988 (Grid::Zero(16), Grid::Zero(16))
16989+ } else if chroma_444 {
16990+ // lane-av1-444: every leaf coded and reconstructed its own chroma in
16991+ // the loop above ([`sub8_leaf_chroma444`] stamped the mi-exact maps
16992+ // and per-leaf entropy state); only the coarse slots remain, filled
16993+ // from the bottom-right leaf like the 4:2:0 tail's single unit.
16994+ neighbours.above_uv_mode[c] = last_uv444;
16995+ neighbours.left_uv_mode[r] = last_uv444;
16996+ (Grid::Zero(16), Grid::Zero(16))
1674316997 } else {
1674416998 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
1674516999 let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
@@ -16849,19 +17103,23 @@ fn decode_leaf_split4(
1684917103 neighbours.left_side_mi[leaf_mi.0 + cell] = 4;
1685017104 neighbours.above_side_mi[leaf_mi.1 + cell] = 4;
1685117105 }
16852- let round_up_even = |n: usize| n.div_ceil(2) * 2;
16853- let bound_h = round_up_even(neighbours.mi_rows);
16854- let bound_w = round_up_even(neighbours.mi_cols);
16855- let u_state = neighbour_state(&u_grid);
16856- let v_state = neighbour_state(&v_grid);
16857- for cell in 0..side_mi {
16858- if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) {
16859- neighbours.left[leaf_mi.0 + cell][1] = u_state;
16860- neighbours.left[leaf_mi.0 + cell][2] = v_state;
16861- }
16862- if cell < side_mi.min(bound_w.saturating_sub(leaf_mi.1)) {
16863- neighbours.above[leaf_mi.1 + cell][1] = u_state;
16864- neighbours.above[leaf_mi.1 + cell][2] = v_state;
17106+ // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each
17107+ // leaf's own span as it decoded; these placeholder grids carry no state.
17108+ if !chroma_444 {
17109+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
17110+ let bound_h = round_up_even(neighbours.mi_rows);
17111+ let bound_w = round_up_even(neighbours.mi_cols);
17112+ let u_state = neighbour_state(&u_grid);
17113+ let v_state = neighbour_state(&v_grid);
17114+ for cell in 0..side_mi {
17115+ if cell < side_mi.min(bound_h.saturating_sub(leaf_mi.0)) {
17116+ neighbours.left[leaf_mi.0 + cell][1] = u_state;
17117+ neighbours.left[leaf_mi.0 + cell][2] = v_state;
17118+ }
17119+ if cell < side_mi.min(bound_w.saturating_sub(leaf_mi.1)) {
17120+ neighbours.above[leaf_mi.1 + cell][1] = u_state;
17121+ neighbours.above[leaf_mi.1 + cell][2] = v_state;
17122+ }
1686517123 }
1686617124 }
1686717125 // lane-dkey: a sub-8x8 leaf can never use palette (`av1_allow_palette`
@@ -16931,7 +17189,7 @@ fn decode_leaf_rect8(
1693117189 // lane-modectx r1: availability-correct fallback pair (see
1693217190 // `modes_above_left`), not the raw coarse bands.
1693317191 let (above_mode, left_mode) = neighbours.modes_above_left(r, c);
16934- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);
17192+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
1693517193 let (bw, bh) = if vert { (4, 8) } else { (8, 4) };
1693617194 let (w_mi, h_mi) = (bw / MI, bh / MI);
1693717195 let scan: &[u16] = if vert { &SCAN_4X8 } else { &SCAN_8X4 };
@@ -16940,6 +17198,11 @@ fn decode_leaf_rect8(
1694017198 let mut last_uv: Option<(usize, i32, Option<(i32, i32)>)> = None;
1694117199 // lane-av1txr: as [`decode_leaf_split4`]'s own `last_intrabc`.
1694217200 let mut last_intrabc: Option<(i32, i32)> = None;
17201+ // 4:4:4 (lane-av1-444): as [`decode_leaf_split4`] -- at subsampling 0/0
17202+ // EVERY 4x8/8x4 leaf reads its own `uv_mode` and codes its own
17203+ // full-resolution rect chroma unit right after its luma.
17204+ let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
17205+ let mut last_uv444 = DC_PRED;
1694317206 for i in 0..2usize {
1694417207 let lmi = if vert {
1694517208 (leaf_mi.0, leaf_mi.1 + i)
@@ -16958,7 +17221,7 @@ fn decode_leaf_rect8(
1695817221 } else {
1695917222 neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode)
1696017223 };
16961- let has_chroma = i == 1;
17224+ let has_chroma = chroma_444 || i == 1;
1696217225 let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1);
1696317226 let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8(
1696417227 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,
@@ -17132,11 +17395,22 @@ fn decode_leaf_rect8(
1713217395 // 4x8/8x4 leaf needs its true `w_mi`x`h_mi` (lane-av1txr).
1713317396 record_intrabc_mi_rect(lmi.0, lmi.1, w_mi, h_mi, Some(dv), neighbours, fctx);
1713417397 if has_chroma {
17135- last_uv = Some((DC_PRED, 0, None));
17136- last_intrabc = Some(dv);
1713717398 // See [`decode_leaf_split4`]: an intrabc block's chroma
1713817399 // inherits the luma transform type.
1713917400 fctx.intrabc_chroma_tx.with(|c| c.set(Some(chroma_tx)));
17401+ if chroma_444 {
17402+ // lane-av1-444: this leaf codes its OWN rect chroma unit
17403+ // right here (frame copy at the DV); no group tail.
17404+ sub8_leaf_chroma444(
17405+ dec, cdfs, neighbours, lmi, bw, bh, DC_PRED, None, skip,
17406+ Some(dv), y, u, v, scan4, base_q_idx,
17407+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
17408+ )?;
17409+ last_uv444 = DC_PRED;
17410+ } else {
17411+ last_uv = Some((DC_PRED, 0, None));
17412+ last_intrabc = Some(dv);
17413+ }
1714017414 }
1714117415 continue;
1714217416 }
@@ -17273,7 +17547,20 @@ fn decode_leaf_rect8(
1727317547 neighbours.fill_skip_grid_rect(lmi, w_mi, h_mi, skip);
1727417548 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, 4, 4, 0, fctx);
1727517549 if has_chroma {
17276- last_uv = chroma;
17550+ if chroma_444 {
17551+ // lane-av1-444: the leaf's own rect chroma unit after its
17552+ // split luma (no shared group unit at ss 0/0).
17553+ let (uv_mode, _, alpha) =
17554+ chroma.expect("4:4:4 reads uv_mode on every leaf");
17555+ sub8_leaf_chroma444(
17556+ dec, cdfs, neighbours, lmi, bw, bh, uv_mode, alpha, skip,
17557+ None, y, u, v, scan4, base_q_idx,
17558+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
17559+ )?;
17560+ last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
17561+ } else {
17562+ last_uv = chroma;
17563+ }
1727717564 }
1727817565 continue;
1727917566 }
@@ -17348,7 +17635,20 @@ fn decode_leaf_rect8(
1734817635 let (tx_w, tx_h) = if split { (4, 4) } else { (bw as u8, bh as u8) };
1734917636 neighbours.fill_lf_grid_rect(lmi, w_mi, h_mi, tx_w, tx_h, 0, fctx);
1735017637 if has_chroma {
17351- last_uv = chroma;
17638+ if chroma_444 {
17639+ // lane-av1-444: the leaf's own rect chroma unit after its
17640+ // luma (no shared group unit at ss 0/0).
17641+ let (uv_mode, _, alpha) =
17642+ chroma.expect("4:4:4 reads uv_mode on every leaf");
17643+ sub8_leaf_chroma444(
17644+ dec, cdfs, neighbours, lmi, bw, bh, uv_mode, alpha, skip,
17645+ None, y, u, v, scan4, base_q_idx,
17646+ neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx,
17647+ )?;
17648+ last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
17649+ } else {
17650+ last_uv = chroma;
17651+ }
1735217652 }
1735317653 }
1735417654 // lane-av1mono: a monochrome frame codes no chroma at all -- no
@@ -17356,6 +17656,12 @@ fn decode_leaf_rect8(
1735617656 // so there is no chroma to reconstruct and no chroma coefficient to read.
1735717657 let (u_grid, v_grid): (Grid, Grid) = if mono(fctx) {
1735817658 (Grid::Zero(16), Grid::Zero(16))
17659+ } else if chroma_444 {
17660+ // lane-av1-444: every leaf coded and reconstructed its own chroma in
17661+ // the loop above; only the coarse slots remain (last leaf's mode).
17662+ neighbours.above_uv_mode[c] = last_uv444;
17663+ neighbours.left_uv_mode[r] = last_uv444;
17664+ (Grid::Zero(16), Grid::Zero(16))
1735917665 } else {
1736017666 let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
1736117667 let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
@@ -17453,19 +17759,23 @@ fn decode_leaf_rect8(
1745317759 neighbours.above_side_mi[leaf_mi.1 + cell] = bw as u8;
1745417760 neighbours.left_side_mi[leaf_mi.0 + cell] = bh as u8;
1745517761 }
17456- let round_up_even = |n: usize| n.div_ceil(2) * 2;
17457- let bound_h = round_up_even(neighbours.mi_rows);
17458- let bound_w = round_up_even(neighbours.mi_cols);
17459- let u_state = neighbour_state(&u_grid);
17460- let v_state = neighbour_state(&v_grid);
17461- for cell in 0..2usize {
17462- if cell < 2usize.min(bound_h.saturating_sub(leaf_mi.0)) {
17463- neighbours.left[leaf_mi.0 + cell][1] = u_state;
17464- neighbours.left[leaf_mi.0 + cell][2] = v_state;
17465- }
17466- if cell < 2usize.min(bound_w.saturating_sub(leaf_mi.1)) {
17467- neighbours.above[leaf_mi.1 + cell][1] = u_state;
17468- neighbours.above[leaf_mi.1 + cell][2] = v_state;
17762+ // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each
17763+ // leaf's own span as it decoded; these placeholder grids carry no state.
17764+ if !chroma_444 {
17765+ let round_up_even = |n: usize| n.div_ceil(2) * 2;
17766+ let bound_h = round_up_even(neighbours.mi_rows);
17767+ let bound_w = round_up_even(neighbours.mi_cols);
17768+ let u_state = neighbour_state(&u_grid);
17769+ let v_state = neighbour_state(&v_grid);
17770+ for cell in 0..2usize {
17771+ if cell < 2usize.min(bound_h.saturating_sub(leaf_mi.0)) {
17772+ neighbours.left[leaf_mi.0 + cell][1] = u_state;
17773+ neighbours.left[leaf_mi.0 + cell][2] = v_state;
17774+ }
17775+ if cell < 2usize.min(bound_w.saturating_sub(leaf_mi.1)) {
17776+ neighbours.above[leaf_mi.1 + cell][1] = u_state;
17777+ neighbours.above[leaf_mi.1 + cell][2] = v_state;
17778+ }
1746917779 }
1747017780 }
1747117781 // lane-dkey (same clear as `decode_leaf_split4`): a sub-8x8 leaf can never use palette (`av1_allow_palette`
@@ -30774,7 +31084,7 @@ fn decode_inter_block(
3077431084 // as [`read_intra_mode`]/[`read_intra_mode_rect`] -- the CHROMA
3077531085 // neighbour's own `uv_mode`, not the luma one.
3077631086 let smooth_neighbor_uv =
30777- neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);
31087+ neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c, fctx);
3077831088 // `read_palette_mode_info` (decodemv.c:567, called from
3077931089 // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same
3078031090 // gating and same corner-cut as `read_intra_mode`'s own copy above
@@ -30856,13 +31166,16 @@ fn decode_inter_block(
3085631166 PaletteY { size: n, colors, map }
3085731167 });
3085831168 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
30859- // `av1_get_plane_block_size(bsize, 1, 1)` floors at the 4-px
30860- // transform, as the rect reader's own copy.
30861- let (cw, ch) = ((write_w / 2).max(4), (write_h / 2).max(4));
31169+ // `av1_get_plane_block_size(bsize, 1, 1)` at the sequence's own
31170+ // subsampling, floored at the 4-px transform -- the rect reader's
31171+ // own copy; a hardcoded `/ 2` sized a 4:4:4 chroma map at 4:2:0
31172+ // and the full-size reconstruct panicked on it (lane-av1-444).
31173+ let (cw, ch) = ((write_w >> ss_x(fctx)).max(4), (write_h >> ss_y(fctx)).max(4));
3086231174 let on = palette_onscreen_uv(
3086331175 (write_w, write_h),
3086431176 palette_onscreen(rmi, cmi, write_w, write_h, fctx),
3086531177 (cw, ch),
31178+ (ss_x(fctx), ss_y(fctx)),
3086631179 );
3086731180 let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, on, true);
3086831181 hit!(PALETTE_UV_HITS);
@@ -31622,6 +31935,12 @@ fn decode_inter_sub8_split4(
3162231935 // Set when the chroma-reference (last) sub-block is INTRA: it coded the
3162331936 // group's one chroma unit itself.
3162431937 let mut intra_chroma = false;
31938+ // 4:4:4 (lane-av1-444): `is_chroma_reference` is unconditional at
31939+ // subsampling 0/0, so EVERY 4x4 sub-block codes its own 4x4 chroma unit
31940+ // right after its own luma (aomdec EC_COEFF on `av1-profile1-444.ivf`
31941+ // frame 1: plane 0,1,2 per leaf in leaf order) -- there is no shared
31942+ // group unit and no 2x2-piece group prediction.
31943+ let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
3162531944 for i in 0..4usize {
3162631945 let (dr, dc) = (i / 2, i % 2);
3162731946 let lmi = (gr + dr, gc + dc);
@@ -31679,7 +31998,7 @@ fn decode_inter_sub8_split4(
3167931998 group_mi,
3168031999 lmi,
3168132000 (B4, B4),
31682- i == 3,
32001+ chroma_444 || i == 3,
3168332002 skip,
3168432003 scan4,
3168532004 y,
@@ -32522,7 +32841,7 @@ fn decode_intra_sub8_leaf(
3252232841 let (gpx, gpy) = (gc * MI, gr * MI);
3252332842 let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx));
3252432843 let group_reach = Reach::of(8, gpx, gpy, y.width, y.height, fctx);
32525- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(gr, gc, r, c);
32844+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(gr, gc, r, c, fctx);
3252632845 let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode };
3252732846 let angle_delta_uv = 0;
3252832847 neighbours.above_uv_mode[c] = uv_predict_mode;
@@ -33407,7 +33726,18 @@ fn decode_inter_block8(
3340733726 // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
3340833727 let split8;
3340933728 const SIDE: usize = 8;
33410- const CHROMA_SIDE: usize = 4;
33729+ // lane-av1-444: this 8x8 leaf's chroma plane block is `8 >> ss` a side --
33730+ // 4 at 4:2:0 (one TX_4X4 unit) and the full 8 at 4:4:4, where libaom
33731+ // codes ONE TX_8X8 unit (`av1_get_max_uv_txsize(BLOCK_8X8)` at ss 0/0,
33732+ // measured against aomdec's EC_COEFF on `av1-profile1-444.ivf` frame 1:
33733+ // plane=1 tx=TX_8X8 per 8x8 block, not a 4:2:0 4x4).
33734+ let chroma_side: usize = SIDE >> ss_x(fctx);
33735+ let (chroma_set, chroma_scan): (TxbSet, &[u16]) = if chroma_side == 8 {
33736+ (TxbSet::Chroma8, scan8)
33737+ } else {
33738+ (TxbSet::Chroma4, scan4)
33739+ };
33740+ let chroma_tx = if chroma_side == 8 { TX8 } else { TX4 };
3341133741
3341233742 let (r, c) = outer_at;
3341333743 // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's --
@@ -33916,7 +34246,7 @@ fn decode_inter_block8(
3391634246 mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y, fctx);
3391734247 }
3391834248
33919- let mut inter0_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
34249+ let mut inter0_u = vec![0i32; chroma_side * chroma_side];
3392034250 mc::predict_compound_intermediate(
3392134251 &pu0.data,
3392234252 pu0.width,
@@ -33925,13 +34255,13 @@ fn decode_inter_block8(
3392534255 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
3392634256 mv_to_q4(cpy, mv0.0, ss_x(fctx)),
3392734257 scale0,
33928- CHROMA_SIDE,
33929- CHROMA_SIDE,
34258+ chroma_side,
34259+ chroma_side,
3393034260 h_filter,
3393134261 v_filter,
3393234262 &mut inter0_u,
3393334263 );
33934- let mut inter1_u = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
34264+ let mut inter1_u = vec![0i32; chroma_side * chroma_side];
3393534265 mc::predict_compound_intermediate(
3393634266 &pu1.data,
3393734267 pu1.width,
@@ -33940,21 +34270,21 @@ fn decode_inter_block8(
3394034270 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
3394134271 mv_to_q4(cpy, mv1.0, ss_x(fctx)),
3394234272 scale1,
33943- CHROMA_SIDE,
33944- CHROMA_SIDE,
34273+ chroma_side,
34274+ chroma_side,
3394534275 h_filter,
3394634276 v_filter,
3394734277 &mut inter1_u,
3394834278 );
33949- let mut pred_u = refill(std::mem::take(&mut out[1]), CHROMA_SIDE * CHROMA_SIDE);
34279+ let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);
3395034280 if let Some(mask_y) = mask_y {
3395134281 mc::blend_masked_compound(
3395234282 &inter0_u,
3395334283 &inter1_u,
3395434284 mask_y,
3395534285 SIDE,
33956- CHROMA_SIDE,
33957- CHROMA_SIDE,
34286+ chroma_side,
34287+ chroma_side,
3395834288 ss_x(fctx) == 1 && ss_y(fctx) == 1,
3395934289 &mut pred_u, fctx,
3396034290 );
@@ -33962,7 +34292,7 @@ fn decode_inter_block8(
3396234292 mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u, fctx);
3396334293 }
3396434294
33965- let mut inter0_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
34295+ let mut inter0_v = vec![0i32; chroma_side * chroma_side];
3396634296 mc::predict_compound_intermediate(
3396734297 &pv0.data,
3396834298 pv0.width,
@@ -33971,13 +34301,13 @@ fn decode_inter_block8(
3397134301 mv_to_q4(cpx, mv0.1, ss_x(fctx)),
3397234302 mv_to_q4(cpy, mv0.0, ss_x(fctx)),
3397334303 scale0,
33974- CHROMA_SIDE,
33975- CHROMA_SIDE,
34304+ chroma_side,
34305+ chroma_side,
3397634306 h_filter,
3397734307 v_filter,
3397834308 &mut inter0_v,
3397934309 );
33980- let mut inter1_v = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
34310+ let mut inter1_v = vec![0i32; chroma_side * chroma_side];
3398134311 mc::predict_compound_intermediate(
3398234312 &pv1.data,
3398334313 pv1.width,
@@ -33986,21 +34316,21 @@ fn decode_inter_block8(
3398634316 mv_to_q4(cpx, mv1.1, ss_x(fctx)),
3398734317 mv_to_q4(cpy, mv1.0, ss_x(fctx)),
3398834318 scale1,
33989- CHROMA_SIDE,
33990- CHROMA_SIDE,
34319+ chroma_side,
34320+ chroma_side,
3399134321 h_filter,
3399234322 v_filter,
3399334323 &mut inter1_v,
3399434324 );
33995- let mut pred_v = refill(std::mem::take(&mut out[2]), CHROMA_SIDE * CHROMA_SIDE);
34325+ let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);
3399634326 if let Some(mask_y) = mask_y {
3399734327 mc::blend_masked_compound(
3399834328 &inter0_v,
3399934329 &inter1_v,
3400034330 mask_y,
3400134331 SIDE,
34002- CHROMA_SIDE,
34003- CHROMA_SIDE,
34332+ chroma_side,
34333+ chroma_side,
3400434334 ss_x(fctx) == 1 && ss_y(fctx) == 1,
3400534335 &mut pred_v, fctx,
3400634336 );
@@ -34016,8 +34346,8 @@ fn decode_inter_block8(
3401634346 push_pred(fctx, build);
3401734347 (
3401834348 Pred::Cur { plane: 0, stride: SIDE, off: 0 },
34019- Pred::Cur { plane: 1, stride: CHROMA_SIDE, off: 0 },
34020- Pred::Cur { plane: 2, stride: CHROMA_SIDE, off: 0 },
34349+ Pred::Cur { plane: 1, stride: chroma_side, off: 0 },
34350+ Pred::Cur { plane: 2, stride: chroma_side, off: 0 },
3402134351 )
3402234352 } else {
3402334353 let mut built: [Vec<u16>; 3] = Default::default();
@@ -34026,8 +34356,8 @@ fn decode_inter_block8(
3402634356 (pred_y, pred_u, pred_v) = (by, bu, bv);
3402734357 (
3402834358 Pred::Inline(&pred_y, SIDE),
34029- Pred::Inline(&pred_u, CHROMA_SIDE),
34030- Pred::Inline(&pred_v, CHROMA_SIDE),
34359+ Pred::Inline(&pred_u, chroma_side),
34360+ Pred::Inline(&pred_v, chroma_side),
3403134361 )
3403234362 };
3403334363 split8 = read_block_tx_size(
@@ -34047,20 +34377,20 @@ fn decode_inter_block8(
3404734377 push_mc(1,
3404834378 cpx,
3404934379 cpy,
34050- CHROMA_SIDE,
34380+ chroma_side,
3405134381 su,
34052- &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
34382+ &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
3405334383 );
3405434384 push_mc(2,
3405534385 cpx,
3405634386 cpy,
34057- CHROMA_SIDE,
34387+ chroma_side,
3405834388 sv,
34059- &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
34389+ &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
3406034390 );
3406134391 luma_grid = Grid::Zero(SIDE * SIDE);
34062- u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
34063- v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
34392+ u_grid = Grid::Zero(chroma_side * chroma_side);
34393+ v_grid = Grid::Zero(chroma_side * chroma_side);
3406434394 } else {
3406534395 let around = neighbours.around_mi(leaf_mi, 8);
3406634396 let (grid8, luma_tx_type) = read_inter_luma8(
@@ -34083,15 +34413,15 @@ fn decode_inter_block8(
3408334413 u_grid = read_inter_plane(
3408434414 dec,
3408534415 cdfs,
34086- TxbSet::Chroma4,
34087- scan4,
34416+ chroma_set,
34417+ chroma_scan,
3408834418 1,
3408934419 around[1],
3409034420 mode_for_tx,
3409134421 u,
3409234422 cpx,
3409334423 cpy,
34094- CHROMA_SIDE,
34424+ chroma_side,
3409534425 base_q_idx,
3409634426 su,
3409734427 Some(luma_tx_type),
@@ -34101,15 +34431,15 @@ fn decode_inter_block8(
3410134431 v_grid = read_inter_plane(
3410234432 dec,
3410334433 cdfs,
34104- TxbSet::Chroma4,
34105- scan4,
34434+ chroma_set,
34435+ chroma_scan,
3410634436 2,
3410734437 around[2],
3410834438 mode_for_tx,
3410934439 v,
3411034440 cpx,
3411134441 cpy,
34112- CHROMA_SIDE,
34442+ chroma_side,
3411334443 base_q_idx,
3411434444 sv,
3411534445 Some(luma_tx_type),
@@ -34596,7 +34926,7 @@ fn decode_inter_block8(
3459634926 SIDE,
3459734927 SIDE,
3459834928 SIDE,
34599- CHROMA_SIDE,
34929+ chroma_side,
3460034930 px,
3460134931 py,
3460234932 cpx,
@@ -34620,15 +34950,15 @@ fn decode_inter_block8(
3462034950 return;
3462134951 };
3462234952 let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE);
34623- let mut pred_u = refill(std::mem::take(&mut out[1]), CHROMA_SIDE * CHROMA_SIDE);
34624- let mut pred_v = refill(std::mem::take(&mut out[2]), CHROMA_SIDE * CHROMA_SIDE);
34953+ let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side);
34954+ let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side);
3462534955 // Merge of lane-gmaffine (this leaf's own switchable filters) with
3462634956 // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either
3462734957 // way, only the sample walk differs.
3462834958 for (plane, x, y, dim, dst) in [
3462934959 (sref_y, px, py, SIDE, &mut pred_y),
34630- (sref_u, cpx, cpy, CHROMA_SIDE, &mut pred_u),
34631- (sref_v, cpx, cpy, CHROMA_SIDE, &mut pred_v),
34960+ (sref_u, cpx, cpy, chroma_side, &mut pred_u),
34961+ (sref_v, cpx, cpy, chroma_side, &mut pred_v),
3463234962 ] {
3463334963 let luma = std::ptr::eq(plane, sref_y);
3463434964 if luma_scale == mc::REF_NO_SCALE {
@@ -34680,16 +35010,16 @@ fn decode_inter_block8(
3468035010 // bail-out: an 8x8 leaf's chroma plane is 4x4 in 420, so it is
3468135011 // predicted translationally even when the luma warps.
3468235012 #[allow(clippy::absurd_extreme_comparisons)]
34683- if CHROMA_SIDE >= 8 {
35013+ if chroma_side >= 8 {
3468435014 crate::warp::warp_affine(
3468535015 params, &sref_u.data, sref_u.true_width as i32, sref_u.true_height as i32,
34686- sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, CHROMA_SIDE as i32,
34687- CHROMA_SIDE as i32, CHROMA_SIDE as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
35016+ sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32,
35017+ chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
3468835018 );
3468935019 crate::warp::warp_affine(
3469035020 params, &sref_v.data, sref_v.true_width as i32, sref_v.true_height as i32,
34691- sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, CHROMA_SIDE as i32,
34692- CHROMA_SIDE as i32, CHROMA_SIDE as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
35021+ sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_side as i32,
35022+ chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx,
3469335023 );
3469435024 }
3469535025 }
@@ -34703,10 +35033,10 @@ fn decode_inter_block8(
3470335033 if let Some(ii) = interintra_mode {
3470435034 interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y, fctx);
3470535035 interintra_blend(
34706- u, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_u, fctx,
35036+ u, cpx, cpy, chroma_side, chroma_side, chroma_side, ii, wedge_mask, &mut pred_u, fctx,
3470735037 );
3470835038 interintra_blend(
34709- v, cpx, cpy, CHROMA_SIDE, CHROMA_SIDE, CHROMA_SIDE, ii, wedge_mask, &mut pred_v, fctx,
35039+ v, cpx, cpy, chroma_side, chroma_side, chroma_side, ii, wedge_mask, &mut pred_v, fctx,
3471035040 );
3471135041 }
3471235042
@@ -34718,8 +35048,8 @@ fn decode_inter_block8(
3471835048 push_pred(fctx, build);
3471935049 (
3472035050 Pred::Cur { plane: 0, stride: SIDE, off: 0 },
34721- Pred::Cur { plane: 1, stride: CHROMA_SIDE, off: 0 },
34722- Pred::Cur { plane: 2, stride: CHROMA_SIDE, off: 0 },
35051+ Pred::Cur { plane: 1, stride: chroma_side, off: 0 },
35052+ Pred::Cur { plane: 2, stride: chroma_side, off: 0 },
3472335053 )
3472435054 } else {
3472535055 // The interintra predictor reads this block's own above/left
@@ -34734,8 +35064,8 @@ fn decode_inter_block8(
3473435064 (pred_y, pred_u, pred_v) = (by, bu, bv);
3473535065 (
3473635066 Pred::Inline(&pred_y, SIDE),
34737- Pred::Inline(&pred_u, CHROMA_SIDE),
34738- Pred::Inline(&pred_v, CHROMA_SIDE),
35067+ Pred::Inline(&pred_u, chroma_side),
35068+ Pred::Inline(&pred_v, chroma_side),
3473935069 )
3474035070 };
3474135071 split8 = read_block_tx_size(
@@ -34755,20 +35085,20 @@ fn decode_inter_block8(
3475535085 push_mc(1,
3475635086 cpx,
3475735087 cpy,
34758- CHROMA_SIDE,
35088+ chroma_side,
3475935089 su,
34760- &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
35090+ &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
3476135091 );
3476235092 push_mc(2,
3476335093 cpx,
3476435094 cpy,
34765- CHROMA_SIDE,
35095+ chroma_side,
3476635096 sv,
34767- &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE], fctx,
35097+ &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx,
3476835098 );
3476935099 luma_grid = Grid::Zero(SIDE * SIDE);
34770- u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
34771- v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
35100+ u_grid = Grid::Zero(chroma_side * chroma_side);
35101+ v_grid = Grid::Zero(chroma_side * chroma_side);
3477235102 } else {
3477335103 let around = neighbours.around_mi(leaf_mi, 8);
3477435104 let (grid8, luma_tx_type) = read_inter_luma8(
@@ -34791,15 +35121,15 @@ fn decode_inter_block8(
3479135121 u_grid = read_inter_plane(
3479235122 dec,
3479335123 cdfs,
34794- TxbSet::Chroma4,
34795- scan4,
35124+ chroma_set,
35125+ chroma_scan,
3479635126 1,
3479735127 around[1],
3479835128 mode_for_tx,
3479935129 u,
3480035130 cpx,
3480135131 cpy,
34802- CHROMA_SIDE,
35132+ chroma_side,
3480335133 base_q_idx,
3480435134 su,
3480535135 Some(luma_tx_type),
@@ -34809,15 +35139,15 @@ fn decode_inter_block8(
3480935139 v_grid = read_inter_plane(
3481035140 dec,
3481135141 cdfs,
34812- TxbSet::Chroma4,
34813- scan4,
35142+ chroma_set,
35143+ chroma_scan,
3481435144 2,
3481535145 around[2],
3481635146 mode_for_tx,
3481735147 v,
3481835148 cpx,
3481935149 cpy,
34820- CHROMA_SIDE,
35150+ chroma_side,
3482135151 base_q_idx,
3482235152 sv,
3482335153 Some(luma_tx_type),
@@ -34918,7 +35248,7 @@ fn decode_inter_block8(
3491835248 // The CHROMA neighbour's own `uv_mode` decides the chroma edge filter
3491935249 // strength (`get_intra_edge_filter_type`, reconintra.c:974), never the
3492035250 // luma one -- same read [`decode_leaf8`] does.
34921- let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c);
35251+ let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(leaf_mi.0, leaf_mi.1, r, c, fctx);
3492235252 // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/
3492335253 // `uv_mode` are both effectively `DC_PRED`-gated already on this
3492435254 // leaf (a nonzero `mode` still passes, but `uv_mode` is forced
@@ -35033,14 +35363,17 @@ fn decode_inter_block8(
3503335363 PaletteY { size: n, colors, map }
3503435364 });
3503535365 let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
35036- // `av1_get_plane_block_size(BLOCK_8X8, 1, 1)` = BLOCK_4X4.
35366+ // `av1_get_plane_block_size(BLOCK_8X8, 1, 1)` at the sequence's
35367+ // own subsampling: BLOCK_4X4 at 4:2:0, BLOCK_8X8 at 4:4:4
35368+ // (`chroma_side`, lane-av1-444).
3503735369 let on = palette_onscreen_uv(
3503835370 (SIDE, SIDE),
3503935371 palette_onscreen(rmi, cmi, SIDE, SIDE, fctx),
35040- (CHROMA_SIDE, CHROMA_SIDE),
35372+ (chroma_side, chroma_side),
35373+ (ss_x(fctx), ss_y(fctx)),
3504135374 );
3504235375 let map =
35043- decode_color_index_map_wh(dec, cdfs, n, CHROMA_SIDE, CHROMA_SIDE, on, true);
35376+ decode_color_index_map_wh(dec, cdfs, n, chroma_side, chroma_side, on, true);
3504435377 hit!(PALETTE_UV_HITS);
3504535378 hit!(INTRA_IN_INTER_PALETTE_UV_HITS);
3504635379 hit_do! {
@@ -35214,11 +35547,11 @@ fn decode_inter_block8(
3521435547 push_intra(1,
3521535548 cpx,
3521635549 cpy,
35217- CHROMA_SIDE,
35550+ chroma_side,
3521835551 uv_predict_mode,
3521935552 angle_delta_uv,
3522035553 reach,
35221- &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE],
35554+ &ZERO_RESIDUAL[..chroma_side * chroma_side],
3522235555 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
3522335556 None,
3522435557 smooth_neighbor_uv, fctx,
@@ -35229,18 +35562,18 @@ fn decode_inter_block8(
3522935562 push_intra(2,
3523035563 cpx,
3523135564 cpy,
35232- CHROMA_SIDE,
35565+ chroma_side,
3523335566 uv_predict_mode,
3523435567 angle_delta_uv,
3523535568 reach,
35236- &ZERO_RESIDUAL[..CHROMA_SIDE * CHROMA_SIDE],
35569+ &ZERO_RESIDUAL[..chroma_side * chroma_side],
3523735570 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
3523835571 None,
3523935572 smooth_neighbor_uv, fctx,
3524035573 );
3524135574 luma_grid = Grid::Zero(SIDE * SIDE);
35242- u_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
35243- v_grid = Grid::Zero(CHROMA_SIDE * CHROMA_SIDE);
35575+ u_grid = Grid::Zero(chroma_side * chroma_side);
35576+ v_grid = Grid::Zero(chroma_side * chroma_side);
3524435577 } else {
3524535578 let around = neighbours.around_mi(leaf_mi, 8);
3524635579 luma_grid = if split8 {
@@ -35290,8 +35623,8 @@ fn decode_inter_block8(
3529035623 u_grid = read_plane(
3529135624 dec,
3529235625 cdfs,
35293- TxbSet::Chroma4,
35294- scan4,
35626+ chroma_set,
35627+ chroma_scan,
3529535628 1,
3529635629 around[1],
3529735630 mode,
@@ -35301,8 +35634,8 @@ fn decode_inter_block8(
3530135634 u,
3530235635 cpx,
3530335636 cpy,
35304- CHROMA_SIDE,
35305- TX4,
35637+ chroma_side,
35638+ chroma_tx,
3530635639 base_q_idx,
3530735640 alpha.zip(ac).map(|((au, _), ac)| (au, ac)),
3530835641 None,
@@ -35315,8 +35648,8 @@ fn decode_inter_block8(
3531535648 v_grid = read_plane(
3531635649 dec,
3531735650 cdfs,
35318- TxbSet::Chroma4,
35319- scan4,
35651+ chroma_set,
35652+ chroma_scan,
3532035653 2,
3532135654 around[2],
3532235655 mode,
@@ -35326,8 +35659,8 @@ fn decode_inter_block8(
3532635659 v,
3532735660 cpx,
3532835661 cpy,
35329- CHROMA_SIDE,
35330- TX4,
35662+ chroma_side,
35663+ chroma_tx,
3533135664 base_q_idx,
3533235665 alpha.zip(ac).map(|((_, av), ac)| (av, ac)),
3533335666 None,
crates/ec-av1/src/encode.rsmodified+2 -0
@@ -6500,6 +6500,8 @@ fn search_chroma(
65006500 side.min(luma.true_height.saturating_sub(y)),
65016501 ),
65026502 (at.side, at.side),
6503+ // The encoder writes 4:2:0 only (`palette_uv_side` above).
6504+ (1, 1),
65036505 );
65046506 for mut pal in palette_candidates(&u_source) {
65056507 let n = usize::from(pal.size);
crates/ec-av1/src/tile.rsmodified+674 -351
@@ -12,17 +12,17 @@
1212 use std::cell::RefCell;
1313 #[cfg(test)]
1414 use std::collections::BTreeMap;
15-use std::sync::LazyLock;
1615 use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
16+use std::sync::LazyLock;
1717
1818 use ec_core::{Error, Result};
1919
2020 use crate::cdf;
2121 use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables};
22-use crate::decode::{TXFM_CTX_INIT, txfm_partition_ctx_rect};
22+use crate::decode::{txfm_partition_ctx_rect, TXFM_CTX_INIT};
2323 use crate::msac::SymbolEncoder;
24+use crate::mvstack::{find_mv_stack, mv16, MiGrid, MiInfo, NO_REF1};
2425 use crate::transform::TxType;
25-use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, mv16};
2626
2727 // ---------------------------------------------------------------------------
2828 // lane-av1lr: per-64x64 `cdef_idx` (spec 5.11.56, `read_cdef`). The decoder
@@ -386,9 +386,7 @@ fn write_inter_block_128(
386386 let scan32 = default_scan(TX32);
387387 let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec<i32> {
388388 (0..32)
389- .flat_map(|row| {
390- packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec()
391- })
389+ .flat_map(|row| packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec())
392390 .collect()
393391 };
394392 let mut chroma_units: Vec<((usize, usize), [Vec<i32>; 2])> = Vec::new();
@@ -659,9 +657,7 @@ fn write_inter_block_128_rect(
659657 let scan32 = default_scan(TX32);
660658 let unit_of = |plane: usize, cr: usize, cc: usize| -> Vec<i32> {
661659 (0..32)
662- .flat_map(|row| {
663- packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec()
664- })
660+ .flat_map(|row| packed[plane][(cr * 32 + row) * 64 + cc * 32..][..32].to_vec())
665661 .collect()
666662 };
667663 let mut chroma_units: Vec<((usize, usize), [Vec<i32>; 2])> = Vec::new();
@@ -702,7 +698,8 @@ fn write_inter_block_128_rect(
702698 &mut cdfs.txb(TxbSet::Chroma32, 0),
703699 &grid,
704700 &scan32,
705- usize::from(around.above_coded) + usize::from(around.left_coded)
701+ usize::from(around.above_coded)
702+ + usize::from(around.left_coded)
706703 + 3 * usize::from(is_half),
707704 dc_sign_ctx(around.dc_vote),
708705 Some(plane),
@@ -781,8 +778,7 @@ pub fn take_sb128_ab_hits() -> [usize; 4] {
781778 /// lane-b128r: how many of those blocks carried a REAL residual (four
782779 /// TX_64X64 luma units plus their per-chunk chroma pair) rather than being
783780 /// skipped, since the last [`take_sb128_residual_hits`].
784-static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize =
785- std::sync::atomic::AtomicUsize::new(0);
781+static SB128_RESIDUAL_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
786782
787783 /// The 128x128-with-residual count since the last call, and zero it.
788784 pub fn take_sb128_residual_hits() -> usize {
@@ -792,8 +788,7 @@ pub fn take_sb128_residual_hits() -> usize {
792788 /// [`write_inter_block_128_rect`] codes) carried a REAL residual rather than
793789 /// being skipped, since the last [`take_sb128_rectres_hits`] -- the writer
794790 /// side of [`crate::encode::take_b128_rectres_hits`]'s search count.
795-static SB128_RECTRES_HITS: std::sync::atomic::AtomicUsize =
796- std::sync::atomic::AtomicUsize::new(0);
791+static SB128_RECTRES_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
797792
798793 /// The rect/AB-piece-with-residual count since the last call, and zero it.
799794 pub fn take_sb128_rectres_hits() -> usize {
@@ -803,8 +798,7 @@ pub fn take_sb128_rectres_hits() -> usize {
803798 /// lane-b128r: how many of those blocks named a SECOND reference (the
804799 /// compound arm at the 128 root), since the last
805800 /// [`take_sb128_compound_hits`].
806-static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize =
807- std::sync::atomic::AtomicUsize::new(0);
801+static SB128_COMPOUND_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
808802
809803 /// The compound-128 count since the last call, and zero it.
810804 pub fn take_sb128_compound_hits() -> usize {
@@ -838,12 +832,7 @@ fn write_lr(enc: &mut SymbolEncoder, cdfs: &mut Cdfs, mi_row: u32, mi_col: u32,
838832 let info = plan.units[(rcol + rrow * plan.horz_units) as usize];
839833 enc.symbol(usize::from(info.is_some()), &mut cdfs.restore_wiener);
840834 if let Some(info) = info {
841- crate::restoration::write_wiener_filter(
842- enc,
843- false,
844- &mut plan.reference,
845- &info,
846- );
835+ crate::restoration::write_wiener_filter(enc, false, &mut plan.reference, &info);
847836 }
848837 }
849838 }
@@ -919,7 +908,10 @@ impl TileLayout {
919908 let starts = |total: u32, log2: u32| {
920909 let total128 = total.div_ceil(unit);
921910 let step = total128.div_ceil(1 << log2).max(1);
922- let mut v: Vec<u32> = (0..total128).step_by(step as usize).map(|s| s * unit).collect();
911+ let mut v: Vec<u32> = (0..total128)
912+ .step_by(step as usize)
913+ .map(|s| s * unit)
914+ .collect();
923915 v.push(total);
924916 v
925917 };
@@ -1067,11 +1059,9 @@ pub(crate) fn cdef_unit_owner(blocks: &[Quadrant], mi_cols: u32, mi_rows: u32) -
10671059 // (its two squares are one unit each); only a non-skip one
10681060 // codes a literal, so only it fires.
10691061 Quadrant::Ab128(symbol, pieces) => {
1070- for (piece, ((mi_r, mi_c), (w, h))) in
1071- pieces.iter().zip(crate::encode::ab128_pieces(
1072- usize::from(*symbol),
1073- (0, 0),
1074- ))
1062+ for (piece, ((mi_r, mi_c), (w, h))) in pieces
1063+ .iter()
1064+ .zip(crate::encode::ab128_pieces(usize::from(*symbol), (0, 0)))
10751065 {
10761066 if piece.skip {
10771067 continue;
@@ -1111,7 +1101,12 @@ thread_local! {
11111101 /// carries no literal at all).
11121102 pub(crate) fn arm_cdef_idx(bits: u8, sb_cols: usize, grid: Vec<u8>) {
11131103 CDEF_IDX.with(|c| {
1114- *c.borrow_mut() = (bits > 0).then(|| CdefIdxPlan { bits, sb_cols, grid, last: None });
1104+ *c.borrow_mut() = (bits > 0).then(|| CdefIdxPlan {
1105+ bits,
1106+ sb_cols,
1107+ grid,
1108+ last: None,
1109+ });
11151110 });
11161111 }
11171112
@@ -1143,8 +1138,12 @@ thread_local! {
11431138 /// lane-deltaq) when `res == 0`.
11441139 pub(crate) fn arm_delta_q(res: i32, sb_cols: usize, grid: Vec<u8>, base: u8) {
11451140 DELTA_Q.with(|c| {
1146- *c.borrow_mut() =
1147- (res > 0).then(|| DeltaQPlan { res, sb_cols, grid, cur: i32::from(base) });
1141+ *c.borrow_mut() = (res > 0).then(|| DeltaQPlan {
1142+ res,
1143+ sb_cols,
1144+ grid,
1145+ cur: i32::from(base),
1146+ });
11481147 });
11491148 }
11501149
@@ -1285,14 +1284,23 @@ fn write_filter_intra(
12851284 filter_intra: Option<u8>,
12861285 ) {
12871286 if !filter_intra_armed() || mode != DC_PRED || has_palette_y {
1288- debug_assert!(filter_intra.is_none(), "no `use_filter_intra` symbol exists here");
1287+ debug_assert!(
1288+ filter_intra.is_none(),
1289+ "no `use_filter_intra` symbol exists here"
1290+ );
12891291 return;
12901292 }
12911293 let Some(class) = crate::decode::filter_intra_size_class(side) else {
1292- debug_assert!(filter_intra.is_none(), "past av1_filter_intra_allowed_bsize");
1294+ debug_assert!(
1295+ filter_intra.is_none(),
1296+ "past av1_filter_intra_allowed_bsize"
1297+ );
12931298 return;
12941299 };
1295- enc.symbol(usize::from(filter_intra.is_some()), &mut cdfs.filter_intra[class]);
1300+ enc.symbol(
1301+ usize::from(filter_intra.is_some()),
1302+ &mut cdfs.filter_intra[class],
1303+ );
12961304 if let Some(fi) = filter_intra {
12971305 enc.symbol(usize::from(fi), &mut cdfs.filter_intra_mode);
12981306 FILTER_INTRA_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
@@ -1525,7 +1533,12 @@ fn write_motion_mode(
15251533 /// a single-reference or intra block, and `record_compound_mi`'s overwrite of
15261534 /// the ALTREF default for a compound one (this writer only codes
15271535 /// `comp_group_idx == 0`, `compound_idx == 1`).
1528-fn record_block_compound(neighbours: &mut Neighbours, at_mi: (usize, usize), side: usize, block: &BlockCoeffs) {
1536+fn record_block_compound(
1537+ neighbours: &mut Neighbours,
1538+ at_mi: (usize, usize),
1539+ side: usize,
1540+ block: &BlockCoeffs,
1541+) {
15291542 if let Some(r1) = block.inter.and_then(|i| i.ref1) {
15301543 neighbours.record_compound_mi(at_mi, side, r1, 0, 1);
15311544 }
@@ -1577,14 +1590,19 @@ pub(crate) fn high_precision_mv() -> bool {
15771590 /// `allow_high_precision_mv`, one per non-zero mv component with it), `[1]`
15781591 /// counts the ones that came out ZERO -- an eighth-pel vector, i.e. one a
15791592 /// frame without the flag cannot name at all.
1580-static HP_SYMBOLS: [std::sync::atomic::AtomicU64; 2] =
1581- [std::sync::atomic::AtomicU64::new(0), std::sync::atomic::AtomicU64::new(0)];
1593+static HP_SYMBOLS: [std::sync::atomic::AtomicU64; 2] = [
1594+ std::sync::atomic::AtomicU64::new(0),
1595+ std::sync::atomic::AtomicU64::new(0),
1596+];
15821597
15831598 /// Reads and clears [`HP_SYMBOLS`]: `(hp symbols coded, eighth-pel ones)`.
15841599 #[allow(dead_code)] // read only from the `#[cfg(test)]` witness
15851600 pub(crate) fn take_hp_symbols() -> (u64, u64) {
15861601 let all = HP_SYMBOLS[0].swap(0, std::sync::atomic::Ordering::Relaxed);
1587- (all, HP_SYMBOLS[1].swap(0, std::sync::atomic::Ordering::Relaxed))
1602+ (
1603+ all,
1604+ HP_SYMBOLS[1].swap(0, std::sync::atomic::Ordering::Relaxed),
1605+ )
15881606 }
15891607
15901608 /// [`take_hp_symbols`] without clearing -- what the NEWMV census prints.
@@ -1611,10 +1629,10 @@ fn write_compound_ref_frames(
16111629 (ref0, ref1): (i8, i8),
16121630 ) -> Result<()> {
16131631 use crate::mvstack::{
1632+ comp_reference_type_ctx, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx,
1633+ single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, uni_comp_ref_p1_ctx,
16141634 ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,
1615- LAST_FRAME, comp_reference_type_ctx, single_ref_p1_ctx, single_ref_p2_ctx,
1616- single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx,
1617- uni_comp_ref_p1_ctx,
1635+ LAST_FRAME,
16181636 };
16191637 let a = (above_ref > 0).then_some(above_ref);
16201638 let l = (left_ref > 0).then_some(left_ref);
@@ -1810,14 +1828,20 @@ fn write_compound_block(
18101828 let mut walk = 1usize;
18111829 while walk < 3 && stack.entries.len() > walk + 1 {
18121830 let advance = walk < idx;
1813- enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[walk]]);
1831+ enc.symbol(
1832+ usize::from(advance),
1833+ &mut cdfs.drl_mode[stack.drl_ctx[walk]],
1834+ );
18141835 if !advance {
18151836 break;
18161837 }
18171838 walk += 1;
18181839 }
18191840 let near = |i: usize| {
1820- stack.entries.get(i).map_or(stack.near_mv, |e| (e.mv0, e.mv1))
1841+ stack
1842+ .entries
1843+ .get(i)
1844+ .map_or(stack.near_mv, |e| (e.mv0, e.mv1))
18211845 };
18221846 if walk != idx && near(walk) != near(idx) {
18231847 note_drl_clamp(idx, walk, stack.entries.len());
@@ -1845,14 +1869,20 @@ fn write_compound_block(
18451869 let mut walk = 0usize;
18461870 while walk < 2 && stack.entries.len() > walk + 1 {
18471871 let advance = walk < idx;
1848- enc.symbol(usize::from(advance), &mut cdfs.drl_mode[stack.drl_ctx[walk]]);
1872+ enc.symbol(
1873+ usize::from(advance),
1874+ &mut cdfs.drl_mode[stack.drl_ctx[walk]],
1875+ );
18491876 if !advance {
18501877 break;
18511878 }
18521879 walk += 1;
18531880 }
18541881 let nearest = |i: usize| {
1855- stack.entries.get(i).map_or(stack.nearest_mv, |e| (e.mv0, e.mv1))
1882+ stack
1883+ .entries
1884+ .get(i)
1885+ .map_or(stack.nearest_mv, |e| (e.mv0, e.mv1))
18561886 };
18571887 if walk != idx && nearest(walk) != nearest(idx) {
18581888 note_drl_clamp(idx, walk, stack.entries.len());
@@ -1993,7 +2023,11 @@ fn write_delta_q(
19932023 // under `EC_AV1_SB128` -- decode.rs `maybe_read_delta_q` gates on
19942024 // `sb_mi_cur`, and a writer gating on a hardcoded 64 codes three
19952025 // symbol groups per 128 root the reader never reads.
1996- let sb_mi = if sb128_armed() { SB_MI as usize * 2 } else { SB_MI as usize };
2026+ let sb_mi = if sb128_armed() {
2027+ SB_MI as usize * 2
2028+ } else {
2029+ SB_MI as usize
2030+ };
19972031 if mi.0 % sb_mi != 0 || mi.1 % sb_mi != 0 {
19982032 return;
19992033 }
@@ -2820,9 +2854,9 @@ impl Quadrant {
28202854 Quadrant::Whole(block) | Quadrant::Whole64(block) | Quadrant::Whole128(block) => {
28212855 std::slice::from_ref(block)
28222856 }
2823- Quadrant::Split(blocks)
2824- | Quadrant::Rect128(_, blocks)
2825- | Quadrant::Ab128(_, blocks) => blocks.as_slice(),
2857+ Quadrant::Split(blocks) | Quadrant::Rect128(_, blocks) | Quadrant::Ab128(_, blocks) => {
2858+ blocks.as_slice()
2859+ }
28262860 Quadrant::Covered => &[],
28272861 }
28282862 }
@@ -3040,8 +3074,12 @@ impl Neighbours {
30403074 fn start_row(&mut self) {
30413075 self.left.iter_mut().for_each(|l| *l = Default::default());
30423076 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);
3043- self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
3044- self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
3077+ self.left_side
3078+ .iter_mut()
3079+ .for_each(|s| *s = NO_NEIGHBOUR_SIDE);
3080+ self.left_side_mi
3081+ .iter_mut()
3082+ .for_each(|s| *s = NO_NEIGHBOUR_SIDE);
30453083 self.left_skip.iter_mut().for_each(|s| *s = false);
30463084 self.left_inter.iter_mut().for_each(|i| *i = false);
30473085 self.left_ref.iter_mut().for_each(|r| *r = -1);
@@ -3052,7 +3090,9 @@ impl Neighbours {
30523090 self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT);
30533091 self.left_palette_size.iter_mut().for_each(|s| *s = 0);
30543092 self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0);
3055- self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
3093+ self.left_palette_uv_colors
3094+ .iter_mut()
3095+ .for_each(|c| *c = [0u16; 8]);
30563096 }
30573097
30583098 /// `av1_get_palette_mode_ctx` + `av1_get_palette_cache`, mirrored from
@@ -3069,12 +3109,18 @@ impl Neighbours {
30693109 let above_ok = r % 16 != 0;
30703110 let above_is_palette = r > 0 && self.above_palette_size[c] > 0;
30713111 let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 {
3072- (usize::from(self.above_palette_size[c]), self.above_palette_colors[c])
3112+ (
3113+ usize::from(self.above_palette_size[c]),
3114+ self.above_palette_colors[c],
3115+ )
30733116 } else {
30743117 (0, [0u16; 8])
30753118 };
30763119 let (left_n, left_colors) = if c > 0 && self.left_palette_size[r] > 0 {
3077- (usize::from(self.left_palette_size[r]), self.left_palette_colors[r])
3120+ (
3121+ usize::from(self.left_palette_size[r]),
3122+ self.left_palette_colors[r],
3123+ )
30783124 } else {
30793125 (0, [0u16; 8])
30803126 };
@@ -3167,7 +3213,13 @@ impl Neighbours {
31673213 /// [`Self::record_palette_y`] for the chroma bands (decode.rs
31683214 /// `record_palette_uv_rect`) -- `size == 0` clears stale state the same
31693215 /// way, and the span is in LUMA pixels for both planes' bands alike.
3170- fn record_palette_uv(&mut self, (r, c): (usize, usize), (w, h): (usize, usize), size: u8, colors: [u16; 8]) {
3216+ fn record_palette_uv(
3217+ &mut self,
3218+ (r, c): (usize, usize),
3219+ (w, h): (usize, usize),
3220+ size: u8,
3221+ colors: [u16; 8],
3222+ ) {
31713223 // lane-b128hv: the above band spans the block's WIDTH and the left
31723224 // band its HEIGHT; identical to the one loop this replaces at w == h.
31733225 for cell in 0..(w / MI).max(1) {
@@ -3191,7 +3243,13 @@ impl Neighbours {
31913243 /// What a just-written block leaves in the palette bands (decode.rs
31923244 /// `record_palette_y_rect`): its size and colours over every 4x4 unit it
31933245 /// spans, `0` for a block that took no palette.
3194- fn record_palette_y(&mut self, (r, c): (usize, usize), (w, h): (usize, usize), size: u8, colors: [u16; 8]) {
3246+ fn record_palette_y(
3247+ &mut self,
3248+ (r, c): (usize, usize),
3249+ (w, h): (usize, usize),
3250+ size: u8,
3251+ colors: [u16; 8],
3252+ ) {
31953253 // lane-b128hv: the above band spans the block's WIDTH and the left
31963254 // band its HEIGHT; identical to the one loop this replaces at w == h.
31973255 for cell in 0..(w / MI).max(1) {
@@ -3216,7 +3274,13 @@ impl Neighbours {
32163274 /// of an INTER frame leaves in the two `TXFM_CONTEXT` bands -- its
32173275 /// resolved transform size over the span `(w_px, h_px)`, which for a
32183276 /// SKIPPED inter block is its own block size instead.
3219- fn record_txfm(&mut self, (mi_r, mi_c): (usize, usize), tx_px: usize, w_px: usize, h_px: usize) {
3277+ fn record_txfm(
3278+ &mut self,
3279+ (mi_r, mi_c): (usize, usize),
3280+ tx_px: usize,
3281+ w_px: usize,
3282+ h_px: usize,
3283+ ) {
32203284 for i in 0..h_px / MI {
32213285 if let Some(cell) = self.left_txfm.get_mut(mi_r + i) {
32223286 *cell = tx_px as u8;
@@ -3492,9 +3556,22 @@ impl Neighbours {
34923556 /// Writes one inter-frame block's skip flag and inter/intra state into
34933557 /// every 16x16 column and row it covers, the same span [`Self::record`]
34943558 /// fills for the coefficient and mode state.
3495- fn record_inter(&mut self, at: (usize, usize), side: usize, skip: bool, is_inter: bool, ref_frame: i8) {
3559+ fn record_inter(
3560+ &mut self,
3561+ at: (usize, usize),
3562+ side: usize,
3563+ skip: bool,
3564+ is_inter: bool,
3565+ ref_frame: i8,
3566+ ) {
34963567 let (r, c) = at;
3497- self.record_inter_mi((r * (SUB / MI), c * (SUB / MI)), side, skip, is_inter, ref_frame);
3568+ self.record_inter_mi(
3569+ (r * (SUB / MI), c * (SUB / MI)),
3570+ side,
3571+ skip,
3572+ is_inter,
3573+ ref_frame,
3574+ );
34983575 }
34993576
35003577 /// lane-b128hv: [`Self::record_inter_mi`] with independent above (width)
@@ -3572,7 +3649,14 @@ impl Neighbours {
35723649
35733650 /// [`Self::record_inter`] taking the block's position directly in 4x4
35743651 /// mode-info units, for a block finer than one [`SUB`] slot.
3575- fn record_inter_mi(&mut self, (mi_r, mi_c): (usize, usize), side: usize, skip: bool, is_inter: bool, ref_frame: i8) {
3652+ fn record_inter_mi(
3653+ &mut self,
3654+ (mi_r, mi_c): (usize, usize),
3655+ side: usize,
3656+ skip: bool,
3657+ is_inter: bool,
3658+ ref_frame: i8,
3659+ ) {
35763660 for cell in 0..side / MI {
35773661 self.above_skip[mi_c + cell] = skip;
35783662 self.left_skip[mi_r + cell] = skip;
@@ -3838,7 +3922,16 @@ pub(crate) fn sb_coeff_key_frame_tile_cdfs(
38383922 neighbours.start_row();
38393923 }
38403924 if sb128 && sb_start {
3841- write_sb128_root(&mut enc, &mut cdfs, &neighbours, sb_r, sb_c, mi_cols, mi_rows, PARTITION_SPLIT);
3925+ write_sb128_root(
3926+ &mut enc,
3927+ &mut cdfs,
3928+ &neighbours,
3929+ sb_r,
3930+ sb_c,
3931+ mi_cols,
3932+ mi_rows,
3933+ PARTITION_SPLIT,
3934+ );
38423935 }
38433936 {
38443937 if !sb128 {
@@ -4316,7 +4409,12 @@ fn write_palette_colors_y(enc: &mut SymbolEncoder, colors: &[u16], cache: &[u16]
43164409 /// below sees, so it only ever makes the encoder take FEWER chroma palettes
43174410 /// than it should -- never a wrong stream. Upgrade path: price both forms
43184411 /// here and write the cheaper one under its own leading bit.
4319-fn write_palette_colors_uv(enc: &mut SymbolEncoder, u_colors: &[u16], v_colors: &[u16], cache: &[u16]) {
4412+fn write_palette_colors_uv(
4413+ enc: &mut SymbolEncoder,
4414+ u_colors: &[u16],
4415+ v_colors: &[u16],
4416+ cache: &[u16],
4417+) {
43204418 let n = u_colors.len();
43214419 let mut cached: Vec<u16> = Vec::with_capacity(n);
43224420 for &c in cache {
@@ -4441,7 +4539,14 @@ pub(crate) fn palette_uv_bits(pal: &PaletteUv, side: usize, on: (usize, usize))
44414539 enc.symbol(n - 2, &mut size_cdf);
44424540 write_palette_colors_uv(&mut enc, &pal.u_colors[..n], &pal.v_colors[..n], &[]);
44434541 let mut idx_cdfs = cdf::PALETTE_UV_COLOR_INDEX[n - 2];
4444- write_color_index_map(&mut enc, &mut idx_cdfs, &pal.map, palette_uv_side(side), n, on);
4542+ write_color_index_map(
4543+ &mut enc,
4544+ &mut idx_cdfs,
4545+ &pal.map,
4546+ palette_uv_side(side),
4547+ n,
4548+ on,
4549+ );
44454550 enc.bits()
44464551 }
44474552
@@ -4552,7 +4657,12 @@ fn write_dv_component(enc: &mut SymbolEncoder, c: &mut MvComponentCdfs, diff: i3
45524657
45534658 /// One intrabc block's DV as a residual against [`intrabc_dv_pred`], off the
45544659 /// `dv` nmv context (decode.rs `read_intrabc_dv` -> `read_mv`).
4555-fn write_dv(enc: &mut SymbolEncoder, cdfs: &mut Cdfs, dv: (i32, i32), pred: (i32, i32)) -> Result<()> {
4660+fn write_dv(
4661+ enc: &mut SymbolEncoder,
4662+ cdfs: &mut Cdfs,
4663+ dv: (i32, i32),
4664+ pred: (i32, i32),
4665+) -> Result<()> {
45564666 let diff = (dv.0 - pred.0, dv.1 - pred.1);
45574667 let joint = match (diff.0 != 0, diff.1 != 0) {
45584668 (false, false) => 0,
@@ -4584,7 +4694,8 @@ fn write_intrabc_block(
45844694 mi: (usize, usize),
45854695 side: usize,
45864696 ) -> Result<()> {
4587- let skip_ctx = usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]);
4697+ let skip_ctx =
4698+ usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]);
45884699 enc.symbol(1, &mut cdfs.skip[skip_ctx]);
45894700 write_cdef_idx(enc, mi, true);
45904701 enc.symbol(1, &mut cdfs.intrabc);
@@ -4705,7 +4816,8 @@ fn write_intra_mode(
47054816 // above + left. Every block this writer codes outside an `allow_intrabc`
47064817 // frame is unskipped, so both bands stay false and this stays 0 -- the
47074818 // literal every stream before this lane was written with.
4708- let skip_ctx = usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]);
4819+ let skip_ctx =
4820+ usize::from(neighbours.above_skip[mi.1]) + usize::from(neighbours.left_skip[mi.0]);
47094821 enc.symbol(0, &mut cdfs.skip[skip_ctx]);
47104822 write_cdef_idx(enc, mi, false);
47114823 // `read_intrabc_info` (spec 5.11.13): the flag is read for EVERY intra
@@ -4737,7 +4849,9 @@ fn write_intra_mode(
47374849 write_cfl_alphas(
47384850 enc,
47394851 cdfs,
4740- block.cfl_alphas.expect("a UV_CFL_PRED block carries its alphas"),
4852+ block
4853+ .cfl_alphas
4854+ .expect("a UV_CFL_PRED block carries its alphas"),
47414855 );
47424856 }
47434857 // `angle_delta_uv` (spec `read_intra_angle_info`) off the same CDF array
@@ -4858,7 +4972,8 @@ fn write_palette_syntax(
48584972 &pal.map,
48594973 uv_side,
48604974 n,
4861- crate::decode::palette_onscreen_uv((side, side), on, (uv_side, uv_side)),
4975+ // The encoder writes 4:2:0 only (`palette_uv_side` above).
4976+ crate::decode::palette_onscreen_uv((side, side), on, (uv_side, uv_side), (1, 1)),
48624977 );
48634978 note_palette_uv(n);
48644979 }
@@ -4890,8 +5005,7 @@ static PALETTE_HITS: [std::sync::atomic::AtomicUsize; 9] =
48905005 /// i.e. palette blocks this writer cut at the frame's right/bottom mi edge.
48915006 /// A gate asserts it non-zero so it cannot pass on a stream that never cuts
48925007 /// one (class `gate-blind-to-feature`).
4893-static PALETTE_CUT_MAPS: std::sync::atomic::AtomicUsize =
4894- std::sync::atomic::AtomicUsize::new(0);
5008+static PALETTE_CUT_MAPS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
48955009
48965010 /// Current value of [`PALETTE_CUT_MAPS`] (colour-index maps).
48975011 pub fn palette_cut_maps_written() -> usize {
@@ -4975,15 +5089,7 @@ fn write_block(
49755089 }
49765090 let (above_mode, left_mode) = (neighbours.above_mode[c], neighbours.left_mode[r]);
49775091 let mode = write_intra_mode(
4978- enc,
4979- cdfs,
4980- neighbours,
4981- block,
4982- above_mode,
4983- left_mode,
4984- cfl,
4985- at_mi,
4986- side,
5092+ enc, cdfs, neighbours, block, above_mode, left_mode, cfl, at_mi, side,
49875093 );
49885094 // The coefficient tables read `fimode_to_intradir[filter_intra_mode]`'s
49895095 // row on a filter-intra block; the neighbour publication below still gets
@@ -5085,7 +5191,9 @@ fn write_leaf8(
50855191 // true first divergence (a differently-sized alphabet under the same
50865192 // DC_PRED decision desyncs the coder even though the decoded mode is
50875193 // unchanged).
5088- let mode = write_intra_mode(enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8);
5194+ let mode = write_intra_mode(
5195+ enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8,
5196+ );
50895197 let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4];
50905198 // As [`write_block`]: the coefficient row follows the filter-intra mode,
50915199 // the mode this leaf publishes (and returns to the next leaf) does not.
@@ -5218,7 +5326,11 @@ fn write_block_planes(
52185326 /// The single luma transform type a block carries, `DCT_DCT` for one that
52195327 /// never searched one (lane-txset).
52205328 fn block_tx_type(block: &BlockCoeffs) -> TxType {
5221- block.luma_tx_types.first().copied().unwrap_or(TxType::DctDct)
5329+ block
5330+ .luma_tx_types
5331+ .first()
5332+ .copied()
5333+ .unwrap_or(TxType::DctDct)
52225334 }
52235335
52245336 /// The `(side / tx)^2` transform units of one block's luma residual, raster
@@ -5294,9 +5406,7 @@ fn write_luma_tus(
52945406 grid.to_vec()
52955407 } else {
52965408 (0..tx)
5297- .flat_map(|row| {
5298- grid[(tu_row * tx + row) * side + tu_col * tx..][..tx].to_vec()
5299- })
5409+ .flat_map(|row| grid[(tu_row * tx + row) * side + tu_col * tx..][..tx].to_vec())
53005410 .collect()
53015411 };
53025412 // spec `get_txb_ctx_general`: a lone transform unit covering its
@@ -5381,7 +5491,9 @@ fn write_luma_select(
53815491 }
53825492 }
53835493 let tx = max_tx >> depth;
5384- write_luma_tus(enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans, false, tx_types)?;
5494+ write_luma_tus(
5495+ enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans, false, tx_types,
5496+ )?;
53855497 neighbours.record_tx(at_mi, side, tx);
53865498 Ok(tx)
53875499 }
@@ -5681,7 +5793,9 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 {
56815793 .map(|tu| {
56825794 let (r0, c0) = ((tu / 2) * 32, (tu % 2) * 32);
56835795 let unit: Vec<i32> = (0..32)
5684- .flat_map(|row| g[(r0 + row) * 64 + c0..][..32].to_vec())
5796+ .flat_map(|row| {
5797+ g[(r0 + row) * 64 + c0..][..32].to_vec()
5798+ })
56855799 .collect();
56865800 coeff_bits(&unit, TxbSet::Luma32Inter, q_ctx, 0, 0)
56875801 })
@@ -5696,7 +5810,10 @@ pub(crate) fn predicted_coeff_bits(blocks: &[Quadrant], base_q_idx: u8) -> f64 {
56965810 }
56975811 Quadrant::Covered => return 0.0,
56985812 };
5699- q.blocks().iter().map(|b| block_bits(b, side, q_ctx)).sum::<f64>()
5813+ q.blocks()
5814+ .iter()
5815+ .map(|b| block_bits(b, side, q_ctx))
5816+ .sum::<f64>()
57005817 })
57015818 .sum()
57025819 }
@@ -5764,7 +5881,7 @@ fn scan_of(side: usize) -> &'static Vec<u16> {
57645881 /// DECODER's own table so the two cannot drift, cached per size and class.
57655882 fn class_scan_of(side: usize, class: crate::decode::TxClass) -> &'static [u16] {
57665883 static SCANS: LazyLock<[[Vec<u16>; 2]; 4]> = LazyLock::new(|| {
5767- use crate::decode::{TxClass, class_scan_table};
5884+ use crate::decode::{class_scan_table, TxClass};
57685885 [TX4, TX8, TX16, TX32].map(|side| {
57695886 [
57705887 class_scan_table(side, TxClass::Horiz),
@@ -5846,7 +5963,16 @@ pub(crate) fn coeff_bits_typed(
58465963 }
58475964 let scan = scan_of(coding.side);
58485965 let mut enc = SymbolEncoder::pricer();
5849- write_coeffs(&mut enc, &mut coding, grid, scan, skip_ctx, sign_ctx, None, tx_type);
5966+ write_coeffs(
5967+ &mut enc,
5968+ &mut coding,
5969+ grid,
5970+ scan,
5971+ skip_ctx,
5972+ sign_ctx,
5973+ None,
5974+ tx_type,
5975+ );
58505976 enc.bits()
58515977 };
58525978 // lane-av1speed2: 60% of the transform units of an inter stream hold no
@@ -5866,12 +5992,20 @@ pub(crate) fn coeff_bits_typed(
58665992 let all_zero = grid.iter().all(|&level| level == 0);
58675993 PRICING_BASE.with_borrow_mut(|base| {
58685994 if let Some(slot) = base.as_deref_mut().filter(|s| s.0.q_ctx == q_ctx) {
5869- return if all_zero { zero_price(slot) } else { price(slot) };
5995+ return if all_zero {
5996+ zero_price(slot)
5997+ } else {
5998+ price(slot)
5999+ };
58706000 }
58716001 PRICING.with_borrow_mut(|slots| {
58726002 let slot = slots[q_ctx.min(3)]
58736003 .get_or_insert_with(|| Box::new((Cdfs::new(q_ctx), Cdfs::new(q_ctx))));
5874- if all_zero { zero_price(slot) } else { price(slot) }
6004+ if all_zero {
6005+ zero_price(slot)
6006+ } else {
6007+ price(slot)
6008+ }
58756009 })
58766010 })
58776011 }
@@ -5951,7 +6085,11 @@ pub(crate) fn rdoq(
59516085 // is what the writer and the pricer take (`coded_corner`).
59526086 let coded = side.min(TX32);
59536087 let q_ctx = crate::decode::q_ctx_of(base_q_idx);
5954- let mut dense = if coded == side { Vec::new() } else { vec![0i32; coded * coded] };
6088+ let mut dense = if coded == side {
6089+ Vec::new()
6090+ } else {
6091+ vec![0i32; coded * coded]
6092+ };
59556093 fn price(
59566094 levels: &[i32],
59576095 dense: &mut [i32],
@@ -5971,7 +6109,9 @@ pub(crate) fn rdoq(
59716109 }
59726110 coeff_bits_typed(dense, set, q_ctx, skip_ctx, sign_ctx, tx_type)
59736111 }
5974- let mut bits = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type);
6112+ let mut bits = price(
6113+ levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type,
6114+ );
59756115 // The DC has its own quantiser, so its squared error per unit of level is
59766116 // `(dc_q / ac_q)^2` of an AC coefficient's.
59776117 let dc = f64::from(crate::quant::dc_q(8, i32::from(base_q_idx)));
@@ -6022,9 +6162,11 @@ pub(crate) fn rdoq(
60226162 let candidate = level - level.signum();
60236163 levels[i] = candidate;
60246164 budget -= 1;
6025- let after = price(levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type);
6026- let distortion = weight
6027- * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2));
6165+ let after = price(
6166+ levels, &mut dense, side, coded, set, q_ctx, skip_ctx, sign_ctx, tx_type,
6167+ );
6168+ let distortion =
6169+ weight * ((s - f64::from(candidate)).powi(2) - (s - f64::from(level)).powi(2));
60286170 if distortion + lambda * (after - bits) < 0.0 {
60296171 bits = after;
60306172 if census {
@@ -6049,8 +6191,14 @@ pub(crate) fn rdoq(
60496191 /// at the end of the scan), zeroed coefficients, lowered coefficients, bits
60506192 /// after the pass * 64, bits before the pass * 64.
60516193 pub(crate) static RDOQ_STATS: [AtomicU64; 8] = [
6052- AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0),
6053- AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0), AtomicU64::new(0),
6194+ AtomicU64::new(0),
6195+ AtomicU64::new(0),
6196+ AtomicU64::new(0),
6197+ AtomicU64::new(0),
6198+ AtomicU64::new(0),
6199+ AtomicU64::new(0),
6200+ AtomicU64::new(0),
6201+ AtomicU64::new(0),
60546202 ];
60556203
60566204 /// The pre-pass half of [`RDOQ_STATS`] (`EC_AV1_RDOQ_CENSUS`): what the
@@ -6146,11 +6294,13 @@ thread_local! {
61466294 /// at native, still with every one of its frames armed with the defaults.
61476295 pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) {
61486296 static MODE: std::sync::OnceLock<u8> = std::sync::OnceLock::new();
6149- let mode = *MODE.get_or_init(|| match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() {
6150- Ok("0") => 0,
6151- Ok("1") => 1,
6152- _ => 2,
6153- });
6297+ let mode = *MODE.get_or_init(
6298+ || match std::env::var("EC_AV1_PRICE_FRAME_CDFS").as_deref() {
6299+ Ok("0") => 0,
6300+ Ok("1") => 1,
6301+ _ => 2,
6302+ },
6303+ );
61546304 let on = match mode {
61556305 0 => false,
61566306 1 => true,
@@ -6158,7 +6308,9 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) {
61586308 };
61596309 PRICING_HITS[usize::from(on && base.is_some())].fetch_add(1, Ordering::Relaxed);
61606310 PRICING_BASE.with_borrow_mut(|slot| {
6161- *slot = base.filter(|_| on).map(|c| Box::new((c.clone(), c.clone())));
6311+ *slot = base
6312+ .filter(|_| on)
6313+ .map(|c| Box::new((c.clone(), c.clone())));
61626314 });
61636315 }
61646316
@@ -6166,8 +6318,7 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) {
61666318 /// many with the frame's REAL starting tables ([`arm_pricing_cdfs`]), so a
61676319 /// gate can print which side of the screen gate every frame landed on. Counts
61686320 /// arming calls, not frames: a multi-tile frame arms one worker per tile.
6169-pub(crate) static PRICING_HITS: [AtomicUsize; 2] =
6170- [AtomicUsize::new(0), AtomicUsize::new(0)];
6321+pub(crate) static PRICING_HITS: [AtomicUsize; 2] = [AtomicUsize::new(0), AtomicUsize::new(0)];
61716322
61726323 /// Reads and clears [`PRICING_HITS`]: (default-table armings, real-table
61736324 /// armings).
@@ -6389,7 +6540,10 @@ fn write_coeffs(
63896540 // lane-av1speed3: `side` is 4, 8, 16 or 32, but it is a runtime value --
63906541 // `pos / side` compiles to a real integer division, once per coefficient,
63916542 // in the encoder's largest self-time symbol. Same row and column.
6392- debug_assert!(side.is_power_of_two(), "the scan splits a position by shifting");
6543+ debug_assert!(
6544+ side.is_power_of_two(),
6545+ "the scan splits a position by shifting"
6546+ );
63936547 let (shift, mask) = (side.trailing_zeros(), side - 1);
63946548 for scan_idx in (0..eob).rev() {
63956549 let pos = scan[scan_idx] as usize;
@@ -6649,7 +6803,11 @@ fn br_ctx(
66496803 if row == 0 && col == 0 {
66506804 return mag;
66516805 }
6652- let near_origin = if class == TxClass::Horiz { col == 0 } else { row == 0 };
6806+ let near_origin = if class == TxClass::Horiz {
6807+ col == 0
6808+ } else {
6809+ row == 0
6810+ };
66536811 return if near_origin { mag + 7 } else { mag + 14 };
66546812 }
66556813 let p = row * side + col;
@@ -6800,7 +6958,11 @@ pub(crate) fn intra_inter_ctx(
68006958 /// `CLASS0_SIZE << (class + 2)` (spec 3), the magnitude an `MV_CLASS_n`
68016959 /// component's own bits start counting from; class zero starts at zero.
68026960 fn mv_class_base(class: usize) -> i32 {
6803- if class == 0 { 0 } else { 2i32 << (class + 2) }
6961+ if class == 0 {
6962+ 0
6963+ } else {
6964+ 2i32 << (class + 2)
6965+ }
68046966 }
68056967
68066968 /// The class a pre-offset magnitude `z` (`|diff| - 1`) falls in — the inverse
@@ -6923,11 +7085,12 @@ fn write_single_ref(
69237085 left_ref: i8,
69247086 left_ref1: Option<i8>,
69257087 ) {
6926- REF_HITS[(ref_frame.max(1) - 1) as usize % 7].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
7088+ REF_HITS[(ref_frame.max(1) - 1) as usize % 7]
7089+ .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
69277090 use crate::mvstack::{
6928- ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,
69297091 single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx,
6930- single_ref_p5_ctx, single_ref_p6_ctx,
7092+ single_ref_p5_ctx, single_ref_p6_ctx, ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME,
7093+ GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,
69317094 };
69327095 let above = (above_ref > 0).then_some(above_ref);
69337096 let left = (left_ref > 0).then_some(left_ref);
@@ -7071,7 +7234,10 @@ pub(crate) fn take_drl_hits() -> [usize; 4] {
70717234 /// pricer's own offer set is enumerated against this rule by
70727235 /// `crate::encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`.
70737236 pub(crate) fn signalled_drl_idx(entries: usize, start: usize, target: usize) -> usize {
7074- target.min(start + 2).min(entries.saturating_sub(1)).max(start)
7237+ target
7238+ .min(start + 2)
7239+ .min(entries.saturating_sub(1))
7240+ .max(start)
70757241 }
70767242
70777243 fn write_drl_idx(
@@ -7161,7 +7327,7 @@ fn write_inter_mode(
71617327 enc.symbol(1, &mut cdfs.new_mv[stack.new_mv_ctx]); // not NEWMV
71627328 enc.symbol(1, &mut cdfs.zero_mv[stack.zero_mv_ctx]); // not GLOBALMV
71637329 enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV
7164- // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).
7330+ // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).
71657331 let idx = idx.max(1);
71667332 let signalled = write_drl_idx(enc, cdfs, stack, 1, idx);
71677333 let mv = stack.entries.get(signalled).map_or(stack.near_mv, |e| e.mv);
@@ -7335,12 +7501,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
73357501 let scan4 = default_scan(TX4);
73367502 // The same four tables again as one array, which is what the per-unit
73377503 // luma writer indexes by transform side.
7338- let all_scans = [
7339- scan32.clone(),
7340- scan16.clone(),
7341- scan8.clone(),
7342- scan4.clone(),
7343- ];
7504+ let all_scans = [scan32.clone(), scan16.clone(), scan8.clone(), scan4.clone()];
73447505 let zero_grids = [
73457506 vec![0i32; TX32 * TX32],
73467507 vec![0i32; TX16 * TX16],
@@ -7431,7 +7592,10 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
74317592 // (mi_row, mi_col) and a second one at + hbs (16 mi) along the
74327593 // cut axis, the second only when it is inside the frame -- the
74337594 // search only offers a root wholly inside, so both are.
7434- let base_mi = ((sb_r & !1) as usize * SB_MI as usize, (sb_c & !1) as usize * SB_MI as usize);
7595+ let base_mi = (
7596+ (sb_r & !1) as usize * SB_MI as usize,
7597+ (sb_c & !1) as usize * SB_MI as usize,
7598+ );
74357599 let (w, h) = if horz { (128usize, 64usize) } else { (64, 128) };
74367600 for (i, half) in halves.iter().enumerate() {
74377601 let at_mi = if horz {
@@ -7467,8 +7631,9 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
74677631 (sb_r & !1) as usize * SB_MI as usize,
74687632 (sb_c & !1) as usize * SB_MI as usize,
74697633 );
7470- for (((mi_r, mi_c), (w, h)), piece) in
7471- crate::encode::ab128_pieces(symbol, base_mi).iter().zip(pieces)
7634+ for (((mi_r, mi_c), (w, h)), piece) in crate::encode::ab128_pieces(symbol, base_mi)
7635+ .iter()
7636+ .zip(pieces)
74727637 {
74737638 write_inter_block_128_rect(
74747639 &mut enc,
@@ -7532,7 +7697,13 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
75327697 + usize::from(neighbours.left_skip[mi_r]);
75337698 enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]);
75347699 write_cdef_idx(&mut enc, (mi_r, mi_c), block.skip);
7535- write_delta_q(&mut enc, &mut cdfs, (mi_r, mi_c), !sb128_armed(), block.skip);
7700+ write_delta_q(
7701+ &mut enc,
7702+ &mut cdfs,
7703+ (mi_r, mi_c),
7704+ !sb128_armed(),
7705+ block.skip,
7706+ );
75367707 let ii_ctx = intra_inter_ctx(
75377708 has_above,
75387709 has_left,
@@ -7926,7 +8097,6 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
79268097 // caller (r15): the SUB-grid skip/inter arrays
79278098 // are otherwise left stale for the next
79288099 // 16x16 slot.
7929-
79308100 }
79318101 }
79328102 continue;
@@ -7951,111 +8121,137 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
79518121
79528122 let mode_for_tx;
79538123 if let Some(info) = block.inter {
7954- write_comp_mode(&mut enc, &mut cdfs, &neighbours, (mi_r, mi_c), (has_above, has_left), info.ref1.is_some());
8124+ write_comp_mode(
8125+ &mut enc,
8126+ &mut cdfs,
8127+ &neighbours,
8128+ (mi_r, mi_c),
8129+ (has_above, has_left),
8130+ info.ref1.is_some(),
8131+ );
79558132 let (mi_row, mi_col) = (r32 as usize * 8, c32 as usize * 8);
79568133 if info.ref1.is_some() {
79578134 let (mv, mv1, is_new_mv) = write_compound_block(
7958- &mut enc, &mut cdfs, &neighbours, &grid, (mi_row, mi_col), (8, 8),
7959- (has_above, has_left), info, (mi_cols as usize, mi_rows as usize),
8135+ &mut enc,
8136+ &mut cdfs,
8137+ &neighbours,
8138+ &grid,
8139+ (mi_row, mi_col),
8140+ (8, 8),
8141+ (has_above, has_left),
8142+ info,
8143+ (mi_cols as usize, mi_rows as usize),
79608144 )?;
79618145 for dr in 0..8 {
79628146 for dc in 0..8 {
7963- grid.set(mi_row + dr, mi_col + dc, MiInfo {
7964- is_inter: true,
7965- ref_frame: info.ref_frame,
7966- ref_frame1: info.ref1.unwrap_or(NO_REF1),
7967- mv1: mv16(mv1),
7968- mv: mv16(mv),
7969- is_new_mv,
7970- size: 8,
7971- size_h: 8,
7972- is_global_mv0: false,
7973- is_global_mv1: false,
7974- });
8147+ grid.set(
8148+ mi_row + dr,
8149+ mi_col + dc,
8150+ MiInfo {
8151+ is_inter: true,
8152+ ref_frame: info.ref_frame,
8153+ ref_frame1: info.ref1.unwrap_or(NO_REF1),
8154+ mv1: mv16(mv1),
8155+ mv: mv16(mv),
8156+ is_new_mv,
8157+ size: 8,
8158+ size_h: 8,
8159+ is_global_mv0: false,
8160+ is_global_mv1: false,
8161+ },
8162+ );
79758163 }
79768164 }
79778165 mode_for_tx = 0;
79788166 } else {
7979- write_single_ref(&mut enc, &mut cdfs, info.ref_frame, neighbours.above_ref[mi_c], neighbours.above_ref1[mi_c], neighbours.left_ref[mi_r], neighbours.left_ref1[mi_r]);
8167+ write_single_ref(
8168+ &mut enc,
8169+ &mut cdfs,
8170+ info.ref_frame,
8171+ neighbours.above_ref[mi_c],
8172+ neighbours.above_ref1[mi_c],
8173+ neighbours.left_ref[mi_r],
8174+ neighbours.left_ref1[mi_r],
8175+ );
79808176
7981- let stack = find_mv_stack(
7982- &grid,
7983- mi_row,
7984- mi_col,
7985- 8,
7986- 8,
7987- info.ref_frame,
7988- mi_cols as usize,
7989- mi_rows as usize,
7990- );
8177+ let stack = find_mv_stack(
8178+ &grid,
8179+ mi_row,
8180+ mi_col,
8181+ 8,
8182+ 8,
8183+ info.ref_frame,
8184+ mi_cols as usize,
8185+ mi_rows as usize,
8186+ );
79918187
7992- let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?;
7993- if crate::msac::symtrace::dir().is_some() {
7994- crate::msac::symtrace::note(&format!(
7995- " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}",
7996- info.mode, info.ref_mv_idx, info.mv
7997- ));
7998- }
7999- grid.set(
8000- mi_row,
8001- mi_col,
8002- MiInfo {
8003- is_inter: true,
8004- ref_frame: info.ref_frame,
8005- ref_frame1: NO_REF1,
8006- mv1: (0, 0),
8007- mv: mv16(mv),
8008- is_new_mv,
8009- size: 8,
8010- size_h: 8,
8011- is_global_mv0: false,
8012- is_global_mv1: false,
8013- },
8014- );
8015- for dr in 0..8 {
8016- for dc in 0..8 {
8017- if dr == 0 && dc == 0 {
8018- continue;
8188+ let (mv, is_new_mv) = write_inter_mode(&mut enc, &mut cdfs, info, &stack)?;
8189+ if crate::msac::symtrace::dir().is_some() {
8190+ crate::msac::symtrace::note(&format!(
8191+ " MODE mi=({mi_r},{mi_c}) mode={:?} idx={} mv={mv:?} info_mv={:?}",
8192+ info.mode, info.ref_mv_idx, info.mv
8193+ ));
8194+ }
8195+ grid.set(
8196+ mi_row,
8197+ mi_col,
8198+ MiInfo {
8199+ is_inter: true,
8200+ ref_frame: info.ref_frame,
8201+ ref_frame1: NO_REF1,
8202+ mv1: (0, 0),
8203+ mv: mv16(mv),
8204+ is_new_mv,
8205+ size: 8,
8206+ size_h: 8,
8207+ is_global_mv0: false,
8208+ is_global_mv1: false,
8209+ },
8210+ );
8211+ for dr in 0..8 {
8212+ for dc in 0..8 {
8213+ if dr == 0 && dc == 0 {
8214+ continue;
8215+ }
8216+ grid.set(
8217+ mi_row + dr,
8218+ mi_col + dc,
8219+ MiInfo {
8220+ is_inter: true,
8221+ ref_frame: info.ref_frame,
8222+ ref_frame1: NO_REF1,
8223+ mv1: (0, 0),
8224+ mv: mv16(mv),
8225+ is_new_mv,
8226+ size: 8,
8227+ size_h: 8,
8228+ is_global_mv0: false,
8229+ is_global_mv1: false,
8230+ },
8231+ );
80198232 }
8020- grid.set(
8021- mi_row + dr,
8022- mi_col + dc,
8023- MiInfo {
8024- is_inter: true,
8025- ref_frame: info.ref_frame,
8026- ref_frame1: NO_REF1,
8027- mv1: (0, 0),
8028- mv: mv16(mv),
8029- is_new_mv,
8030- size: 8,
8031- size_h: 8,
8032- is_global_mv0: false,
8033- is_global_mv1: false,
8034- },
8035- );
80368233 }
8037- }
8038- write_motion_mode(
8039- &mut enc,
8040- &mut cdfs,
8041- &grid,
8042- (mi_row, mi_col),
8043- (8, 8),
8044- (BLOCK, BLOCK),
8045- (mi_cols as usize, mi_rows as usize),
8046- info.ref_frame,
8047- block.motion_mode,
8048- )?;
8049- mode_for_tx = 0;
8234+ write_motion_mode(
8235+ &mut enc,
8236+ &mut cdfs,
8237+ &grid,
8238+ (mi_row, mi_col),
8239+ (8, 8),
8240+ (BLOCK, BLOCK),
8241+ (mi_cols as usize, mi_rows as usize),
8242+ info.ref_frame,
8243+ block.motion_mode,
8244+ )?;
8245+ mode_for_tx = 0;
80508246 }
80518247 } else {
80528248 let mode = usize::from(block.mode);
80538249 enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_32]);
80548250 if (V_PRED..=D67_PRED).contains(&mode) {
80558251 enc.symbol(
8056- (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8057- &mut cdfs.angle_delta[mode - V_PRED],
8058- );
8252+ (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8253+ &mut cdfs.angle_delta[mode - V_PRED],
8254+ );
80598255 }
80608256 let uv_mode = usize::from(block.uv_mode);
80618257 enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]);
@@ -8208,7 +8404,8 @@ fn write_inter_frame_leaf(
82088404
82098405 let (r, c) = at;
82108406 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
8211- let skip_ctx = usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]);
8407+ let skip_ctx =
8408+ usize::from(neighbours.above_skip[mi_c]) + usize::from(neighbours.left_skip[mi_r]);
82128409 enc.symbol(usize::from(block.skip), &mut cdfs.skip[skip_ctx]);
82138410 write_cdef_idx(enc, (mi_r, mi_c), block.skip);
82148411 write_delta_q(enc, cdfs, (mi_r, mi_c), false, block.skip);
@@ -8221,87 +8418,113 @@ fn write_inter_frame_leaf(
82218418
82228419 let mode_for_tx;
82238420 if let Some(info) = block.inter {
8224- write_comp_mode(enc, cdfs, neighbours, (mi_r, mi_c), (has_above, has_left), info.ref1.is_some());
8421+ write_comp_mode(
8422+ enc,
8423+ cdfs,
8424+ neighbours,
8425+ (mi_r, mi_c),
8426+ (has_above, has_left),
8427+ info.ref1.is_some(),
8428+ );
82258429 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
82268430 if info.ref1.is_some() {
82278431 let n = SUB_MI as usize;
82288432 let (mv, mv1, is_new_mv) = write_compound_block(
8229- enc, cdfs, neighbours, grid, (mi_row, mi_col), (n, n),
8230- (has_above, has_left), info, (mi_cols as usize, mi_rows as usize),
8433+ enc,
8434+ cdfs,
8435+ neighbours,
8436+ grid,
8437+ (mi_row, mi_col),
8438+ (n, n),
8439+ (has_above, has_left),
8440+ info,
8441+ (mi_cols as usize, mi_rows as usize),
82318442 )?;
82328443 for dr in 0..n {
82338444 for dc in 0..n {
8234- grid.set(mi_row + dr, mi_col + dc, MiInfo {
8235- is_inter: true,
8236- ref_frame: info.ref_frame,
8237- ref_frame1: info.ref1.unwrap_or(NO_REF1),
8238- mv1: mv16(mv1),
8239- mv: mv16(mv),
8240- is_new_mv,
8241- size: n as u8,
8242- size_h: n as u8,
8243- is_global_mv0: false,
8244- is_global_mv1: false,
8245- });
8445+ grid.set(
8446+ mi_row + dr,
8447+ mi_col + dc,
8448+ MiInfo {
8449+ is_inter: true,
8450+ ref_frame: info.ref_frame,
8451+ ref_frame1: info.ref1.unwrap_or(NO_REF1),
8452+ mv1: mv16(mv1),
8453+ mv: mv16(mv),
8454+ is_new_mv,
8455+ size: n as u8,
8456+ size_h: n as u8,
8457+ is_global_mv0: false,
8458+ is_global_mv1: false,
8459+ },
8460+ );
82468461 }
82478462 }
82488463 mode_for_tx = 0;
82498464 } else {
8250- write_single_ref(enc, cdfs, info.ref_frame, neighbours.above_ref[mi_c], neighbours.above_ref1[mi_c], neighbours.left_ref[mi_r], neighbours.left_ref1[mi_r]);
8465+ write_single_ref(
8466+ enc,
8467+ cdfs,
8468+ info.ref_frame,
8469+ neighbours.above_ref[mi_c],
8470+ neighbours.above_ref1[mi_c],
8471+ neighbours.left_ref[mi_r],
8472+ neighbours.left_ref1[mi_r],
8473+ );
82518474
8252- let stack = find_mv_stack(
8253- grid,
8254- mi_row,
8255- mi_col,
8256- SUB_MI as usize,
8257- SUB_MI as usize,
8258- info.ref_frame,
8259- mi_cols as usize,
8260- mi_rows as usize,
8261- );
8475+ let stack = find_mv_stack(
8476+ grid,
8477+ mi_row,
8478+ mi_col,
8479+ SUB_MI as usize,
8480+ SUB_MI as usize,
8481+ info.ref_frame,
8482+ mi_cols as usize,
8483+ mi_rows as usize,
8484+ );
82628485
8263- let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?;
8264- for dr in 0..SUB_MI as usize {
8265- for dc in 0..SUB_MI as usize {
8266- grid.set(
8267- mi_row + dr,
8268- mi_col + dc,
8269- MiInfo {
8270- is_inter: true,
8271- ref_frame: info.ref_frame,
8272- ref_frame1: NO_REF1,
8273- mv1: (0, 0),
8274- mv: mv16(mv),
8275- is_new_mv,
8276- size: SUB_MI as usize as u8,
8277- size_h: SUB_MI as usize as u8,
8278- is_global_mv0: false,
8279- is_global_mv1: false,
8280- },
8281- );
8486+ let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?;
8487+ for dr in 0..SUB_MI as usize {
8488+ for dc in 0..SUB_MI as usize {
8489+ grid.set(
8490+ mi_row + dr,
8491+ mi_col + dc,
8492+ MiInfo {
8493+ is_inter: true,
8494+ ref_frame: info.ref_frame,
8495+ ref_frame1: NO_REF1,
8496+ mv1: (0, 0),
8497+ mv: mv16(mv),
8498+ is_new_mv,
8499+ size: SUB_MI as usize as u8,
8500+ size_h: SUB_MI as usize as u8,
8501+ is_global_mv0: false,
8502+ is_global_mv1: false,
8503+ },
8504+ );
8505+ }
82828506 }
8283- }
8284- write_motion_mode(
8285- enc,
8286- cdfs,
8287- grid,
8288- (mi_row, mi_col),
8289- (SUB_MI as usize, SUB_MI as usize),
8290- (SUB, SUB),
8291- (mi_cols as usize, mi_rows as usize),
8292- info.ref_frame,
8293- block.motion_mode,
8294- )?;
8295- mode_for_tx = 0;
8507+ write_motion_mode(
8508+ enc,
8509+ cdfs,
8510+ grid,
8511+ (mi_row, mi_col),
8512+ (SUB_MI as usize, SUB_MI as usize),
8513+ (SUB, SUB),
8514+ (mi_cols as usize, mi_rows as usize),
8515+ info.ref_frame,
8516+ block.motion_mode,
8517+ )?;
8518+ mode_for_tx = 0;
82968519 }
82978520 } else {
82988521 let mode = usize::from(block.mode);
82998522 enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_16]);
83008523 if (V_PRED..=D67_PRED).contains(&mode) {
83018524 enc.symbol(
8302- (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8303- &mut cdfs.angle_delta[mode - V_PRED],
8304- );
8525+ (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8526+ &mut cdfs.angle_delta[mode - V_PRED],
8527+ );
83058528 }
83068529 let uv_mode = usize::from(block.uv_mode);
83078530 enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]);
@@ -8380,7 +8603,16 @@ fn write_inter_frame_leaf(
83808603 ];
83818604 if split {
83828605 write_luma_tus(
8383- enc, cdfs, neighbours, at_mi, SUB, tx, &grids[0], mode_for_tx, all_scans, is_inter,
8606+ enc,
8607+ cdfs,
8608+ neighbours,
8609+ at_mi,
8610+ SUB,
8611+ tx,
8612+ &grids[0],
8613+ mode_for_tx,
8614+ all_scans,
8615+ is_inter,
83848616 &block.luma_tx_types,
83858617 )?;
83868618 }
@@ -8467,93 +8699,122 @@ fn write_inter_frame_leaf8(
84678699 write_cdef_idx(enc, leaf_mi, block.skip);
84688700 write_delta_q(enc, cdfs, leaf_mi, false, block.skip);
84698701
8470- let (has_above, has_left) = (neighbours.has_above(leaf_mi.0), neighbours.has_left(leaf_mi.1));
8702+ let (has_above, has_left) = (
8703+ neighbours.has_above(leaf_mi.0),
8704+ neighbours.has_left(leaf_mi.1),
8705+ );
84718706 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
84728707 let is_inter = block.inter.is_some();
84738708 enc.symbol(usize::from(is_inter), &mut cdfs.intra_inter[ii_ctx]);
84748709
84758710 let mode_for_tx;
84768711 if let Some(info) = block.inter {
8477- write_comp_mode(enc, cdfs, neighbours, leaf_mi, (has_above, has_left), info.ref1.is_some());
8712+ write_comp_mode(
8713+ enc,
8714+ cdfs,
8715+ neighbours,
8716+ leaf_mi,
8717+ (has_above, has_left),
8718+ info.ref1.is_some(),
8719+ );
84788720 let (mi_row, mi_col) = leaf_mi;
84798721 if info.ref1.is_some() {
84808722 let (mv, mv1, is_new_mv) = write_compound_block(
8481- enc, cdfs, neighbours, grid, (mi_row, mi_col), (2, 2),
8482- (has_above, has_left), info, (mi_cols as usize, mi_rows as usize),
8723+ enc,
8724+ cdfs,
8725+ neighbours,
8726+ grid,
8727+ (mi_row, mi_col),
8728+ (2, 2),
8729+ (has_above, has_left),
8730+ info,
8731+ (mi_cols as usize, mi_rows as usize),
84838732 )?;
84848733 for dr in 0..2 {
84858734 for dc in 0..2 {
8486- grid.set(mi_row + dr, mi_col + dc, MiInfo {
8487- is_inter: true,
8488- ref_frame: info.ref_frame,
8489- ref_frame1: info.ref1.unwrap_or(NO_REF1),
8490- mv1: mv16(mv1),
8491- mv: mv16(mv),
8492- is_new_mv,
8493- size: 2,
8494- size_h: 2,
8495- is_global_mv0: false,
8496- is_global_mv1: false,
8497- });
8735+ grid.set(
8736+ mi_row + dr,
8737+ mi_col + dc,
8738+ MiInfo {
8739+ is_inter: true,
8740+ ref_frame: info.ref_frame,
8741+ ref_frame1: info.ref1.unwrap_or(NO_REF1),
8742+ mv1: mv16(mv1),
8743+ mv: mv16(mv),
8744+ is_new_mv,
8745+ size: 2,
8746+ size_h: 2,
8747+ is_global_mv0: false,
8748+ is_global_mv1: false,
8749+ },
8750+ );
84988751 }
84998752 }
85008753 mode_for_tx = 0;
85018754 } else {
8502- write_single_ref(enc, cdfs, info.ref_frame, neighbours.above_ref[leaf_mi.1], neighbours.above_ref1[leaf_mi.1], neighbours.left_ref[leaf_mi.0], neighbours.left_ref1[leaf_mi.0]);
8755+ write_single_ref(
8756+ enc,
8757+ cdfs,
8758+ info.ref_frame,
8759+ neighbours.above_ref[leaf_mi.1],
8760+ neighbours.above_ref1[leaf_mi.1],
8761+ neighbours.left_ref[leaf_mi.0],
8762+ neighbours.left_ref1[leaf_mi.0],
8763+ );
85038764
8504- let stack = find_mv_stack(
8505- grid,
8506- mi_row,
8507- mi_col,
8508- 2,
8509- 2,
8510- info.ref_frame,
8511- mi_cols as usize,
8512- mi_rows as usize,
8513- );
8765+ let stack = find_mv_stack(
8766+ grid,
8767+ mi_row,
8768+ mi_col,
8769+ 2,
8770+ 2,
8771+ info.ref_frame,
8772+ mi_cols as usize,
8773+ mi_rows as usize,
8774+ );
85148775
8515- let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?;
8516- for dr in 0..2 {
8517- for dc in 0..2 {
8518- grid.set(
8519- mi_row + dr,
8520- mi_col + dc,
8521- MiInfo {
8522- is_inter: true,
8523- ref_frame: info.ref_frame,
8524- ref_frame1: NO_REF1,
8525- mv1: (0, 0),
8526- mv: mv16(mv),
8527- is_new_mv,
8528- size: 2,
8529- size_h: 2,
8530- is_global_mv0: false,
8531- is_global_mv1: false,
8532- },
8533- );
8776+ let (mv, is_new_mv) = write_inter_mode(enc, cdfs, info, &stack)?;
8777+ for dr in 0..2 {
8778+ for dc in 0..2 {
8779+ grid.set(
8780+ mi_row + dr,
8781+ mi_col + dc,
8782+ MiInfo {
8783+ is_inter: true,
8784+ ref_frame: info.ref_frame,
8785+ ref_frame1: NO_REF1,
8786+ mv1: (0, 0),
8787+ mv: mv16(mv),
8788+ is_new_mv,
8789+ size: 2,
8790+ size_h: 2,
8791+ is_global_mv0: false,
8792+ is_global_mv1: false,
8793+ },
8794+ );
8795+ }
85348796 }
8535- }
8536- write_motion_mode(
8537- enc,
8538- cdfs,
8539- grid,
8540- (mi_row, mi_col),
8541- (2, 2),
8542- (8, 8),
8543- (mi_cols as usize, mi_rows as usize),
8544- info.ref_frame,
8545- block.motion_mode,
8546- )?;
8547- mode_for_tx = 0;
8797+ write_motion_mode(
8798+ enc,
8799+ cdfs,
8800+ grid,
8801+ (mi_row, mi_col),
8802+ (2, 2),
8803+ (8, 8),
8804+ (mi_cols as usize, mi_rows as usize),
8805+ info.ref_frame,
8806+ block.motion_mode,
8807+ )?;
8808+ mode_for_tx = 0;
85488809 }
85498810 } else {
85508811 let mode = usize::from(block.mode);
85518812 enc.symbol(mode, &mut cdfs.y_mode[SIZE_GROUP_8]);
85528813 if (V_PRED..=D67_PRED).contains(&mode) {
85538814 enc.symbol(
8554- (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8555- &mut cdfs.angle_delta[mode - V_PRED],
8556- );
8815+ (ANGLE_DELTA_ZERO as i32 + i32::from(block.angle_delta_y)) as usize,
8816+ &mut cdfs.angle_delta[mode - V_PRED],
8817+ );
85578818 }
85588819 let uv_mode = usize::from(block.uv_mode);
85598820 enc.symbol(uv_mode, &mut cdfs.uv_mode_cfl[mode]);
@@ -8606,7 +8867,7 @@ fn write_inter_frame_leaf8(
86068867 } else {
86078868 [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4]
86088869 };
8609- let tx = if tx_select {
8870+ let tx = if tx_select {
86108871 write_tx_syntax_inter(
86118872 enc,
86128873 cdfs,
@@ -8628,7 +8889,13 @@ fn write_inter_frame_leaf8(
86288889 vec![0i32; TX4 * TX4],
86298890 ];
86308891 neighbours.record_mi(leaf_mi, 8, &zero_grids);
8631- neighbours.record_inter_mi(leaf_mi, 8, block.skip, block.inter.is_some(), block_ref(block));
8892+ neighbours.record_inter_mi(
8893+ leaf_mi,
8894+ 8,
8895+ block.skip,
8896+ block.inter.is_some(),
8897+ block_ref(block),
8898+ );
86328899 record_block_compound(neighbours, leaf_mi, 8, block);
86338900 } else {
86348901 let grids = [
@@ -8638,7 +8905,16 @@ fn write_inter_frame_leaf8(
86388905 ];
86398906 if split {
86408907 write_luma_tus(
8641- enc, cdfs, neighbours, leaf_mi, 8, tx, &grids[0], mode_for_tx, all_scans, is_inter,
8908+ enc,
8909+ cdfs,
8910+ neighbours,
8911+ leaf_mi,
8912+ 8,
8913+ tx,
8914+ &grids[0],
8915+ mode_for_tx,
8916+ all_scans,
8917+ is_inter,
86428918 &block.luma_tx_types,
86438919 )?;
86448920 }
@@ -8669,8 +8945,8 @@ mod tests {
86698945 use crate::sequence::sequence_header_obu;
86708946 use ec_av1_syntax::sequence::SequenceHeader;
86718947 use ec_av1_syntax::{
8672- FrameHeader, FrameType, LoopFilterParams, PRIMARY_REF_NONE, QuantizationParams, TileInfo,
8673- TxMode,
8948+ FrameHeader, FrameType, LoopFilterParams, QuantizationParams, TileInfo, TxMode,
8949+ PRIMARY_REF_NONE,
86748950 };
86758951 use std::io::Write;
86768952 use std::process::{Command, Stdio};
@@ -10327,7 +10603,11 @@ mod tests {
1032710603 .map(|&v| {
1032810604 let m = f64::from(v).abs() + 0.5;
1032910605 let l = if m < 1.0 { 0 } else { m.floor() as i32 };
10330- if v < 0.0 { -l } else { l }
10606+ if v < 0.0 {
10607+ -l
10608+ } else {
10609+ l
10610+ }
1033110611 })
1033210612 .collect();
1033310613 let before = levels.clone();
@@ -10340,18 +10620,40 @@ mod tests {
1034010620 .zip(&scaled)
1034110621 .enumerate()
1034210622 .map(|(i, (&l, &s))| {
10343- (if i == 0 { dc_weight } else { 1.0 })
10344- * (f64::from(s) - f64::from(l)).powi(2)
10623+ (if i == 0 { dc_weight } else { 1.0 }) * (f64::from(s) - f64::from(l)).powi(2)
1034510624 })
1034610625 .sum();
1034710626 d + lambda * coeff_bits(grid, set, crate::decode::q_ctx_of(q), 0, 0)
1034810627 };
10349- let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct);
10350- assert_eq!(bits, coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0));
10351- assert!(cost(&levels) <= cost(&before), "{:?} vs {:?}", cost(&levels), cost(&before));
10628+ let bits = rdoq(
10629+ &mut levels,
10630+ &scaled,
10631+ side,
10632+ q,
10633+ set,
10634+ 0,
10635+ 0,
10636+ lambda,
10637+ TxType::DctDct,
10638+ );
10639+ assert_eq!(
10640+ bits,
10641+ coeff_bits(&levels, set, crate::decode::q_ctx_of(q), 0, 0)
10642+ );
10643+ assert!(
10644+ cost(&levels) <= cost(&before),
10645+ "{:?} vs {:?}",
10646+ cost(&levels),
10647+ cost(&before)
10648+ );
1035210649 // The tail is what it is for: the last coded position moves earlier.
1035310650 let last = |g: &[i32]| scan_of(side).iter().rposition(|&p| g[usize::from(p)] != 0);
10354- assert!(last(&levels) < last(&before), "eob {:?} -> {:?}", last(&before), last(&levels));
10651+ assert!(
10652+ last(&levels) < last(&before),
10653+ "eob {:?} -> {:?}",
10654+ last(&before),
10655+ last(&levels)
10656+ );
1035510657 // A 64-point transform is priced on its top-left 32x32 corner, and
1035610658 // the pass has to hand back THAT price (the dense path).
1035710659 let (side, set) = (64usize, TxbSet::Luma64);
@@ -10364,14 +10666,31 @@ mod tests {
1036410666 .map(|&v| {
1036510667 let m = f64::from(v).abs() + 0.5;
1036610668 let l = if m < 1.0 { 0 } else { m.floor() as i32 };
10367- if v < 0.0 { -l } else { l }
10669+ if v < 0.0 {
10670+ -l
10671+ } else {
10672+ l
10673+ }
1036810674 })
1036910675 .collect();
10370- let bits = rdoq(&mut levels, &scaled, side, q, set, 0, 0, lambda, TxType::DctDct);
10676+ let bits = rdoq(
10677+ &mut levels,
10678+ &scaled,
10679+ side,
10680+ q,
10681+ set,
10682+ 0,
10683+ 0,
10684+ lambda,
10685+ TxType::DctDct,
10686+ );
1037110687 let corner: Vec<i32> = (0..32)
1037210688 .flat_map(|row| levels[row * side..][..32].to_vec())
1037310689 .collect();
10374- assert_eq!(bits, coeff_bits(&corner, set, crate::decode::q_ctx_of(q), 0, 0));
10690+ assert_eq!(
10691+ bits,
10692+ coeff_bits(&corner, set, crate::decode::q_ctx_of(q), 0, 0)
10693+ );
1037510694 }
1037610695
1037710696 #[test]
@@ -10848,7 +11167,11 @@ mod tests {
1084811167 (d << 3) | (fr << 1) | 1
1084911168 };
1085011169 let mag = mv_class_base(class) + local as i32 + 1;
10851- if sign == 1 { -mag } else { mag }
11170+ if sign == 1 {
11171+ -mag
11172+ } else {
11173+ mag
11174+ }
1085211175 }
1085311176
1085411177 /// Decodes one superblock a [`sb_coeff_inter_frame_tile`] payload wrote,