forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-chromau': inter chroma inherits the colocated luma's coded tx_type

Browse files at this commit

30b983348e680a86e83a9af5bda27a318898f60eAhmet Kaan GümüşParent: 3a8f2f2752b1ef
libaom av1_get_tx_type: an inter block's chroma plane codes no tx_type
symbol of its own -- it inherits the colocated luma transform's coded
type verbatim (DCT_DCT clamp at tx_size_sqr_up >= TX_32X32). Our
DCT_DCT default gave a wrong inverse-transform basis on chroma
residuals: delta-1 chroma-U mismatch on the pinned seed-45 stream,
now 4/4 frames all-plane byte-exact.
crates/ec-av1/src/decode.rsmodified+53 -26
@@ -2488,11 +2488,6 @@ fn cdef_filter_block(
24882488 }
24892489 }
24902490
2491-/// Applies CDEF (spec 7.15) to the whole reconstructed frame, over its true
2492-/// (unpadded) `mi_cols`/`mi_rows` extent, before it is cropped to its display
2493-/// size. `cdef_bits == 0` is this crate's only supported case so far (see the
2494-/// refusal in `stream.rs`), so every 64x64 filter block always uses index 0's
2495-/// strengths -- no per-block `cdef_idx` selection is implemented yet.
24962491 /// Spec 7.14: the in-loop deblocking filter, applied once per frame after
24972492 /// tile reconstruction and before [`apply_cdef`]. Uniform-level path only --
24982493 /// `stream.rs` already refuses `delta_lf_present`/segmentation upstream, so
@@ -3847,20 +3842,28 @@ fn read_inter_plane(
38473842 side: usize,
38483843 base_q_idx: u8,
38493844 prediction: &[u8],
3850-) -> Result<Vec<i32>> {
3845+ // lane-chromau: this block's own luma transform's *actual coded*
3846+ // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's
3847+ // chroma plane never codes its own `tx_type` symbol, but (unlike an
3848+ // intra block, which falls back to `Intra_Mode_To_Tx_Type`) it inherits
3849+ // the colocated luma transform's coded type verbatim, clamped back to
3850+ // `DCT_DCT` at the chroma tx sizes the spec forces DCT-only
3851+ // (`av1_get_ext_tx_set_type`: `tx_size_sqr_up >= TX_32X32`, i.e. this
3852+ // function's own `side >= 32`). `None` for the luma call itself
3853+ // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true
3854+ // `DCT_DCT` default at 32-point+) already resolves it without help.
3855+ inherited_luma_tx_type: Option<TxType>,
3856+) -> Result<(Vec<i32>, TxType)> {
38513857 let skip_ctx = if plane_idx == 0 {
38523858 0
38533859 } else {
38543860 usize::from(around.0) + usize::from(around.1)
38553861 };
38563862 let mut coding = cdfs.txb(set, tx_mode);
3857- // `av1_get_tx_type` (libaom `blockd.h`): `Intra_Mode_To_Tx_Type` only
3858- // ever applies to an intra block's chroma plane -- an `is_inter` block
3859- // (this function, [`read_inter_plane`], reads only those) has no
3860- // predicted intra mode to index it with, and its `tx_type` (luma or
3861- // chroma alike) is `DCT_DCT` whenever the `TxbSet` itself codes no
3862- // symbol for it.
3863- let default_tx_type = TxType::DctDct;
3863+ let default_tx_type = match inherited_luma_tx_type {
3864+ Some(t) if side < 32 => t,
3865+ _ => TxType::DctDct,
3866+ };
38643867 let (grid, tx_type) = read_coeffs(
38653868 dec,
38663869 &mut coding,
@@ -3871,7 +3874,7 @@ fn read_inter_plane(
38713874 )?;
38723875 let residual = dequant_and_inverse_typed(&grid, side, 8, i32::from(base_q_idx), tx_type);
38733876 plane.reconstruct_mc(x, y, side, prediction, &residual);
3874- Ok(grid)
3877+ Ok((grid, tx_type))
38753878 }
38763879
38773880 /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode`
@@ -4836,7 +4839,8 @@ fn decode_inter_block(
48364839 v_grid = vec![0i32; chroma_side * chroma_side];
48374840 } else {
48384841 let around = neighbours.around(at, side);
4839- luma_grid = read_inter_plane(
4842+ let luma_tx_type;
4843+ (luma_grid, luma_tx_type) = read_inter_plane(
48404844 dec,
48414845 cdfs,
48424846 luma_set_inter,
@@ -4850,6 +4854,7 @@ fn decode_inter_block(
48504854 side,
48514855 base_q_idx,
48524856 &pred_y,
4857+ None,
48534858 )?;
48544859 u_grid = read_inter_plane(
48554860 dec,
@@ -4865,7 +4870,9 @@ fn decode_inter_block(
48654870 chroma_side,
48664871 base_q_idx,
48674872 &pred_u,
4868- )?;
4873+ Some(luma_tx_type),
4874+ )?
4875+ .0;
48694876 v_grid = read_inter_plane(
48704877 dec,
48714878 cdfs,
@@ -4880,7 +4887,9 @@ fn decode_inter_block(
48804887 chroma_side,
48814888 base_q_idx,
48824889 &pred_v,
4883- )?;
4890+ Some(luma_tx_type),
4891+ )?
4892+ .0;
48844893 }
48854894 } else {
48864895 let ref_frame =
@@ -5128,7 +5137,8 @@ fn decode_inter_block(
51285137 v_grid = vec![0i32; chroma_side * chroma_side];
51295138 } else {
51305139 let around = neighbours.around(at, side);
5131- luma_grid = read_inter_plane(
5140+ let luma_tx_type;
5141+ (luma_grid, luma_tx_type) = read_inter_plane(
51325142 dec,
51335143 cdfs,
51345144 luma_set_inter,
@@ -5142,6 +5152,7 @@ fn decode_inter_block(
51425152 side,
51435153 base_q_idx,
51445154 &pred_y,
5155+ None,
51455156 )?;
51465157 u_grid = read_inter_plane(
51475158 dec,
@@ -5157,7 +5168,9 @@ fn decode_inter_block(
51575168 chroma_side,
51585169 base_q_idx,
51595170 &pred_u,
5160- )?;
5171+ Some(luma_tx_type),
5172+ )?
5173+ .0;
51615174 v_grid = read_inter_plane(
51625175 dec,
51635176 cdfs,
@@ -5172,7 +5185,9 @@ fn decode_inter_block(
51725185 chroma_side,
51735186 base_q_idx,
51745187 &pred_v,
5175- )?;
5188+ Some(luma_tx_type),
5189+ )?
5190+ .0;
51765191 }
51775192 }
51785193 } else {
@@ -5726,7 +5741,8 @@ fn decode_inter_block8(
57265741 v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
57275742 } else {
57285743 let around = neighbours.around_mi(leaf_mi, 8);
5729- luma_grid = read_inter_plane(
5744+ let luma_tx_type;
5745+ (luma_grid, luma_tx_type) = read_inter_plane(
57305746 dec,
57315747 cdfs,
57325748 if reduced_tx_set {
@@ -5744,6 +5760,7 @@ fn decode_inter_block8(
57445760 SIDE,
57455761 base_q_idx,
57465762 &pred_y,
5763+ None,
57475764 )?;
57485765 u_grid = read_inter_plane(
57495766 dec,
@@ -5759,7 +5776,9 @@ fn decode_inter_block8(
57595776 CHROMA_SIDE,
57605777 base_q_idx,
57615778 &pred_u,
5762- )?;
5779+ Some(luma_tx_type),
5780+ )?
5781+ .0;
57635782 v_grid = read_inter_plane(
57645783 dec,
57655784 cdfs,
@@ -5774,7 +5793,9 @@ fn decode_inter_block8(
57745793 CHROMA_SIDE,
57755794 base_q_idx,
57765795 &pred_v,
5777- )?;
5796+ Some(luma_tx_type),
5797+ )?
5798+ .0;
57785799 }
57795800 return Ok((skip, is_inter, skip_mode, compound_ctx8));
57805801 }
@@ -5924,7 +5945,8 @@ fn decode_inter_block8(
59245945 v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
59255946 } else {
59265947 let around = neighbours.around_mi(leaf_mi, 8);
5927- luma_grid = read_inter_plane(
5948+ let luma_tx_type;
5949+ (luma_grid, luma_tx_type) = read_inter_plane(
59285950 dec,
59295951 cdfs,
59305952 if reduced_tx_set {
@@ -5942,6 +5964,7 @@ fn decode_inter_block8(
59425964 SIDE,
59435965 base_q_idx,
59445966 &pred_y,
5967+ None,
59455968 )?;
59465969 u_grid = read_inter_plane(
59475970 dec,
@@ -5957,7 +5980,9 @@ fn decode_inter_block8(
59575980 CHROMA_SIDE,
59585981 base_q_idx,
59595982 &pred_u,
5960- )?;
5983+ Some(luma_tx_type),
5984+ )?
5985+ .0;
59615986 v_grid = read_inter_plane(
59625987 dec,
59635988 cdfs,
@@ -5972,7 +5997,9 @@ fn decode_inter_block8(
59725997 CHROMA_SIDE,
59735998 base_q_idx,
59745999 &pred_v,
5975- )?;
6000+ Some(luma_tx_type),
6001+ )?
6002+ .0;
59766003 }
59776004 } else {
59786005 let mode = dec.symbol(&mut cdfs.y_mode[SIZE_GROUP_8]);