forge
Explore
Log in

Don't you dare go Hollow

S7: vp8 MC filter as McMode enum (SixTap|Bilinear) instead of a bool flag through predict_luma/predict_chroma

Browse files at this commit

4d4e82ef8bf12afb912904ed429a0fd6398dd5a4Ahmet Kaan GümüşParent: eb7a198
crates/ec-vp8/src/decode.rsmodified+13 -9
@@ -166,7 +166,7 @@ pub struct Decoder {
166166 /// six-tap filters, versions 1-3 the bilinear ones) and full-pel
167167 /// flag (version 3: `fullpixel_mask = ~7`). The decoder never reads
168168 /// `no_lpf` — dead there too.
169- mc_bilinear: bool,
169+ mc_mode: mc::McMode,
170170 mc_fullpel: bool,
171171 }
172172
@@ -219,7 +219,7 @@ impl Decoder {
219219 refs: [None, None, None, None],
220220 segment_map: Vec::new(),
221221 frame_decoded: false,
222- mc_bilinear: false,
222+ mc_mode: mc::McMode::SixTap,
223223 mc_fullpel: false,
224224 }
225225 }
@@ -268,7 +268,11 @@ impl Decoder {
268268 // vp8_setup_version (decodeframe.c:935): the tag's version bits
269269 // pick the MC interpolation filter and full-pel mode for this
270270 // frame (see the field docs on Decoder).
271- self.mc_bilinear = matches!(header.tag.version, 1..=3);
271+ self.mc_mode = if matches!(header.tag.version, 1..=3) {
272+ mc::McMode::Bilinear
273+ } else {
274+ mc::McMode::SixTap
275+ };
272276 self.mc_fullpel = header.tag.version == 3;
273277 let refresh_entropy = header.refresh.refresh_entropy;
274278 let pic = match header.tag.frame_type {
@@ -912,13 +916,13 @@ impl Decoder {
912916 mc::predict_luma(
913917 &reff.y, reff.stride, MC_BORDER, w, h, x + bx, y + by, mb.bmi[b],
914918 mb.mv_clamp && corner,
915- &mut py[by * 16 + bx..], 16, 4, 4, self.mc_bilinear,
919+ &mut py[by * 16 + bx..], 16, 4, 4, self.mc_mode,
916920 );
917921 }
918922 } else {
919923 mc::predict_luma(
920924 &reff.y, reff.stride, MC_BORDER, w, h, x, y, mb.mv, mb.mv_clamp, &mut py, 16,
921- 16, 16, self.mc_bilinear,
925+ 16, 16, self.mc_mode,
922926 );
923927 }
924928
@@ -950,23 +954,23 @@ impl Decoder {
950954 mc::predict_chroma(
951955 &reff.u, reff.uv_stride, MC_BORDER, w, h, cx, cy, uvmv,
952956 mb.mv_clamp, &mut pu[qy4 * 16 + qx4..], 16, 4, 4,
953- self.mc_bilinear,
957+ self.mc_mode,
954958 );
955959 mc::predict_chroma(
956960 &reff.v, reff.uv_stride, MC_BORDER, w, h, cx, cy, uvmv,
957961 mb.mv_clamp, &mut pv[qy4 * 16 + qx4..], 16, 4, 4,
958- self.mc_bilinear,
962+ self.mc_mode,
959963 );
960964 }
961965 } else {
962966 let uvmv = modes::chroma_mv_whole(mb.mv, self.mc_fullpel);
963967 mc::predict_chroma(
964968 &reff.u, reff.uv_stride, MC_BORDER, w, h, x / 2, y / 2, uvmv, true,
965- &mut pu, 16, 8, 8, self.mc_bilinear,
969+ &mut pu, 16, 8, 8, self.mc_mode,
966970 );
967971 mc::predict_chroma(
968972 &reff.v, reff.uv_stride, MC_BORDER, w, h, x / 2, y / 2, uvmv, true,
969- &mut pv, 16, 8, 8, self.mc_bilinear,
973+ &mut pv, 16, 8, 8, self.mc_mode,
970974 );
971975 }
972976
crates/ec-vp8/src/mc.rsmodified+28 -37
@@ -26,6 +26,12 @@ use multiversion::target::match_target;
2626 use crate::frame::clamp255;
2727 use crate::modes;
2828
29+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30+pub(crate) enum McMode {
31+ SixTap,
32+ Bilinear,
33+}
34+
2935 /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes.
3036 const VP8_FILTER_WEIGHT: i32 = 128;
3137 /// `VP8_FILTER_SHIFT` (filter.c): normalize the 7-bit-precision result.
@@ -120,7 +126,7 @@ pub(crate) fn predict_luma(
120126 dst_stride: usize,
121127 bw: usize,
122128 bh: usize,
123- bilinear: bool,
129+ mode: McMode,
124130 ) {
125131 debug_assert!((4..=16).contains(&bw) && bw.is_multiple_of(4));
126132 debug_assert!((4..=16).contains(&bh) && bh.is_multiple_of(4));
@@ -138,7 +144,7 @@ pub(crate) fn predict_luma(
138144 // unclamped split MV may not, so the origin is brought back in range.
139145 let (sx, sy) = clamp_read_origin(sx, sy, stride, vis_h + 2 * border, bw, bh);
140146
141- if bilinear {
147+ if mode == McMode::Bilinear {
142148 bilinear_block(src, stride, sx, sy, fx, fy, dst, dst_stride, bw, bh);
143149 } else {
144150 sixtap_block(src, stride, sx, sy, fx, fy, dst, dst_stride, bw, bh);
@@ -679,7 +685,7 @@ fn bilinear_v_scalar(
679685 /// `vp8_setup_version` picks six-tap for version 0 (and reserved 4-7) and
680686 /// bilinear for versions 1-3 (decodeframe.c:851-860 assigns BOTH
681687 /// `subpixel_predict` and `subpixel_predict8x8` from that one switch, and
682-/// reconinter.c uses them for the chroma predicts). `bilinear` is that
688+/// reconinter.c uses them for the chroma predicts). `mode` is that
683689 /// per-frame selection.
684690 ///
685691 /// When `need_clamp` is set, the MV is first passed through
@@ -700,7 +706,7 @@ pub(crate) fn predict_chroma(
700706 dst_stride: usize,
701707 bw: usize,
702708 bh: usize,
703- bilinear: bool,
709+ mode: McMode,
704710 ) {
705711 debug_assert!((2..=16).contains(&bw) && bw.is_multiple_of(2));
706712 debug_assert!((2..=16).contains(&bh) && bh.is_multiple_of(2));
@@ -723,7 +729,7 @@ pub(crate) fn predict_chroma(
723729 // Chroma planes hold vis_h / 2 visible rows (`vis_*` are luma sizes).
724730 let (sx, sy) = clamp_read_origin(sx, sy, uv_stride, vis_h / 2 + 2 * border, bw, bh);
725731
726- if bilinear {
732+ if mode == McMode::Bilinear {
727733 bilinear_block(src, uv_stride, sx, sy, fx, fy, dst, dst_stride, bw, bh);
728734 } else {
729735 sixtap_block(src, uv_stride, sx, sy, fx, fy, dst, dst_stride, bw, bh);
@@ -917,8 +923,7 @@ mod tests {
917923 // mv.0 is the row component, mv.1 the column component. x=y=8 keeps
918924 // every read inside the visible region of the unextended plane.
919925 predict_luma(
920- &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (16, -8), false, &mut dst, 16, 16, 16,
921- false);
926+ &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (16, -8), false, &mut dst, 16, 16, 16, McMode::SixTap);
922927 for r in 0..16 {
923928 for c in 0..16 {
924929 assert_eq!(dst[r * 16 + c], vis(&p, 8 - 1 + c, 8 + 2 + r), "({r},{c})");
@@ -927,8 +932,7 @@ mod tests {
927932
928933 // Zero MV → identity copy.
929934 predict_luma(
930- &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (0, 0), false, &mut dst, 16, 16, 16,
931- false);
935+ &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (0, 0), false, &mut dst, 16, 16, 16, McMode::SixTap);
932936 for r in 0..16 {
933937 for c in 0..16 {
934938 assert_eq!(dst[r * 16 + c], vis(&p, 8 + c, 8 + r), "({r},{c})");
@@ -939,8 +943,7 @@ mod tests {
939943 // → full-pel offset (x+1, y-2).
940944 let mut dst8 = [0u8; 8 * 8];
941945 predict_chroma(
942- &p, STRIDE, BORDER, VIS_W, VIS_H, 4, 4, (-16, 8), false, &mut dst8, 8, 8, 8,
943- false);
946+ &p, STRIDE, BORDER, VIS_W, VIS_H, 4, 4, (-16, 8), false, &mut dst8, 8, 8, 8, McMode::SixTap);
944947 for r in 0..8 {
945948 for c in 0..8 {
946949 assert_eq!(dst8[r * 8 + c], vis(&p, 4 + 1 + c, 4 - 2 + r), "({r},{c})");
@@ -960,65 +963,53 @@ mod tests {
960963 // Luma: mv (-1000, -1000) < 0 - 152 → both components set to -128
961964 // (left - (16 << 3)); prediction must equal an explicit (-128, -128).
962965 predict_luma(
963- &p, STRIDE, BORDER, 16, 16, 0, 0, (-1000, -1000), true, &mut a, 16, 16, 16,
964- false);
966+ &p, STRIDE, BORDER, 16, 16, 0, 0, (-1000, -1000), true, &mut a, 16, 16, 16, McMode::SixTap);
965967 predict_luma(
966- &p, STRIDE, BORDER, 16, 16, 0, 0, (-128, -128), false, &mut b, 16, 16, 16,
967- false);
968+ &p, STRIDE, BORDER, 16, 16, 0, 0, (-128, -128), false, &mut b, 16, 16, 16, McMode::SixTap);
968969 assert_eq!(a, b);
969970
970971 // Strict threshold: (-152, -152) is NOT clamped (condition is strict
971972 // `<`), (-153, -153) IS clamped to (-128, -128).
972973 predict_luma(
973- &p, STRIDE, BORDER, 16, 16, 0, 0, (-152, -152), true, &mut a, 16, 16, 16,
974- false);
974+ &p, STRIDE, BORDER, 16, 16, 0, 0, (-152, -152), true, &mut a, 16, 16, 16, McMode::SixTap);
975975 predict_luma(
976- &p, STRIDE, BORDER, 16, 16, 0, 0, (-152, -152), false, &mut b, 16, 16, 16,
977- false);
976+ &p, STRIDE, BORDER, 16, 16, 0, 0, (-152, -152), false, &mut b, 16, 16, 16, McMode::SixTap);
978977 assert_eq!(a, b);
979978 predict_luma(
980- &p, STRIDE, BORDER, 16, 16, 0, 0, (-153, -153), true, &mut a, 16, 16, 16,
981- false);
979+ &p, STRIDE, BORDER, 16, 16, 0, 0, (-153, -153), true, &mut a, 16, 16, 16, McMode::SixTap);
982980 predict_luma(
983- &p, STRIDE, BORDER, 16, 16, 0, 0, (-128, -128), false, &mut b, 16, 16, 16,
984- false);
981+ &p, STRIDE, BORDER, 16, 16, 0, 0, (-128, -128), false, &mut b, 16, 16, 16, McMode::SixTap);
985982 assert_eq!(a, b);
986983
987984 // Right/bottom: mv (4000, 4000) > 0 + 144 → set to +128.
988985 predict_luma(
989- &p, STRIDE, BORDER, 16, 16, 0, 0, (4000, 4000), true, &mut a, 16, 16, 16,
990- false);
986+ &p, STRIDE, BORDER, 16, 16, 0, 0, (4000, 4000), true, &mut a, 16, 16, 16, McMode::SixTap);
991987 predict_luma(
992- &p, STRIDE, BORDER, 16, 16, 0, 0, (128, 128), false, &mut b, 16, 16, 16,
993- false);
988+ &p, STRIDE, BORDER, 16, 16, 0, 0, (128, 128), false, &mut b, 16, 16, 16, McMode::SixTap);
994989 assert_eq!(a, b);
995990
996991 // Chroma: 2 * (-2000) < -152 → (-128 >> 1) = -64 per component.
997992 let mut ca = [0u8; 8 * 8];
998993 let mut cb = [0u8; 8 * 8];
999994 predict_chroma(
1000- &p, STRIDE, BORDER, 8, 8, 0, 0, (-2000, -2000), true, &mut ca, 8, 8, 8,
1001- false);
995+ &p, STRIDE, BORDER, 8, 8, 0, 0, (-2000, -2000), true, &mut ca, 8, 8, 8, McMode::SixTap);
1002996 predict_chroma(
1003- &p, STRIDE, BORDER, 8, 8, 0, 0, (-64, -64), false, &mut cb, 8, 8, 8,
1004- false);
997+ &p, STRIDE, BORDER, 8, 8, 0, 0, (-64, -64), false, &mut cb, 8, 8, 8, McMode::SixTap);
1005998 assert_eq!(ca, cb);
1006999
10071000 // Chroma right/bottom: 2 * 2000 > 144 → (128 >> 1) = 64.
10081001 predict_chroma(
1009- &p, STRIDE, BORDER, 8, 8, 0, 0, (2000, 2000), true, &mut ca, 8, 8, 8,
1010- false);
1002+ &p, STRIDE, BORDER, 8, 8, 0, 0, (2000, 2000), true, &mut ca, 8, 8, 8, McMode::SixTap);
10111003 predict_chroma(
1012- &p, STRIDE, BORDER, 8, 8, 0, 0, (64, 64), false, &mut cb, 8, 8, 8,
1013- false);
1004+ &p, STRIDE, BORDER, 8, 8, 0, 0, (64, 64), false, &mut cb, 8, 8, 8, McMode::SixTap);
10141005 assert_eq!(ca, cb);
10151006
10161007 // An in-range MV with need_clamp=true must pass through untouched.
10171008 predict_luma(
1018- &p, STRIDE, BORDER, 16, 16, 0, 0, (10, -10), true, &mut a, 16, 16, 16, false,
1009+ &p, STRIDE, BORDER, 16, 16, 0, 0, (10, -10), true, &mut a, 16, 16, 16, McMode::SixTap,
10191010 );
10201011 predict_luma(
1021- &p, STRIDE, BORDER, 16, 16, 0, 0, (10, -10), false, &mut b, 16, 16, 16, false,
1012+ &p, STRIDE, BORDER, 16, 16, 0, 0, (10, -10), false, &mut b, 16, 16, 16, McMode::SixTap,
10221013 );
10231014 assert_eq!(a, b);
10241015 }