Commit 72e1fac3 authored by Monty's avatar Monty Committed by Monty Montgomery

Add RestorationContext infrastructure for loop restoration filter

parent 945cb6a2
......@@ -51,7 +51,9 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
let fc = CDFContext::new(fi.base_q_idx);
let bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fs = FrameState::new(&fi);
let mut cw = ContextWriter::new(fc, bc);
// For now, restoration unit size is locked to superblock size.
let rc = RestorationContext::new(fi.sb_width, fi.sb_height);
let mut cw = ContextWriter::new(fc, bc, rc);
let tx_type = TxType::DCT_DCT;
......
......@@ -22,6 +22,8 @@ use partition::PredictionMode::*;
use partition::TxSize::*;
use partition::TxType::*;
use partition::*;
use lrf::WIENER_TAPS_MID;
use lrf::SGR_XQD_MID;
use plane::*;
use util::clamp;
use util::msb;
......@@ -1630,6 +1632,53 @@ impl BlockContext {
}
}
#[derive(Copy, Clone)]
pub enum RestorationFilter {
None,
Wiener { coeffs: [[i8; 2]; 3] },
Sgr { xqd: [i8; 2] },
}
impl RestorationFilter {
pub fn default() -> RestorationFilter {
RestorationFilter::None
}
}
#[derive(Copy, Clone)]
pub struct RestorationUnit {
pub params: RestorationFilter,
}
impl RestorationUnit {
pub fn default() -> RestorationUnit {
RestorationUnit {
params: RestorationFilter::default()
}
}
}
#[derive(Clone, Default)]
pub struct RestorationContext {
pub cols: usize,
pub rows: usize,
pub wiener_ref: [[[i8; 3]; 2]; PLANES],
pub sgr_ref: [[i8; 2]; PLANES],
pub units: Vec<Vec<Vec<RestorationUnit>>>
}
impl RestorationContext {
pub fn new(cols: usize, rows: usize) -> RestorationContext {
RestorationContext {
cols,
rows,
wiener_ref: [[WIENER_TAPS_MID; 2]; PLANES],
sgr_ref: [SGR_XQD_MID; PLANES],
units: vec![vec![vec![RestorationUnit::default(); cols]; rows]; PLANES]
}
}
}
#[derive(Copy, Clone, PartialEq)]
pub enum CFLSign {
CFL_SIGN_ZERO = 0,
......@@ -1725,16 +1774,18 @@ pub struct ContextWriterCheckpoint {
pub struct ContextWriter {
pub bc: BlockContext,
pub fc: CDFContext,
pub rc: RestorationContext,
#[cfg(debug)]
fc_map: Option<FieldMap> // For debugging purposes
}
impl ContextWriter {
pub fn new(fc: CDFContext, bc: BlockContext) -> Self {
pub fn new(fc: CDFContext, bc: BlockContext, rc: RestorationContext) -> Self {
#[allow(unused_mut)]
let mut cw = ContextWriter {
fc,
bc,
rc,
#[cfg(debug)]
fc_map: Default::default()
};
......
......@@ -2105,7 +2105,9 @@ fn encode_tile(sequence: &mut Sequence, fi: &FrameInvariants, fs: &mut FrameStat
};
let bc = BlockContext::new(fi.w_in_b, fi.h_in_b);
let mut cw = ContextWriter::new(fc, bc);
// For now, restoration unit size is locked to superblock size.
let rc = RestorationContext::new(fi.sb_width, fi.sb_height);
let mut cw = ContextWriter::new(fc, bc, rc);
for sby in 0..fi.sb_height {
cw.bc.reset_left_contexts();
......@@ -2138,7 +2140,7 @@ fn encode_tile(sequence: &mut Sequence, fi: &FrameInvariants, fs: &mut FrameStat
cw.bc.set_cdef(&sbo, cdef_index);
}
// loop restoration must be decided last... but coded first.
// loop restoration must be decided last but coded before anything else
if sequence.enable_restoration {
}
......
......@@ -14,3 +14,11 @@ pub const RESTORE_SWITCHABLE: u8 = 1;
pub const RESTORE_WIENER: u8 = 2;
pub const RESTORE_SGRPROJ: u8 = 3;
pub const WIENER_TAPS_MIN: [i8; 3] = [ -5, -23, -17 ];
pub const WIENER_TAPS_MID: [i8; 3] = [ 3, -7, 15 ];
pub const WIENER_TAPS_MAX: [i8; 3] = [ 10, 8, 46 ];
pub const SGR_XQD_MIN: [i8; 2] = [ -96, -32 ];
pub const SGR_XQD_MID: [i8; 2] = [ -32, 31 ];
pub const SGR_XQD_MAX: [i8; 2] = [ 31, 95 ];
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