Commit 32effc32 authored by Romain Vimont's avatar Romain Vimont Committed by Luca Barbato

Make SuperBlockOffset derive Copy

Like previous commit did for BlockOffset.
parent 42d96a36
......@@ -206,8 +206,8 @@ fn adjust_strength(strength: i32, var: i32) -> i32 {
pub fn cdef_analyze_superblock<T: Pixel>(
in_frame: &Frame<T>,
bc_global: &mut BlockContext,
sbo: &SuperBlockOffset,
sbo_global: &SuperBlockOffset,
sbo: SuperBlockOffset,
sbo_global: SuperBlockOffset,
bit_depth: usize,
) -> CdefDirections {
let coeff_shift = bit_depth as usize - 8;
......@@ -259,7 +259,7 @@ pub fn cdef_sb_frame<T: Pixel>(fi: &FrameInvariants<T>, f: &Frame<T>) -> Frame<T
}
pub fn cdef_sb_padded_frame_copy<T: Pixel>(
fi: &FrameInvariants<T>, sbo: &SuperBlockOffset,
fi: &FrameInvariants<T>, sbo: SuperBlockOffset,
f: &Frame<T>, pad: usize
) -> Frame<u16> {
let ipad = pad as isize;
......@@ -333,8 +333,8 @@ pub fn cdef_filter_superblock<T: Pixel>(
in_frame: &Frame<u16>,
out_frame: &mut Frame<T>,
bc_global: &mut BlockContext,
sbo: &SuperBlockOffset,
sbo_global: &SuperBlockOffset,
sbo: SuperBlockOffset,
sbo_global: SuperBlockOffset,
cdef_index: u8,
cdef_dirs: &CdefDirections,
) {
......@@ -481,8 +481,8 @@ pub fn cdef_filter_frame<T: Pixel>(fi: &FrameInvariants<T>, rec: &mut Frame<T>,
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_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);
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);
}
}
}
......
......@@ -1126,7 +1126,7 @@ pub const LOCAL_BLOCK_MASK: usize = (1 << SUPERBLOCK_TO_BLOCK_SHIFT) - 1;
/// Absolute offset in superblocks inside a plane, where a superblock is defined
/// to be an N*N square where N = (1 << SUPERBLOCK_TO_PLANE_SHIFT).
#[derive(Clone)]
#[derive(Clone, Copy, Debug)]
pub struct SuperBlockOffset {
pub x: usize,
pub y: usize
......@@ -1134,7 +1134,7 @@ pub struct SuperBlockOffset {
impl SuperBlockOffset {
/// Offset of a block inside the current superblock.
pub fn block_offset(&self, block_x: usize, block_y: usize) -> BlockOffset {
pub fn block_offset(self, block_x: usize, block_y: usize) -> BlockOffset {
BlockOffset {
x: (self.x << SUPERBLOCK_TO_BLOCK_SHIFT) + block_x,
y: (self.y << SUPERBLOCK_TO_BLOCK_SHIFT) + block_y
......@@ -1142,7 +1142,7 @@ impl SuperBlockOffset {
}
/// Offset of the top-left pixel of this block.
pub fn plane_offset(&self, plane: &PlaneConfig) -> PlaneOffset {
pub fn plane_offset(self, plane: &PlaneConfig) -> PlaneOffset {
PlaneOffset {
x: (self.x as isize) << (SUPERBLOCK_TO_PLANE_SHIFT - plane.xdec),
y: (self.y as isize) << (SUPERBLOCK_TO_PLANE_SHIFT - plane.ydec)
......@@ -1545,7 +1545,7 @@ impl BlockContext {
}
}
pub fn set_cdef(&mut self, sbo: &SuperBlockOffset, cdef_index: u8) {
pub fn set_cdef(&mut self, sbo: SuperBlockOffset, cdef_index: u8) {
let bo = sbo.block_offset(0, 0);
// Checkme: Is 16 still the right block unit for 128x128 superblocks?
let bw = cmp::min (bo.x + MAX_MIB_SIZE, self.blocks[bo.y as usize].len());
......@@ -1557,7 +1557,7 @@ impl BlockContext {
}
}
pub fn get_cdef(&mut self, sbo: &SuperBlockOffset) -> u8 {
pub fn get_cdef(&mut self, sbo: SuperBlockOffset) -> u8 {
let bo = sbo.block_offset(0, 0);
self.blocks[bo.y][bo.x].cdef_index
}
......@@ -3041,7 +3041,7 @@ impl ContextWriter {
}
pub fn write_lrf<T: Pixel>(
&mut self, w: &mut dyn Writer, fi: &FrameInvariants<T>, rs: &mut RestorationState, sbo: &SuperBlockOffset
&mut self, w: &mut dyn Writer, fi: &FrameInvariants<T>, rs: &mut RestorationState, sbo: SuperBlockOffset
) {
if !fi.allow_intrabc { // TODO: also disallow if lossless
for pli in 0..PLANES {
......
......@@ -2124,11 +2124,11 @@ fn encode_tile<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>) -> Vec
// CDEF has to be decided before loop restoration, but coded after.
// loop restoration must be decided last but coded before anything else.
if cw.bc.cdef_coded || fi.sequence.enable_restoration {
rdo_loop_decision(&sbo, fi, fs, &mut cw, &mut w);
rdo_loop_decision(sbo, fi, fs, &mut cw, &mut w);
}
if fi.sequence.enable_restoration {
cw.write_lrf(&mut w, fi, &mut fs.restoration, &sbo);
cw.write_lrf(&mut w, fi, &mut fs.restoration, sbo);
}
// Once loop restoration is coded, we can replay the initial block bits
......@@ -2136,7 +2136,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.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);
......
......@@ -830,7 +830,7 @@ impl RestorationPlane {
}
}
fn restoration_unit_index(&self, sbo: &SuperBlockOffset) -> (usize, usize) {
fn restoration_unit_index(&self, sbo: SuperBlockOffset) -> (usize, usize) {
(
(sbo.x >> self.sb_shift).min(self.cols - 1),
(sbo.y >> self.sb_shift).min(self.rows - 1),
......@@ -847,12 +847,12 @@ impl RestorationPlane {
)
}
pub fn restoration_unit(&self, sbo: &SuperBlockOffset) -> &RestorationUnit {
pub fn restoration_unit(&self, sbo: SuperBlockOffset) -> &RestorationUnit {
let (x, y) = self.restoration_unit_index(sbo);
&self.units[y * self.cols + x]
}
pub fn restoration_unit_as_mut(&mut self, sbo: &SuperBlockOffset) -> &mut RestorationUnit {
pub fn restoration_unit_as_mut(&mut self, sbo: SuperBlockOffset) -> &mut RestorationUnit {
let (x, y) = self.restoration_unit_index(sbo);
&mut self.units[y * self.cols + x]
}
......@@ -902,11 +902,11 @@ impl RestorationState {
}
}
pub fn restoration_unit(&self, sbo: &SuperBlockOffset, pli: usize) -> &RestorationUnit {
pub fn restoration_unit(&self, sbo: SuperBlockOffset, pli: usize) -> &RestorationUnit {
self.planes[pli].restoration_unit(sbo)
}
pub fn restoration_unit_as_mut(&mut self, sbo: &SuperBlockOffset, pli: usize) -> &mut RestorationUnit {
pub fn restoration_unit_as_mut(&mut self, sbo: SuperBlockOffset, pli: usize) -> &mut RestorationUnit {
self.planes[pli].restoration_unit_as_mut(sbo)
}
......
......@@ -1221,7 +1221,7 @@ pub fn rdo_partition_decision<T: Pixel>(
}
}
fn rdo_loop_plane_error<T: Pixel>(sbo: &SuperBlockOffset, fi: &FrameInvariants<T>,
fn rdo_loop_plane_error<T: Pixel>(sbo: SuperBlockOffset, fi: &FrameInvariants<T>,
fs: &FrameState<T>, bc: &BlockContext,
test: &Frame<T>, pli: usize) -> u64 {
let sbo_0 = SuperBlockOffset { x: 0, y: 0 };
......@@ -1258,7 +1258,7 @@ fn rdo_loop_plane_error<T: Pixel>(sbo: &SuperBlockOffset, fi: &FrameInvariants<T
err
}
pub fn rdo_loop_decision<T: Pixel>(sbo: &SuperBlockOffset, fi: &FrameInvariants<T>,
pub fn rdo_loop_decision<T: Pixel>(sbo: SuperBlockOffset, fi: &FrameInvariants<T>,
fs: &mut FrameState<T>,
cw: &mut ContextWriter, w: &mut dyn Writer) {
assert!(fi.sequence.enable_cdef || fi.sequence.enable_restoration);
......@@ -1308,7 +1308,7 @@ pub fn rdo_loop_decision<T: Pixel>(sbo: &SuperBlockOffset, fi: &FrameInvariants<
// If LRF choice changed for any plane, repeat last two steps.
let bd = fi.sequence.bit_depth;
let cdef_data = cdef_input.as_ref().map(|input| {
(input, cdef_analyze_superblock(input, &mut cw.bc, &sbo_0, &sbo, bd))
(input, cdef_analyze_superblock(input, &mut cw.bc, sbo_0, sbo, bd))
});
let mut first_loop = true;
loop {
......@@ -1321,7 +1321,7 @@ pub fn rdo_loop_decision<T: Pixel>(sbo: &SuperBlockOffset, fi: &FrameInvariants<
let mut cost = [0.; PLANES];
let mut cost_acc = 0.;
cdef_filter_superblock(fi, &cdef_input, &mut lrf_input,
&mut cw.bc, &sbo_0, &sbo, cdef_index as u8, &cdef_dirs);
&mut cw.bc, sbo_0, sbo, cdef_index as u8, &cdef_dirs);
for pli in 0..3 {
match best_lrf[pli] {
RestorationFilter::None{} => {
......@@ -1370,7 +1370,7 @@ pub fn rdo_loop_decision<T: Pixel>(sbo: &SuperBlockOffset, fi: &FrameInvariants<
// need cdef output from best index, not just last iteration
if let Some((cdef_input, cdef_dirs)) = cdef_data.as_ref() {
cdef_filter_superblock(fi, &cdef_input, &mut lrf_input,
&mut cw.bc, &sbo_0, &sbo, best_index as u8, &cdef_dirs);
&mut cw.bc, sbo_0, sbo, best_index as u8, &cdef_dirs);
}
// Wiener LRF decision coming soon
......@@ -1426,7 +1426,7 @@ pub fn rdo_loop_decision<T: Pixel>(sbo: &SuperBlockOffset, fi: &FrameInvariants<
}
if cw.bc.cdef_coded {
cw.bc.set_cdef(&sbo, best_index as u8);
cw.bc.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