forge
Explore
Log in

Don't you dare go Hollow

wip(hbd): scale CDEF strength/damping/direction-search by bit-depth coeff_shift

Browse files at this commit

50d59cc49dd769c882fcb68142e24aa6965150c1Ahmet Kaan GümüşParent: 9c66378
libaom cdef_block.c: coeff_shift = bit_depth - 8 scales pri/sec strength
(<< coeff_shift) and damping (luma + coeff_shift, chroma one less), and
cdef_find_dir normalises each sample (>> coeff_shift) before the -128
centring (cdef_block.c:74).

Coded by lane-hbd r6, `cargo check -p ec-av1 --lib` clean, committed by
the orchestrator at the agent's turn cap. NOT yet run against the gate.
crates/ec-av1/src/decode.rsmodified+19 -11
@@ -5106,12 +5106,14 @@ fn cdef_constrain(diff: i32, threshold: i32, damping: i32) -> i32 {
5106 /// Spec 7.15.3's direction search (libaom `cdef_find_dir_c`): the dominant5106 /// Spec 7.15.3's direction search (libaom `cdef_find_dir_c`): the dominant
5107 /// direction of an 8x8 luma window and the variance gap between it and its5107 /// direction of an 8x8 luma window and the variance gap between it and its
5108 /// orthogonal, `sample(row, col)` reading that window's own pixels.5108 /// orthogonal, `sample(row, col)` reading that window's own pixels.
5109-fn cdef_find_dir(sample: impl Fn(usize, usize) -> i32) -> (usize, i32) {5109+fn cdef_find_dir(coeff_shift: i32, sample: impl Fn(usize, usize) -> i32) -> (usize, i32) {
5110 const DIV_TABLE: [i64; 9] = [0, 840, 420, 280, 210, 168, 140, 120, 105];5110 const DIV_TABLE: [i64; 9] = [0, 840, 420, 280, 210, 168, 140, 120, 105];
5111 let mut partial = [[0i64; 15]; 8];5111 let mut partial = [[0i64; 15]; 8];
5112 for i in 0..8i64 {5112 for i in 0..8i64 {
5113 for j in 0..8i64 {5113 for j in 0..8i64 {
5114- let x = i64::from(sample(i as usize, j as usize)) - 128;5114+ // libaom `cdef_find_dir_c`: normalise to an 8-bit sample before
5115+ // accumulating, same as `constrain`'s threshold shift below.
5116+ let x = i64::from(sample(i as usize, j as usize) >> coeff_shift) - 128;
5115 partial[0][(i + j) as usize] += x;5117 partial[0][(i + j) as usize] += x;
5116 partial[1][(i + j / 2) as usize] += x;5118 partial[1][(i + j / 2) as usize] += x;
5117 partial[2][i as usize] += x;5119 partial[2][i as usize] += x;
@@ -5907,7 +5909,10 @@ fn apply_cdef(
5907 let src_y = y.data.clone();5909 let src_y = y.data.clone();
5908 let src_u = u.data.clone();5910 let src_u = u.data.clone();
5909 let src_v = v.data.clone();5911 let src_v = v.data.clone();
5910- let damping = i32::from(cdef.damping);5912+ // libaom `av1_cdef_filter_fb`: `pri_strength = level << coeff_shift`,
5913+ // `sec_strength <<= coeff_shift`, `damping += coeff_shift - (pli != 0)`.
5914+ let coeff_shift = i32::from(bit_depth()) - 8;
5915+ let damping = i32::from(cdef.damping) + coeff_shift;
5911 let damping_uv = (damping - 1).max(0);5916 let damping_uv = (damping - 1).max(0);
5912 let mut mi_r = 0usize;5917 let mut mi_r = 0usize;
5913 while mi_r < skip_grid.mi_rows {5918 while mi_r < skip_grid.mi_rows {
@@ -5925,7 +5930,7 @@ fn apply_cdef(
5925 i32::from(src_y[ny as usize * y_stride + nx as usize])5930 i32::from(src_y[ny as usize * y_stride + nx as usize])
5926 }5931 }
5927 };5932 };
5928- let (dir, var) = cdef_find_dir(|r, c| {5933+ let (dir, var) = cdef_find_dir(coeff_shift, |r, c| {
5929 let (ny, nx) = ((oy + r).min(y_true_h - 1), (ox + c).min(y_true_w - 1));5934 let (ny, nx) = ((oy + r).min(y_true_h - 1), (ox + c).min(y_true_w - 1));
5930 i32::from(src_y[ny * y_stride + nx])5935 i32::from(src_y[ny * y_stride + nx])
5931 });5936 });
@@ -5934,10 +5939,12 @@ fn apply_cdef(
5934 // -- each plane zeroes the shared direction when *its own*5939 // -- each plane zeroes the shared direction when *its own*
5935 // frame-level primary strength is 0, independent of the5940 // frame-level primary strength is 0, independent of the
5936 // per-block adjusted `t` and of the other plane's strength.5941 // per-block adjusted `t` and of the other plane's strength.
5937- let y_dir = if cdef.y_pri_strength[sidx] != 0 { dir } else { 0 };5942+ let y_pri_strength = i32::from(cdef.y_pri_strength[sidx]) << coeff_shift;
5938- let t = cdef_adjust_strength(i32::from(cdef.y_pri_strength[sidx]), var);5943+ let y_sec_strength = i32::from(cdef.y_sec_strength[sidx]) << coeff_shift;
5944+ let y_dir = if y_pri_strength != 0 { dir } else { 0 };
5945+ let t = cdef_adjust_strength(y_pri_strength, var);
5939 let enable_primary = t != 0;5946 let enable_primary = t != 0;
5940- let enable_secondary = cdef.y_sec_strength[sidx] != 0;5947+ let enable_secondary = y_sec_strength != 0;
5941 if enable_primary || enable_secondary {5948 if enable_primary || enable_secondary {
5942 cdef_filter_block(5949 cdef_filter_block(
5943 sample_y,5950 sample_y,
@@ -5947,7 +5954,7 @@ fn apply_cdef(
5947 8,5954 8,
5948 8,5955 8,
5949 t,5956 t,
5950- i32::from(cdef.y_sec_strength[sidx]),5957+ y_sec_strength,
5951 y_dir,5958 y_dir,
5952 damping,5959 damping,
5953 damping,5960 damping,
@@ -5956,10 +5963,11 @@ fn apply_cdef(
5956 );5963 );
5957 }5964 }
5958 5965
5959- let t_uv = i32::from(cdef.uv_pri_strength[sidx]);5966+ let t_uv = i32::from(cdef.uv_pri_strength[sidx]) << coeff_shift;
5967+ let uv_sec_strength = i32::from(cdef.uv_sec_strength[sidx]) << coeff_shift;
5960 let uv_dir = if t_uv != 0 { dir } else { 0 };5968 let uv_dir = if t_uv != 0 { dir } else { 0 };
5961 let enable_primary_uv = t_uv != 0;5969 let enable_primary_uv = t_uv != 0;
5962- let enable_secondary_uv = cdef.uv_sec_strength[sidx] != 0;5970+ let enable_secondary_uv = uv_sec_strength != 0;
5963 if enable_primary_uv || enable_secondary_uv {5971 if enable_primary_uv || enable_secondary_uv {
5964 let (cox, coy) = (ox / 2, oy / 2);5972 let (cox, coy) = (ox / 2, oy / 2);
5965 for (plane, src_p) in [(&mut *u, &src_u), (&mut *v, &src_v)] {5973 for (plane, src_p) in [(&mut *u, &src_u), (&mut *v, &src_v)] {
@@ -5981,7 +5989,7 @@ fn apply_cdef(
5981 4,5989 4,
5982 4,5990 4,
5983 t_uv,5991 t_uv,
5984- i32::from(cdef.uv_sec_strength[sidx]),5992+ uv_sec_strength,
5985 uv_dir,5993 uv_dir,
5986 damping_uv,5994 damping_uv,
5987 damping_uv,5995 damping_uv,