edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching0 forksRust370.3 MiB84fa44cTahinli2 months ago3331 commits
| 1 | //! Motion compensation: the decoder's inter predictor (`dec_build_inter_predictors`, |
| 2 | //! libvpx `vp9/decoder/vp9_decodeframe.c:593`), the on-the-fly reference border |
| 3 | //! extension (`build_mc_border`, :473), the UMV-border MV clamp |
| 4 | //! (`clamp_mv_to_umv_border_sb`, `vp9/common/vp9_reconinter.c:88`), the |
| 5 | //! switchable filter kernels (`vp9/common/vp9_filter.c`) and the sub-pixel |
| 6 | //! convolve (`vpx_dsp/vpx_convolve.c`). |
| 7 | //! |
| 8 | //! The VP9 decoder does NOT extend the reference frame's borders in place: it |
| 9 | //! builds a bordered copy of the block's reference window per prediction |
| 10 | //! (`extend_and_predict`) whenever the window leaves the frame or the frame's |
| 11 | //! dimensions are not a multiple of 8. A reference slot whose size differs |
| 12 | //! from the current frame is SCALED: [`ScaleFactors`] carries |
| 13 | //! `vp9_setup_scale_factors_for_frame`, the block/MV are mapped into the |
| 14 | //! reference with `vp9_scale_mv`, and the convolve steps by `x_step_q4` / |
| 15 | //! `y_step_q4` (`sf->predict`, `vpx_scaled_*`). |
| 16 | //! |
| 17 | //! Indexing note: libvpx's convolve helpers take a raw pointer and subtract |
| 18 | //! `SUBPEL_TAPS / 2 - 1` from it, so they read taps *before* the block's first |
| 19 | //! sample. Rust slices cannot go negative, so every helper here takes a buffer |
| 20 | //! plus an `origin` (the block's first sample) and indexes with `isize`. |
| 21 | |
| 22 | /// `SUBPEL_BITS` / `SUBPEL_MASK` / `SUBPEL_SHIFTS` / `SUBPEL_TAPS` |
| 23 | /// (`vpx_dsp/vpx_filter.h:23-26`). |
| 24 | const SUBPEL_BITS: i32 = 4; |
| 25 | const SUBPEL_MASK: i32 = - 1; |
| 26 | const SUBPEL_SHIFTS: i32 = 1 << SUBPEL_BITS; |
| 27 | const TAPS: usize = 8; |
| 28 | /// `FILTER_BITS` (`vpx_dsp/vpx_filter.h:21`). |
| 29 | const FILTER_BITS: i32 = 7; |
| 30 | /// `VP9_INTERP_EXTEND` (`vpx_scale/yv12config.h:25`). |
| 31 | const INTERP_EXTEND: i32 = 4; |
| 32 | |
| 33 | /// `REF_SCALE_SHIFT` / `REF_NO_SCALE` / `REF_INVALID_SCALE` |
| 34 | /// (`vp9/common/vp9_scale.h:21-23`): the fixed-point precision of a reference |
| 35 | /// frame's scale factor. |
| 36 | const REF_SCALE_SHIFT: i32 = 14; |
| 37 | const REF_NO_SCALE: i32 = 1 << REF_SCALE_SHIFT; |
| 38 | const REF_INVALID_SCALE: i32 = -1; |
| 39 | |
| 40 | /// `scaled_x` / `scaled_y` (`vp9_scale.c:22`). |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | /// `struct scale_factors` (`vp9/common/vp9_scale.h:27`) set up by |
| 46 | /// `vp9_setup_scale_factors_for_frame` (`vp9_scale.c:44`): the scale from a |
| 47 | /// reference frame's coded size to this frame's, its derived 1/16-pel step |
| 48 | /// (`x_step_q4`/`y_step_q4`; 16 means "no scaling on that axis") and |
| 49 | /// `vp9_scale_mv`. |
| 50 | |
| 51 | pub |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | /// `vp9_filter_kernels` (`vp9/common/vp9_filter.c:79`), in libvpx's filter |
| 121 | /// numbering: 0 `EIGHTTAP`, 1 `EIGHTTAP_SMOOTH`, 2 `EIGHTTAP_SHARP`, |
| 122 | /// 3 `BILINEAR` (the 4-tap index 4 is unreachable for profile 0). |
| 123 | pub const FILTERS: = |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 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 | use crate::; |
| 203 | |
| 204 | /// Read `buf[i]` for a possibly negative `i`. Every caller keeps `i` inside |
| 205 | /// the buffer (the border copy guarantees the tap margins exist). |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | /// `clamp_mv_to_umv_border_sb` (`vp9/common/vp9_reconinter.c:88`), returning |
| 212 | /// the MV in 1/16-pel (`MV_PRECISION_Q4`) units. |
| 213 | /// |
| 214 | /// `mb_*` are the block's distances to the frame edges in 1/8-pel units |
| 215 | /// (`xd->mb_to_*_edge`, i.e. `±mi * 64`); `bw`/`bh` are the PLANE block's |
| 216 | /// pixel dimensions. `clamp_mv(mv, min_col, max_col, min_row, max_row)`: |
| 217 | /// columns are bounded by the left/right edges, rows by the top/bottom. |
| 218 | pub |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | |
| 226 | |
| 227 | |
| 228 | |
| 229 | |
| 230 | |
| 231 | |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | /// `build_mc_border` (`vp9/decoder/vp9_decodeframe.c:473`): copy the |
| 241 | /// `b_w` x `b_h` window whose top-left is frame pixel `(x, y)` into `dst`, |
| 242 | /// replicating the frame's first/last row and column for reads outside |
| 243 | /// `[0, w)` x `[0, h)`. |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 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 | |
| 288 | |
| 289 | |
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | |
| 302 | |
| 303 | |
| 304 | /// `convolve_horiz` / `convolve_avg_horiz` (`vpx_dsp/vpx_convolve.c:22`). |
| 305 | /// `origin` is the block's first sample in `buf`; taps are read from |
| 306 | /// `origin + y*stride + (x_q4 >> SUBPEL_BITS) - (SUBPEL_TAPS / 2 - 1) + k`. |
| 307 | /// `x_step` advances `x_q4` per output sample — `SUBPEL_SHIFTS` for an |
| 308 | /// unscaled reference, `sf->x_step_q4` (the scaled sampler, also used by |
| 309 | /// `vpx_scaled_horiz`) otherwise. |
| 310 | |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | |
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 | |
| 322 | |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 | |
| 336 | |
| 337 | |
| 338 | |
| 339 | |
| 340 | |
| 341 | |
| 342 | |
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | /// `convolve_vert` / `convolve_avg_vert` (`vpx_dsp/vpx_convolve.c:80`). |
| 348 | /// `y_step` advances `y_q4` per output sample (`SUBPEL_SHIFTS` unscaled, |
| 349 | /// `sf->y_step_q4` for `vpx_scaled_vert`). |
| 350 | |
| 351 | |
| 352 | |
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 | |
| 360 | |
| 361 | |
| 362 | |
| 363 | |
| 364 | |
| 365 | |
| 366 | |
| 367 | |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | |
| 373 | |
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 | |
| 380 | |
| 381 | |
| 382 | |
| 383 | |
| 384 | |
| 385 | |
| 386 | |
| 387 | |
| 388 | /// `inter_predictor` + `sf->predict` (`vp9/common/vp9_reconinter.h:23`, |
| 389 | /// `vp9/common/vp9_scale.c:79`): the kernel is picked by |
| 390 | /// `predict[subpel_x != 0][subpel_y != 0][avg]`. Unscaled that is |
| 391 | /// copy/avg, the vertical, the horizontal and the 2D convolve; with a scaled |
| 392 | /// reference the table collapses to the scaled variants (`vpx_scaled_horiz` / |
| 393 | /// `vpx_scaled_vert` — the same walk with `x_step_q4` / `y_step_q4` — and |
| 394 | /// `vpx_scaled_2d`), reproduced here by the step-aware convolve helpers. |
| 395 | /// |
| 396 | /// `w` x `h` output samples written at `dst`; `buf`/`origin` locate the |
| 397 | /// block's first reference sample. `temp` is the `vpx_convolve8` intermediate |
| 398 | /// (stride-64 scratch of `64 * 135` bytes plus a `64 * 64` second scratch for |
| 399 | /// the averaging variant). |
| 400 | |
| 401 | |
| 402 | |
| 403 | |
| 404 | |
| 405 | |
| 406 | |
| 407 | |
| 408 | |
| 409 | |
| 410 | |
| 411 | |
| 412 | |
| 413 | |
| 414 | |
| 415 | |
| 416 | |
| 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 | |
| 446 | |
| 447 | |
| 448 | |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | /// `vpx_convolve8_c` / `vpx_convolve8_avg_c` (`vpx_dsp/vpx_convolve.c:158`) = |
| 497 | /// `vpx_scaled_2d` / `vpx_scaled_avg_2d`: horizontal pass into a stride-64 |
| 498 | /// intermediate with `intermediate_height = (((h - 1) * y_step_q4 + y0_q4) >> |
| 499 | /// SUBPEL_BITS) + SUBPEL_TAPS`, then the vertical pass. The horizontal pass |
| 500 | /// starts `SUBPEL_TAPS / 2 - 1` rows ABOVE the block (C passes |
| 501 | /// `src - src_stride * (SUBPEL_TAPS / 2 - 1)`). |
| 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 | /// One reference plane of a stored frame. |
| 581 | pub |
| 582 | |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | |
| 590 | |
| 591 | |
| 592 | |
| 593 | |
| 594 | |
| 595 | /// `dec_build_inter_predictors` (`vp9/decoder/vp9_decodeframe.c:593`): |
| 596 | /// predict one `w` x `h` plane block whose top-left is plane pixel `(x, y)` |
| 597 | /// inside the block at MI `(mi_row, mi_col)`. `sf` is the reference's scale |
| 598 | /// factors; when they scale, the block is mapped into the reference frame |
| 599 | /// (`scale_value_x/y`), the MV is scaled with it (`vp9_scale_mv`) and the |
| 600 | /// convolve steps by `x_step_q4` / `y_step_q4`. |
| 601 | |
| 602 | pub |
| 603 | |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | |
| 613 | |
| 614 | |
| 615 | |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | |
| 626 | |
| 627 | |
| 628 | |
| 629 | |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | |
| 639 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 655 | |
| 656 | |
| 657 | |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | |
| 666 | |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | |
| 677 | |
| 678 | |
| 679 | |
| 680 | |
| 681 | |
| 682 | |
| 683 | |
| 684 | |
| 685 | |
| 686 | |
| 687 | |
| 688 | |
| 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 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | |
| 734 | |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 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 | /// `average_split_mvs` (`vp9/common/vp9_reconinter.c:113`): the per-sub-block |
| 770 | /// MV of a sub-8x8 inter block, selected by the plane's subsampling. |
| 771 | /// |
| 772 | /// `ss_idx` 0 (luma and 4:4:4 chroma): the sub-block's own MV; 1 (4:4:0): the |
| 773 | /// q2-rounded average of the vertical pair (`block`, `block + 2`); 2 (4:2:2): |
| 774 | /// the horizontal pair (`block`, `block + 1`); 3 (4:2:0): the q4-rounded |
| 775 | /// average of all four. |
| 776 | /// |
| 777 | /// `round_mv_comp_qN(v) = (v < 0 ? v - N/2 : v + N/2) / N` — C's truncating |
| 778 | /// division, which Rust's `/` on integers reproduces. |
| 779 | pub |
| 780 | |
| 781 | |
| 782 | |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | |
| 795 | |
| 796 | |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 |