Search the diagonals too
Browse files at this commitcdfa0380fe950f5fae1580ccfebcb0e5dca9a019Parent: 5f9d4c9- perf
- search the diagonals too
1 changed file +30 -1
- crates/ec-h264/src/enc/mb.rs +30 -1
crates/ec-h264/src/enc/mb.rsmodified+30 -1
| @@ -601,6 +601,34 @@ fn intra_pre_cost( | ||
| 601 | 601 | /// below a half and falls away above it. |
| 602 | 602 | const MV_BITS_WEIGHT: f64 = 0.5; |
| 603 | 603 | |
| 604 | +/// The offsets the whole-sample search steps through, in units of the current | |
| 605 | +/// step size. | |
| 606 | +/// | |
| 607 | +/// A square, not a cross. The cross this used to be could only walk along an | |
| 608 | +/// axis, so a diagonally moving macroblock had to be reached in two steps | |
| 609 | +/// through a point that was worse than both -- and a step search stops at the | |
| 610 | +/// first point it cannot improve on. Adding the four diagonals is worth 0.032 | |
| 611 | +/// dB BD-PSNR-YUV on the film clip and 0.041 on the screen capture for twice | |
| 612 | +/// the candidates in the whole-sample stage, which is the cheap stage: it reads | |
| 613 | +/// the reference in place and never interpolates. | |
| 614 | +/// | |
| 615 | +/// The step the walk starts from was swept with it, at 4, 8 and 16 whole | |
| 616 | +/// samples: -0.580/-0.580/-0.593 dB on the film clip and -0.474/-0.493/-0.529 | |
| 617 | +/// on the screen capture. Four is screen capture's optimum and inside film's | |
| 618 | +/// flat part -- a wider opening step is not a wider search here, it just lands | |
| 619 | +/// the walk further from the seeds, which are already the answer most of the | |
| 620 | +/// time. | |
| 621 | +const ME_PATTERN: [(i16, i16); 8] = [ | |
| 622 | + (1, 0), | |
| 623 | + (-1, 0), | |
| 624 | + (0, 1), | |
| 625 | + (0, -1), | |
| 626 | + (1, 1), | |
| 627 | + (-1, -1), | |
| 628 | + (1, -1), | |
| 629 | + (-1, 1), | |
| 630 | +]; | |
| 631 | + | |
| 604 | 632 | /// What the search charges P_8x8 for its own signalling, against the six bits |
| 605 | 633 | /// a 16x8 or 8x16 is charged: an mb_type that is one bin longer plus four |
| 606 | 634 | /// sub_mb_type bins, before the four predictors' own mvd. |
| @@ -871,7 +899,8 @@ fn choose_inter(pic: &Picture, e: &MbEnc<'_>, mb_x: usize, mb_y: usize) -> Inter | ||
| 871 | 899 | let mut improved = true; |
| 872 | 900 | while improved { |
| 873 | 901 | improved = false; |
| 874 | - for (dx, dy) in [(step, 0), (-step, 0), (0, step), (0, -step)] { | |
| 902 | + for (dx, dy) in ME_PATTERN { | |
| 903 | + let (dx, dy) = (dx * step, dy * step); | |
| 875 | 904 | let cand = [best.0[0] + dx, best.0[1] + dy]; |
| 876 | 905 | if (cand[0] - mvp[0]).abs() > range * 4 |
| 877 | 906 | || (cand[1] - mvp[1]).abs() > range * 4 |