Commit fc992256 authored by Tristan Matthews's avatar Tristan Matthews Committed by Luca Barbato

cdef: pull some expressions out of loops

parent 4078c2a3
......@@ -151,27 +151,30 @@ unsafe fn cdef_filter_block<T: Pixel>(
let mut max = x;
let mut min = x;
for k in 0..2usize {
let p = [*ptr_in.offset(cdef_directions[dir][k]),
*ptr_in.offset(-cdef_directions[dir][k])];
sum = p.iter().fold(sum, |sum, &elem| { sum + pri_taps[k] * constrain(i32::cast_from(elem) - i32::cast_from(x), pri_strength, damping) });
let cdef_dirs = [cdef_directions[dir][k], cdef_directions[(dir + 2) & 7][k], cdef_directions[(dir + 6) & 7][k]];
let pri_tap = pri_taps[k];
let p = [*ptr_in.offset(cdef_dirs[0]),
*ptr_in.offset(-cdef_dirs[0])];
for p_elem in p.iter() {
sum += pri_tap * constrain(i32::cast_from(*p_elem) - i32::cast_from(x), pri_strength, damping);
if *p_elem != CDEF_VERY_LARGE {
max = cmp::max(*p_elem, max);
}
min = cmp::min(*p_elem, min);
}
let s = [*ptr_in.offset(cdef_directions[(dir + 2) & 7][k]),
*ptr_in.offset(-cdef_directions[(dir + 2) & 7][k]),
*ptr_in.offset(cdef_directions[(dir + 6) & 7][k]),
*ptr_in.offset(-cdef_directions[(dir + 6) & 7][k])];
let s = [*ptr_in.offset(cdef_dirs[1]),
*ptr_in.offset(-cdef_dirs[1]),
*ptr_in.offset(cdef_dirs[2]),
*ptr_in.offset(-cdef_dirs[2])];
let sec_tap = sec_taps[k];
for s_elem in s.iter() {
if *s_elem != CDEF_VERY_LARGE {
max = cmp::max(*s_elem, max);
}
min = cmp::min(*s_elem, min);
sum += sec_tap * constrain(i32::cast_from(*s_elem) - i32::cast_from(x), sec_strength, damping);
}
sum = s.iter().fold(sum, |sum, &elem| { sum + sec_taps[k] * constrain(i32::cast_from(elem) - i32::cast_from(x), sec_strength, damping) });
}
let v = T::cast_from(i32::cast_from(x) + ((8 + sum - (sum < 0) as i32) >> 4));
*ptr_out = clamp(v, T::cast_from(min), T::cast_from(max));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment