S7: vp8 MC filter as McMode enum (SixTap|Bilinear) instead of a bool flag through predict_luma/predict_chroma
Browse files at this commit4d4e82ef8bf12afb912904ed429a0fd6398dd5a4Parent: eb7a1982 changed files +41 -46
- crates/ec-vp8/src/decode.rs +13 -9
- crates/ec-vp8/src/mc.rs +28 -37
crates/ec-vp8/src/decode.rsmodified+13 -9
| @@ -166,7 +166,7 @@ pub struct Decoder { | |||
| 166 | /// six-tap filters, versions 1-3 the bilinear ones) and full-pel | 166 | /// six-tap filters, versions 1-3 the bilinear ones) and full-pel |
| 167 | /// flag (version 3: `fullpixel_mask = ~7`). The decoder never reads | 167 | /// flag (version 3: `fullpixel_mask = ~7`). The decoder never reads |
| 168 | /// `no_lpf` — dead there too. | 168 | /// `no_lpf` — dead there too. |
| 169 | - mc_bilinear: bool, | 169 | + mc_mode: mc::McMode, |
| 170 | mc_fullpel: bool, | 170 | mc_fullpel: bool, |
| 171 | } | 171 | } |
| 172 | 172 | ||
| @@ -219,7 +219,7 @@ impl Decoder { | |||
| 219 | refs: [None, None, None, None], | 219 | refs: [None, None, None, None], |
| 220 | segment_map: Vec::new(), | 220 | segment_map: Vec::new(), |
| 221 | frame_decoded: false, | 221 | frame_decoded: false, |
| 222 | - mc_bilinear: false, | 222 | + mc_mode: mc::McMode::SixTap, |
| 223 | mc_fullpel: false, | 223 | mc_fullpel: false, |
| 224 | } | 224 | } |
| 225 | } | 225 | } |
| @@ -268,7 +268,11 @@ impl Decoder { | |||
| 268 | // vp8_setup_version (decodeframe.c:935): the tag's version bits | 268 | // vp8_setup_version (decodeframe.c:935): the tag's version bits |
| 269 | // pick the MC interpolation filter and full-pel mode for this | 269 | // pick the MC interpolation filter and full-pel mode for this |
| 270 | // frame (see the field docs on Decoder). | 270 | // 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 | + }; | ||
| 272 | self.mc_fullpel = header.tag.version == 3; | 276 | self.mc_fullpel = header.tag.version == 3; |
| 273 | let refresh_entropy = header.refresh.refresh_entropy; | 277 | let refresh_entropy = header.refresh.refresh_entropy; |
| 274 | let pic = match header.tag.frame_type { | 278 | let pic = match header.tag.frame_type { |
| @@ -912,13 +916,13 @@ impl Decoder { | |||
| 912 | mc::predict_luma( | 916 | mc::predict_luma( |
| 913 | &reff.y, reff.stride, MC_BORDER, w, h, x + bx, y + by, mb.bmi[b], | 917 | &reff.y, reff.stride, MC_BORDER, w, h, x + bx, y + by, mb.bmi[b], |
| 914 | mb.mv_clamp && corner, | 918 | 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, |
| 916 | ); | 920 | ); |
| 917 | } | 921 | } |
| 918 | } else { | 922 | } else { |
| 919 | mc::predict_luma( | 923 | mc::predict_luma( |
| 920 | &reff.y, reff.stride, MC_BORDER, w, h, x, y, mb.mv, mb.mv_clamp, &mut py, 16, | 924 | &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, |
| 922 | ); | 926 | ); |
| 923 | } | 927 | } |
| 924 | 928 | ||
| @@ -950,23 +954,23 @@ impl Decoder { | |||
| 950 | mc::predict_chroma( | 954 | mc::predict_chroma( |
| 951 | &reff.u, reff.uv_stride, MC_BORDER, w, h, cx, cy, uvmv, | 955 | &reff.u, reff.uv_stride, MC_BORDER, w, h, cx, cy, uvmv, |
| 952 | mb.mv_clamp, &mut pu[qy4 * 16 + qx4..], 16, 4, 4, | 956 | mb.mv_clamp, &mut pu[qy4 * 16 + qx4..], 16, 4, 4, |
| 953 | - self.mc_bilinear, | 957 | + self.mc_mode, |
| 954 | ); | 958 | ); |
| 955 | mc::predict_chroma( | 959 | mc::predict_chroma( |
| 956 | &reff.v, reff.uv_stride, MC_BORDER, w, h, cx, cy, uvmv, | 960 | &reff.v, reff.uv_stride, MC_BORDER, w, h, cx, cy, uvmv, |
| 957 | mb.mv_clamp, &mut pv[qy4 * 16 + qx4..], 16, 4, 4, | 961 | mb.mv_clamp, &mut pv[qy4 * 16 + qx4..], 16, 4, 4, |
| 958 | - self.mc_bilinear, | 962 | + self.mc_mode, |
| 959 | ); | 963 | ); |
| 960 | } | 964 | } |
| 961 | } else { | 965 | } else { |
| 962 | let uvmv = modes::chroma_mv_whole(mb.mv, self.mc_fullpel); | 966 | let uvmv = modes::chroma_mv_whole(mb.mv, self.mc_fullpel); |
| 963 | mc::predict_chroma( | 967 | mc::predict_chroma( |
| 964 | &reff.u, reff.uv_stride, MC_BORDER, w, h, x / 2, y / 2, uvmv, true, | 968 | &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, |
| 966 | ); | 970 | ); |
| 967 | mc::predict_chroma( | 971 | mc::predict_chroma( |
| 968 | &reff.v, reff.uv_stride, MC_BORDER, w, h, x / 2, y / 2, uvmv, true, | 972 | &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, |
| 970 | ); | 974 | ); |
| 971 | } | 975 | } |
| 972 | 976 | ||
crates/ec-vp8/src/mc.rsmodified+28 -37
| @@ -26,6 +26,12 @@ use multiversion::target::match_target; | |||
| 26 | use crate::frame::clamp255; | 26 | use crate::frame::clamp255; |
| 27 | use crate::modes; | 27 | use crate::modes; |
| 28 | 28 | ||
| 29 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 30 | +pub(crate) enum McMode { | ||
| 31 | + SixTap, | ||
| 32 | + Bilinear, | ||
| 33 | +} | ||
| 34 | + | ||
| 29 | /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes. | 35 | /// `VP8_FILTER_WEIGHT` (filter.c): tap weights sum to this, DC passes. |
| 30 | const VP8_FILTER_WEIGHT: i32 = 128; | 36 | const VP8_FILTER_WEIGHT: i32 = 128; |
| 31 | /// `VP8_FILTER_SHIFT` (filter.c): normalize the 7-bit-precision result. | 37 | /// `VP8_FILTER_SHIFT` (filter.c): normalize the 7-bit-precision result. |
| @@ -120,7 +126,7 @@ pub(crate) fn predict_luma( | |||
| 120 | dst_stride: usize, | 126 | dst_stride: usize, |
| 121 | bw: usize, | 127 | bw: usize, |
| 122 | bh: usize, | 128 | bh: usize, |
| 123 | - bilinear: bool, | 129 | + mode: McMode, |
| 124 | ) { | 130 | ) { |
| 125 | debug_assert!((4..=16).contains(&bw) && bw.is_multiple_of(4)); | 131 | debug_assert!((4..=16).contains(&bw) && bw.is_multiple_of(4)); |
| 126 | debug_assert!((4..=16).contains(&bh) && bh.is_multiple_of(4)); | 132 | debug_assert!((4..=16).contains(&bh) && bh.is_multiple_of(4)); |
| @@ -138,7 +144,7 @@ pub(crate) fn predict_luma( | |||
| 138 | // unclamped split MV may not, so the origin is brought back in range. | 144 | // unclamped split MV may not, so the origin is brought back in range. |
| 139 | let (sx, sy) = clamp_read_origin(sx, sy, stride, vis_h + 2 * border, bw, bh); | 145 | let (sx, sy) = clamp_read_origin(sx, sy, stride, vis_h + 2 * border, bw, bh); |
| 140 | 146 | ||
| 141 | - if bilinear { | 147 | + if mode == McMode::Bilinear { |
| 142 | bilinear_block(src, stride, sx, sy, fx, fy, dst, dst_stride, bw, bh); | 148 | bilinear_block(src, stride, sx, sy, fx, fy, dst, dst_stride, bw, bh); |
| 143 | } else { | 149 | } else { |
| 144 | sixtap_block(src, stride, sx, sy, fx, fy, dst, dst_stride, bw, bh); | 150 | sixtap_block(src, stride, sx, sy, fx, fy, dst, dst_stride, bw, bh); |
| @@ -679,7 +685,7 @@ fn bilinear_v_scalar( | |||
| 679 | /// `vp8_setup_version` picks six-tap for version 0 (and reserved 4-7) and | 685 | /// `vp8_setup_version` picks six-tap for version 0 (and reserved 4-7) and |
| 680 | /// bilinear for versions 1-3 (decodeframe.c:851-860 assigns BOTH | 686 | /// bilinear for versions 1-3 (decodeframe.c:851-860 assigns BOTH |
| 681 | /// `subpixel_predict` and `subpixel_predict8x8` from that one switch, and | 687 | /// `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 |
| 683 | /// per-frame selection. | 689 | /// per-frame selection. |
| 684 | /// | 690 | /// |
| 685 | /// When `need_clamp` is set, the MV is first passed through | 691 | /// When `need_clamp` is set, the MV is first passed through |
| @@ -700,7 +706,7 @@ pub(crate) fn predict_chroma( | |||
| 700 | dst_stride: usize, | 706 | dst_stride: usize, |
| 701 | bw: usize, | 707 | bw: usize, |
| 702 | bh: usize, | 708 | bh: usize, |
| 703 | - bilinear: bool, | 709 | + mode: McMode, |
| 704 | ) { | 710 | ) { |
| 705 | debug_assert!((2..=16).contains(&bw) && bw.is_multiple_of(2)); | 711 | debug_assert!((2..=16).contains(&bw) && bw.is_multiple_of(2)); |
| 706 | debug_assert!((2..=16).contains(&bh) && bh.is_multiple_of(2)); | 712 | debug_assert!((2..=16).contains(&bh) && bh.is_multiple_of(2)); |
| @@ -723,7 +729,7 @@ pub(crate) fn predict_chroma( | |||
| 723 | // Chroma planes hold vis_h / 2 visible rows (`vis_*` are luma sizes). | 729 | // Chroma planes hold vis_h / 2 visible rows (`vis_*` are luma sizes). |
| 724 | let (sx, sy) = clamp_read_origin(sx, sy, uv_stride, vis_h / 2 + 2 * border, bw, bh); | 730 | let (sx, sy) = clamp_read_origin(sx, sy, uv_stride, vis_h / 2 + 2 * border, bw, bh); |
| 725 | 731 | ||
| 726 | - if bilinear { | 732 | + if mode == McMode::Bilinear { |
| 727 | bilinear_block(src, uv_stride, sx, sy, fx, fy, dst, dst_stride, bw, bh); | 733 | bilinear_block(src, uv_stride, sx, sy, fx, fy, dst, dst_stride, bw, bh); |
| 728 | } else { | 734 | } else { |
| 729 | sixtap_block(src, uv_stride, sx, sy, fx, fy, dst, dst_stride, bw, bh); | 735 | sixtap_block(src, uv_stride, sx, sy, fx, fy, dst, dst_stride, bw, bh); |
| @@ -917,8 +923,7 @@ mod tests { | |||
| 917 | // mv.0 is the row component, mv.1 the column component. x=y=8 keeps | 923 | // mv.0 is the row component, mv.1 the column component. x=y=8 keeps |
| 918 | // every read inside the visible region of the unextended plane. | 924 | // every read inside the visible region of the unextended plane. |
| 919 | predict_luma( | 925 | predict_luma( |
| 920 | - &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (16, -8), false, &mut dst, 16, 16, 16, | 926 | + &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (16, -8), false, &mut dst, 16, 16, 16, McMode::SixTap); |
| 921 | - false); | ||
| 922 | for r in 0..16 { | 927 | for r in 0..16 { |
| 923 | for c in 0..16 { | 928 | for c in 0..16 { |
| 924 | assert_eq!(dst[r * 16 + c], vis(&p, 8 - 1 + c, 8 + 2 + r), "({r},{c})"); | 929 | assert_eq!(dst[r * 16 + c], vis(&p, 8 - 1 + c, 8 + 2 + r), "({r},{c})"); |
| @@ -927,8 +932,7 @@ mod tests { | |||
| 927 | 932 | ||
| 928 | // Zero MV → identity copy. | 933 | // Zero MV → identity copy. |
| 929 | predict_luma( | 934 | predict_luma( |
| 930 | - &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (0, 0), false, &mut dst, 16, 16, 16, | 935 | + &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (0, 0), false, &mut dst, 16, 16, 16, McMode::SixTap); |
| 931 | - false); | ||
| 932 | for r in 0..16 { | 936 | for r in 0..16 { |
| 933 | for c in 0..16 { | 937 | for c in 0..16 { |
| 934 | assert_eq!(dst[r * 16 + c], vis(&p, 8 + c, 8 + r), "({r},{c})"); | 938 | assert_eq!(dst[r * 16 + c], vis(&p, 8 + c, 8 + r), "({r},{c})"); |
| @@ -939,8 +943,7 @@ mod tests { | |||
| 939 | // → full-pel offset (x+1, y-2). | 943 | // → full-pel offset (x+1, y-2). |
| 940 | let mut dst8 = [0u8; 8 * 8]; | 944 | let mut dst8 = [0u8; 8 * 8]; |
| 941 | predict_chroma( | 945 | predict_chroma( |
| 942 | - &p, STRIDE, BORDER, VIS_W, VIS_H, 4, 4, (-16, 8), false, &mut dst8, 8, 8, 8, | 946 | + &p, STRIDE, BORDER, VIS_W, VIS_H, 4, 4, (-16, 8), false, &mut dst8, 8, 8, 8, McMode::SixTap); |
| 943 | - false); | ||
| 944 | for r in 0..8 { | 947 | for r in 0..8 { |
| 945 | for c in 0..8 { | 948 | for c in 0..8 { |
| 946 | assert_eq!(dst8[r * 8 + c], vis(&p, 4 + 1 + c, 4 - 2 + r), "({r},{c})"); | 949 | assert_eq!(dst8[r * 8 + c], vis(&p, 4 + 1 + c, 4 - 2 + r), "({r},{c})"); |
| @@ -960,65 +963,53 @@ mod tests { | |||
| 960 | // Luma: mv (-1000, -1000) < 0 - 152 → both components set to -128 | 963 | // Luma: mv (-1000, -1000) < 0 - 152 → both components set to -128 |
| 961 | // (left - (16 << 3)); prediction must equal an explicit (-128, -128). | 964 | // (left - (16 << 3)); prediction must equal an explicit (-128, -128). |
| 962 | predict_luma( | 965 | predict_luma( |
| 963 | - &p, STRIDE, BORDER, 16, 16, 0, 0, (-1000, -1000), true, &mut a, 16, 16, 16, | 966 | + &p, STRIDE, BORDER, 16, 16, 0, 0, (-1000, -1000), true, &mut a, 16, 16, 16, McMode::SixTap); |
| 964 | - false); | ||
| 965 | predict_luma( | 967 | predict_luma( |
| 966 | - &p, STRIDE, BORDER, 16, 16, 0, 0, (-128, -128), false, &mut b, 16, 16, 16, | 968 | + &p, STRIDE, BORDER, 16, 16, 0, 0, (-128, -128), false, &mut b, 16, 16, 16, McMode::SixTap); |
| 967 | - false); | ||
| 968 | assert_eq!(a, b); | 969 | assert_eq!(a, b); |
| 969 | 970 | ||
| 970 | // Strict threshold: (-152, -152) is NOT clamped (condition is strict | 971 | // Strict threshold: (-152, -152) is NOT clamped (condition is strict |
| 971 | // `<`), (-153, -153) IS clamped to (-128, -128). | 972 | // `<`), (-153, -153) IS clamped to (-128, -128). |
| 972 | predict_luma( | 973 | predict_luma( |
| 973 | - &p, STRIDE, BORDER, 16, 16, 0, 0, (-152, -152), true, &mut a, 16, 16, 16, | 974 | + &p, STRIDE, BORDER, 16, 16, 0, 0, (-152, -152), true, &mut a, 16, 16, 16, McMode::SixTap); |
| 974 | - false); | ||
| 975 | predict_luma( | 975 | predict_luma( |
| 976 | - &p, STRIDE, BORDER, 16, 16, 0, 0, (-152, -152), false, &mut b, 16, 16, 16, | 976 | + &p, STRIDE, BORDER, 16, 16, 0, 0, (-152, -152), false, &mut b, 16, 16, 16, McMode::SixTap); |
| 977 | - false); | ||
| 978 | assert_eq!(a, b); | 977 | assert_eq!(a, b); |
| 979 | predict_luma( | 978 | predict_luma( |
| 980 | - &p, STRIDE, BORDER, 16, 16, 0, 0, (-153, -153), true, &mut a, 16, 16, 16, | 979 | + &p, STRIDE, BORDER, 16, 16, 0, 0, (-153, -153), true, &mut a, 16, 16, 16, McMode::SixTap); |
| 981 | - false); | ||
| 982 | predict_luma( | 980 | predict_luma( |
| 983 | - &p, STRIDE, BORDER, 16, 16, 0, 0, (-128, -128), false, &mut b, 16, 16, 16, | 981 | + &p, STRIDE, BORDER, 16, 16, 0, 0, (-128, -128), false, &mut b, 16, 16, 16, McMode::SixTap); |
| 984 | - false); | ||
| 985 | assert_eq!(a, b); | 982 | assert_eq!(a, b); |
| 986 | 983 | ||
| 987 | // Right/bottom: mv (4000, 4000) > 0 + 144 → set to +128. | 984 | // Right/bottom: mv (4000, 4000) > 0 + 144 → set to +128. |
| 988 | predict_luma( | 985 | predict_luma( |
| 989 | - &p, STRIDE, BORDER, 16, 16, 0, 0, (4000, 4000), true, &mut a, 16, 16, 16, | 986 | + &p, STRIDE, BORDER, 16, 16, 0, 0, (4000, 4000), true, &mut a, 16, 16, 16, McMode::SixTap); |
| 990 | - false); | ||
| 991 | predict_luma( | 987 | predict_luma( |
| 992 | - &p, STRIDE, BORDER, 16, 16, 0, 0, (128, 128), false, &mut b, 16, 16, 16, | 988 | + &p, STRIDE, BORDER, 16, 16, 0, 0, (128, 128), false, &mut b, 16, 16, 16, McMode::SixTap); |
| 993 | - false); | ||
| 994 | assert_eq!(a, b); | 989 | assert_eq!(a, b); |
| 995 | 990 | ||
| 996 | // Chroma: 2 * (-2000) < -152 → (-128 >> 1) = -64 per component. | 991 | // Chroma: 2 * (-2000) < -152 → (-128 >> 1) = -64 per component. |
| 997 | let mut ca = [0u8; 8 * 8]; | 992 | let mut ca = [0u8; 8 * 8]; |
| 998 | let mut cb = [0u8; 8 * 8]; | 993 | let mut cb = [0u8; 8 * 8]; |
| 999 | predict_chroma( | 994 | predict_chroma( |
| 1000 | - &p, STRIDE, BORDER, 8, 8, 0, 0, (-2000, -2000), true, &mut ca, 8, 8, 8, | 995 | + &p, STRIDE, BORDER, 8, 8, 0, 0, (-2000, -2000), true, &mut ca, 8, 8, 8, McMode::SixTap); |
| 1001 | - false); | ||
| 1002 | predict_chroma( | 996 | predict_chroma( |
| 1003 | - &p, STRIDE, BORDER, 8, 8, 0, 0, (-64, -64), false, &mut cb, 8, 8, 8, | 997 | + &p, STRIDE, BORDER, 8, 8, 0, 0, (-64, -64), false, &mut cb, 8, 8, 8, McMode::SixTap); |
| 1004 | - false); | ||
| 1005 | assert_eq!(ca, cb); | 998 | assert_eq!(ca, cb); |
| 1006 | 999 | ||
| 1007 | // Chroma right/bottom: 2 * 2000 > 144 → (128 >> 1) = 64. | 1000 | // Chroma right/bottom: 2 * 2000 > 144 → (128 >> 1) = 64. |
| 1008 | predict_chroma( | 1001 | predict_chroma( |
| 1009 | - &p, STRIDE, BORDER, 8, 8, 0, 0, (2000, 2000), true, &mut ca, 8, 8, 8, | 1002 | + &p, STRIDE, BORDER, 8, 8, 0, 0, (2000, 2000), true, &mut ca, 8, 8, 8, McMode::SixTap); |
| 1010 | - false); | ||
| 1011 | predict_chroma( | 1003 | predict_chroma( |
| 1012 | - &p, STRIDE, BORDER, 8, 8, 0, 0, (64, 64), false, &mut cb, 8, 8, 8, | 1004 | + &p, STRIDE, BORDER, 8, 8, 0, 0, (64, 64), false, &mut cb, 8, 8, 8, McMode::SixTap); |
| 1013 | - false); | ||
| 1014 | assert_eq!(ca, cb); | 1005 | assert_eq!(ca, cb); |
| 1015 | 1006 | ||
| 1016 | // An in-range MV with need_clamp=true must pass through untouched. | 1007 | // An in-range MV with need_clamp=true must pass through untouched. |
| 1017 | predict_luma( | 1008 | 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, |
| 1019 | ); | 1010 | ); |
| 1020 | predict_luma( | 1011 | 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, |
| 1022 | ); | 1013 | ); |
| 1023 | assert_eq!(a, b); | 1014 | assert_eq!(a, b); |
| 1024 | } | 1015 | } |