pub fn cdef_filter_superblock(fi: &FrameInvariants,
                              in_frame: &mut Frame,
                              out_frame: &mut Frame,
                              bc_global: &mut BlockContext,
                              sbo: &SuperBlockOffset,
                              sbo_global: &SuperBlockOffset,
                              bit_depth: usize,
                              cdef_index: u8,
                              cdef_dirs: &CdefDirections) {
    let coeff_shift = bit_depth as i32 - 8;
    let cdef_damping = fi.cdef_damping as i32;
    let cdef_y_strength = fi.cdef_y_strengths[cdef_index as usize];
    let cdef_uv_strength = fi.cdef_uv_strengths[cdef_index as usize];
    let cdef_pri_y_strength = (cdef_y_strength / CDEF_SEC_STRENGTHS) as i32;
    let mut cdef_sec_y_strength = (cdef_y_strength % CDEF_SEC_STRENGTHS) as i32;
    let cdef_pri_uv_strength = (cdef_uv_strength / CDEF_SEC_STRENGTHS) as i32;
    let mut cdef_sec_uv_strength = (cdef_uv_strength % CDEF_SEC_STRENGTHS) as i32;
    if cdef_sec_y_strength == 3 {
        cdef_sec_y_strength += 1;
    }
    if cdef_sec_uv_strength == 3 {
        cdef_sec_uv_strength += 1;
    }

    // Each direction block is 8x8 in y, potentially smaller if subsampled in chroma
    for by in 0..8 {
        for bx in 0..8 {
            let global_block_offset = sbo_global.block_offset(bx<<1, by<<1);
            if global_block_offset.x < bc_global.cols && global_block_offset.y < bc_global.rows {
                let skip = bc_global.at(&global_block_offset).skip
                         & bc_global.at(&sbo_global.block_offset(2*bx+1, 2*by)).skip
                         & bc_global.at(&sbo_global.block_offset(2*bx, 2*by+1)).skip
                         & bc_global.at(&sbo_global.block_offset(2*bx+1, 2*by+1)).skip;
                if !skip {
                    let dir = cdef_dirs.dir[bx][by];
                    let var = cdef_dirs.var[bx][by];
                    for p in 0..3 {
                        let mut out_plane = &mut out_frame.planes[p];
                        let out_po = sbo.plane_offset(&out_plane.cfg);
                        let mut in_plane = &mut in_frame.planes[p];
                        let in_po = sbo.plane_offset(&in_plane.cfg);
                        let xdec = in_plane.cfg.xdec;
                        let ydec = in_plane.cfg.ydec;

                        let in_stride = in_plane.cfg.stride;
                        let in_slice = &in_plane.mut_slice(&in_po);
                        let out_stride = out_plane.cfg.stride;
                        let mut out_slice = &mut out_plane.mut_slice(&out_po);
                            
                        let mut local_pri_strength;
                        let mut local_sec_strength;
                        let mut local_damping: i32 = cdef_damping + coeff_shift;
                        let mut local_dir: usize;
                            
                        if p==0 {
                            local_pri_strength = adjust_strength(cdef_pri_y_strength << coeff_shift, var);
                            local_sec_strength = cdef_sec_y_strength << coeff_shift;
                            local_dir = if cdef_pri_y_strength != 0 {dir as usize} else {0};
                        } else {
                            local_pri_strength = cdef_pri_uv_strength << coeff_shift;
                            local_sec_strength = cdef_sec_uv_strength << coeff_shift;
                            local_damping -= 1;
                            local_dir = if cdef_pri_uv_strength != 0 {dir as usize} else {0};
                        }
                            
                        unsafe {
                            cdef_filter_block(out_slice.offset_as_mutable(8*bx>>xdec,8*by>>ydec),
                                              out_stride as isize,
                                              in_slice.offset(8*bx>>xdec,8*by>>ydec),
                                              in_stride as isize,
                                              local_pri_strength, local_sec_strength, local_dir,
                                              local_damping, local_damping,
                                              8 >> xdec, 8 >> ydec, coeff_shift as i32);
                        }
                    }
                }
            }
        }
    }
}
// We assume in is padded, and the area we'll write out is at least as
// large as the unpadded area of in
// cdef_index is taken from the block context
We assume in is padded, and the area we'll write out is at least as
large as the unpadded area of in
cdef_index is taken from the block context
We assume in is padded and the area we ' ll write out is at least as large as the unpadded area of in cdef_index is taken from the block context
pub fn cdef_filter_superblock(fi: &FrameInvariants,
                              in_frame: &mut Frame,
                              out_frame: &mut Frame,
                              bc_global: &mut BlockContext,
                              sbo: &SuperBlockOffset,
                              sbo_global: &SuperBlockOffset,
                              bit_depth: usize,
                              cdef_index: u8,
                              cdef_dirs: &CdefDirections) {
    let coeff_shift = bit_depth as i32 - 8;
    let cdef_damping = fi.cdef_damping as i32;
    let cdef_y_strength = fi.cdef_y_strengths[cdef_index as usize];
    let cdef_uv_strength = fi.cdef_uv_strengths[cdef_index as usize];
    let cdef_pri_y_strength = (cdef_y_strength / CDEF_SEC_STRENGTHS) as i32;
    let mut cdef_sec_y_strength = (cdef_y_strength % CDEF_SEC_STRENGTHS) as i32;
    let cdef_pri_uv_strength = (cdef_uv_strength / CDEF_SEC_STRENGTHS) as i32;
    let mut cdef_sec_uv_strength = (cdef_uv_strength % CDEF_SEC_STRENGTHS) as i32;
    if cdef_sec_y_strength == 3 {
        cdef_sec_y_strength += 1;
    }
    if cdef_sec_uv_strength == 3 {
        cdef_sec_uv_strength += 1;
    }
    // Each direction block is 8x8 in y, potentially smaller if subsampled in chroma
    for by in 0..8 {
        for bx in 0..8 {
            let global_block_offset = sbo_global.block_offset(bx<<1, by<<1);
            if global_block_offset.x < bc_global.cols && global_block_offset.y < bc_global.rows {
                let skip = bc_global.at(&global_block_offset).skip
                         & bc_global.at(&sbo_global.block_offset(2*bx+1, 2*by)).skip
                         & bc_global.at(&sbo_global.block_offset(2*bx, 2*by+1)).skip
                         & bc_global.at(&sbo_global.block_offset(2*bx+1, 2*by+1)).skip;
                if !skip {
                    let dir = cdef_dirs.dir[bx][by];
                    let var = cdef_dirs.var[bx][by];
                    for p in 0..3 {
                        let mut out_plane = &mut out_frame.planes[p];
                        let out_po = sbo.plane_offset(&out_plane.cfg);
                        let mut in_plane = &mut in_frame.planes[p];
                        let in_po = sbo.plane_offset(&in_plane.cfg);
                        let xdec = in_plane.cfg.xdec;
                        let ydec = in_plane.cfg.ydec;
                        let in_stride = in_plane.cfg.stride;
                        let in_slice = &in_plane.mut_slice(&in_po);
                        let out_stride = out_plane.cfg.stride;
                        let mut out_slice = &mut out_plane.mut_slice(&out_po);
                        let mut local_pri_strength;
                        let mut local_sec_strength;
                        let mut local_damping: i32 = cdef_damping + coeff_shift;
                        let mut local_dir: usize;
                        if p==0 {
                            local_pri_strength = adjust_strength(cdef_pri_y_strength << coeff_shift, var);
                            local_sec_strength = cdef_sec_y_strength << coeff_shift;
                            local_dir = if cdef_pri_y_strength != 0 {dir as usize} else {0};
                        } else {
                            local_pri_strength = cdef_pri_uv_strength << coeff_shift;
                            local_sec_strength = cdef_sec_uv_strength << coeff_shift;
                            local_damping -= 1;
                            local_dir = if cdef_pri_uv_strength != 0 {dir as usize} else {0};
                        }
                        unsafe {
                            cdef_filter_block(out_slice.offset_as_mutable(8*bx>>xdec,8*by>>ydec),
                                              out_stride as isize,
                                              in_slice.offset(8*bx>>xdec,8*by>>ydec),
                                              in_stride as isize,
                                              local_pri_strength, local_sec_strength, local_dir,
                                              local_damping, local_damping,
                                              8 >> xdec, 8 >> ydec, coeff_shift as i32);
                        }
                    }
                }
            }
        }
    }
}
pub fn cdef_filter_superblock ( fi : & FrameInvariants , in_frame : & mut Frame , out_frame : & mut Frame , bc_global : & mut BlockContext , sbo : & SuperBlockOffset , sbo_global : & SuperBlockOffset , bit_depth : usize , cdef_index : u8 , cdef_dirs : & CdefDirections ) { let coeff_shift = bit_depth as i32 - 8 ; let cdef_damping = fi . cdef_damping as i32 ; let cdef_y_strength = fi . cdef_y_strengths [ cdef_index as usize ] ; let cdef_uv_strength = fi . cdef_uv_strengths [ cdef_index as usize ] ; let cdef_pri_y_strength = ( cdef_y_strength / CDEF_SEC_STRENGTHS ) as i32 ; let mut cdef_sec_y_strength = ( cdef_y_strength % CDEF_SEC_STRENGTHS ) as i32 ; let cdef_pri_uv_strength = ( cdef_uv_strength / CDEF_SEC_STRENGTHS ) as i32 ; let mut cdef_sec_uv_strength = ( cdef_uv_strength % CDEF_SEC_STRENGTHS ) as i32 ; if cdef_sec_y_strength == 3 { cdef_sec_y_strength += 1 ; } if cdef_sec_uv_strength == 3 { cdef_sec_uv_strength += 1 ; } // Each direction block is 8x8 in y, potentially smaller if subsampled in chroma for by in 0 .. 8 { for bx in 0 .. 8 { let global_block_offset = sbo_global . block_offset ( bx << 1 , by << 1 ) ; if global_block_offset . x < bc_global . cols && global_block_offset . y < bc_global . rows { let skip = bc_global . at ( & global_block_offset ) . skip & bc_global . at ( & sbo_global . block_offset ( 2 * bx + 1 , 2 * by ) ) . skip & bc_global . at ( & sbo_global . block_offset ( 2 * bx , 2 * by + 1 ) ) . skip & bc_global . at ( & sbo_global . block_offset ( 2 * bx + 1 , 2 * by + 1 ) ) . skip ; if ! skip { let dir = cdef_dirs . dir [ bx ] [ by ] ; let var = cdef_dirs . var [ bx ] [ by ] ; for p in 0 .. 3 { let mut out_plane = & mut out_frame . planes [ p ] ; let out_po = sbo . plane_offset ( & out_plane . cfg ) ; let mut in_plane = & mut in_frame . planes [ p ] ; let in_po = sbo . plane_offset ( & in_plane . cfg ) ; let xdec = in_plane . cfg . xdec ; let ydec = in_plane . cfg . ydec ; let in_stride = in_plane . cfg . stride ; let in_slice = & in_plane . mut_slice ( & in_po ) ; let out_stride = out_plane . cfg . stride ; let mut out_slice = & mut out_plane . mut_slice ( & out_po ) ; let mut local_pri_strength ; let mut local_sec_strength ; let mut local_damping : i32 = cdef_damping + coeff_shift ; let mut local_dir : usize ; if p == 0 { local_pri_strength = adjust_strength ( cdef_pri_y_strength << coeff_shift , var ) ; local_sec_strength = cdef_sec_y_strength << coeff_shift ; local_dir = if cdef_pri_y_strength != 0 { dir as usize } else { 0 } ; } else { local_pri_strength = cdef_pri_uv_strength << coeff_shift ; local_sec_strength = cdef_sec_uv_strength << coeff_shift ; local_damping -= 1 ; local_dir = if cdef_pri_uv_strength != 0 { dir as usize } else { 0 } ; } unsafe { cdef_filter_block ( out_slice . offset_as_mutable ( 8 * bx >> xdec , 8 * by >> ydec ) , out_stride as isize , in_slice . offset ( 8 * bx >> xdec , 8 * by >> ydec ) , in_stride as isize , local_pri_strength , local_sec_strength , local_dir , local_damping , local_damping , 8 >> xdec , 8 >> ydec , coeff_shift as i32 ) ; } } } } } } }
We assume in is padded, and the area we'll write out is at least as
large as the unpadded area of in
cdef_index is taken from the block context
We assume in is padded and the area we ' ll write out is at least as large as the unpadded area of in cdef_index is taken from the block context
fi
&FrameInvariants
in_frame
&mut Frame
out_frame
&mut Frame
bc_global
&mut BlockContext
sbo
&SuperBlockOffset
sbo_global
&SuperBlockOffset
bit_depth
usize
cdef_index
u8
cdef_dirs
&CdefDirections