From f66f359057272bb8896eee8fd935f7856f0c52aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 21:58:39 +0300 Subject: [PATCH] feat(av1): inter var-tx (TxMode::Select) read + per-TU residual; blanket inter refusal lifted spec 5.11.17 read_block_tx_size/read_var_tx_size, libaom decodeframe.c read_tx_size_vartx: an inter block's transform size is now the recursive txfm_split tree from its max square transform down to MAX_VARTX_DEPTH=2, with the above/left TXFM_CONTEXT arrays maintained per transform unit (txfm_partition_update) and per block (set_txfm_ctxs; a skipped inter block records its BLOCK size, not its transform size). Coefficients are read and reconstructed leaf by leaf in the tree's own order, each unit against its own slice of the motion-compensated predictor and its own txb_skip context; chroma keeps the block's uv transform and inherits the top-left unit's coded tx_type. - decode.rs: read_block_tx_size/read_var_tx_size/txfm_partition_ctx/ txfm_partition_update/set_txfm_ctxs, TXFM_SPLIT_READS/HITS counters, Neighbours::above_txfm/left_txfm, wired into both decode_inter_block residual branches and (new this round) all three decode_inter_block8 branches via read_inter_luma8. - TXFM_CTX_INIT = 64, not 0: av1_zero_above_context memsets the txfm row to tx_size_wide[TX_SIZES_LARGEST] and av1_zero_left_context to tx_size_high[TX_SIZES_LARGEST] (av1_common_int.h:1624/1632). The WIP's zero-init was a false premise and desynced frame 2 of the gate. - cdf.rs/cdf_state.rs: TXFM_PARTITION (21 contexts) in the table set, adaptation and the per-frame counter reset; Luma4Inter/Luma4InterSet1 coefficient sets for a var-tx tree that reaches 4x4. - stream.rs: the blanket "an inter frame using TxMode::Select" refusal is gone; what remains refused is named at its own site (a var-tx leaf larger than 32x32; an intra block in an inter frame whose tx_depth splits). New gate a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact -- the aomenc recipe WITHOUT --enable-tx-size-search=0, hard-asserting both txfm_split counters and panicking (never SKIPping) when nothing fires. - refusal_inventory.rs: -1 blanket refusal, +2 narrow ones. Gate is RED at frame 2 (see lanes/txselect-r1.report.md): key frame + first inter frame decode pixel-exact with 8 splits taken, frame 2 diverges. --- crates/ec-av1/src/cdf.rs | 35 +- crates/ec-av1/src/decode.rs | 5001 +++++++++++++----------- crates/ec-av1/src/encode.rs | 65 +- crates/ec-av1/src/encoder.rs | 10 +- crates/ec-av1/src/gate_coverage.rs | 37 +- crates/ec-av1/src/intra.rs | 13 +- crates/ec-av1/src/lib.rs | 2 +- crates/ec-av1/src/mc.rs | 9 +- crates/ec-av1/src/motion.rs | 9 +- crates/ec-av1/src/mvstack.rs | 134 +- crates/ec-av1/src/quant.rs | 10 +- crates/ec-av1/src/refusal_inventory.rs | 23 +- crates/ec-av1/src/restoration.rs | 178 +- crates/ec-av1/src/stream.rs | 790 +++- crates/ec-av1/src/superres.rs | 14 +- crates/ec-av1/src/transform.rs | 12 +- crates/ec-av1/src/warp.rs | 31 +- crates/ec-av1/src/wedge.rs | 32 +- 18 files changed, 3869 insertions(+), 2536 deletions(-) diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index 551eed43..da3ad71b 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -277,21 +277,16 @@ pub const EOB_PT_512_LUMA_Q3: [u16; 11] = [ /// coded positions -- what a true 16x8/8x16 rectangular transform has /// (`txsize_log2_minus4` = 3), distinct from [`EOB_PT_256_CHROMA`]'s /// 256-position group a *square* 16x16 reads. -pub const EOB_PT_128_CHROMA: [u16; 9] = [ - 13627, 16246, 20173, 24429, 27948, 30415, 31863, 32768, 0, -]; +pub const EOB_PT_128_CHROMA: [u16; 9] = [13627, 16246, 20173, 24429, 27948, 30415, 31863, 32768, 0]; /// [`EOB_PT_128_CHROMA`], q-context 0. -pub const EOB_PT_128_CHROMA_Q0: [u16; 9] = [ - 5245, 7456, 12880, 15852, 20033, 23932, 27608, 32768, 0, -]; +pub const EOB_PT_128_CHROMA_Q0: [u16; 9] = + [5245, 7456, 12880, 15852, 20033, 23932, 27608, 32768, 0]; /// [`EOB_PT_128_CHROMA`], q-context 1. -pub const EOB_PT_128_CHROMA_Q1: [u16; 9] = [ - 8045, 11200, 15497, 19595, 23948, 27408, 30938, 32768, 0, -]; +pub const EOB_PT_128_CHROMA_Q1: [u16; 9] = + [8045, 11200, 15497, 19595, 23948, 27408, 30938, 32768, 0]; /// [`EOB_PT_128_CHROMA`], q-context 3. -pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [ - 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, -]; +pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = + [24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0]; /// `av1_default_eob_multi512_cdfs[*][1][*]` (`token_cdfs.h:874-901`, /// lane-sbpart): the end-of-block group of a CHROMA transform with 512 coded @@ -1656,20 +1651,20 @@ pub const WEDGE_IDX: [[u16; 17]; 22] = [ 29629, 32768, 0, ], [ - 2779, 3738, 4683, 7213, 7775, 8017, 8655, 14357, 17939, 21332, 24520, 27470, 29456, - 30529, 31656, 32768, 0, + 2779, 3738, 4683, 7213, 7775, 8017, 8655, 14357, 17939, 21332, 24520, 27470, 29456, 30529, + 31656, 32768, 0, ], [ 1684, 3625, 5675, 7108, 9302, 11274, 14429, 17144, 19163, 20961, 22884, 24471, 26719, 28714, 30877, 32768, 0, ], [ - 1142, 3491, 6277, 7314, 8089, 8355, 9023, 13624, 15369, 16730, 18114, 19313, 22521, - 26012, 29550, 32768, 0, + 1142, 3491, 6277, 7314, 8089, 8355, 9023, 13624, 15369, 16730, 18114, 19313, 22521, 26012, + 29550, 32768, 0, ], [ - 2742, 4195, 5727, 8035, 8980, 9336, 10146, 14124, 17270, 20533, 23434, 25972, 27944, - 29570, 31416, 32768, 0, + 2742, 4195, 5727, 8035, 8980, 9336, 10146, 14124, 17270, 20533, 23434, 25972, 27944, 29570, + 31416, 32768, 0, ], [ 1727, 3948, 6101, 7796, 9841, 12344, 15766, 18944, 20638, 22038, 23963, 25311, 26988, @@ -1712,8 +1707,8 @@ pub const WEDGE_IDX: [[u16; 17]; 22] = [ 30911, 32768, 0, ], [ - 1135, 1322, 1493, 2635, 2696, 2737, 2770, 21016, 22935, 25057, 27251, 29173, 30089, - 30960, 31933, 32768, 0, + 1135, 1322, 1493, 2635, 2696, 2737, 2770, 21016, 22935, 25057, 27251, 29173, 30089, 30960, + 31933, 32768, 0, ], [ 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480, 22528, 24576, 26624, diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index c06b0880..b1c29a0c 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -21,9 +21,7 @@ //! too). Anything outside that refuses with [`Error::unsupported`] rather than //! silently miscoding. -use ec_av1_syntax::{ - CdefParams, DeltaParams, LoopFilterParams, LoopRestorationParams, TileInfo, -}; +use ec_av1_syntax::{CdefParams, DeltaParams, LoopFilterParams, LoopRestorationParams, TileInfo}; use ec_core::{Error, Result}; use crate::cdf; @@ -199,7 +197,14 @@ fn plane_q_delta(plane_idx: usize) -> (i32, i32) { /// top-left leaf is the only block that can ever land there), or when that /// leaf both *is* the whole superblock and is `skip` (the one case libaom /// itself skips the read, state carrying over unchanged). -fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, is_whole_sb: bool, skip: bool) { +fn maybe_read_delta_q( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + mi_r: usize, + mi_c: usize, + is_whole_sb: bool, + skip: bool, +) { if !DELTA_Q_PRESENT.with(|c| c.get()) { return; } @@ -254,7 +259,14 @@ pub(crate) fn delta_lf_hits() -> usize { /// [`maybe_read_delta_q`] (spec order `delta_q -> delta_lf`), looped over /// `FRAME_LF_COUNT = 4` planes/directions when `delta_lf_multi` is set, or /// read once into index 0 otherwise. -fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, is_whole_sb: bool, skip: bool) { +fn maybe_read_delta_lf( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + mi_r: usize, + mi_c: usize, + is_whole_sb: bool, + skip: bool, +) { if !DELTA_LF_PRESENT.with(|c| c.get()) { return; } @@ -370,8 +382,7 @@ thread_local! { /// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`, /// mirroring stream.rs's `pictures_decoded` so the two dumps index /// identically against aomdec's own `ec_frame_idx` in decodeframe.c. -static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = - std::sync::atomic::AtomicUsize::new(0); +static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); /// Current value of [`DEBLOCK_HITS`]. pub(crate) fn deblock_hits() -> usize { @@ -1186,33 +1197,33 @@ fn br_ctx(grid: &[i32], side: usize, row: usize, col: usize, class: TxClass) -> /// against the real table). Not the square zigzag formula generalized to /// unequal `w`/`h` -- checked and that does NOT reproduce this table. const SCAN_32X16: [u16; 512] = [ - 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, - 130, 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39, - 8, 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72, - 41, 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229, - 198, 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44, - 13, 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418, - 387, 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326, - 295, 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234, - 203, 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142, - 111, 80, 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19, - 485, 454, 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424, - 393, 362, 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332, - 301, 270, 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240, - 209, 178, 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148, - 117, 86, 55, 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25, - 491, 460, 429, 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430, - 399, 368, 337, 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338, - 307, 276, 245, 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246, - 215, 184, 153, 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154, - 123, 92, 61, 30, 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31, - 497, 466, 435, 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405, - 374, 343, 312, 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251, - 220, 189, 158, 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439, - 408, 377, 346, 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503, - 472, 441, 410, 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443, - 412, 381, 350, 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415, - 509, 478, 447, 510, 479, 511, + 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130, + 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39, 8, + 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72, 41, + 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229, 198, + 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44, 13, + 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418, 387, + 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326, 295, + 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234, 203, + 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142, 111, 80, + 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19, 485, 454, + 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424, 393, 362, + 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332, 301, 270, + 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240, 209, 178, + 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148, 117, 86, 55, + 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25, 491, 460, 429, + 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430, 399, 368, 337, + 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338, 307, 276, 245, + 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246, 215, 184, 153, + 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154, 123, 92, 61, 30, + 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31, 497, 466, 435, + 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405, 374, 343, 312, + 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251, 220, 189, 158, + 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439, 408, 377, 346, + 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503, 472, 441, 410, + 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443, 412, 381, 350, + 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415, 509, 478, 447, + 510, 479, 511, ]; /// `Default_Scan_16x32`, this decoder's own row-major transcription (see @@ -1316,7 +1327,11 @@ fn br_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usiz if row == 0 && col == 0 { return mag; } - if row < 2 && col < 2 { mag + 7 } else { mag + 14 } + if row < 2 && col < 2 { + mag + 7 + } else { + mag + 14 + } } fn dc_vote(dc: Option) -> i32 { @@ -1472,7 +1487,9 @@ fn read_coeffs( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}", - all_zero as u8, dec.debug_bitpos(), dec.debug_state().0 + all_zero as u8, + dec.debug_bitpos(), + dec.debug_state().0 ); } if trace { @@ -1611,7 +1628,10 @@ fn read_coeffs( }; if ec_trace_coeff { let (rng, _) = dec.debug_state(); - eprintln!("EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}", negative as i32); + eprintln!( + "EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}", + negative as i32 + ); } let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL { let g = read_golomb(dec)?; @@ -1796,10 +1816,10 @@ struct Neighbours { /// 4x4 mi granularity: the transform *width* (above) / *height* (left) in /// pixels last written over each unit by `set_txfm_ctxs`/ /// `txfm_partition_update`, which is what an inter block's `txfm_split` - /// symbol reads its context from (lane-txselect, spec 5.11.17). Zero - /// (libaom's own tile-start value) until a block writes one; a fresh - /// full-height `left` array is exactly libaom's per-superblock-row reset, - /// since each mi row is only ever visited inside one superblock row. + /// symbol reads its context from (lane-txselect, spec 5.11.17). + /// [`TXFM_CTX_INIT`] until a block writes one; a fresh full-height `left` + /// array is exactly libaom's per-superblock-row reset, since each mi row + /// is only ever visited inside one superblock row. above_txfm: Vec, left_txfm: Vec, /// Whether the block above/left of this column/row coded `skip_mode` @@ -1924,8 +1944,8 @@ impl Neighbours { left_side_mi: vec![SB; rows * (SUB / MI)], above_skip: vec![false; cols], left_skip: vec![false; rows], - above_txfm: vec![0u8; cols * (SUB / MI)], - left_txfm: vec![0u8; rows * (SUB / MI)], + above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)], + left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)], above_skip_mode: vec![false; cols], left_skip_mode: vec![false; rows], above_inter: vec![false; cols], @@ -2064,7 +2084,13 @@ impl Neighbours { /// As [`Self::record_palette_y`], for a just-decoded block's own chroma /// (U-channel) palette size/colours -- `size == 0` clears stale state the /// same way (lane-palette2 r1). - fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) { + fn record_palette_uv( + &mut self, + at: (usize, usize), + side: usize, + size: usize, + colors: [u16; 8], + ) { let (r, c) = at; for cell in 0..side / SUB { self.above_palette_uv_size[c + cell] = size; @@ -2085,7 +2111,10 @@ impl Neighbours { let (r, c) = at; let above_ok = r % 4 != 0; let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 { - (self.above_palette_uv_size[c], self.above_palette_uv_colors[c]) + ( + self.above_palette_uv_size[c], + self.above_palette_uv_colors[c], + ) } else { (0, [0u16; 8]) }; @@ -2419,7 +2448,12 @@ impl Neighbours { /// [`Self::around_rect`] taking the block's position directly in 4x4 /// mode-info units, mirroring [`Self::around_mi`]. - fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] { + fn around_mi_rect( + &self, + (mi_r, mi_c): (usize, usize), + w: usize, + h: usize, + ) -> [(bool, bool, i32); 3] { let (w_mi, h_mi) = (w / MI, h / MI); std::array::from_fn(|plane| { let mut above_coded = false; @@ -2518,13 +2552,7 @@ impl Neighbours { /// [`Self::record_mi`] with independent above (`w`)/left (`h`) extents, /// in pixels (lane-partitions r1, mirroring [`Self::record_rect`]). - fn record_mi_rect( - &mut self, - at_mi: (usize, usize), - w: usize, - h: usize, - grids: &[Vec; 3], - ) { + fn record_mi_rect(&mut self, at_mi: (usize, usize), w: usize, h: usize, grids: &[Vec; 3]) { let (mi_r, mi_c) = at_mi; let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane])); let (w_mi, h_mi) = (w / MI, h / MI); @@ -2720,7 +2748,11 @@ struct PaletteUv { /// `get_unsigned_bits`, which is the same formula): smallest `n` with /// `2^n >= x`, `0` for `x <= 1`. fn ceil_log2(x: u32) -> u32 { - if x < 2 { 0 } else { 32 - (x - 1).leading_zeros() } + if x < 2 { + 0 + } else { + 32 - (x - 1).leading_zeros() + } } /// `av1_read_uniform` (decoder.h:425): a uniform `0..n` value coded as @@ -2807,7 +2839,11 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> [u /// side by side). V never uses a cache: a leading bit picks either `n` raw /// literals, or a first raw value plus `n-1` signed deltas that wrap mod 256 /// rather than clamp. -fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16]) -> ([u16; 8], [u16; 8]) { +fn read_palette_colors_uv( + dec: &mut SymbolDecoder, + n: usize, + cache: &[u16], +) -> ([u16; 8], [u16; 8]) { let mut cached = Vec::with_capacity(n); for &c in cache { if cached.len() >= n { @@ -2887,13 +2923,21 @@ fn palette_color_index_context( col: usize, n: usize, ) -> (usize, [u8; 8]) { - let left = if col >= 1 { Some(map[row * side + col - 1]) } else { None }; + let left = if col >= 1 { + Some(map[row * side + col - 1]) + } else { + None + }; let up_left = if col >= 1 && row >= 1 { Some(map[(row - 1) * side + col - 1]) } else { None }; - let up = if row >= 1 { Some(map[(row - 1) * side + col]) } else { None }; + let up = if row >= 1 { + Some(map[(row - 1) * side + col]) + } else { + None + }; let mut scores = [0i32; 8]; for (neighbour, weight) in [(left, 2), (up_left, 1), (up, 2)] { if let Some(v) = neighbour { @@ -3366,128 +3410,135 @@ fn decode_block_rect( // --enable-tx-size-search=0 the encoder writes no such symbol, so the // decoder consumed one that was never there. { - let around = neighbours.around_rect(at, bw, bh); - let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); - let (luma_levels, luma_tx_type) = read_coeffs_rect( - dec, - &mut luma_coding, - luma_scan, - bw, - bh, - 0, - dc_sign_ctx(around[0].2), - TxType::DctDct, - )?; - if std::env::var_os("EC_AV1_TRACE").is_some() { - let (rng, _) = dec.debug_state(); - eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}"); - } - let luma_residual = dequant_and_inverse_typed_wh( - &luma_levels, - bw, - bh, - crate::decode::bit_depth(), - CURRENT_Q_IDX.with(|c| c.get()), - plane_q_delta(0).0, - plane_q_delta(0).1, - luma_tx_type, - ); - y.reconstruct_rect( - px, - py, - bw, - bh, - mode, - angle_delta_y, - reach, - &luma_residual, - None, - filter_intra, - smooth_neighbor, - ); - let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); - let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); - let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); - let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); - let (u_levels, u_tx_type) = read_coeffs_rect( - dec, - &mut u_coding, - chroma_scan, - chroma_w, - chroma_h, - u_skip_ctx, - dc_sign_ctx(around[1].2), - u_default_tx, - )?; - if std::env::var_os("EC_AV1_TRACE").is_some() { - let (rng, _) = dec.debug_state(); - eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}"); - } - let u_residual = dequant_and_inverse_typed_wh( - &u_levels, - chroma_w, - chroma_h, - crate::decode::bit_depth(), - CURRENT_Q_IDX.with(|c| c.get()), - plane_q_delta(1).0, - plane_q_delta(1).1, - u_tx_type, - ); - u.reconstruct_rect( - cpx, - cpy, - chroma_w, - chroma_h, - uv_predict_mode, - angle_delta_uv, - reach, - &u_residual, - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), - None, - smooth_neighbor_uv, - ); - let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); - let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); - let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); - let (v_levels, v_tx_type) = read_coeffs_rect( - dec, - &mut v_coding, - chroma_scan, - chroma_w, - chroma_h, - v_skip_ctx, - dc_sign_ctx(around[2].2), - v_default_tx, - )?; - if std::env::var_os("EC_AV1_TRACE").is_some() { - let (rng, _) = dec.debug_state(); - eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}"); - } - let v_residual = dequant_and_inverse_typed_wh( - &v_levels, - chroma_w, - chroma_h, - crate::decode::bit_depth(), - CURRENT_Q_IDX.with(|c| c.get()), - plane_q_delta(2).0, - plane_q_delta(2).1, - v_tx_type, - ); - v.reconstruct_rect( - cpx, - cpy, - chroma_w, - chroma_h, - uv_predict_mode, - angle_delta_uv, - reach, - &v_residual, - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), - None, - smooth_neighbor_uv, - ); - neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]); - RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); + let around = neighbours.around_rect(at, bw, bh); + let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); + let (luma_levels, luma_tx_type) = read_coeffs_rect( + dec, + &mut luma_coding, + luma_scan, + bw, + bh, + 0, + dc_sign_ctx(around[0].2), + TxType::DctDct, + )?; + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } + let luma_residual = dequant_and_inverse_typed_wh( + &luma_levels, + bw, + bh, + crate::decode::bit_depth(), + CURRENT_Q_IDX.with(|c| c.get()), + plane_q_delta(0).0, + plane_q_delta(0).1, + luma_tx_type, + ); + y.reconstruct_rect( + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &luma_residual, + None, + filter_intra, + smooth_neighbor, + ); + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); + let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); + let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); + let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); + let (u_levels, u_tx_type) = read_coeffs_rect( + dec, + &mut u_coding, + chroma_scan, + chroma_w, + chroma_h, + u_skip_ctx, + dc_sign_ctx(around[1].2), + u_default_tx, + )?; + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } + let u_residual = dequant_and_inverse_typed_wh( + &u_levels, + chroma_w, + chroma_h, + crate::decode::bit_depth(), + CURRENT_Q_IDX.with(|c| c.get()), + plane_q_delta(1).0, + plane_q_delta(1).1, + u_tx_type, + ); + u.reconstruct_rect( + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &u_residual, + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, + ); + let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); + let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); + let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); + let (v_levels, v_tx_type) = read_coeffs_rect( + dec, + &mut v_coding, + chroma_scan, + chroma_w, + chroma_h, + v_skip_ctx, + dc_sign_ctx(around[2].2), + v_default_tx, + )?; + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } + let v_residual = dequant_and_inverse_typed_wh( + &v_levels, + chroma_w, + chroma_h, + crate::decode::bit_depth(), + CURRENT_Q_IDX.with(|c| c.get()), + plane_q_delta(2).0, + plane_q_delta(2).1, + v_tx_type, + ); + v.reconstruct_rect( + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &v_residual, + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, + ); + neighbours.record_rect( + at, + bw, + bh, + mode, + uv_predict_mode, + &[luma_levels, u_levels, v_levels], + ); + RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); } } neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); @@ -3546,8 +3597,7 @@ fn decode_leaf_rect( left_mode = pmode; } } - let smooth_neighbor = - is_smooth_mode(above_mode) || is_smooth_mode(left_mode); + let smooth_neighbor = is_smooth_mode(above_mode) || is_smooth_mode(left_mode); if smooth_neighbor { SMOOTH_LUMA_HITS.with(|c| c.set(c.get() + 1)); } @@ -3571,7 +3621,11 @@ fn decode_leaf_rect( "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", )); } - let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + let uv_predict_mode = if uv_mode == UV_CFL_PRED { + DC_PRED + } else { + uv_mode + }; let depth = if tx_select { let ctx = tx_size_context_rect(neighbours, leaf_mi, bw, bh); dec.symbol(&mut cdfs.tx_size_cat2[ctx]) @@ -3862,7 +3916,9 @@ fn decode_block_rect64( ); if std::env::var_os("EC_SBPART_DUMP64").is_some() { let leftcol: Vec = if px > 0 { - (py..py + bh).map(|row| y.data[row * y.width + px - 1]).collect() + (py..py + bh) + .map(|row| y.data[row * y.width + px - 1]) + .collect() } else { vec![] }; @@ -3986,7 +4042,14 @@ fn decode_block_rect64( None, smooth_neighbor_uv, ); - neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]); + neighbours.record_rect( + at, + bw, + bh, + mode, + uv_predict_mode, + &[luma_levels, u_levels, v_levels], + ); RECT_COEFF_HITS.with(|c| c.set(c.get() + 1)); } neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); @@ -4179,9 +4242,7 @@ fn read_intra_mode( // `decode_color_index_map` call). let mut palette_y_pending: Option<(usize, [u16; 8])> = None; let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; - if allow_screen_content_tools - && let Some(bsize_ctx) = palette_bsize_ctx(side) - { + if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx(side) { let (mode_ctx, cache) = palette.unwrap_or((0, &[])); if mode == DC_PRED { if trace { @@ -4195,7 +4256,10 @@ fn read_intra_mode( mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0; if mode == DC_PRED && trace { let (rng, _) = dec.debug_state(); - eprintln!("TRACE palette_y_mode value={} rng={rng}", use_palette_y as i32); + eprintln!( + "TRACE palette_y_mode value={} rng={rng}", + use_palette_y as i32 + ); } if use_palette_y { if palette.is_none() { @@ -4266,7 +4330,11 @@ fn read_intra_mode( if trace { eprintln!("TRACE palette_y size={n} colors={:?}", &colors[..n]); } - PaletteY { size: n, colors, map } + PaletteY { + size: n, + colors, + map, + } }); let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { let map = decode_color_index_map(dec, cdfs, n, side / 2, true); @@ -4278,7 +4346,12 @@ fn read_intra_mode( &v_colors[..n] ); } - PaletteUv { size: n, u_colors, v_colors, map } + PaletteUv { + size: n, + u_colors, + v_colors, + map, + } }); Ok(( skip, @@ -4728,7 +4801,15 @@ fn read_plane( full }; let (dc_delta, ac_delta) = plane_q_delta(plane_idx); - let residual = dequant_and_inverse_typed(&levels, side, bit_depth(), CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type); + let residual = dequant_and_inverse_typed( + &levels, + side, + bit_depth(), + CURRENT_Q_IDX.with(|c| c.get()), + dc_delta, + ac_delta, + tx_type, + ); if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}", @@ -4795,23 +4876,32 @@ fn decode_block( let (px, py) = (c * SUB, r * SUB); let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at); let palette_uv_cache = neighbours.palette_uv_cache(at); - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) = - read_intra_mode( - dec, - cdfs, - neighbours.above_mode[c], - neighbours.left_mode[r], - cfl, - side, - enable_filter_intra, - neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), - allow_screen_content_tools, - allow_intrabc, - Some((palette_ctx, &palette_cache)), - &palette_uv_cache, - r * (SUB / MI), - c * (SUB / MI), - )?; + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + palette_y, + palette_uv, + ) = read_intra_mode( + dec, + cdfs, + neighbours.above_mode[c], + neighbours.left_mode[r], + cfl, + side, + enable_filter_intra, + neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)), + allow_screen_content_tools, + allow_intrabc, + Some((palette_ctx, &palette_cache)), + &palette_uv_cache, + r * (SUB / MI), + c * (SUB / MI), + )?; // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED` // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the // actual chroma-from-luma correlation, same as this decoder always did. @@ -4869,11 +4959,7 @@ fn decode_block( "a palette block with a split luma transform (round 1)", )); } - let buf: Vec = py - .map - .iter() - .map(|&idx| py.colors[idx as usize]) - .collect(); + let buf: Vec = py.map.iter().map(|&idx| py.colors[idx as usize]).collect(); PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf)); } // A UV-palette block's own chroma prediction override (lane-palette2 r1), @@ -4883,8 +4969,14 @@ fn decode_block( // either of these run. let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|puv| { ( - puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(), - puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(), + puv.map + .iter() + .map(|&idx| puv.u_colors[idx as usize]) + .collect(), + puv.map + .iter() + .map(|&idx| puv.v_colors[idx as usize]) + .collect(), ) }); if skip { @@ -4936,7 +5028,13 @@ fn decode_block( let luma_grid = vec![0i32; side * side]; let u_grid = vec![0i32; chroma_side * chroma_side]; let v_grid = vec![0i32; chroma_side * chroma_side]; - neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); + neighbours.record( + at, + side, + mode, + uv_predict_mode, + &[luma_grid, u_grid, v_grid], + ); } else if !tx_select || logical_tx == side { // A single luma transform unit -- the old path, unchanged (including // the 64x64 corner case, `logical_tx == side == 64` with @@ -5021,7 +5119,13 @@ fn decode_block( None, smooth_neighbor_uv, )?; - neighbours.record(at, side, mode, uv_predict_mode, &[luma_grid, u_grid, v_grid]); + neighbours.record( + at, + side, + mode, + uv_predict_mode, + &[luma_grid, u_grid, v_grid], + ); } else { // Several luma transform units, raster order (spec // `transform_block`'s loop): the block's resolved transform is @@ -5202,23 +5306,32 @@ fn decode_leaf8( // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other // `decode_block` caller at 16x16 and up. - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y, _palette_uv) = - read_intra_mode( - dec, - cdfs, - above_mode, - left_mode, - true, - 8, - enable_filter_intra, - neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), - allow_screen_content_tools, - allow_intrabc, - None, - &[], - leaf_mi.0, - leaf_mi.1, - )?; + let ( + skip, + mode, + angle_delta_y, + uv_mode, + angle_delta_uv, + alpha, + filter_intra, + _palette_y, + _palette_uv, + ) = read_intra_mode( + dec, + cdfs, + above_mode, + left_mode, + true, + 8, + enable_filter_intra, + neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1), + allow_screen_content_tools, + allow_intrabc, + None, + &[], + leaf_mi.0, + leaf_mi.1, + )?; let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { @@ -5764,18 +5877,10 @@ fn read_tx_size( ) -> usize { let ctx = tx_size_context(n, at_mi, side); let depth = match side { - 8 => { - dec.symbol(&mut cdfs.tx_size_cat0[ctx]) - } - 16 => { - dec.symbol(&mut cdfs.tx_size_cat1[ctx]) - } - 32 => { - dec.symbol(&mut cdfs.tx_size_cat2[ctx]) - } - 64 => { - dec.symbol(&mut cdfs.tx_size_cat3[ctx]) - } + 8 => dec.symbol(&mut cdfs.tx_size_cat0[ctx]), + 16 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), + 32 => dec.symbol(&mut cdfs.tx_size_cat2[ctx]), + 64 => dec.symbol(&mut cdfs.tx_size_cat3[ctx]), _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"), }; if std::env::var_os("EC_TRACE_MODE_STEP").is_some() { @@ -5852,6 +5957,14 @@ fn set_txfm_ctxs( } } +/// The value libaom initialises both transform contexts to -- NOT zero: +/// `av1_zero_above_context` memsets the txfm row to +/// `tx_size_wide[TX_SIZES_LARGEST]` and `av1_zero_left_context` does the same +/// with `tx_size_high[TX_SIZES_LARGEST]` (`av1_common_int.h`), i.e. 64 +/// pixels, so an unwritten neighbour reads as the *widest* possible +/// transform, not the narrowest. +const TXFM_CTX_INIT: u8 = 64; + /// libaom's `MAX_VARTX_DEPTH`: an inter block's transform tree halves at most /// twice below its own largest transform. const MAX_VARTX_DEPTH: usize = 2; @@ -5985,6 +6098,14 @@ fn read_block_tx_size( } } let single = leaves.len() == 1 && leaves[0].2 == side; + if !single && leaves.iter().any(|leaf| leaf.2 > 32) { + // Only a block wider than a superblock's own 64x64 max transform + // reaches here; this crate has no 64-point *inter* coefficient + // table set ([`inter_txbset_for`] stops at 32). + return Err(unsupported( + "an inter var-tx tree with a leaf transform larger than 32x32", + )); + } let resolved = leaves.last().map_or(side, |l| l.2); return Ok((resolved, (!single).then_some(leaves))); } @@ -6008,6 +6129,94 @@ fn read_block_tx_size( Ok((tx, None)) } +/// One 8x8 inter leaf's luma residual (lane-txselect): either the whole-8x8 +/// transform, or -- when [`read_block_tx_size`]'s var-tx tree took the single +/// split a `BLOCK_8X8` can take (`split`) -- the four 4x4 transform units in +/// raster order, each reading its own coefficient context off the units +/// already decoded before it. Returns the block's luma grid (all-zero in the +/// split case, whose reconstruction has already happened unit by unit) and +/// the `tx_type` chroma inherits: `av1_get_tx_type`'s colocated luma lookup, +/// which for a split block lands on the top-left unit. +#[allow(clippy::too_many_arguments)] +fn read_inter_luma8( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + leaf_mi: (usize, usize), + y: &mut PlaneBuf, + px: usize, + py: usize, + pred_y: &[u16], + mode_for_tx: usize, + base_q_idx: u8, + scan8: &[u16], + scan4: &[u16], + reduced_tx_set: bool, + split: bool, +) -> Result<(Vec, TxType)> { + if !split { + return read_inter_plane( + dec, + cdfs, + if reduced_tx_set { + TxbSet::Luma8Inter + } else { + TxbSet::Luma8InterSet1 + }, + scan8, + 0, + neighbours.around_mi(leaf_mi, 8)[0], + mode_for_tx, + y, + px, + py, + 8, + base_q_idx, + pred_y, + None, + None, + ); + } + let mut first = TxType::DctDct; + for tu_row in 0..2 { + for tu_col in 0..2 { + let tu_mi = (leaf_mi.0 + tu_row, leaf_mi.1 + tu_col); + let mut tu_pred = Vec::with_capacity(16); + for rr in 0..4 { + let start = (tu_row * 4 + rr) * 8 + tu_col * 4; + tu_pred.extend_from_slice(&pred_y[start..start + 4]); + } + let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); + let (tu_grid, tu_tx_type) = read_inter_plane( + dec, + cdfs, + if reduced_tx_set { + TxbSet::Luma4Inter + } else { + TxbSet::Luma4InterSet1 + }, + scan4, + 0, + neighbours.around_mi(tu_mi, 4)[0], + mode_for_tx, + y, + px + tu_col * 4, + py + tu_row * 4, + 4, + base_q_idx, + &tu_pred, + None, + Some(tu_skip_ctx), + )?; + if tu_row == 0 && tu_col == 0 { + first = tu_tx_type; + } + neighbours.record_mi_luma(tu_mi, 4, &tu_grid); + } + } + Ok((vec![0i32; 64], first)) +} + /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its /// coefficient tables from -- the inter counterpart of [`txbset_for`]. fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { @@ -6082,7 +6291,13 @@ fn unit_log2(px: u32) -> i32 { /// the flat `mode_deltas[1]` this used before was a `LAST_FRAME`-reachable /// wrong delta on every `GLOBALMV` block, masked while any `GOLDEN_FRAME` /// block anywhere aborted the whole stream's decode before comparison). -fn lf_level(lf: &LoopFilterParams, plane_idx: usize, dir: usize, ref_frame: i8, delta_lf: i32) -> i32 { +fn lf_level( + lf: &LoopFilterParams, + plane_idx: usize, + dir: usize, + ref_frame: i8, + delta_lf: i32, +) -> i32 { let base = i32::from(if plane_idx == 0 { lf.level[dir] } else if plane_idx == 1 { @@ -6147,7 +6362,8 @@ fn edge_params( let pv_ref = n.ref_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c]; let delta_idx = if plane_idx == 0 { dir } else { plane_idx + 1 }; let cur_delta_lf = i32::from(n.delta_lf_grid[mi_r * n.skip_grid_cols_mi + mi_c][delta_idx]); - let pv_delta_lf = i32::from(n.delta_lf_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c][delta_idx]); + let pv_delta_lf = + i32::from(n.delta_lf_grid[pv_mi_r * n.skip_grid_cols_mi + pv_mi_c][delta_idx]); let cur_level = lf_level(lf, plane_idx, dir, cur_ref, cur_delta_lf); let pv_level = lf_level(lf, plane_idx, dir, pv_ref, pv_delta_lf); @@ -6510,9 +6726,7 @@ fn deblock_plane( let mut y0 = 4usize; while y0 < th { if let Some((len, level)) = edge_params(lf, n, plane_idx, 1, chroma, x0, y0) { - if std::env::var_os("EC_AV1_DEBLOCK_TRACE").is_some() - && plane_idx == 0 - && x0 == 44 + if std::env::var_os("EC_AV1_DEBLOCK_TRACE").is_some() && plane_idx == 0 && x0 == 44 { eprintln!( "HEDGE x0={x0} y0={y0} len={len} level={level} sharpness={}", @@ -6563,10 +6777,7 @@ fn apply_cdef( return 0; } let (sb_r, sb_c) = (mi_r / SB_MI as usize, mi_c / SB_MI as usize); - idx_grid - .get(sb_r * sb_cols + sb_c) - .copied() - .unwrap_or(0) as usize + idx_grid.get(sb_r * sb_cols + sb_c).copied().unwrap_or(0) as usize }; let src_y = y.data.clone(); let src_u = u.data.clone(); @@ -6937,8 +7148,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // last entry) is not, so the upper bound needs `div_ceil` the same // way the whole-frame `sb_rows`/`sb_cols` above does, to keep the // trailing partial superblock row/column in scope. - let (sb_r0, sb_r1) = ((mi_row0 / SB_MI).min(sb_rows), mi_row1.div_ceil(SB_MI).min(sb_rows)); - let (sb_c0, sb_c1) = ((mi_col0 / SB_MI).min(sb_cols), mi_col1.div_ceil(SB_MI).min(sb_cols)); + let (sb_r0, sb_r1) = ( + (mi_row0 / SB_MI).min(sb_rows), + mi_row1.div_ceil(SB_MI).min(sb_rows), + ); + let (sb_c0, sb_c1) = ( + (mi_col0 / SB_MI).min(sb_cols), + mi_col1.div_ceil(SB_MI).min(sb_cols), + ); let mut cdfs = base_cdfs.clone(); // spec `decode_tile`: `CurrentQIndex` resets to the frame's own @@ -6975,186 +7192,495 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( ); TILE_HITS.with(|c| c.set(c.get() + 1)); - for sb_r in sb_r0..sb_r1 { - neighbours.start_row(); - for sb_c in sb_c0..sb_c1 { - crate::restoration::read_lr( - &mut dec, - &mut cdfs, - lr, - &mut lr_grid, - &mut lr_reference, - sb_r * SB_MI, - sb_c * SB_MI, - SB_MI, - ); - CDEF_TRANSMITTED.with(|c| c.set(false)); - let at = (sb_r as usize * 4, sb_c as usize * 4); - let ctx = neighbours.partition_ctx(at, SB); - let (has_cols, has_rows) = ( - sb_c * SB_MI + SB_MI / 2 < mi_cols, - sb_r * SB_MI + SB_MI / 2 < mi_rows, - ); - // Recomputed at this superblock's own half (spec - // `decode_partition`): a full alphabet symbol when both halves are - // inside the true frame, a single gathered bit when just one is - // (the superblock cannot be left whole, so this is forced split), - // and nothing at all (SPLIT inferred, no bits) when neither is — - // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own - // three-way write exactly. - let part = if has_cols && has_rows { - let p = dec.symbol(&mut cdfs.partition_w64[ctx]); - if std::env::var_os("EC_AV1_TRACE").is_some() { - eprintln!("TRACE partition_w64 ctx={ctx} value={p}"); - } - p - } else { - match (has_cols, has_rows) { - (true, false) => { - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); - } - (false, true) => { - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); + for sb_r in sb_r0..sb_r1 { + neighbours.start_row(); + for sb_c in sb_c0..sb_c1 { + crate::restoration::read_lr( + &mut dec, + &mut cdfs, + lr, + &mut lr_grid, + &mut lr_reference, + sb_r * SB_MI, + sb_c * SB_MI, + SB_MI, + ); + CDEF_TRANSMITTED.with(|c| c.set(false)); + let at = (sb_r as usize * 4, sb_c as usize * 4); + let ctx = neighbours.partition_ctx(at, SB); + let (has_cols, has_rows) = ( + sb_c * SB_MI + SB_MI / 2 < mi_cols, + sb_r * SB_MI + SB_MI / 2 < mi_rows, + ); + // Recomputed at this superblock's own half (spec + // `decode_partition`): a full alphabet symbol when both halves are + // inside the true frame, a single gathered bit when just one is + // (the superblock cannot be left whole, so this is forced split), + // and nothing at all (SPLIT inferred, no bits) when neither is — + // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own + // three-way write exactly. + let part = if has_cols && has_rows { + let p = dec.symbol(&mut cdfs.partition_w64[ctx]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!("TRACE partition_w64 ctx={ctx} value={p}"); } - _ => {} - } - PARTITION_SPLIT - }; - match part { - PARTITION_NONE => { - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - at, - SB, - TxbSet::Luma64, - TxbSet::Chroma32, - TX32, - TX32, - (&scan32, &scan32), - false, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, - )?; - } - PARTITION_SPLIT => { - for q in 0..4 { - let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2); - if r32 >= rows32 || c32 >= cols32 { - continue; + p + } else { + match (has_cols, has_rows) { + (true, false) => { + dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); } - let at32 = (r32 as usize * 2, c32 as usize * 2); - let ctx32 = neighbours.partition_ctx(at32, BLOCK); - let (has_cols32, has_rows32) = ( - has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), - has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), - ); - let part32 = if has_cols32 && has_rows32 { - let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); - if std::env::var_os("EC_AV1_TRACE").is_some() { - let (rng, _) = dec.debug_state(); - eprintln!( - "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}", - r32 * BLOCK_MI, - c32 * BLOCK_MI - ); + (false, true) => { + dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); + } + _ => {} + } + PARTITION_SPLIT + }; + match part { + PARTITION_NONE => { + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at, + SB, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + (&scan32, &scan32), + false, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + )?; + } + PARTITION_SPLIT => { + for q in 0..4 { + let (r32, c32) = (sb_r * 2 + q / 2, sb_c * 2 + q % 2); + if r32 >= rows32 || c32 >= cols32 { + continue; } - p - } else { - match (has_cols32, has_rows32) { - (true, false) => { - dec.symbol_fixed(&gather( - &cdfs.partition_w32[ctx32], - VERT_ALIKE, - )); - } - (false, true) => { - dec.symbol_fixed(&gather( - &cdfs.partition_w32[ctx32], - HORZ_ALIKE, - )); + let at32 = (r32 as usize * 2, c32 as usize * 2); + let ctx32 = neighbours.partition_ctx(at32, BLOCK); + let (has_cols32, has_rows32) = ( + has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), + has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), + ); + let part32 = if has_cols32 && has_rows32 { + let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!( + "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}", + r32 * BLOCK_MI, + c32 * BLOCK_MI + ); } - _ => {} - } - PARTITION_SPLIT - }; - match part32 { - PARTITION_NONE => { - decode_block( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - BLOCK, - TxbSet::Luma32, - TxbSet::Chroma16, - TX32, - TX16, - (&scan32, &scan16), - true, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, - tx_select, - reduced_tx_set, - )?; - } - PARTITION_SPLIT => { - for sub in 0..4 { - let (sr, sc) = - (r32 as usize * 2 + sub / 2, c32 as usize * 2 + sub % 2); - if (sr as u32) * SUB_MI >= mi_rows - || (sc as u32) * SUB_MI >= mi_cols - { - continue; + p + } else { + match (has_cols32, has_rows32) { + (true, false) => { + dec.symbol_fixed(&gather( + &cdfs.partition_w32[ctx32], + VERT_ALIKE, + )); } - let (has_cols16, has_rows16) = ( - has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), - has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), - ); - let at16 = (sr, sc); - let ctx16 = neighbours.partition_ctx(at16, SUB); - if has_cols16 && has_rows16 { - let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); - if std::env::var_os("EC_AV1_TRACE").is_some() { - eprintln!( - "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}", - at16.0, at16.1 - ); + (false, true) => { + dec.symbol_fixed(&gather( + &cdfs.partition_w32[ctx32], + HORZ_ALIKE, + )); + } + _ => {} + } + PARTITION_SPLIT + }; + match part32 { + PARTITION_NONE => { + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + BLOCK, + TxbSet::Luma32, + TxbSet::Chroma16, + TX32, + TX16, + (&scan32, &scan16), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + )?; + } + PARTITION_SPLIT => { + for sub in 0..4 { + let (sr, sc) = ( + r32 as usize * 2 + sub / 2, + c32 as usize * 2 + sub % 2, + ); + if (sr as u32) * SUB_MI >= mi_rows + || (sc as u32) * SUB_MI >= mi_cols + { + continue; + } + let (has_cols16, has_rows16) = ( + has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), + has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), + ); + let at16 = (sr, sc); + let ctx16 = neighbours.partition_ctx(at16, SUB); + if has_cols16 && has_rows16 { + let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}", + at16.0, at16.1 + ); + } + if part16 == PARTITION_NONE { + decode_block( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + SUB, + TxbSet::Luma16, + TxbSet::Chroma8, + TX16, + TX8, + (&scan16, &scan8), + true, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + &scan32, + &scan16, + &scan8, + &scan4, + tx_select, + reduced_tx_set, + )?; + continue; + } + if part16 == PARTITION_VERT_B { + VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1)); + // Left rect: 8x16, real + // `decode_block_rect`, sat at the + // 16x16 parent's own origin (no + // fractional-SUB-grid pixel + // offset needed -- the plain + // HORZ/VERT arms this lane's + // charter named DO need one, + // since their second half is + // offset by half the parent; + // unported, see decode_block_rect's + // own doc comment). + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + 8, + 16, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + // Two 8x8 squares stacked on the + // right, chained through + // `prev_leaf` exactly like the + // real (non-straddle) SPLIT path + // below: the bottom leaf's ABOVE + // context is the top leaf, not + // the coarse SUB-grid array (a + // real block never sat there). + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let top_right = + (mi_row0 as usize, mi_col0 as usize + 2); + let bot_right = + (mi_row0 as usize + 2, mi_col0 as usize + 2); + let mode_tr = decode_leaf8( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + top_right, + (&scan8, &scan4), + None, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + tx_select, + reduced_tx_set, + )?; + let mode_br = decode_leaf8( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + bot_right, + (&scan8, &scan4), + Some((top_right, mode_tr)), + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + tx_select, + reduced_tx_set, + )?; + // `record()`'s above_mode/left_mode + // write is a no-op at an 8x8 + // leaf's own side (same gap the + // real-SPLIT path above patches): + // force it from the last-decoded + // (bottom-right) leaf. + neighbours.above_mode[sc] = mode_br; + neighbours.left_mode[sr] = mode_br; + continue; + } + if part16 == PARTITION_HORZ { + HORZ_VERT_INTRA_HITS.with(|c| c.set(c.get() + 1)); + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let top = (mi_row0 as usize, mi_col0 as usize); + let bot = (mi_row0 as usize + 2, mi_col0 as usize); + let mode_top = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + top, + 16, + 8, + None, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + let mode_bot = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + bot, + 16, + 8, + Some((top, mode_top)), + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + neighbours.above_mode[sc] = mode_bot; + neighbours.left_mode[sr] = mode_bot; + continue; + } + if part16 == PARTITION_VERT { + HORZ_VERT_INTRA_HITS.with(|c| c.set(c.get() + 1)); + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let left = (mi_row0 as usize, mi_col0 as usize); + let right = + (mi_row0 as usize, mi_col0 as usize + 2); + let mode_left = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + left, + 8, + 16, + None, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + let mode_right = decode_leaf_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + right, + 8, + 16, + Some((left, mode_left)), + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + neighbours.above_mode[sc] = mode_right; + neighbours.left_mode[sr] = mode_right; + continue; + } + if part16 != PARTITION_SPLIT { + return Err(unsupported( + "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", + )); + } + // A real (non-straddle) SPLIT of a + // whole 16x16 into four 8x8 leaves -- + // the same recursion the straddle + // path below already runs when the + // true frame edge forces it, just + // over all four positions instead of + // the one or two the edge leaves. + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let mut prev_leaf: Option<((usize, usize), usize)> = + None; + for i in 0..4 { + let (mr, mc) = + (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); + let leaf_mi = (mr as usize, mc as usize); + let leaf_ctx = + neighbours.partition_ctx_mi(leaf_mi, 8); + let part8 = + dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" + ); + } + if part8 != PARTITION_NONE { + return Err(unsupported( + "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", + )); + } + let leaf_mode = decode_leaf8( + &mut dec, + &mut cdfs, + &mut neighbours, + at16, + leaf_mi, + (&scan8, &scan4), + prev_leaf, + &mut y, + &mut u, + &mut v, + base_q_idx, + enable_filter_intra, + allow_screen_content_tools, + allow_intrabc, + tx_select, + reduced_tx_set, + )?; + prev_leaf = Some((leaf_mi, leaf_mode)); + } + if let Some((_, mode)) = prev_leaf { + neighbours.above_mode[sc] = mode; + neighbours.left_mode[sr] = mode; + } + continue; + } + // The true edge falls inside this 16x16 + // leaf itself (mod-32==8 target sizes, + // lane-av1-rect): one axis only -- an 8x8 + // leaf never itself straddles, so the + // block splits cleanly along whichever + // axis is short. + if !has_cols16 && !has_rows16 { + return Err(unsupported( + "a 16x16 block whose true edge cuts through both \ + axes needs a rectangular transform this decoder \ + does not code yet", + )); + } + if has_cols16 { + dec.symbol_fixed(&gather( + &cdfs.partition_w16[ctx16], + VERT_ALIKE, + )); + } else { + dec.symbol_fixed(&gather( + &cdfs.partition_w16[ctx16], + HORZ_ALIKE, + )); } - if part16 == PARTITION_NONE { - decode_block( + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let leaf_positions: Vec<(u32, u32)> = (0..4) + .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) + .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) + .collect(); + let mut prev_leaf: Option<((usize, usize), usize)> = None; + for (mr, mc) in leaf_positions { + let leaf_mi = (mr as usize, mc as usize); + let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); + let part8 = + dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" + ); + } + if part8 != PARTITION_NONE { + return Err(unsupported( + "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", + )); + } + let leaf_mode = decode_leaf8( &mut dec, &mut cdfs, &mut neighbours, at16, - SUB, - TxbSet::Luma16, - TxbSet::Chroma8, - TX16, - TX8, - (&scan16, &scan8), - true, + leaf_mi, + (&scan8, &scan4), + prev_leaf, &mut y, &mut u, &mut v, @@ -7162,499 +7688,192 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( enable_filter_intra, allow_screen_content_tools, allow_intrabc, - &scan32, - &scan16, - &scan8, - &scan4, tx_select, reduced_tx_set, )?; - continue; - } - if part16 == PARTITION_VERT_B { - VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1)); - // Left rect: 8x16, real - // `decode_block_rect`, sat at the - // 16x16 parent's own origin (no - // fractional-SUB-grid pixel - // offset needed -- the plain - // HORZ/VERT arms this lane's - // charter named DO need one, - // since their second half is - // offset by half the parent; - // unported, see decode_block_rect's - // own doc comment). - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - 8, - 16, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - // Two 8x8 squares stacked on the - // right, chained through - // `prev_leaf` exactly like the - // real (non-straddle) SPLIT path - // below: the bottom leaf's ABOVE - // context is the top leaf, not - // the coarse SUB-grid array (a - // real block never sat there). - let (mi_row0, mi_col0) = - (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let top_right = - (mi_row0 as usize, mi_col0 as usize + 2); - let bot_right = - (mi_row0 as usize + 2, mi_col0 as usize + 2); - let mode_tr = decode_leaf8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - top_right, - (&scan8, &scan4), - None, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - tx_select, - reduced_tx_set, - )?; - let mode_br = decode_leaf8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - bot_right, - (&scan8, &scan4), - Some((top_right, mode_tr)), - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - tx_select, - reduced_tx_set, - )?; - // `record()`'s above_mode/left_mode - // write is a no-op at an 8x8 - // leaf's own side (same gap the - // real-SPLIT path above patches): - // force it from the last-decoded - // (bottom-right) leaf. - neighbours.above_mode[sc] = mode_br; - neighbours.left_mode[sr] = mode_br; - continue; - } - if part16 == PARTITION_HORZ { - HORZ_VERT_INTRA_HITS.with(|c| c.set(c.get() + 1)); - let (mi_row0, mi_col0) = ( - sr as u32 * SUB_MI, - sc as u32 * SUB_MI, - ); - let top = (mi_row0 as usize, mi_col0 as usize); - let bot = (mi_row0 as usize + 2, mi_col0 as usize); - let mode_top = decode_leaf_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - top, - 16, - 8, - None, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - let mode_bot = decode_leaf_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - bot, - 16, - 8, - Some((top, mode_top)), - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - neighbours.above_mode[sc] = mode_bot; - neighbours.left_mode[sr] = mode_bot; - continue; - } - if part16 == PARTITION_VERT { - HORZ_VERT_INTRA_HITS.with(|c| c.set(c.get() + 1)); - let (mi_row0, mi_col0) = ( - sr as u32 * SUB_MI, - sc as u32 * SUB_MI, - ); - let left = (mi_row0 as usize, mi_col0 as usize); - let right = (mi_row0 as usize, mi_col0 as usize + 2); - let mode_left = decode_leaf_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - left, - 8, - 16, - None, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - let mode_right = decode_leaf_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - right, - 8, - 16, - Some((left, mode_left)), - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - neighbours.above_mode[sc] = mode_right; - neighbours.left_mode[sr] = mode_right; - continue; - } - if part16 != PARTITION_SPLIT { - return Err(unsupported( - "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", - )); - } - // A real (non-straddle) SPLIT of a - // whole 16x16 into four 8x8 leaves -- - // the same recursion the straddle - // path below already runs when the - // true frame edge forces it, just - // over all four positions instead of - // the one or two the edge leaves. - let (mi_row0, mi_col0) = - (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let mut prev_leaf: Option<((usize, usize), usize)> = None; - for i in 0..4 { - let (mr, mc) = - (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); - let leaf_mi = (mr as usize, mc as usize); - let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); - let part8 = - dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); - if std::env::var_os("EC_AV1_TRACE").is_some() { - eprintln!( - "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" - ); - } - if part8 != PARTITION_NONE { - return Err(unsupported( - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", - )); - } - let leaf_mode = decode_leaf8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - leaf_mi, - (&scan8, &scan4), - prev_leaf, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - tx_select, - reduced_tx_set, - )?; - prev_leaf = Some((leaf_mi, leaf_mode)); + prev_leaf = Some((leaf_mi, leaf_mode)); } + // `record()`'s `above_mode`/`left_mode` + // write is a no-op at an 8x8 leaf's own + // side, so force the write once the whole + // 16x16 slot's leaves are done, from the + // last leaf (mirrors the writer's r15 + // fix). if let Some((_, mode)) = prev_leaf { neighbours.above_mode[sc] = mode; neighbours.left_mode[sr] = mode; } - continue; - } - // The true edge falls inside this 16x16 - // leaf itself (mod-32==8 target sizes, - // lane-av1-rect): one axis only -- an 8x8 - // leaf never itself straddles, so the - // block splits cleanly along whichever - // axis is short. - if !has_cols16 && !has_rows16 { - return Err(unsupported( - "a 16x16 block whose true edge cuts through both \ - axes needs a rectangular transform this decoder \ - does not code yet", - )); - } - if has_cols16 { - dec.symbol_fixed(&gather( - &cdfs.partition_w16[ctx16], - VERT_ALIKE, - )); - } else { - dec.symbol_fixed(&gather( - &cdfs.partition_w16[ctx16], - HORZ_ALIKE, - )); - } - let (mi_row0, mi_col0) = - (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let leaf_positions: Vec<(u32, u32)> = (0..4) - .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) - .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) - .collect(); - let mut prev_leaf: Option<((usize, usize), usize)> = None; - for (mr, mc) in leaf_positions { - let leaf_mi = (mr as usize, mc as usize); - let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); - let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); - if std::env::var_os("EC_AV1_TRACE").is_some() { - eprintln!( - "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" - ); - } - if part8 != PARTITION_NONE { - return Err(unsupported( - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", - )); - } - let leaf_mode = decode_leaf8( - &mut dec, - &mut cdfs, - &mut neighbours, - at16, - leaf_mi, - (&scan8, &scan4), - prev_leaf, - &mut y, - &mut u, - &mut v, - base_q_idx, - enable_filter_intra, - allow_screen_content_tools, - allow_intrabc, - tx_select, - reduced_tx_set, - )?; - prev_leaf = Some((leaf_mi, leaf_mode)); - } - // `record()`'s `above_mode`/`left_mode` - // write is a no-op at an 8x8 leaf's own - // side, so force the write once the whole - // 16x16 slot's leaves are done, from the - // last leaf (mirrors the writer's r15 - // fix). - if let Some((_, mode)) = prev_leaf { - neighbours.above_mode[sc] = mode; - neighbours.left_mode[sr] = mode; } } - } - PARTITION_HORZ => { - // lane-intradisp r1: two true 32x16 strips. - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - 32, - 16, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0 + 1, at32.1), - 32, - 16, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - } - PARTITION_VERT => { - // lane-intradisp r1: mirror of PARTITION_HORZ - // above with width/height swapped. - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - at32, - 16, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - decode_block_rect( - &mut dec, - &mut cdfs, - &mut neighbours, - (at32.0, at32.1 + 1), - 16, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - } - _ => { - return Err(unsupported(format!( - "a 32x32 partition type this decoder does not code (value={part32})" - ))); + PARTITION_HORZ => { + // lane-intradisp r1: two true 32x16 strips. + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + 32, + 16, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0 + 1, at32.1), + 32, + 16, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + } + PARTITION_VERT => { + // lane-intradisp r1: mirror of PARTITION_HORZ + // above with width/height swapped. + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + at32, + 16, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + decode_block_rect( + &mut dec, + &mut cdfs, + &mut neighbours, + (at32.0, at32.1 + 1), + 16, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + } + _ => { + return Err(unsupported(format!( + "a 32x32 partition type this decoder does not code (value={part32})" + ))); + } } } } - } - PARTITION_HORZ => { - // lane-sbpart r2: two true 64x32 strips. - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - at, - 64, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - (at.0 + 2, at.1), - 64, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - } - PARTITION_VERT => { - // lane-sbpart r2: mirror of PARTITION_HORZ above with - // width/height swapped. - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - at, - 32, - 64, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - (at.0, at.1 + 2), - 32, - 64, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - )?; - } - _ => { - return Err(unsupported( - "a superblock-level partition type other than NONE or SPLIT (this \ - decoder's intra tile path codes only those two at 64x64)", - )); - } - } - } - } - - if tile_num == tile_info.context_update_tile_id { - result_cdfs = cdfs; - } - } - - // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's - // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against - // that isolate whether a decode-order frame's mismatch already exists - // in reconstruction (this dump) vs is introduced by the loop filter - // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). - if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { - use std::io::Write; - let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); - if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { - let narrow = |p: &PlaneBuf| -> Vec { p.data.iter().map(|&s| s as u8).collect() }; - let _ = f.write_all(&narrow(&y)); - let _ = f.write_all(&narrow(&u)); + PARTITION_HORZ => { + // lane-sbpart r2: two true 64x32 strips. + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + at, + 64, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + (at.0 + 2, at.1), + 64, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + } + PARTITION_VERT => { + // lane-sbpart r2: mirror of PARTITION_HORZ above with + // width/height swapped. + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + at, + 32, + 64, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + (at.0, at.1 + 2), + 32, + 64, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + )?; + } + _ => { + return Err(unsupported( + "a superblock-level partition type other than NONE or SPLIT (this \ + decoder's intra tile path codes only those two at 64x64)", + )); + } + } + } + } + + if tile_num == tile_info.context_update_tile_id { + result_cdfs = cdfs; + } + } + + // lane-comppin r4: pre-loop-filter decode-order dump, matching aomdec's + // own EC_AV1_PREFILT_DUMP shape (decodeframe.c ~5451) -- diffs against + // that isolate whether a decode-order frame's mismatch already exists + // in reconstruction (this dump) vs is introduced by the loop filter + // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump). + if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") { + use std::io::Write; + let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst); + if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { + let narrow = |p: &PlaneBuf| -> Vec { p.data.iter().map(|&s| s as u8).collect() }; + let _ = f.write_all(&narrow(&y)); + let _ = f.write_all(&narrow(&u)); let _ = f.write_all(&narrow(&v)); } } else { @@ -7667,7 +7886,11 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( let crop_wide = |plane: &PlaneBuf| -> Vec { let mut out = Vec::with_capacity(plane.true_width * plane.true_height); for row in 0..plane.true_height { - out.extend(plane.data[row * plane.width..][..plane.true_width].iter().map(|&s| s as u8)); + out.extend( + plane.data[row * plane.width..][..plane.true_width] + .iter() + .map(|&s| s as u8), + ); } out }; @@ -7688,7 +7911,16 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( ); let (deblocked_y, deblocked_u, deblocked_v) = (y.clone(), u.clone(), v.clone()); apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); - apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid); + apply_loop_restoration( + &mut y, + &mut u, + &mut v, + &deblocked_y, + &deblocked_u, + &deblocked_v, + lr, + &lr_grid, + ); let (fw, fh) = (frame_width as usize, frame_height as usize); if fw == width && fh == height { @@ -7920,7 +8152,11 @@ fn read_mv_component( } // spec 5.11.32 `mv_fr`: same force_integer_mv carve-out as // `mv_class0_fr` above. - let fr = if force_integer_mv { 3 } else { dec.symbol(&mut c.fr) }; + let fr = if force_integer_mv { + 3 + } else { + dec.symbol(&mut c.fr) + }; let hp = if allow_high_precision_mv { dec.symbol(&mut c.hp) } else { @@ -7945,10 +8181,20 @@ fn read_mv( let joint = dec.symbol(mv_joint); let mut diff = (0, 0); if joint == 2 || joint == 3 { - diff.0 = read_mv_component(dec, &mut mv_comp[0], allow_high_precision_mv, force_integer_mv); + diff.0 = read_mv_component( + dec, + &mut mv_comp[0], + allow_high_precision_mv, + force_integer_mv, + ); } if joint == 1 || joint == 3 { - diff.1 = read_mv_component(dec, &mut mv_comp[1], allow_high_precision_mv, force_integer_mv); + diff.1 = read_mv_component( + dec, + &mut mv_comp[1], + allow_high_precision_mv, + force_integer_mv, + ); } (pred.0 + diff.0, pred.1 + diff.1) } @@ -8062,7 +8308,15 @@ fn read_inter_plane( None, )?; let (dc_delta, ac_delta) = plane_q_delta(plane_idx); - let residual = dequant_and_inverse_typed(&grid, side, bit_depth(), CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type); + let residual = dequant_and_inverse_typed( + &grid, + side, + bit_depth(), + CURRENT_Q_IDX.with(|c| c.get()), + dc_delta, + ac_delta, + tx_type, + ); plane.reconstruct_mc(x, y, side, prediction, &residual); Ok((grid, tx_type)) } @@ -8082,22 +8336,31 @@ fn read_single_ref( ) -> i8 { let above = (above_ref > 0).then_some(above_ref); let left = (left_ref > 0).then_some(left_ref); - let p1 = dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, above_ref1, left, left_ref1)][0]); + let p1 = + dec.symbol(&mut cdfs.single_ref[single_ref_p1_ctx(above, above_ref1, left, left_ref1)][0]); let ref_frame = if p1 == 1 { - let p2 = dec.symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, above_ref1, left, left_ref1)][1]); + let p2 = dec + .symbol(&mut cdfs.single_ref[single_ref_p2_ctx(above, above_ref1, left, left_ref1)][1]); if p2 == 1 { ALTREF_FRAME } else { - let p6 = dec.symbol(&mut cdfs.single_ref[single_ref_p6_ctx(above, above_ref1, left, left_ref1)][5]); + let p6 = dec.symbol( + &mut cdfs.single_ref[single_ref_p6_ctx(above, above_ref1, left, left_ref1)][5], + ); if p6 == 1 { ALTREF2_FRAME } else { BWDREF_FRAME } } } else { - let p3 = dec.symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, above_ref1, left, left_ref1)][2]); + let p3 = dec + .symbol(&mut cdfs.single_ref[single_ref_p3_ctx(above, above_ref1, left, left_ref1)][2]); if p3 == 1 { - let p5 = dec.symbol(&mut cdfs.single_ref[single_ref_p5_ctx(above, above_ref1, left, left_ref1)][4]); + let p5 = dec.symbol( + &mut cdfs.single_ref[single_ref_p5_ctx(above, above_ref1, left, left_ref1)][4], + ); if p5 == 1 { GOLDEN_FRAME } else { LAST3_FRAME } } else { - let p4 = dec.symbol(&mut cdfs.single_ref[single_ref_p4_ctx(above, above_ref1, left, left_ref1)][3]); + let p4 = dec.symbol( + &mut cdfs.single_ref[single_ref_p4_ctx(above, above_ref1, left, left_ref1)][3], + ); if p4 == 1 { LAST2_FRAME } else { LAST_FRAME } } }; @@ -8282,7 +8545,9 @@ fn find_samples( // neighbour donates its sample at ITS center (aom pts y=-72 for a // 32x16 above strip; the square assumption put it at -136). let nb_bh = (info.size_h * 4) as i32; - crate::warp::record_sample(nb_bw, nb_bh, info.mv, row_offset, sign_r, col_offset, sign_c) + crate::warp::record_sample( + nb_bw, nb_bh, info.mv, row_offset, sign_r, col_offset, sign_c, + ) }; 'outer: { @@ -8415,8 +8680,8 @@ fn obmc_mask(len: usize) -> &'static [u8] { 34, 37, 40, 43, 46, 49, 52, 54, 56, 58, 60, 61, 64, 64, 64, 64, ]; const M32: [u8; 32] = [ - 33, 35, 36, 38, 40, 41, 43, 44, 45, 47, 48, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 60, - 61, 62, 64, 64, 64, 64, 64, 64, 64, 64, + 33, 35, 36, 38, 40, 41, 43, 44, 45, 47, 48, 50, 51, 52, 53, 55, 56, 57, 58, 59, 60, 60, 61, + 62, 64, 64, 64, 64, 64, 64, 64, 64, ]; match len { 4 => &M4, @@ -8484,13 +8749,11 @@ fn obmc_neighbour_pred( /// row (the above-neighbour pass, `aom_blend_a64_vmask`). /// `ii_weights1d` (reconinter.c:524): the interintra smooth-mask falloff. const II_WEIGHTS_1D: [u8; 128] = [ - 60, 58, 56, 54, 52, 50, 48, 47, 45, 44, 42, 41, 39, 38, 37, 35, 34, 33, 32, - 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 18, 17, 16, - 16, 15, 15, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10, 10, 10, 9, 9, 9, 8, - 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, - 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 60, 58, 56, 54, 52, 50, 48, 47, 45, 44, 42, 41, 39, 38, 37, 35, 34, 33, 32, 31, 30, 29, 28, 27, + 26, 25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 18, 17, 16, 16, 15, 15, 14, 14, 13, 13, 12, 12, 12, + 11, 11, 10, 10, 10, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4, 4, 4, + 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ]; /// lane-interintra r1: non-wedge interintra prediction for one plane @@ -8577,7 +8840,15 @@ fn interintra_blend( } } -fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) { +fn obmc_blend_v( + dst: &mut [u16], + stride: usize, + ox: usize, + oy: usize, + w: usize, + h: usize, + tmp: &[u16], +) { let mask = obmc_mask(h); for row in 0..h { let m = u32::from(mask[row]); @@ -8591,7 +8862,15 @@ fn obmc_blend_v(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, /// Blends `tmp` into `dst` at `(ox, oy)`, mask varying by column (the /// left-neighbour pass, `aom_blend_a64_hmask`). -fn obmc_blend_h(dst: &mut [u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u16]) { +fn obmc_blend_h( + dst: &mut [u16], + stride: usize, + ox: usize, + oy: usize, + w: usize, + h: usize, + tmp: &[u16], +) { let mask = obmc_mask(w); for row in 0..h { for col in 0..w { @@ -8653,8 +8932,7 @@ fn obmc_blend( let overlap_above = write_h / 2; let overlap_left = write_w / 2; - for (off4, span4, nb) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) - { + for (off4, span4, nb) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4)) { // `Neighbours::above_filter` is indexed in `SUB`(16px)-wide columns // (this decoder's own outer block-loop granularity), one step // coarser than the mi(4px) units `overlappable_above` walks in -- @@ -9132,7 +9410,10 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}", - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 + r * SUB_MI as usize, + c * SUB_MI as usize, + dec.debug_bitpos(), + dec.debug_state().0 ); } let skip_mode_ctx = @@ -9160,8 +9441,22 @@ fn decode_inter_block( let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]); let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip); - maybe_read_delta_q(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip); - maybe_read_delta_lf(dec, cdfs, r * SUB_MI as usize, c * SUB_MI as usize, side == 64, skip); + maybe_read_delta_q( + dec, + cdfs, + r * SUB_MI as usize, + c * SUB_MI as usize, + side == 64, + skip, + ); + maybe_read_delta_lf( + dec, + cdfs, + r * SUB_MI as usize, + c * SUB_MI as usize, + side == 64, + skip, + ); // lane-warp r5: see `reject_residual` -- a square-block decode of a // HORZ_B strip is symbol-exact only for `skip` (no residual, no // motion_mode/warp symbol), so gate here before any further read. @@ -9181,7 +9476,10 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}", - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 + r * SUB_MI as usize, + c * SUB_MI as usize, + dec.debug_bitpos(), + dec.debug_state().0 ); } @@ -9301,15 +9599,20 @@ fn decode_inter_block( compound_mode, allow_high_precision_mv, force_integer_mv, - (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]), + ( + gm_table[(ref0 - LAST_FRAME) as usize], + gm_table[(ref1 - LAST_FRAME) as usize], + ), ); let is_globalmv = compound_mode == 6; // GLOBAL_GLOBALMV // spec `is_nontrans_global_motion`: ALL active refs' models must // be non-TRANSLATION (IDENTITY counts) for the compound block's // interp-filter read to be suppressed. let gm_nontrans = is_globalmv - && global_motion[(ref0 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation - && global_motion[(ref1 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation; + && global_motion[(ref0 - LAST_FRAME) as usize].model + != ec_av1_syntax::WarpModel::Translation + && global_motion[(ref1 - LAST_FRAME) as usize].model + != ec_av1_syntax::WarpModel::Translation; let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?; let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?; // spec `get_ref_filter_type`: matches when EITHER of the @@ -9320,20 +9623,18 @@ fn decode_inter_block( // real filter match down to the "no neighbour" sentinel // whenever the shared reference sits in the neighbour's SECOND // slot (lane-av1idx r2). - let above_filter_ctx = if neighbours.above_ref[c] == ref0 - || neighbours.above_ref1[c] == Some(ref0) - { - neighbours.above_filter[c] - } else { - [3, 3] - }; - let left_filter_ctx = if neighbours.left_ref[r] == ref0 - || neighbours.left_ref1[r] == Some(ref0) - { - neighbours.left_filter[r] - } else { - [3, 3] - }; + let above_filter_ctx = + if neighbours.above_ref[c] == ref0 || neighbours.above_ref1[c] == Some(ref0) { + neighbours.above_filter[c] + } else { + [3, 3] + }; + let left_filter_ctx = + if neighbours.left_ref[r] == ref0 || neighbours.left_ref1[r] == Some(ref0) { + neighbours.left_filter[r] + } else { + [3, 3] + }; globalmv_for_lf = is_globalmv; ref_frame_for_lf = ref0; mode_for_tx = 0; @@ -9381,14 +9682,12 @@ fn decode_inter_block( // as an explicit call so a future smaller block size is not // silently wrong (libaom `reconinter.h::is_any_masked_compound_used`). let group_ctx = get_comp_group_idx_context(neighbours, at, side); - let comp_group_idx = if !skip_mode - && enable_masked_compound - && is_any_masked_compound_used_here(side) - { - dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) - } else { - 0 - }; + let comp_group_idx = + if !skip_mode && enable_masked_compound && is_any_masked_compound_used_here(side) { + dec.symbol(&mut cdfs.comp_group_idx[group_ctx]) + } else { + 0 + }; // lane-maskcomp r2 / lane-wedge r3: `Some(mask_type)` for a // `COMPOUND_DIFFWTD` block, `Some(mask)` (wedge codebook lookup) // for a `COMPOUND_WEDGE` block -- exactly one of the two is set @@ -9628,39 +9927,41 @@ fn decode_inter_block( // split. This gate was missing before r2 (dead code: the masked // path always refused earlier, so it never executed with // `comp_group_idx == 1` in practice). - let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 - && !skip_mode - && enable_jnt_comp - { - let idx_ctx = get_comp_index_context( - neighbours, - at, - side, - order_hint_bits, - order_hint, - ref_order_hints[(ref0 - LAST_FRAME) as usize], - ref_order_hints[(ref1 - LAST_FRAME) as usize], - ); - let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); - if idx == 1 { - (8, 8, 1u8) - } else { - let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( + let (fwd_offset, bck_offset, compound_idx) = + if comp_group_idx == 0 && !skip_mode && enable_jnt_comp { + let idx_ctx = get_comp_index_context( + neighbours, + at, + side, order_hint_bits, order_hint, ref_order_hints[(ref0 - LAST_FRAME) as usize], ref_order_hints[(ref1 - LAST_FRAME) as usize], ); - (fwd, bck, 0u8) - } - } else { - (8, 8, 1u8) - }; + let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); + if idx == 1 { + (8, 8, 1u8) + } else { + let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( + order_hint_bits, + order_hint, + ref_order_hints[(ref0 - LAST_FRAME) as usize], + ref_order_hints[(ref1 - LAST_FRAME) as usize], + ); + (fwd, bck, 0u8) + } + } else { + (8, 8, 1u8) + }; compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx)); if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { eprintln!( "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize={side} mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}", - mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos() + mv0.0, + mv0.1, + mv1.0, + mv1.1, + dec.debug_bitpos() ); } @@ -9739,7 +10040,14 @@ fn decode_inter_block( }; if let Some(mask_y) = mask_y { mc::blend_masked_compound( - &inter0_y, &inter1_y, mask_y, side, side, side, false, &mut pred_y, + &inter0_y, + &inter1_y, + mask_y, + side, + side, + side, + false, + &mut pred_y, ); } else { mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); @@ -9980,21 +10288,21 @@ fn decode_inter_block( .0; } } else { - let ref_frame = - read_single_ref( - dec, - cdfs, - neighbours.above_ref[c], - neighbours.above_ref1[c], - neighbours.left_ref[r], - neighbours.left_ref1[r], - ); + let ref_frame = read_single_ref( + dec, + cdfs, + neighbours.above_ref[c], + neighbours.above_ref1[c], + neighbours.left_ref[r], + neighbours.left_ref1[r], + ); ref_frame_for_lf = ref_frame; if std::env::var_os("EC_AV1_TELL").is_some() { let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize); eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}", - dec.debug_bitpos(), dec.debug_state().0 + dec.debug_bitpos(), + dec.debug_state().0 ); } // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own @@ -10137,7 +10445,8 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}", - dec.debug_bitpos(), dec.debug_state().0 + dec.debug_bitpos(), + dec.debug_state().0 ); } // lane-sb128 r4: `interintra` (spec 5.11.24; libaom @@ -10186,7 +10495,8 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_interintra tell={} range={}", - dec.debug_bitpos(), dec.debug_state().0 + dec.debug_bitpos(), + dec.debug_state().0 ); } // lane-motionmode round 1: `read_motion_mode` (spec 5.11.24; @@ -10260,7 +10570,16 @@ fn decode_inter_block( // instead of the 2-symbol `obmc_cdf` exactly when // `num_proj_ref >= 1` under `allow_warped_motion`. let warp_eligible = allow_warped_motion - && num_proj_ref(grid, mi_row, mi_col, bw4, bh4, mi_cols as usize, mi_rows as usize, ref_frame) >= 1; + && num_proj_ref( + grid, + mi_row, + mi_col, + bw4, + bh4, + mi_cols as usize, + mi_rows as usize, + ref_frame, + ) >= 1; if warp_eligible { let mode = dec.symbol(&mut cdfs.motion_mode[bsize_idx]); match mode { @@ -10288,11 +10607,19 @@ fn decode_inter_block( samples.len() ); for (i, s) in samples.iter().enumerate() { - eprintln!("EC_WARP_DEBUG sample[{i}] pts={:?} pts_inref={:?}", s.pts1, s.pts2); + eprintln!( + "EC_WARP_DEBUG sample[{i}] pts={:?} pts_inref={:?}", + s.pts1, s.pts2 + ); } } if samples.len() > 1 { - crate::warp::select_samples(mv, &mut samples, side as i32, side as i32); + crate::warp::select_samples( + mv, + &mut samples, + side as i32, + side as i32, + ); } warp_params = crate::warp::find_projection( &samples, @@ -10309,10 +10636,16 @@ fn decode_inter_block( if std::env::var_os("EC_WARP_DEBUG").is_some() { eprintln!( "EC_WARP_DEBUG projection mi_row={mi_row} mi_col={mi_col} num_proj_ref(final)={} mv=({},{}) params={:?}", - samples.len(), mv.0, mv.1, warp_params + samples.len(), + mv.0, + mv.1, + warp_params ); for (i, s) in samples.iter().enumerate() { - eprintln!("EC_WARP_DEBUG sample_used[{i}] pts={:?} pts_inref={:?}", s.pts1, s.pts2); + eprintln!( + "EC_WARP_DEBUG sample_used[{i}] pts={:?} pts_inref={:?}", + s.pts1, s.pts2 + ); } } } @@ -10347,7 +10680,9 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}", - motion_mode_eligible as u8, dec.debug_bitpos(), dec.debug_state().0 + motion_mode_eligible as u8, + dec.debug_bitpos(), + dec.debug_state().0 ); } // spec `get_ref_filter_type`: a neighbour's own filter only feeds @@ -10390,13 +10725,21 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={mi_row} mi_col={mi_col} label=post_interp_filter tell={} range={}", - dec.debug_bitpos(), dec.debug_state().0 + dec.debug_bitpos(), + dec.debug_state().0 ); } if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?} motion_mode_eligible={} obmc_selected={} warped={} tell={}", - skip as u8, mv.0, mv.1, block_filter, motion_mode_eligible as u8, obmc_selected as u8, warp_params.is_some() as u8, dec.debug_bitpos() + skip as u8, + mv.0, + mv.1, + block_filter, + motion_mode_eligible as u8, + obmc_selected as u8, + warp_params.is_some() as u8, + dec.debug_bitpos() ); } // lane-rect r2: see the compound path's matching comment above -- @@ -10538,19 +10881,49 @@ fn decode_inter_block( if let Some(params) = &warp_params { crate::warp::warp_affine( - params, &py_ref.data, py_ref.true_width as i32, py_ref.true_height as i32, - py_ref.width as i32, &mut pred_y, px as i32, py as i32, side as i32, - side as i32, side as i32, 0, 0, + params, + &py_ref.data, + py_ref.true_width as i32, + py_ref.true_height as i32, + py_ref.width as i32, + &mut pred_y, + px as i32, + py as i32, + side as i32, + side as i32, + side as i32, + 0, + 0, ); crate::warp::warp_affine( - params, &pu_ref.data, pu_ref.true_width as i32, pu_ref.true_height as i32, - pu_ref.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32, - chroma_side as i32, chroma_side as i32, 1, 1, + params, + &pu_ref.data, + pu_ref.true_width as i32, + pu_ref.true_height as i32, + pu_ref.width as i32, + &mut pred_u, + cpx as i32, + cpy as i32, + chroma_side as i32, + chroma_side as i32, + chroma_side as i32, + 1, + 1, ); crate::warp::warp_affine( - params, &pv_ref.data, pv_ref.true_width as i32, pv_ref.true_height as i32, - pv_ref.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_side as i32, - chroma_side as i32, chroma_side as i32, 1, 1, + params, + &pv_ref.data, + pv_ref.true_width as i32, + pv_ref.true_height as i32, + pv_ref.width as i32, + &mut pred_v, + cpx as i32, + cpy as i32, + chroma_side as i32, + chroma_side as i32, + chroma_side as i32, + 1, + 1, ); } @@ -10796,17 +11169,15 @@ fn decode_inter_block( // lane-chroma r4: same chroma edge-filter-strength neighbour check // as [`read_intra_mode`]/[`read_intra_mode_rect`] -- the CHROMA // neighbour's own `uv_mode`, not the luma one. - let smooth_neighbor_uv = - is_smooth_mode(neighbours.above_uv_mode[c]) || is_smooth_mode(neighbours.left_uv_mode[r]); + let smooth_neighbor_uv = is_smooth_mode(neighbours.above_uv_mode[c]) + || is_smooth_mode(neighbours.left_uv_mode[r]); // `read_palette_mode_info` (decodemv.c:567, called from // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same // gating and same corner-cut as `read_intra_mode`'s own copy above // -- `palette_mode_ctx`/`palette_uv_mode_ctx` hardcoded 0, provably // safe since a nonzero neighbour `palette_size` would already have // refused the decode that produced it. - if allow_screen_content_tools - && let Some(bsize_ctx) = palette_bsize_ctx(side) - { + if allow_screen_content_tools && let Some(bsize_ctx) = palette_bsize_ctx(side) { if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][0]) != 0 { return Err(unsupported( "a block that actually uses a palette (Y) -- reconstruction is out of scope", @@ -10976,7 +11347,10 @@ fn decode_inter_block( if std::env::var_os("EC_AV1_TELL").is_some() { eprintln!( "TELL mi_row={} mi_col={} label=block_end tell={} range={}", - r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0 + r * SUB_MI as usize, + c * SUB_MI as usize, + dec.debug_bitpos(), + dec.debug_state().0 ); } if vartx_leaves.is_some() { @@ -11142,6 +11516,11 @@ fn decode_inter_block8( let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI); let (cpx, cpy) = (px / 2, py / 2); + // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took + // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) -- + // read back by the luma residual read and the tail's neighbour/loop-filter + // bookkeeping. Always `false` outside a `TxMode::Select` inter frame. + let mut split8 = false; const SIDE: usize = 8; const CHROMA_SIDE: usize = 4; @@ -11312,39 +11691,41 @@ fn decode_inter_block8( // compound_idx defect surfaces on the wide gate sweep. // lane-av1idx r1: same re-mask as the 16x16 leaf above -- // see that comment. - let (fwd_offset, bck_offset, compound_idx) = if comp_group_idx == 0 - && !skip_mode - && enable_jnt_comp - { - let idx_ctx = get_comp_index_context( - neighbours, - outer_at, - SIDE, - order_hint_bits, - order_hint, - ref_order_hints[(ref0 - LAST_FRAME) as usize], - ref_order_hints[(ref1 - LAST_FRAME) as usize], - ); - let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); - if idx == 1 { - (8, 8, 1u8) - } else { - let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( + let (fwd_offset, bck_offset, compound_idx) = + if comp_group_idx == 0 && !skip_mode && enable_jnt_comp { + let idx_ctx = get_comp_index_context( + neighbours, + outer_at, + SIDE, order_hint_bits, order_hint, ref_order_hints[(ref0 - LAST_FRAME) as usize], ref_order_hints[(ref1 - LAST_FRAME) as usize], ); - (fwd, bck, 0u8) - } - } else { - (8, 8, 1u8) - }; + let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]); + if idx == 1 { + (8, 8, 1u8) + } else { + let (fwd, bck) = crate::compound::dist_wtd_comp_weight_assign( + order_hint_bits, + order_hint, + ref_order_hints[(ref0 - LAST_FRAME) as usize], + ref_order_hints[(ref1 - LAST_FRAME) as usize], + ); + (fwd, bck, 0u8) + } + } else { + (8, 8, 1u8) + }; compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx)); if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() { eprintln!( "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize=8 mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}", - mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos() + mv0.0, + mv0.1, + mv1.0, + mv1.1, + dec.debug_bitpos() ); } @@ -11417,7 +11798,14 @@ fn decode_inter_block8( }; if let Some(mask_y) = mask_y { mc::blend_masked_compound( - &inter0_y, &inter1_y, mask_y, SIDE, SIDE, SIDE, false, &mut pred_y, + &inter0_y, + &inter1_y, + mask_y, + SIDE, + SIDE, + SIDE, + false, + &mut pred_y, ); } else { mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y); @@ -11511,6 +11899,18 @@ fn decode_inter_block8( mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v); } + split8 = read_block_tx_size( + dec, + cdfs, + neighbours, + leaf_mi, + SIDE, + (mi_cols as usize, mi_rows as usize), + true, + skip, + )? + .1 + .is_some(); if skip { y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); u.reconstruct_mc( @@ -11532,28 +11932,23 @@ fn decode_inter_block8( v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; } else { let around = neighbours.around_mi(leaf_mi, 8); - let luma_tx_type; - (luma_grid, luma_tx_type) = read_inter_plane( + let (grid8, luma_tx_type) = read_inter_luma8( dec, cdfs, - if reduced_tx_set { - TxbSet::Luma8Inter - } else { - TxbSet::Luma8InterSet1 - }, - scan8, - 0, - around[0], - mode_for_tx, + neighbours, + leaf_mi, y, px, py, - SIDE, - base_q_idx, &pred_y, - None, - None, + mode_for_tx, + base_q_idx, + scan8, + scan4, + reduced_tx_set, + split8, )?; + luma_grid = grid8; u_grid = read_inter_plane( dec, cdfs, @@ -11713,7 +12108,16 @@ fn decode_inter_block8( // (see its own doc) -- this leaf is always `LAST_FRAME`-only // (grid.set below hardcodes it). let warp_eligible = allow_warped_motion - && num_proj_ref(grid, mi_row, mi_col, 2, 2, mi_cols as usize, mi_rows as usize, LAST_FRAME) >= 1; + && num_proj_ref( + grid, + mi_row, + mi_col, + 2, + 2, + mi_cols as usize, + mi_rows as usize, + LAST_FRAME, + ) >= 1; if warp_eligible { let mode = dec.symbol(&mut cdfs.motion_mode[0]); match mode { @@ -11839,8 +12243,20 @@ fn decode_inter_block8( interintra_blend(v, cpx, cpy, CHROMA_SIDE, ii, wedge_mask, &mut pred_v); } - if skip { - y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); + split8 = read_block_tx_size( + dec, + cdfs, + neighbours, + leaf_mi, + SIDE, + (mi_cols as usize, mi_rows as usize), + true, + skip, + )? + .1 + .is_some(); + if skip { + y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]); u.reconstruct_mc( cpx, cpy, @@ -11860,28 +12276,23 @@ fn decode_inter_block8( v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE]; } else { let around = neighbours.around_mi(leaf_mi, 8); - let luma_tx_type; - (luma_grid, luma_tx_type) = read_inter_plane( + let (grid8, luma_tx_type) = read_inter_luma8( dec, cdfs, - if reduced_tx_set { - TxbSet::Luma8Inter - } else { - TxbSet::Luma8InterSet1 - }, - scan8, - 0, - around[0], - mode_for_tx, + neighbours, + leaf_mi, y, px, py, - SIDE, - base_q_idx, &pred_y, - None, - None, + mode_for_tx, + base_q_idx, + scan8, + scan4, + reduced_tx_set, + split8, )?; + luma_grid = grid8; u_grid = read_inter_plane( dec, cdfs, @@ -11980,6 +12391,16 @@ fn decode_inter_block8( } } + read_block_tx_size( + dec, + cdfs, + neighbours, + leaf_mi, + SIDE, + (mi_cols as usize, mi_rows as usize), + false, + skip, + )?; let reach = Reach::of(SIDE, px, py, y.width, y.height); if skip { y.reconstruct( @@ -12091,8 +12512,38 @@ fn decode_inter_block8( )?; } } + // lane-txselect: a split leaf's plane-0 neighbour context is per 4x4 + // transform unit (written by `record_mi_luma` inside `read_inter_luma8`), + // but `record_mi` rewrites all three planes of these cells at once -- so + // save plane 0 across it, exactly as `record_split_luma` leaves plane 0 + // alone at the bigger block sizes. + let saved_luma_ctx = split8.then(|| { + ( + [ + neighbours.left[leaf_mi.0][0], + neighbours.left[leaf_mi.0 + 1][0], + ], + [ + neighbours.above[leaf_mi.1][0], + neighbours.above[leaf_mi.1 + 1][0], + ], + ) + }); neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); - neighbours.fill_lf_grid(leaf_mi, 2, 8, if is_inter { LAST_FRAME } else { 0 }); + if let Some((left, above)) = saved_luma_ctx { + for (cell, state) in left.into_iter().enumerate() { + neighbours.left[leaf_mi.0 + cell][0] = state; + } + for (cell, state) in above.into_iter().enumerate() { + neighbours.above[leaf_mi.1 + cell][0] = state; + } + } + neighbours.fill_lf_grid( + leaf_mi, + 2, + if split8 { 4 } else { 8 }, + if is_inter { LAST_FRAME } else { 0 }, + ); Ok((skip, is_inter, skip_mode, compound_ctx8)) } @@ -12163,6 +12614,9 @@ pub fn decode_inter_frame_tile( false, [0; 2], true, + // `tx_select`: this raw entry point decodes this crate's own encoder's + // streams, which always write `TxMode::Largest`. + false, false, false, false, @@ -12229,6 +12683,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // `Set1` coefficient tables at 16x16/8x8 rather than the reduced // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]). reduced_tx_set: bool, + // lane-txselect: this frame header's own `tx_mode == TxMode::Select` + // bit (spec 5.9.14). Together with `reduced_tx_set` it is stashed in a + // thread-local by [`set_inter_tx_mode`] rather than threaded through + // `decode_inter_block`'s forty parameters -- both are frame-constant, and + // only [`read_block_tx_size`]/the var-tx residual loop read them. + tx_select: bool, // lane-motionmode round 1/3: this frame header's own `is_motion_mode_switchable`/ // `allow_warped_motion` bits, threaded to every `decode_inter_block`/ // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`). @@ -12245,6 +12705,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // param -- only `q_present`/`q_res` are read. delta: DeltaParams, ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { + set_inter_tx_mode(tx_select, reduced_tx_set); let tpl_frame = tpl_field.map(|field| TplFrameArgs { field, order_hint_bits, @@ -12489,438 +12950,1141 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); TILE_HITS.with(|c| c.set(c.get() + 1)); - for sb_r in sb_r0..sb_r1 { - neighbours.start_row(); - for sb_c in sb_c0..sb_c1 { - crate::restoration::read_lr( - &mut dec, - &mut cdfs, - lr, - &mut lr_grid, - &mut lr_reference, - sb_r * SB_MI, - sb_c * SB_MI, - SB_MI, - ); - CDEF_TRANSMITTED.with(|c| c.set(false)); - let sb_at = (sb_r as usize * 4, sb_c as usize * 4); - let sb_ctx = neighbours.partition_ctx(sb_at, SB); - let (has_cols, has_rows) = ( - sb_c * SB_MI + SB_MI / 2 < mi_cols, - sb_r * SB_MI + SB_MI / 2 < mi_rows, - ); - // The straddle cases (one or both halves outside the true - // frame) never carry a real alphabet symbol -- spec forces - // SPLIT there (mirrors the intra key-frame tile's own - // three-way write above). Only the (true, true) case can name - // a non-SPLIT value, and this loop below only ever recurses as - // SPLIT -- so a real non-SPLIT part64 here must refuse by name - // instead of silently decoding as SPLIT and desyncing. - let part64 = match (has_cols, has_rows) { - (true, true) => { - let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); - if std::env::var_os("EC_AV1_TRACE").is_some() { - eprintln!( - "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p}", - sb_r * SB_MI, - sb_c * SB_MI - ); - } - p - } - (true, false) => { - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)); - PARTITION_SPLIT - } - (false, true) => { - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)); - PARTITION_SPLIT - } - (false, false) => PARTITION_SPLIT, - }; - if part64 != PARTITION_SPLIT { - return Err(unsupported( - "an inter SB-level partition type other than SPLIT (this decoder's \ - inter tile path only recurses a superblock as SPLIT)", - )); - } - - for quadrant in 0..4 { - let (r32, c32) = (sb_r * 2 + quadrant / 2, sb_c * 2 + quadrant % 2); - if r32 >= rows || c32 >= cols { - continue; - } - let at = (r32 as usize * 2, c32 as usize * 2); - let ctx32 = neighbours.partition_ctx(at, BLOCK); - let (has_cols32, has_rows32) = ( - has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), - has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), + for sb_r in sb_r0..sb_r1 { + neighbours.start_row(); + for sb_c in sb_c0..sb_c1 { + crate::restoration::read_lr( + &mut dec, + &mut cdfs, + lr, + &mut lr_grid, + &mut lr_reference, + sb_r * SB_MI, + sb_c * SB_MI, + SB_MI, ); - let part32 = if has_cols32 && has_rows32 { - if std::env::var_os("EC_AV1_TRACE").is_some() { - eprintln!( - "TRACE part32_pre mi=({},{}) rng={}", - r32 * BLOCK_MI, - c32 * BLOCK_MI, - dec.debug_state().0 - ); + CDEF_TRANSMITTED.with(|c| c.set(false)); + let sb_at = (sb_r as usize * 4, sb_c as usize * 4); + let sb_ctx = neighbours.partition_ctx(sb_at, SB); + let (has_cols, has_rows) = ( + sb_c * SB_MI + SB_MI / 2 < mi_cols, + sb_r * SB_MI + SB_MI / 2 < mi_rows, + ); + // The straddle cases (one or both halves outside the true + // frame) never carry a real alphabet symbol -- spec forces + // SPLIT there (mirrors the intra key-frame tile's own + // three-way write above). Only the (true, true) case can name + // a non-SPLIT value, and this loop below only ever recurses as + // SPLIT -- so a real non-SPLIT part64 here must refuse by name + // instead of silently decoding as SPLIT and desyncing. + let part64 = match (has_cols, has_rows) { + (true, true) => { + let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p}", + sb_r * SB_MI, + sb_c * SB_MI + ); + } + p } - let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); - if std::env::var_os("EC_AV1_TRACE").is_some() { - eprintln!( - "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}", - r32 * BLOCK_MI, - c32 * BLOCK_MI - ); + (true, false) => { + dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)); + PARTITION_SPLIT } - p - } else { - match (has_cols32, has_rows32) { - (true, false) => { - dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)); - } - (false, true) => { - dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)); - } - _ => {} + (false, true) => { + dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)); + PARTITION_SPLIT } - PARTITION_SPLIT + (false, false) => PARTITION_SPLIT, }; - match part32 { - PARTITION_NONE => { - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - at, - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - BLOCK, - BLOCK, - allow_screen_content_tools, - frame_width as usize, - )?; + if part64 != PARTITION_SPLIT { + return Err(unsupported( + "an inter SB-level partition type other than SPLIT (this decoder's \ + inter tile path only recurses a superblock as SPLIT)", + )); + } + + for quadrant in 0..4 { + let (r32, c32) = (sb_r * 2 + quadrant / 2, sb_c * 2 + quadrant % 2); + if r32 >= rows || c32 >= cols { + continue; } - PARTITION_SPLIT => { - for sub in 0..4 { - let (sr, sc) = (r32 as usize * 2 + sub / 2, c32 as usize * 2 + sub % 2); - if (sr as u32) * SUB_MI >= mi_rows || (sc as u32) * SUB_MI >= mi_cols { - continue; - } - let (has_cols16, has_rows16) = ( - has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), - has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), + let at = (r32 as usize * 2, c32 as usize * 2); + let ctx32 = neighbours.partition_ctx(at, BLOCK); + let (has_cols32, has_rows32) = ( + has_half(c32 * BLOCK_MI, BLOCK_MI, mi_cols), + has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), + ); + let part32 = if has_cols32 && has_rows32 { + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE part32_pre mi=({},{}) rng={}", + r32 * BLOCK_MI, + c32 * BLOCK_MI, + dec.debug_state().0 ); - if !has_cols16 && !has_rows16 { - return Err(unsupported( - "a 16x16 inter block whose true edge cuts through both \ - axes needs a rectangular transform this decoder does \ - not code yet", - )); + } + let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}", + r32 * BLOCK_MI, + c32 * BLOCK_MI + ); + } + p + } else { + match (has_cols32, has_rows32) { + (true, false) => { + dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)); + } + (false, true) => { + dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)); } - let at16 = (sr, sc); - if has_cols16 && has_rows16 { - let ctx16 = neighbours.partition_ctx(at16, SUB); - let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); - if part16 != PARTITION_NONE { + _ => {} + } + PARTITION_SPLIT + }; + match part32 { + PARTITION_NONE => { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + BLOCK, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + )?; + } + PARTITION_SPLIT => { + for sub in 0..4 { + let (sr, sc) = + (r32 as usize * 2 + sub / 2, c32 as usize * 2 + sub % 2); + if (sr as u32) * SUB_MI >= mi_rows + || (sc as u32) * SUB_MI >= mi_cols + { + continue; + } + let (has_cols16, has_rows16) = ( + has_half(sc as u32 * SUB_MI, SUB_MI, mi_cols), + has_half(sr as u32 * SUB_MI, SUB_MI, mi_rows), + ); + if !has_cols16 && !has_rows16 { return Err(unsupported( - "an inter partition below 16x16 (8x8 and smaller inter blocks are not coded yet)", + "a 16x16 inter block whose true edge cuts through both \ + axes needs a rectangular transform this decoder does \ + not code yet", )); } - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - at16, - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter + let at16 = (sr, sc); + if has_cols16 && has_rows16 { + let ctx16 = neighbours.partition_ctx(at16, SUB); + let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); + if part16 != PARTITION_NONE { + return Err(unsupported( + "an inter partition below 16x16 (8x8 and smaller inter blocks are not coded yet)", + )); + } + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at16, + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + } else { + let ctx16 = neighbours.partition_ctx(at16, SUB); + if has_cols16 { + dec.symbol_fixed(&gather( + &cdfs.partition_w16[ctx16], + VERT_ALIKE, + )); } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - } else { - let ctx16 = neighbours.partition_ctx(at16, SUB); - if has_cols16 { - dec.symbol_fixed(&gather( - &cdfs.partition_w16[ctx16], - VERT_ALIKE, - )); + dec.symbol_fixed(&gather( + &cdfs.partition_w16[ctx16], + HORZ_ALIKE, + )); + } + let (mi_row0, mi_col0) = + (sr as u32 * SUB_MI, sc as u32 * SUB_MI); + let leaf_positions: Vec<(u32, u32)> = (0..4) + .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) + .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) + .collect(); + // lane-superres r9: decode_inter_block8's own + // MC (below) is not threaded for a scaled + // reference (unlike decode_inter_block's 19 + // sites) -- refuse the whole 8x8-leaf split + // up front when ANY live reference this leaf + // could pick has a different width than this + // frame, rather than thread frame_width + // through its own single-ref/compound MC + // calls to reach the same block this round. + if ref_y.width != frame_width as usize + || ref_slots + .iter() + .flatten() + .any(|(py, _, _)| py.width != frame_width as usize) + { + return Err(unsupported( + "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", + )); + } + let mut prev_leaf: Option<((usize, usize), bool, bool)> = None; + let mut last_compound_ctx: Option<(i8, i8, u8, u8)> = None; + let mut last_skip_mode = false; + for (mr, mc) in leaf_positions { + let leaf_mi = (mr as usize, mc as usize); + let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); + let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); + if part8 != PARTITION_NONE { + return Err(unsupported( + "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", + )); + } + let (skip, is_inter, skip_mode_leaf, compound_ctx8) = + decode_inter_block8( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + mi_cols, + mi_rows, + at16, + leaf_mi, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + base_q_idx, + &scan8, + &scan4, + prev_leaf, + allow_high_precision_mv, + force_integer_mv, + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + reduced_tx_set, + interp_fixed, + switchable_motion_mode, + allow_warped_motion, + allow_screen_content_tools, + )?; + prev_leaf = Some((leaf_mi, skip, is_inter)); + last_skip_mode = skip_mode_leaf; + if compound_ctx8.is_some() { + last_compound_ctx = compound_ctx8; + } + } + if let Some((_, skip, is_inter)) = prev_leaf { + // corner-cut: `decode_inter_block8`'s + // leaves never read a switchable filter + // (round-3 GLOBALMV refusal already + // bounds them away from the Regular-only + // gap this round closes elsewhere); `[3, + // 3]` is "no info", the same value an + // intra neighbour records. Upgrade: + // thread `interp_fixed`/`enable_dual_filter` + // into `decode_inter_block8` once a + // straddling 8x8 SWITCHABLE stream is on + // hand to pin against. + neighbours.record_inter( + at16, + SUB, + skip, + is_inter, + if is_inter { LAST_FRAME } else { -1 }, + [3, 3], + last_skip_mode, + ); + if let Some((ref0, ref1, group_idx, idx)) = + last_compound_ctx + { + neighbours.record_inter( + at16, + SUB, + skip, + is_inter, + ref0, + [3, 3], + last_skip_mode, + ); + neighbours.record_compound_ctx( + at16, SUB, ref1, group_idx, idx, + ); + } + } + } + } + } + PARTITION_HORZ_B => { + // lane-warp r5: PARTITION_HORZ_B = 32x32 top strip + + // 16x16 bottom-left + 16x16 bottom-right. aomenc + // carves static regions into it; the strip is + // decoded as a square 32x32 block: for a `skip` + // block the symbol stream is identical to the true + // 32x16 coding (no residual, no motion_mode/warp + // symbol), and the square stamps it leaves over the + // bottom half (neighbour arrays, skip/lf grids) are + // re-stamped by the C/D leaves right after. The + // mi-granular `left_side_mi` rows of a last-block-in- + // tile strip leak 32-vs-16 only until the per-tile + // `Neighbours::new` reset. + EXTENDED_PARTITION_HITS.with(|c| c.set(c.get() + 1)); + let at32 = at; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at32, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + // lane-rect r2: the top strip's TRUE 32x16 + // footprint (was BLOCK,BLOCK -- the same square + // corner-cut rect-flake-1 exposed on HORZ). + BLOCK, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2 + 1), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + } + } + } + PARTITION_HORZ => { + // lane-rect r2: two true 32x16 strips. Both read at + // `side=BLOCK` (CDF/size-class selection stays square, + // matching HORZ_B's accepted corner-cut) but bw4/bh4 + // (mvstack.rs, `motion_mode_eligible`) now derive from + // `write_w`/`write_h`'s true 32x16 footprint -- the + // pin's fix (r1's finding). + RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + BLOCK, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + BLOCK, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + } + PARTITION_VERT => { + // lane-rect r2: mirror of PARTITION_HORZ above with + // width/height swapped. + RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2, c32 as usize * 2 + 1), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + )?; + } + PARTITION_HORZ_A => { + // lane-partab r1: two 16x16 squares on top + a true + // 32x16 strip below (libaom decode_partition + // PARTITION_HORZ_A: TL, TR, bottom strip). + PARTAB_HITS.with(|c| c.set(c.get() + 1)); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2, c32 as usize * 2 + 1), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + BLOCK, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + } + PARTITION_VERT_A => { + // lane-partab r1: mirror of PARTITION_HORZ_A with + // width/height swapped (TL, BL, right 16x32 strip). + PARTAB_HITS.with(|c| c.set(c.get() + 1)); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter } else { - dec.symbol_fixed(&gather( - &cdfs.partition_w16[ctx16], - HORZ_ALIKE, - )); - } - let (mi_row0, mi_col0) = (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let leaf_positions: Vec<(u32, u32)> = (0..4) - .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) - .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) - .collect(); - // lane-superres r9: decode_inter_block8's own - // MC (below) is not threaded for a scaled - // reference (unlike decode_inter_block's 19 - // sites) -- refuse the whole 8x8-leaf split - // up front when ANY live reference this leaf - // could pick has a different width than this - // frame, rather than thread frame_width - // through its own single-ref/compound MC - // calls to reach the same block this round. - if ref_y.width != frame_width as usize - || ref_slots.iter().flatten().any(|(py, _, _)| { - py.width != frame_width as usize - }) - { - return Err(unsupported( - "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", - )); - } - let mut prev_leaf: Option<((usize, usize), bool, bool)> = None; - let mut last_compound_ctx: Option<(i8, i8, u8, u8)> = None; - let mut last_skip_mode = false; - for (mr, mc) in leaf_positions { - let leaf_mi = (mr as usize, mc as usize); - let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); - let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); - if part8 != PARTITION_NONE { - return Err(unsupported( - "a partition below 8x8 (this decoder codes no leaf smaller than 8x8)", - )); - } - let (skip, is_inter, skip_mode_leaf, compound_ctx8) = - decode_inter_block8( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - mi_cols, - mi_rows, - at16, - leaf_mi, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - base_q_idx, - &scan8, - &scan4, - prev_leaf, - allow_high_precision_mv, - force_integer_mv, - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - reduced_tx_set, - interp_fixed, - switchable_motion_mode, - allow_warped_motion, - allow_screen_content_tools, - )?; - prev_leaf = Some((leaf_mi, skip, is_inter)); - last_skip_mode = skip_mode_leaf; - if compound_ctx8.is_some() { - last_compound_ctx = compound_ctx8; - } - } - if let Some((_, skip, is_inter)) = prev_leaf { - // corner-cut: `decode_inter_block8`'s - // leaves never read a switchable filter - // (round-3 GLOBALMV refusal already - // bounds them away from the Regular-only - // gap this round closes elsewhere); `[3, - // 3]` is "no info", the same value an - // intra neighbour records. Upgrade: - // thread `interp_fixed`/`enable_dual_filter` - // into `decode_inter_block8` once a - // straddling 8x8 SWITCHABLE stream is on - // hand to pin against. - neighbours.record_inter( - at16, - SUB, - skip, - is_inter, - if is_inter { LAST_FRAME } else { -1 }, - [3, 3], - last_skip_mode, - ); - if let Some((ref0, ref1, group_idx, idx)) = last_compound_ctx { - neighbours.record_inter( - at16, - SUB, - skip, - is_inter, - ref0, - [3, 3], - last_skip_mode, - ); - neighbours - .record_compound_ctx(at16, SUB, ref1, group_idx, idx); - } - } - } + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2, c32 as usize * 2 + 1), + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + )?; } - } - PARTITION_HORZ_B => { - // lane-warp r5: PARTITION_HORZ_B = 32x32 top strip + - // 16x16 bottom-left + 16x16 bottom-right. aomenc - // carves static regions into it; the strip is - // decoded as a square 32x32 block: for a `skip` - // block the symbol stream is identical to the true - // 32x16 coding (no residual, no motion_mode/warp - // symbol), and the square stamps it leaves over the - // bottom half (neighbour arrays, skip/lf grids) are - // re-stamped by the C/D leaves right after. The - // mi-granular `left_side_mi` rows of a last-block-in- - // tile strip leak 32-vs-16 only until the per-tile - // `Neighbours::new` reset. - EXTENDED_PARTITION_HITS.with(|c| c.set(c.get() + 1)); - let at32 = at; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - at32, - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - // lane-rect r2: the top strip's TRUE 32x16 - // footprint (was BLOCK,BLOCK -- the same square - // corner-cut rect-flake-1 exposed on HORZ). - BLOCK, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows { + PARTITION_VERT_B => { + // lane-partab r1: true 16x32 strip on the left + two + // 16x16 squares on the right (libaom decode_partition + // PARTITION_VERT_B: left strip, TR, BR). + PARTAB_HITS.with(|c| c.set(c.get() + 1)); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + SUB, + BLOCK, + allow_screen_content_tools, + frame_width as usize, + )?; decode_inter_block( &mut dec, &mut cdfs, &mut neighbours, &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2), + (r32 as usize * 2, c32 as usize * 2 + 1), SUB, mi_cols, mi_rows, @@ -12932,7 +14096,60 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( &ref_v, &ref_slots, &sign_bias_table, - &global_motion, + &global_motion, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + SUB, + SUB, + allow_screen_content_tools, + frame_width as usize, + )?; + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize * 2 + 1, c32 as usize * 2 + 1), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, base_q_idx, TxbSet::Luma16, if reduced_tx_set { @@ -12968,764 +14185,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( allow_screen_content_tools, frame_width as usize, )?; - if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols { - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2 + 1), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - } } - } - PARTITION_HORZ => { - // lane-rect r2: two true 32x16 strips. Both read at - // `side=BLOCK` (CDF/size-class selection stays square, - // matching HORZ_B's accepted corner-cut) but bw4/bh4 - // (mvstack.rs, `motion_mode_eligible`) now derive from - // `write_w`/`write_h`'s true 32x16 footprint -- the - // pin's fix (r1's finding). - RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - at, - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - BLOCK, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - BLOCK, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - } - PARTITION_VERT => { - // lane-rect r2: mirror of PARTITION_HORZ above with - // width/height swapped. - RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1)); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - at, - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - SUB, - BLOCK, - allow_screen_content_tools, - frame_width as usize, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2, c32 as usize * 2 + 1), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - SUB, - BLOCK, - allow_screen_content_tools, - frame_width as usize, - )?; - } - PARTITION_HORZ_A => { - // lane-partab r1: two 16x16 squares on top + a true - // 32x16 strip below (libaom decode_partition - // PARTITION_HORZ_A: TL, TR, bottom strip). - PARTAB_HITS.with(|c| c.set(c.get() + 1)); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - at, - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2, c32 as usize * 2 + 1), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - BLOCK, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - } - PARTITION_VERT_A => { - // lane-partab r1: mirror of PARTITION_HORZ_A with - // width/height swapped (TL, BL, right 16x32 strip). - PARTAB_HITS.with(|c| c.set(c.get() + 1)); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - at, - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2, c32 as usize * 2 + 1), - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - SUB, - BLOCK, - allow_screen_content_tools, - frame_width as usize, - )?; - } - PARTITION_VERT_B => { - // lane-partab r1: true 16x32 strip on the left + two - // 16x16 squares on the right (libaom decode_partition - // PARTITION_VERT_B: left strip, TR, BR). - PARTAB_HITS.with(|c| c.set(c.get() + 1)); - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - at, - BLOCK, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma32, - TxbSet::Luma32Inter, - TxbSet::Chroma16, - TX32, - TX16, - &scan32, - &scan16, - 3, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - true, - SUB, - BLOCK, - allow_screen_content_tools, - frame_width as usize, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2, c32 as usize * 2 + 1), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - decode_inter_block( - &mut dec, - &mut cdfs, - &mut neighbours, - &mut grid, - (r32 as usize * 2 + 1, c32 as usize * 2 + 1), - SUB, - mi_cols, - mi_rows, - &mut y, - &mut u, - &mut v, - &ref_y, - &ref_u, - &ref_v, - &ref_slots, - &sign_bias_table, - &global_motion, - base_q_idx, - TxbSet::Luma16, - if reduced_tx_set { - TxbSet::Luma16Inter - } else { - TxbSet::Luma16InterSet1 - }, - TxbSet::Chroma8, - TX16, - TX8, - &scan16, - &scan8, - 2, - allow_high_precision_mv, - force_integer_mv, - interp_fixed, - enable_dual_filter, - tpl_frame.as_ref(), - reference_select, - enable_masked_compound, - enable_interintra_compound, - enable_jnt_comp, - order_hint_bits, - order_hint, - ref_order_hints, - skip_mode_present, - skip_mode_frame, - switchable_motion_mode, - allow_warped_motion, - false, - SUB, - SUB, - allow_screen_content_tools, - frame_width as usize, - )?; - } - _ => { - return Err(unsupported(format!( - "an INTER 32x32 partition type this decoder does not code (value={part32})" - ))); + _ => { + return Err(unsupported(format!( + "an INTER 32x32 partition type this decoder does not code (value={part32})" + ))); + } } } } } - } if tile_num == tile_info.context_update_tile_id { result_cdfs = cdfs; @@ -13760,7 +14229,16 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); let (deblocked_y, deblocked_u, deblocked_v) = (y.clone(), u.clone(), v.clone()); apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours); - apply_loop_restoration(&mut y, &mut u, &mut v, &deblocked_y, &deblocked_u, &deblocked_v, lr, &lr_grid); + apply_loop_restoration( + &mut y, + &mut u, + &mut v, + &deblocked_y, + &deblocked_u, + &deblocked_v, + lr, + &lr_grid, + ); let motion_field = build_motion_field( &grid, @@ -14139,8 +14617,14 @@ mod tests { width, height, y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[luma..luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[luma + chroma..] + .iter() + .map(|&v| u16::from(v)) + .collect(), } } @@ -14186,9 +14670,18 @@ mod tests { Picture { width, height, - y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), + y: out.stdout[base..base + luma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + u: out.stdout[base + luma..base + luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[base + luma + chroma..base + frame_bytes] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) .collect() diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index b84fdf92..2424a52c 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -1098,7 +1098,10 @@ impl Reach { return false; } let table = HAS_TOP_RIGHT_RECT[usize::from(bw == 16)]; - Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) + Self::bit( + table, + (row * Self::table_stride(bw) + col) % (table.len() * 8), + ) } fn bottom_left_rect(bw: usize, bh: usize, x: usize, y: usize) -> bool { @@ -1110,7 +1113,10 @@ impl Reach { return false; } let table = HAS_BOTTOM_LEFT_RECT[usize::from(bw == 16)]; - Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8)) + Self::bit( + table, + (row * Self::table_stride(bw) + col) % (table.len() * 8), + ) } /// Neither, which is all a mode that reads no further than its own edges @@ -3105,8 +3111,14 @@ mod tests { width, height, y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[luma..luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[luma + chroma..] + .iter() + .map(|&v| u16::from(v)) + .collect(), } } @@ -3676,8 +3688,14 @@ mod tests { width, height, y: out.stdout[..luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), + u: out.stdout[luma..luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[luma + chroma..] + .iter() + .map(|&v| u16::from(v)) + .collect(), } } @@ -4409,9 +4427,18 @@ mod tests { Picture { width, height, - y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), + y: out.stdout[base..base + luma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + u: out.stdout[base + luma..base + luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[base + luma + chroma..base + frame_bytes] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) .collect() @@ -4751,8 +4778,14 @@ mod tests { width, height, y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), - u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), + u: bytes[luma..luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: bytes[luma + chroma..] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) } @@ -4878,8 +4911,14 @@ mod tests { width, height, y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), - u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), + u: bytes[luma..luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: bytes[luma + chroma..] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) .collect() diff --git a/crates/ec-av1/src/encoder.rs b/crates/ec-av1/src/encoder.rs index 06b07c32..7e8bcf85 100644 --- a/crates/ec-av1/src/encoder.rs +++ b/crates/ec-av1/src/encoder.rs @@ -680,8 +680,14 @@ mod tests { width, height, y: bytes[..luma].iter().map(|&v| u16::from(v)).collect(), - u: bytes[luma..luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: bytes[luma + chroma..].iter().map(|&v| u16::from(v)).collect(), + u: bytes[luma..luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: bytes[luma + chroma..] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) .collect(), diff --git a/crates/ec-av1/src/gate_coverage.rs b/crates/ec-av1/src/gate_coverage.rs index 5b60712b..aff9ab74 100644 --- a/crates/ec-av1/src/gate_coverage.rs +++ b/crates/ec-av1/src/gate_coverage.rs @@ -32,9 +32,10 @@ /// Each entry is `(flag, why)`. Removing an entry is how a lane records that /// its tool is now covered by a real stream. #[cfg(test)] -const NEVER_EXERCISED: &[(&str, &str)] = &[ - ("enable-intrabc", "intra block copy syntax is consumed but no block is reconstructed from it"), -]; +const NEVER_EXERCISED: &[(&str, &str)] = &[( + "enable-intrabc", + "intra block copy syntax is consumed but no block is reconstructed from it", +)]; #[cfg(test)] mod tests { @@ -51,7 +52,11 @@ mod tests { .split("\n #[") .filter(|body| body.contains("\"--passes=1\"")) .collect(); - assert!(gates.len() >= 20, "expected the real-aomenc gates, found {}", gates.len()); + assert!( + gates.len() >= 20, + "expected the real-aomenc gates, found {}", + gates.len() + ); let mut per_tool: BTreeMap = BTreeMap::new(); let mut names: BTreeSet = BTreeSet::new(); @@ -61,8 +66,12 @@ mod tests { for (i, _) in gate.match_indices("\"--enable-") { let rest = &gate[i + 3..]; let Some(end) = rest.find('"') else { continue }; - let Some((flag, value)) = rest[..end].split_once('=') else { continue }; - let Some(value) = value.chars().next() else { continue }; + let Some((flag, value)) = rest[..end].split_once('=') else { + continue; + }; + let Some(value) = value.chars().next() else { + continue; + }; names.insert(flag.to_owned()); here.insert(flag.to_owned(), value); } @@ -120,10 +129,20 @@ mod tests { #[test] fn tool_settings_reads_whole_flags() { let (gate_count, per_tool) = tool_settings(); - assert!(per_tool.contains_key("enable-cdef"), "expected --enable-cdef among the gate flags"); + assert!( + per_tool.contains_key("enable-cdef"), + "expected --enable-cdef among the gate flags" + ); for (name, &(off, on, defaulted)) in &per_tool { - assert!(!name.is_empty() && !name.contains(['"', '=']), "malformed flag {name:?}"); - assert_eq!(off + on + defaulted, gate_count, "{name} counts do not cover every gate"); + assert!( + !name.is_empty() && !name.contains(['"', '=']), + "malformed flag {name:?}" + ); + assert_eq!( + off + on + defaulted, + gate_count, + "{name} counts do not cover every gate" + ); } } } diff --git a/crates/ec-av1/src/intra.rs b/crates/ec-av1/src/intra.rs index 818779d2..dff64007 100644 --- a/crates/ec-av1/src/intra.rs +++ b/crates/ec-av1/src/intra.rs @@ -768,7 +768,8 @@ pub fn predict_filter_intra( for k in 0..8 { let (r_off, c_off) = (k >> 2, k & 3); let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum(); - let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, crate::decode::sample_max()); + let value = + round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, crate::decode::sample_max()); let idx = (r + r_off) * (side + 1) + c + c_off; buffer[idx] = value; } @@ -908,7 +909,11 @@ mod tests { let left = fill(reach, 2); let corner = ((bw * 3 + bh * 5) % 256) as u16; - for (name, mode) in [("DC", DC_PRED), ("SMOOTH", SMOOTH_PRED), ("PAETH", PAETH_PRED)] { + for (name, mode) in [ + ("DC", DC_PRED), + ("SMOOTH", SMOOTH_PRED), + ("PAETH", PAETH_PRED), + ] { let mut dst = vec![0u16; bw * bh]; predict( mode, @@ -953,7 +958,9 @@ mod tests { let got = checksum(&dst); let key = ("DR", bw, bh, angle, i32::from(ef), i32::from(sn)); let want = *expected.get(&key).unwrap_or_else(|| { - panic!("missing DR {bw}x{bh} angle={angle} ef={ef} sn={sn} in the C dump") + panic!( + "missing DR {bw}x{bh} angle={angle} ef={ef} sn={sn} in the C dump" + ) }); assert_eq!( got, want, diff --git a/crates/ec-av1/src/lib.rs b/crates/ec-av1/src/lib.rs index ca25eff4..41647acb 100644 --- a/crates/ec-av1/src/lib.rs +++ b/crates/ec-av1/src/lib.rs @@ -33,8 +33,8 @@ pub mod quant; mod refusal_inventory; mod restoration; pub mod sequence; -mod superres; pub mod stream; +mod superres; pub mod tile; pub mod transform; mod warp; diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index 3e927d5a..50568684 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -403,7 +403,8 @@ pub fn predict_with_filters( for (t, &tap) in v_filter.iter().enumerate() { sum += tap * intermediate[(row + t) * block_w + col]; } - dst[row * block_w + col] = round2(sum, INTER_ROUND_1).clamp(0, crate::decode::sample_max()) as u16; + dst[row * block_w + col] = + round2(sum, INTER_ROUND_1).clamp(0, crate::decode::sample_max()) as u16; } } @@ -656,7 +657,8 @@ pub fn combine_compound( assert_eq!(dst.len(), pred0.len(), "the destination is the block"); for i in 0..dst.len() { let sum = pred0[i] * fwd_weight + pred1[i] * bck_weight; - dst[i] = round2(sum, INTER_POST_ROUND + DIST_PRECISION_BITS).clamp(0, crate::decode::sample_max()) as u16; + dst[i] = round2(sum, INTER_POST_ROUND + DIST_PRECISION_BITS) + .clamp(0, crate::decode::sample_max()) as u16; } } @@ -719,7 +721,8 @@ pub fn blend_masked_compound( i32::from(mask[i * mask_stride + j]) }; let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6; - dst[i * w + j] = round2(res, INTER_POST_ROUND).clamp(0, crate::decode::sample_max()) as u16; + dst[i * w + j] = + round2(res, INTER_POST_ROUND).clamp(0, crate::decode::sample_max()) as u16; } } } diff --git a/crates/ec-av1/src/motion.rs b/crates/ec-av1/src/motion.rs index d3d5cad6..c2e44e0f 100644 --- a/crates/ec-av1/src/motion.rs +++ b/crates/ec-av1/src/motion.rs @@ -273,7 +273,14 @@ fn search_traced_from_step( let x_q4 = (block_x as i32) * 16 + mv.1 * Q4_PER_Q3; let y_q4 = (block_y as i32) * 16 + mv.0 * Q4_PER_Q3; predict( - &reference16, stride, ref_width, ref_height, x_q4, y_q4, block_w, block_h, + &reference16, + stride, + ref_width, + ref_height, + x_q4, + y_q4, + block_w, + block_h, &mut dst16, ); let sad: f64 = source diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index 96284d7c..951fd4d1 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -1235,8 +1235,16 @@ fn scan_row_compound( found = true; add_compound_candidate( candidates, - if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv }, - if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) }, + if info.is_global_mv0 { + gm_mv(gm, ref_frame.0) + } else { + info.mv + }, + if info.is_global_mv1 { + gm_mv(gm, ref_frame.1) + } else { + info.mv1.unwrap_or((0, 0)) + }, len as u32 * weight, ); *newmv_count += u32::from(info.is_new_mv); @@ -1292,8 +1300,16 @@ fn scan_col_compound( found = true; add_compound_candidate( candidates, - if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv }, - if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) }, + if info.is_global_mv0 { + gm_mv(gm, ref_frame.0) + } else { + info.mv + }, + if info.is_global_mv1 { + gm_mv(gm, ref_frame.1) + } else { + info.mv1.unwrap_or((0, 0)) + }, len as u32 * weight, ); *newmv_count += u32::from(info.is_new_mv); @@ -1326,8 +1342,16 @@ fn scan_top_right_compound( { add_compound_candidate( candidates, - if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv }, - if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) }, + if info.is_global_mv0 { + gm_mv(gm, ref_frame.0) + } else { + info.mv + }, + if info.is_global_mv1 { + gm_mv(gm, ref_frame.1) + } else { + info.mv1.unwrap_or((0, 0)) + }, CORNER_WEIGHT, ); *newmv_count += u32::from(info.is_new_mv); @@ -1356,8 +1380,16 @@ fn scan_corner_compound( { add_compound_candidate( candidates, - if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv }, - if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) }, + if info.is_global_mv0 { + gm_mv(gm, ref_frame.0) + } else { + info.mv + }, + if info.is_global_mv1 { + gm_mv(gm, ref_frame.1) + } else { + info.mv1.unwrap_or((0, 0)) + }, CORNER_WEIGHT, ); *newmv_count += u32::from(info.is_new_mv); @@ -1876,8 +1908,16 @@ fn ref_ctx( b_set: &[i8], ) -> usize { let refs = [above0, above1, left0, left1]; - let a = refs.into_iter().flatten().filter(|r| a_set.contains(r)).count(); - let b = refs.into_iter().flatten().filter(|r| b_set.contains(r)).count(); + let a = refs + .into_iter() + .flatten() + .filter(|r| a_set.contains(r)) + .count(); + let b = refs + .into_iter() + .flatten() + .filter(|r| b_set.contains(r)) + .count(); match a.cmp(&b) { std::cmp::Ordering::Less => 0, std::cmp::Ordering::Equal => 1, @@ -1953,7 +1993,14 @@ pub(crate) fn single_ref_p5_ctx( left0: Option, left1: Option, ) -> usize { - ref_ctx(above0, above1, left0, left1, &[LAST3_FRAME], &[GOLDEN_FRAME]) + ref_ctx( + above0, + above1, + left0, + left1, + &[LAST3_FRAME], + &[GOLDEN_FRAME], + ) } /// `av1_get_pred_context_single_ref_p6` @@ -1964,7 +2011,14 @@ pub(crate) fn single_ref_p6_ctx( left0: Option, left1: Option, ) -> usize { - ref_ctx(above0, above1, left0, left1, &[BWDREF_FRAME], &[ALTREF2_FRAME]) + ref_ctx( + above0, + above1, + left0, + left1, + &[BWDREF_FRAME], + &[ALTREF2_FRAME], + ) } /// `av1_get_pred_context_uni_comp_ref_p1`: `LAST2` vs. `LAST3`/`GOLDEN`, @@ -2658,7 +2712,19 @@ mod tests { let (mv0, mv1) = ((2, 2), (-6, 3)); grid.set(2, 1, comp_inter(mv0, mv1)); - let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, &NO_GM_MV, None); + let stack = find_mv_stack_compound( + &grid, + 2, + 2, + 2, + 2, + COMP_PAIR, + 8, + 8, + &NO_SIGN_BIAS, + &NO_GM_MV, + None, + ); // The exact-pair immediate scan lands one boosted entry; the // compound extension pass (short stack, len < MAX_MV_REF_CANDIDATES) @@ -2682,7 +2748,19 @@ mod tests { grid.set(2, 1, comp_inter(mv0, mv1)); grid.set(3, 1, comp_inter(mv0, mv1)); - let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, &NO_GM_MV, None); + let stack = find_mv_stack_compound( + &grid, + 2, + 2, + 2, + 2, + COMP_PAIR, + 8, + 8, + &NO_SIGN_BIAS, + &NO_GM_MV, + None, + ); // Exact libaom `is_dup` port: with exactly one entry already in the // stack (the four identical-pair neighbours deduped by the @@ -2714,7 +2792,19 @@ mod tests { grid.set(4, 2, comp_inter(left.0, left.1)); grid.set(5, 2, comp_inter(left.0, left.1)); - let stack = find_mv_stack_compound(&grid, 3, 3, 2, 3, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, &NO_GM_MV, None); + let stack = find_mv_stack_compound( + &grid, + 3, + 3, + 2, + 3, + COMP_PAIR, + 8, + 8, + &NO_SIGN_BIAS, + &NO_GM_MV, + None, + ); assert_eq!(stack.entries.len(), 2); assert_eq!(stack.entries[0].mv0, left.0); @@ -2803,7 +2893,19 @@ mod tests { }, ); - let stack = find_mv_stack_compound(&grid, 2, 2, 2, 2, COMP_PAIR, 8, 8, &NO_SIGN_BIAS, &NO_GM_MV, None); + let stack = find_mv_stack_compound( + &grid, + 2, + 2, + 2, + 2, + COMP_PAIR, + 8, + 8, + &NO_SIGN_BIAS, + &NO_GM_MV, + None, + ); // The combine step (libaom's real "Handle compound reference frame // extension") zips each side's ref_id-then-ref_diff lists diff --git a/crates/ec-av1/src/quant.rs b/crates/ec-av1/src/quant.rs index a42166c5..28fc747a 100644 --- a/crates/ec-av1/src/quant.rs +++ b/crates/ec-av1/src/quant.rs @@ -225,7 +225,15 @@ pub fn dequant(levels: &[i32], side: usize, bit_depth: u8, q_idx: i32) -> Vec Vec { +pub fn dequant_wh( + levels: &[i32], + w: usize, + h: usize, + bit_depth: u8, + q_idx: i32, + dc_delta: i32, + ac_delta: i32, +) -> Vec { levels .iter() .enumerate() diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index fb771602..f03c2d15 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -64,7 +64,8 @@ const REFUSALS: &[&str] = &[ "a reference picture whose height does not match this frame's own true size", "a show_existing_frame header naming an empty reference slot", "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): av1_find_projection/the affine warp filter are not ported, only motion_mode_allowed's alphabet choice is", - "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)", + "an inter var-tx tree with a leaf transform larger than 32x32", + "an intra block in an inter frame whose tx_depth splits its luma transform (round 1)", "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)", "an inter frame with no key frame before it", "an inter SB-level partition type other than SPLIT (this decoder's inter tile path only recurses a superblock as SPLIT)", @@ -178,7 +179,11 @@ mod tests { .chain(REFUSALS) .map(|&s| s.to_owned()) .collect(); - assert!(found.len() >= 30, "the refusal scan found only {} reasons -- it is broken, not the decoder", found.len()); + assert!( + found.len() >= 30, + "the refusal scan found only {} reasons -- it is broken, not the decoder", + found.len() + ); let added: Vec<&String> = found.difference(&listed).collect(); assert!( @@ -224,9 +229,14 @@ mod tests { let mut found: BTreeSet = BTreeSet::new(); for (i, _) in src.match_indices("\"SKIP ") { let rest = &src[i + "\"SKIP ".len()..]; - let Some(colon) = rest.find(':') else { continue }; + let Some(colon) = rest.find(':') else { + continue; + }; let name = &rest[..colon]; - if !name.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') { + if !name + .chars() + .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') + { continue; } // The tail of the message says what was skipped. Only "{e}" -- the @@ -239,7 +249,10 @@ mod tests { } } let listed: BTreeSet<&str> = GATES_THAT_SKIP_ON_A_DECODE_ERROR.iter().copied().collect(); - let added: Vec<&String> = found.iter().filter(|n| !listed.contains(n.as_str())).collect(); + let added: Vec<&String> = found + .iter() + .filter(|n| !listed.contains(n.as_str())) + .collect(); assert!( added.is_empty(), "these gates turn a decode error into a printed SKIP and are not declared: \ diff --git a/crates/ec-av1/src/restoration.rs b/crates/ec-av1/src/restoration.rs index ac35db2a..cfb9e6f7 100644 --- a/crates/ec-av1/src/restoration.rs +++ b/crates/ec-av1/src/restoration.rs @@ -62,7 +62,12 @@ fn inverse_recenter(r: u32, v: u32) -> u32 { /// `aom_read_primitive_refsubexpfin` (`inv_recenter_finite_nonneg` composed /// with `read_primitive_subexpfin`): a value in `[0, n)` recentred around /// `reference`. -fn decode_unsigned_subexp_with_ref_msac(dec: &mut SymbolDecoder, n: u32, k: u32, reference: u32) -> u32 { +fn decode_unsigned_subexp_with_ref_msac( + dec: &mut SymbolDecoder, + n: u32, + k: u32, + reference: u32, +) -> u32 { let v = decode_subexp_msac(dec, n, k); if (reference << 1) <= n { inverse_recenter(reference, v) @@ -73,7 +78,13 @@ fn decode_unsigned_subexp_with_ref_msac(dec: &mut SymbolDecoder, n: u32, k: u32, /// Signed wrapper, matching the way `read_wiener_filter`/`read_sgrproj_filter` /// call `aom_read_primitive_refsubexpfin(rb, max-min+1, k, ref-min)+min`. -fn decode_signed_subexp_with_ref_msac(dec: &mut SymbolDecoder, low: i32, high: i32, k: u32, reference: i32) -> i32 { +fn decode_signed_subexp_with_ref_msac( + dec: &mut SymbolDecoder, + low: i32, + high: i32, + k: u32, + reference: i32, +) -> i32 { let n = (high - low) as u32; let r = (reference - low).clamp(0, n as i32) as u32; decode_unsigned_subexp_with_ref_msac(dec, n, k, r) as i32 + low @@ -138,7 +149,11 @@ fn read_wiener_direction(dec: &mut SymbolDecoder, chroma: bool, reference: &[i32 /// `read_wiener_filter` (decodeframe.c ~1595): both directions, updating /// `reference` in place (the running per-plane, per-tile reference state). -fn read_wiener_filter(dec: &mut SymbolDecoder, chroma: bool, reference: &mut WienerInfo) -> WienerInfo { +fn read_wiener_filter( + dec: &mut SymbolDecoder, + chroma: bool, + reference: &mut WienerInfo, +) -> WienerInfo { let vfilter = read_wiener_direction(dec, chroma, &reference.vfilter); let hfilter = read_wiener_direction(dec, chroma, &reference.hfilter); let info = WienerInfo { vfilter, hfilter }; @@ -539,7 +554,9 @@ fn apply_wiener_stripe( for (t, &tap) in info.hfilter.iter().enumerate() { let x = col - 3 + t as i64; sum += tap as i64 - * lr_sample(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, x) as i64; + * lr_sample( + cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, x, + ) as i64; } // `WIENER_CLAMP_LIMIT(round0=3, bd=8) - 1`. inter[r * w + c] = round2(sum, 3).clamp(0, 8191) as i32; @@ -551,7 +568,8 @@ fn apply_wiener_stripe( for (t, &tap) in info.vfilter.iter().enumerate() { sum += tap as i64 * inter[(r + t) * w + c] as i64; } - out[(v_start + r) * stride + h_start + c] = round2(sum, 11).clamp(0, crate::decode::sample_max() as i64) as u16; + out[(v_start + r) * stride + h_start + c] = + round2(sum, 11).clamp(0, crate::decode::sample_max() as i64) as u16; } } } @@ -568,31 +586,27 @@ fn apply_wiener_stripe( // `~/.cache/aom-oracle/src/av1/common/restoration.c` to rule out any other // transcription slip. const SGR_X_BY_XPLUS1: [i32; 256] = [ - 1, 128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239, - 240, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 247, 247, - 248, 248, 248, 248, 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250, - 250, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 252, 252, 252, 252, - 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, - 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, - 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 256, + 1, 128, 171, 192, 205, 213, 219, 224, 228, 230, 233, 235, 236, 238, 239, 240, 241, 242, 243, + 243, 244, 244, 245, 245, 246, 246, 247, 247, 247, 247, 248, 248, 248, 248, 249, 249, 249, 249, + 249, 250, 250, 250, 250, 250, 250, 250, 251, 251, 251, 251, 251, 251, 251, 251, 251, 251, 252, + 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 253, 253, 253, + 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, + 253, 253, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, + 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, + 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, + 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 256, ]; /// `av1_one_by_x` (`restoration.c`): `round(4096/n)` for `n` in `1..=25` /// (`MAX_NELEM`, `(2*MAX_RADIUS+1)^2`), indexed `[n-1]`. const SGR_ONE_BY_X: [i32; 25] = [ - 4096, 2048, 1365, 1024, 819, 683, 585, 512, 455, 410, 372, 341, 315, 293, 273, 256, 241, 228, 216, 205, 195, 186, - 178, 171, 164, + 4096, 2048, 1365, 1024, 819, 683, 585, 512, 455, 410, 372, 341, 315, 293, 273, 256, 241, 228, + 216, 205, 195, 186, 178, 171, 164, ]; const SGRPROJ_MTABLE_BITS: u32 = 20; @@ -640,8 +654,9 @@ fn compute_ab( let row = v_start as i64 + i + dr as i64; for dc in -r..=r { let col = h_start as i64 + j + dc as i64; - let px = - lr_sample(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, col) as i64; + let px = lr_sample( + cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, col, + ) as i64; a += px * px; b += px; } @@ -697,8 +712,16 @@ fn apply_sgrproj_stripe( let gw = w + 2; let idx = |gi: i64, gj: i64| -> usize { (gi + 1) as usize * gw + (gj + 1) as usize }; - let ab0 = (r0 > 0).then(|| compute_ab(cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r0, s0)); - let ab1 = (r1 > 0).then(|| compute_ab(cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r1, s1)); + let ab0 = (r0 > 0).then(|| { + compute_ab( + cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r0, s0, + ) + }); + let ab1 = (r1 > 0).then(|| { + compute_ab( + cdef, deblocked, stride, plane_w, plane_h, h_start, v_start, v_end, w, h, r1, s1, + ) + }); // r8: call-unique debug dump -- r6's coordinate-only gate (`v_start==60`) // matched several unrelated calls across the gate's attempt sweep, so its @@ -711,7 +734,9 @@ fn apply_sgrproj_stripe( let bytes: Vec = (59..=61) .flat_map(|row| { (5..=7).map(move |col| { - lr_sample(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, col) + lr_sample( + cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, col, + ) }) }) .collect(); @@ -788,7 +813,8 @@ fn apply_sgrproj_stripe( let (a_ur, b_ur) = ab[idx(i - 1, j + 1)]; let (a_dl, b_dl) = ab[idx(i + 1, j - 1)]; let (a_dr, b_dr) = ab[idx(i + 1, j + 1)]; - let a = (a_c + a_u + a_d + a_l + a_r) as i64 * 4 + (a_ul + a_ur + a_dl + a_dr) as i64 * 3; + let a = (a_c + a_u + a_d + a_l + a_r) as i64 * 4 + + (a_ul + a_ur + a_dl + a_dr) as i64 * 3; let b = (b_c + b_u + b_d + b_l + b_r) * 4 + (b_ul + b_ur + b_dl + b_dr) * 3; let flt1 = round2(a * dgd + b, SGRPROJ_SGR_BITS + 5 - SGRPROJ_RST_BITS); v += xq[1] as i64 * (flt1 - u); @@ -801,13 +827,20 @@ fn apply_sgrproj_stripe( "EC_LR_CALL_DUMP combine: c={:?} u_tap(row60)={:?} d={:?} l={:?} r={:?} \ ul={:?} ur={:?} dl={:?} dr={:?} dense a={a} b={b} dgd={dgd} \ u={u} flt1={flt1} xq={xq:?} v_before_final_round={v}", - ab[idx(i, j)], ab[idx(i - 1, j)], ab[idx(i + 1, j)], ab[idx(i, j - 1)], - ab[idx(i, j + 1)], ab[idx(i - 1, j - 1)], ab[idx(i - 1, j + 1)], - ab[idx(i + 1, j - 1)], ab[idx(i + 1, j + 1)] + ab[idx(i, j)], + ab[idx(i - 1, j)], + ab[idx(i + 1, j)], + ab[idx(i, j - 1)], + ab[idx(i, j + 1)], + ab[idx(i - 1, j - 1)], + ab[idx(i - 1, j + 1)], + ab[idx(i + 1, j - 1)], + ab[idx(i + 1, j + 1)] ); } } - let out_v = round2(v, SGRPROJ_PRJ_BITS as u32 + SGRPROJ_RST_BITS).clamp(0, crate::decode::sample_max() as i64) as u16; + let out_v = round2(v, SGRPROJ_PRJ_BITS as u32 + SGRPROJ_RST_BITS) + .clamp(0, crate::decode::sample_max() as i64) as u16; out[(v_start as i64 + i) as usize * stride + (h_start as i64 + j) as usize] = out_v; } } @@ -847,10 +880,30 @@ fn filter_restoration_unit( let stripe_v_end = stripe_v_start + h; match filter { UnitFilter::Wiener(info) => apply_wiener_stripe( - out, cdef, deblocked, stride, plane_w, plane_h, h_start, h_end, stripe_v_start, stripe_v_end, &info, + out, + cdef, + deblocked, + stride, + plane_w, + plane_h, + h_start, + h_end, + stripe_v_start, + stripe_v_end, + &info, ), UnitFilter::Sgrproj(info) => apply_sgrproj_stripe( - out, cdef, deblocked, stride, plane_w, plane_h, h_start, h_end, stripe_v_start, stripe_v_end, &info, + out, + cdef, + deblocked, + stride, + plane_w, + plane_h, + h_start, + h_end, + stripe_v_start, + stripe_v_end, + &info, ), UnitFilter::None => {} } @@ -893,7 +946,11 @@ pub(crate) fn apply_loop_restoration_plane( let mut rrow = 0usize; while y0 < plane_h as u32 { let remaining_h = plane_h as u32 - y0; - let uh = if remaining_h < ext_size { remaining_h } else { unit_size }; + let uh = if remaining_h < ext_size { + remaining_h + } else { + unit_size + }; let v_start = (y0 as i64 - voffset as i64).max(0) as u32; let mut v_end = y0 + uh; if v_end < plane_h as u32 { @@ -904,7 +961,11 @@ pub(crate) fn apply_loop_restoration_plane( let mut rcol = 0usize; while x0 < plane_w as u32 { let remaining_w = plane_w as u32 - x0; - let uw = if remaining_w < ext_size { remaining_w } else { unit_size }; + let uw = if remaining_w < ext_size { + remaining_w + } else { + unit_size + }; let filter = grid.get(plane, rrow, rcol); if filter != UnitFilter::None { filter_restoration_unit( @@ -928,7 +989,10 @@ pub(crate) fn apply_loop_restoration_plane( y0 += uh; rrow += 1; } - debug_assert_eq!(rrow, grid.vert_units[plane], "RU row walk must match RestorationGrid::new's count_units"); + debug_assert_eq!( + rrow, grid.vert_units[plane], + "RU row walk must match RestorationGrid::new's count_units" + ); out } @@ -985,7 +1049,13 @@ mod tests { } } - fn write_unsigned_subexp_with_ref(enc: &mut SymbolEncoder, n: u32, k: u32, reference: u32, v: u32) { + fn write_unsigned_subexp_with_ref( + enc: &mut SymbolEncoder, + n: u32, + k: u32, + reference: u32, + v: u32, + ) { let r = reference.clamp(0, n.saturating_sub(1)); let coded = if (r << 1) <= n { recenter(r, v) @@ -1001,7 +1071,15 @@ mod tests { /// `SGRPROJ_PRJ_MAX-MIN+1`. #[test] fn subexp_roundtrips_every_value() { - for &(num_syms, k) in &[(16u32, 1u32), (32, 2), (64, 3), (96, 4), (128, 4), (3, 1), (1, 3)] { + for &(num_syms, k) in &[ + (16u32, 1u32), + (32, 2), + (64, 3), + (96, 4), + (128, 4), + (3, 1), + (1, 3), + ] { for v in 0..num_syms { let mut enc = SymbolEncoder::new(); write_subexp(&mut enc, num_syms, k, v); @@ -1039,10 +1117,10 @@ mod tests { #[test] fn signed_subexp_with_ref_roundtrips() { let cases: [(i32, i32, u32); 4] = [ - (-5, 11, 1), // Wiener tap0 - (-23, 9, 2), // Wiener tap1 - (-17, 47, 3), // Wiener tap2 - (-96, 32, 4), // SGR xqd0 + (-5, 11, 1), // Wiener tap0 + (-23, 9, 2), // Wiener tap1 + (-17, 47, 3), // Wiener tap2 + (-96, 32, 4), // SGR xqd0 ]; for (low, high, k) in cases { let n = (high - low) as u32; @@ -1054,8 +1132,12 @@ mod tests { write_unsigned_subexp_with_ref(&mut enc, n, k, r, coded_v); let payload = enc.finish(); let mut dec = SymbolDecoder::new(&payload); - let got = decode_signed_subexp_with_ref_msac(&mut dec, low, high, k, reference_v); - assert_eq!(got, v, "low={low} high={high} k={k} reference={reference_v} v={v}"); + let got = + decode_signed_subexp_with_ref_msac(&mut dec, low, high, k, reference_v); + assert_eq!( + got, v, + "low={low} high={high} k={k} reference={reference_v} v={v}" + ); } } } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 8a2b0df0..6c78187b 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -195,24 +195,13 @@ pub fn decode_stream(data: &[u8]) -> Result> { // now read (`maybe_read_cdef_idx` in decode.rs) and threaded into // [`crate::decode::apply_cdef`]'s per-superblock strength lookup, so // a `cdef_bits > 0` stream no longer needs this refusal. - // An intra frame's `decode_key_frame_tile*` now reads `tx_depth` - // under `TxMode::Select` (lane-av1txsel, spec 5.11.16): the key-frame - // decode path threads `tx_select` through `decode_block`/ - // `decode_leaf8`, and refuses on its own (a named `unsupported`, not - // a silent desync) the one case it still cannot code -- a resolved - // 4x4 luma transform, which has no coefficient tables here. This - // refusal is narrowed to what genuinely still has no reader at all: - // `decode_inter_frame`'s inter path never threads `tx_select` - // through its own block loop, so an inter frame under - // `TxMode::Select` still desyncs the same way the comment above used - // to describe for every frame -- lane-av1real r3's - // luma-near-flat-vs-ffmpeg-gradient bug. - if header.tx_mode == TxMode::Select && header.frame_type != FrameType::Key { - return Err(Error::unsupported( - "AV1 decode_stream", - "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)", - )); - } + // Both frame types now read their transform size under + // `TxMode::Select`: an intra frame's `decode_key_frame_tile*` reads + // `tx_depth` (lane-av1txsel, spec 5.11.16), and an inter frame's + // `decode_inter_block`/`decode_inter_block8` read the recursive + // `txfm_split` var-tx tree (lane-txselect, spec 5.11.17) -- so the + // blanket inter-frame refusal that used to stand here is gone. What + // remains refused is named at its own site in `read_block_tx_size`. // lane-av1real r11's blindness-audit sweep (`read_intra_frame_mode_info`, // libaom decodemv.c): three more per-block/per-SB symbols this crate // never reads at all, each gated by a header field this decoder @@ -615,6 +604,7 @@ pub fn decode_stream(data: &[u8]) -> Result> { header.skip_mode_present, header.skip_mode_frame, header.reduced_tx_set, + header.tx_mode == TxMode::Select, header.is_motion_mode_switchable, header.allow_warped_motion, header.allow_screen_content_tools, @@ -931,9 +921,18 @@ mod tests { Pic { width, height, - y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(), - u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(), - v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(), + y: out.stdout[base..base + luma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + u: out.stdout[base + luma..base + luma + chroma] + .iter() + .map(|&v| u16::from(v)) + .collect(), + v: out.stdout[base + luma + chroma..base + frame_bytes] + .iter() + .map(|&v| u16::from(v)) + .collect(), } }) .collect() @@ -952,8 +951,17 @@ mod tests { ) -> Vec { let mut child = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", - "yuv420p10le", "-", + "-v", + "error", + "-f", + "obu", + "-i", + "-", + "-f", + "rawvideo", + "-pix_fmt", + "yuv420p10le", + "-", ]) .stdin(Stdio::piped()) .stdout(Stdio::piped()) @@ -1195,7 +1203,9 @@ mod tests { hash_color(seed, 2), hash_color(seed, 3), ); - format!("gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}") + format!( + "gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}" + ) } /// The determinism guard: same seed twice must byte-match ffmpeg's own @@ -1210,7 +1220,16 @@ mod tests { fn render_hash(lavfi: &str) -> Vec { let out = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", lavfi, "-frames:v", "1", "-f", "rawvideo", + "-v", + "error", + "-f", + "lavfi", + "-i", + lavfi, + "-frames:v", + "1", + "-f", + "rawvideo", "-", ]) .stdin(Stdio::null()) @@ -2333,6 +2352,215 @@ mod tests { ); } + /// lane-txselect's decisive gate: a real aomenc INTER sequence WITHOUT + /// `--enable-tx-size-search=0`, the flag every other inter recipe in this + /// file pins off precisely to keep the stream on `TxMode::Largest`. + /// Dropped, aomenc takes its own default (`TX_MODE_SELECT` -- which is + /// what both of the user's real films use), and an inter block's + /// transform size is then the recursive `txfm_split` tree of spec + /// 5.11.17 rather than one whole-block transform. A stream that decoded + /// pixel-exact while every `txfm_split` symbol resolved to "no split" + /// would prove nothing (it is `TxMode::Largest` by another name), so this + /// gate hard-asserts BOTH counters: at least one `txfm_split` symbol read + /// AND at least one split actually taken. Exhausting every attempt is a + /// FAILURE, not a SKIP -- an unfired gate is a vacuous gate. + #[test] + fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact() { + if !have_ffmpeg() { + eprintln!( + "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no ffmpeg" + ); + return; + } + if !have_aomenc() { + eprintln!( + "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no aomenc at {}", + aomenc_path().display() + ); + return; + } + let (width, height, frame_count) = (64usize, 64usize, 4usize); + let mut refusals = Vec::new(); + for attempt in 0..40u32 { + let seed = 42 + attempt; + // Detail is what makes aomenc's RD prefer a split transform; a + // flat gradient resolves every `txfm_split` to 0. `mandelbrot`'s + // fractal boundary is the same source the sibling intra tx-select + // gate uses, at a different `start_scale` per attempt. + let source = format!( + "mandelbrot=size=64x64:start_scale={}:rate=25", + 5.0 - f64::from(attempt) * 0.06 + ); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + // Desaturated chroma: `uv_mode` stays DC_PRED, so the + // still-refused directional-chroma gap never fires and + // luma detail alone drives the transform split. + "-vf", + "hue=s=0", + "-pix_fmt", + "yuv420p", + "-t", + "0.16", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=55", + "--cpu-used=0", + "--lag-in-frames=0", + "--auto-alt-ref=0", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--enable-order-hint=0", + "--enable-warped-motion=0", + "--enable-obmc=0", + "--enable-masked-comp=0", + "--enable-interintra-comp=0", + "--enable-dist-wtd-comp=0", + "--enable-diff-wtd-comp=0", + "--enable-onesided-comp=0", + "--enable-interintra-wedge=0", + "--enable-smooth-interintra=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + // DELIBERATELY ABSENT: --enable-tx-size-search=0. + "--enable-cdef=0", + "--enable-restoration=0", + "--max-partition-size=32", + // Sub-16 inter partitions are a separate named refusal + // (this decoder codes no inter block below 16x16 through + // the square path this gate drives), and detailed content + // makes aomenc's RD reach for them on nearly every seed. + "--min-partition-size=16", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--obu", + "-o", + "-", + "-", + ]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let (reads_before, hits_before) = + (decode::txfm_split_reads(), decode::txfm_split_hits()); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "tx-select inter decode failed outright (seed {seed}): {msg}" + ); + refusals.push(format!("seed {seed}: {msg}")); + continue; + } + }; + let (reads, hits) = ( + decode::txfm_split_reads() - reads_before, + decode::txfm_split_hits() - hits_before, + ); + if hits == 0 { + refusals.push(format!( + "seed {seed}: decoded, but no block took a txfm_split ({reads} symbols read)" + )); + continue; + } + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); + assert_eq!(frames.len(), frame_count); + eprintln!("txselect gate seed={seed}: txfm_split reads={reads} splits taken={hits}"); + // Name the first differing sample before the assert fires: a + // 64x64 plane's `assert_eq!` output is 4096 numbers, useless for + // locating a desync. + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + for (plane, (g, w)) in [ + ("Y", (&got.y, &want.y)), + ("U", (&got.u, &want.u)), + ("V", (&got.v, &want.v)), + ] { + let stride = if plane == "Y" { width } else { width / 2 }; + if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) { + eprintln!( + "txselect gate seed={seed}: frame {i} {plane} first diff at \ + ({}, {}) got {} want {} ({} samples differ)", + at % stride, + at / stride, + g[at], + w[at], + g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(), + ); + let coords: Vec = g + .iter() + .zip(w.iter()) + .enumerate() + .filter(|(_, (a, b))| a != b) + .take(12) + .map(|(k, (a, b))| format!("({},{})={a}/{b}", k % stride, k / stride)) + .collect(); + eprintln!("txselect gate seed={seed}: frame {i} {plane} diffs {coords:?}"); + } + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})"); + assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})"); + } + return; + } + panic!( + "a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact never observed a \ + taken txfm_split:\n{}", + refusals.join("\n") + ); + } + /// lane-chroma r2 stage 1: a real aomenc key frame with /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`) /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still- @@ -2506,8 +2734,19 @@ mod tests { ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-t", - "0.04", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-t", + "0.04", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -2779,13 +3018,7 @@ mod tests { let y4m = Command::new("ffmpeg") .args(["-v", "error", "-f", "lavfi", "-i"]) .arg(&source) - .args([ - "-pix_fmt", - "yuv420p", - "-f", - "yuv4mpegpipe", - "-", - ]) + .args(["-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-"]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) @@ -2893,7 +3126,10 @@ mod tests { if !ok { let pin = std::env::temp_dir().join("ec-av1-deblocking-gate-fail.obu"); let _ = std::fs::write(&pin, &stream); - panic!("frame {i} mismatch vs ffmpeg -- stream pinned at {}", pin.display()); + panic!( + "frame {i} mismatch vs ffmpeg -- stream pinned at {}", + pin.display() + ); } } } @@ -3828,32 +4064,41 @@ mod tests { .zip(&ffmpeg_frames) .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); if mismatched { - let pin = std::env::temp_dir().join("ec-av1-reference-select-gate-fail.obu"); + let pin = + std::env::temp_dir().join("ec-av1-reference-select-gate-fail.obu"); let _ = std::fs::write(&pin, &stream); if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { std::fs::write(&path, &stream).expect("writing pinned stream"); - eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); + eprintln!( + "EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}" + ); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!( - got.y, want.y, + got.y, + want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); assert_eq!( - got.u, want.u, + got.u, + want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); assert_eq!( - got.v, want.v, + got.v, + want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); } } else { for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -4024,17 +4269,20 @@ mod tests { } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { assert_eq!( - got.y, want.y, + got.y, + want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); assert_eq!( - got.u, want.u, + got.u, + want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); assert_eq!( - got.v, want.v, + got.v, + want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed}) -- stream pinned at {}", pin.display() ); @@ -4198,7 +4446,10 @@ mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -4389,7 +4640,10 @@ mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -4555,7 +4809,10 @@ mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -4679,8 +4936,7 @@ mod tests { if let Ok(path) = std::env::var("EC_SUPERRES_STREAM_DUMP") { std::fs::write(path, &stream).expect("dump stream"); } - let frames = - decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); + let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); assert_eq!(frames.len(), frame_count); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { @@ -4825,8 +5081,7 @@ mod tests { if let Ok(path) = std::env::var("EC_SUPERRES_INTER_STREAM_DUMP") { std::fs::write(&path, &stream).expect("dump stream"); } - let frames = - decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); + let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}")); assert_eq!(frames.len(), frame_count); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { @@ -5004,7 +5259,10 @@ mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -5184,7 +5442,10 @@ mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -5505,7 +5766,10 @@ mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -5706,7 +5970,10 @@ mod tests { let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); assert_eq!(frames.len(), frame_count); for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -5912,7 +6179,10 @@ mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -5953,7 +6223,6 @@ mod tests { ); } - /// lane-lr r3: proves stage 1/2's exit criterion -- a real /// `--enable-restoration=1` aomenc stream must survive the whole /// partition walk (every symbol read entropy-exact) and land on the @@ -6082,9 +6351,18 @@ mod tests { ); } for (i, (pic, refpic)) in pics.iter().zip(reference.iter()).enumerate() { - assert_eq!(pic.y, refpic.y, "{NAME}: luma mismatch (seed {seed} frame {i})"); - assert_eq!(pic.u, refpic.u, "{NAME}: U mismatch (seed {seed} frame {i})"); - assert_eq!(pic.v, refpic.v, "{NAME}: V mismatch (seed {seed} frame {i})"); + assert_eq!( + pic.y, refpic.y, + "{NAME}: luma mismatch (seed {seed} frame {i})" + ); + assert_eq!( + pic.u, refpic.u, + "{NAME}: U mismatch (seed {seed} frame {i})" + ); + assert_eq!( + pic.v, refpic.v, + "{NAME}: V mismatch (seed {seed} frame {i})" + ); } lr_refusals += 1; // reused below as "attempts that actually exercised LR pixels" } @@ -6344,7 +6622,10 @@ mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -6373,8 +6654,16 @@ mod tests { eprintln!("SKIP: no ffmpeg/aomenc"); return; } - let sizes: &[(usize, usize)] = - &[(8, 8), (16, 16), (32, 32), (16, 32), (32, 16), (64, 64), (48, 48), (24, 24)]; + let sizes: &[(usize, usize)] = &[ + (8, 8), + (16, 16), + (32, 32), + (16, 32), + (32, 16), + (64, 64), + (48, 48), + (24, 24), + ]; for &(width, height) in sizes { let mut ok = 0u32; let mut bad = 0u32; @@ -6389,26 +6678,53 @@ mod tests { ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", - "yuv420p", "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + "0.04", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) .output() .expect("ffmpeg failed to run"); - assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); let max_part = width.max(height).min(64).next_power_of_two(); let min_part = width.min(height).next_power_of_two().max(8).min(max_part); let max_part_arg = format!("--max-partition-size={max_part}"); let min_part_arg = format!("--min-partition-size={min_part}"); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", - "--cpu-used=4", "--kf-max-dist=0", "--limit=1", "--threads=1", - "--row-mt=0", "--enable-rect-partitions=0", "--enable-ab-partitions=0", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=32", + "--cpu-used=4", + "--kf-max-dist=0", + "--limit=1", + "--threads=1", + "--row-mt=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - &max_part_arg, &min_part_arg, - "--obu", "-o", "-", "-", + &max_part_arg, + &min_part_arg, + "--obu", + "-o", + "-", + "-", ]; let mut child = Command::new(aomenc_path()) .args(&args) @@ -6417,9 +6733,18 @@ mod tests { .stderr(Stdio::piped()) .spawn() .expect("aomenc failed to start"); - child.stdin.take().expect("aomenc stdin").write_all(&y4m.stdout).expect("write y4m"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("write y4m"); let out = child.wait_with_output().expect("aomenc failed to run"); - assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr)); + assert!( + out.status.success(), + "aomenc refused: {}", + String::from_utf8_lossy(&out.stderr) + ); let stream = out.stdout; let frames = match decode_stream(&stream) { Err(e) => { @@ -6486,8 +6811,19 @@ mod tests { ); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-t", "0.04", "-pix_fmt", "yuv420p", - "-f", "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-t", + "0.04", + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -6496,12 +6832,25 @@ mod tests { .expect("ffmpeg failed to run"); assert!(y4m.status.success()); let args: Vec<&str> = vec![ - "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", "--cpu-used=4", - "--kf-max-dist=0", "--limit=1", "--threads=1", "--row-mt=0", - "--enable-rect-partitions=0", "--enable-ab-partitions=0", - "--enable-1to4-partitions=0", "--max-partition-size=32", "--min-partition-size=32", + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=32", + "--cpu-used=4", + "--kf-max-dist=0", + "--limit=1", + "--threads=1", + "--row-mt=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--max-partition-size=32", + "--min-partition-size=32", "--enable-filter-intra=0", - "--obu", "-o", "-", "-", + "--obu", + "-o", + "-", + "-", ]; let mut child = Command::new(aomenc_path()) .args(&args) @@ -6589,9 +6938,9 @@ mod tests { // below it, blending the wrong OBMC prediction there. "rect-flake-3", ] - .iter() - .map(|n| format!("{fixtures}/{n}.obu")) - .collect(), + .iter() + .map(|n| format!("{fixtures}/{n}.obu")) + .collect(), }; for path in paths { eprintln!("pin: {path}"); @@ -7590,9 +7939,18 @@ mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + picture.y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -7804,9 +8162,18 @@ mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + picture.y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -7843,8 +8210,17 @@ mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -7930,12 +8306,25 @@ mod tests { "{NAME}: tile_hits delta was {hits}, expected >1 -- both tile rows must actually \ decode, not just tile 0 (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -7976,8 +8365,17 @@ mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -8126,9 +8524,18 @@ mod tests { ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + picture.y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + picture.v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -8178,8 +8585,17 @@ mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -8283,12 +8699,25 @@ mod tests { "{NAME}: tile_hits delta was {hits}, expected >2 -- all four tile rows must \ actually decode, not just a subset (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -8320,7 +8749,8 @@ mod tests { /// comment used to describe are gone from `decode_stream`. #[test] fn a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream() { - const NAME: &str = "a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream"; + const NAME: &str = + "a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream"; if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); return; @@ -8337,8 +8767,17 @@ mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -8425,12 +8864,25 @@ mod tests { "{NAME}: tile_hits delta was {hits}, expected >1 -- both tiles must actually \ decode, not just tile 0 (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -8615,7 +9067,10 @@ mod tests { eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -8681,8 +9136,17 @@ mod tests { let source = gradients_source(seed, width, height, "duration=0.08:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -8806,11 +9270,18 @@ mod tests { "{NAME}: tile_hits delta was {hits}, expected > {frames} -- both tiles of both \ frames must actually decode (seed {seed})" ); - assert_eq!(pictures.len(), frames, "{NAME}: expected {frames} pictures (seed {seed})"); + assert_eq!( + pictures.len(), + frames, + "{NAME}: expected {frames} pictures (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames); for (i, (got, want)) in pictures.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME}: seed {seed} frame {i} luma vs ffmpeg"); + assert_eq!( + got.y, want.y, + "{NAME}: seed {seed} frame {i} luma vs ffmpeg" + ); assert_eq!(got.u, want.u, "{NAME}: seed {seed} frame {i} U vs ffmpeg"); assert_eq!(got.v, want.v, "{NAME}: seed {seed} frame {i} V vs ffmpeg"); } @@ -8862,8 +9333,17 @@ mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -8964,12 +9444,25 @@ mod tests { hits > 0, "{NAME}: tile_hits delta was {hits}, expected >0 (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -9032,8 +9525,17 @@ mod tests { let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); let y4m = Command::new("ffmpeg") .args([ - "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", - "yuv4mpegpipe", "-", + "-v", + "error", + "-f", + "lavfi", + "-i", + &source, + "-pix_fmt", + "yuv420p", + "-f", + "yuv4mpegpipe", + "-", ]) .stdin(Stdio::null()) .stdout(Stdio::piped()) @@ -9145,12 +9647,25 @@ mod tests { hits > 0, "{NAME}: tile_hits delta was {hits}, expected >0 (seed {seed})" ); - assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + assert_eq!( + pictures.len(), + 1, + "{NAME}: expected exactly 1 picture (seed {seed})" + ); let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); - assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); - assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + assert_eq!( + pictures[0].y, ffmpeg_frames[0].y, + "{NAME}: luma vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].u, ffmpeg_frames[0].u, + "{NAME}: U vs ffmpeg (seed {seed})" + ); + assert_eq!( + pictures[0].v, ffmpeg_frames[0].v, + "{NAME}: V vs ffmpeg (seed {seed})" + ); matched += 1; } assert!( @@ -9311,7 +9826,10 @@ mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } @@ -9353,9 +9871,8 @@ mod tests { #[test] #[ignore = "drift never observed this round -- see lanes/rect64q-r1.report.md"] fn a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact() - { - const NAME: &str = - "a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact"; + { + const NAME: &str = "a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); if !have_ffmpeg() { eprintln!("SKIP {NAME}: no ffmpeg"); @@ -9472,7 +9989,10 @@ mod tests { } } for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { - assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!( + got.y, want.y, + "{NAME} frame {i} luma vs ffmpeg (seed {seed})" + ); assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); } diff --git a/crates/ec-av1/src/superres.rs b/crates/ec-av1/src/superres.rs index 6affd094..09693c49 100644 --- a/crates/ec-av1/src/superres.rs +++ b/crates/ec-av1/src/superres.rs @@ -114,7 +114,10 @@ pub(crate) fn upscale_row(row: &[u8], real_right_margin: &[u8], out_width: usize padded[pad..pad + in_width].copy_from_slice(row); let real_n = real_right_margin.len().min(pad); padded[pad + in_width..pad + in_width + real_n].copy_from_slice(&real_right_margin[..real_n]); - let replicate_from = real_right_margin.last().copied().unwrap_or(row[in_width - 1]); + let replicate_from = real_right_margin + .last() + .copied() + .unwrap_or(row[in_width - 1]); padded[pad + in_width + real_n..].fill(replicate_from); // `av1_convolve_horiz_rs_c` is called with `input - 1` and itself @@ -262,7 +265,9 @@ mod tests { upscale_row(&row, &[], 16, &mut out); assert_eq!( out, - [9, 12, 17, 23, 28, 32, 37, 43, 48, 53, 58, 62, 67, 73, 78, 81] + [ + 9, 12, 17, 23, 28, 32, 37, 43, 48, 53, 58, 62, 67, 73, 78, 81 + ] ); } @@ -295,6 +300,9 @@ mod tests { let real_margin = [140u8]; let mut out = [0u8; 64]; upscale_row(&row, &real_margin, 64, &mut out); - assert_eq!(out[62], 141, "column 62 must match libaom, not the old replicate-padded 140"); + assert_eq!( + out[62], 141, + "column 62 must match libaom, not the old replicate-padded 140" + ); } } diff --git a/crates/ec-av1/src/transform.rs b/crates/ec-av1/src/transform.rs index b68061ed..a25b7044 100644 --- a/crates/ec-av1/src/transform.rs +++ b/crates/ec-av1/src/transform.rs @@ -839,12 +839,12 @@ pub fn inverse_transform_2d_typed_wh( let mut t = [0i32; 64]; for i in 0..h { for j in 0..w { - let c = if i < 32 && j < 32 { dequant[i * w + j] } else { 0 }; - t[j] = if rect_scale { - round2(c * 2896, 12) + let c = if i < 32 && j < 32 { + dequant[i * w + j] } else { - c + 0 }; + t[j] = if rect_scale { round2(c * 2896, 12) } else { c }; } inverse_1d(&mut t, log2w, row_clamp, row_kind); for j in 0..w { @@ -898,7 +898,9 @@ pub fn dequant_and_inverse_typed( ac_delta: i32, tx_type: TxType, ) -> Vec { - dequant_and_inverse_typed_wh(levels, side, side, bit_depth, q_idx, dc_delta, ac_delta, tx_type) + dequant_and_inverse_typed_wh( + levels, side, side, bit_depth, q_idx, dc_delta, ac_delta, tx_type, + ) } /// [`dequant_and_inverse_typed`] widened to `(w, h)` (lane-recttx). `dc_delta`/ diff --git a/crates/ec-av1/src/warp.rs b/crates/ec-av1/src/warp.rs index 96e7124b..7eb579d0 100644 --- a/crates/ec-av1/src/warp.rs +++ b/crates/ec-av1/src/warp.rs @@ -326,12 +326,20 @@ fn get_shear_params(wmmat: [i32; 6]) -> Option<(i16, i16, i16, i16)> { return None; } let mat = wmmat.map(|v| v as i64); - let mut alpha = clamp(mat[2] - (1 << WARPEDMODEL_PREC_BITS), i16::MIN as i64, i16::MAX as i64); + let mut alpha = clamp( + mat[2] - (1 << WARPEDMODEL_PREC_BITS), + i16::MIN as i64, + i16::MAX as i64, + ); let beta = clamp(mat[3], i16::MIN as i64, i16::MAX as i64); let (y_mag, shift) = resolve_divisor_32(mat[2].unsigned_abs() as u32); let y = if mat[2] < 0 { -y_mag } else { y_mag }; let v = (mat[4] * (1 << WARPEDMODEL_PREC_BITS)) * y; - let mut gamma = clamp(round2_signed(v, shift as u32), i16::MIN as i64, i16::MAX as i64); + let mut gamma = clamp( + round2_signed(v, shift as u32), + i16::MIN as i64, + i16::MAX as i64, + ); let v = (mat[3] * mat[4]) * y; let mut delta = clamp( mat[5] - round2_signed(v, shift as u32) - (1 << WARPEDMODEL_PREC_BITS), @@ -412,7 +420,13 @@ pub fn find_projection( /// translational fallback in that rare case. pub fn global_warp_params(wmmat: [i32; 6]) -> Option { let (alpha, beta, gamma, delta) = get_shear_params(wmmat)?; - Some(WarpParams { wmmat, alpha, beta, gamma, delta }) + Some(WarpParams { + wmmat, + alpha, + beta, + gamma, + delta, + }) } fn clip_pixel(v: i32) -> u16 { @@ -480,8 +494,8 @@ pub fn warp_affine( let mut sx = sx4 + beta * (k as i64 + 4); for l in -4..4i32 { let ix = ix4 + l - 3; - let offs = - (round2(sx, WARPEDDIFF_PREC_BITS) as i32 + WARPEDPIXEL_PREC_SHIFTS) as usize; + let offs = (round2(sx, WARPEDDIFF_PREC_BITS) as i32 + WARPEDPIXEL_PREC_SHIFTS) + as usize; let coeffs = &AV1_WARPED_FILTER[offs]; let mut sum: i32 = 1 << offset_bits_horiz; for (m, &c) in coeffs.iter().enumerate() { @@ -501,12 +515,13 @@ pub fn warp_affine( let l_hi = (4i32).min(p_col + p_width - j - 4); let mut l = -4i32; while l < l_hi { - let offs = - (round2(sy, WARPEDDIFF_PREC_BITS) as i32 + WARPEDPIXEL_PREC_SHIFTS) as usize; + let offs = (round2(sy, WARPEDDIFF_PREC_BITS) as i32 + WARPEDPIXEL_PREC_SHIFTS) + as usize; let coeffs = &AV1_WARPED_FILTER[offs]; let mut sum: i32 = 1 << offset_bits_vert; for m in 0..8i32 { - sum += tmp[(k + m + 4) as usize][(l + 4) as usize] * coeffs[m as usize] as i32; + sum += + tmp[(k + m + 4) as usize][(l + 4) as usize] * coeffs[m as usize] as i32; } sum = round2(sum as i64, reduce_bits_vert as u32) as i32; let out_row = (i - p_row + k + 4) as usize; diff --git a/crates/ec-av1/src/wedge.rs b/crates/ec-av1/src/wedge.rs index e133d489..85f6d63a 100644 --- a/crates/ec-av1/src/wedge.rs +++ b/crates/ec-av1/src/wedge.rs @@ -33,18 +33,18 @@ const N_DIR: usize = 6; const WEDGE_MASTER_OBLIQUE_ODD: [u8; MASK_MASTER_SIZE] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 6, - 18, 37, 53, 60, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 18, 37, 53, 60, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, ]; const WEDGE_MASTER_OBLIQUE_EVEN: [u8; MASK_MASTER_SIZE] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 11, - 27, 46, 58, 62, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 27, 46, 58, 62, 63, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, ]; const WEDGE_MASTER_VERTICAL: [u8; MASK_MASTER_SIZE] = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 7, - 21, 43, 57, 62, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 21, 43, 57, 62, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, ]; /// `wedge_codebook_16_heqw` (reconinter.c) -- (direction, x_offset, y_offset). @@ -149,7 +149,13 @@ fn init_wedge_master_masks() -> MasterMasks { /// `get_wedge_mask_inplace` (reconinter.c): the `bw x bh` window of the /// master plane for this `(wedge_index, neg, bw, bh)`, still in /// `MASK_MASTER_SIZE`-stride coordinates (caller extracts the window). -fn wedge_window(master: &MasterMasks, wedge_index: usize, neg: usize, bw: usize, bh: usize) -> (usize, usize, usize) { +fn wedge_window( + master: &MasterMasks, + wedge_index: usize, + neg: usize, + bw: usize, + bh: usize, +) -> (usize, usize, usize) { let (dir, xo, yo) = HEQW[wedge_index]; let wsignflip = SIGNFLIP[wedge_index] as usize; let woff = (xo as usize * bw) >> 3; @@ -157,7 +163,11 @@ fn wedge_window(master: &MasterMasks, wedge_index: usize, neg: usize, bw: usize, let _ = &master.obl[neg ^ wsignflip][dir as usize]; let row0 = MASK_MASTER_SIZE / 2 - hoff; let col0 = MASK_MASTER_SIZE / 2 - woff; - (neg ^ wsignflip, dir as usize, row0 * MASK_MASTER_SIZE + col0) + ( + neg ^ wsignflip, + dir as usize, + row0 * MASK_MASTER_SIZE + col0, + ) } /// Per-`(sign, wedge_index)` `bw x bh` mask, contiguous stride `bw`. @@ -282,6 +292,10 @@ mod tests { } } } - assert_eq!(checked, 3 * 2 * MAX_WEDGE_TYPES, "checked every (bsize,sign,index) triple"); + assert_eq!( + checked, + 3 * 2 * MAX_WEDGE_TYPES, + "checked every (bsize,sign,index) triple" + ); } }