forge
Explore
Log in

Don't you dare go Hollow

U5: remove ec-vp8 DC-shortcut transforms and hand-value tests

Browse files at this commit

3dc32a56b0e3aba401aebb693e0388199e108633Ahmet Kaan GümüşParent: b0cfde8
iwht4x4_dc and idct4x4_dc are test-only oracles of the full transforms; their tests and the hand-derived sixtap/bilinear/iwht/idct literal tests go with them. Decoder output unchanged.
crates/ec-vp8/src/mc.rsmodified+0 -140
@@ -974,146 +974,6 @@ mod tests {
974 }974 }
975 }975 }
976 976
977- #[test]
978- fn sixtap_pure_horizontal_matches_hand_computed_values() {
979- let p = plane();
980- let mut dst = [0u8; 4 * 4];
981-
982- // mv = (0, 4): full-pel start (16, 12), fx = 4, fy = 0.
983- predict_luma(
984- &p, STRIDE, BORDER, VIS_W, VIS_H, 16, 12, (0, 4), false, &mut dst, 4, 4, 4, false,
985- );
986-
987- // Hand-computed from vp8_sub_pel_filters[4] = { 3, -16, 77, 77, -16, 3 }
988- // and vp8_sub_pel_filters[0] = { 0, 0, 128, 0, 0, 0 } (vertical is the
989- // exact identity over the clamped horizontal intermediate).
990- // out[0][0]: taps are visible pixels (12, 14..19) = [183, 106, 2, 87, 75, 198]:
991- // 183*3 - 106*16 + 2*77 + 87*77 - 75*16 + 198*3 + 64 = 5164
992- // 5164 >> 7 = 40, already in 0..=255.
993- // out[1][2]: taps (13, 17..22) = [153, 188, 219, 13, 86, 194]:
994- // 153*3 - 188*16 + 219*77 + 13*77 - 86*16 + 194*3 + 64 = 14585
995- // 14585 >> 7 = 113.
996- assert_eq!(dst[0], 40);
997- assert_eq!(dst[6], 113);
998-
999- // Full block against the tap-table reference formula.
1000- for r in 0..4 {
1001- for c in 0..4 {
1002- let taps: Vec<i32> = (0..6)
1003- .map(|k| i32::from(vis(&p, 16 + c - 2 + k as usize, 12 + r)))
1004- .collect();
1005- let acc: i32 = taps
1006- .iter()
1007- .zip(SUB_PEL_FILTERS[4])
1008- .map(|(t, f)| t * f)
1009- .sum::<i32>()
1010- + 64;
1011- assert_eq!(
1012- dst[r * 4 + c],
1013- (acc >> 7).clamp(0, 255) as u8,
1014- "out[{r}][{c}] taps={taps:?} acc={acc}"
1015- );
1016- }
1017- }
1018- }
1019-
1020- #[test]
1021- fn sixtap_combined_phase_16x16_matches_hand_computed_values() {
1022- let p = plane();
1023- let mut dst = [0u8; 16 * 16];
1024-
1025- // mv = (14, 18): full-pel start (10, 9), fx = 2, fy = 6.
1026- predict_luma(
1027- &p, STRIDE, BORDER, VIS_W, VIS_H, 8, 8, (14, 18), false, &mut dst, 16, 16, 16, false,
1028- );
1029-
1030- // vp8_sub_pel_filters[2] = { 2, -11, 108, 36, -8, 1 }, each
1031- // intermediate clamped to 0..=255 (e.g. tmp[3][10] taps
1032- // [75, 190, 18, 15, 104, 40], raw dot -184, -184 >> 7 = -2, clamped 0);
1033- // vertical pass with vp8_sub_pel_filters[6] = { 1, -8, 36, 108, -11, 2 }.
1034- //
1035- // out[0][0]: horizontal taps are visible pixels (7, 8..13), giving the
1036- // post-clamp intermediate column h_tmp = [41, 186, 229, 210, 95, 185]:
1037- // 41*1 - 186*8 + 229*36 + 210*108 - 95*11 + 185*2 + 64 = 28866
1038- // 28866 >> 7 = 225, already in 0..=255.
1039- //
1040- // out[5][9]: horizontal taps are visible pixels (11, 15..20),
1041- // h_tmp = [205, 8, 14, 189, 108, 4]:
1042- // 205*1 - 8*8 + 14*36 + 189*108 - 108*11 + 4*2 + 64 = 19941
1043- // 19941 >> 7 = 155.
1044- assert_eq!(dst[0], 225);
1045- assert_eq!(dst[5 * 16 + 9], 155);
1046-
1047- // Full block against the two-pass reference formula.
1048- let mut tmp = [0i32; 21 * 16];
1049- for i in 0..21 {
1050- for j in 0..16 {
1051- let acc: i32 = (0..6)
1052- .map(|k| i32::from(vis(&p, 10 - 2 + j + k, 9 - 2 + i)))
1053- .zip(SUB_PEL_FILTERS[2])
1054- .map(|(t, f)| t * f)
1055- .sum::<i32>()
1056- + 64;
1057- tmp[i * 16 + j] = (acc >> 7).clamp(0, 255);
1058- }
1059- }
1060- for r in 0..16 {
1061- for c in 0..16 {
1062- let acc: i32 = (0..6)
1063- .map(|k| tmp[(r + k) * 16 + c])
1064- .zip(SUB_PEL_FILTERS[6])
1065- .map(|(t, f)| t * f)
1066- .sum::<i32>()
1067- + 64;
1068- assert_eq!(
1069- dst[r * 16 + c],
1070- (acc >> 7).clamp(0, 255) as u8,
1071- "out[{r}][{c}]"
1072- );
1073- }
1074- }
1075- }
1076-
1077- #[test]
1078- fn bilinear_chroma_matches_hand_computed_values() {
1079- let p = plane();
1080- let mut dst = [0u8; 8 * 8];
1081-
1082- // mv = (11, 5): full-pel start (4, 7), fx = 5, fy = 3.
1083- predict_chroma(
1084- &p, STRIDE, BORDER, VIS_W, VIS_H, 4, 6, (11, 5), false, &mut dst, 8, 8, 8, true,
1085- );
1086-
1087- // Horizontal taps { 48, 80 } (phase 5), vertical { 80, 48 } (phase 3),
1088- // both passes (dot + 64) >> 7, no clamp (provably in range).
1089- //
1090- // out[0][0]: tmp[0][0] = (160*48 + 96*80 + 64) >> 7 = 120 from visible
1091- // pixels (4,7),(5,7); tmp[1][0] = (107*48 + 42*80 + 64) >> 7 = 66
1092- // from (4,8),(5,8).
1093- // 120*80 + 66*48 + 64 = 12832, 12832 >> 7 = 100.
1094- // out[3][7]: tmp[3][7] = 84, tmp[4][7] = 189;
1095- // 84*80 + 189*48 + 64 = 15856, 15856 >> 7 = 123.
1096- assert_eq!(dst[0], 100);
1097- assert_eq!(dst[3 * 8 + 7], 123);
1098-
1099- // Full block against the two-pass reference formula.
1100- let mut tmp = [0u16; 9 * 8];
1101- for i in 0..9 {
1102- for j in 0..8 {
1103- tmp[i * 8 + j] = ((i32::from(vis(&p, 4 + j, 7 + i)) * 48
1104- + i32::from(vis(&p, 4 + j + 1, 7 + i)) * 80
1105- + 64)
1106- >> 7) as u16;
1107- }
1108- }
1109- for r in 0..8 {
1110- for c in 0..8 {
1111- let acc = i32::from(tmp[r * 8 + c]) * 80 + i32::from(tmp[(r + 1) * 8 + c]) * 48 + 64;
1112- assert_eq!(dst[r * 8 + c], (acc >> 7) as u8, "out[{r}][{c}]");
1113- }
1114- }
1115- }
1116-
1117 #[test]977 #[test]
1118 fn umv_border_clamps_match_libvpx_arithmetic() {978 fn umv_border_clamps_match_libvpx_arithmetic() {
1119 let p = plane();979 let p = plane();
crates/ec-vp8/src/transform.rsmodified+0 -127
@@ -131,18 +131,6 @@ pub fn iwht4x4(input: &[i16; 16]) -> [i16; 16] {
131 output131 output
132 }132 }
133 133
134-/// One-nonzero-DC shortcut of the inverse WHT
135-/// (RFC 6386 §14.3 `vp8_short_inv_walsh4x4_1_c`, oracle
136-/// `vp8_short_inv_walsh4x4_1_c` in `idctllm.c`).
137-///
138-/// When only `input[0]` is non-zero, every Y-subblock DC equals
139-/// `(input[0] + 3) >> 3`. Bit-identical to `iwht4x4` for such inputs.
140-#[inline]
141-pub fn iwht4x4_dc(input: &[i16; 16]) -> [i16; 16] {
142- let a1 = ((input[0] as i32 + 3) >> 3) as i16;
143- [a1; 16]
144-}
145-
146 /// Full inverse DCT of one dequantized 4x4 coefficient block134 /// Full inverse DCT of one dequantized 4x4 coefficient block
147 /// (RFC 6386 §14.4; oracle `short_idct4x4llm_c` in `idctllm.c`).135 /// (RFC 6386 §14.4; oracle `short_idct4x4llm_c` in `idctllm.c`).
148 ///136 ///
@@ -211,18 +199,6 @@ pub fn idct4x4(coeffs: &[i16; 16]) -> [i16; 16] {
211 output199 output
212 }200 }
213 201
214-/// DC-only inverse DCT shortcut (RFC 6386 §14.4
215-/// `vp8_dc_only_idct_add_c` math; oracle `idctllm.c`): when position 0 is
216-/// the sole non-zero coefficient, every residual pixel is `(dc + 4) >> 3`.
217-///
218-/// Bit-identical to `idct4x4` on such inputs. Not clamped; the caller
219-/// adds and clamps (or uses [`idct4x4_add`]).
220-#[inline]
221-pub fn idct4x4_dc(dc: i16) -> [i16; 16] {
222- let a1 = ((dc as i32 + 4) >> 3) as i16;
223- [a1; 16]
224-}
225-
226 /// Combined per-block reconstruction kernel (RFC 6386 §14.4/§14.5; oracle202 /// Combined per-block reconstruction kernel (RFC 6386 §14.4/§14.5; oracle
227 /// `short_idct4x4llm_c` final loop in `idctllm.c`): inverse-transforms203 /// `short_idct4x4llm_c` final loop in `idctllm.c`): inverse-transforms
228 /// `coeffs` and writes `clamp(predict + residual)` into `recon`.204 /// `coeffs` and writes `clamp(predict + residual)` into `recon`.
@@ -305,38 +281,6 @@ pub fn dequant(
305 mod tests {281 mod tests {
306 use super::*;282 use super::*;
307 283
308- /// Hand-derived: impulse `input[0] = 8`, all else 0. First pass, the
309- /// only touched column (0) reads (8,0,0,0): a1 = 8+0 = 8, b1 = 0,
310- /// c1 = 0, d1 = 8, giving intermediate column 0 = [8,8,8,8]. Second
311- /// pass, every row reads (8,0,0,0): a2 = b2 = c2 = d2 = 8, and
312- /// (8 + 3) >> 3 = 1. Expected: all 16 outputs are 1.
313- #[test]
314- fn iwht_unit_impulse_yields_all_ones() {
315- let mut input = [0i16; 16];
316- input[0] = 8;
317- assert_eq!(iwht4x4(&input), [1i16; 16]);
318- }
319-
320- /// Hand-derived: impulse `input[5] = 8` (row 1, col 1). First pass,
321- /// column 1 reads (0,8,0,0): a1 = 0, b1 = 8, c1 = 8, d1 = 0, giving
322- /// intermediate column 1 = [8, 8, -8, -8]. Second pass, rows 0-1 read
323- /// (0,8,0,0) → outputs (1, 1, -1, -1); rows 2-3 read (0,-8,0,0) →
324- /// (-1, -1, 1, 1) — the Hadamard basis pattern for position (1,1).
325- #[test]
326- fn iwht_impulse_at_row1_col1_yields_hadamard_pattern() {
327- let mut input = [0i16; 16];
328- input[5] = 8;
329- assert_eq!(
330- iwht4x4(&input),
331- [
332- 1, 1, -1, -1, //
333- 1, 1, -1, -1, //
334- -1, -1, 1, 1, //
335- -1, -1, 1, 1,
336- ]
337- );
338- }
339-
340 /// Mixed-coefficient oracle: expected values computed with a Python284 /// Mixed-coefficient oracle: expected values computed with a Python
341 /// model of the exact libvpx integer algorithm (see the model in285 /// model of the exact libvpx integer algorithm (see the model in
342 /// `idct_mixed_block_matches_oracle` below — the WHT variant is the286 /// `idct_mixed_block_matches_oracle` below — the WHT variant is the
@@ -357,49 +301,6 @@ mod tests {
357 );301 );
358 }302 }
359 303
360- /// The `_dc` shortcut must agree with the full transform whenever
361- /// only `input[0]` is non-zero — across the whole practical range,
362- /// including negatives and both i16 extremes (arithmetic shifts are
363- /// floor rounding for negatives in both C and Rust).
364- #[test]
365- fn iwht_dc_shortcut_matches_full_transform() {
366- for v in [
367- 0,
368- 1,
369- -1,
370- 3,
371- -3,
372- 8,
373- -8,
374- 100,
375- -100,
376- 1234,
377- -4321,
378- i16::MAX,
379- i16::MIN,
380- ] {
381- let input = {
382- let mut i = [0i16; 16];
383- i[0] = v;
384- i
385- };
386- assert_eq!(iwht4x4(&input), iwht4x4_dc(&input), "mismatch at dc={v}");
387- }
388- }
389-
390- /// §14.4 DC-only math: input [40, 0, ...] gives every pixel
391- /// (40 + 4) >> 3 = 5.
392- #[test]
393- fn idct_dc_only_40_yields_five() {
394- let coeffs = {
395- let mut c = [0i16; 16];
396- c[0] = 40;
397- c
398- };
399- assert_eq!(idct4x4(&coeffs), [5i16; 16]);
400- assert_eq!(idct4x4_dc(40), [5i16; 16]);
401- }
402-
403 /// Mixed-coefficient oracle. The Python model below is a line-for-line304 /// Mixed-coefficient oracle. The Python model below is a line-for-line
404 /// transcription of libvpx `short_idct4x4llm_c` (same integer math,305 /// transcription of libvpx `short_idct4x4llm_c` (same integer math,
405 /// `short` truncation between passes via `s16`); running it on306 /// `short` truncation between passes via `s16`); running it on
@@ -446,34 +347,6 @@ mod tests {
446 );347 );
447 }348 }
448 349
449- /// The DC-only shortcut must equal the full transform for any value
450- /// at coefficient position 0 (with the rest zero), including the i16
451- /// extremes where the intermediate still fits.
452- #[test]
453- fn idct_dc_shortcut_matches_full_transform() {
454- for v in [
455- 0,
456- 1,
457- -1,
458- 8,
459- -8,
460- 40,
461- -40,
462- 100,
463- -100,
464- 4088,
465- i16::MAX,
466- i16::MIN,
467- ] {
468- let coeffs = {
469- let mut c = [0i16; 16];
470- c[0] = v;
471- c
472- };
473- assert_eq!(idct4x4(&coeffs), idct4x4_dc(v), "mismatch at dc={v}");
474- }
475- }
476-
477 /// §14.5: `idct4x4_add` is `clamp255(predict + idct4x4(coeffs))`350 /// §14.5: `idct4x4_add` is `clamp255(predict + idct4x4(coeffs))`
478 /// pixelwise. With a flat prediction of 100, every output byte must351 /// pixelwise. With a flat prediction of 100, every output byte must
479 /// be the saturated sum; extreme residuals clamp to 0 and 255.352 /// be the saturated sum; extreme residuals clamp to 0 and 255.