Commit 2e9aacda authored by Romain Vimont's avatar Romain Vimont Committed by Romain Vimont

Move methods from BlockContext to FrameBlocks

Some BlockContext methods are specific to FrameBlocks, so move them.

With tiling, the lifetime of FrameBlocks will exceed that of
BlockContext (which will exist only during tile encoding).

This paves the way to move FrameBlocks out of BlockContext.
parent 38ae3a7d
......@@ -221,10 +221,10 @@ pub fn cdef_analyze_superblock<T: Pixel>(
// in the main frame.
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;
let skip = bc_global.blocks.at(global_block_offset).skip
& bc_global.blocks.at(sbo_global.block_offset(2*bx+1, 2*by)).skip
& bc_global.blocks.at(sbo_global.block_offset(2*bx, 2*by+1)).skip
& bc_global.blocks.at(sbo_global.block_offset(2*bx+1, 2*by+1)).skip;
if !skip {
let mut var: i32 = 0;
......@@ -358,10 +358,10 @@ pub fn cdef_filter_superblock<T: Pixel>(
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;
let skip = bc_global.blocks.at(global_block_offset).skip
& bc_global.blocks.at(sbo_global.block_offset(2*bx+1, 2*by)).skip
& bc_global.blocks.at(sbo_global.block_offset(2*bx, 2*by+1)).skip
& bc_global.blocks.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];
......@@ -480,7 +480,7 @@ pub fn cdef_filter_frame<T: Pixel>(fi: &FrameInvariants<T>, rec: &mut Frame<T>,
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_index = bc.blocks.at(sbo.block_offset(0, 0)).cdef_index;
let cdef_dirs = cdef_analyze_superblock(&cdef_frame, bc, sbo, sbo, fi.sequence.bit_depth);
cdef_filter_superblock(fi, &cdef_frame, rec, bc, sbo, sbo, cdef_index, &cdef_dirs);
}
......
This diff is collapsed.
......@@ -92,7 +92,7 @@ fn deblock_left<'a, T: Pixel>(
let bo = BlockOffset { x: in_bo.x | xdec, y: in_bo.y | ydec };
// We already know we're not at the upper/left corner, so prev_block is in frame
bc.at(bo.with_offset(-1 << xdec, 0))
bc.blocks.at(bo.with_offset(-1 << xdec, 0))
}
fn deblock_up<'a, T: Pixel>(
......@@ -106,7 +106,7 @@ fn deblock_up<'a, T: Pixel>(
let bo = BlockOffset { x: in_bo.x | xdec, y: in_bo.y | ydec };
// We already know we're not at the upper/left corner, so prev_block is in frame
bc.at(bo.with_offset(0, -1 << ydec))
bc.blocks.at(bo.with_offset(0, -1 << ydec))
}
// Must be called on a tx edge, and not on a frame edge. This is enforced above the call.
......@@ -1029,7 +1029,7 @@ fn filter_v_edge<T: Pixel>(
deblock: &DeblockState, bc: &BlockContext, bo: BlockOffset, p: &mut Plane<T>,
pli: usize, bd: usize, xdec: usize, ydec: usize
) {
let block = bc.at(bo);
let block = bc.blocks.at(bo);
let txsize = if pli==0 { block.txsize } else { block.bsize.largest_uv_tx_size(xdec, ydec) };
let tx_edge = bo.x >> xdec & (txsize.width_mi() - 1) == 0;
if tx_edge {
......@@ -1067,7 +1067,7 @@ fn sse_v_edge<T: Pixel>(
bc: &BlockContext, bo: BlockOffset, rec_plane: &Plane<T>, src_plane: &Plane<T>,
tally: &mut [i64; MAX_LOOP_FILTER + 2], pli: usize, bd: usize, xdec: usize, ydec: usize
) {
let block = bc.at(bo);
let block = bc.blocks.at(bo);
let txsize = if pli==0 { block.txsize } else { block.bsize.largest_uv_tx_size(xdec, ydec) };
let tx_edge = bo.x >> xdec & (txsize.width_mi() - 1) == 0;
if tx_edge {
......@@ -1134,7 +1134,7 @@ fn filter_h_edge<T: Pixel>(
deblock: &DeblockState, bc: &BlockContext, bo: BlockOffset, p: &mut Plane<T>,
pli: usize, bd: usize, xdec: usize, ydec: usize
) {
let block = bc.at(bo);
let block = bc.blocks.at(bo);
let txsize = if pli==0 { block.txsize } else { block.bsize.largest_uv_tx_size(xdec, ydec) };
let tx_edge = bo.y >> ydec & (txsize.height_mi() - 1) == 0;
if tx_edge {
......@@ -1172,7 +1172,7 @@ fn sse_h_edge<T: Pixel>(
bc: &BlockContext, bo: BlockOffset, rec_plane: &Plane<T>, src_plane: &Plane<T>,
tally: &mut [i64; MAX_LOOP_FILTER + 2], pli: usize, bd: usize, xdec: usize, ydec: usize
) {
let block = bc.at(bo);
let block = bc.blocks.at(bo);
let txsize = if pli==0 { block.txsize } else { block.bsize.largest_uv_tx_size(xdec, ydec) };
let tx_edge = bo.y >> ydec & (txsize.height_mi() - 1) == 0;
if tx_edge {
......
......@@ -950,7 +950,7 @@ fn diff<T: Pixel>(dst: &mut [i16], src1: &PlaneSlice<'_, T>, src2: &PlaneSlice<'
fn get_qidx<T: Pixel>(fi: &FrameInvariants<T>, fs: &FrameState<T>, cw: &ContextWriter, bo: BlockOffset) -> u8 {
let mut qidx = fi.base_q_idx;
let sidx = cw.bc.at(bo).segmentation_idx as usize;
let sidx = cw.bc.blocks.at(bo).segmentation_idx as usize;
if fs.segmentation.features[sidx][SegLvl::SEG_LVL_ALT_Q as usize] {
let delta = fs.segmentation.data[sidx][SegLvl::SEG_LVL_ALT_Q as usize];
qidx = clamp((qidx as i16) + delta, 0, 255) as u8;
......@@ -1072,11 +1072,11 @@ pub fn motion_compensate<T: Pixel>(
if p > 0 && bsize < BlockSize::BLOCK_8X8 {
let mut some_use_intra = false;
if bsize == BlockSize::BLOCK_4X4 || bsize == BlockSize::BLOCK_4X8 {
some_use_intra |= cw.bc.at(bo.with_offset(-1,0)).mode.is_intra(); };
some_use_intra |= cw.bc.blocks.at(bo.with_offset(-1,0)).mode.is_intra(); };
if !some_use_intra && bsize == BlockSize::BLOCK_4X4 || bsize == BlockSize::BLOCK_8X4 {
some_use_intra |= cw.bc.at(bo.with_offset(0,-1)).mode.is_intra(); };
some_use_intra |= cw.bc.blocks.at(bo.with_offset(0,-1)).mode.is_intra(); };
if !some_use_intra && bsize == BlockSize::BLOCK_4X4 {
some_use_intra |= cw.bc.at(bo.with_offset(-1,-1)).mode.is_intra(); };
some_use_intra |= cw.bc.blocks.at(bo.with_offset(-1,-1)).mode.is_intra(); };
if some_use_intra {
luma_mode.predict_inter(fi, p, po, &mut rec.mut_slice(po), plane_bsize.width(),
......@@ -1085,13 +1085,13 @@ pub fn motion_compensate<T: Pixel>(
assert!(xdec == 1 && ydec == 1);
// TODO: these are absolutely only valid for 4:2:0
if bsize == BlockSize::BLOCK_4X4 {
let mv0 = cw.bc.at(bo.with_offset(-1,-1)).mv;
let rf0 = cw.bc.at(bo.with_offset(-1,-1)).ref_frames;
let mv1 = cw.bc.at(bo.with_offset(0,-1)).mv;
let rf1 = cw.bc.at(bo.with_offset(0,-1)).ref_frames;
let mv0 = cw.bc.blocks.at(bo.with_offset(-1,-1)).mv;
let rf0 = cw.bc.blocks.at(bo.with_offset(-1,-1)).ref_frames;
let mv1 = cw.bc.blocks.at(bo.with_offset(0,-1)).mv;
let rf1 = cw.bc.blocks.at(bo.with_offset(0,-1)).ref_frames;
let po1 = PlaneOffset { x: po.x+2, y: po.y };
let mv2 = cw.bc.at(bo.with_offset(-1,0)).mv;
let rf2 = cw.bc.at(bo.with_offset(-1,0)).ref_frames;
let mv2 = cw.bc.blocks.at(bo.with_offset(-1,0)).mv;
let rf2 = cw.bc.blocks.at(bo.with_offset(-1,0)).ref_frames;
let po2 = PlaneOffset { x: po.x, y: po.y+2 };
let po3 = PlaneOffset { x: po.x+2, y: po.y+2 };
luma_mode.predict_inter(fi, p, po, &mut rec.mut_slice(po), 2, 2, rf0, mv0);
......@@ -1100,15 +1100,15 @@ pub fn motion_compensate<T: Pixel>(
luma_mode.predict_inter(fi, p, po3, &mut rec.mut_slice(po3), 2, 2, ref_frames, mvs);
}
if bsize == BlockSize::BLOCK_8X4 {
let mv1 = cw.bc.at(bo.with_offset(0,-1)).mv;
let rf1 = cw.bc.at(bo.with_offset(0,-1)).ref_frames;
let mv1 = cw.bc.blocks.at(bo.with_offset(0,-1)).mv;
let rf1 = cw.bc.blocks.at(bo.with_offset(0,-1)).ref_frames;
luma_mode.predict_inter(fi, p, po, &mut rec.mut_slice(po), 4, 2, rf1, mv1);
let po3 = PlaneOffset { x: po.x, y: po.y+2 };
luma_mode.predict_inter(fi, p, po3, &mut rec.mut_slice(po3), 4, 2, ref_frames, mvs);
}
if bsize == BlockSize::BLOCK_4X8 {
let mv2 = cw.bc.at(bo.with_offset(-1,0)).mv;
let rf2 = cw.bc.at(bo.with_offset(-1,0)).ref_frames;
let mv2 = cw.bc.blocks.at(bo.with_offset(-1,0)).mv;
let rf2 = cw.bc.blocks.at(bo.with_offset(-1,0)).ref_frames;
luma_mode.predict_inter(fi, p, po, &mut rec.mut_slice(po), 2, 4, rf2, mv2);
let po3 = PlaneOffset { x: po.x+2, y: po.y };
luma_mode.predict_inter(fi, p, po3, &mut rec.mut_slice(po3), 2, 4, ref_frames, mvs);
......@@ -1142,7 +1142,7 @@ pub fn encode_block_a<T: Pixel>(
cw: &mut ContextWriter, w: &mut dyn Writer,
bsize: BlockSize, bo: BlockOffset, skip: bool
) -> bool {
cw.bc.set_skip(bo, bsize, skip);
cw.bc.blocks.set_skip(bo, bsize, skip);
if fs.segmentation.enabled && fs.segmentation.update_map && fs.segmentation.preskip {
cw.write_segmentation(w, bo, bsize, false, fs.segmentation.last_active_segid);
}
......@@ -1177,11 +1177,11 @@ pub fn encode_block_b<T: Pixel>(
if skip {
cw.bc.reset_skip_context(bo, bsize, xdec, ydec);
}
cw.bc.set_block_size(bo, bsize);
cw.bc.set_mode(bo, bsize, luma_mode);
cw.bc.set_tx_size(bo, bsize, tx_size);
cw.bc.set_ref_frames(bo, bsize, ref_frames);
cw.bc.set_motion_vectors(bo, bsize, mvs);
cw.bc.blocks.set_block_size(bo, bsize);
cw.bc.blocks.set_mode(bo, bsize, luma_mode);
cw.bc.blocks.set_tx_size(bo, bsize, tx_size);
cw.bc.blocks.set_ref_frames(bo, bsize, ref_frames);
cw.bc.blocks.set_motion_vectors(bo, bsize, mvs);
//write_q_deltas();
if cw.bc.code_deltas && fs.deblock.block_deltas_enabled && (bsize < sb_size || !skip) {
......@@ -2176,7 +2176,7 @@ fn encode_tile<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>) -> Vec
if cw.bc.cdef_coded {
// CDEF index must be written in the middle, we can code it now
let cdef_index = cw.bc.get_cdef(sbo);
let cdef_index = cw.bc.blocks.get_cdef(sbo);
cw.write_cdef(&mut w, cdef_index, fi.cdef_bits);
// ...and then finally code what comes after the CDEF index
w_post_cdef.replay(&mut w);
......
......@@ -879,9 +879,9 @@ pub fn rdo_mode_decision<T: Pixel>(
}
}
cw.bc.set_mode(bo, bsize, best.mode_luma);
cw.bc.set_ref_frames(bo, bsize, best.ref_frames);
cw.bc.set_motion_vectors(bo, bsize, best.mvs);
cw.bc.blocks.set_mode(bo, bsize, best.mode_luma);
cw.bc.blocks.set_ref_frames(bo, bsize, best.ref_frames);
cw.bc.blocks.set_motion_vectors(bo, bsize, best.mvs);
assert!(best.rd >= 0_f64);
......@@ -1243,7 +1243,7 @@ fn rdo_loop_plane_error<T: Pixel>(sbo: SuperBlockOffset, fi: &FrameInvariants<T>
for bx in 0..sb_blocks {
let bo = sbo.block_offset(bx<<1, by<<1);
if bo.x < bc.cols && bo.y < bc.rows {
let skip = bc.at(bo).skip;
let skip = bc.blocks.at(bo).skip;
if !skip {
let in_plane = &fs.input.planes[pli];
let in_po = sbo.block_offset(bx<<1, by<<1).plane_offset(&in_plane.cfg);
......@@ -1436,7 +1436,7 @@ pub fn rdo_loop_decision<T: Pixel>(sbo: SuperBlockOffset, fi: &FrameInvariants<T
}
if cw.bc.cdef_coded {
cw.bc.set_cdef(sbo, best_index as u8);
cw.bc.blocks.set_cdef(sbo, best_index as u8);
}
if fi.sequence.enable_restoration {
......
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