wip(av1): inter chroma tx_type inherits colocated luma's coded type -- NOT COMPILING
Browse files at this commit74c4dbd67be06f75058691379844fdb4b3f890a5Parent: 3a8f2f21 changed file +48 -9
- crates/ec-av1/src/decode.rs +48 -9
crates/ec-av1/src/decode.rsmodified+48 -9
| @@ -2493,6 +2493,29 @@ fn cdef_filter_block( | |||
| 2493 | /// size. `cdef_bits == 0` is this crate's only supported case so far (see the | 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 | 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. | 2495 | /// strengths -- no per-block `cdef_idx` selection is implemented yet. |
| 2496 | +/// bisect scratch (lane-chromau): dump this frame's Y/U/V pre-deblock, mirrors | ||
| 2497 | +/// the instrumented `aomdec` build's `EC_AV1_PREFILT_DUMP` (raw | ||
| 2498 | +/// `true_width`x`true_height` bytes per plane, decode order, one file per | ||
| 2499 | +/// frame index). Zero-cost/zero-behavior off. Called from both the key-frame | ||
| 2500 | +/// and inter-frame tile decoders so the frame index lines up with aomdec's. | ||
| 2501 | +fn scratch_dump_prefilt(y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) { | ||
| 2502 | + let Some(base) = std::env::var_os("EC_AV1_PREFILT_DUMP_OURS") else { | ||
| 2503 | + return; | ||
| 2504 | + }; | ||
| 2505 | + use std::sync::atomic::{AtomicUsize, Ordering}; | ||
| 2506 | + static IDX: AtomicUsize = AtomicUsize::new(0); | ||
| 2507 | + let idx = IDX.fetch_add(1, Ordering::SeqCst); | ||
| 2508 | + let path = format!("{}.f{}", base.to_string_lossy(), idx); | ||
| 2509 | + let mut out = Vec::new(); | ||
| 2510 | + for plane in [y, u, v] { | ||
| 2511 | + for row in 0..plane.true_height { | ||
| 2512 | + let start = row * plane.width; | ||
| 2513 | + out.extend_from_slice(&plane.data[start..start + plane.true_width]); | ||
| 2514 | + } | ||
| 2515 | + } | ||
| 2516 | + let _ = std::fs::write(path, out); | ||
| 2517 | +} | ||
| 2518 | + | ||
| 2496 | /// Spec 7.14: the in-loop deblocking filter, applied once per frame after | 2519 | /// Spec 7.14: the in-loop deblocking filter, applied once per frame after |
| 2497 | /// tile reconstruction and before [`apply_cdef`]. Uniform-level path only -- | 2520 | /// tile reconstruction and before [`apply_cdef`]. Uniform-level path only -- |
| 2498 | /// `stream.rs` already refuses `delta_lf_present`/segmentation upstream, so | 2521 | /// `stream.rs` already refuses `delta_lf_present`/segmentation upstream, so |
| @@ -3596,6 +3619,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 3596 | } | 3619 | } |
| 3597 | } | 3620 | } |
| 3598 | 3621 | ||
| 3622 | + scratch_dump_prefilt(&y, &u, &v); | ||
| 3599 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | 3623 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); |
| 3600 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); | 3624 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 3601 | 3625 | ||
| @@ -3847,20 +3871,28 @@ fn read_inter_plane( | |||
| 3847 | side: usize, | 3871 | side: usize, |
| 3848 | base_q_idx: u8, | 3872 | base_q_idx: u8, |
| 3849 | prediction: &[u8], | 3873 | prediction: &[u8], |
| 3850 | -) -> Result<Vec<i32>> { | 3874 | + // lane-chromau: this block's own luma transform's *actual coded* |
| 3875 | + // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's | ||
| 3876 | + // chroma plane never codes its own `tx_type` symbol, but (unlike an | ||
| 3877 | + // intra block, which falls back to `Intra_Mode_To_Tx_Type`) it inherits | ||
| 3878 | + // the colocated luma transform's coded type verbatim, clamped back to | ||
| 3879 | + // `DCT_DCT` at the chroma tx sizes the spec forces DCT-only | ||
| 3880 | + // (`av1_get_ext_tx_set_type`: `tx_size_sqr_up >= TX_32X32`, i.e. this | ||
| 3881 | + // function's own `side >= 32`). `None` for the luma call itself | ||
| 3882 | + // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true | ||
| 3883 | + // `DCT_DCT` default at 32-point+) already resolves it without help. | ||
| 3884 | + inherited_luma_tx_type: Option<TxType>, | ||
| 3885 | +) -> Result<(Vec<i32>, TxType)> { | ||
| 3851 | let skip_ctx = if plane_idx == 0 { | 3886 | let skip_ctx = if plane_idx == 0 { |
| 3852 | 0 | 3887 | 0 |
| 3853 | } else { | 3888 | } else { |
| 3854 | usize::from(around.0) + usize::from(around.1) | 3889 | usize::from(around.0) + usize::from(around.1) |
| 3855 | }; | 3890 | }; |
| 3856 | let mut coding = cdfs.txb(set, tx_mode); | 3891 | let mut coding = cdfs.txb(set, tx_mode); |
| 3857 | - // `av1_get_tx_type` (libaom `blockd.h`): `Intra_Mode_To_Tx_Type` only | 3892 | + let default_tx_type = match inherited_luma_tx_type { |
| 3858 | - // ever applies to an intra block's chroma plane -- an `is_inter` block | 3893 | + Some(t) if side < 32 => t, |
| 3859 | - // (this function, [`read_inter_plane`], reads only those) has no | 3894 | + _ => TxType::DctDct, |
| 3860 | - // predicted intra mode to index it with, and its `tx_type` (luma or | 3895 | + }; |
| 3861 | - // chroma alike) is `DCT_DCT` whenever the `TxbSet` itself codes no | ||
| 3862 | - // symbol for it. | ||
| 3863 | - let default_tx_type = TxType::DctDct; | ||
| 3864 | let (grid, tx_type) = read_coeffs( | 3896 | let (grid, tx_type) = read_coeffs( |
| 3865 | dec, | 3897 | dec, |
| 3866 | &mut coding, | 3898 | &mut coding, |
| @@ -3870,8 +3902,14 @@ fn read_inter_plane( | |||
| 3870 | default_tx_type, | 3902 | default_tx_type, |
| 3871 | )?; | 3903 | )?; |
| 3872 | let residual = dequant_and_inverse_typed(&grid, side, 8, i32::from(base_q_idx), tx_type); | 3904 | let residual = dequant_and_inverse_typed(&grid, side, 8, i32::from(base_q_idx), tx_type); |
| 3905 | + if std::env::var_os("EC_AV1_CHROMA_TRACE").is_some() && x == 16 && y == 24 && plane_idx != 0 { | ||
| 3906 | + eprintln!( | ||
| 3907 | + "CHROMA_TRACE plane={plane_idx} x={x} y={y} side={side} tx_type={tx_type:?} \ | ||
| 3908 | + q_idx={base_q_idx} grid={grid:?} pred={prediction:?} residual={residual:?}" | ||
| 3909 | + ); | ||
| 3910 | + } | ||
| 3873 | plane.reconstruct_mc(x, y, side, prediction, &residual); | 3911 | plane.reconstruct_mc(x, y, side, prediction, &residual); |
| 3874 | - Ok(grid) | 3912 | + Ok((grid, tx_type)) |
| 3875 | } | 3913 | } |
| 3876 | 3914 | ||
| 3877 | /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode` | 3915 | /// Spec 5.11.25's `single_ref_p1`..`p6` tree (reachable only once `comp_mode` |
| @@ -6619,6 +6657,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 6619 | } | 6657 | } |
| 6620 | } | 6658 | } |
| 6621 | 6659 | ||
| 6660 | + scratch_dump_prefilt(&y, &u, &v); | ||
| 6622 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); | 6661 | apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours); |
| 6623 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); | 6662 | apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); |
| 6624 | 6663 | ||