forge
Explore
Log in

Don't you dare go Hollow

The 32x32 inter search's intra candidate gets a palette arm

Browse files at this commit

d247d4292d3c15b4e632a87361b32e4b7e141b44Ahmet Kaan GümüşParent: 93f25fe
  • feat
    • the 32x32 inter search's intra candidate gets a palette arm
Show full message
feat(av1): the 32x32 inter search's intra candidate gets a palette arm

The corner-cut code_square closed for an inter frame's 16/8 intra leaves
but the hand-rolled 32x32 loop did not. tile.rs already writes
palette_mode_info from block.palette at that side, so only the candidate
was missing.
crates/ec-av1/src/encode.rsmodified+62 -1
@@ -4484,6 +4484,9 @@ fn search_inter_block(
4484 mode: u8,4484 mode: u8,
4485 skip: bool,4485 skip: bool,
4486 inter: Option<InterInfo>,4486 inter: Option<InterInfo>,
4487+ /// The luma palette this candidate is predicted from, `None` for
4488+ /// every ordinary intra/inter candidate (the palette arm below).
4489+ palette: Option<crate::tile::PaletteY>,
4487 }4490 }
4488 let mut best: Option<Candidate> = None;4491 let mut best: Option<Candidate> = None;
4489 let mut consider = |candidate: Candidate| {4492 let mut consider = |candidate: Candidate| {
@@ -4578,9 +4581,65 @@ fn search_inter_block(
4578 mode,4581 mode,
4579 skip: false,4582 skip: false,
4580 inter: None,4583 inter: None,
4584+ palette: None,
4581 });4585 });
4582 }4586 }
4583 4587
4588+ // The palette arm of this search -- the corner-cut `code_square` closed
4589+ // for an inter frame's 16/8 intra leaves but this hand-rolled 32x32 loop
4590+ // did not. A 32x32 intra block inside an inter frame codes the same
4591+ // `palette_mode_info` syntax a key frame's does (tile.rs writes it from
4592+ // `block.palette` at every one of the three sides already), so the only
4593+ // thing missing was a candidate. Priced against the same `DC_PRED`
4594+ // chroma trials the ordinary intra candidates reuse, and a palette block
4595+ // is `DC_PRED` with `tx_depth` 0 by construction (its prediction is the
4596+ // colour map, not the DC of its neighbours).
4597+ if search.screen && crate::decode::palette_bsize_ctx(BLOCK).is_some() {
4598+ let source: Vec<u8> = (y..y + BLOCK)
4599+ .flat_map(|row| luma.source[row * luma.width + x..][..BLOCK].to_vec())
4600+ .collect();
4601+ for pal in palette_candidates(&source) {
4602+ let n = usize::from(pal.size);
4603+ let prediction: Vec<u8> = pal
4604+ .map
4605+ .iter()
4606+ .map(|&i| pal.colors[usize::from(i).min(n - 1)] as u8)
4607+ .collect();
4608+ let luma_trial = luma.code_from_prediction(
4609+ x,
4610+ y,
4611+ BLOCK,
4612+ &prediction,
4613+ false,
4614+ search.base_q_idx,
4615+ search.deadzone,
4616+ luma_set,
4617+ );
4618+ let (u, v) = (u_trial.clone(), v_trial.clone());
4619+ let cost = luma_trial.sse
4620+ + u.sse
4621+ + v.sse
4622+ + search.lambda
4623+ * (luma_trial.bits
4624+ + u.bits
4625+ + v.bits
4626+ + mode_bits[DC_PRED as usize]
4627+ + crate::tile::palette_bits(&pal, BLOCK)
4628+ + skip_bits(false)
4629+ + intra_inter_bits(false));
4630+ consider(Candidate {
4631+ cost,
4632+ luma: luma_trial,
4633+ u,
4634+ v,
4635+ mode: DC_PRED,
4636+ skip: false,
4637+ inter: None,
4638+ palette: Some(pal),
4639+ });
4640+ }
4641+ }
4642+
4584 // The reference frame buffer a spec decoder holds is exactly the true4643 // The reference frame buffer a spec decoder holds is exactly the true
4585 // (unpadded) coded extent -- a superblock whose partition stops early at4644 // (unpadded) coded extent -- a superblock whose partition stops early at
4586 // `has_cols`/`has_rows` never codes syntax for the padding columns/rows4645 // `has_cols`/`has_rows` never codes syntax for the padding columns/rows
@@ -4929,6 +4988,7 @@ fn search_inter_block(
4929 mode: DC_PRED,4988 mode: DC_PRED,
4930 skip,4989 skip,
4931 inter: Some(info),4990 inter: Some(info),
4991+ palette: None,
4932 });4992 });
4933 }4993 }
4934 }4994 }
@@ -5026,6 +5086,7 @@ fn search_inter_block(
5026 mode: DC_PRED,5086 mode: DC_PRED,
5027 skip,5087 skip,
5028 inter: Some(info),5088 inter: Some(info),
5089+ palette: None,
5029 });5090 });
5030 }5091 }
5031 }5092 }
@@ -5044,7 +5105,7 @@ fn search_inter_block(
5044 skip: best.skip,5105 skip: best.skip,
5045 inter: best.inter,5106 inter: best.inter,
5046 eight: None,5107 eight: None,
5047- palette: None,5108+ palette: best.palette,
5048 tx_depth: 0,5109 tx_depth: 0,
5049 },5110 },
5050 best.cost,5111 best.cost,