The objective delta_q mapping leans the right way and stops at libaom's clamp
Browse files at this commit3676d057f503b53ef5faec55c01458dff9606055Parent: 4cfdb9d- test
- the objective delta_q mapping leans the right way and stops at libaom's clamp
1 changed file +34 -0
- crates/ec-av1/src/encode.rs +34 -0
crates/ec-av1/src/encode.rsmodified+34 -0
| @@ -12785,6 +12785,40 @@ mod tests { | ||
| 12785 | 12785 | assert_eq!(plane.block_sse(32, 32, 16, &block), (190.0 * 190.0) * 64.0); |
| 12786 | 12786 | } |
| 12787 | 12787 | |
| 12788 | + /// lane-dq: libaom's objective mapping ([`super::deltaq_libaom`]) must | |
| 12789 | + /// spend WHERE THE WINDOW LEANS, stay congruent to the base on the | |
| 12790 | + /// `delta_q_res` grid, and stop at libaom's own `+-(res * 9 - 1)` bound. | |
| 12791 | + #[test] | |
| 12792 | + fn the_objective_delta_q_mapping_leans_the_right_way_and_stops_at_libaom_s_clamp() { | |
| 12793 | + let (base, res) = (162u8, 4i32); | |
| 12794 | + let rf = 2.0; | |
| 12795 | + // A superblock the window leans on more than the frame average is | |
| 12796 | + // coded FINER (lower qindex); a slack one coarser; the average one | |
| 12797 | + // exactly at the base. | |
| 12798 | + assert!(super::deltaq_libaom(base, 8.0, rf, 1.0, res) < base, "leaned-on SB must go finer"); | |
| 12799 | + assert!(super::deltaq_libaom(base, 0.2, rf, 1.0, res) > base, "idle SB must go coarser"); | |
| 12800 | + assert_eq!(super::deltaq_libaom(base, rf, rf, 1.0, res), base, "the average SB moves 0"); | |
| 12801 | + // Every offset is a whole number of steps and inside +-(res * 9 - 1). | |
| 12802 | + let max = ((res * 9 - 1) / res) * res; | |
| 12803 | + for r in [0.0f64, 0.01, 0.5, 1.0, 3.0, 50.0, 1e6] { | |
| 12804 | + for k in [0.5f64, 1.0, 1.5] { | |
| 12805 | + let q = i32::from(super::deltaq_libaom(base, r, rf, k, res)); | |
| 12806 | + let d = q - i32::from(base); | |
| 12807 | + assert_eq!(d % res, 0, "r={r} k={k}: offset {d} is not a whole {res}-step"); | |
| 12808 | + assert!(d.abs() <= max, "r={r} k={k}: offset {d} past libaom's +-{max}"); | |
| 12809 | + } | |
| 12810 | + } | |
| 12811 | + // The clamp is REACHED from both ends, so the bound is a real bound | |
| 12812 | + // and not a formula that never gets there. | |
| 12813 | + assert_eq!(i32::from(super::deltaq_libaom(base, 1e9, rf, 1.0, res)) - i32::from(base), -max); | |
| 12814 | + assert_eq!(i32::from(super::deltaq_libaom(base, 0.0, 1e9, 1.0, res)) - i32::from(base), max); | |
| 12815 | + // A stronger `k` never moves less than a weaker one. | |
| 12816 | + let d = |k: f64| (i32::from(super::deltaq_libaom(base, 8.0, rf, k, res)) - i32::from(base)).abs(); | |
| 12817 | + assert!(d(0.5) <= d(1.0) && d(1.0) <= d(1.5), "strength must be monotone: {} {} {}", d(0.5), d(1.0), d(1.5)); | |
| 12818 | + // The frame reference is libaom's log-mean: flat in, the same value out. | |
| 12819 | + assert!((super::tpl_frame_ratio(&[2.5; 16]) - 2.5).abs() < 1e-9); | |
| 12820 | + } | |
| 12821 | + | |
| 12788 | 12822 | #[test] |
| 12789 | 12823 | fn tpl_factors_are_flat_on_a_uniform_repeat_and_fall_where_the_window_leans() { |
| 12790 | 12824 | // Four 64x64 superblocks across: the shipped map forms its ratio per |