Commit 14de53db authored by Frank Bossen's avatar Frank Bossen Committed by Yushin Cho

Add rate of partition symbol to RD cost

parent 60d375ca
......@@ -1615,9 +1615,13 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
if !must_split {
partition = PartitionType::PARTITION_NONE;
let mut cost: f64 = 0.0;
if bsize >= BlockSize::BLOCK_8X8 {
let w: &mut dyn Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
let tell = w.tell_frac();
cw.write_partition(w, bo, partition, bsize);
cost = (w.tell_frac() - tell) as f64 * get_lambda(fi, seq.bit_depth)/ ((1 << OD_BITRES) as f64);
}
let mode_decision = rdo_mode_decision(seq, fi, fs, cw, bsize, bo).part_modes[0].clone();
let (mode_luma, mode_chroma) = (mode_decision.pred_mode_luma, mode_decision.pred_mode_chroma);
......@@ -1626,7 +1630,7 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
let mv = mode_decision.mv;
let skip = mode_decision.skip;
let mut cdef_coded = cw.bc.cdef_coded;
rd_cost = mode_decision.rd_cost;
rd_cost = mode_decision.rd_cost + cost;
let (tx_size, tx_type) =
rdo_tx_size_type(seq, fi, fs, cw, bsize, bo, mode_luma, ref_frame, mv, skip);
......@@ -1651,13 +1655,17 @@ fn encode_partition_bottomup(seq: &Sequence, fi: &FrameInvariants, fs: &mut Fram
let nosplit_rd_cost = rd_cost;
rd_cost = 0.0;
if bsize >= BlockSize::BLOCK_8X8 {
let w: &mut dyn Writer = if cw.bc.cdef_coded {w_post_cdef} else {w_pre_cdef};
let tell = w.tell_frac();
cw.write_partition(w, bo, partition, bsize);
rd_cost = (w.tell_frac() - tell) as f64 * get_lambda(fi, seq.bit_depth)/ ((1 << OD_BITRES) as f64);
}
rd_cost = encode_partition_bottomup(seq, fi, fs, cw, w_pre_cdef, w_post_cdef, subsize,
bo);
rd_cost += encode_partition_bottomup(seq, fi, fs, cw, w_pre_cdef, w_post_cdef, subsize,
bo);
rd_cost += encode_partition_bottomup(seq, fi, fs, cw, w_pre_cdef, w_post_cdef, subsize,
&BlockOffset { x: bo.x + hbs as usize, y: bo.y });
rd_cost += encode_partition_bottomup(seq, fi, fs, cw, w_pre_cdef, w_post_cdef, subsize,
......
......@@ -126,11 +126,7 @@ fn sse_wxh(src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize) ->
sse
}
// Compute the rate-distortion cost for an encode
fn compute_rd_cost(
fi: &FrameInvariants, fs: &FrameState, w_y: usize, h_y: usize,
is_chroma_block: bool, bo: &BlockOffset, bit_cost: u32, bit_depth: usize, luma_only: bool
) -> f64 {
pub fn get_lambda(fi: &FrameInvariants, bit_depth: usize) -> f64 {
let q = dc_q(fi.config.quantizer, bit_depth) as f64;
// Convert q into Q0 precision, given that libaom quantizers are Q3
......@@ -138,7 +134,15 @@ fn compute_rd_cost(
// Lambda formula from doc/theoretical_results.lyx in the daala repo
// Use Q0 quantizer since lambda will be applied to Q0 pixel domain
let lambda = q0 * q0 * std::f64::consts::LN_2 / 6.0;
q0 * q0 * std::f64::consts::LN_2 / 6.0
}
// Compute the rate-distortion cost for an encode
fn compute_rd_cost(
fi: &FrameInvariants, fs: &FrameState, w_y: usize, h_y: usize,
is_chroma_block: bool, bo: &BlockOffset, bit_cost: u32, bit_depth: usize, luma_only: bool
) -> f64 {
let lambda = get_lambda(fi, bit_depth);
// Compute distortion
let po = bo.plane_offset(&fs.input.planes[0].cfg);
......
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