The straddling-edge leaves are offered compound too
Browse files at this commit48a7da3bc24454323deebb3a038642932df4e454Parent: f2d1542- feat
- the straddling-edge leaves are offered compound too
1 changed file +57 -26
- crates/ec-av1/src/encode.rs +57 -26
crates/ec-av1/src/encode.rsmodified+57 -26
| @@ -2856,6 +2856,49 @@ fn search_chroma( | ||
| 2856 | 2856 | /// search, so `NEARESTMV`-or-intra is this function's deliberate first cut |
| 2857 | 2857 | /// (see `write_inter_frame_leaf`'s doc comment). |
| 2858 | 2858 | #[allow(clippy::too_many_arguments)] |
| 2859 | +/// The compound MV stack of each `LAST` + extra-reference pair at one leaf, | |
| 2860 | +/// as [`code_square_inter`] wants them: empty on a frame that codes no | |
| 2861 | +/// `reference_select`, or when the leaf compound candidates are switched off. | |
| 2862 | +/// One helper because THREE leaf call sites need it -- the split quadrants | |
| 2863 | +/// and, since lane-av1comp4, both straddling-edge sites, which used to pass | |
| 2864 | +/// `&[]` and so coded no compound block anywhere along the frame's true edge. | |
| 2865 | +#[allow(clippy::too_many_arguments)] | |
| 2866 | +fn leaf_compound_stacks<'a>( | |
| 2867 | + grid: &MiGrid, | |
| 2868 | + mi_row: usize, | |
| 2869 | + mi_col: usize, | |
| 2870 | + bw4: usize, | |
| 2871 | + bh4: usize, | |
| 2872 | + mi_cols: usize, | |
| 2873 | + mi_rows: usize, | |
| 2874 | + reference_select: bool, | |
| 2875 | + golden: Option<&'a Picture>, | |
| 2876 | + altref: Option<&'a Picture>, | |
| 2877 | +) -> Vec<(i8, &'a Picture, crate::mvstack::CompoundMvStack)> { | |
| 2878 | + if !(reference_select && leaf_compound()) { | |
| 2879 | + return Vec::new(); | |
| 2880 | + } | |
| 2881 | + [ | |
| 2882 | + (crate::mvstack::GOLDEN_FRAME, golden), | |
| 2883 | + (crate::mvstack::ALTREF_FRAME, altref), | |
| 2884 | + ] | |
| 2885 | + .into_iter() | |
| 2886 | + .filter_map(|(r, pic)| { | |
| 2887 | + pic.map(|p| { | |
| 2888 | + ( | |
| 2889 | + r, | |
| 2890 | + p, | |
| 2891 | + crate::mvstack::find_mv_stack_compound( | |
| 2892 | + grid, mi_row, mi_col, bw4, bh4, | |
| 2893 | + (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows, | |
| 2894 | + grid.sign_bias_table(), &[(0, 0); 7], None, | |
| 2895 | + ), | |
| 2896 | + ) | |
| 2897 | + }) | |
| 2898 | + }) | |
| 2899 | + .collect() | |
| 2900 | +} | |
| 2901 | + | |
| 2859 | 2902 | fn code_square_inter( |
| 2860 | 2903 | luma: &mut Plane, |
| 2861 | 2904 | chroma: &mut [Plane; 2], |
| @@ -6093,30 +6136,10 @@ pub(crate) fn encode_inter_frame( | ||
| 6093 | 6136 | let stack = find_mv_stack( |
| 6094 | 6137 | &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows, |
| 6095 | 6138 | ); |
| 6096 | - let cstacks: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> = | |
| 6097 | - if header.reference_select && leaf_compound() { | |
| 6098 | - [ | |
| 6099 | - (crate::mvstack::GOLDEN_FRAME, golden), | |
| 6100 | - (crate::mvstack::ALTREF_FRAME, altref), | |
| 6101 | - ] | |
| 6102 | - .into_iter() | |
| 6103 | - .filter_map(|(r, pic)| { | |
| 6104 | - pic.map(|p| { | |
| 6105 | - ( | |
| 6106 | - r, | |
| 6107 | - p, | |
| 6108 | - crate::mvstack::find_mv_stack_compound( | |
| 6109 | - &grid, mi_row, mi_col, 4, 4, | |
| 6110 | - (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows, | |
| 6111 | - grid.sign_bias_table(), &[(0, 0); 7], None, | |
| 6112 | - ), | |
| 6113 | - ) | |
| 6114 | - }) | |
| 6115 | - }) | |
| 6116 | - .collect() | |
| 6117 | - } else { | |
| 6118 | - Vec::new() | |
| 6119 | - }; | |
| 6139 | + let cstacks = leaf_compound_stacks( | |
| 6140 | + &grid, mi_row, mi_col, 4, 4, mi_cols, mi_rows, | |
| 6141 | + header.reference_select, golden, altref, | |
| 6142 | + ); | |
| 6120 | 6143 | let (leaf, leaf_cost) = code_square_inter( |
| 6121 | 6144 | &mut luma, |
| 6122 | 6145 | &mut chroma, |
| @@ -6279,6 +6302,10 @@ pub(crate) fn encode_inter_frame( | ||
| 6279 | 6302 | let stack = find_mv_stack( |
| 6280 | 6303 | &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows, |
| 6281 | 6304 | ); |
| 6305 | + let cstacks = leaf_compound_stacks( | |
| 6306 | + &grid, mi_row, mi_col, 4, 4, mi_cols, mi_rows, | |
| 6307 | + header.reference_select, golden, altref, | |
| 6308 | + ); | |
| 6282 | 6309 | let (block, _) = code_square_inter( |
| 6283 | 6310 | &mut luma, |
| 6284 | 6311 | &mut chroma, |
| @@ -6287,7 +6314,7 @@ pub(crate) fn encode_inter_frame( | ||
| 6287 | 6314 | &search, |
| 6288 | 6315 | &mode_bits_table, |
| 6289 | 6316 | reference, |
| 6290 | - &stack, &[], fctx, | |
| 6317 | + &stack, &cstacks, fctx, | |
| 6291 | 6318 | ); |
| 6292 | 6319 | // One publication point for every coded leaf |
| 6293 | 6320 | // (`record_mi`): this site used to spell the vote |
| @@ -6312,6 +6339,10 @@ pub(crate) fn encode_inter_frame( | ||
| 6312 | 6339 | let stack = find_mv_stack( |
| 6313 | 6340 | &grid, mi_row, mi_col, 2, 2, LAST_FRAME, mi_cols, mi_rows, |
| 6314 | 6341 | ); |
| 6342 | + let cstacks = leaf_compound_stacks( | |
| 6343 | + &grid, mi_row, mi_col, 2, 2, mi_cols, mi_rows, | |
| 6344 | + header.reference_select, golden, altref, | |
| 6345 | + ); | |
| 6315 | 6346 | let (leaf, _) = code_square_inter( |
| 6316 | 6347 | &mut luma, |
| 6317 | 6348 | &mut chroma, |
| @@ -6320,7 +6351,7 @@ pub(crate) fn encode_inter_frame( | ||
| 6320 | 6351 | &search, |
| 6321 | 6352 | &mode_bits_table, |
| 6322 | 6353 | reference, |
| 6323 | - &stack, &[], fctx, | |
| 6354 | + &stack, &cstacks, fctx, | |
| 6324 | 6355 | ); |
| 6325 | 6356 | // Same publication point as the 16x16 |
| 6326 | 6357 | // straddling leaf above (`record_mi`). |