edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB00c1b3fTahinli2 months ago1999 commits
| 1 | //! Sub-pel motion compensation, spec 7.11.3 ("Motion vector scaling process" |
| 2 | //! through "Block inter predictor process"), the REGULAR (`EIGHTTAP`) filter |
| 3 | //! only, 8-bit samples only. |
| 4 | //! |
| 5 | //! A block's inter prediction is separable: an 8-tap horizontal pass over the |
| 6 | //! reference, rounded down by `InterRound0`, feeds an 8-tap vertical pass |
| 7 | //! over that intermediate, rounded down by `InterRound1`. Both fractions run |
| 8 | //! in 1/16-pel steps -- luma motion vectors are stored at 1/8-pel and always |
| 9 | //! land on an even step; chroma vectors, once scaled for subsampling, can |
| 10 | //! land on any of the 16. |
| 11 | |
| 12 | /// `Round2` (spec 4.7): halves round up. |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | /// `InterRound0` (spec 7.11.3.2), 8-bit, non-compound: the shift the |
| 22 | /// horizontal pass's sum is brought down by before it is stored as the |
| 23 | /// intermediate. |
| 24 | const INTER_ROUND_0: u32 = 3; |
| 25 | /// `InterRound1` (spec 7.11.3.2), 8-bit, non-compound: the shift the vertical |
| 26 | /// pass's sum is brought down by to land back on an 8-bit sample. Composed |
| 27 | /// with `INTER_ROUND_0` the two shifts are the filter's own gain (each pass |
| 28 | /// sums to 128, `128 * 128 == 1 << 14 == 1 << (INTER_ROUND_0 + INTER_ROUND_1)`) |
| 29 | /// -- so an identity or DC input comes back exactly, by construction of the |
| 30 | /// table rather than by a fitted constant. |
| 31 | const INTER_ROUND_1: u32 = 11; |
| 32 | |
| 33 | /// `Subpel_Filters[EIGHTTAP]` (spec 7.11.3.3): 16 rows, one per 1/16-pel |
| 34 | /// fraction, each an 8-tap kernel centred so tap index 3 lands on the integer |
| 35 | /// sample (fraction 0 is the identity tap `[.., 128, ..]`). |
| 36 | const SUBPEL_FILTERS: = |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | ; |
| 54 | |
| 55 | /// `Subpel_Filters[EIGHTTAP]`'s narrow-block counterpart (spec 7.11.3.4's |
| 56 | /// filter selection is per-axis: a `predict` axis whose output block |
| 57 | /// dimension is 4 or less reads this table instead of [`SUBPEL_FILTERS`]), |
| 58 | /// mirroring `av1_sub_pel_filters_4` (`filter.h`): the same 8-slot shape but |
| 59 | /// zeroed at taps 0/1/6/7, so a 4-wide (or 4-tall) block's filter never |
| 60 | /// reaches a full 3 samples past its own edge. Every 4:2:0 chroma block |
| 61 | /// under an 8x8 (or smaller) luma leaf hits this on at least one axis -- |
| 62 | /// this is not an edge case, it is the common chroma shape. |
| 63 | const SUBPEL_FILTERS_4: = |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | ; |
| 81 | |
| 82 | /// `Subpel_Filters[EIGHTTAP_SMOOTH]` (`filter.h`'s `av1_sub_pel_filters_8smooth`). |
| 83 | const SUBPEL_FILTERS_SMOOTH: = |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | ; |
| 101 | |
| 102 | /// `SUBPEL_FILTERS_SMOOTH`'s narrow-block counterpart (`av1_sub_pel_filters_4smooth`). |
| 103 | const SUBPEL_FILTERS_SMOOTH_4: = |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | ; |
| 121 | |
| 122 | /// `Subpel_Filters[EIGHTTAP_SHARP]` (`av1_sub_pel_filters_8sharp`). A block |
| 123 | /// whose dimension is 4 or less does NOT read this table: spec 7.11.3.4's |
| 124 | /// `filterIdx` sends both EIGHTTAP and EIGHTTAP_SHARP to filter index 4, and |
| 125 | /// libaom agrees -- `av1_interp_4tap[MULTITAP_SHARP]` is `av1_sub_pel_filters_4`, |
| 126 | /// the REGULAR narrow kernel (`filter.h:243`), not a sharp one (lane-gmaffine r5). |
| 127 | const SUBPEL_FILTERS_SHARP: = |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | ; |
| 145 | |
| 146 | /// `Subpel_Filters[BILINEAR]` (`av1_bilinear_filters`) -- also never swapped |
| 147 | /// for a narrow-block table (it is already only 2 non-zero taps). |
| 148 | const SUBPEL_FILTERS_BILINEAR: = |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | ; |
| 166 | |
| 167 | /// Which of the spec's four `interpolation_filter` kernels a block's motion |
| 168 | /// compensation reads (spec 6.8.9 / `frame_header`'s `interpolation_filter`). |
| 169 | /// A frame codes exactly one of these when not `Switchable`; a `Switchable` |
| 170 | /// frame codes one per block per direction (spec 5.11.20's |
| 171 | /// `read_interp_filter`, see `decode::decode_inter_block`), so `predict`'s |
| 172 | /// callers resolve `Switchable` to a concrete pair of kinds themselves -- |
| 173 | /// this type only ever names the resolved kernel, never `Switchable` itself. |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | /// A reference sample at `(x, y)`, clamped to the frame's true (unpadded) |
| 227 | /// extent -- `true_width`/`true_height`, which can be narrower than |
| 228 | /// `stride` -- rather than read out of range (spec 7.11.3.4's `Clip3` |
| 229 | /// against the frame's edges): a motion vector that points past the true |
| 230 | /// edge repeats the true edge's sample instead of panicking or picking up |
| 231 | /// whatever this encoder's own uncoded padding columns/rows hold. |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | /// lane-perf2: one row of the separable filter's horizontal pass, dav1d |
| 247 | /// style. When the row's whole 8-tap footprint (`x0-3 .. x0+block_w+4`) lies |
| 248 | /// inside the reference's true extent -- the overwhelmingly common case -- |
| 249 | /// the row is one contiguous slice and the taps are a fixed `[i32; 8]`, so |
| 250 | /// the per-sample `Clip3` and the per-tap table load both leave the inner |
| 251 | /// loop and it auto-vectorises. The edge case keeps the exact spec form |
| 252 | /// (`sample`'s clamp per tap); both arms compute the same sums. |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | |
| 270 | |
| 271 | |
| 272 | |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | /// lane-perf2: the unscaled horizontal pass, `block_h + 7` rows of |
| 288 | /// [`hpass_row`] with the vertical clamp hoisted out of the row. |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | |
| 306 | |
| 307 | |
| 308 | |
| 309 | |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | /// lane-perf2: one output row of the vertical pass, accumulated tap-major so |
| 330 | /// the inner loop walks two contiguous `i32` slices (vectorisable) instead of |
| 331 | /// striding the intermediate by `block_w` per tap. A zero tap is skipped -- |
| 332 | /// adding `0 * x` is exactly nothing, and the 4-tap kernels zero four of the |
| 333 | /// eight slots. `acc` is left holding the unrounded sums. |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 | thread_local! |
| 349 | |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | /// Runs `f` on a scratch slice of `rows * block_w` intermediate elements plus |
| 359 | /// a `block_w` accumulator (see [`MC_SCRATCH`]). |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | /// Predicts one `block_w * block_h` block into `dst`, row-major, from |
| 373 | /// `reference` (row-major, stride `stride`, true content |
| 374 | /// `true_width` x `true_height` -- a reference frame's decoded picture |
| 375 | /// buffer can be wider/taller than the true frame it holds, when this |
| 376 | /// encoder pads a picture to a whole number of superblocks; a spec decoder |
| 377 | /// never codes syntax for those extra columns/rows, so motion compensation |
| 378 | /// must clamp to the true extent, not the buffer's own stride). |
| 379 | /// |
| 380 | /// `x_q4` / `y_q4` are the block's top-left position in the reference, in |
| 381 | /// 1/16-pel units (an integer MV has its low 4 bits zero); this function |
| 382 | /// splits each into its whole-sample part and its 0..16 fraction itself, so |
| 383 | /// the caller need not pre-split a motion vector. |
| 384 | /// |
| 385 | /// # Panics |
| 386 | /// Panics when `dst` is not `block_w * block_h` long, or the reference is |
| 387 | /// empty. |
| 388 | // one reference plane, one position, one block shape |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | /// [`predict`], selecting the interpolation filter kernel explicitly (spec |
| 415 | /// 6.8.9's `interpolation_filter`) instead of always `Regular` -- the same |
| 416 | /// kernel both directions. |
| 417 | |
| 418 | |
| 419 | |
| 420 | |
| 421 | |
| 422 | |
| 423 | |
| 424 | |
| 425 | |
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 | |
| 431 | |
| 432 | |
| 433 | |
| 434 | |
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 | |
| 441 | |
| 442 | |
| 443 | |
| 444 | |
| 445 | /// [`predict_with_filter`], with the horizontal (`interp_filter[0]`) and |
| 446 | /// vertical (`interp_filter[1]`) kernels chosen independently -- spec |
| 447 | /// 5.11.20's per-block `SWITCHABLE` read is per-direction (`enable_dual_filter`), |
| 448 | /// so the two passes can genuinely differ. |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | /// [`predict_with_filters`] with the 4-tap decision taken from the block's |
| 470 | /// TRUE width/height (`kern_w`/`kern_h`) rather than the destination buffer's. |
| 471 | /// libaom's `av1_get_interp_filter_params_with_block_size` (reconinter.h, |
| 472 | /// called per axis from `inter_predictor` with `w` then `h`) picks the narrow |
| 473 | /// kernel from the PREDICTION block's own dimensions; our inter path predicts |
| 474 | /// a rectangular block over its enclosing square buffer, so a rect block whose |
| 475 | /// chroma is 4 wide or 4 tall (luma 8x16 / 16x8 and taller kin) must still ask |
| 476 | /// for the 4-tap kernel on that axis -- lane-rectchroma2 r1. |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 512 | |
| 513 | |
| 514 | |
| 515 | |
| 516 | |
| 517 | |
| 518 | |
| 519 | |
| 520 | |
| 521 | |
| 522 | |
| 523 | |
| 524 | |
| 525 | |
| 526 | |
| 527 | |
| 528 | |
| 529 | |
| 530 | |
| 531 | |
| 532 | |
| 533 | |
| 534 | |
| 535 | |
| 536 | |
| 537 | |
| 538 | |
| 539 | |
| 540 | |
| 541 | |
| 542 | |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | |
| 551 | |
| 552 | |
| 553 | |
| 554 | |
| 555 | |
| 556 | |
| 557 | |
| 558 | |
| 559 | |
| 560 | |
| 561 | |
| 562 | |
| 563 | |
| 564 | |
| 565 | |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
| 570 | |
| 571 | |
| 572 | |
| 573 | |
| 574 | |
| 575 | |
| 576 | |
| 577 | |
| 578 | |
| 579 | |
| 580 | |
| 581 | |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | /// `REF_SCALE_SHIFT`'s "no scaling" value (spec 7.11.3.3, libaom `scale.h` |
| 591 | /// `REF_NO_SCALE`): `x_scale_fp == REF_NO_SCALE` means the stored reference's |
| 592 | /// luma width equals the current frame's, so [`predict_scaled`] reduces |
| 593 | /// exactly to [`predict_with_filters`] (verified in |
| 594 | /// `predict_scaled_at_no_scale_matches_predict_with_filters` below). |
| 595 | pub const REF_NO_SCALE: i64 = 1 << 14; |
| 596 | |
| 597 | /// The horizontal scale ratio spec 7.11.3.3 derives from luma widths only |
| 598 | /// (libaom `av1_setup_scale_factors_for_frame`, luma widths, `REF_SCALE_SHIFT |
| 599 | /// == 14`): `other_width` is the stored reference picture's own luma width, |
| 600 | /// `this_width` the current frame's coded luma width. AV1 superres never |
| 601 | /// scales height (r8's derivation), so there is no vertical counterpart. |
| 602 | |
| 603 | |
| 604 | |
| 605 | |
| 606 | thread_local! |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | /// Current value of [`PREDICT_SCALED_HITS`]. |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | thread_local! |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | /// Current value of [`RECT_NARROW_KERN_HITS`]. |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | /// Resets [`RECT_NARROW_KERN_HITS`] (per-attempt counting, class |
| 642 | /// `counter-from-refused-stream`). |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | /// Bumps [`RECT_NARROW_KERN_HITS`] when the block's true dims pick a kernel |
| 648 | /// the destination buffer's dims would not have. |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | /// Current value of [`INTER_PRED_HITS`]. |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | /// `ROUND_POWER_OF_TWO_SIGNED` (libaom `common/common.h`): halves round away |
| 669 | /// from zero's *magnitude* -- negative inputs are rounded like their |
| 670 | /// negation, not truncated toward zero the way a plain arithmetic shift |
| 671 | /// would. |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | /// Spec 7.11.3.3's horizontal pass on a (possibly) scaled reference, shared |
| 681 | /// by [`predict_scaled`] and [`predict_compound_intermediate`] -- the two |
| 682 | /// differ only in their VERTICAL rounding ([`INTER_ROUND_1`] vs |
| 683 | /// [`INTER_ROUND_1_COMPOUND`]), never here. Each output column walks the |
| 684 | /// reference by `x_step_qn` (the Q14 scale rounded down to the Q10 |
| 685 | /// `SCALE_SUBPEL_BITS` grid) and picks its own filter phase from the low |
| 686 | /// bits, so `x_scale_fp == REF_NO_SCALE` reduces to the ordinary stride-1 |
| 687 | /// whole-pel walk with one fixed phase (pinned by |
| 688 | /// `predict_scaled_at_no_scale_matches_predict_with_filters`). |
| 689 | |
| 690 | |
| 691 | |
| 692 | |
| 693 | |
| 694 | |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | |
| 707 | |
| 708 | |
| 709 | |
| 710 | |
| 711 | |
| 712 | |
| 713 | |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | |
| 722 | |
| 723 | |
| 724 | |
| 725 | |
| 726 | |
| 727 | |
| 728 | |
| 729 | /// lane-perf2: the horizontal pass every two-pass entry point takes. |
| 730 | /// `horizontal_scaled_pass` was carrying the UNSCALED work too (every |
| 731 | /// compound prediction goes through it whatever the reference's scale), and |
| 732 | /// its per-column walk re-derives an integer position and a filter phase |
| 733 | /// that are constant at `REF_NO_SCALE`, reads the reference column-major, |
| 734 | /// and clamps per tap -- 14% of decode self time. At `REF_NO_SCALE` the |
| 735 | /// scaled walk reduces algebraically to `x0 = x_q4 / 16`, phase `x_q4 % 16` |
| 736 | /// (`pos_x_q10 == x_q4 * 64 + 32`, so `int_pel == x0` and |
| 737 | /// `(x_qn & 1023) >> 6 == xfrac` for every column), which is exactly |
| 738 | /// [`horizontal_pass_unscaled`] -- and |
| 739 | /// `predict_scaled_at_no_scale_matches_predict_with_filters` pins that |
| 740 | /// equality end to end. A genuinely scaled reference (superres) still takes |
| 741 | /// the general path. |
| 742 | |
| 743 | |
| 744 | |
| 745 | |
| 746 | |
| 747 | |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | |
| 759 | |
| 760 | |
| 761 | |
| 762 | |
| 763 | |
| 764 | |
| 765 | |
| 766 | |
| 767 | |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | |
| 777 | |
| 778 | |
| 779 | |
| 780 | |
| 781 | /// [`predict_with_filters`]'s scaled-reference counterpart (spec 7.11.3.3): |
| 782 | /// used only when the stored reference's luma width differs from the current |
| 783 | /// frame's (`use_superres` on a non-key frame). `x_scale_fp` is |
| 784 | /// [`scale_factor`]'s ratio ([`REF_NO_SCALE`] reproduces |
| 785 | /// `predict_with_filters` bit-exact, pinned by |
| 786 | /// `predict_scaled_at_no_scale_matches_predict_with_filters`). Per r8's |
| 787 | /// derivation AV1 superres never scales height, so `y_q4`'s whole-sample / |
| 788 | /// fraction split and the vertical pass are untouched -- only the horizontal |
| 789 | /// pass's per-column integer position and filter phase come from a scaled |
| 790 | /// walk (`x_qn`) instead of a fixed stride-1 one. |
| 791 | /// |
| 792 | /// # Panics |
| 793 | /// Panics when `dst` is not `block_w * block_h` long, or the reference is |
| 794 | /// empty. |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 815 | |
| 816 | /// [`predict_scaled`] with the 4-tap decision from the block's true dims |
| 817 | /// (see [`predict_with_filters_kern`]). |
| 818 | |
| 819 | |
| 820 | |
| 821 | |
| 822 | |
| 823 | |
| 824 | |
| 825 | |
| 826 | |
| 827 | |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | |
| 836 | |
| 837 | |
| 838 | |
| 839 | |
| 840 | |
| 841 | |
| 842 | |
| 843 | |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | |
| 851 | |
| 852 | |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | |
| 860 | |
| 861 | |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | |
| 868 | |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | /// `InterRound1` for a compound ref (spec 7.11.3.2's `isCompound` branch, |
| 878 | /// `COMPOUND_ROUND1_BITS` in libaom's `convolve.h`): 4 bits shallower than |
| 879 | /// [`INTER_ROUND_1`] so the vertical pass lands in the `CONV_BUF` domain |
| 880 | /// (still above 8-bit pixel range) instead of a finished sample -- |
| 881 | /// `predict_compound_intermediate` below stops there and leaves the final |
| 882 | /// clip to whichever combine step (simple/distance-weighted average, or a |
| 883 | /// future masked blend) runs on the pair of intermediates. |
| 884 | const INTER_ROUND_1_COMPOUND: u32 = 7; |
| 885 | |
| 886 | /// `InterPostRound` (spec 7.11.3.2): `2 * FILTER_BITS - (InterRound0 + |
| 887 | /// InterRound1)` with the *compound* `InterRound1` above -- `2*7 - (3+7) == |
| 888 | /// 4`. [`combine_compound`] folds this together with `DIST_PRECISION_BITS` |
| 889 | /// (below) into one final shift. |
| 890 | const INTER_POST_ROUND: u32 = 4; |
| 891 | |
| 892 | /// `DIST_PRECISION_BITS` (spec 7.11.3.15 / libaom `enums.h`): the two |
| 893 | /// weights [`combine_compound`] takes always sum to `1 << 4 == 16`, whether |
| 894 | /// they are the simple-average split (8/8) or a distance-weighted split |
| 895 | /// from [`crate::compound::dist_wtd_comp_weight_assign`]. |
| 896 | const DIST_PRECISION_BITS: u32 = 4; |
| 897 | |
| 898 | /// [`predict_with_filters`]'s compound counterpart: same two-pass separable |
| 899 | /// filter, but the vertical pass rounds by [`INTER_ROUND_1_COMPOUND`] |
| 900 | /// instead of [`INTER_ROUND_1`] and is never clipped to a pixel -- the |
| 901 | /// `CONV_BUF` intermediate domain spec 7.11.3.2 keeps a compound block's two |
| 902 | /// per-reference predictions in until [`combine_compound`] blends them. |
| 903 | /// `dst` receives one `i32` per sample, row-major, same shape as |
| 904 | /// [`predict_with_filters`]'s `u8` `dst`. |
| 905 | /// |
| 906 | /// # Panics |
| 907 | /// Panics when `dst` is not `block_w * block_h` long, or the reference is |
| 908 | /// empty. |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | |
| 914 | |
| 915 | |
| 916 | |
| 917 | |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | |
| 924 | |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | /// [`predict_compound_intermediate`] with the 4-tap decision from the block's |
| 931 | /// true dims (see [`predict_with_filters_kern`]). |
| 932 | |
| 933 | |
| 934 | |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | |
| 940 | |
| 941 | |
| 942 | |
| 943 | |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | |
| 951 | |
| 952 | |
| 953 | |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | |
| 961 | |
| 962 | |
| 963 | |
| 964 | |
| 965 | |
| 966 | |
| 967 | |
| 968 | |
| 969 | |
| 970 | |
| 971 | |
| 972 | |
| 973 | |
| 974 | |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | |
| 985 | |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | /// Blends two [`predict_compound_intermediate`] outputs into a finished |
| 993 | /// 8-bit block (spec 7.11.3.15's weighted-average combine, the |
| 994 | /// `comp_group_idx == 0` path -- `fwd_weight`/`bck_weight` are either the |
| 995 | /// simple-average split `(8, 8)` or [`crate::compound::dist_wtd_comp_weight_assign`]'s |
| 996 | /// output; both always sum to `1 << DIST_PRECISION_BITS`). Masked compound |
| 997 | /// (`comp_group_idx == 1`, wedge/diffwtd) is a different combine this |
| 998 | /// function does not cover -- decode.rs still refuses those by name. |
| 999 | |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | |
| 1011 | |
| 1012 | |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | |
| 1019 | |
| 1020 | |
| 1021 | |
| 1022 | /// lane-maskcomp r2: `build_compound_diffwtd_mask` (reconinter.c) -- |
| 1023 | /// `DIFFWTD_38`/`DIFFWTD_38_INV` (`mask_type` bit: 0/1). Operates directly on |
| 1024 | /// the two [`predict_compound_intermediate`] outputs: libaom's own |
| 1025 | /// `av1_build_compound_diffwtd_mask_d16_c` runs on its CONV_BUF domain (which |
| 1026 | /// carries a constant `round_offset` bias baked into every sample by its |
| 1027 | /// convolve stage), but `abs(src0 - src1)` cancels an equal bias on both |
| 1028 | /// sides exactly, so the unbiased `i32` intermediates this crate already |
| 1029 | /// produces give the identical `diff` libaom computes. `round` is |
| 1030 | /// `2*FILTER_BITS - round_0 - round_1 + (bd-8)` == [`INTER_POST_ROUND`] for |
| 1031 | /// 8-bit content (`round_0=3`, compound `round_1=7`, `bd=8`). |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | |
| 1036 | |
| 1037 | |
| 1038 | |
| 1039 | |
| 1040 | |
| 1041 | |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | |
| 1047 | |
| 1048 | /// lane-maskcomp r2: `aom_lowbd_blend_a64_d16_mask_c` (blend_a64_mask.c), |
| 1049 | /// algebraically simplified to this crate's unbiased `i32` intermediate |
| 1050 | /// domain the same way [`diffwtd_mask`]'s doc comment derives -- libaom's |
| 1051 | /// `res -= round_offset` step cancels exactly against the bias `m + (64-m) |
| 1052 | /// == 64` contributes equally from both inputs, leaving `(m*pred0 + |
| 1053 | /// (64-m)*pred1) >> 6` (a plain, unrounded shift, matching the C `>>` on |
| 1054 | /// `int32_t`) then one final [`round2`] by [`INTER_POST_ROUND`]. `mask` is |
| 1055 | /// always the LUMA-resolution mask (`mask_stride` == luma block width); |
| 1056 | /// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 / |
| 1057 | /// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read. |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | |
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 | |
| 1076 | |
| 1077 | |
| 1078 | |
| 1079 | |
| 1080 | |
| 1081 | |
| 1082 | |
| 1083 | |
| 1084 | |
| 1085 | |
| 1086 | |
| 1087 | |
| 1088 | |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | /// Whole-pel identity case: [`predict_compound_intermediate`]'s two-pass |
| 1093 | /// filter reduces to `16 * source_sample` exactly (the fraction-0 row is a |
| 1094 | /// single `128` tap both passes, and `128*128 == 1 << 14`, `14 - 7 == 7 == |
| 1095 | /// INTER_ROUND_1_COMPOUND`, so the extra `2^4` of gain the compound path |
| 1096 | /// keeps over [`predict`]'s 11-bit round survives untouched) -- |
| 1097 | /// [`combine_compound`] then divides that back out exactly with an 8/8 |
| 1098 | /// simple-average weight split, so a compound block whose two references |
| 1099 | /// (and MVs) happen to coincide reproduces the plain source sample, not an |
| 1100 | /// off-by-one from double rounding. |
| 1101 | |
| 1102 | |
| 1103 | |
| 1104 | |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 | |
| 1133 | |
| 1134 | |
| 1135 | |
| 1136 | |
| 1137 | |
| 1138 | |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | |
| 1144 | |
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | |
| 1150 | |
| 1151 | |
| 1152 | |
| 1153 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | |
| 1169 | |
| 1170 | |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | |
| 1183 | |
| 1184 | |
| 1185 | |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 | |
| 1201 | |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | |
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | |
| 1232 | |
| 1233 | |
| 1234 | |
| 1235 | |
| 1236 | |
| 1237 | |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | |
| 1253 | |
| 1254 | |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | |
| 1268 | |
| 1269 | |
| 1270 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | |
| 1292 | |
| 1293 | |
| 1294 | |
| 1295 | |
| 1296 | |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | |
| 1318 | |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | |
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 | |
| 1340 | |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | |
| 1360 | |
| 1361 | |
| 1362 | |
| 1363 | |
| 1364 | |
| 1365 | |
| 1366 | |
| 1367 | |
| 1368 | |
| 1369 | |
| 1370 | |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 1386 | |
| 1387 | |
| 1388 | |
| 1389 | |
| 1390 | |
| 1391 | |
| 1392 | |
| 1393 | |
| 1394 | |
| 1395 | |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | |
| 1404 | |
| 1405 | |
| 1406 | |
| 1407 | |
| 1408 | |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | |
| 1413 | |
| 1414 | |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | |
| 1423 | |
| 1424 | |
| 1425 | |
| 1426 | |
| 1427 | |
| 1428 | |
| 1429 | |
| 1430 | |
| 1431 | |
| 1432 | |
| 1433 | |
| 1434 | |
| 1435 | |
| 1436 | |
| 1437 | |
| 1438 | |
| 1439 | |
| 1440 | |
| 1441 | |
| 1442 | |
| 1443 | |
| 1444 | |
| 1445 | |
| 1446 | |
| 1447 | |
| 1448 | |
| 1449 | |
| 1450 | |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | |
| 1456 | |
| 1457 | |
| 1458 | |
| 1459 | |
| 1460 | |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | |
| 1470 | |
| 1471 | |
| 1472 | |
| 1473 | |
| 1474 | |
| 1475 | |
| 1476 | |
| 1477 | |
| 1478 | |
| 1479 | |
| 1480 | |
| 1481 | |
| 1482 | |
| 1483 | |
| 1484 | |
| 1485 | |
| 1486 | |
| 1487 | |
| 1488 | |
| 1489 | |
| 1490 | |
| 1491 | |
| 1492 |