//! The CDFs a tile adapts as it is written. //! //! AV1's symbol decoder updates every non-literal CDF it reads (spec 8.3.2), //! so an encoder that wants `disable_cdf_update` off has to keep the same //! state and update it in the same order. What lives here is that state: one //! owned copy of each table the tile writer touches, seeded from the defaults //! in [`crate::cdf`]. //! //! The tables are owned once, not once per use: two coefficient table sets //! that share a table -- a 64x64 luma transform reads the 32x32 base-range //! rows, and both luma sets read the same DC sign table -- share the *adapted* //! table too, which is what the decoder does. use crate::cdf; /// Which of the four coefficient table sets a transform block is coded with. #[derive(Clone, Copy)] pub(crate) enum TxbSet { /// The 32x32 luma transform of an intra 32x32 block. `get_tx_set` is /// DCT-only at this size for an intra block, so no `tx_type` symbol is /// coded; an `is_inter` 32x32 block reads a different set and uses /// [`Luma32Inter`](TxbSet::Luma32Inter) instead. Luma32, /// The 32x32 luma transform of an `is_inter` 32x32 block: the same /// coefficient tables [`Luma32`](TxbSet::Luma32) reads, but `get_tx_set` /// (spec 5.11.48) returns `TX_SET_INTER_3` rather than `TX_SET_DCTONLY` /// at this size for an inter block, so this variant carries the /// `tx_type` symbol `Luma32` does not. Luma32Inter, /// The 64x64 luma transform of a whole superblock, scanned as a 32x32. Luma64, /// The 16x16 luma transform of a 16x16 block. Luma16, /// The 16x16 luma transform of an `is_inter` 16x16 block, coded under /// `reduced_tx_set` (see [`crate::cdf::INTER_TX_TYPE_SET3_16`]'s doc /// comment): the same coefficient tables [`Luma16`](TxbSet::Luma16) /// reads, but its own two-symbol `tx_type` table rather than `Luma16`'s /// five-symbol, mode-indexed one. Luma16Inter, /// [`Luma16Inter`](TxbSet::Luma16Inter)'s `reduced_tx_set: false` /// counterpart (lane-cdffwd2, root-caused off `cdfflake-stream-seed45`): /// the same coefficient tables, but the twelve-symbol /// `EXT_TX_SET_DTT9_IDTX_1DDCT` `tx_type` table /// ([`crate::cdf::INTER_TX_TYPE_SET2_16`]) rather than `Luma16Inter`'s /// two-symbol reduced one. Luma16InterSet1, /// The 8x8 luma transform of an intra 8x8 leaf under a straddling 16x16 /// block (lane-av1-rect). An `is_inter` leaf reads /// [`Luma8Inter`](TxbSet::Luma8Inter) instead. Luma8, /// [`Luma8`](TxbSet::Luma8)'s `reduced_tx_set: false` counterpart (round /// 8): the same coefficient tables, but the seven-symbol `TX_SET_INTRA_1` /// `tx_type` table rather than `Luma8`'s five-symbol reduced one. Luma8Set1, /// The 8x8 luma transform of an `is_inter` 8x8 leaf under a straddling /// 16x16 block (lane-av1inter8): the same coefficient tables /// [`Luma8`](TxbSet::Luma8) reads, but `get_tx_set` (spec 5.11.48) /// returns `TX_SET_INTER_3` at this size too under this encoder's /// always-on `reduced_tx_set` -- the same two-symbol alphabet /// [`Luma16Inter`](TxbSet::Luma16Inter) carries, just its own CDF (libaom /// `default_inter_ext_tx_cdf[EXT_TX_SET_DCT_IDTX][TX_8X8]`, a distinct /// adapted table from the 16x16 and 32x32 sizes' own entries in the same /// set, per `entropymode.c`). Luma8Inter, /// [`Luma8Inter`](TxbSet::Luma8Inter)'s `reduced_tx_set: false` /// counterpart (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` /// `tx_type` table ([`crate::cdf::INTER_TX_TYPE_SET1_8`]). Luma8InterSet1, /// The 4x4 luma transform of a `TxMode::Select` 8x8 leaf or 16x16 block /// whose `tx_depth` resolves all the way down (lane-av1tx4). An /// `is_inter` block has no writer path yet, so this crate has no /// `Luma4Inter` counterpart to [`Luma8Inter`](TxbSet::Luma8Inter). Luma4, /// The 4x4 luma transform of an `is_inter` block whose `TxMode::Select` /// var-tx tree splits an 8x8 unit all the way down (lane-txselect): the /// same coefficient tables [`Luma4`](TxbSet::Luma4) reads (libaom's /// coefficient CDFs are keyed by plane type, not intra/inter), with the /// inter `tx_type` set in place of the intra one. Luma4Inter, /// [`Luma4Inter`](TxbSet::Luma4Inter)'s `reduced_tx_set: false` /// counterpart -- the sixteen-symbol `EXT_TX_SET_ALL16` table /// ([`crate::cdf::INTER_TX_TYPE_SET1_4`]). Luma4InterSet1, /// [`Luma4`](TxbSet::Luma4)'s `reduced_tx_set: false` counterpart, same /// split as [`Luma8Set1`](TxbSet::Luma8Set1). Luma4Set1, /// The 8x8 transform of a chroma plane of a 16x16 block. Chroma8, /// The 4x4 transform of a chroma plane of an 8x8 leaf (lane-av1-rect). /// r5 correction: libaom's `is_chroma_reference` (`av1_common_int.h`) is /// unconditionally true for `bsize >= BLOCK_8X8`, so chroma *does* follow /// luma all the way down to 8x8 — it is coded once per 8x8 leaf, not once /// per parent 16x16 (that "stays at the parent's Chroma8 granularity" /// framing this doc carried through r4 was never checked against a real /// decoder and is wrong; only `BLOCK_4X4`/`4X8`/`8X4`, one mi-unit wide or /// high, get the "last sub-block only" chroma-merge treatment). A real /// writer for the straddling-16x16 case must use this variant per leaf. Chroma4, /// The 16x16 transform of a chroma plane of a 32x32 block. Chroma16, /// The 32x32 transform of a chroma plane of a whole superblock. Chroma32, /// The luma 32x16/16x32 transform of a `PARTITION_HORZ`/`VERT` intra /// strip (lane-rectwire): `get_txsize_entropy_ctx` reduces any 2:1 rect /// size to its square-up equivalent (`entropy.h:172`), so this shares /// every table [`Luma32`](TxbSet::Luma32) does except `eob_pt` -- a true /// 512-position transform reads [`crate::cdf::EOB_PT_512_LUMA`], not /// `Luma32`'s 1024-position one. Never carries a `tx_type` symbol: both /// orientations use one variant (`get_tx_set` is `EXT_TX_SET_DCTONLY` at /// `tx_size_sqr_up == TX_32X32` regardless of which axis is longer). /// The 32x8/8x32 luma transform of a 32x32-level `PARTITION_HORZ_4`/ /// `PARTITION_VERT_4` strip (lane-tx64x16 r3). `get_txsize_entropy_ctx` /// averages the two log2 sides ((5 + 3) / 2 = 4), so the coefficient CDF /// set is the 16x16 one [`Luma16`](TxbSet::Luma16) reads -- 256 coded /// positions, `eob_pt_256`. Unlike `Luma16` it carries NO `tx_type` /// symbol: `tx_size_sqr_up` of a 4:1 32-wide strip is `TX_32X32`, where /// `av1_get_ext_tx_set_type` returns `EXT_TX_SET_DCTONLY` for an intra /// block, so the encoder writes none (same reason /// [`LumaRect32x16`](TxbSet::LumaRect32x16) has none). LumaRect32x8, /// lane-rectres r1: [`LumaRect32x8`](TxbSet::LumaRect32x8)'s INTER twin -- /// the 32x32-level 1:4 strip (`max_txsize_rect_lookup[BLOCK_32X8] == /// TX_32X8`). Same coefficient tables (`get_txsize_entropy_ctx` = TX_16X16, /// `txsize_log2_minus4` = 4, 256 positions), but an inter unit DOES code a /// `tx_type`: `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_32X32` is /// `EXT_TX_SET_DCT_IDTX` for inter regardless of `reduced_tx_set`, read at /// the `txsize_sqr_map[TX_32X8] == TX_8X8` CDF row. LumaRect32x8Inter, LumaRect32x16, /// lane-inter4 r2: [`LumaRect32x16`](TxbSet::LumaRect32x16)'s INTER twin -- /// same coefficient tables (`get_txsize_entropy_ctx` reduces TX_32X16 and /// TX_16X32 alike to the 32x32 set, 512-coefficient `eob_pt`), but an /// inter block DOES code a `tx_type` symbol here: `av1_get_ext_tx_set_type` /// with `tx_size_sqr_up == TX_32X32` and `is_inter` returns /// `EXT_TX_SET_DCT_IDTX` (2 symbols), whose CDF is /// `default_inter_ext_tx_cdf[3][txsize_sqr_map[TX_32X16] == TX_16X16]`, /// i.e. exactly [`INTER_TX_TYPE_SET3_16`](crate::cdf::INTER_TX_TYPE_SET3_16) /// -- the same table the square `Luma16Inter` set reads. LumaRect32x16Inter, /// The chroma 16x8/8x16 transform under the same strip (lane-rectwire): /// [`Chroma16`](TxbSet::Chroma16)'s tables except `eob_pt`, which reads /// the true 128-position [`crate::cdf::EOB_PT_128_CHROMA`] instead of /// `Chroma16`'s 256-position one. ChromaRect16x8, /// The chroma 32x16/16x32 transform of an intra `PARTITION_HORZ`/`VERT` /// 64x32/32x64 SUPERBLOCK strip (lane-sbpart): `get_txsize_entropy_ctx` /// (`(txsize_sqr_map + txsize_sqr_up_map + 1) >> 1`) resolves `TX_32X16` /// to `TX_32X32`, so this shares every table /// [`Chroma32`](TxbSet::Chroma32) does except `eob_pt`, which reads the /// true 512-position [`crate::cdf::EOB_PT_512_CHROMA`] instead of /// `Chroma32`'s 1024-position one. The SIBLING luma plane of this same /// strip is genuinely truncated (64/32 > 32), so it reads /// [`Luma64`](TxbSet::Luma64) instead -- `get_txsize_entropy_ctx(TX_64X32)` /// resolves to `TX_64X64`, not `TX_32X32`, the two axes landing on /// different existing sets is why this variant exists at all rather than /// reusing [`LumaRect32x16`](TxbSet::LumaRect32x16)'s chroma sibling. ChromaRect32x16, /// The luma 16x8/8x16 transform of a `PARTITION_HORZ`/`VERT` intra strip /// below 16x16 (lane-rectx, `decode_leaf_rect`'s own leaf, one level /// under [`LumaRect32x16`](TxbSet::LumaRect32x16)): `get_txsize_entropy_ctx` /// reduces this 2:1 rect size to `TX_16X16` too, so this shares every /// table [`Luma16`](TxbSet::Luma16) does except two: its mode-indexed /// `tx_type` CDF, which is the *8x8* row's (see /// [`LumaRect16x8Set1`](TxbSet::LumaRect16x8Set1)), and `eob_pt`, which /// reads the true 128-position [`crate::cdf::EOB_PT_128_LUMA`] rather /// than `Luma16`'s 256-position one. Unlike /// [`LumaRect32x16`](TxbSet::LumaRect32x16), this size DOES carry a /// `tx_type` symbol: `av1_get_ext_tx_set_type` (`av1/common/blockd.h`) /// sees `tx_size_sqr_up == TX_16X16`, so intra reads /// `EXT_TX_SET_DTT4_IDTX` under `reduced_tx_set` and /// `EXT_TX_SET_DTT4_IDTX_1DDCT` without it (`tx_size_sqr` is `TX_8X8` /// here, not `TX_16X16`) -- this variant is the reduced arm, its /// `Set1` sibling the other. LumaRect16x8, /// [`LumaRect16x8`](TxbSet::LumaRect16x8)'s `reduced_tx_set: false` /// counterpart (lane-rectx r3), the same split /// [`Luma8Set1`](TxbSet::Luma8Set1) has to [`Luma8`](TxbSet::Luma8) -- /// and it is deliberately those two tables, not the 16x16 row: libaom's /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][square_tx_size]` with /// `square_tx_size = txsize_sqr_map[tx_size]`, which for `TX_16X8`/ /// `TX_8X16` is `TX_8X8`, NOT the `txsize_sqr_up_map` `TX_16X16` the /// txb-skip/base/br tables use (`get_txsize_entropy_ctx`). r2 read the /// 16x16 row's five-symbol reduced CDF here and desynced on the very /// first coded rect leaf. LumaRect16x8Set1, /// lane-inter4 r3: [`LumaRect16x8`](TxbSet::LumaRect16x8)'s INTER twin -- /// the same coefficient tables (`get_txsize_entropy_ctx` reduces TX_16X8 /// and TX_8X16 alike to the 16x16 set, 128-position `eob_pt`), with the /// inter `tx_type` alphabet in place of the intra one. Under /// `reduced_tx_set` `av1_get_ext_tx_set_type` (`tx_size_sqr_up == /// TX_16X16`, `is_inter`) returns `EXT_TX_SET_DCT_IDTX` (2 symbols), /// whose CDF row is `default_inter_ext_tx_cdf[1][txsize_sqr_map[TX_16X8] /// == TX_8X8]`, i.e. [`INTER_TX_TYPE_SET3_8`](crate::cdf::INTER_TX_TYPE_SET3_8) /// -- the same table the square `Luma8Inter` set reads. LumaRect16x8Inter, /// [`LumaRect16x8Inter`](TxbSet::LumaRect16x8Inter)'s `reduced_tx_set: /// false` counterpart: `tx_size_sqr` is `TX_8X8` here (NOT the /// `txsize_sqr_up_map` `TX_16X16` the coefficient tables use), so /// `av1_ext_tx_set_lookup[is_inter=1][tx_size_sqr == TX_16X16 -> 0]` is /// `EXT_TX_SET_ALL16` -- sixteen symbols, `default_inter_ext_tx_cdf[1] /// [TX_8X8]`, i.e. [`INTER_TX_TYPE_SET1_8`](crate::cdf::INTER_TX_TYPE_SET1_8), /// the table [`Luma8InterSet1`](TxbSet::Luma8InterSet1) also reads. LumaRect16x8InterSet1, /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx): /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of /// `Chroma8`'s 64-position one -- the same square-up relationship /// [`ChromaRect16x8`](TxbSet::ChromaRect16x8) has to `Chroma16`, one size /// class down. ChromaRect8x4, /// The luma 4x8/8x4 transform of a `PARTITION_VERT`/`HORZ` leaf under an /// 8x8 block (lane-tx4x8), under this encoder's `reduced_tx_set`. /// `get_txsize_entropy_ctx` ((`txsize_sqr_map` + `txsize_sqr_up_map` + 1) /// >> 1) resolves `TX_4X8` to `TX_8X8`, so every coefficient table here is /// [`Luma8`](TxbSet::Luma8)'s -- except `eob_pt`, a true 32-position /// alphabet ([`crate::cdf::EOB_PT_32_LUMA`]), and `tx_type`, whose CDF row /// is `txsize_sqr_map[TX_4X8]` = `TX_4X4` (libaom `read_tx_type`'s /// `square_tx_size`), i.e. [`Luma4`](TxbSet::Luma4)'s own table. LumaRect4x8, /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s `reduced_tx_set: false` /// counterpart: `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_8X8`, /// `tx_size_sqr == TX_4X4`, intra returns `EXT_TX_SET_DTT4_IDTX_1DDCT`, /// the same seven-symbol set (and same `TX_4X4` row) `Luma4Set1` reads. LumaRect4x8Set1, /// The luma 16x4/4x16 transform of a 16x16-level `PARTITION_HORZ_4`/ /// `PARTITION_VERT_4` strip (lane-r14). `get_txsize_entropy_ctx` /// ((`txsize_sqr_map` + `txsize_sqr_up_map` + 1) >> 1) resolves `TX_16X4` /// to `TX_8X8`, and the transform has 64 coded positions, so EVERY table /// here is [`Luma8`](TxbSet::Luma8)'s (`eob_pt_64` included) except /// `tx_type`: `read_tx_type` indexes `intra_ext_tx_cdf[eset] /// [txsize_sqr_map[TX_16X4]]` = the `TX_4X4` row, and /// `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_16X16` with /// `tx_size_sqr == TX_4X4` returns `EXT_TX_SET_DTT4_IDTX` under /// `reduced_tx_set` -- the same pair [`LumaRect4x8`](TxbSet::LumaRect4x8) /// reads, which differs from this variant only in its 32-position `eob_pt`. LumaRect16x4, /// [`LumaRect16x4`](TxbSet::LumaRect16x4)'s `reduced_tx_set: false` /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4` /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads. LumaRect16x4Set1, /// The luma 8x4/4x8 transform of an INTER `PARTITION_HORZ`/`PARTITION_VERT` /// leaf under an 8x8 block (lane-intersub8 r3): every coefficient table is /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s (`get_txsize_entropy_ctx` squares /// `TX_8X4` up to the 8x8 class, 32-position `eob_pt`), with the INTER /// `tx_type` alphabet in its place. Under `reduced_tx_set` /// `av1_get_ext_tx_set_type` (`tx_size_sqr_up == TX_8X8`, `is_inter`) /// returns `EXT_TX_SET_DCT_IDTX`, whose row is /// `default_inter_ext_tx_cdf[?][txsize_sqr_map[TX_8X4] == TX_4X4]` -- the /// same `TX_4X4` inter row [`Luma4Inter`](TxbSet::Luma4Inter) reads. LumaRect8x4Inter, /// [`LumaRect8x4Inter`](TxbSet::LumaRect8x4Inter)'s `reduced_tx_set: false` /// counterpart: `tx_size_sqr == TX_4X4` with `tx_size_sqr_up == TX_8X8`, so /// `av1_ext_tx_set_lookup[is_inter=1][...]` is `EXT_TX_SET_ALL16` -- sixteen /// symbols at the `TX_4X4` inter row, the table /// [`Luma4InterSet1`](TxbSet::Luma4InterSet1) also reads. LumaRect8x4InterSet1, /// [`LumaRect16x4`](TxbSet::LumaRect16x4)'s INTER counterpart /// (lane-inter16ab r2): the same `Luma8` coefficient tables (64 coded /// positions, `get_txsize_entropy_ctx(TX_16X4)` = TX_8X8), with the /// INTER `tx_type` table at `txsize_sqr_map[TX_16X4]` = TX_4X4. /// `av1_get_ext_tx_set_type` (av1/common/idct.c): `tx_size_sqr_up` is /// TX_16X16 (not > TX_32X32) and `use_reduced_set` picks /// `EXT_TX_SET_DCT_IDTX` -- three symbols, `inter_tx_type_4`. LumaRect16x4Inter, /// [`LumaRect16x4Inter`](TxbSet::LumaRect16x4Inter)'s /// `reduced_tx_set: false` counterpart: `tx_size_sqr` is TX_4X4, not /// TX_16X16, so `av1_get_ext_tx_set_type` returns `EXT_TX_SET_ALL16` -- /// sixteen symbols, `inter_tx_type_4_set1`. LumaRect16x4Inter1, } /// The tables one transform block is coded with, borrowed from the state for /// as long as that block is being written. pub(crate) struct TxbTables<'a> { /// Side of the transform, in coefficients. pub side: usize, /// The all-zero flag, indexed by its own context. pub txb_skip: &'a mut [[u16; 3]], /// The end-of-block group, whose alphabet the transform size sets. pub eob_pt: &'a mut [u16], /// `eob_pt`'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling table (r5): read /// instead of `eob_pt` once this TU's `tx_type` is known to be /// `V_DCT`/`H_DCT`. `None` for any size/set whose `tx_type` alphabet /// cannot produce those two symbols (chroma, and every inter set). pub eob_pt_class1: Option<&'a mut [u16]>, /// The top bit of the offset inside that group. pub eob_extra: &'a mut [[u16; 3]; 9], /// A coefficient's base level. pub base: &'a mut [[u16; 5]; 42], /// The base level of the last coefficient in the scan. pub base_eob: &'a mut [[u16; 4]; 4], /// The base-range tail above level two. pub br: &'a mut [[u16; 5]; 21], /// The sign of the DC. pub dc_sign: &'a mut [[u16; 3]; 3], /// The transform type, for the one size whose set holds more than one -- /// a plain slice because the intra 16x16 table's alphabet (five types) /// and the inter 32x32 table's (two, `TX_SET_INTER_3`) are different /// sizes. pub tx_type: Option<&'a mut [u16]>, } /// Every table a key frame's tile writer adapts. #[derive(Clone)] pub(crate) struct Cdfs { /// The partition symbol of a 64x64 superblock. /// `partition_cdf`'s `BLOCK_128X128` rows (8 symbols). pub partition_w128: [[u16; 9]; 4], pub partition_w64: [[u16; 11]; 4], /// The partition symbol of a 32x32 block. pub partition_w32: [[u16; 11]; 4], /// Whether a block carries no residual at all. /// `txfm_partition_cdf`: an inter block's `txfm_split` flag under /// `TxMode::Select` (lane-txselect, spec 5.11.17), indexed by /// `txfm_partition_context` -- see [`cdf::TXFM_PARTITION`]. pub txfm_partition: [[u16; 3]; 21], pub skip: [[u16; 3]; 3], /// The luma mode of a key frame's block, under the two neighbours' modes. pub kf_y_mode: [[[u16; 14]; 5]; 5], /// The chroma mode of a block too big to be offered chroma from luma. pub uv_mode_no_cfl: [[u16; 14]; 13], /// The chroma mode of a block that is offered it. pub uv_mode_cfl: [[u16; 15]; 13], /// The joint sign of a `UV_CFL_PRED` block's U/V alpha. pub cfl_sign: [u16; 9], /// A `UV_CFL_PRED` block's per-plane alpha magnitude, by joint-sign context. pub cfl_alpha: [[u16; 17]; 6], /// The angle a directional mode is nudged by. pub angle_delta: [[u16; 8]; 8], /// The all-zero flag of a 16x16 luma transform, 7 contexts (index 0 for /// a lone TU whose own bsize equals the block's; 1..6 the /// `skip_contexts[top][left]` table when `TxMode::Select` splits the /// block's luma into several smaller transform units, spec /// `get_txb_ctx_general`). pub txb_skip_luma_16: [[u16; 3]; 7], /// The same, for an 8x8 luma transform. pub txb_skip_luma_8: [[u16; 3]; 7], /// The same, for a 4x4 luma transform (lane-av1tx4). pub txb_skip_luma_4: [[u16; 3]; 7], /// The all-zero flag of an 8x8 chroma transform. pub txb_skip_chroma_8: [[u16; 3]; 3], /// The all-zero flag of a 4x4 chroma transform. pub txb_skip_chroma_4: [[u16; 3]; 3], /// The end-of-block group of a 16x16 luma transform. pub eob_pt_256_luma: [u16; 10], /// The end-of-block group of an 8x8 luma transform. pub eob_pt_64_luma: [u16; 8], /// The end-of-block group of an 8x8 chroma transform. pub eob_pt_64_chroma: [u16; 8], /// The end-of-block group of a 4x4 chroma transform. pub eob_pt_16_chroma: [u16; 6], /// The end-of-block group of a 4x4 luma transform (lane-av1tx4). pub eob_pt_16_luma: [u16; 6], /// `eob_pt_16_luma`'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling, read /// instead whenever the TU's `tx_type` is `V_DCT`/`H_DCT` (r5). pub eob_pt_16_luma_class1: [u16; 6], /// `eob_pt_64_luma`'s class-1 sibling (r5), see `eob_pt_16_luma_class1`. pub eob_pt_64_luma_class1: [u16; 8], /// `eob_pt_16_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_16_chroma_class1: [u16; 6], /// `eob_pt_64_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_64_chroma_class1: [u16; 8], /// `eob_pt_128_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_128_chroma_class1: [u16; 9], /// `eob_pt_128_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_128_luma_class1: [u16; 9], /// `eob_pt_32_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_32_chroma_class1: [u16; 7], /// `eob_pt_256_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_256_luma_class1: [u16; 10], /// `eob_pt_256_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_256_chroma_class1: [u16; 10], /// `eob_pt_512_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_512_luma_class1: [u16; 11], /// `eob_pt_512_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_512_chroma_class1: [u16; 11], /// `eob_pt_1024_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_1024_luma_class1: [u16; 12], /// `eob_pt_1024_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. pub eob_pt_1024_chroma_class1: [u16; 12], /// The end-of-block group of a 32-position (4x8/8x4) luma transform /// (lane-tx4x8). pub eob_pt_32_luma: [u16; 7], /// `eob_pt_32_luma`'s class-1 sibling, see `eob_pt_16_luma_class1`. pub eob_pt_32_luma_class1: [u16; 7], /// The end-of-block offset bit of a 16x16 luma transform. pub eob_extra_luma_16: [[u16; 3]; 9], /// The same, for an 8x8 luma transform. pub eob_extra_luma_8: [[u16; 3]; 9], /// The same, for a 4x4 luma transform. pub eob_extra_luma_4: [[u16; 3]; 9], /// The same, for an 8x8 chroma transform. pub eob_extra_chroma_8: [[u16; 3]; 9], /// The same, for a 4x4 chroma transform. pub eob_extra_chroma_4: [[u16; 3]; 9], /// The base level of a 16x16 luma coefficient. pub base_luma_16: [[u16; 5]; 42], /// The base level of an 8x8 luma coefficient. pub base_luma_8: [[u16; 5]; 42], /// The base level of a 4x4 luma coefficient. pub base_luma_4: [[u16; 5]; 42], /// The base level of an 8x8 chroma coefficient. pub base_chroma_8: [[u16; 5]; 42], /// The base level of a 4x4 chroma coefficient. pub base_chroma_4: [[u16; 5]; 42], /// The last coefficient's base level, for a 16x16 luma transform. pub base_eob_luma_16: [[u16; 4]; 4], /// The same, for an 8x8 luma transform. pub base_eob_luma_8: [[u16; 4]; 4], /// The same, for a 4x4 luma transform. pub base_eob_luma_4: [[u16; 4]; 4], /// The same, for an 8x8 chroma transform. pub base_eob_chroma_8: [[u16; 4]; 4], /// The same, for a 4x4 chroma transform. pub base_eob_chroma_4: [[u16; 4]; 4], /// The base-range tail of a 16x16 luma coefficient. pub br_luma_16: [[u16; 5]; 21], /// The base-range tail of an 8x8 luma coefficient. pub br_luma_8: [[u16; 5]; 21], /// The base-range tail of a 4x4 luma coefficient. pub br_luma_4: [[u16; 5]; 21], /// The base-range tail of an 8x8 chroma coefficient. pub br_chroma_8: [[u16; 5]; 21], /// The base-range tail of a 4x4 chroma coefficient. pub br_chroma_4: [[u16; 5]; 21], /// The partition symbol of a 16x16 block. pub partition_w16: [[u16; 11]; 4], /// The partition symbol of an 8x8 block (lane-av1-rect): only /// `PARTITION_NONE` is ever coded against it, but the alphabet still /// adapts on every read, same as every other partition table. pub partition_w8: [[u16; 5]; 4], /// The same as `txb_skip_luma_16`'s 7 contexts, for a 32x32 luma transform. pub txb_skip_luma_32: [[u16; 3]; 7], /// The same, for a 64x64 luma transform. pub txb_skip_luma_64: [[u16; 3]; 7], /// The all-zero flag of a 16x16 chroma transform. pub txb_skip_chroma_16: [[u16; 3]; 3], /// The all-zero flag of a 32x32 chroma transform. /// SIX contexts, not three: rows 0..3 are libaom's `txb_skip_ctx` 7..9 /// (chroma transform == its plane block) and rows 3..6 its 10..12 (plane /// block larger, i.e. a 128x128 block's four TX_32X32 chroma units). pub txb_skip_chroma_32: [[u16; 3]; 6], /// The end-of-block group of a luma transform of 1024 positions. pub eob_pt_1024_luma: [u16; 12], /// The same, for chroma. pub eob_pt_1024_chroma: [u16; 12], /// The end-of-block group of a 16x16 chroma transform. pub eob_pt_256_chroma: [u16; 10], /// The end-of-block group of a true 32x16/16x32 rect luma transform /// (lane-rectwire), see [`TxbSet::LumaRect32x16`]. pub eob_pt_512_luma: [u16; 11], /// The end-of-block group of a true 16x8/8x16 rect chroma transform /// (lane-rectwire), see [`TxbSet::ChromaRect16x8`]. pub eob_pt_128_chroma: [u16; 9], /// The end-of-block group of a true 32x16/16x32 rect CHROMA transform /// (lane-sbpart), see [`TxbSet::ChromaRect32x16`]. pub eob_pt_512_chroma: [u16; 11], /// The end-of-block group of a true 16x8/8x16 rect LUMA transform /// (lane-rectx), see [`TxbSet::LumaRect16x8`]. pub eob_pt_128_luma: [u16; 9], /// The end-of-block group of a true 8x4/4x8 rect CHROMA transform /// (lane-rectx), see [`TxbSet::ChromaRect8x4`]. pub eob_pt_32_chroma: [u16; 7], /// The end-of-block offset bit, per table set. pub eob_extra_luma_32: [[u16; 3]; 9], /// The same, for a 64x64 luma transform. pub eob_extra_luma_64: [[u16; 3]; 9], /// The same, for a 16x16 chroma transform. pub eob_extra_chroma_16: [[u16; 3]; 9], /// The same, for a 32x32 chroma transform. pub eob_extra_chroma_32: [[u16; 3]; 9], /// The base level of a 32x32 luma coefficient. pub base_luma_32: [[u16; 5]; 42], /// The base level of a 64x64 luma coefficient. pub base_luma_64: [[u16; 5]; 42], /// The base level of a 16x16 chroma coefficient. pub base_chroma_16: [[u16; 5]; 42], /// The base level of a 32x32 chroma coefficient. pub base_chroma_32: [[u16; 5]; 42], /// The last coefficient's base level, per table set. pub base_eob_luma_32: [[u16; 4]; 4], /// The same, for a 64x64 luma transform. pub base_eob_luma_64: [[u16; 4]; 4], /// The same, for a 16x16 chroma transform. pub base_eob_chroma_16: [[u16; 4]; 4], /// The same, for a 32x32 chroma transform. pub base_eob_chroma_32: [[u16; 4]; 4], /// The base-range tail of a luma coefficient, which a 64x64 transform /// reads too because its index is clamped at the 32x32 size. pub br_luma_32: [[u16; 5]; 21], /// The base-range tail of a 16x16 chroma coefficient. pub br_chroma_16: [[u16; 5]; 21], /// The base-range tail of a 32x32 chroma coefficient. pub br_chroma_32: [[u16; 5]; 21], /// The DC sign of a luma coefficient, shared by both luma sets. pub dc_sign_luma: [[u16; 3]; 3], /// The transform type of a 16x16 intra luma transform, by luma mode. pub intra_tx_type_16: [[u16; 6]; 13], /// The transform type of an 8x8 intra luma transform, by luma mode. pub intra_tx_type_8: [[u16; 6]; 13], /// The transform type of an 8x8 intra luma transform, by luma mode, when /// `reduced_tx_set` is false (spec `TX_SET_INTRA_1`, seven types) -- /// [`Self::intra_tx_type_8`]'s five-type table is only the /// `reduced_tx_set` row (round 8: a real `aomenc` stream with /// `reduced_tx_set` off desyncs an 8x8 TU read against this row's /// wrong-length CDF). pub intra_tx_type_8_set1: [[u16; 8]; 13], /// The transform type of a 4x4 intra luma transform, by luma mode /// (lane-av1tx4): the flat five-symbol `reduced_tx_set` row, byte- /// identical to [`Self::intra_tx_type_8`]'s own table /// ([`cdf::INTRA_TX_TYPE_SET2_8`]) -- libaom leaves `TX_4X4` at the same /// uniform default. pub intra_tx_type_4: [[u16; 6]; 13], /// [`Self::intra_tx_type_4`]'s `reduced_tx_set: false` counterpart, same /// split as [`Self::intra_tx_type_8_set1`]. pub intra_tx_type_4_set1: [[u16; 8]; 13], /// The transform type of an `is_inter` 32x32 luma transform (spec /// `TX_SET_INTER_3`, `TX_32X32` row) -- unlike the intra 16x16 table, it /// is not indexed by mode. pub inter_tx_type_32: [u16; 3], /// The transform type of an `is_inter` 16x16 luma transform under /// `reduced_tx_set` (spec `TX_SET_INTER_3`, `TX_16X16` row) -- not /// indexed by mode, same as [`Self::inter_tx_type_32`]. pub inter_tx_type_16: [u16; 3], /// The transform type of an `is_inter` 8x8 luma transform under /// `reduced_tx_set` (spec `TX_SET_INTER_3`, `TX_8X8` row) -- not indexed /// by mode, same as [`Self::inter_tx_type_32`] (lane-av1inter8). pub inter_tx_type_8: [u16; 3], /// [`Self::inter_tx_type_16`]'s `reduced_tx_set: false` counterpart /// (lane-cdffwd2): the twelve-symbol `EXT_TX_SET_DTT9_IDTX_1DDCT` row, /// not indexed by mode. pub inter_tx_type_16_set2: [u16; 13], /// [`Self::inter_tx_type_8`]'s `reduced_tx_set: false` counterpart /// (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` row, not /// indexed by mode. pub inter_tx_type_8_set1: [u16; 17], /// The 4x4 counterparts of [`Self::inter_tx_type_8`]/ /// [`Self::inter_tx_type_8_set1`] (lane-txselect). pub inter_tx_type_4: [u16; 3], /// See [`Self::inter_tx_type_4`]. pub inter_tx_type_4_set1: [u16; 17], /// The DC sign of a chroma coefficient, shared by both chroma sets. pub dc_sign_chroma: [[u16; 3]; 3], /// Whether an inter frame's block is coded as intra. pub intra_inter: [[u16; 3]; 4], /// The six binary decisions of an inter block's single reference frame. pub single_ref: [[[u16; 3]; 6]; 3], /// Whether a block reads `SINGLE_REFERENCE` or `COMPOUND_REFERENCE` /// (lane-av1comp, spec 5.11.25's `comp_mode`). pub comp_mode: [[u16; 3]; 5], /// Whether a block reads `skip_mode` (lane-av1comp, spec 5.11.29's /// `skip_mode`), indexed by `av1_get_skip_mode_context`. pub skip_mode: [[u16; 3]; 3], /// `use_obmc` (spec 5.11.24's `read_motion_mode`, the `OBMC_CAUSAL`-vs- /// `SIMPLE_TRANSLATION` two-symbol alphabet libaom's `obmc_cdf` reads /// whenever `motion_mode_allowed` can't offer `WARPED_CAUSAL` -- /// lane-motionmode round 1 only reaches this arm, never the three-way /// `motion_mode_cdf`), indexed by this block's own square bsize: 0 = /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- /// this decoder only ever codes those four square sizes). pub obmc: [[u16; 3]; 17], /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. /// lane-warp round 1. pub motion_mode: [[u16; 4]; 17], /// `interintra`, indexed by `size_group_lookup[bsize]` -- see /// `cdf::INTERINTRA`'s own doc. pub interintra: [[u16; 3]; 4], /// `interintra_mode` (II_DC/II_V/II_H/II_SMOOTH), same size-group /// indexing -- see `cdf::INTERINTRA_MODE` (lane-interintra r1). pub interintra_mode: [[u16; 5]; 4], /// `wedge_interintra`, indexed by bsize over `BLOCK_SIZES_ALL` -- see /// `cdf::WEDGE_INTERINTRA` (lane-interintra r1). pub wedge_interintra: [[u16; 3]; 22], /// `compound_type` (`COMPOUND_WEDGE` vs `COMPOUND_DIFFWTD`), indexed by /// bsize over `BLOCK_SIZES_ALL` -- see `cdf::COMPOUND_TYPE` /// (lane-maskcomp). pub compound_type: [[u16; 3]; 22], /// `wedge_index` (16-ary), indexed by bsize over `BLOCK_SIZES_ALL` -- /// see `cdf::WEDGE_IDX` (lane-maskcomp). pub wedge_idx: [[u16; 17]; 22], /// Which of the eight `INTER_COMPOUND_MODES` a `COMPOUND_REFERENCE` /// block takes (lane-av1comp, spec 5.11.24's `compound_mode`). pub inter_compound_mode: [[u16; 9]; 8], /// Unidirectional vs. bidirectional compound reference pair /// (lane-av1comp, spec 5.11.25's `comp_reference_type`). pub comp_ref_type: [[u16; 3]; 5], /// The three binary decisions of a unidirectional compound pair. pub uni_comp_ref: [[[u16; 3]; 3]; 3], /// The three binary decisions of a bidirectional pair's forward ref. pub comp_ref: [[[u16; 3]; 3]; 3], /// The two binary decisions of a bidirectional pair's backward ref. pub comp_bwdref: [[[u16; 3]; 2]; 3], /// Whether a compound block's `comp_group_idx` picks masked compound /// (lane-av1comp, spec 5.11.25's `comp_group_idx`). pub comp_group_idx: [[u16; 3]; 6], /// Whether a compound block's `compound_idx` picks the simple average /// over the distance-weighted blend (lane-av1comp, spec 5.11.25's /// `compound_idx`). pub compound_idx: [[u16; 3]; 6], /// The luma mode of an inter frame's intra block, by its size group. pub y_mode: [[u16; 14]; 4], /// Whether an inter block codes its motion vector explicitly. pub new_mv: [[u16; 3]; 6], /// Whether an inter block's motion vector is the zero vector. pub zero_mv: [[u16; 3]; 2], /// Which reference motion vector candidate an inter block takes. pub ref_mv: [[u16; 3]; 6], /// The dynamic reference list index of a motion vector prediction. pub drl_mode: [[u16; 3]; 3], /// A motion vector's joint (which components change), shared by both /// components since it is read once per vector, not once per component. pub mv_joint: [u16; 5], /// The two motion vector components' own tables: separate owned state, /// since spec 8.3.2 adapts one component without touching the other. pub mv_comp: [MvComponentCdfs; 2], /// libaom's `ndvc` (`av1_init_mv_probs`): the block-vector MV context an /// intrabc block reads (spec's `MV_INTRABC_CONTEXT`). Same spec-8.4 /// defaults as [`Self::mv_joint`]/[`Self::mv_comp`], separate adaptation. pub dv_joint: [u16; 5], /// [`Self::dv_joint`]'s per-component half. pub dv_comp: [MvComponentCdfs; 2], /// The `use_filter_intra` flag, indexed by block-size class (`[0]`=4x4, /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32, /// `[6]`=16x8, `[7]`=8x16, `[8]`=4x8, `[9]`=8x4, `[10]`=32x8, `[11]`=8x32) -- /// see [`cdf::FILTER_INTRA`]. pub filter_intra: [[u16; 3]; 14], /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. pub filter_intra_mode: [u16; 6], /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` /// (0..=2) -- see [`cdf::TX_SIZE_CAT0`]. pub tx_size_cat0: [[u16; 3]; 3], /// `tx_depth` at a 16x16 block -- see [`cdf::TX_SIZE_CAT1`]. pub tx_size_cat1: [[u16; 4]; 3], /// `tx_depth` at a 32x32 block -- see [`cdf::TX_SIZE_CAT2`]. pub tx_size_cat2: [[u16; 4]; 3], /// `tx_depth` at a 64x64 block -- see [`cdf::TX_SIZE_CAT3`]. pub tx_size_cat3: [[u16; 4]; 3], /// A `SWITCHABLE`-filter inter block's own `interp_filter[dir]` -- see /// [`cdf::SWITCHABLE_INTERP`]. pub switchable_interp: [[u16; 4]; 16], /// A `DC_PRED` block's own palette-use flag -- see [`cdf::PALETTE_Y_MODE`]. pub palette_y_mode: [[[u16; 3]; 3]; 7], /// A palette block's own size (2..=8) -- see [`cdf::PALETTE_Y_SIZE`]. pub palette_y_size: [[u16; 8]; 7], /// A `UV_DC_PRED` block's own chroma palette-use flag -- see /// [`cdf::PALETTE_UV_MODE`]. pub palette_uv_mode: [[u16; 3]; 2], /// A chroma palette block's own size -- see [`cdf::PALETTE_UV_SIZE`]. pub palette_uv_size: [[u16; 8]; 7], /// A palette-Y block's per-pixel colour-index symbol -- see /// [`cdf::PALETTE_Y_COLOR_INDEX`]. pub palette_y_color_index: [[[u16; 9]; 5]; 7], /// A palette-UV block's per-pixel colour-index symbol -- see /// [`cdf::PALETTE_UV_COLOR_INDEX`]. pub palette_uv_color_index: [[[u16; 9]; 5]; 7], /// The `use_intrabc` flag -- see [`cdf::INTRABC`]. pub intrabc: [u16; 3], /// A `RESTORE_WIENER`-plane LR unit's `use_wiener` flag -- see /// [`cdf::RESTORE_WIENER`]. pub restore_wiener: [u16; 3], /// A `RESTORE_SGRPROJ`-plane LR unit's `use_sgrproj` flag -- see /// [`cdf::RESTORE_SGRPROJ`]. pub restore_sgrproj: [u16; 3], /// A `RESTORE_SWITCHABLE`-plane LR unit's `restoration_type` -- see /// [`cdf::RESTORE_SWITCHABLE`]. pub restore_switchable: [u16; 4], /// `segment_id` (lane-seg, spec 5.11.8) -- see [`cdf::SEGMENT_ID`]. pub segment_id: [[u16; 9]; 3], /// `seg_id_predicted` (lane-seg, spec 5.11.9) -- see [`cdf::SEGMENT_PRED`]. pub segment_pred: [[u16; 3]; 3], /// `delta_q_abs` (lane-realworld r4, spec 5.11.10) -- see [`cdf::DELTA_Q`]. pub delta_q: [u16; 5], /// `delta_lf_abs`, the single-value form (spec 5.11.11) -- see /// [`cdf::DELTA_LF`]. Currently unread: `delta_lf_present` still refuses /// by name in `stream.rs` (the deblocker has no per-block carrier for /// the result yet), kept here so the struct is ready for that round. pub delta_lf: [u16; 5], /// `delta_lf_abs[i]`, the `delta_lf_multi` per-plane/direction form /// (`FRAME_LF_COUNT = 4`) -- same unread status as [`Self::delta_lf`]. pub delta_lf_multi: [[u16; 5]; 4], } /// One motion vector component's adapting state (spec 9.4's `Default_Mv_*`, /// held once per component so that adapting one leaves the other alone). #[derive(Clone)] pub(crate) struct MvComponentCdfs { /// The magnitude class. pub class: [u16; 12], /// The integer bit of a small-class magnitude. pub class0_bit: [u16; 3], /// The fractional part of a small-class magnitude, by its integer bit. pub class0_fr: [[u16; 5]; 2], /// The half-pel bit of a small-class magnitude (spec `mv_class0_hp`), /// read only when the frame header sets `allow_high_precision_mv` (a /// real encoder's choice, not this crate's own writer's -- which always /// leaves the flag off and so never needs this table, but a foreign /// stream this decoder reads can set it per frame). pub class0_hp: [u16; 3], /// One bit of an above-small-class magnitude, by its position. pub bit: [[u16; 3]; 10], /// The fractional part of an above-small-class magnitude. pub fr: [u16; 5], /// The half-pel bit of an above-small-class magnitude (spec `mv_hp`), /// same `allow_high_precision_mv` gating as [`Self::class0_hp`]. pub hp: [u16; 3], /// The component's sign. pub sign: [u16; 3], } impl MvComponentCdfs { fn new() -> MvComponentCdfs { MvComponentCdfs { class: cdf::MV_CLASS, class0_bit: cdf::MV_CLASS0_BIT, class0_fr: cdf::MV_CLASS0_FR, class0_hp: cdf::MV_CLASS0_HP, bit: cdf::MV_BIT, fr: cdf::MV_FR, hp: cdf::MV_HP, sign: cdf::MV_SIGN, } } } /// Picks one of the four q-context variants of a coefficient table /// (`crate::cdf`'s `_Q0`/`_Q1`/plain/`_Q3` constants), `q_ctx` already reduced /// to 0..=3 by the caller. pub(crate) fn pick(q_ctx: usize, q0: T, q1: T, q2: T, q3: T) -> T { match q_ctx { 0 => q0, 1 => q1, 2 => q2, _ => q3, } } /// `reset_cdf_symbol_counter` (spec 7.20's `save_cdfs`, libaom /// `av1_reset_cdf_symbol_counters`, `entropy.c`): every adapting table's last /// entry is a symbol counter that slows [`update_cdf`](crate::msac)'s rate /// down for a table's first 32 observations. A tile decoded with /// `disable_frame_end_update_cdf == false` saves its *adapted* table into the /// reference slots the frame refreshes, but the counters go back to zero /// first -- forwarding the raw counts (this crate's bug until it was found: /// the counts climbed unchecked, so every table forwarded across two or more /// frames adapted *faster* than the real decoder's, a divergence too small to /// flip any one symbol in a single hop but compounding into a visible /// mismatch by the third). fn reset1(a: &mut [u16; N]) { a[N - 1] = 0; } fn reset2(a: &mut [[u16; N]; M]) { a.iter_mut().for_each(reset1); } fn reset3(a: &mut [[[u16; N]; M]; K]) { a.iter_mut().for_each(reset2); } /// [`reset3`] for a table whose ALPHABET grows with its first index: the /// palette colour-index CDFs are `[u16; 9]` rows read as `[..=n]` with /// `n = idx + 2`, so their symbol counter sits at index `n`, not `N - 1`. fn reset_var_alphabet( a: &mut [[[u16; N]; M]; K], ) { for (idx, rows) in a.iter_mut().enumerate() { for row in rows.iter_mut() { row[idx + 2] = 0; } } } impl MvComponentCdfs { fn reset_counts(&mut self) { reset1(&mut self.class); reset1(&mut self.class0_bit); reset2(&mut self.class0_fr); reset1(&mut self.class0_hp); reset2(&mut self.bit); reset1(&mut self.fr); reset1(&mut self.hp); reset1(&mut self.sign); } } impl Cdfs { /// Zeroes every table's symbol counter (its last entry), leaving the /// probabilities themselves untouched -- spec 7.20's `save_cdfs`. Call /// this on the tile's own end-of-tile adapted state before storing it /// into a reference slot for cross-frame forwarding; never on a table /// still being read within the same tile. pub(crate) fn reset_counts(&mut self) { reset2(&mut self.partition_w128); reset2(&mut self.partition_w64); reset2(&mut self.partition_w32); reset2(&mut self.txfm_partition); reset2(&mut self.skip); reset3(&mut self.kf_y_mode); reset2(&mut self.uv_mode_no_cfl); reset2(&mut self.uv_mode_cfl); reset1(&mut self.cfl_sign); reset2(&mut self.cfl_alpha); reset2(&mut self.angle_delta); reset2(&mut self.txb_skip_luma_16); reset2(&mut self.txb_skip_luma_8); reset2(&mut self.txb_skip_luma_4); reset2(&mut self.txb_skip_chroma_8); reset2(&mut self.txb_skip_chroma_4); reset1(&mut self.eob_pt_256_luma); reset1(&mut self.eob_pt_64_luma); reset1(&mut self.eob_pt_64_chroma); reset1(&mut self.eob_pt_16_chroma); reset1(&mut self.eob_pt_16_luma); reset1(&mut self.eob_pt_16_luma_class1); reset1(&mut self.eob_pt_64_luma_class1); reset1(&mut self.eob_pt_16_chroma_class1); reset1(&mut self.eob_pt_64_chroma_class1); reset1(&mut self.eob_pt_128_chroma_class1); reset1(&mut self.eob_pt_128_luma_class1); reset1(&mut self.eob_pt_32_chroma_class1); reset1(&mut self.eob_pt_256_luma_class1); reset1(&mut self.eob_pt_256_chroma_class1); reset1(&mut self.eob_pt_512_luma_class1); reset1(&mut self.eob_pt_512_chroma_class1); reset1(&mut self.eob_pt_1024_luma_class1); reset1(&mut self.eob_pt_1024_chroma_class1); reset1(&mut self.eob_pt_32_luma); reset1(&mut self.eob_pt_32_luma_class1); reset2(&mut self.eob_extra_luma_16); reset2(&mut self.eob_extra_luma_8); reset2(&mut self.eob_extra_luma_4); reset2(&mut self.eob_extra_chroma_8); reset2(&mut self.eob_extra_chroma_4); reset2(&mut self.base_luma_16); reset2(&mut self.base_luma_8); reset2(&mut self.base_luma_4); reset2(&mut self.base_chroma_8); reset2(&mut self.base_chroma_4); reset2(&mut self.base_eob_luma_16); reset2(&mut self.base_eob_luma_8); reset2(&mut self.base_eob_luma_4); reset2(&mut self.base_eob_chroma_8); reset2(&mut self.base_eob_chroma_4); reset2(&mut self.br_luma_16); reset2(&mut self.br_luma_8); reset2(&mut self.br_luma_4); reset2(&mut self.br_chroma_8); reset2(&mut self.br_chroma_4); reset2(&mut self.partition_w16); reset2(&mut self.partition_w8); reset2(&mut self.txb_skip_luma_32); reset2(&mut self.txb_skip_luma_64); reset2(&mut self.txb_skip_chroma_16); reset2(&mut self.txb_skip_chroma_32); reset1(&mut self.eob_pt_1024_luma); reset1(&mut self.eob_pt_1024_chroma); reset1(&mut self.eob_pt_256_chroma); reset1(&mut self.eob_pt_512_luma); reset1(&mut self.eob_pt_128_chroma); reset1(&mut self.eob_pt_512_chroma); reset1(&mut self.eob_pt_128_luma); reset1(&mut self.eob_pt_32_chroma); reset2(&mut self.eob_extra_luma_32); reset2(&mut self.eob_extra_luma_64); reset2(&mut self.eob_extra_chroma_16); reset2(&mut self.eob_extra_chroma_32); reset2(&mut self.base_luma_32); reset2(&mut self.base_luma_64); reset2(&mut self.base_chroma_16); reset2(&mut self.base_chroma_32); reset2(&mut self.base_eob_luma_32); reset2(&mut self.base_eob_luma_64); reset2(&mut self.base_eob_chroma_16); reset2(&mut self.base_eob_chroma_32); reset2(&mut self.br_luma_32); reset2(&mut self.br_chroma_16); reset2(&mut self.br_chroma_32); reset2(&mut self.dc_sign_luma); reset2(&mut self.intra_tx_type_16); reset2(&mut self.intra_tx_type_8); reset2(&mut self.intra_tx_type_8_set1); reset2(&mut self.intra_tx_type_4); reset2(&mut self.intra_tx_type_4_set1); reset1(&mut self.inter_tx_type_32); reset1(&mut self.inter_tx_type_16); reset1(&mut self.inter_tx_type_8); reset1(&mut self.inter_tx_type_16_set2); reset1(&mut self.inter_tx_type_8_set1); reset1(&mut self.inter_tx_type_4); reset1(&mut self.inter_tx_type_4_set1); reset2(&mut self.dc_sign_chroma); reset2(&mut self.intra_inter); reset3(&mut self.single_ref); reset2(&mut self.comp_mode); reset2(&mut self.skip_mode); reset2(&mut self.obmc); reset2(&mut self.motion_mode); // lane-interintra r1 (ii-flake-9): the ONE table this list missed -- // an unreset counter saturates past 15 reads and slows update_cdf's // rate to >>5 while libaom (reset per frame) stays at >>4; the rows // drift a few counts apart and the gate flakes only on streams with // enough switchable-filter reads. Audit: every other Cdfs field was // covered (script-checked against the struct's field list). reset2(&mut self.switchable_interp); reset2(&mut self.interintra); reset2(&mut self.interintra_mode); reset2(&mut self.wedge_interintra); reset2(&mut self.compound_type); reset2(&mut self.wedge_idx); reset2(&mut self.inter_compound_mode); reset2(&mut self.comp_ref_type); reset3(&mut self.uni_comp_ref); reset3(&mut self.comp_ref); reset3(&mut self.comp_bwdref); reset2(&mut self.comp_group_idx); reset2(&mut self.compound_idx); reset2(&mut self.y_mode); reset2(&mut self.new_mv); reset2(&mut self.zero_mv); reset2(&mut self.ref_mv); reset2(&mut self.drl_mode); reset1(&mut self.mv_joint); reset1(&mut self.dv_joint); self.dv_comp .iter_mut() .for_each(MvComponentCdfs::reset_counts); self.mv_comp .iter_mut() .for_each(MvComponentCdfs::reset_counts); reset2(&mut self.filter_intra); reset1(&mut self.filter_intra_mode); reset2(&mut self.tx_size_cat0); reset2(&mut self.tx_size_cat1); reset2(&mut self.tx_size_cat2); reset2(&mut self.tx_size_cat3); reset3(&mut self.palette_y_mode); reset2(&mut self.palette_y_size); reset2(&mut self.palette_uv_mode); reset2(&mut self.palette_uv_size); // lane-t900 r22 (class cdf-counter-not-reset): the two colour-index // tables are the only VARIABLE-ALPHABET ones here -- the reader takes // `[..=n]` of a `[u16; 9]` row, so `update_cdf`'s symbol counter lives // at index `n` (= table index + 2), not at the array's last entry. // `reset3` zeroed slot 8, which no `n < 8` row ever uses, so every // palette colour-index row crossed a frame boundary with a SATURATED // count (32) and adapted at rate 6 where libaom, counting from 0, // adapts at rate 4: the first inter-frame palette block's map desynced // at its third colour-index symbol (witness `palette_screen_witness.obu`, // decode-order frame 3, mi(40,0), Y map (0,2)). reset_var_alphabet(&mut self.palette_y_color_index); reset_var_alphabet(&mut self.palette_uv_color_index); reset1(&mut self.intrabc); reset1(&mut self.restore_wiener); reset1(&mut self.restore_sgrproj); reset1(&mut self.restore_switchable); reset2(&mut self.segment_id); reset2(&mut self.segment_pred); reset1(&mut self.delta_q); reset1(&mut self.delta_lf); reset2(&mut self.delta_lf_multi); } /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and /// `init_non_coeff_cdfs`), for coefficient q-context `q_ctx` (0..=3, spec /// 8.3.2's `Get_Qctx`). The non-coefficient tables do not vary with the /// quantizer, so they are the same for every `q_ctx`. pub fn new(q_ctx: usize) -> Cdfs { Cdfs { partition_w128: cdf::PARTITION_W128, partition_w64: cdf::PARTITION_W64, partition_w32: cdf::PARTITION_W32, skip: cdf::SKIP, kf_y_mode: cdf::KF_Y_MODE, uv_mode_no_cfl: cdf::UV_MODE_NO_CFL, uv_mode_cfl: cdf::UV_MODE_CFL, cfl_sign: cdf::CFL_SIGN, cfl_alpha: cdf::CFL_ALPHA, angle_delta: cdf::ANGLE_DELTA, txb_skip_luma_16: pick( q_ctx, cdf::TXB_SKIP_LUMA_16_Q0_CTX, cdf::TXB_SKIP_LUMA_16_Q1_CTX, cdf::TXB_SKIP_LUMA_16_CTX, cdf::TXB_SKIP_LUMA_16_Q3_CTX, ), txb_skip_luma_8: pick( q_ctx, cdf::TXB_SKIP_LUMA_8_Q0_CTX, cdf::TXB_SKIP_LUMA_8_Q1_CTX, cdf::TXB_SKIP_LUMA_8_CTX, cdf::TXB_SKIP_LUMA_8_Q3_CTX, ), txb_skip_luma_4: pick( q_ctx, cdf::TXB_SKIP_LUMA_4_Q0_CTX, cdf::TXB_SKIP_LUMA_4_Q1_CTX, cdf::TXB_SKIP_LUMA_4_CTX, cdf::TXB_SKIP_LUMA_4_Q3_CTX, ), txb_skip_chroma_8: pick( q_ctx, cdf::TXB_SKIP_CHROMA_8_Q0, cdf::TXB_SKIP_CHROMA_8_Q1, cdf::TXB_SKIP_CHROMA_8, cdf::TXB_SKIP_CHROMA_8_Q3, ), txb_skip_chroma_4: pick( q_ctx, cdf::TXB_SKIP_CHROMA_4_Q0, cdf::TXB_SKIP_CHROMA_4_Q1, cdf::TXB_SKIP_CHROMA_4, cdf::TXB_SKIP_CHROMA_4_Q3, ), eob_pt_256_luma: pick( q_ctx, cdf::EOB_PT_256_LUMA_Q0, cdf::EOB_PT_256_LUMA_Q1, cdf::EOB_PT_256_LUMA, cdf::EOB_PT_256_LUMA_Q3, ), eob_pt_64_luma: pick( q_ctx, cdf::EOB_PT_64_LUMA_Q0, cdf::EOB_PT_64_LUMA_Q1, cdf::EOB_PT_64_LUMA, cdf::EOB_PT_64_LUMA_Q3, ), eob_pt_64_chroma: pick( q_ctx, cdf::EOB_PT_64_CHROMA_Q0, cdf::EOB_PT_64_CHROMA_Q1, cdf::EOB_PT_64_CHROMA, cdf::EOB_PT_64_CHROMA_Q3, ), eob_pt_16_chroma: pick( q_ctx, cdf::EOB_PT_16_CHROMA_Q0, cdf::EOB_PT_16_CHROMA_Q1, cdf::EOB_PT_16_CHROMA, cdf::EOB_PT_16_CHROMA_Q3, ), eob_pt_16_luma: pick( q_ctx, cdf::EOB_PT_16_LUMA_Q0, cdf::EOB_PT_16_LUMA_Q1, cdf::EOB_PT_16_LUMA, cdf::EOB_PT_16_LUMA_Q3, ), eob_pt_16_luma_class1: pick( q_ctx, cdf::EOB_PT_16_LUMA_CLASS1_Q0, cdf::EOB_PT_16_LUMA_CLASS1_Q1, cdf::EOB_PT_16_LUMA_CLASS1, cdf::EOB_PT_16_LUMA_CLASS1_Q3, ), eob_pt_32_luma: pick( q_ctx, cdf::EOB_PT_32_LUMA_Q0, cdf::EOB_PT_32_LUMA_Q1, cdf::EOB_PT_32_LUMA, cdf::EOB_PT_32_LUMA_Q3, ), eob_pt_32_luma_class1: pick( q_ctx, cdf::EOB_PT_32_LUMA_CLASS1_Q0, cdf::EOB_PT_32_LUMA_CLASS1_Q1, cdf::EOB_PT_32_LUMA_CLASS1, cdf::EOB_PT_32_LUMA_CLASS1_Q3, ), eob_pt_64_luma_class1: pick( q_ctx, cdf::EOB_PT_64_LUMA_CLASS1_Q0, cdf::EOB_PT_64_LUMA_CLASS1_Q1, cdf::EOB_PT_64_LUMA_CLASS1, cdf::EOB_PT_64_LUMA_CLASS1_Q3, ), eob_pt_16_chroma_class1: pick( q_ctx, cdf::EOB_PT_16_CHROMA_CLASS1_Q0, cdf::EOB_PT_16_CHROMA_CLASS1_Q1, cdf::EOB_PT_16_CHROMA_CLASS1, cdf::EOB_PT_16_CHROMA_CLASS1_Q3, ), eob_pt_64_chroma_class1: pick( q_ctx, cdf::EOB_PT_64_CHROMA_CLASS1_Q0, cdf::EOB_PT_64_CHROMA_CLASS1_Q1, cdf::EOB_PT_64_CHROMA_CLASS1, cdf::EOB_PT_64_CHROMA_CLASS1_Q3, ), eob_pt_128_chroma_class1: pick( q_ctx, cdf::EOB_PT_128_CHROMA_CLASS1_Q0, cdf::EOB_PT_128_CHROMA_CLASS1_Q1, cdf::EOB_PT_128_CHROMA_CLASS1, cdf::EOB_PT_128_CHROMA_CLASS1_Q3, ), eob_pt_128_luma_class1: pick( q_ctx, cdf::EOB_PT_128_LUMA_CLASS1_Q0, cdf::EOB_PT_128_LUMA_CLASS1_Q1, cdf::EOB_PT_128_LUMA_CLASS1, cdf::EOB_PT_128_LUMA_CLASS1_Q3, ), eob_pt_32_chroma_class1: pick( q_ctx, cdf::EOB_PT_32_CHROMA_CLASS1_Q0, cdf::EOB_PT_32_CHROMA_CLASS1_Q1, cdf::EOB_PT_32_CHROMA_CLASS1, cdf::EOB_PT_32_CHROMA_CLASS1_Q3, ), eob_pt_256_luma_class1: pick( q_ctx, cdf::EOB_PT_256_LUMA_CLASS1_Q0, cdf::EOB_PT_256_LUMA_CLASS1_Q1, cdf::EOB_PT_256_LUMA_CLASS1, cdf::EOB_PT_256_LUMA_CLASS1_Q3, ), eob_pt_256_chroma_class1: pick( q_ctx, cdf::EOB_PT_256_CHROMA_CLASS1_Q0, cdf::EOB_PT_256_CHROMA_CLASS1_Q1, cdf::EOB_PT_256_CHROMA_CLASS1, cdf::EOB_PT_256_CHROMA_CLASS1_Q3, ), eob_pt_512_luma_class1: pick( q_ctx, cdf::EOB_PT_512_LUMA_CLASS1_Q0, cdf::EOB_PT_512_LUMA_CLASS1_Q1, cdf::EOB_PT_512_LUMA_CLASS1, cdf::EOB_PT_512_LUMA_CLASS1_Q3, ), eob_pt_512_chroma_class1: pick( q_ctx, cdf::EOB_PT_512_CHROMA_CLASS1_Q0, cdf::EOB_PT_512_CHROMA_CLASS1_Q1, cdf::EOB_PT_512_CHROMA_CLASS1, cdf::EOB_PT_512_CHROMA_CLASS1_Q3, ), eob_pt_1024_luma_class1: pick( q_ctx, cdf::EOB_PT_1024_LUMA_CLASS1_Q0, cdf::EOB_PT_1024_LUMA_CLASS1_Q1, cdf::EOB_PT_1024_LUMA_CLASS1, cdf::EOB_PT_1024_LUMA_CLASS1_Q3, ), eob_pt_1024_chroma_class1: pick( q_ctx, cdf::EOB_PT_1024_CHROMA_CLASS1_Q0, cdf::EOB_PT_1024_CHROMA_CLASS1_Q1, cdf::EOB_PT_1024_CHROMA_CLASS1, cdf::EOB_PT_1024_CHROMA_CLASS1_Q3, ), eob_extra_luma_16: pick( q_ctx, cdf::EOB_EXTRA_LUMA_16_Q0, cdf::EOB_EXTRA_LUMA_16_Q1, cdf::EOB_EXTRA_LUMA_16, cdf::EOB_EXTRA_LUMA_16_Q3, ), eob_extra_luma_8: pick( q_ctx, cdf::EOB_EXTRA_LUMA_8_Q0, cdf::EOB_EXTRA_LUMA_8_Q1, cdf::EOB_EXTRA_LUMA_8, cdf::EOB_EXTRA_LUMA_8_Q3, ), eob_extra_luma_4: pick( q_ctx, cdf::EOB_EXTRA_LUMA_4_Q0, cdf::EOB_EXTRA_LUMA_4_Q1, cdf::EOB_EXTRA_LUMA_4, cdf::EOB_EXTRA_LUMA_4_Q3, ), eob_extra_chroma_8: pick( q_ctx, cdf::EOB_EXTRA_CHROMA_8_Q0, cdf::EOB_EXTRA_CHROMA_8_Q1, cdf::EOB_EXTRA_CHROMA_8, cdf::EOB_EXTRA_CHROMA_8_Q3, ), eob_extra_chroma_4: pick( q_ctx, cdf::EOB_EXTRA_CHROMA_4_Q0, cdf::EOB_EXTRA_CHROMA_4_Q1, cdf::EOB_EXTRA_CHROMA_4, cdf::EOB_EXTRA_CHROMA_4_Q3, ), base_luma_16: pick( q_ctx, cdf::COEFF_BASE_LUMA_16_Q0, cdf::COEFF_BASE_LUMA_16_Q1, cdf::COEFF_BASE_LUMA_16, cdf::COEFF_BASE_LUMA_16_Q3, ), base_luma_8: pick( q_ctx, cdf::COEFF_BASE_LUMA_8_Q0, cdf::COEFF_BASE_LUMA_8_Q1, cdf::COEFF_BASE_LUMA_8, cdf::COEFF_BASE_LUMA_8_Q3, ), base_luma_4: pick( q_ctx, cdf::COEFF_BASE_LUMA_4_Q0, cdf::COEFF_BASE_LUMA_4_Q1, cdf::COEFF_BASE_LUMA_4, cdf::COEFF_BASE_LUMA_4_Q3, ), base_chroma_8: pick( q_ctx, cdf::COEFF_BASE_CHROMA_8_Q0, cdf::COEFF_BASE_CHROMA_8_Q1, cdf::COEFF_BASE_CHROMA_8, cdf::COEFF_BASE_CHROMA_8_Q3, ), base_chroma_4: pick( q_ctx, cdf::COEFF_BASE_CHROMA_4_Q0, cdf::COEFF_BASE_CHROMA_4_Q1, cdf::COEFF_BASE_CHROMA_4, cdf::COEFF_BASE_CHROMA_4_Q3, ), base_eob_luma_16: pick( q_ctx, cdf::COEFF_BASE_EOB_LUMA_16_Q0, cdf::COEFF_BASE_EOB_LUMA_16_Q1, cdf::COEFF_BASE_EOB_LUMA_16, cdf::COEFF_BASE_EOB_LUMA_16_Q3, ), base_eob_luma_8: pick( q_ctx, cdf::COEFF_BASE_EOB_LUMA_8_Q0, cdf::COEFF_BASE_EOB_LUMA_8_Q1, cdf::COEFF_BASE_EOB_LUMA_8, cdf::COEFF_BASE_EOB_LUMA_8_Q3, ), base_eob_luma_4: pick( q_ctx, cdf::COEFF_BASE_EOB_LUMA_4_Q0, cdf::COEFF_BASE_EOB_LUMA_4_Q1, cdf::COEFF_BASE_EOB_LUMA_4, cdf::COEFF_BASE_EOB_LUMA_4_Q3, ), base_eob_chroma_8: pick( q_ctx, cdf::COEFF_BASE_EOB_CHROMA_8_Q0, cdf::COEFF_BASE_EOB_CHROMA_8_Q1, cdf::COEFF_BASE_EOB_CHROMA_8, cdf::COEFF_BASE_EOB_CHROMA_8_Q3, ), base_eob_chroma_4: pick( q_ctx, cdf::COEFF_BASE_EOB_CHROMA_4_Q0, cdf::COEFF_BASE_EOB_CHROMA_4_Q1, cdf::COEFF_BASE_EOB_CHROMA_4, cdf::COEFF_BASE_EOB_CHROMA_4_Q3, ), br_luma_16: pick( q_ctx, cdf::COEFF_BR_LUMA_16_Q0, cdf::COEFF_BR_LUMA_16_Q1, cdf::COEFF_BR_LUMA_16, cdf::COEFF_BR_LUMA_16_Q3, ), br_luma_8: pick( q_ctx, cdf::COEFF_BR_LUMA_8_Q0, cdf::COEFF_BR_LUMA_8_Q1, cdf::COEFF_BR_LUMA_8, cdf::COEFF_BR_LUMA_8_Q3, ), br_luma_4: pick( q_ctx, cdf::COEFF_BR_LUMA_4_Q0, cdf::COEFF_BR_LUMA_4_Q1, cdf::COEFF_BR_LUMA_4, cdf::COEFF_BR_LUMA_4_Q3, ), br_chroma_8: pick( q_ctx, cdf::COEFF_BR_CHROMA_8_Q0, cdf::COEFF_BR_CHROMA_8_Q1, cdf::COEFF_BR_CHROMA_8, cdf::COEFF_BR_CHROMA_8_Q3, ), br_chroma_4: pick( q_ctx, cdf::COEFF_BR_CHROMA_4_Q0, cdf::COEFF_BR_CHROMA_4_Q1, cdf::COEFF_BR_CHROMA_4, cdf::COEFF_BR_CHROMA_4_Q3, ), partition_w16: cdf::PARTITION_W16, partition_w8: cdf::PARTITION_W8, txb_skip_luma_32: pick( q_ctx, cdf::TXB_SKIP_LUMA_32_Q0_CTX, cdf::TXB_SKIP_LUMA_32_Q1_CTX, cdf::TXB_SKIP_LUMA_32_CTX, cdf::TXB_SKIP_LUMA_32_Q3_CTX, ), txb_skip_luma_64: pick( q_ctx, cdf::TXB_SKIP_LUMA_64_Q0_CTX, cdf::TXB_SKIP_LUMA_64_Q1_CTX, cdf::TXB_SKIP_LUMA_64_CTX, cdf::TXB_SKIP_LUMA_64_Q3_CTX, ), txb_skip_chroma_16: pick( q_ctx, cdf::TXB_SKIP_CHROMA_16_Q0, cdf::TXB_SKIP_CHROMA_16_Q1, cdf::TXB_SKIP_CHROMA_16, cdf::TXB_SKIP_CHROMA_16_Q3, ), txb_skip_chroma_32: { let small = pick( q_ctx, cdf::TXB_SKIP_CHROMA_32_Q0, cdf::TXB_SKIP_CHROMA_32_Q1, cdf::TXB_SKIP_CHROMA_32, cdf::TXB_SKIP_CHROMA_32_Q3, ); let big = pick( q_ctx, cdf::TXB_SKIP_CHROMA_32_BIG_Q0, cdf::TXB_SKIP_CHROMA_32_BIG_Q1, cdf::TXB_SKIP_CHROMA_32_BIG, cdf::TXB_SKIP_CHROMA_32_BIG_Q3, ); [small[0], small[1], small[2], big[0], big[1], big[2]] }, eob_pt_1024_luma: pick( q_ctx, cdf::EOB_PT_1024_LUMA_Q0, cdf::EOB_PT_1024_LUMA_Q1, cdf::EOB_PT_1024_LUMA, cdf::EOB_PT_1024_LUMA_Q3, ), eob_pt_1024_chroma: pick( q_ctx, cdf::EOB_PT_1024_CHROMA_Q0, cdf::EOB_PT_1024_CHROMA_Q1, cdf::EOB_PT_1024_CHROMA, cdf::EOB_PT_1024_CHROMA_Q3, ), eob_pt_256_chroma: pick( q_ctx, cdf::EOB_PT_256_CHROMA_Q0, cdf::EOB_PT_256_CHROMA_Q1, cdf::EOB_PT_256_CHROMA, cdf::EOB_PT_256_CHROMA_Q3, ), eob_pt_512_luma: pick( q_ctx, cdf::EOB_PT_512_LUMA_Q0, cdf::EOB_PT_512_LUMA_Q1, cdf::EOB_PT_512_LUMA, cdf::EOB_PT_512_LUMA_Q3, ), eob_pt_128_chroma: pick( q_ctx, cdf::EOB_PT_128_CHROMA_Q0, cdf::EOB_PT_128_CHROMA_Q1, cdf::EOB_PT_128_CHROMA, cdf::EOB_PT_128_CHROMA_Q3, ), eob_pt_128_luma: pick( q_ctx, cdf::EOB_PT_128_LUMA_Q0, cdf::EOB_PT_128_LUMA_Q1, cdf::EOB_PT_128_LUMA, cdf::EOB_PT_128_LUMA_Q3, ), eob_pt_32_chroma: pick( q_ctx, cdf::EOB_PT_32_CHROMA_Q0, cdf::EOB_PT_32_CHROMA_Q1, cdf::EOB_PT_32_CHROMA, cdf::EOB_PT_32_CHROMA_Q3, ), eob_pt_512_chroma: pick( q_ctx, cdf::EOB_PT_512_CHROMA_Q0, cdf::EOB_PT_512_CHROMA_Q1, cdf::EOB_PT_512_CHROMA, cdf::EOB_PT_512_CHROMA_Q3, ), eob_extra_luma_32: pick( q_ctx, cdf::EOB_EXTRA_LUMA_32_Q0, cdf::EOB_EXTRA_LUMA_32_Q1, cdf::EOB_EXTRA_LUMA_32, cdf::EOB_EXTRA_LUMA_32_Q3, ), eob_extra_luma_64: pick( q_ctx, cdf::EOB_EXTRA_LUMA_64_Q0, cdf::EOB_EXTRA_LUMA_64_Q1, cdf::EOB_EXTRA_LUMA_64, cdf::EOB_EXTRA_LUMA_64_Q3, ), eob_extra_chroma_16: pick( q_ctx, cdf::EOB_EXTRA_CHROMA_16_Q0, cdf::EOB_EXTRA_CHROMA_16_Q1, cdf::EOB_EXTRA_CHROMA_16, cdf::EOB_EXTRA_CHROMA_16_Q3, ), eob_extra_chroma_32: pick( q_ctx, cdf::EOB_EXTRA_CHROMA_32_Q0, cdf::EOB_EXTRA_CHROMA_32_Q1, cdf::EOB_EXTRA_CHROMA_32, cdf::EOB_EXTRA_CHROMA_32_Q3, ), base_luma_32: pick( q_ctx, cdf::COEFF_BASE_LUMA_32_Q0, cdf::COEFF_BASE_LUMA_32_Q1, cdf::COEFF_BASE_LUMA_32, cdf::COEFF_BASE_LUMA_32_Q3, ), base_luma_64: pick( q_ctx, cdf::COEFF_BASE_LUMA_64_Q0, cdf::COEFF_BASE_LUMA_64_Q1, cdf::COEFF_BASE_LUMA_64, cdf::COEFF_BASE_LUMA_64_Q3, ), base_chroma_16: pick( q_ctx, cdf::COEFF_BASE_CHROMA_16_Q0, cdf::COEFF_BASE_CHROMA_16_Q1, cdf::COEFF_BASE_CHROMA_16, cdf::COEFF_BASE_CHROMA_16_Q3, ), base_chroma_32: pick( q_ctx, cdf::COEFF_BASE_CHROMA_32_Q0, cdf::COEFF_BASE_CHROMA_32_Q1, cdf::COEFF_BASE_CHROMA_32, cdf::COEFF_BASE_CHROMA_32_Q3, ), base_eob_luma_32: pick( q_ctx, cdf::COEFF_BASE_EOB_LUMA_32_Q0, cdf::COEFF_BASE_EOB_LUMA_32_Q1, cdf::COEFF_BASE_EOB_LUMA_32, cdf::COEFF_BASE_EOB_LUMA_32_Q3, ), base_eob_luma_64: pick( q_ctx, cdf::COEFF_BASE_EOB_LUMA_64_Q0, cdf::COEFF_BASE_EOB_LUMA_64_Q1, cdf::COEFF_BASE_EOB_LUMA_64, cdf::COEFF_BASE_EOB_LUMA_64_Q3, ), base_eob_chroma_16: pick( q_ctx, cdf::COEFF_BASE_EOB_CHROMA_16_Q0, cdf::COEFF_BASE_EOB_CHROMA_16_Q1, cdf::COEFF_BASE_EOB_CHROMA_16, cdf::COEFF_BASE_EOB_CHROMA_16_Q3, ), base_eob_chroma_32: pick( q_ctx, cdf::COEFF_BASE_EOB_CHROMA_32_Q0, cdf::COEFF_BASE_EOB_CHROMA_32_Q1, cdf::COEFF_BASE_EOB_CHROMA_32, cdf::COEFF_BASE_EOB_CHROMA_32_Q3, ), br_luma_32: pick( q_ctx, cdf::COEFF_BR_LUMA_32_Q0, cdf::COEFF_BR_LUMA_32_Q1, cdf::COEFF_BR_LUMA_32, cdf::COEFF_BR_LUMA_32_Q3, ), br_chroma_16: pick( q_ctx, cdf::COEFF_BR_CHROMA_16_Q0, cdf::COEFF_BR_CHROMA_16_Q1, cdf::COEFF_BR_CHROMA_16, cdf::COEFF_BR_CHROMA_16_Q3, ), br_chroma_32: pick( q_ctx, cdf::COEFF_BR_CHROMA_32_Q0, cdf::COEFF_BR_CHROMA_32_Q1, cdf::COEFF_BR_CHROMA_32, cdf::COEFF_BR_CHROMA_32_Q3, ), dc_sign_luma: cdf::DC_SIGN_LUMA, intra_tx_type_16: cdf::INTRA_TX_TYPE_SET2_16, intra_tx_type_8: cdf::INTRA_TX_TYPE_SET2_8, intra_tx_type_8_set1: cdf::INTRA_TX_TYPE_SET1_8, intra_tx_type_4: cdf::INTRA_TX_TYPE_SET2_8, intra_tx_type_4_set1: cdf::INTRA_TX_TYPE_SET1_4, inter_tx_type_32: cdf::INTER_TX_TYPE_SET3_32, inter_tx_type_16: cdf::INTER_TX_TYPE_SET3_16, inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8, inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16, inter_tx_type_8_set1: cdf::INTER_TX_TYPE_SET1_8, inter_tx_type_4: cdf::INTER_TX_TYPE_SET3_4, inter_tx_type_4_set1: cdf::INTER_TX_TYPE_SET1_4, dc_sign_chroma: cdf::DC_SIGN_CHROMA, intra_inter: cdf::INTRA_INTER, single_ref: cdf::SINGLE_REF, comp_mode: cdf::COMP_MODE, inter_compound_mode: cdf::INTER_COMPOUND_MODE, comp_ref_type: cdf::COMP_REF_TYPE, uni_comp_ref: cdf::UNI_COMP_REF, comp_ref: cdf::COMP_REF, comp_bwdref: cdf::COMP_BWDREF, txfm_partition: cdf::TXFM_PARTITION, skip_mode: cdf::SKIP_MODE, obmc: cdf::OBMC, motion_mode: cdf::MOTION_MODE, interintra: cdf::INTERINTRA, interintra_mode: cdf::INTERINTRA_MODE, wedge_interintra: cdf::WEDGE_INTERINTRA, compound_type: cdf::COMPOUND_TYPE, wedge_idx: cdf::WEDGE_IDX, comp_group_idx: cdf::COMP_GROUP_IDX, compound_idx: cdf::COMPOUND_IDX, y_mode: cdf::Y_MODE, new_mv: cdf::NEW_MV, zero_mv: cdf::ZERO_MV, ref_mv: cdf::REF_MV, drl_mode: cdf::DRL_MODE, mv_joint: cdf::MV_JOINT, mv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], dv_joint: cdf::MV_JOINT, dv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], filter_intra: cdf::FILTER_INTRA, filter_intra_mode: cdf::FILTER_INTRA_MODE, tx_size_cat0: cdf::TX_SIZE_CAT0, tx_size_cat1: cdf::TX_SIZE_CAT1, tx_size_cat2: cdf::TX_SIZE_CAT2, tx_size_cat3: cdf::TX_SIZE_CAT3, switchable_interp: cdf::SWITCHABLE_INTERP, palette_y_mode: cdf::PALETTE_Y_MODE, palette_y_size: cdf::PALETTE_Y_SIZE, palette_uv_mode: cdf::PALETTE_UV_MODE, palette_uv_size: cdf::PALETTE_UV_SIZE, palette_y_color_index: cdf::PALETTE_Y_COLOR_INDEX, palette_uv_color_index: cdf::PALETTE_UV_COLOR_INDEX, intrabc: cdf::INTRABC, restore_wiener: cdf::RESTORE_WIENER, restore_sgrproj: cdf::RESTORE_SGRPROJ, restore_switchable: cdf::RESTORE_SWITCHABLE, segment_id: cdf::SEGMENT_ID, segment_pred: cdf::SEGMENT_PRED, delta_q: cdf::DELTA_Q, delta_lf: cdf::DELTA_LF, delta_lf_multi: [cdf::DELTA_LF; 4], } } /// The tables one table set is coded with, borrowed out of the state. pub fn txb(&mut self, set: TxbSet, mode: usize) -> TxbTables<'_> { match set { TxbSet::Luma32 => TxbTables { side: 32, txb_skip: &mut self.txb_skip_luma_32, eob_pt: &mut self.eob_pt_1024_luma, eob_extra: &mut self.eob_extra_luma_32, base: &mut self.base_luma_32, base_eob: &mut self.base_eob_luma_32, br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), }, // lane-comppin r4 (REVERTED, see r4's own commit message): // `Some(inter_tx_type_32)` looked wrong against aomdec's 32x32 // trace (degenerate 1-symbol EC_TXTYPE_VAL=0 read) and matches // spec `av1_get_ext_tx_set_type`'s `EXT_TX_SET_DCTONLY` for // every tx_size_sqr >= TX_32X32 -- but flipping this to `None` // regressed 16 previously-green `ec-av1` tests (full-suite count // went 217/217 -> 201/216), and did NOT fix the pin's own // eob_pt desync either (still reads 6 instead of aomdec's 5 // right after this read, proving eob_pt's own context/table // selection is a SEPARATE, still-unfound bug upstream of this // one) -- kept `Some` pending a real fix that ports both without // breaking the 16. TxbSet::Luma32Inter => TxbTables { side: 32, txb_skip: &mut self.txb_skip_luma_32, eob_pt: &mut self.eob_pt_1024_luma, eob_extra: &mut self.eob_extra_luma_32, base: &mut self.base_luma_32, base_eob: &mut self.base_eob_luma_32, br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_32.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), }, TxbSet::Luma64 => TxbTables { side: 32, txb_skip: &mut self.txb_skip_luma_64, eob_pt: &mut self.eob_pt_1024_luma, eob_extra: &mut self.eob_extra_luma_64, base: &mut self.base_luma_64, base_eob: &mut self.base_eob_luma_64, br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), }, TxbSet::Luma16 => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_256_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_16[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), }, TxbSet::Luma16Inter => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_256_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_16.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), }, TxbSet::Luma16InterSet1 => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_256_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_16_set2.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), }, TxbSet::Luma8 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_64_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::Luma8Set1 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_64_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::Luma4 => TxbTables { side: 4, txb_skip: &mut self.txb_skip_luma_4, eob_pt: &mut self.eob_pt_16_luma, eob_extra: &mut self.eob_extra_luma_4, base: &mut self.base_luma_4, base_eob: &mut self.base_eob_luma_4, br: &mut self.br_luma_4, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), }, TxbSet::Luma4Inter => TxbTables { side: 4, txb_skip: &mut self.txb_skip_luma_4, eob_pt: &mut self.eob_pt_16_luma, eob_extra: &mut self.eob_extra_luma_4, base: &mut self.base_luma_4, base_eob: &mut self.base_eob_luma_4, br: &mut self.br_luma_4, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_4.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), }, TxbSet::Luma4InterSet1 => TxbTables { side: 4, txb_skip: &mut self.txb_skip_luma_4, eob_pt: &mut self.eob_pt_16_luma, eob_extra: &mut self.eob_extra_luma_4, base: &mut self.base_luma_4, base_eob: &mut self.base_eob_luma_4, br: &mut self.br_luma_4, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), }, TxbSet::Luma4Set1 => TxbTables { side: 4, txb_skip: &mut self.txb_skip_luma_4, eob_pt: &mut self.eob_pt_16_luma, eob_extra: &mut self.eob_extra_luma_4, base: &mut self.base_luma_4, base_eob: &mut self.base_eob_luma_4, br: &mut self.br_luma_4, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), }, TxbSet::Luma8Inter => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_64_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_8.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::Luma8InterSet1 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_64_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_8_set1.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::Chroma8 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_chroma_8, eob_pt: &mut self.eob_pt_64_chroma, eob_extra: &mut self.eob_extra_chroma_8, base: &mut self.base_chroma_8, base_eob: &mut self.base_eob_chroma_8, br: &mut self.br_chroma_8, dc_sign: &mut self.dc_sign_chroma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_64_chroma_class1), }, TxbSet::Chroma4 => TxbTables { side: 4, txb_skip: &mut self.txb_skip_chroma_4, eob_pt: &mut self.eob_pt_16_chroma, eob_extra: &mut self.eob_extra_chroma_4, base: &mut self.base_chroma_4, base_eob: &mut self.base_eob_chroma_4, br: &mut self.br_chroma_4, dc_sign: &mut self.dc_sign_chroma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_16_chroma_class1), }, TxbSet::Chroma16 => TxbTables { side: 16, txb_skip: &mut self.txb_skip_chroma_16, eob_pt: &mut self.eob_pt_256_chroma, eob_extra: &mut self.eob_extra_chroma_16, base: &mut self.base_chroma_16, base_eob: &mut self.base_eob_chroma_16, br: &mut self.br_chroma_16, dc_sign: &mut self.dc_sign_chroma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_256_chroma_class1), }, TxbSet::Chroma32 => TxbTables { side: 32, txb_skip: &mut self.txb_skip_chroma_32, eob_pt: &mut self.eob_pt_1024_chroma, eob_extra: &mut self.eob_extra_chroma_32, base: &mut self.base_chroma_32, base_eob: &mut self.base_eob_chroma_32, br: &mut self.br_chroma_32, dc_sign: &mut self.dc_sign_chroma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_1024_chroma_class1), }, TxbSet::LumaRect32x8Inter => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_256_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_8.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), }, TxbSet::LumaRect32x8 => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_256_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), }, TxbSet::LumaRect32x16Inter => TxbTables { side: 32, txb_skip: &mut self.txb_skip_luma_32, eob_pt: &mut self.eob_pt_512_luma, eob_extra: &mut self.eob_extra_luma_32, base: &mut self.base_luma_32, base_eob: &mut self.base_eob_luma_32, br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_16.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_512_luma_class1), }, TxbSet::LumaRect32x16 => TxbTables { side: 32, txb_skip: &mut self.txb_skip_luma_32, eob_pt: &mut self.eob_pt_512_luma, eob_extra: &mut self.eob_extra_luma_32, base: &mut self.base_luma_32, base_eob: &mut self.base_eob_luma_32, br: &mut self.br_luma_32, dc_sign: &mut self.dc_sign_luma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_512_luma_class1), }, TxbSet::ChromaRect16x8 => TxbTables { side: 16, txb_skip: &mut self.txb_skip_chroma_16, eob_pt: &mut self.eob_pt_128_chroma, eob_extra: &mut self.eob_extra_chroma_16, base: &mut self.base_chroma_16, base_eob: &mut self.base_eob_chroma_16, br: &mut self.br_chroma_16, dc_sign: &mut self.dc_sign_chroma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_128_chroma_class1), }, TxbSet::LumaRect4x8 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_32_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), }, TxbSet::LumaRect8x4Inter => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_32_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_4.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), }, TxbSet::LumaRect8x4InterSet1 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_32_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), }, TxbSet::LumaRect4x8Set1 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_32_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), }, TxbSet::ChromaRect32x16 => TxbTables { side: 32, txb_skip: &mut self.txb_skip_chroma_32, eob_pt: &mut self.eob_pt_512_chroma, eob_extra: &mut self.eob_extra_chroma_32, base: &mut self.base_chroma_32, base_eob: &mut self.base_eob_chroma_32, br: &mut self.br_chroma_32, dc_sign: &mut self.dc_sign_chroma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_512_chroma_class1), }, TxbSet::LumaRect16x8 => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_128_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), }, TxbSet::LumaRect16x8Set1 => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_128_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), }, TxbSet::LumaRect16x4 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_64_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::LumaRect16x4Set1 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_64_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::LumaRect16x4Inter => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_64_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_4.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::LumaRect16x4Inter1 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_luma_8, eob_pt: &mut self.eob_pt_64_luma, eob_extra: &mut self.eob_extra_luma_8, base: &mut self.base_luma_8, base_eob: &mut self.base_eob_luma_8, br: &mut self.br_luma_8, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), }, TxbSet::LumaRect16x8Inter => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_128_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_8.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), }, TxbSet::LumaRect16x8InterSet1 => TxbTables { side: 16, txb_skip: &mut self.txb_skip_luma_16, eob_pt: &mut self.eob_pt_128_luma, eob_extra: &mut self.eob_extra_luma_16, base: &mut self.base_luma_16, base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, tx_type: Some(self.inter_tx_type_8_set1.as_mut_slice()), eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), }, TxbSet::ChromaRect8x4 => TxbTables { side: 8, txb_skip: &mut self.txb_skip_chroma_8, eob_pt: &mut self.eob_pt_32_chroma, eob_extra: &mut self.eob_extra_chroma_8, base: &mut self.base_chroma_8, base_eob: &mut self.base_eob_chroma_8, br: &mut self.br_chroma_8, dc_sign: &mut self.dc_sign_chroma, tx_type: None, eob_pt_class1: Some(&mut self.eob_pt_32_chroma_class1), }, } } } #[cfg(test)] mod tests { use super::*; /// A 64x64 luma transform reads the 32x32 base-range rows, so the two sets /// have to adapt the same table: a decoder keeps one copy, and an encoder /// that kept two would drift away from it the first time a level above two /// was coded. #[test] fn the_two_luma_sets_share_the_base_range_table() { let mut cdfs = Cdfs::new(2); cdfs.txb(TxbSet::Luma64, 0).br[0][0] = 1; assert_eq!(cdfs.txb(TxbSet::Luma32, 0).br[0][0], 1); } /// Both luma sets read one DC sign table, and both chroma sets another; /// what a luma block adapts must not reach the chroma one. #[test] fn the_sign_tables_are_shared_within_a_plane_type_and_not_across() { let mut cdfs = Cdfs::new(2); cdfs.txb(TxbSet::Luma32, 0).dc_sign[1][0] = 1; cdfs.txb(TxbSet::Chroma16, 0).dc_sign[2][0] = 2; assert_eq!(cdfs.txb(TxbSet::Luma64, 0).dc_sign[1][0], 1); assert_eq!(cdfs.txb(TxbSet::Chroma32, 0).dc_sign[2][0], 2); assert_ne!(cdfs.txb(TxbSet::Chroma32, 0).dc_sign[1][0], 1); assert_ne!(cdfs.txb(TxbSet::Luma64, 0).dc_sign[2][0], 2); } /// The end-of-block table a 1024-position transform reads is shared by both /// luma sets and separate from chroma's, which is the same hazard one table /// further along. #[test] fn the_luma_end_of_block_table_is_shared_and_chromas_is_not() { let mut cdfs = Cdfs::new(2); cdfs.txb(TxbSet::Luma32, 0).eob_pt[0] = 7; assert_eq!(cdfs.txb(TxbSet::Luma64, 0).eob_pt[0], 7); assert_ne!(cdfs.txb(TxbSet::Chroma32, 0).eob_pt[0], 7); } /// Every set starts from the spec's defaults, so a tile that adapts nothing /// writes exactly what a non-adapting one does. #[test] fn the_state_starts_at_the_defaults() { let mut cdfs = Cdfs::new(2); assert_eq!( cdfs.txb(TxbSet::Luma32, 0).base[3], cdf::COEFF_BASE_LUMA_32[3] ); assert_eq!( cdfs.txb(TxbSet::Chroma16, 0).eob_extra[2], cdf::EOB_EXTRA_CHROMA_16[2] ); assert_eq!(cdfs.partition_w64[2], cdf::PARTITION_W64[2]); assert_eq!(cdfs.intra_inter, cdf::INTRA_INTER); assert_eq!(cdfs.single_ref, cdf::SINGLE_REF); assert_eq!(cdfs.comp_mode, cdf::COMP_MODE); assert_eq!(cdfs.inter_compound_mode, cdf::INTER_COMPOUND_MODE); assert_eq!(cdfs.comp_ref_type, cdf::COMP_REF_TYPE); assert_eq!(cdfs.uni_comp_ref, cdf::UNI_COMP_REF); assert_eq!(cdfs.comp_ref, cdf::COMP_REF); assert_eq!(cdfs.comp_bwdref, cdf::COMP_BWDREF); assert_eq!(cdfs.y_mode, cdf::Y_MODE); assert_eq!(cdfs.new_mv, cdf::NEW_MV); assert_eq!(cdfs.zero_mv, cdf::ZERO_MV); assert_eq!(cdfs.ref_mv, cdf::REF_MV); assert_eq!(cdfs.drl_mode, cdf::DRL_MODE); assert_eq!(cdfs.mv_joint, cdf::MV_JOINT); assert_eq!(cdfs.mv_comp[0].class, cdf::MV_CLASS); assert_eq!(cdfs.mv_comp[1].sign, cdf::MV_SIGN); } /// A motion vector's two components are separate owned tables: adapting /// one component's CDFs must not be visible through the other, the same /// hazard the coefficient sets guard against above. #[test] fn the_mv_components_are_separate_and_do_not_share_adaptation() { let mut cdfs = Cdfs::new(2); cdfs.mv_comp[0].class[0] = 1; cdfs.mv_comp[0].bit[3][0] = 2; assert_ne!(cdfs.mv_comp[1].class[0], 1); assert_ne!(cdfs.mv_comp[1].bit[3][0], 2); assert_eq!(cdfs.mv_comp[1].class[0], cdf::MV_CLASS[0]); assert_eq!(cdfs.mv_comp[1].bit[3][0], cdf::MV_BIT[3][0]); } }