Intra tx_depth ctx in an inter frame reads the TXFM_CONTEXT arrays, not the deblock tx grid
Browse files at this commit4fc3a96c5506934f531c6e72411696f05ac73e4aParent: 88c3a38- fix
- intra tx_depth ctx in an inter frame reads the TXFM_CONTEXT arrays, not the deblock tx grid
1 changed file +42 -4
- crates/ec-av1/src/decode.rs +42 -4
crates/ec-av1/src/decode.rsmodified+42 -4
| @@ -4931,7 +4931,7 @@ fn decode_block( | |||
| 4931 | // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side, | 4931 | // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side, |
| 4932 | // which only differs from it at that one corner case. | 4932 | // which only differs from it at that one corner case. |
| 4933 | let (logical_tx, coeff_tx_side) = if tx_select { | 4933 | let (logical_tx, coeff_tx_side) = if tx_select { |
| 4934 | - let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side); | 4934 | + let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None); |
| 4935 | (resolved, if resolved == 64 { 32 } else { resolved }) | 4935 | (resolved, if resolved == 64 { 32 } else { resolved }) |
| 4936 | } else { | 4936 | } else { |
| 4937 | (side, luma_tx) | 4937 | (side, luma_tx) |
| @@ -5343,7 +5343,7 @@ fn decode_leaf8( | |||
| 5343 | // transform units, same raster-order per-TU pattern `decode_block`'s | 5343 | // transform units, same raster-order per-TU pattern `decode_block`'s |
| 5344 | // multi-TU branch runs). | 5344 | // multi-TU branch runs). |
| 5345 | let resolved = if tx_select { | 5345 | let resolved = if tx_select { |
| 5346 | - read_tx_size(dec, cdfs, neighbours, leaf_mi, 8) | 5346 | + read_tx_size(dec, cdfs, neighbours, leaf_mi, 8, None) |
| 5347 | } else { | 5347 | } else { |
| 5348 | 8 | 5348 | 8 |
| 5349 | }; | 5349 | }; |
| @@ -5863,6 +5863,33 @@ fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize | |||
| 5863 | usize::from(above) + usize::from(left) | 5863 | usize::from(above) + usize::from(left) |
| 5864 | } | 5864 | } |
| 5865 | 5865 | ||
| 5866 | +/// `get_tx_size_context` as libaom actually writes it (`pred_common.h:342`), | ||
| 5867 | +/// for a block inside an INTER frame: the two `TXFM_CONTEXT` arrays | ||
| 5868 | +/// ([`Neighbours::above_txfm`]/[`Neighbours::left_txfm`], which only the | ||
| 5869 | +/// inter path maintains), except that an *inter* neighbour contributes its | ||
| 5870 | +/// own BLOCK size rather than its transform size -- the two differ the moment | ||
| 5871 | +/// a neighbour's var-tx tree splits. [`tx_size_context`]'s deblock-grid | ||
| 5872 | +/// approximation coincides with this only while every neighbour codes one | ||
| 5873 | +/// whole-block transform, which is exactly what `TxMode::Select` ends. | ||
| 5874 | +fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usize) -> usize { | ||
| 5875 | + let has_above = mi_r > n.tile_row0_mi; | ||
| 5876 | + let has_left = mi_c > n.tile_col0_mi; | ||
| 5877 | + let mut above = usize::from(n.above_txfm[mi_c]) >= side; | ||
| 5878 | + let mut left = usize::from(n.left_txfm[mi_r]) >= side; | ||
| 5879 | + if has_above && n.above_inter[mi_c / (SUB / MI)] { | ||
| 5880 | + above = n.above_side_mi[mi_c] >= side; | ||
| 5881 | + } | ||
| 5882 | + if has_left && n.left_inter[mi_r / (SUB / MI)] { | ||
| 5883 | + left = n.left_side_mi[mi_r] >= side; | ||
| 5884 | + } | ||
| 5885 | + match (has_above, has_left) { | ||
| 5886 | + (true, true) => usize::from(above) + usize::from(left), | ||
| 5887 | + (true, false) => usize::from(above), | ||
| 5888 | + (false, true) => usize::from(left), | ||
| 5889 | + (false, false) => 0, | ||
| 5890 | + } | ||
| 5891 | +} | ||
| 5892 | + | ||
| 5866 | /// `read_tx_size`/`read_selected_tx_size` (spec 5.11.16): under | 5893 | /// `read_tx_size`/`read_selected_tx_size` (spec 5.11.16): under |
| 5867 | /// `TxMode::Select`, an intra block's `tx_depth` symbol, resolved straight to | 5894 | /// `TxMode::Select`, an intra block's `tx_depth` symbol, resolved straight to |
| 5868 | /// the transform's own side in pixels (`side >> depth`) -- this decoder's | 5895 | /// the transform's own side in pixels (`side >> depth`) -- this decoder's |
| @@ -5874,8 +5901,12 @@ fn read_tx_size( | |||
| 5874 | n: &Neighbours, | 5901 | n: &Neighbours, |
| 5875 | at_mi: (usize, usize), | 5902 | at_mi: (usize, usize), |
| 5876 | side: usize, | 5903 | side: usize, |
| 5904 | + // lane-txselect: `get_tx_size_context`'s real context, for the callers | ||
| 5905 | + // that have one -- see [`tx_size_context_txfm`]. `None` keeps the | ||
| 5906 | + // key-frame path's own deblock-grid approximation. | ||
| 5907 | + ctx_override: Option<usize>, | ||
| 5877 | ) -> usize { | 5908 | ) -> usize { |
| 5878 | - let ctx = tx_size_context(n, at_mi, side); | 5909 | + let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, side)); |
| 5879 | let depth = match side { | 5910 | let depth = match side { |
| 5880 | 8 => dec.symbol(&mut cdfs.tx_size_cat0[ctx]), | 5911 | 8 => dec.symbol(&mut cdfs.tx_size_cat0[ctx]), |
| 5881 | 16 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), | 5912 | 16 => dec.symbol(&mut cdfs.tx_size_cat1[ctx]), |
| @@ -6112,7 +6143,14 @@ fn read_block_tx_size( | |||
| 6112 | let tx = if is_inter { | 6143 | let tx = if is_inter { |
| 6113 | side.min(64) | 6144 | side.min(64) |
| 6114 | } else { | 6145 | } else { |
| 6115 | - let resolved = read_tx_size(dec, cdfs, n, at_mi, side); | 6146 | + let resolved = read_tx_size( |
| 6147 | + dec, | ||
| 6148 | + cdfs, | ||
| 6149 | + n, | ||
| 6150 | + at_mi, | ||
| 6151 | + side, | ||
| 6152 | + Some(tx_size_context_txfm(n, at_mi, side)), | ||
| 6153 | + ); | ||
| 6116 | if resolved != side { | 6154 | if resolved != side { |
| 6117 | // An intra block inside an inter frame whose `tx_depth` splits its | 6155 | // An intra block inside an inter frame whose `tx_depth` splits its |
| 6118 | // luma transform needs the per-transform-unit intra prediction | 6156 | // luma transform needs the per-transform-unit intra prediction |