forge
Explore
Log in

Don't you dare go Hollow

Filter-intra predictor (spec 7.11.2.3), refusal lifted

Browse files at this commit

f90ea1e936b42ffbf678fbf9eca25ef8acf8aa0bAhmet Kaan GümüşParent: 6efce81
  • feat
    • filter-intra predictor (spec 7.11.2.3), refusal lifted
Show full message
feat(av1): filter-intra predictor (spec 7.11.2.3), refusal lifted

Recursive filter intra: 4x2 sub-blocks, the 7-tap av1_filter_intra_taps
table, five modes. use_filter_intra==1 blocks now predict instead of
erroring. Existing suite green; the real-stream gate that proves the
path against ffmpeg lands next.
crates/ec-av1/src/decode.rsmodified+83 -27
@@ -624,7 +624,7 @@ fn read_intra_mode(
624 cfl: bool,624 cfl: bool,
625 side: usize,625 side: usize,
626 enable_filter_intra: bool,626 enable_filter_intra: bool,
627-) -> Result<(bool, usize, Option<(i32, i32)>)> {627+) -> Result<(bool, usize, Option<(i32, i32)>, Option<usize>)> {
628 let trace = std::env::var_os("EC_AV1_TRACE").is_some();628 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
629 let skip = dec.symbol(&mut cdfs.skip[0]) != 0;629 let skip = dec.symbol(&mut cdfs.skip[0]) != 0;
630 if trace {630 if trace {
@@ -669,6 +669,7 @@ fn read_intra_mode(
669 // of the tile (the pinned CfL stream's actual bug: partition/skip/mode669 // of the tile (the pinned CfL stream's actual bug: partition/skip/mode
670 // matched bit-exact, then `eob_pt` read 5 instead of 6, because this670 // matched bit-exact, then `eob_pt` read 5 instead of 6, because this
671 // symbol's bits were never consumed).671 // symbol's bits were never consumed).
672+ let mut filter_intra = None;
672 if mode == DC_PRED673 if mode == DC_PRED
673 && enable_filter_intra674 && enable_filter_intra
674 && let Some(class) = filter_intra_size_class(side)675 && let Some(class) = filter_intra_size_class(side)
@@ -681,18 +682,14 @@ fn read_intra_mode(
681 );682 );
682 }683 }
683 if use_filter_intra {684 if use_filter_intra {
684- // libaom still reads `filter_intra_mode` to stay in sync, but685+ let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
685- // this decoder does not implement filter-intra prediction686+ if trace {
686- // (spec 7.11.2.3's 5-tap recursive filter) -- refuse rather687+ eprintln!("TRACE filter_intra_mode value={fi_mode}");
687- // than silently miscode the reconstruction, the same pattern688+ }
688- // as this crate's other `Error::unsupported` refusals.689+ filter_intra = Some(fi_mode);
689- let _ = dec.symbol(&mut cdfs.filter_intra_mode);
690- return Err(unsupported(
691- "a filter-intra block (this decoder does not implement the 5.11.14 recursive predictor)",
692- ));
693 }690 }
694 }691 }
695- Ok((skip, mode, alpha))692+ Ok((skip, mode, alpha, filter_intra))
696 }693 }
697 694
698 /// `UV_CFL_PRED` (spec 6.10.19's chroma intra mode enum): the fourteenth695 /// `UV_CFL_PRED` (spec 6.10.19's chroma intra mode enum): the fourteenth
@@ -830,17 +827,29 @@ impl PlaneBuf {
830 reach: Reach,827 reach: Reach,
831 residual: &[i32],828 residual: &[i32],
832 cfl: Option<(i32, &[i32])>,829 cfl: Option<(i32, &[i32])>,
830+ filter_intra: Option<usize>,
833 ) {831 ) {
834 let (above, left, corner) = self.edges(x, y, side, reach);832 let (above, left, corner) = self.edges(x, y, side, reach);
835 let mut prediction = vec![0u8; side * side];833 let mut prediction = vec![0u8; side * side];
836- predict(834+ if let Some(fi_mode) = filter_intra {
837- mode as u8,835+ crate::intra::predict_filter_intra(
838- above.as_deref(),836+ fi_mode,
839- left.as_deref(),837+ above.as_deref(),
840- corner,838+ left.as_deref(),
841- side,839+ corner,
842- &mut prediction,840+ side,
843- );841+ &mut prediction,
842+ );
843+ } else {
844+ predict(
845+ mode as u8,
846+ above.as_deref(),
847+ left.as_deref(),
848+ corner,
849+ side,
850+ &mut prediction,
851+ );
852+ }
844 for row in 0..side {853 for row in 0..side {
845 for col in 0..side {854 for col in 0..side {
846 let idx = row * side + col;855 let idx = row * side + col;
@@ -878,6 +887,7 @@ fn read_plane(
878 tx_side: usize,887 tx_side: usize,
879 base_q_idx: u8,888 base_q_idx: u8,
880 cfl: Option<(i32, &[i32])>,889 cfl: Option<(i32, &[i32])>,
890+ filter_intra: Option<usize>,
881 ) -> Result<Vec<i32>> {891 ) -> Result<Vec<i32>> {
882 let skip_ctx = if plane_idx == 0 {892 let skip_ctx = if plane_idx == 0 {
883 0893 0
@@ -911,7 +921,7 @@ fn read_plane(
911 &residual[..4.min(residual.len())]921 &residual[..4.min(residual.len())]
912 );922 );
913 }923 }
914- plane.reconstruct(x, y, side, predict_mode, reach, &residual, cfl);924+ plane.reconstruct(x, y, side, predict_mode, reach, &residual, cfl, filter_intra);
915 Ok(if tx_side == side {925 Ok(if tx_side == side {
916 residual_grid_placeholder(&levels, side)926 residual_grid_placeholder(&levels, side)
917 } else {927 } else {
@@ -951,7 +961,7 @@ fn decode_block(
951 ) -> Result<()> {961 ) -> Result<()> {
952 let (r, c) = at;962 let (r, c) = at;
953 let (px, py) = (c * SUB, r * SUB);963 let (px, py) = (c * SUB, r * SUB);
954- let (skip, mode, alpha) = read_intra_mode(964+ let (skip, mode, alpha, filter_intra) = read_intra_mode(
955 dec,965 dec,
956 cdfs,966 cdfs,
957 neighbours.above_mode[c],967 neighbours.above_mode[c],
@@ -967,7 +977,16 @@ fn decode_block(
967 if skip {977 if skip {
968 // A skipped block codes no residual syntax at all (spec 5.11.34):978 // A skipped block codes no residual syntax at all (spec 5.11.34):
969 // straight prediction, on every plane.979 // straight prediction, on every plane.
970- y.reconstruct(px, py, side, mode, reach, &vec![0i32; side * side], None);980+ y.reconstruct(
981+ px,
982+ py,
983+ side,
984+ mode,
985+ reach,
986+ &vec![0i32; side * side],
987+ None,
988+ filter_intra,
989+ );
971 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));990 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
972 u.reconstruct(991 u.reconstruct(
973 cpx,992 cpx,
@@ -977,6 +996,7 @@ fn decode_block(
977 Reach::none(),996 Reach::none(),
978 &vec![0i32; chroma_side * chroma_side],997 &vec![0i32; chroma_side * chroma_side],
979 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),998 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
999+ None,
980 );1000 );
981 v.reconstruct(1001 v.reconstruct(
982 cpx,1002 cpx,
@@ -986,6 +1006,7 @@ fn decode_block(
986 Reach::none(),1006 Reach::none(),
987 &vec![0i32; chroma_side * chroma_side],1007 &vec![0i32; chroma_side * chroma_side],
988 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),1008 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
1009+ None,
989 );1010 );
990 luma_grid = vec![0i32; side * side];1011 luma_grid = vec![0i32; side * side];
991 u_grid = vec![0i32; chroma_side * chroma_side];1012 u_grid = vec![0i32; chroma_side * chroma_side];
@@ -994,7 +1015,7 @@ fn decode_block(
994 let around = neighbours.around(at, side);1015 let around = neighbours.around(at, side);
995 luma_grid = read_plane(1016 luma_grid = read_plane(
996 dec, cdfs, luma_set, scans.0, 0, around[0], mode, mode, reach, y, px, py, side,1017 dec, cdfs, luma_set, scans.0, 0, around[0], mode, mode, reach, y, px, py, side,
997- luma_tx, base_q_idx, None,1018+ luma_tx, base_q_idx, None, filter_intra,
998 )?;1019 )?;
999 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));1020 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
1000 u_grid = read_plane(1021 u_grid = read_plane(
@@ -1014,6 +1035,7 @@ fn decode_block(
1014 chroma_tx,1035 chroma_tx,
1015 base_q_idx,1036 base_q_idx,
1016 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),1037 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
1038+ None,
1017 )?;1039 )?;
1018 v_grid = read_plane(1040 v_grid = read_plane(
1019 dec,1041 dec,
@@ -1032,6 +1054,7 @@ fn decode_block(
1032 chroma_tx,1054 chroma_tx,
1033 base_q_idx,1055 base_q_idx,
1034 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),1056 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
1057+ None,
1035 )?;1058 )?;
1036 }1059 }
1037 neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);1060 neighbours.record(at, side, mode, &[luma_grid, u_grid, v_grid]);
@@ -1076,7 +1099,7 @@ fn decode_leaf8(
1076 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec1099 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
1077 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other1100 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other
1078 // `decode_block` caller at 16x16 and up.1101 // `decode_block` caller at 16x16 and up.
1079- let (skip, mode, alpha) = read_intra_mode(1102+ let (skip, mode, alpha, filter_intra) = read_intra_mode(
1080 dec,1103 dec,
1081 cdfs,1104 cdfs,
1082 above_mode,1105 above_mode,
@@ -1090,7 +1113,7 @@ fn decode_leaf8(
1090 let (cpx, cpy) = (px / 2, py / 2);1113 let (cpx, cpy) = (px / 2, py / 2);
1091 let (luma_grid, u_grid, v_grid);1114 let (luma_grid, u_grid, v_grid);
1092 if skip {1115 if skip {
1093- y.reconstruct(px, py, 8, mode, reach, &vec![0i32; 64], None);1116+ y.reconstruct(px, py, 8, mode, reach, &vec![0i32; 64], None, filter_intra);
1094 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));1117 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
1095 u.reconstruct(1118 u.reconstruct(
1096 cpx,1119 cpx,
@@ -1100,6 +1123,7 @@ fn decode_leaf8(
1100 Reach::none(),1123 Reach::none(),
1101 &vec![0i32; 16],1124 &vec![0i32; 16],
1102 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),1125 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
1126+ None,
1103 );1127 );
1104 v.reconstruct(1128 v.reconstruct(
1105 cpx,1129 cpx,
@@ -1109,6 +1133,7 @@ fn decode_leaf8(
1109 Reach::none(),1133 Reach::none(),
1110 &vec![0i32; 16],1134 &vec![0i32; 16],
1111 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),1135 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
1136+ None,
1112 );1137 );
1113 luma_grid = vec![0i32; 64];1138 luma_grid = vec![0i32; 64];
1114 u_grid = vec![0i32; 16];1139 u_grid = vec![0i32; 16];
@@ -1132,6 +1157,7 @@ fn decode_leaf8(
1132 TX8,1157 TX8,
1133 base_q_idx,1158 base_q_idx,
1134 None,1159 None,
1160+ filter_intra,
1135 )?;1161 )?;
1136 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));1162 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, 8));
1137 u_grid = read_plane(1163 u_grid = read_plane(
@@ -1151,6 +1177,7 @@ fn decode_leaf8(
1151 TX4,1177 TX4,
1152 base_q_idx,1178 base_q_idx,
1153 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),1179 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
1180+ None,
1154 )?;1181 )?;
1155 v_grid = read_plane(1182 v_grid = read_plane(
1156 dec,1183 dec,
@@ -1169,6 +1196,7 @@ fn decode_leaf8(
1169 TX4,1196 TX4,
1170 base_q_idx,1197 base_q_idx,
1171 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),1198 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
1199+ None,
1172 )?;1200 )?;
1173 }1201 }
1174 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);1202 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
@@ -2265,7 +2293,16 @@ fn decode_inter_block(
2265 2293
2266 let reach = Reach::of(side, px, py, y.width, y.height);2294 let reach = Reach::of(side, px, py, y.width, y.height);
2267 if skip {2295 if skip {
2268- y.reconstruct(px, py, side, mode, reach, &vec![0i32; side * side], None);2296+ y.reconstruct(
2297+ px,
2298+ py,
2299+ side,
2300+ mode,
2301+ reach,
2302+ &vec![0i32; side * side],
2303+ None,
2304+ None,
2305+ );
2269 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));2306 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
2270 u.reconstruct(2307 u.reconstruct(
2271 cpx,2308 cpx,
@@ -2275,6 +2312,7 @@ fn decode_inter_block(
2275 Reach::none(),2312 Reach::none(),
2276 &vec![0i32; chroma_side * chroma_side],2313 &vec![0i32; chroma_side * chroma_side],
2277 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),2314 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
2315+ None,
2278 );2316 );
2279 v.reconstruct(2317 v.reconstruct(
2280 cpx,2318 cpx,
@@ -2284,6 +2322,7 @@ fn decode_inter_block(
2284 Reach::none(),2322 Reach::none(),
2285 &vec![0i32; chroma_side * chroma_side],2323 &vec![0i32; chroma_side * chroma_side],
2286 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),2324 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
2325+ None,
2287 );2326 );
2288 luma_grid = vec![0i32; side * side];2327 luma_grid = vec![0i32; side * side];
2289 u_grid = vec![0i32; chroma_side * chroma_side];2328 u_grid = vec![0i32; chroma_side * chroma_side];
@@ -2307,6 +2346,7 @@ fn decode_inter_block(
2307 luma_tx,2346 luma_tx,
2308 base_q_idx,2347 base_q_idx,
2309 None,2348 None,
2349+ None,
2310 )?;2350 )?;
2311 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));2351 let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side));
2312 u_grid = read_plane(2352 u_grid = read_plane(
@@ -2326,6 +2366,7 @@ fn decode_inter_block(
2326 chroma_tx,2366 chroma_tx,
2327 base_q_idx,2367 base_q_idx,
2328 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),2368 alpha.zip(ac.as_deref()).map(|((au, _), ac)| (au, ac)),
2369+ None,
2329 )?;2370 )?;
2330 v_grid = read_plane(2371 v_grid = read_plane(
2331 dec,2372 dec,
@@ -2344,6 +2385,7 @@ fn decode_inter_block(
2344 chroma_tx,2385 chroma_tx,
2345 base_q_idx,2386 base_q_idx,
2346 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),2387 alpha.zip(ac.as_deref()).map(|((_, av), ac)| (av, ac)),
2388+ None,
2347 )?;2389 )?;
2348 }2390 }
2349 }2391 }
@@ -2634,7 +2676,16 @@ fn decode_inter_block8(
2634 2676
2635 let reach = Reach::of(SIDE, px, py, y.width, y.height);2677 let reach = Reach::of(SIDE, px, py, y.width, y.height);
2636 if skip {2678 if skip {
2637- y.reconstruct(px, py, SIDE, mode, reach, &vec![0i32; SIDE * SIDE], None);2679+ y.reconstruct(
2680+ px,
2681+ py,
2682+ SIDE,
2683+ mode,
2684+ reach,
2685+ &vec![0i32; SIDE * SIDE],
2686+ None,
2687+ None,
2688+ );
2638 u.reconstruct(2689 u.reconstruct(
2639 cpx,2690 cpx,
2640 cpy,2691 cpy,
@@ -2643,6 +2694,7 @@ fn decode_inter_block8(
2643 Reach::none(),2694 Reach::none(),
2644 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],2695 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
2645 None,2696 None,
2697+ None,
2646 );2698 );
2647 v.reconstruct(2699 v.reconstruct(
2648 cpx,2700 cpx,
@@ -2652,6 +2704,7 @@ fn decode_inter_block8(
2652 Reach::none(),2704 Reach::none(),
2653 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],2705 &vec![0i32; CHROMA_SIDE * CHROMA_SIDE],
2654 None,2706 None,
2707+ None,
2655 );2708 );
2656 luma_grid = vec![0i32; SIDE * SIDE];2709 luma_grid = vec![0i32; SIDE * SIDE];
2657 u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];2710 u_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
@@ -2675,6 +2728,7 @@ fn decode_inter_block8(
2675 TX8,2728 TX8,
2676 base_q_idx,2729 base_q_idx,
2677 None,2730 None,
2731+ None,
2678 )?;2732 )?;
2679 u_grid = read_plane(2733 u_grid = read_plane(
2680 dec,2734 dec,
@@ -2693,6 +2747,7 @@ fn decode_inter_block8(
2693 TX4,2747 TX4,
2694 base_q_idx,2748 base_q_idx,
2695 None,2749 None,
2750+ None,
2696 )?;2751 )?;
2697 v_grid = read_plane(2752 v_grid = read_plane(
2698 dec,2753 dec,
@@ -2711,6 +2766,7 @@ fn decode_inter_block8(
2711 TX4,2766 TX4,
2712 base_q_idx,2767 base_q_idx,
2713 None,2768 None,
2769+ None,
2714 )?;2770 )?;
2715 }2771 }
2716 }2772 }
crates/ec-av1/src/intra.rsmodified+133 -0
@@ -341,6 +341,139 @@ fn dc(above: Option<&[u8]>, left: Option<&[u8]>, side: usize) -> i32 {
341 }341 }
342 }342 }
343 343
344+/// `Intra_Filter_Taps` (spec 7.11.2.3 / libaom `av1_filter_intra_taps`,
345+/// `av1/common/reconintra.c`): five recursive-filter modes (DC/V/H/D157/Paeth
346+/// variants, in that order), each predicting an 8-tap block of eight output
347+/// samples from seven already-known neighbours.
348+const FILTER_INTRA_TAPS: [[[i32; 7]; 8]; 5] = [
349+ [
350+ [-6, 10, 0, 0, 0, 12, 0],
351+ [-5, 2, 10, 0, 0, 9, 0],
352+ [-3, 1, 1, 10, 0, 7, 0],
353+ [-3, 1, 1, 2, 10, 5, 0],
354+ [-4, 6, 0, 0, 0, 2, 12],
355+ [-3, 2, 6, 0, 0, 2, 9],
356+ [-3, 2, 2, 6, 0, 2, 7],
357+ [-3, 1, 2, 2, 6, 3, 5],
358+ ],
359+ [
360+ [-10, 16, 0, 0, 0, 10, 0],
361+ [-6, 0, 16, 0, 0, 6, 0],
362+ [-4, 0, 0, 16, 0, 4, 0],
363+ [-2, 0, 0, 0, 16, 2, 0],
364+ [-10, 16, 0, 0, 0, 0, 10],
365+ [-6, 0, 16, 0, 0, 0, 6],
366+ [-4, 0, 0, 16, 0, 0, 4],
367+ [-2, 0, 0, 0, 16, 0, 2],
368+ ],
369+ [
370+ [-8, 8, 0, 0, 0, 16, 0],
371+ [-8, 0, 8, 0, 0, 16, 0],
372+ [-8, 0, 0, 8, 0, 16, 0],
373+ [-8, 0, 0, 0, 8, 16, 0],
374+ [-4, 4, 0, 0, 0, 0, 16],
375+ [-4, 0, 4, 0, 0, 0, 16],
376+ [-4, 0, 0, 4, 0, 0, 16],
377+ [-4, 0, 0, 0, 4, 0, 16],
378+ ],
379+ [
380+ [-2, 8, 0, 0, 0, 10, 0],
381+ [-1, 3, 8, 0, 0, 6, 0],
382+ [-1, 2, 3, 8, 0, 4, 0],
383+ [0, 1, 2, 3, 8, 2, 0],
384+ [-1, 4, 0, 0, 0, 3, 10],
385+ [-1, 3, 4, 0, 0, 4, 6],
386+ [-1, 2, 3, 4, 0, 4, 4],
387+ [-1, 2, 2, 3, 4, 3, 3],
388+ ],
389+ [
390+ [-12, 14, 0, 0, 0, 14, 0],
391+ [-10, 0, 14, 0, 0, 12, 0],
392+ [-9, 0, 0, 14, 0, 11, 0],
393+ [-8, 0, 0, 0, 14, 10, 0],
394+ [-10, 12, 0, 0, 0, 0, 14],
395+ [-9, 1, 12, 0, 0, 0, 12],
396+ [-8, 0, 0, 12, 0, 1, 11],
397+ [-7, 0, 0, 1, 12, 1, 9],
398+ ],
399+];
400+
401+/// `FILTER_INTRA_SCALE_BITS` (libaom `reconintra.h`): the taps' fixed-point
402+/// shift.
403+const FILTER_INTRA_SCALE_BITS: u32 = 4;
404+
405+/// Recursive filter-intra prediction (spec 7.11.2.3, libaom
406+/// `av1_filter_intra_predictor_c`): walks 4x2 sub-blocks left-to-right,
407+/// top-to-bottom, each of the eight output samples a linear combination of
408+/// seven already-decoded or already-predicted neighbours (never past the
409+/// block's own top row / left column -- unlike the directional modes, this
410+/// one never reaches beyond `side` samples of either edge).
411+///
412+/// `mode` is `0..=4`, indexing [`FILTER_INTRA_TAPS`]/`FILTER_DC_PRED`
413+/// through `FILTER_PAETH_PRED`. `above`/`left`/`corner` are exactly
414+/// [`predict`]'s edge arguments -- a side that does not exist is filled from
415+/// the side that does and a side that runs out is extended by repeating its
416+/// last sample, the same [`Edges::build`] rule every other mode uses, even
417+/// though this mode itself never reaches past its own `side` samples of
418+/// either edge.
419+///
420+/// # Panics
421+/// Panics when `dst` is not `side * side` long, or `side` is not a multiple
422+/// of 4 (spec `av1_filter_intra_allowed_bsize` never offers this mode past
423+/// 32x32, and only on square blocks: 4, 8, 16 or 32).
424+pub fn predict_filter_intra(
425+ mode: usize,
426+ above: Option<&[u8]>,
427+ left: Option<&[u8]>,
428+ corner: Option<u8>,
429+ side: usize,
430+ dst: &mut [u8],
431+) {
432+ assert_eq!(dst.len(), side * side, "the destination is the block");
433+ assert_eq!(side % 4, 0, "filter intra only offers 4/8/16/32");
434+ let edges = Edges::build(above, left, corner, side);
435+ let taps = &FILTER_INTRA_TAPS[mode];
436+ // A (side+1)-square buffer: row 0 / column 0 hold the corner and the
437+ // above/left edges, `buffer[r+1][c+1]` the block's own sample at (r, c).
438+ let mut buffer = vec![0i32; (side + 1) * (side + 1)];
439+ let at = |buffer: &[i32], r: usize, c: usize| buffer[r * (side + 1) + c];
440+ buffer[0] = edges.above(-1);
441+ for c in 0..side {
442+ buffer[c + 1] = edges.above(c as i32);
443+ }
444+ for r in 0..side {
445+ buffer[(r + 1) * (side + 1)] = edges.left(r as i32);
446+ }
447+ let mut r = 1;
448+ while r < side + 1 {
449+ let mut c = 1;
450+ while c < side + 1 {
451+ let p0 = at(&buffer, r - 1, c - 1);
452+ let p1 = at(&buffer, r - 1, c);
453+ let p2 = at(&buffer, r - 1, c + 1);
454+ let p3 = at(&buffer, r - 1, c + 2);
455+ let p4 = at(&buffer, r - 1, c + 3);
456+ let p5 = at(&buffer, r, c - 1);
457+ let p6 = at(&buffer, r + 1, c - 1);
458+ let p = [p0, p1, p2, p3, p4, p5, p6];
459+ for k in 0..8 {
460+ let (r_off, c_off) = (k >> 2, k & 3);
461+ let pr: i32 = taps[k].iter().zip(&p).map(|(t, s)| t * s).sum();
462+ let value = round2(pr, FILTER_INTRA_SCALE_BITS).clamp(0, 255);
463+ let idx = (r + r_off) * (side + 1) + c + c_off;
464+ buffer[idx] = value;
465+ }
466+ c += 4;
467+ }
468+ r += 2;
469+ }
470+ for row in 0..side {
471+ for col in 0..side {
472+ dst[row * side + col] = at(&buffer, row + 1, col + 1) as u8;
473+ }
474+ }
475+}
476+
344 /// `paeth_predict` (spec 7.11.2.2): of the three neighbours, the one nearest477 /// `paeth_predict` (spec 7.11.2.2): of the three neighbours, the one nearest
345 /// the gradient they describe.478 /// the gradient they describe.
346 fn paeth(above: i32, left: i32, corner: i32) -> i32 {479 fn paeth(above: i32, left: i32, corner: i32) -> i32 {