wip(av1): rect coefficient wiring (in progress, orchestrator-committed at the turn cap)
Browse files at this commita27a5359f7da5757bd46638e768b80fdf533df78Parent: 46dcc374 changed files +547 -57
- crates/ec-av1/src/cdf.rs +42 -0
- crates/ec-av1/src/cdf_state.rs +60 -0
- crates/ec-av1/src/decode.rs +431 -56
- crates/ec-av1/src/stream.rs +14 -1
crates/ec-av1/src/cdf.rsmodified+42 -0
| @@ -224,6 +224,48 @@ pub const EOB_PT_1024_LUMA: [u16; 12] = [ | |||
| 224 | /// coefficient is the DC. | 224 | /// coefficient is the DC. |
| 225 | pub const COEFF_BASE_EOB_LUMA_64_DC: [u16; 4] = [935, 3382, 32768, 0]; | 225 | pub const COEFF_BASE_EOB_LUMA_64_DC: [u16; 4] = [935, 3382, 32768, 0]; |
| 226 | 226 | ||
| 227 | +/// `av1_default_eob_multi512_cdfs[2][0][0]` (`token_cdfs.h:829-906`, | ||
| 228 | +/// lane-rectwire): the end-of-block group of a luma transform with 512 coded | ||
| 229 | +/// positions -- what a true 32x16/16x32 rectangular transform has | ||
| 230 | +/// (`txsize_log2_minus4` = 5, `common_data.h:346`), distinct from | ||
| 231 | +/// [`EOB_PT_1024_LUMA`]'s 1024-position group a *square* 32x32 reads. | ||
| 232 | +pub const EOB_PT_512_LUMA: [u16; 11] = [ | ||
| 233 | + 2624, 3936, 6480, 9686, 13979, 17726, 23267, 28410, 31078, 32768, 0, | ||
| 234 | +]; | ||
| 235 | +/// [`EOB_PT_512_LUMA`], q-context 0 (`base_q_idx` 0..=20). | ||
| 236 | +pub const EOB_PT_512_LUMA_Q0: [u16; 11] = [ | ||
| 237 | + 641, 983, 3707, 5430, 10234, 14958, 18788, 23412, 26061, 32768, 0, | ||
| 238 | +]; | ||
| 239 | +/// [`EOB_PT_512_LUMA`], q-context 1 (`base_q_idx` 21..=60). | ||
| 240 | +pub const EOB_PT_512_LUMA_Q1: [u16; 11] = [ | ||
| 241 | + 1230, 2278, 5035, 7776, 11871, 15346, 19590, 24584, 28749, 32768, 0, | ||
| 242 | +]; | ||
| 243 | +/// [`EOB_PT_512_LUMA`], q-context 3 (`base_q_idx` 121..=255). | ||
| 244 | +pub const EOB_PT_512_LUMA_Q3: [u16; 11] = [ | ||
| 245 | + 5927, 7809, 10923, 14597, 19439, 24135, 28456, 31142, 32060, 32768, 0, | ||
| 246 | +]; | ||
| 247 | + | ||
| 248 | +/// `av1_default_eob_multi128_cdfs[2][1][0]` (`token_cdfs.h:829-906`, | ||
| 249 | +/// lane-rectwire): the end-of-block group of a chroma transform with 128 | ||
| 250 | +/// coded positions -- what a true 16x8/8x16 rectangular transform has | ||
| 251 | +/// (`txsize_log2_minus4` = 3), distinct from [`EOB_PT_256_CHROMA`]'s | ||
| 252 | +/// 256-position group a *square* 16x16 reads. | ||
| 253 | +pub const EOB_PT_128_CHROMA: [u16; 9] = [ | ||
| 254 | + 13627, 16246, 20173, 24429, 27948, 30415, 31863, 32768, 0, | ||
| 255 | +]; | ||
| 256 | +/// [`EOB_PT_128_CHROMA`], q-context 0. | ||
| 257 | +pub const EOB_PT_128_CHROMA_Q0: [u16; 9] = [ | ||
| 258 | + 5245, 7456, 12880, 15852, 20033, 23932, 27608, 32768, 0, | ||
| 259 | +]; | ||
| 260 | +/// [`EOB_PT_128_CHROMA`], q-context 1. | ||
| 261 | +pub const EOB_PT_128_CHROMA_Q1: [u16; 9] = [ | ||
| 262 | + 8045, 11200, 15497, 19595, 23948, 27408, 30938, 32768, 0, | ||
| 263 | +]; | ||
| 264 | +/// [`EOB_PT_128_CHROMA`], q-context 3. | ||
| 265 | +pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [ | ||
| 266 | + 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, | ||
| 267 | +]; | ||
| 268 | + | ||
| 227 | /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient, | 269 | /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient, |
| 228 | /// indexed by whether the neighbouring blocks' DC signs lean negative (1), | 270 | /// indexed by whether the neighbouring blocks' DC signs lean negative (1), |
| 229 | /// positive (2) or neither (0). | 271 | /// positive (2) or neither (0). |
crates/ec-av1/src/cdf_state.rsmodified+60 -0
| @@ -90,6 +90,20 @@ pub(crate) enum TxbSet { | |||
| 90 | Chroma16, | 90 | Chroma16, |
| 91 | /// The 32x32 transform of a chroma plane of a whole superblock. | 91 | /// The 32x32 transform of a chroma plane of a whole superblock. |
| 92 | Chroma32, | 92 | Chroma32, |
| 93 | + /// The luma 32x16/16x32 transform of a `PARTITION_HORZ`/`VERT` intra | ||
| 94 | + /// strip (lane-rectwire): `get_txsize_entropy_ctx` reduces any 2:1 rect | ||
| 95 | + /// size to its square-up equivalent (`entropy.h:172`), so this shares | ||
| 96 | + /// every table [`Luma32`](TxbSet::Luma32) does except `eob_pt` -- a true | ||
| 97 | + /// 512-position transform reads [`crate::cdf::EOB_PT_512_LUMA`], not | ||
| 98 | + /// `Luma32`'s 1024-position one. Never carries a `tx_type` symbol: both | ||
| 99 | + /// orientations use one variant (`get_tx_set` is `EXT_TX_SET_DCTONLY` at | ||
| 100 | + /// `tx_size_sqr_up == TX_32X32` regardless of which axis is longer). | ||
| 101 | + LumaRect32x16, | ||
| 102 | + /// The chroma 16x8/8x16 transform under the same strip (lane-rectwire): | ||
| 103 | + /// [`Chroma16`](TxbSet::Chroma16)'s tables except `eob_pt`, which reads | ||
| 104 | + /// the true 128-position [`crate::cdf::EOB_PT_128_CHROMA`] instead of | ||
| 105 | + /// `Chroma16`'s 256-position one. | ||
| 106 | + ChromaRect16x8, | ||
| 93 | } | 107 | } |
| 94 | 108 | ||
| 95 | /// The tables one transform block is coded with, borrowed from the state for | 109 | /// The tables one transform block is coded with, borrowed from the state for |
| @@ -233,6 +247,12 @@ pub(crate) struct Cdfs { | |||
| 233 | pub eob_pt_1024_chroma: [u16; 12], | 247 | pub eob_pt_1024_chroma: [u16; 12], |
| 234 | /// The end-of-block group of a 16x16 chroma transform. | 248 | /// The end-of-block group of a 16x16 chroma transform. |
| 235 | pub eob_pt_256_chroma: [u16; 10], | 249 | pub eob_pt_256_chroma: [u16; 10], |
| 250 | + /// The end-of-block group of a true 32x16/16x32 rect luma transform | ||
| 251 | + /// (lane-rectwire), see [`TxbSet::LumaRect32x16`]. | ||
| 252 | + pub eob_pt_512_luma: [u16; 11], | ||
| 253 | + /// The end-of-block group of a true 16x8/8x16 rect chroma transform | ||
| 254 | + /// (lane-rectwire), see [`TxbSet::ChromaRect16x8`]. | ||
| 255 | + pub eob_pt_128_chroma: [u16; 9], | ||
| 236 | /// The end-of-block offset bit, per table set. | 256 | /// The end-of-block offset bit, per table set. |
| 237 | pub eob_extra_luma_32: [[u16; 3]; 9], | 257 | pub eob_extra_luma_32: [[u16; 3]; 9], |
| 238 | /// The same, for a 64x64 luma transform. | 258 | /// The same, for a 64x64 luma transform. |
| @@ -560,6 +580,8 @@ impl Cdfs { | |||
| 560 | reset1(&mut self.eob_pt_1024_luma); | 580 | reset1(&mut self.eob_pt_1024_luma); |
| 561 | reset1(&mut self.eob_pt_1024_chroma); | 581 | reset1(&mut self.eob_pt_1024_chroma); |
| 562 | reset1(&mut self.eob_pt_256_chroma); | 582 | reset1(&mut self.eob_pt_256_chroma); |
| 583 | + reset1(&mut self.eob_pt_512_luma); | ||
| 584 | + reset1(&mut self.eob_pt_128_chroma); | ||
| 563 | reset2(&mut self.eob_extra_luma_32); | 585 | reset2(&mut self.eob_extra_luma_32); |
| 564 | reset2(&mut self.eob_extra_luma_64); | 586 | reset2(&mut self.eob_extra_luma_64); |
| 565 | reset2(&mut self.eob_extra_chroma_16); | 587 | reset2(&mut self.eob_extra_chroma_16); |
| @@ -924,6 +946,20 @@ impl Cdfs { | |||
| 924 | cdf::EOB_PT_256_CHROMA, | 946 | cdf::EOB_PT_256_CHROMA, |
| 925 | cdf::EOB_PT_256_CHROMA_Q3, | 947 | cdf::EOB_PT_256_CHROMA_Q3, |
| 926 | ), | 948 | ), |
| 949 | + eob_pt_512_luma: pick( | ||
| 950 | + q_ctx, | ||
| 951 | + cdf::EOB_PT_512_LUMA_Q0, | ||
| 952 | + cdf::EOB_PT_512_LUMA_Q1, | ||
| 953 | + cdf::EOB_PT_512_LUMA, | ||
| 954 | + cdf::EOB_PT_512_LUMA_Q3, | ||
| 955 | + ), | ||
| 956 | + eob_pt_128_chroma: pick( | ||
| 957 | + q_ctx, | ||
| 958 | + cdf::EOB_PT_128_CHROMA_Q0, | ||
| 959 | + cdf::EOB_PT_128_CHROMA_Q1, | ||
| 960 | + cdf::EOB_PT_128_CHROMA, | ||
| 961 | + cdf::EOB_PT_128_CHROMA_Q3, | ||
| 962 | + ), | ||
| 927 | eob_extra_luma_32: pick( | 963 | eob_extra_luma_32: pick( |
| 928 | q_ctx, | 964 | q_ctx, |
| 929 | cdf::EOB_EXTRA_LUMA_32_Q0, | 965 | cdf::EOB_EXTRA_LUMA_32_Q0, |
| @@ -1288,6 +1324,30 @@ impl Cdfs { | |||
| 1288 | tx_type: None, | 1324 | tx_type: None, |
| 1289 | eob_pt_class1: None, | 1325 | eob_pt_class1: None, |
| 1290 | }, | 1326 | }, |
| 1327 | + TxbSet::LumaRect32x16 => TxbTables { | ||
| 1328 | + side: 32, | ||
| 1329 | + txb_skip: &mut self.txb_skip_luma_32, | ||
| 1330 | + eob_pt: &mut self.eob_pt_512_luma, | ||
| 1331 | + eob_extra: &mut self.eob_extra_luma_32, | ||
| 1332 | + base: &mut self.base_luma_32, | ||
| 1333 | + base_eob: &mut self.base_eob_luma_32, | ||
| 1334 | + br: &mut self.br_luma_32, | ||
| 1335 | + dc_sign: &mut self.dc_sign_luma, | ||
| 1336 | + tx_type: None, | ||
| 1337 | + eob_pt_class1: None, | ||
| 1338 | + }, | ||
| 1339 | + TxbSet::ChromaRect16x8 => TxbTables { | ||
| 1340 | + side: 16, | ||
| 1341 | + txb_skip: &mut self.txb_skip_chroma_16, | ||
| 1342 | + eob_pt: &mut self.eob_pt_128_chroma, | ||
| 1343 | + eob_extra: &mut self.eob_extra_chroma_16, | ||
| 1344 | + base: &mut self.base_chroma_16, | ||
| 1345 | + base_eob: &mut self.base_eob_chroma_16, | ||
| 1346 | + br: &mut self.br_chroma_16, | ||
| 1347 | + dc_sign: &mut self.dc_sign_chroma, | ||
| 1348 | + tx_type: None, | ||
| 1349 | + eob_pt_class1: None, | ||
| 1350 | + }, | ||
| 1291 | } | 1351 | } |
| 1292 | } | 1352 | } |
| 1293 | } | 1353 | } |
crates/ec-av1/src/decode.rsmodified+431 -56
| @@ -38,7 +38,7 @@ use crate::mvstack::{ | |||
| 38 | single_ref_p6_ctx, uni_comp_ref_p1_ctx, | 38 | single_ref_p6_ctx, uni_comp_ref_p1_ctx, |
| 39 | }; | 39 | }; |
| 40 | use crate::tile::{INTRA_MODE_CTX, block_grid, has_half}; | 40 | use crate::tile::{INTRA_MODE_CTX, block_grid, has_half}; |
| 41 | -use crate::transform::{TxType, dequant_and_inverse_typed}; | 41 | +use crate::transform::{TxType, dequant_and_inverse_typed, dequant_and_inverse_typed_wh}; |
| 42 | 42 | ||
| 43 | const PARTITION_NONE: usize = 0; | 43 | const PARTITION_NONE: usize = 0; |
| 44 | const PARTITION_HORZ: usize = 1; | 44 | const PARTITION_HORZ: usize = 1; |
| @@ -272,6 +272,17 @@ pub(crate) fn rect_partition_hits() -> usize { | |||
| 272 | RECT_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed) | 272 | RECT_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed) |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | +/// lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded | ||
| 276 | +/// real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the | ||
| 277 | +/// rect coefficient reader itself fired, not just the strip-level partition | ||
| 278 | +/// symbol [`RECT_PARTITION_HITS`] already counts. | ||
| 279 | +static RECT_COEFF_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0); | ||
| 280 | + | ||
| 281 | +/// Current value of [`RECT_COEFF_HITS`]. | ||
| 282 | +pub(crate) fn rect_coeff_hits() -> usize { | ||
| 283 | + RECT_COEFF_HITS.load(std::sync::atomic::Ordering::Relaxed) | ||
| 284 | +} | ||
| 285 | + | ||
| 275 | /// lane-partab r1: how many 32x32 quadrants decoded an AB partition | 286 | /// lane-partab r1: how many 32x32 quadrants decoded an AB partition |
| 276 | /// (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one | 287 | /// (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one |
| 277 | /// 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the | 288 | /// 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the |
| @@ -616,6 +627,145 @@ fn br_ctx(grid: &[i32], side: usize, row: usize, col: usize, class: TxClass) -> | |||
| 616 | if near_origin { mag + 7 } else { mag + 14 } | 627 | if near_origin { mag + 7 } else { mag + 14 } |
| 617 | } | 628 | } |
| 618 | 629 | ||
| 630 | +/// `Default_Scan_32x16` (spec 8.4.2, libaom `scan.c`'s `default_scan_32x16`): | ||
| 631 | +/// transposed from libaom's column-major buffer into this decoder's row-major | ||
| 632 | +/// `pos = row * 32 + col` (lane-rectwire, verified as a bijection of `0..512` | ||
| 633 | +/// against the real table). Not the square zigzag formula generalized to | ||
| 634 | +/// unequal `w`/`h` -- checked and that does NOT reproduce this table. | ||
| 635 | +const SCAN_32X16: [u16; 512] = [ | ||
| 636 | + 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, | ||
| 637 | + 130, 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39, | ||
| 638 | + 8, 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72, | ||
| 639 | + 41, 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229, | ||
| 640 | + 198, 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44, | ||
| 641 | + 13, 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418, | ||
| 642 | + 387, 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326, | ||
| 643 | + 295, 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234, | ||
| 644 | + 203, 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142, | ||
| 645 | + 111, 80, 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19, | ||
| 646 | + 485, 454, 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424, | ||
| 647 | + 393, 362, 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332, | ||
| 648 | + 301, 270, 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240, | ||
| 649 | + 209, 178, 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148, | ||
| 650 | + 117, 86, 55, 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25, | ||
| 651 | + 491, 460, 429, 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430, | ||
| 652 | + 399, 368, 337, 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338, | ||
| 653 | + 307, 276, 245, 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246, | ||
| 654 | + 215, 184, 153, 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154, | ||
| 655 | + 123, 92, 61, 30, 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31, | ||
| 656 | + 497, 466, 435, 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405, | ||
| 657 | + 374, 343, 312, 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251, | ||
| 658 | + 220, 189, 158, 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439, | ||
| 659 | + 408, 377, 346, 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503, | ||
| 660 | + 472, 441, 410, 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443, | ||
| 661 | + 412, 381, 350, 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415, | ||
| 662 | + 509, 478, 447, 510, 479, 511, | ||
| 663 | +]; | ||
| 664 | + | ||
| 665 | +/// `Default_Scan_16x32`, this decoder's own row-major transcription (see | ||
| 666 | +/// [`SCAN_32X16`]'s doc comment). | ||
| 667 | +const SCAN_16X32: [u16; 512] = [ | ||
| 668 | + 0, 1, 16, 2, 17, 32, 3, 18, 33, 48, 4, 19, 34, 49, 64, 5, 20, 35, 50, 65, 80, 6, 21, 36, 51, | ||
| 669 | + 66, 81, 96, 7, 22, 37, 52, 67, 82, 97, 112, 8, 23, 38, 53, 68, 83, 98, 113, 128, 9, 24, 39, 54, | ||
| 670 | + 69, 84, 99, 114, 129, 144, 10, 25, 40, 55, 70, 85, 100, 115, 130, 145, 160, 11, 26, 41, 56, 71, | ||
| 671 | + 86, 101, 116, 131, 146, 161, 176, 12, 27, 42, 57, 72, 87, 102, 117, 132, 147, 162, 177, 192, | ||
| 672 | + 13, 28, 43, 58, 73, 88, 103, 118, 133, 148, 163, 178, 193, 208, 14, 29, 44, 59, 74, 89, 104, | ||
| 673 | + 119, 134, 149, 164, 179, 194, 209, 224, 15, 30, 45, 60, 75, 90, 105, 120, 135, 150, 165, 180, | ||
| 674 | + 195, 210, 225, 240, 31, 46, 61, 76, 91, 106, 121, 136, 151, 166, 181, 196, 211, 226, 241, 256, | ||
| 675 | + 47, 62, 77, 92, 107, 122, 137, 152, 167, 182, 197, 212, 227, 242, 257, 272, 63, 78, 93, 108, | ||
| 676 | + 123, 138, 153, 168, 183, 198, 213, 228, 243, 258, 273, 288, 79, 94, 109, 124, 139, 154, 169, | ||
| 677 | + 184, 199, 214, 229, 244, 259, 274, 289, 304, 95, 110, 125, 140, 155, 170, 185, 200, 215, 230, | ||
| 678 | + 245, 260, 275, 290, 305, 320, 111, 126, 141, 156, 171, 186, 201, 216, 231, 246, 261, 276, 291, | ||
| 679 | + 306, 321, 336, 127, 142, 157, 172, 187, 202, 217, 232, 247, 262, 277, 292, 307, 322, 337, 352, | ||
| 680 | + 143, 158, 173, 188, 203, 218, 233, 248, 263, 278, 293, 308, 323, 338, 353, 368, 159, 174, 189, | ||
| 681 | + 204, 219, 234, 249, 264, 279, 294, 309, 324, 339, 354, 369, 384, 175, 190, 205, 220, 235, 250, | ||
| 682 | + 265, 280, 295, 310, 325, 340, 355, 370, 385, 400, 191, 206, 221, 236, 251, 266, 281, 296, 311, | ||
| 683 | + 326, 341, 356, 371, 386, 401, 416, 207, 222, 237, 252, 267, 282, 297, 312, 327, 342, 357, 372, | ||
| 684 | + 387, 402, 417, 432, 223, 238, 253, 268, 283, 298, 313, 328, 343, 358, 373, 388, 403, 418, 433, | ||
| 685 | + 448, 239, 254, 269, 284, 299, 314, 329, 344, 359, 374, 389, 404, 419, 434, 449, 464, 255, 270, | ||
| 686 | + 285, 300, 315, 330, 345, 360, 375, 390, 405, 420, 435, 450, 465, 480, 271, 286, 301, 316, 331, | ||
| 687 | + 346, 361, 376, 391, 406, 421, 436, 451, 466, 481, 496, 287, 302, 317, 332, 347, 362, 377, 392, | ||
| 688 | + 407, 422, 437, 452, 467, 482, 497, 303, 318, 333, 348, 363, 378, 393, 408, 423, 438, 453, 468, | ||
| 689 | + 483, 498, 319, 334, 349, 364, 379, 394, 409, 424, 439, 454, 469, 484, 499, 335, 350, 365, 380, | ||
| 690 | + 395, 410, 425, 440, 455, 470, 485, 500, 351, 366, 381, 396, 411, 426, 441, 456, 471, 486, 501, | ||
| 691 | + 367, 382, 397, 412, 427, 442, 457, 472, 487, 502, 383, 398, 413, 428, 443, 458, 473, 488, 503, | ||
| 692 | + 399, 414, 429, 444, 459, 474, 489, 504, 415, 430, 445, 460, 475, 490, 505, 431, 446, 461, 476, | ||
| 693 | + 491, 506, 447, 462, 477, 492, 507, 463, 478, 493, 508, 479, 494, 509, 495, 510, 511, | ||
| 694 | +]; | ||
| 695 | + | ||
| 696 | +/// `Default_Scan_16x8`, this decoder's own row-major transcription (see | ||
| 697 | +/// [`SCAN_32X16`]'s doc comment). | ||
| 698 | +const SCAN_16X8: [u16; 128] = [ | ||
| 699 | + 0, 16, 1, 32, 17, 2, 48, 33, 18, 3, 64, 49, 34, 19, 4, 80, 65, 50, 35, 20, 5, 96, 81, 66, 51, | ||
| 700 | + 36, 21, 6, 112, 97, 82, 67, 52, 37, 22, 7, 113, 98, 83, 68, 53, 38, 23, 8, 114, 99, 84, 69, 54, | ||
| 701 | + 39, 24, 9, 115, 100, 85, 70, 55, 40, 25, 10, 116, 101, 86, 71, 56, 41, 26, 11, 117, 102, 87, | ||
| 702 | + 72, 57, 42, 27, 12, 118, 103, 88, 73, 58, 43, 28, 13, 119, 104, 89, 74, 59, 44, 29, 14, 120, | ||
| 703 | + 105, 90, 75, 60, 45, 30, 15, 121, 106, 91, 76, 61, 46, 31, 122, 107, 92, 77, 62, 47, 123, 108, | ||
| 704 | + 93, 78, 63, 124, 109, 94, 79, 125, 110, 95, 126, 111, 127, | ||
| 705 | +]; | ||
| 706 | + | ||
| 707 | +/// `Default_Scan_8x16`, this decoder's own row-major transcription (see | ||
| 708 | +/// [`SCAN_32X16`]'s doc comment). | ||
| 709 | +const SCAN_8X16: [u16; 128] = [ | ||
| 710 | + 0, 1, 8, 2, 9, 16, 3, 10, 17, 24, 4, 11, 18, 25, 32, 5, 12, 19, 26, 33, 40, 6, 13, 20, 27, 34, | ||
| 711 | + 41, 48, 7, 14, 21, 28, 35, 42, 49, 56, 15, 22, 29, 36, 43, 50, 57, 64, 23, 30, 37, 44, 51, 58, | ||
| 712 | + 65, 72, 31, 38, 45, 52, 59, 66, 73, 80, 39, 46, 53, 60, 67, 74, 81, 88, 47, 54, 61, 68, 75, 82, | ||
| 713 | + 89, 96, 55, 62, 69, 76, 83, 90, 97, 104, 63, 70, 77, 84, 91, 98, 105, 112, 71, 78, 85, 92, 99, | ||
| 714 | + 106, 113, 120, 79, 86, 93, 100, 107, 114, 121, 87, 94, 101, 108, 115, 122, 95, 102, 109, 116, | ||
| 715 | + 123, 103, 110, 117, 124, 111, 118, 125, 119, 126, 127, | ||
| 716 | +]; | ||
| 717 | + | ||
| 718 | +/// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents | ||
| 719 | +/// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s | ||
| 720 | +/// asymmetric-extent pattern). | ||
| 721 | +fn neighbour_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> i32 { | ||
| 722 | + if row >= h || col >= w { | ||
| 723 | + 0 | ||
| 724 | + } else { | ||
| 725 | + grid[row * w + col] | ||
| 726 | + } | ||
| 727 | +} | ||
| 728 | + | ||
| 729 | +/// [`base_ctx`]'s `TxClass::TwoD` arm widened to `(w, h)` (lane-rectwire): | ||
| 730 | +/// the rect generalization is libaom's own comment in | ||
| 731 | +/// `get_nz_map_ctx_from_stats` (`txb_common.h:189-224`), reduces to the exact | ||
| 732 | +/// same [`cdf::NZ_MAP_CTX_OFFSET_32`] table when `w == h`. Never called for | ||
| 733 | +/// `V_DCT`/`H_DCT` -- geometrically impossible at the two size pairs | ||
| 734 | +/// [`decode_block_rect`] codes (see that function's own doc comment). | ||
| 735 | +fn base_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usize { | ||
| 736 | + if row == 0 && col == 0 { | ||
| 737 | + return 0; | ||
| 738 | + } | ||
| 739 | + const OFFSETS: [(usize, usize); 5] = [(1, 0), (0, 1), (1, 1), (2, 0), (0, 2)]; | ||
| 740 | + let mag: i32 = OFFSETS | ||
| 741 | + .iter() | ||
| 742 | + .map(|&(dr, dc)| neighbour_rect(grid, w, h, row + dr, col + dc).abs().min(3)) | ||
| 743 | + .sum(); | ||
| 744 | + let ctx = ((mag + 1) >> 1).min(4) as usize; | ||
| 745 | + if w < h && row < 2 { | ||
| 746 | + return ctx + 11; | ||
| 747 | + } | ||
| 748 | + if w > h && col < 2 { | ||
| 749 | + return ctx + 16; | ||
| 750 | + } | ||
| 751 | + ctx + cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize | ||
| 752 | +} | ||
| 753 | + | ||
| 754 | +/// [`br_ctx`]'s `TxClass::TwoD` arm widened to `(w, h)` (lane-rectwire): the | ||
| 755 | +/// neighbour-offset math itself is shape-independent, only the boundary | ||
| 756 | +/// clamp needs the real bound in each axis. | ||
| 757 | +fn br_ctx_rect(grid: &[i32], w: usize, h: usize, row: usize, col: usize) -> usize { | ||
| 758 | + let extra = neighbour_rect(grid, w, h, row + 1, col + 1).abs(); | ||
| 759 | + let mag = neighbour_rect(grid, w, h, row + 1, col).abs() | ||
| 760 | + + neighbour_rect(grid, w, h, row, col + 1).abs() | ||
| 761 | + + extra; | ||
| 762 | + let mag = (((mag + 1) >> 1).min(6)) as usize; | ||
| 763 | + if row == 0 && col == 0 { | ||
| 764 | + return mag; | ||
| 765 | + } | ||
| 766 | + if row < 2 && col < 2 { mag + 7 } else { mag + 14 } | ||
| 767 | +} | ||
| 768 | + | ||
| 619 | fn dc_vote(dc: Option<bool>) -> i32 { | 769 | fn dc_vote(dc: Option<bool>) -> i32 { |
| 620 | match dc { | 770 | match dc { |
| 621 | None => 0, | 771 | None => 0, |
| @@ -882,6 +1032,89 @@ fn read_coeffs( | |||
| 882 | Ok((grid, tx_type)) | 1032 | Ok((grid, tx_type)) |
| 883 | } | 1033 | } |
| 884 | 1034 | ||
| 1035 | +/// [`read_coeffs`] widened to `(w, h)` (lane-rectwire), restricted to | ||
| 1036 | +/// `TxClass::TwoD` -- the only class either rect size pair this decoder codes | ||
| 1037 | +/// can ever produce (see [`decode_block_rect`]'s doc comment): refuses by | ||
| 1038 | +/// name rather than guess-decode if a `tx_type` symbol or non-2D class ever | ||
| 1039 | +/// shows up here, since neither `base_ctx_rect`/`br_ctx_rect` nor | ||
| 1040 | +/// [`class_scan_table`] have a rect form for those. | ||
| 1041 | +fn read_coeffs_rect( | ||
| 1042 | + dec: &mut SymbolDecoder, | ||
| 1043 | + coding: &mut TxbTables, | ||
| 1044 | + scan: &[u16], | ||
| 1045 | + w: usize, | ||
| 1046 | + h: usize, | ||
| 1047 | + skip_ctx: usize, | ||
| 1048 | + sign_ctx: usize, | ||
| 1049 | + default_tx_type: TxType, | ||
| 1050 | +) -> Result<(Vec<i32>, TxType)> { | ||
| 1051 | + let mut grid = vec![0i32; w * h]; | ||
| 1052 | + let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1; | ||
| 1053 | + if all_zero { | ||
| 1054 | + return Ok((grid, TxType::DctDct)); | ||
| 1055 | + } | ||
| 1056 | + if coding.tx_type.is_some() { | ||
| 1057 | + return Err(unsupported( | ||
| 1058 | + "a tx_type symbol on a rectangular transform (never expected at this size)", | ||
| 1059 | + )); | ||
| 1060 | + } | ||
| 1061 | + let tx_type = default_tx_type; | ||
| 1062 | + if TxClass::of(tx_type) != TxClass::TwoD { | ||
| 1063 | + return Err(unsupported( | ||
| 1064 | + "a non-2D tx class on a rectangular transform (never expected at this size)", | ||
| 1065 | + )); | ||
| 1066 | + } | ||
| 1067 | + let eob = read_eob(dec, coding, TxClass::TwoD); | ||
| 1068 | + let mut levels = vec![0i32; w * h]; | ||
| 1069 | + for scan_idx in (0..eob).rev() { | ||
| 1070 | + let pos = scan[scan_idx] as usize; | ||
| 1071 | + let (row, col) = (pos / w, pos % w); | ||
| 1072 | + let level = if scan_idx == eob - 1 { | ||
| 1073 | + let ctx = eob_coeff_ctx(scan_idx, w * h); | ||
| 1074 | + dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1 | ||
| 1075 | + } else { | ||
| 1076 | + let ctx = base_ctx_rect(&levels, w, h, row, col); | ||
| 1077 | + dec.symbol(&mut coding.base[ctx]) as i32 | ||
| 1078 | + }; | ||
| 1079 | + let level = if level > NUM_BASE_LEVELS { | ||
| 1080 | + let ctx = br_ctx_rect(&levels, w, h, row, col); | ||
| 1081 | + let mut level = level; | ||
| 1082 | + let mut sent = 0; | ||
| 1083 | + loop { | ||
| 1084 | + let k = dec.symbol(&mut coding.br[ctx]) as i32; | ||
| 1085 | + level += k; | ||
| 1086 | + sent += BR_STEP; | ||
| 1087 | + if k < BR_STEP || sent >= COEFF_BASE_RANGE { | ||
| 1088 | + break; | ||
| 1089 | + } | ||
| 1090 | + } | ||
| 1091 | + level | ||
| 1092 | + } else { | ||
| 1093 | + level | ||
| 1094 | + }; | ||
| 1095 | + levels[pos] = level; | ||
| 1096 | + } | ||
| 1097 | + for &pos in &scan[..eob] { | ||
| 1098 | + let level = levels[pos as usize]; | ||
| 1099 | + if level == 0 { | ||
| 1100 | + continue; | ||
| 1101 | + } | ||
| 1102 | + let negative = if pos == 0 { | ||
| 1103 | + dec.symbol(&mut coding.dc_sign[sign_ctx]) == 1 | ||
| 1104 | + } else { | ||
| 1105 | + dec.literal(1) == 1 | ||
| 1106 | + }; | ||
| 1107 | + let level = if level.abs_diff(0) as i32 > MAX_BR_LEVEL { | ||
| 1108 | + let g = read_golomb(dec)?; | ||
| 1109 | + level + g as i32 | ||
| 1110 | + } else { | ||
| 1111 | + level | ||
| 1112 | + }; | ||
| 1113 | + grid[pos as usize] = if negative { -level } else { level }; | ||
| 1114 | + } | ||
| 1115 | + Ok((grid, tx_type)) | ||
| 1116 | +} | ||
| 1117 | + | ||
| 885 | /// What one coded block leaves behind for the blocks that read it as a | 1118 | /// What one coded block leaves behind for the blocks that read it as a |
| 886 | /// neighbour: whether it coded anything at all, and the sign of its DC — | 1119 | /// neighbour: whether it coded anything at all, and the sign of its DC — |
| 887 | /// [`crate::tile`]'s own private `Neighbour`. | 1120 | /// [`crate::tile`]'s own private `Neighbour`. |
| @@ -1336,6 +1569,35 @@ impl Neighbours { | |||
| 1336 | }) | 1569 | }) |
| 1337 | } | 1570 | } |
| 1338 | 1571 | ||
| 1572 | + /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in | ||
| 1573 | + /// pixels -- lane-rectwire, mirrors [`Self::record_rect`]'s asymmetric | ||
| 1574 | + /// extent pattern for a true rectangular strip's own coefficient context. | ||
| 1575 | + fn around_rect(&self, (r, c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] { | ||
| 1576 | + self.around_mi_rect((r * (SUB / MI), c * (SUB / MI)), w, h) | ||
| 1577 | + } | ||
| 1578 | + | ||
| 1579 | + /// [`Self::around_rect`] taking the block's position directly in 4x4 | ||
| 1580 | + /// mode-info units, mirroring [`Self::around_mi`]. | ||
| 1581 | + fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] { | ||
| 1582 | + let (w_mi, h_mi) = (w / MI, h / MI); | ||
| 1583 | + std::array::from_fn(|plane| { | ||
| 1584 | + let mut above_coded = false; | ||
| 1585 | + let mut left_coded = false; | ||
| 1586 | + let mut vote = 0; | ||
| 1587 | + for cell in 0..w_mi { | ||
| 1588 | + let above = &self.above[mi_c + cell][plane]; | ||
| 1589 | + above_coded |= above.level != 0; | ||
| 1590 | + vote += dc_vote(above.dc); | ||
| 1591 | + } | ||
| 1592 | + for cell in 0..h_mi { | ||
| 1593 | + let left = &self.left[mi_r + cell][plane]; | ||
| 1594 | + left_coded |= left.level != 0; | ||
| 1595 | + vote += dc_vote(left.dc); | ||
| 1596 | + } | ||
| 1597 | + (above_coded, left_coded, vote) | ||
| 1598 | + }) | ||
| 1599 | + } | ||
| 1600 | + | ||
| 1339 | /// The luma `txb_skip_ctx` of a transform unit smaller than its own block | 1601 | /// The luma `txb_skip_ctx` of a transform unit smaller than its own block |
| 1340 | /// (spec `get_txb_ctx_general`, plane 0, `plane_bsize != tx_size`): the | 1602 | /// (spec `get_txb_ctx_general`, plane 0, `plane_bsize != tx_size`): the |
| 1341 | /// above/left neighbours' magnitude tiers, OR-reduced over the unit's own | 1603 | /// above/left neighbours' magnitude tiers, OR-reduced over the unit's own |
| @@ -1722,6 +1984,7 @@ fn decode_block_rect( | |||
| 1722 | v: &mut PlaneBuf, | 1984 | v: &mut PlaneBuf, |
| 1723 | enable_filter_intra: bool, | 1985 | enable_filter_intra: bool, |
| 1724 | allow_screen_content_tools: bool, | 1986 | allow_screen_content_tools: bool, |
| 1987 | + base_q_idx: u8, | ||
| 1725 | ) -> Result<()> { | 1988 | ) -> Result<()> { |
| 1726 | let (r, c) = at; | 1989 | let (r, c) = at; |
| 1727 | let (px, py) = (c * SUB, r * SUB); | 1990 | let (px, py) = (c * SUB, r * SUB); |
| @@ -1769,64 +2032,172 @@ fn decode_block_rect( | |||
| 1769 | )); | 2032 | )); |
| 1770 | } | 2033 | } |
| 1771 | let (tx_w, tx_h) = (bw, bh); | 2034 | let (tx_w, tx_h) = (bw, bh); |
| 1772 | - if !skip { | ||
| 1773 | - return Err(unsupported( | ||
| 1774 | - "a non-skip HORZ/VERT intra strip needs a rectangular transform \ | ||
| 1775 | - this decoder does not code yet", | ||
| 1776 | - )); | ||
| 1777 | - } | ||
| 1778 | let (cpx, cpy) = (px / 2, py / 2); | 2035 | let (cpx, cpy) = (px / 2, py / 2); |
| 1779 | let (chroma_w, chroma_h) = (bw / 2, bh / 2); | 2036 | let (chroma_w, chroma_h) = (bw / 2, bh / 2); |
| 1780 | let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); | 2037 | let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); |
| 1781 | - y.reconstruct_rect( | 2038 | + if skip { |
| 1782 | - px, | 2039 | + y.reconstruct_rect( |
| 1783 | - py, | 2040 | + px, |
| 1784 | - bw, | 2041 | + py, |
| 1785 | - bh, | 2042 | + bw, |
| 1786 | - mode, | 2043 | + bh, |
| 1787 | - angle_delta_y, | 2044 | + mode, |
| 1788 | - reach, | 2045 | + angle_delta_y, |
| 1789 | - &vec![0i32; bw * bh], | 2046 | + reach, |
| 1790 | - None, | 2047 | + &vec![0i32; bw * bh], |
| 1791 | - filter_intra, | 2048 | + None, |
| 1792 | - ); | 2049 | + filter_intra, |
| 1793 | - let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | 2050 | + ); |
| 1794 | - u.reconstruct_rect( | 2051 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 1795 | - cpx, | 2052 | + u.reconstruct_rect( |
| 1796 | - cpy, | 2053 | + cpx, |
| 1797 | - chroma_w, | 2054 | + cpy, |
| 1798 | - chroma_h, | 2055 | + chroma_w, |
| 1799 | - uv_predict_mode, | 2056 | + chroma_h, |
| 1800 | - angle_delta_uv, | 2057 | + uv_predict_mode, |
| 1801 | - reach, | 2058 | + angle_delta_uv, |
| 1802 | - &vec![0i32; chroma_w * chroma_h], | 2059 | + reach, |
| 1803 | - alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | 2060 | + &vec![0i32; chroma_w * chroma_h], |
| 1804 | - None, | 2061 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), |
| 1805 | - ); | 2062 | + None, |
| 1806 | - v.reconstruct_rect( | 2063 | + ); |
| 1807 | - cpx, | 2064 | + v.reconstruct_rect( |
| 1808 | - cpy, | 2065 | + cpx, |
| 1809 | - chroma_w, | 2066 | + cpy, |
| 1810 | - chroma_h, | 2067 | + chroma_w, |
| 1811 | - uv_predict_mode, | 2068 | + chroma_h, |
| 1812 | - angle_delta_uv, | 2069 | + uv_predict_mode, |
| 1813 | - reach, | 2070 | + angle_delta_uv, |
| 1814 | - &vec![0i32; chroma_w * chroma_h], | 2071 | + reach, |
| 1815 | - alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | 2072 | + &vec![0i32; chroma_w * chroma_h], |
| 1816 | - None, | 2073 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), |
| 1817 | - ); | 2074 | + None, |
| 1818 | - neighbours.record_rect( | 2075 | + ); |
| 1819 | - at, | 2076 | + neighbours.record_rect( |
| 1820 | - bw, | 2077 | + at, |
| 1821 | - bh, | 2078 | + bw, |
| 1822 | - mode, | 2079 | + bh, |
| 1823 | - &[ | 2080 | + mode, |
| 1824 | - vec![0i32; bw * bh], | 2081 | + &[ |
| 1825 | - vec![0i32; chroma_w * chroma_h], | 2082 | + vec![0i32; bw * bh], |
| 1826 | - vec![0i32; chroma_w * chroma_h], | 2083 | + vec![0i32; chroma_w * chroma_h], |
| 1827 | - ], | 2084 | + vec![0i32; chroma_w * chroma_h], |
| 1828 | - ); | 2085 | + ], |
| 1829 | - neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, true); | 2086 | + ); |
| 2087 | + } else { | ||
| 2088 | + // lane-rectwire r2: real coefficients. `get_txsize_entropy_ctx` | ||
| 2089 | + // reduces both size pairs to their square-up CDF sets | ||
| 2090 | + // (`TxbSet::LumaRect32x16`/`ChromaRect16x8`, see those variants' own | ||
| 2091 | + // doc comments); the scan order and 2D context tables are the real | ||
| 2092 | + // rect ones (`SCAN_32X16`/etc, `base_ctx_rect`/`br_ctx_rect`). | ||
| 2093 | + let (luma_scan, chroma_scan): (&[u16], &[u16]) = if bw == 32 { | ||
| 2094 | + (&SCAN_32X16, &SCAN_16X8) | ||
| 2095 | + } else { | ||
| 2096 | + (&SCAN_16X32, &SCAN_8X16) | ||
| 2097 | + }; | ||
| 2098 | + let around = neighbours.around_rect(at, bw, bh); | ||
| 2099 | + let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); | ||
| 2100 | + let (luma_levels, luma_tx_type) = read_coeffs_rect( | ||
| 2101 | + dec, | ||
| 2102 | + &mut luma_coding, | ||
| 2103 | + luma_scan, | ||
| 2104 | + bw, | ||
| 2105 | + bh, | ||
| 2106 | + 0, | ||
| 2107 | + dc_sign_ctx(around[0].2), | ||
| 2108 | + TxType::DctDct, | ||
| 2109 | + )?; | ||
| 2110 | + let luma_residual = dequant_and_inverse_typed_wh( | ||
| 2111 | + &luma_levels, | ||
| 2112 | + bw, | ||
| 2113 | + bh, | ||
| 2114 | + 8, | ||
| 2115 | + i32::from(base_q_idx), | ||
| 2116 | + luma_tx_type, | ||
| 2117 | + ); | ||
| 2118 | + y.reconstruct_rect( | ||
| 2119 | + px, | ||
| 2120 | + py, | ||
| 2121 | + bw, | ||
| 2122 | + bh, | ||
| 2123 | + mode, | ||
| 2124 | + angle_delta_y, | ||
| 2125 | + reach, | ||
| 2126 | + &luma_residual, | ||
| 2127 | + None, | ||
| 2128 | + filter_intra, | ||
| 2129 | + ); | ||
| 2130 | + let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); | ||
| 2131 | + let u_default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 2132 | + let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); | ||
| 2133 | + let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); | ||
| 2134 | + let (u_levels, u_tx_type) = read_coeffs_rect( | ||
| 2135 | + dec, | ||
| 2136 | + &mut u_coding, | ||
| 2137 | + chroma_scan, | ||
| 2138 | + chroma_w, | ||
| 2139 | + chroma_h, | ||
| 2140 | + u_skip_ctx, | ||
| 2141 | + dc_sign_ctx(around[1].2), | ||
| 2142 | + u_default_tx, | ||
| 2143 | + )?; | ||
| 2144 | + let u_residual = dequant_and_inverse_typed_wh( | ||
| 2145 | + &u_levels, | ||
| 2146 | + chroma_w, | ||
| 2147 | + chroma_h, | ||
| 2148 | + 8, | ||
| 2149 | + i32::from(base_q_idx), | ||
| 2150 | + u_tx_type, | ||
| 2151 | + ); | ||
| 2152 | + u.reconstruct_rect( | ||
| 2153 | + cpx, | ||
| 2154 | + cpy, | ||
| 2155 | + chroma_w, | ||
| 2156 | + chroma_h, | ||
| 2157 | + uv_predict_mode, | ||
| 2158 | + angle_delta_uv, | ||
| 2159 | + reach, | ||
| 2160 | + &u_residual, | ||
| 2161 | + alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)), | ||
| 2162 | + None, | ||
| 2163 | + ); | ||
| 2164 | + let v_default_tx = default_intra_tx_type(uv_predict_mode as u8); | ||
| 2165 | + let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); | ||
| 2166 | + let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode); | ||
| 2167 | + let (v_levels, v_tx_type) = read_coeffs_rect( | ||
| 2168 | + dec, | ||
| 2169 | + &mut v_coding, | ||
| 2170 | + chroma_scan, | ||
| 2171 | + chroma_w, | ||
| 2172 | + chroma_h, | ||
| 2173 | + v_skip_ctx, | ||
| 2174 | + dc_sign_ctx(around[2].2), | ||
| 2175 | + v_default_tx, | ||
| 2176 | + )?; | ||
| 2177 | + let v_residual = dequant_and_inverse_typed_wh( | ||
| 2178 | + &v_levels, | ||
| 2179 | + chroma_w, | ||
| 2180 | + chroma_h, | ||
| 2181 | + 8, | ||
| 2182 | + i32::from(base_q_idx), | ||
| 2183 | + v_tx_type, | ||
| 2184 | + ); | ||
| 2185 | + v.reconstruct_rect( | ||
| 2186 | + cpx, | ||
| 2187 | + cpy, | ||
| 2188 | + chroma_w, | ||
| 2189 | + chroma_h, | ||
| 2190 | + uv_predict_mode, | ||
| 2191 | + angle_delta_uv, | ||
| 2192 | + reach, | ||
| 2193 | + &v_residual, | ||
| 2194 | + alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)), | ||
| 2195 | + None, | ||
| 2196 | + ); | ||
| 2197 | + neighbours.record_rect(at, bw, bh, mode, &[luma_levels, u_levels, v_levels]); | ||
| 2198 | + RECT_COEFF_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | ||
| 2199 | + } | ||
| 2200 | + neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); | ||
| 1830 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); | 2201 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); |
| 1831 | RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 2202 | RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 1832 | Ok(()) | 2203 | Ok(()) |
| @@ -4350,6 +4721,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4350 | &mut v, | 4721 | &mut v, |
| 4351 | enable_filter_intra, | 4722 | enable_filter_intra, |
| 4352 | allow_screen_content_tools, | 4723 | allow_screen_content_tools, |
| 4724 | + base_q_idx, | ||
| 4353 | )?; | 4725 | )?; |
| 4354 | decode_block_rect( | 4726 | decode_block_rect( |
| 4355 | &mut dec, | 4727 | &mut dec, |
| @@ -4363,6 +4735,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4363 | &mut v, | 4735 | &mut v, |
| 4364 | enable_filter_intra, | 4736 | enable_filter_intra, |
| 4365 | allow_screen_content_tools, | 4737 | allow_screen_content_tools, |
| 4738 | + base_q_idx, | ||
| 4366 | )?; | 4739 | )?; |
| 4367 | } | 4740 | } |
| 4368 | PARTITION_VERT => { | 4741 | PARTITION_VERT => { |
| @@ -4380,6 +4753,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4380 | &mut v, | 4753 | &mut v, |
| 4381 | enable_filter_intra, | 4754 | enable_filter_intra, |
| 4382 | allow_screen_content_tools, | 4755 | allow_screen_content_tools, |
| 4756 | + base_q_idx, | ||
| 4383 | )?; | 4757 | )?; |
| 4384 | decode_block_rect( | 4758 | decode_block_rect( |
| 4385 | &mut dec, | 4759 | &mut dec, |
| @@ -4393,6 +4767,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4393 | &mut v, | 4767 | &mut v, |
| 4394 | enable_filter_intra, | 4768 | enable_filter_intra, |
| 4395 | allow_screen_content_tools, | 4769 | allow_screen_content_tools, |
| 4770 | + base_q_idx, | ||
| 4396 | )?; | 4771 | )?; |
| 4397 | } | 4772 | } |
| 4398 | _ => { | 4773 | _ => { |
crates/ec-av1/src/stream.rsmodified+14 -1
| @@ -4191,10 +4191,23 @@ mod tests { | |||
| 4191 | "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ | 4191 | "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ |
| 4192 | ({matched} matches, {named_refusals} refusals); sampling, not a regression" | 4192 | ({matched} matches, {named_refusals} refusals); sampling, not a regression" |
| 4193 | ); | 4193 | ); |
| 4194 | + } else { | ||
| 4195 | + // lane-rectwire r2: once a run fires any HORZ/VERT strip at all, | ||
| 4196 | + // real coefficient decode (not just the skip case) must also | ||
| 4197 | + // fire -- a rect_partition_hits>0, rect_coeff_hits==0 run would | ||
| 4198 | + // mean every fired strip happened to be skip, which the encoder | ||
| 4199 | + // recipe's rate target does not produce in practice. | ||
| 4200 | + assert!( | ||
| 4201 | + crate::decode::rect_coeff_hits() > 0, | ||
| 4202 | + "{NAME}: {} HORZ/VERT strips fired but zero coded real coefficients \ | ||
| 4203 | + (rect_coeff_hits==0) -- the rect coefficient reader is unexercised", | ||
| 4204 | + crate::decode::rect_partition_hits() | ||
| 4205 | + ); | ||
| 4194 | } | 4206 | } |
| 4195 | eprintln!( | 4207 | eprintln!( |
| 4196 | - "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, rect_partition_hits={} extended_partition_hits={} partab_hits={}", | 4208 | + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, rect_partition_hits={} rect_coeff_hits={} extended_partition_hits={} partab_hits={}", |
| 4197 | crate::decode::rect_partition_hits(), | 4209 | crate::decode::rect_partition_hits(), |
| 4210 | + crate::decode::rect_coeff_hits(), | ||
| 4198 | crate::decode::extended_partition_hits(), | 4211 | crate::decode::extended_partition_hits(), |
| 4199 | crate::decode::partab_hits() | 4212 | crate::decode::partab_hits() |
| 4200 | ); | 4213 | ); |