Commit a38a4f54 authored by Monty Montgomery's avatar Monty Montgomery Committed by Thomas Daede
Browse files

Improve block bounds checking in CDEF (#436)

* Improve block bounds checking in CDEF

The block bounds calculation in CDEF was doing nothing due to a
calculation error; due to misunderstanding why, a second, moredetailed
guard was added later that should have been unneccessary.

Correct the earlier/easier check to function properly, remove the more
complex and now unneccessary later guard.

* Move CDEF strength calculaiton outside block loop

Basic CDEF strength is signaled and calculated by superblock; no need
to repeat for each block
parent f038652b
......@@ -253,75 +253,65 @@ pub fn cdef_frame(fi: &FrameInvariants, rec: &mut Frame, bc: &mut BlockContext)
for fby in 0..fb_height {
for fbx in 0..fb_width {
let sbo = SuperBlockOffset { x: fbx, y: fby };
let cdef_index = bc.at(&sbo.block_offset(0,0)).cdef_index;
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 block_offset = sbo.block_offset(bx, by);
if block_offset.x < bc.cols && block_offset.y < bc.rows {
if block_offset.x+bx < bc.cols && block_offset.y+by < bc.rows {
let skip = bc.at(&block_offset).skip;
if !skip {
let mut dir = 0;
let mut var: i32 = 0;
let cdef_index = bc.at(&block_offset).cdef_index;
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;
}
for p in 0..3 {
let mut rec_plane = &mut rec.planes[p];
let rec_po = sbo.plane_offset(&rec_plane.cfg);
let mut cdef_plane = &mut cdef_frame.planes[p];
let xdec = cdef_plane.cfg.xdec;
let ydec = cdef_plane.cfg.ydec;
let mut xsize = (fi.padded_w as i32 - 8*bx as i32 >> xdec as i32) - rec_po.x as i32;
let mut ysize = (fi.padded_h as i32 - 8*by as i32 >> ydec as i32) - rec_po.y as i32;
if xsize > (8>>xdec) {
xsize = 8 >> xdec;
}
if ysize > (8>>ydec) {
ysize = 8 >> ydec;
}
if xsize > 0 && ysize > 0 {
let rec_stride = rec_plane.cfg.stride;
let mut rec_slice = &mut rec_plane.mut_slice(&rec_po);
let cdef_stride = cdef_plane.cfg.stride;
let cdef_po = sbo.plane_offset(&cdef_plane.cfg);
let cdef_slice = &cdef_plane.mut_slice(&cdef_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;
let rec_stride = rec_plane.cfg.stride;
let mut rec_slice = &mut rec_plane.mut_slice(&rec_po);
let cdef_stride = cdef_plane.cfg.stride;
let cdef_po = sbo.plane_offset(&cdef_plane.cfg);
let cdef_slice = &cdef_plane.mut_slice(&cdef_po);
if p==0 {
dir = cdef_find_dir(cdef_slice.offset((8*bx>>xdec)+2,(8*by>>ydec)+2),
cdef_stride, &mut var, coeff_shift);
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};
}
let mut local_pri_strength;
let mut local_sec_strength;
let mut local_damping: i32 = cdef_damping + coeff_shift;
let mut local_dir: usize;
cdef_filter_block(rec_slice.offset_as_mutable(8*bx>>xdec,8*by>>ydec), rec_stride as i32,
cdef_slice.offset(8*bx>>xdec,8*by>>ydec), cdef_stride as i32,
local_pri_strength, local_sec_strength, local_dir,
local_damping, local_damping,
xsize, ysize,
coeff_shift as i32);
if p==0 {
dir = cdef_find_dir(cdef_slice.offset((8*bx>>xdec)+2,(8*by>>ydec)+2),
cdef_stride, &mut var, coeff_shift);
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};
}
cdef_filter_block(rec_slice.offset_as_mutable(8*bx>>xdec,8*by>>ydec), rec_stride as i32,
cdef_slice.offset(8*bx>>xdec,8*by>>ydec), cdef_stride as i32,
local_pri_strength, local_sec_strength, local_dir,
local_damping, local_damping,
8>>xdec, 8>>ydec, coeff_shift as i32);
}
}
}
......
Supports Markdown
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