WIP lane-av1tx: orchestrator snapshot at the agent turn cap (unverified)
Browse files at this commitb56ffce72627c78d759aec513fc3101bdc91baeeParent: 13f50832 changed files +265 -38
- crates/ec-av1/src/decode.rs +2 -2
- crates/ec-av1/src/tile.rs +263 -36
crates/ec-av1/src/decode.rsmodified+2 -2
| @@ -16764,7 +16764,7 @@ fn txfm_partition_ctx(above_px: u8, left_px: u8, blk_max_px: usize, tx_px: usize | ||
| 16764 | 16764 | /// category from `txsize_sqr_up_map[tx_size]` -- all three collapse to one |
| 16765 | 16765 | /// side for a square transform, which is why the square form above is a |
| 16766 | 16766 | /// special case of this one. |
| 16767 | -fn txfm_partition_ctx_rect( | |
| 16767 | +pub(crate) fn txfm_partition_ctx_rect( | |
| 16768 | 16768 | above_px: u8, |
| 16769 | 16769 | left_px: u8, |
| 16770 | 16770 | blk_max_px: usize, |
| @@ -16894,7 +16894,7 @@ fn set_txfm_ctxs( | ||
| 16894 | 16894 | /// with `tx_size_high[TX_SIZES_LARGEST]` (`av1_common_int.h`), i.e. 64 |
| 16895 | 16895 | /// pixels, so an unwritten neighbour reads as the *widest* possible |
| 16896 | 16896 | /// transform, not the narrowest. |
| 16897 | -const TXFM_CTX_INIT: u8 = 64; | |
| 16897 | +pub(crate) const TXFM_CTX_INIT: u8 = 64; | |
| 16898 | 16898 | |
| 16899 | 16899 | /// libaom's `MAX_VARTX_DEPTH`: an inter block's transform tree halves at most |
| 16900 | 16900 | /// twice below its own largest transform. |
crates/ec-av1/src/tile.rsmodified+263 -36
| @@ -15,6 +15,7 @@ use ec_core::{Error, Result}; | ||
| 15 | 15 | |
| 16 | 16 | use crate::cdf; |
| 17 | 17 | use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables}; |
| 18 | +use crate::decode::{TXFM_CTX_INIT, txfm_partition_ctx_rect}; | |
| 18 | 19 | use crate::msac::SymbolEncoder; |
| 19 | 20 | use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, mv16, single_ref_ctx}; |
| 20 | 21 | |
| @@ -661,6 +662,14 @@ struct Neighbours { | ||
| 661 | 662 | /// The same, down the left edge (the transform's HEIGHT, `tx_h_px_at`; |
| 662 | 663 | /// every transform this writer codes is square, so one value serves). |
| 663 | 664 | left_tx: Vec<u8>, |
| 665 | + /// libaom's `above_txfm_context`/`left_txfm_context` (`TXFM_CONTEXT`), per | |
| 666 | + /// 4x4 mode-info unit: what an INTER frame's `txfm_split` and `tx_depth` | |
| 667 | + /// symbols read their context from (decode.rs `txfm_partition_ctx_rect`/ | |
| 668 | + /// `tx_size_context_txfm_rect`). Initialised to the widest transform, not | |
| 669 | + /// zero (decode.rs `TXFM_CTX_INIT`). | |
| 670 | + above_txfm: Vec<u8>, | |
| 671 | + /// The same, down the left edge (transform HEIGHT). | |
| 672 | + left_txfm: Vec<u8>, | |
| 664 | 673 | /// Whether the neighbour was coded inter, for the `is_inter` context. |
| 665 | 674 | /// Unused by the key frame writers. |
| 666 | 675 | above_inter: Vec<bool>, |
| @@ -711,6 +720,8 @@ impl Neighbours { | ||
| 711 | 720 | left_inter: vec![false; rows * (SUB / MI)], |
| 712 | 721 | above_tx: vec![0; cols * (SUB / MI)], |
| 713 | 722 | left_tx: vec![0; rows * (SUB / MI)], |
| 723 | + above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)], | |
| 724 | + left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)], | |
| 714 | 725 | mi_cols, |
| 715 | 726 | mi_rows, |
| 716 | 727 | } |
| @@ -725,6 +736,39 @@ impl Neighbours { | ||
| 725 | 736 | self.left_skip.iter_mut().for_each(|s| *s = false); |
| 726 | 737 | self.left_inter.iter_mut().for_each(|i| *i = false); |
| 727 | 738 | self.left_tx.iter_mut().for_each(|t| *t = 0); |
| 739 | + self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT); | |
| 740 | + } | |
| 741 | + | |
| 742 | + /// `txfm_partition_update`/`set_txfm_ctxs` (decode.rs): what every block | |
| 743 | + /// of an INTER frame leaves in the two `TXFM_CONTEXT` bands -- its | |
| 744 | + /// resolved transform size over the span `(w_px, h_px)`, which for a | |
| 745 | + /// SKIPPED inter block is its own block size instead. | |
| 746 | + fn record_txfm(&mut self, (mi_r, mi_c): (usize, usize), tx_px: usize, w_px: usize, h_px: usize) { | |
| 747 | + for i in 0..h_px / MI { | |
| 748 | + if let Some(cell) = self.left_txfm.get_mut(mi_r + i) { | |
| 749 | + *cell = tx_px as u8; | |
| 750 | + } | |
| 751 | + } | |
| 752 | + for i in 0..w_px / MI { | |
| 753 | + if let Some(cell) = self.above_txfm.get_mut(mi_c + i) { | |
| 754 | + *cell = tx_px as u8; | |
| 755 | + } | |
| 756 | + } | |
| 757 | + } | |
| 758 | + | |
| 759 | + /// `get_tx_size_context` as libaom writes it for a block inside an INTER | |
| 760 | + /// frame (decode.rs `tx_size_context_txfm_rect`): the `TXFM_CONTEXT` | |
| 761 | + /// bands, except that an *inter* neighbour contributes its own BLOCK size. | |
| 762 | + fn tx_size_ctx_txfm(&self, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize { | |
| 763 | + let mut above = usize::from(self.above_txfm[mi_c]) >= own_side; | |
| 764 | + let mut left = usize::from(self.left_txfm[mi_r]) >= own_side; | |
| 765 | + if mi_r > 0 && self.above_inter[mi_c] { | |
| 766 | + above = self.above_side_mi[mi_c] >= own_side; | |
| 767 | + } | |
| 768 | + if mi_c > 0 && self.left_inter[mi_r] { | |
| 769 | + left = self.left_side_mi[mi_r] >= own_side; | |
| 770 | + } | |
| 771 | + usize::from(above) + usize::from(left) | |
| 728 | 772 | } |
| 729 | 773 | |
| 730 | 774 | /// `get_tx_size_context` (decode.rs [`crate::decode::tx_size_context`]): |
| @@ -1648,45 +1692,24 @@ fn write_block_planes( | ||
| 1648 | 1692 | } |
| 1649 | 1693 | } |
| 1650 | 1694 | |
| 1651 | -/// Writes one intra block's luma residual under `TxMode::Select`: the | |
| 1652 | -/// `tx_depth` symbol (spec 5.11.16 `read_selected_tx_size`, off the size | |
| 1653 | -/// category's own CDF at [`Neighbours::tx_size_ctx`]'s row), then the | |
| 1654 | -/// `(side / tx)^2` transform units in raster order -- each predicted and | |
| 1655 | -/// coded against what the units before it already left behind, which is why | |
| 1656 | -/// every unit publishes its own coefficient context before the next one reads | |
| 1657 | -/// it (decode.rs `decode_block`'s multi-transform-unit branch). | |
| 1658 | -/// | |
| 1659 | -/// `grid` is the block's levels in BLOCK coordinates (`side` by `side`) when | |
| 1660 | -/// the transform splits, and the single transform's own coefficient grid when | |
| 1661 | -/// it does not. Hands back the resolved transform side in pixels. | |
| 1695 | +/// The `(side / tx)^2` transform units of one block's luma residual, raster | |
| 1696 | +/// order, each with its own coefficient context and each published before the | |
| 1697 | +/// next one reads it (decode.rs `decode_block`'s multi-transform-unit branch). | |
| 1698 | +/// `grid` is the block's levels in BLOCK coordinates when the transform | |
| 1699 | +/// splits, and the single transform's own coefficient grid when it does not. | |
| 1662 | 1700 | #[allow(clippy::too_many_arguments)] |
| 1663 | -fn write_luma_select( | |
| 1701 | +fn write_luma_tus( | |
| 1664 | 1702 | enc: &mut SymbolEncoder, |
| 1665 | 1703 | cdfs: &mut Cdfs, |
| 1666 | 1704 | neighbours: &mut Neighbours, |
| 1667 | 1705 | at_mi: (usize, usize), |
| 1668 | 1706 | side: usize, |
| 1669 | - depth: usize, | |
| 1707 | + tx: usize, | |
| 1670 | 1708 | grid: &[i32], |
| 1671 | 1709 | mode: usize, |
| 1672 | 1710 | scans: &[Vec<u16>; 4], |
| 1673 | -) -> Result<usize> { | |
| 1674 | - let max_tx = side.min(64); | |
| 1675 | - let ctx = neighbours.tx_size_ctx(at_mi, max_tx); | |
| 1676 | - match max_tx { | |
| 1677 | - 8 => enc.symbol(depth, &mut cdfs.tx_size_cat0[ctx]), | |
| 1678 | - 16 => enc.symbol(depth, &mut cdfs.tx_size_cat1[ctx]), | |
| 1679 | - 32 => enc.symbol(depth, &mut cdfs.tx_size_cat2[ctx]), | |
| 1680 | - 64 => enc.symbol(depth, &mut cdfs.tx_size_cat3[ctx]), | |
| 1681 | - _ => { | |
| 1682 | - return Err(Error::unsupported( | |
| 1683 | - "AV1 tile", | |
| 1684 | - "a tx_depth symbol is only coded at 8/16/32/64", | |
| 1685 | - )); | |
| 1686 | - } | |
| 1687 | - } | |
| 1688 | - let tx = max_tx >> depth; | |
| 1689 | - if depth > 0 && side > 32 { | |
| 1711 | +) -> Result<()> { | |
| 1712 | + if tx < side && side > 32 { | |
| 1690 | 1713 | // A 64x64 block's own levels reach the writer as the 32x32 corner a |
| 1691 | 1714 | // 64-point transform codes, not as a 64x64 block grid, so there is |
| 1692 | 1715 | // nothing to slice per unit here. |
| @@ -1746,10 +1769,107 @@ fn write_luma_select( | ||
| 1746 | 1769 | } |
| 1747 | 1770 | } |
| 1748 | 1771 | } |
| 1772 | + Ok(()) | |
| 1773 | +} | |
| 1774 | + | |
| 1775 | +/// Writes one intra block's luma residual under `TxMode::Select`: the | |
| 1776 | +/// `tx_depth` symbol (spec 5.11.16 `read_selected_tx_size`, off the size | |
| 1777 | +/// category's own CDF at [`Neighbours::tx_size_ctx`]'s row), then the | |
| 1778 | +/// `(side / tx)^2` transform units in raster order -- each predicted and | |
| 1779 | +/// coded against what the units before it already left behind, which is why | |
| 1780 | +/// every unit publishes its own coefficient context before the next one reads | |
| 1781 | +/// it (decode.rs `decode_block`'s multi-transform-unit branch). | |
| 1782 | +/// | |
| 1783 | +/// `grid` is the block's levels in BLOCK coordinates (`side` by `side`) when | |
| 1784 | +/// the transform splits, and the single transform's own coefficient grid when | |
| 1785 | +/// it does not. Hands back the resolved transform side in pixels. | |
| 1786 | +#[allow(clippy::too_many_arguments)] | |
| 1787 | +fn write_luma_select( | |
| 1788 | + enc: &mut SymbolEncoder, | |
| 1789 | + cdfs: &mut Cdfs, | |
| 1790 | + neighbours: &mut Neighbours, | |
| 1791 | + at_mi: (usize, usize), | |
| 1792 | + side: usize, | |
| 1793 | + depth: usize, | |
| 1794 | + grid: &[i32], | |
| 1795 | + mode: usize, | |
| 1796 | + scans: &[Vec<u16>; 4], | |
| 1797 | +) -> Result<usize> { | |
| 1798 | + let max_tx = side.min(64); | |
| 1799 | + let ctx = neighbours.tx_size_ctx(at_mi, max_tx); | |
| 1800 | + match max_tx { | |
| 1801 | + 8 => enc.symbol(depth, &mut cdfs.tx_size_cat0[ctx]), | |
| 1802 | + 16 => enc.symbol(depth, &mut cdfs.tx_size_cat1[ctx]), | |
| 1803 | + 32 => enc.symbol(depth, &mut cdfs.tx_size_cat2[ctx]), | |
| 1804 | + 64 => enc.symbol(depth, &mut cdfs.tx_size_cat3[ctx]), | |
| 1805 | + _ => { | |
| 1806 | + return Err(Error::unsupported( | |
| 1807 | + "AV1 tile", | |
| 1808 | + "a tx_depth symbol is only coded at 8/16/32/64", | |
| 1809 | + )); | |
| 1810 | + } | |
| 1811 | + } | |
| 1812 | + let tx = max_tx >> depth; | |
| 1813 | + write_luma_tus(enc, cdfs, neighbours, at_mi, side, tx, grid, mode, scans)?; | |
| 1749 | 1814 | neighbours.record_tx(at_mi, side, tx); |
| 1750 | 1815 | Ok(tx) |
| 1751 | 1816 | } |
| 1752 | 1817 | |
| 1818 | +/// The transform syntax one block of an INTER frame coded with | |
| 1819 | +/// `tx_mode == TxMode::Select` carries, in the place spec 5.11.16's | |
| 1820 | +/// `read_block_tx_size` reads it -- after the modes and the motion vector, | |
| 1821 | +/// before the residual: | |
| 1822 | +/// * an inter block that codes a residual walks a var-tx tree; this writer | |
| 1823 | +/// keeps it at its own largest transform, so that is one `txfm_split` flag | |
| 1824 | +/// of zero, off `txfm_partition_ctx_rect`'s row, publishing the bands per | |
| 1825 | +/// unit the way `read_var_tx_size` does. | |
| 1826 | +/// * a skipped inter block codes nothing and records its own BLOCK size | |
| 1827 | +/// (`set_txfm_ctxs`'s `skip_inter` term). | |
| 1828 | +/// * an intra block codes `tx_depth` like a key frame's, but off the | |
| 1829 | +/// `TXFM_CONTEXT` bands rather than the deblock grid. | |
| 1830 | +/// | |
| 1831 | +/// Hands back the block's resolved luma transform side. | |
| 1832 | +#[allow(clippy::too_many_arguments)] | |
| 1833 | +fn write_tx_syntax_inter( | |
| 1834 | + enc: &mut SymbolEncoder, | |
| 1835 | + cdfs: &mut Cdfs, | |
| 1836 | + neighbours: &mut Neighbours, | |
| 1837 | + at_mi: (usize, usize), | |
| 1838 | + side: usize, | |
| 1839 | + is_inter: bool, | |
| 1840 | + skip: bool, | |
| 1841 | + depth: usize, | |
| 1842 | +) -> usize { | |
| 1843 | + let max_tx = side.min(64); | |
| 1844 | + let (mi_r, mi_c) = at_mi; | |
| 1845 | + if is_inter { | |
| 1846 | + if !skip { | |
| 1847 | + let ctx = txfm_partition_ctx_rect( | |
| 1848 | + neighbours.above_txfm[mi_c], | |
| 1849 | + neighbours.left_txfm[mi_r], | |
| 1850 | + side, | |
| 1851 | + max_tx, | |
| 1852 | + max_tx, | |
| 1853 | + ); | |
| 1854 | + enc.symbol(0, &mut cdfs.txfm_partition[ctx]); | |
| 1855 | + neighbours.record_txfm(at_mi, max_tx, max_tx, max_tx); | |
| 1856 | + } else { | |
| 1857 | + neighbours.record_txfm(at_mi, side, side, side); | |
| 1858 | + } | |
| 1859 | + return max_tx; | |
| 1860 | + } | |
| 1861 | + let ctx = neighbours.tx_size_ctx_txfm(at_mi, max_tx); | |
| 1862 | + match max_tx { | |
| 1863 | + 8 => enc.symbol(depth, &mut cdfs.tx_size_cat0[ctx]), | |
| 1864 | + 16 => enc.symbol(depth, &mut cdfs.tx_size_cat1[ctx]), | |
| 1865 | + 32 => enc.symbol(depth, &mut cdfs.tx_size_cat2[ctx]), | |
| 1866 | + _ => enc.symbol(depth, &mut cdfs.tx_size_cat3[ctx]), | |
| 1867 | + } | |
| 1868 | + let tx = max_tx >> depth; | |
| 1869 | + neighbours.record_txfm(at_mi, tx, side, side); | |
| 1870 | + tx | |
| 1871 | +} | |
| 1872 | + | |
| 1753 | 1873 | /// What a coded transform block leaves behind for the blocks that read it as a |
| 1754 | 1874 | /// neighbour. |
| 1755 | 1875 | fn neighbour_state(grid: &[i32]) -> Neighbour { |
| @@ -2498,6 +2618,25 @@ pub fn sb_coeff_inter_frame_tile( | ||
| 2498 | 2618 | mi_rows: u32, |
| 2499 | 2619 | base_q_idx: u8, |
| 2500 | 2620 | blocks: &[Quadrant], |
| 2621 | +) -> Result<Vec<u8>> { | |
| 2622 | + sb_coeff_inter_frame_tile_tx(mi_cols, mi_rows, base_q_idx, blocks, false) | |
| 2623 | +} | |
| 2624 | + | |
| 2625 | +/// [`sb_coeff_inter_frame_tile`] for a frame header carrying | |
| 2626 | +/// `tx_mode == TxMode::Select`: every block then codes the transform syntax | |
| 2627 | +/// [`write_tx_syntax_inter`] writes -- one `txfm_split` flag on an inter | |
| 2628 | +/// block that carries a residual, a `tx_depth` symbol on an intra one -- and | |
| 2629 | +/// an intra block whose depth is nonzero codes its luma as several transform | |
| 2630 | +/// units. With `tx_select` false this writes exactly the stream it always did. | |
| 2631 | +/// | |
| 2632 | +/// # Errors | |
| 2633 | +/// As [`sb_coeff_inter_frame_tile`]. | |
| 2634 | +pub fn sb_coeff_inter_frame_tile_tx( | |
| 2635 | + mi_cols: u32, | |
| 2636 | + mi_rows: u32, | |
| 2637 | + base_q_idx: u8, | |
| 2638 | + blocks: &[Quadrant], | |
| 2639 | + tx_select: bool, | |
| 2501 | 2640 | ) -> Result<Vec<u8>> { |
| 2502 | 2641 | check_blocks(mi_cols, mi_rows)?; |
| 2503 | 2642 | // `block_grid`'s ceiling, not a plain division: a true frame size that is |
| @@ -2552,6 +2691,14 @@ pub fn sb_coeff_inter_frame_tile( | ||
| 2552 | 2691 | let scan16 = default_scan(TX16); |
| 2553 | 2692 | let scan8 = default_scan(TX8); |
| 2554 | 2693 | let scan4 = default_scan(TX4); |
| 2694 | + // The same four tables again as one array, which is what the per-unit | |
| 2695 | + // luma writer indexes by transform side. | |
| 2696 | + let all_scans = [ | |
| 2697 | + scan32.clone(), | |
| 2698 | + scan16.clone(), | |
| 2699 | + scan8.clone(), | |
| 2700 | + scan4.clone(), | |
| 2701 | + ]; | |
| 2555 | 2702 | let zero_grids = [ |
| 2556 | 2703 | vec![0i32; TX32 * TX32], |
| 2557 | 2704 | vec![0i32; TX16 * TX16], |
| @@ -2715,6 +2862,8 @@ pub fn sb_coeff_inter_frame_tile( | ||
| 2715 | 2862 | leaf_mi, |
| 2716 | 2863 | &scan8, |
| 2717 | 2864 | &scan4, |
| 2865 | + tx_select, | |
| 2866 | + &all_scans, | |
| 2718 | 2867 | )?; |
| 2719 | 2868 | let _ = (skip, is_inter); |
| 2720 | 2869 | } |
| @@ -2732,6 +2881,8 @@ pub fn sb_coeff_inter_frame_tile( | ||
| 2732 | 2881 | at16, |
| 2733 | 2882 | &scan16, |
| 2734 | 2883 | &scan8, |
| 2884 | + tx_select, | |
| 2885 | + &all_scans, | |
| 2735 | 2886 | )?; |
| 2736 | 2887 | } else { |
| 2737 | 2888 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| @@ -2780,6 +2931,8 @@ pub fn sb_coeff_inter_frame_tile( | ||
| 2780 | 2931 | leaf_mi, |
| 2781 | 2932 | &scan8, |
| 2782 | 2933 | &scan4, |
| 2934 | + tx_select, | |
| 2935 | + &all_scans, | |
| 2783 | 2936 | )?; |
| 2784 | 2937 | let _ = (skip, is_inter); |
| 2785 | 2938 | } |
| @@ -2931,6 +3084,22 @@ pub fn sb_coeff_inter_frame_tile( | ||
| 2931 | 3084 | } |
| 2932 | 3085 | } |
| 2933 | 3086 | |
| 3087 | + let at_mi = (at.0 * (SUB / MI), at.1 * (SUB / MI)); | |
| 3088 | + let tx = if tx_select { | |
| 3089 | + write_tx_syntax_inter( | |
| 3090 | + &mut enc, | |
| 3091 | + &mut cdfs, | |
| 3092 | + &mut neighbours, | |
| 3093 | + at_mi, | |
| 3094 | + BLOCK, | |
| 3095 | + is_inter, | |
| 3096 | + block.skip, | |
| 3097 | + usize::from(block.tx_depth), | |
| 3098 | + ) | |
| 3099 | + } else { | |
| 3100 | + BLOCK | |
| 3101 | + }; | |
| 3102 | + let split = tx < BLOCK; | |
| 2934 | 3103 | if block.skip { |
| 2935 | 3104 | neighbours.record(at, BLOCK, mode_for_tx, &zero_grids); |
| 2936 | 3105 | } else { |
| @@ -2939,6 +3108,19 @@ pub fn sb_coeff_inter_frame_tile( | ||
| 2939 | 3108 | level_grid(&block.u, TX16)?, |
| 2940 | 3109 | level_grid(&block.v, TX16)?, |
| 2941 | 3110 | ]; |
| 3111 | + if split { | |
| 3112 | + write_luma_tus( | |
| 3113 | + &mut enc, | |
| 3114 | + &mut cdfs, | |
| 3115 | + &mut neighbours, | |
| 3116 | + at_mi, | |
| 3117 | + BLOCK, | |
| 3118 | + tx, | |
| 3119 | + &grids[0], | |
| 3120 | + mode_for_tx, | |
| 3121 | + &all_scans, | |
| 3122 | + )?; | |
| 3123 | + } | |
| 2942 | 3124 | write_block_planes( |
| 2943 | 3125 | &mut enc, |
| 2944 | 3126 | &mut cdfs, |
| @@ -2951,9 +3133,9 @@ pub fn sb_coeff_inter_frame_tile( | ||
| 2951 | 3133 | &[&scan32, &scan16, &scan16], |
| 2952 | 3134 | &neighbours.around(at, BLOCK), |
| 2953 | 3135 | mode_for_tx, |
| 2954 | - false, | |
| 3136 | + split, | |
| 2955 | 3137 | ); |
| 2956 | - neighbours.record(at, BLOCK, mode_for_tx, &grids); | |
| 3138 | + neighbours.record_planes(at, BLOCK, mode_for_tx, &grids, !split); | |
| 2957 | 3139 | } |
| 2958 | 3140 | neighbours.record_inter(at, BLOCK, block.skip, is_inter); |
| 2959 | 3141 | } |
| @@ -2984,6 +3166,8 @@ fn write_inter_frame_leaf( | ||
| 2984 | 3166 | at: (usize, usize), |
| 2985 | 3167 | scan16: &Vec<u16>, |
| 2986 | 3168 | scan8: &Vec<u16>, |
| 3169 | + tx_select: bool, | |
| 3170 | + all_scans: &[Vec<u16>; 4], | |
| 2987 | 3171 | ) -> Result<()> { |
| 2988 | 3172 | if block.inter.is_none() && usize::from(block.mode) >= INTRA_MODES { |
| 2989 | 3173 | return Err(Error::unsupported( |
| @@ -3112,6 +3296,22 @@ fn write_inter_frame_leaf( | ||
| 3112 | 3296 | } |
| 3113 | 3297 | } |
| 3114 | 3298 | |
| 3299 | + let at_mi = (at.0 * (SUB / MI), at.1 * (SUB / MI)); | |
| 3300 | + let tx = if tx_select { | |
| 3301 | + write_tx_syntax_inter( | |
| 3302 | + enc, | |
| 3303 | + cdfs, | |
| 3304 | + neighbours, | |
| 3305 | + at_mi, | |
| 3306 | + SUB, | |
| 3307 | + is_inter, | |
| 3308 | + block.skip, | |
| 3309 | + usize::from(block.tx_depth), | |
| 3310 | + ) | |
| 3311 | + } else { | |
| 3312 | + SUB | |
| 3313 | + }; | |
| 3314 | + let split = tx < SUB; | |
| 3115 | 3315 | if block.skip { |
| 3116 | 3316 | let zero_grids = [ |
| 3117 | 3317 | vec![0i32; TX16 * TX16], |
| @@ -3125,6 +3325,11 @@ fn write_inter_frame_leaf( | ||
| 3125 | 3325 | level_grid(&block.u, TX8)?, |
| 3126 | 3326 | level_grid(&block.v, TX8)?, |
| 3127 | 3327 | ]; |
| 3328 | + if split { | |
| 3329 | + write_luma_tus( | |
| 3330 | + enc, cdfs, neighbours, at_mi, SUB, tx, &grids[0], mode_for_tx, all_scans, | |
| 3331 | + )?; | |
| 3332 | + } | |
| 3128 | 3333 | write_block_planes( |
| 3129 | 3334 | enc, |
| 3130 | 3335 | cdfs, |
| @@ -3137,9 +3342,9 @@ fn write_inter_frame_leaf( | ||
| 3137 | 3342 | &[scan16, scan8, scan8], |
| 3138 | 3343 | &neighbours.around(at, SUB), |
| 3139 | 3344 | mode_for_tx, |
| 3140 | - false, | |
| 3345 | + split, | |
| 3141 | 3346 | ); |
| 3142 | - neighbours.record(at, SUB, mode_for_tx, &grids); | |
| 3347 | + neighbours.record_planes(at, SUB, mode_for_tx, &grids, !split); | |
| 3143 | 3348 | } |
| 3144 | 3349 | neighbours.record_inter(at, SUB, block.skip, is_inter); |
| 3145 | 3350 | Ok(()) |
| @@ -3174,6 +3379,8 @@ fn write_inter_frame_leaf8( | ||
| 3174 | 3379 | leaf_mi: (usize, usize), |
| 3175 | 3380 | scan8: &Vec<u16>, |
| 3176 | 3381 | scan4: &Vec<u16>, |
| 3382 | + tx_select: bool, | |
| 3383 | + all_scans: &[Vec<u16>; 4], | |
| 3177 | 3384 | ) -> Result<(bool, bool)> { |
| 3178 | 3385 | if block.inter.is_none() && usize::from(block.mode) >= INTRA_MODES { |
| 3179 | 3386 | return Err(Error::unsupported( |
| @@ -3314,6 +3521,21 @@ fn write_inter_frame_leaf8( | ||
| 3314 | 3521 | } else { |
| 3315 | 3522 | [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4] |
| 3316 | 3523 | }; |
| 3524 | + let tx = if tx_select { | |
| 3525 | + write_tx_syntax_inter( | |
| 3526 | + enc, | |
| 3527 | + cdfs, | |
| 3528 | + neighbours, | |
| 3529 | + leaf_mi, | |
| 3530 | + 8, | |
| 3531 | + is_inter, | |
| 3532 | + block.skip, | |
| 3533 | + usize::from(block.tx_depth), | |
| 3534 | + ) | |
| 3535 | + } else { | |
| 3536 | + 8 | |
| 3537 | + }; | |
| 3538 | + let split = tx < 8; | |
| 3317 | 3539 | if block.skip { |
| 3318 | 3540 | let zero_grids = [ |
| 3319 | 3541 | vec![0i32; TX8 * TX8], |
| @@ -3328,6 +3550,11 @@ fn write_inter_frame_leaf8( | ||
| 3328 | 3550 | level_grid(&block.u, TX4)?, |
| 3329 | 3551 | level_grid(&block.v, TX4)?, |
| 3330 | 3552 | ]; |
| 3553 | + if split { | |
| 3554 | + write_luma_tus( | |
| 3555 | + enc, cdfs, neighbours, leaf_mi, 8, tx, &grids[0], mode_for_tx, all_scans, | |
| 3556 | + )?; | |
| 3557 | + } | |
| 3331 | 3558 | write_block_planes( |
| 3332 | 3559 | enc, |
| 3333 | 3560 | cdfs, |
| @@ -3336,9 +3563,9 @@ fn write_inter_frame_leaf8( | ||
| 3336 | 3563 | &[scan8, scan4, scan4], |
| 3337 | 3564 | &neighbours.around_mi(leaf_mi, 8), |
| 3338 | 3565 | mode_for_tx, |
| 3339 | - false, | |
| 3566 | + split, | |
| 3340 | 3567 | ); |
| 3341 | - neighbours.record_mi(leaf_mi, 8, &grids); | |
| 3568 | + neighbours.record_mi_planes(leaf_mi, 8, &grids, !split); | |
| 3342 | 3569 | neighbours.record_inter_mi(leaf_mi, 8, block.skip, is_inter); |
| 3343 | 3570 | } |
| 3344 | 3571 | Ok((block.skip, is_inter)) |