edith_codecs
Clone
https://git.tahinli.com/Tahinli/edith_codecs.git
0 watching·0 forks·Rust·370.3 MiB·00c1b3f·Tahinli·2 months ago·1999 commits
| 1 | //! The CDFs a tile adapts as it is written. |
| 2 | //! |
| 3 | //! AV1's symbol decoder updates every non-literal CDF it reads (spec 8.3.2), |
| 4 | //! so an encoder that wants `disable_cdf_update` off has to keep the same |
| 5 | //! state and update it in the same order. What lives here is that state: one |
| 6 | //! owned copy of each table the tile writer touches, seeded from the defaults |
| 7 | //! in [`crate::cdf`]. |
| 8 | //! |
| 9 | //! The tables are owned once, not once per use: two coefficient table sets |
| 10 | //! that share a table -- a 64x64 luma transform reads the 32x32 base-range |
| 11 | //! rows, and both luma sets read the same DC sign table -- share the *adapted* |
| 12 | //! table too, which is what the decoder does. |
| 13 | |
| 14 | use crate::cdf; |
| 15 | |
| 16 | /// Which of the four coefficient table sets a transform block is coded with. |
| 17 | #[derive(Clone, Copy)] |
| 18 | pub(crate) enum TxbSet { |
| 19 | /// The 32x32 luma transform of an intra 32x32 block. `get_tx_set` is |
| 20 | /// DCT-only at this size for an intra block, so no `tx_type` symbol is |
| 21 | /// coded; an `is_inter` 32x32 block reads a different set and uses |
| 22 | /// [`Luma32Inter`](TxbSet::Luma32Inter) instead. |
| 23 | Luma32, |
| 24 | /// The 32x32 luma transform of an `is_inter` 32x32 block: the same |
| 25 | /// coefficient tables [`Luma32`](TxbSet::Luma32) reads, but `get_tx_set` |
| 26 | /// (spec 5.11.48) returns `TX_SET_INTER_3` rather than `TX_SET_DCTONLY` |
| 27 | /// at this size for an inter block, so this variant carries the |
| 28 | /// `tx_type` symbol `Luma32` does not. |
| 29 | Luma32Inter, |
| 30 | /// The 64x64 luma transform of a whole superblock, scanned as a 32x32. |
| 31 | Luma64, |
| 32 | /// The 16x16 luma transform of a 16x16 block. |
| 33 | Luma16, |
| 34 | /// The 16x16 luma transform of an `is_inter` 16x16 block, coded under |
| 35 | /// `reduced_tx_set` (see [`crate::cdf::INTER_TX_TYPE_SET3_16`]'s doc |
| 36 | /// comment): the same coefficient tables [`Luma16`](TxbSet::Luma16) |
| 37 | /// reads, but its own two-symbol `tx_type` table rather than `Luma16`'s |
| 38 | /// five-symbol, mode-indexed one. |
| 39 | Luma16Inter, |
| 40 | /// [`Luma16Inter`](TxbSet::Luma16Inter)'s `reduced_tx_set: false` |
| 41 | /// counterpart (lane-cdffwd2, root-caused off `cdfflake-stream-seed45`): |
| 42 | /// the same coefficient tables, but the twelve-symbol |
| 43 | /// `EXT_TX_SET_DTT9_IDTX_1DDCT` `tx_type` table |
| 44 | /// ([`crate::cdf::INTER_TX_TYPE_SET2_16`]) rather than `Luma16Inter`'s |
| 45 | /// two-symbol reduced one. |
| 46 | Luma16InterSet1, |
| 47 | /// The 8x8 luma transform of an intra 8x8 leaf under a straddling 16x16 |
| 48 | /// block (lane-av1-rect). An `is_inter` leaf reads |
| 49 | /// [`Luma8Inter`](TxbSet::Luma8Inter) instead. |
| 50 | Luma8, |
| 51 | /// [`Luma8`](TxbSet::Luma8)'s `reduced_tx_set: false` counterpart (round |
| 52 | /// 8): the same coefficient tables, but the seven-symbol `TX_SET_INTRA_1` |
| 53 | /// `tx_type` table rather than `Luma8`'s five-symbol reduced one. |
| 54 | Luma8Set1, |
| 55 | /// The 8x8 luma transform of an `is_inter` 8x8 leaf under a straddling |
| 56 | /// 16x16 block (lane-av1inter8): the same coefficient tables |
| 57 | /// [`Luma8`](TxbSet::Luma8) reads, but `get_tx_set` (spec 5.11.48) |
| 58 | /// returns `TX_SET_INTER_3` at this size too under this encoder's |
| 59 | /// always-on `reduced_tx_set` -- the same two-symbol alphabet |
| 60 | /// [`Luma16Inter`](TxbSet::Luma16Inter) carries, just its own CDF (libaom |
| 61 | /// `default_inter_ext_tx_cdf[EXT_TX_SET_DCT_IDTX][TX_8X8]`, a distinct |
| 62 | /// adapted table from the 16x16 and 32x32 sizes' own entries in the same |
| 63 | /// set, per `entropymode.c`). |
| 64 | Luma8Inter, |
| 65 | /// [`Luma8Inter`](TxbSet::Luma8Inter)'s `reduced_tx_set: false` |
| 66 | /// counterpart (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` |
| 67 | /// `tx_type` table ([`crate::cdf::INTER_TX_TYPE_SET1_8`]). |
| 68 | Luma8InterSet1, |
| 69 | /// The 4x4 luma transform of a `TxMode::Select` 8x8 leaf or 16x16 block |
| 70 | /// whose `tx_depth` resolves all the way down (lane-av1tx4). An |
| 71 | /// `is_inter` block has no writer path yet, so this crate has no |
| 72 | /// `Luma4Inter` counterpart to [`Luma8Inter`](TxbSet::Luma8Inter). |
| 73 | Luma4, |
| 74 | /// The 4x4 luma transform of an `is_inter` block whose `TxMode::Select` |
| 75 | /// var-tx tree splits an 8x8 unit all the way down (lane-txselect): the |
| 76 | /// same coefficient tables [`Luma4`](TxbSet::Luma4) reads (libaom's |
| 77 | /// coefficient CDFs are keyed by plane type, not intra/inter), with the |
| 78 | /// inter `tx_type` set in place of the intra one. |
| 79 | Luma4Inter, |
| 80 | /// [`Luma4Inter`](TxbSet::Luma4Inter)'s `reduced_tx_set: false` |
| 81 | /// counterpart -- the sixteen-symbol `EXT_TX_SET_ALL16` table |
| 82 | /// ([`crate::cdf::INTER_TX_TYPE_SET1_4`]). |
| 83 | Luma4InterSet1, |
| 84 | /// [`Luma4`](TxbSet::Luma4)'s `reduced_tx_set: false` counterpart, same |
| 85 | /// split as [`Luma8Set1`](TxbSet::Luma8Set1). |
| 86 | Luma4Set1, |
| 87 | /// The 8x8 transform of a chroma plane of a 16x16 block. |
| 88 | Chroma8, |
| 89 | /// The 4x4 transform of a chroma plane of an 8x8 leaf (lane-av1-rect). |
| 90 | /// r5 correction: libaom's `is_chroma_reference` (`av1_common_int.h`) is |
| 91 | /// unconditionally true for `bsize >= BLOCK_8X8`, so chroma *does* follow |
| 92 | /// luma all the way down to 8x8 — it is coded once per 8x8 leaf, not once |
| 93 | /// per parent 16x16 (that "stays at the parent's Chroma8 granularity" |
| 94 | /// framing this doc carried through r4 was never checked against a real |
| 95 | /// decoder and is wrong; only `BLOCK_4X4`/`4X8`/`8X4`, one mi-unit wide or |
| 96 | /// high, get the "last sub-block only" chroma-merge treatment). A real |
| 97 | /// writer for the straddling-16x16 case must use this variant per leaf. |
| 98 | Chroma4, |
| 99 | /// The 16x16 transform of a chroma plane of a 32x32 block. |
| 100 | Chroma16, |
| 101 | /// The 32x32 transform of a chroma plane of a whole superblock. |
| 102 | Chroma32, |
| 103 | /// The luma 32x16/16x32 transform of a `PARTITION_HORZ`/`VERT` intra |
| 104 | /// strip (lane-rectwire): `get_txsize_entropy_ctx` reduces any 2:1 rect |
| 105 | /// size to its square-up equivalent (`entropy.h:172`), so this shares |
| 106 | /// every table [`Luma32`](TxbSet::Luma32) does except `eob_pt` -- a true |
| 107 | /// 512-position transform reads [`crate::cdf::EOB_PT_512_LUMA`], not |
| 108 | /// `Luma32`'s 1024-position one. Never carries a `tx_type` symbol: both |
| 109 | /// orientations use one variant (`get_tx_set` is `EXT_TX_SET_DCTONLY` at |
| 110 | /// `tx_size_sqr_up == TX_32X32` regardless of which axis is longer). |
| 111 | /// The 32x8/8x32 luma transform of a 32x32-level `PARTITION_HORZ_4`/ |
| 112 | /// `PARTITION_VERT_4` strip (lane-tx64x16 r3). `get_txsize_entropy_ctx` |
| 113 | /// averages the two log2 sides ((5 + 3) / 2 = 4), so the coefficient CDF |
| 114 | /// set is the 16x16 one [`Luma16`](TxbSet::Luma16) reads -- 256 coded |
| 115 | /// positions, `eob_pt_256`. Unlike `Luma16` it carries NO `tx_type` |
| 116 | /// symbol: `tx_size_sqr_up` of a 4:1 32-wide strip is `TX_32X32`, where |
| 117 | /// `av1_get_ext_tx_set_type` returns `EXT_TX_SET_DCTONLY` for an intra |
| 118 | /// block, so the encoder writes none (same reason |
| 119 | /// [`LumaRect32x16`](TxbSet::LumaRect32x16) has none). |
| 120 | LumaRect32x8, |
| 121 | /// lane-rectres r1: [`LumaRect32x8`](TxbSet::LumaRect32x8)'s INTER twin -- |
| 122 | /// the 32x32-level 1:4 strip (`max_txsize_rect_lookup[BLOCK_32X8] == |
| 123 | /// TX_32X8`). Same coefficient tables (`get_txsize_entropy_ctx` = TX_16X16, |
| 124 | /// `txsize_log2_minus4` = 4, 256 positions), but an inter unit DOES code a |
| 125 | /// `tx_type`: `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_32X32` is |
| 126 | /// `EXT_TX_SET_DCT_IDTX` for inter regardless of `reduced_tx_set`, read at |
| 127 | /// the `txsize_sqr_map[TX_32X8] == TX_8X8` CDF row. |
| 128 | LumaRect32x8Inter, |
| 129 | LumaRect32x16, |
| 130 | /// lane-inter4 r2: [`LumaRect32x16`](TxbSet::LumaRect32x16)'s INTER twin -- |
| 131 | /// same coefficient tables (`get_txsize_entropy_ctx` reduces TX_32X16 and |
| 132 | /// TX_16X32 alike to the 32x32 set, 512-coefficient `eob_pt`), but an |
| 133 | /// inter block DOES code a `tx_type` symbol here: `av1_get_ext_tx_set_type` |
| 134 | /// with `tx_size_sqr_up == TX_32X32` and `is_inter` returns |
| 135 | /// `EXT_TX_SET_DCT_IDTX` (2 symbols), whose CDF is |
| 136 | /// `default_inter_ext_tx_cdf[3][txsize_sqr_map[TX_32X16] == TX_16X16]`, |
| 137 | /// i.e. exactly [`INTER_TX_TYPE_SET3_16`](crate::cdf::INTER_TX_TYPE_SET3_16) |
| 138 | /// -- the same table the square `Luma16Inter` set reads. |
| 139 | LumaRect32x16Inter, |
| 140 | /// The chroma 16x8/8x16 transform under the same strip (lane-rectwire): |
| 141 | /// [`Chroma16`](TxbSet::Chroma16)'s tables except `eob_pt`, which reads |
| 142 | /// the true 128-position [`crate::cdf::EOB_PT_128_CHROMA`] instead of |
| 143 | /// `Chroma16`'s 256-position one. |
| 144 | ChromaRect16x8, |
| 145 | /// The chroma 32x16/16x32 transform of an intra `PARTITION_HORZ`/`VERT` |
| 146 | /// 64x32/32x64 SUPERBLOCK strip (lane-sbpart): `get_txsize_entropy_ctx` |
| 147 | /// (`(txsize_sqr_map + txsize_sqr_up_map + 1) >> 1`) resolves `TX_32X16` |
| 148 | /// to `TX_32X32`, so this shares every table |
| 149 | /// [`Chroma32`](TxbSet::Chroma32) does except `eob_pt`, which reads the |
| 150 | /// true 512-position [`crate::cdf::EOB_PT_512_CHROMA`] instead of |
| 151 | /// `Chroma32`'s 1024-position one. The SIBLING luma plane of this same |
| 152 | /// strip is genuinely truncated (64/32 > 32), so it reads |
| 153 | /// [`Luma64`](TxbSet::Luma64) instead -- `get_txsize_entropy_ctx(TX_64X32)` |
| 154 | /// resolves to `TX_64X64`, not `TX_32X32`, the two axes landing on |
| 155 | /// different existing sets is why this variant exists at all rather than |
| 156 | /// reusing [`LumaRect32x16`](TxbSet::LumaRect32x16)'s chroma sibling. |
| 157 | ChromaRect32x16, |
| 158 | /// The luma 16x8/8x16 transform of a `PARTITION_HORZ`/`VERT` intra strip |
| 159 | /// below 16x16 (lane-rectx, `decode_leaf_rect`'s own leaf, one level |
| 160 | /// under [`LumaRect32x16`](TxbSet::LumaRect32x16)): `get_txsize_entropy_ctx` |
| 161 | /// reduces this 2:1 rect size to `TX_16X16` too, so this shares every |
| 162 | /// table [`Luma16`](TxbSet::Luma16) does except two: its mode-indexed |
| 163 | /// `tx_type` CDF, which is the *8x8* row's (see |
| 164 | /// [`LumaRect16x8Set1`](TxbSet::LumaRect16x8Set1)), and `eob_pt`, which |
| 165 | /// reads the true 128-position [`crate::cdf::EOB_PT_128_LUMA`] rather |
| 166 | /// than `Luma16`'s 256-position one. Unlike |
| 167 | /// [`LumaRect32x16`](TxbSet::LumaRect32x16), this size DOES carry a |
| 168 | /// `tx_type` symbol: `av1_get_ext_tx_set_type` (`av1/common/blockd.h`) |
| 169 | /// sees `tx_size_sqr_up == TX_16X16`, so intra reads |
| 170 | /// `EXT_TX_SET_DTT4_IDTX` under `reduced_tx_set` and |
| 171 | /// `EXT_TX_SET_DTT4_IDTX_1DDCT` without it (`tx_size_sqr` is `TX_8X8` |
| 172 | /// here, not `TX_16X16`) -- this variant is the reduced arm, its |
| 173 | /// `Set1` sibling the other. |
| 174 | LumaRect16x8, |
| 175 | /// [`LumaRect16x8`](TxbSet::LumaRect16x8)'s `reduced_tx_set: false` |
| 176 | /// counterpart (lane-rectx r3), the same split |
| 177 | /// [`Luma8Set1`](TxbSet::Luma8Set1) has to [`Luma8`](TxbSet::Luma8) -- |
| 178 | /// and it is deliberately those two tables, not the 16x16 row: libaom's |
| 179 | /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][square_tx_size]` with |
| 180 | /// `square_tx_size = txsize_sqr_map[tx_size]`, which for `TX_16X8`/ |
| 181 | /// `TX_8X16` is `TX_8X8`, NOT the `txsize_sqr_up_map` `TX_16X16` the |
| 182 | /// txb-skip/base/br tables use (`get_txsize_entropy_ctx`). r2 read the |
| 183 | /// 16x16 row's five-symbol reduced CDF here and desynced on the very |
| 184 | /// first coded rect leaf. |
| 185 | LumaRect16x8Set1, |
| 186 | /// lane-inter4 r3: [`LumaRect16x8`](TxbSet::LumaRect16x8)'s INTER twin -- |
| 187 | /// the same coefficient tables (`get_txsize_entropy_ctx` reduces TX_16X8 |
| 188 | /// and TX_8X16 alike to the 16x16 set, 128-position `eob_pt`), with the |
| 189 | /// inter `tx_type` alphabet in place of the intra one. Under |
| 190 | /// `reduced_tx_set` `av1_get_ext_tx_set_type` (`tx_size_sqr_up == |
| 191 | /// TX_16X16`, `is_inter`) returns `EXT_TX_SET_DCT_IDTX` (2 symbols), |
| 192 | /// whose CDF row is `default_inter_ext_tx_cdf[1][txsize_sqr_map[TX_16X8] |
| 193 | /// == TX_8X8]`, i.e. [`INTER_TX_TYPE_SET3_8`](crate::cdf::INTER_TX_TYPE_SET3_8) |
| 194 | /// -- the same table the square `Luma8Inter` set reads. |
| 195 | LumaRect16x8Inter, |
| 196 | /// [`LumaRect16x8Inter`](TxbSet::LumaRect16x8Inter)'s `reduced_tx_set: |
| 197 | /// false` counterpart: `tx_size_sqr` is `TX_8X8` here (NOT the |
| 198 | /// `txsize_sqr_up_map` `TX_16X16` the coefficient tables use), so |
| 199 | /// `av1_ext_tx_set_lookup[is_inter=1][tx_size_sqr == TX_16X16 -> 0]` is |
| 200 | /// `EXT_TX_SET_ALL16` -- sixteen symbols, `default_inter_ext_tx_cdf[1] |
| 201 | /// [TX_8X8]`, i.e. [`INTER_TX_TYPE_SET1_8`](crate::cdf::INTER_TX_TYPE_SET1_8), |
| 202 | /// the table [`Luma8InterSet1`](TxbSet::Luma8InterSet1) also reads. |
| 203 | LumaRect16x8InterSet1, |
| 204 | /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx): |
| 205 | /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the |
| 206 | /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of |
| 207 | /// `Chroma8`'s 64-position one -- the same square-up relationship |
| 208 | /// [`ChromaRect16x8`](TxbSet::ChromaRect16x8) has to `Chroma16`, one size |
| 209 | /// class down. |
| 210 | ChromaRect8x4, |
| 211 | /// The luma 4x8/8x4 transform of a `PARTITION_VERT`/`HORZ` leaf under an |
| 212 | /// 8x8 block (lane-tx4x8), under this encoder's `reduced_tx_set`. |
| 213 | /// `get_txsize_entropy_ctx` ((`txsize_sqr_map` + `txsize_sqr_up_map` + 1) |
| 214 | /// >> 1) resolves `TX_4X8` to `TX_8X8`, so every coefficient table here is |
| 215 | /// [`Luma8`](TxbSet::Luma8)'s -- except `eob_pt`, a true 32-position |
| 216 | /// alphabet ([`crate::cdf::EOB_PT_32_LUMA`]), and `tx_type`, whose CDF row |
| 217 | /// is `txsize_sqr_map[TX_4X8]` = `TX_4X4` (libaom `read_tx_type`'s |
| 218 | /// `square_tx_size`), i.e. [`Luma4`](TxbSet::Luma4)'s own table. |
| 219 | LumaRect4x8, |
| 220 | /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s `reduced_tx_set: false` |
| 221 | /// counterpart: `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_8X8`, |
| 222 | /// `tx_size_sqr == TX_4X4`, intra returns `EXT_TX_SET_DTT4_IDTX_1DDCT`, |
| 223 | /// the same seven-symbol set (and same `TX_4X4` row) `Luma4Set1` reads. |
| 224 | LumaRect4x8Set1, |
| 225 | /// The luma 16x4/4x16 transform of a 16x16-level `PARTITION_HORZ_4`/ |
| 226 | /// `PARTITION_VERT_4` strip (lane-r14). `get_txsize_entropy_ctx` |
| 227 | /// ((`txsize_sqr_map` + `txsize_sqr_up_map` + 1) >> 1) resolves `TX_16X4` |
| 228 | /// to `TX_8X8`, and the transform has 64 coded positions, so EVERY table |
| 229 | /// here is [`Luma8`](TxbSet::Luma8)'s (`eob_pt_64` included) except |
| 230 | /// `tx_type`: `read_tx_type` indexes `intra_ext_tx_cdf[eset] |
| 231 | /// [txsize_sqr_map[TX_16X4]]` = the `TX_4X4` row, and |
| 232 | /// `av1_get_ext_tx_set_type` at `tx_size_sqr_up == TX_16X16` with |
| 233 | /// `tx_size_sqr == TX_4X4` returns `EXT_TX_SET_DTT4_IDTX` under |
| 234 | /// `reduced_tx_set` -- the same pair [`LumaRect4x8`](TxbSet::LumaRect4x8) |
| 235 | /// reads, which differs from this variant only in its 32-position `eob_pt`. |
| 236 | LumaRect16x4, |
| 237 | /// [`LumaRect16x4`](TxbSet::LumaRect16x4)'s `reduced_tx_set: false` |
| 238 | /// counterpart: `EXT_TX_SET_DTT4_IDTX_1DDCT`, the seven-symbol `TX_4X4` |
| 239 | /// row [`LumaRect4x8Set1`](TxbSet::LumaRect4x8Set1) reads. |
| 240 | LumaRect16x4Set1, |
| 241 | /// The luma 8x4/4x8 transform of an INTER `PARTITION_HORZ`/`PARTITION_VERT` |
| 242 | /// leaf under an 8x8 block (lane-intersub8 r3): every coefficient table is |
| 243 | /// [`LumaRect4x8`](TxbSet::LumaRect4x8)'s (`get_txsize_entropy_ctx` squares |
| 244 | /// `TX_8X4` up to the 8x8 class, 32-position `eob_pt`), with the INTER |
| 245 | /// `tx_type` alphabet in its place. Under `reduced_tx_set` |
| 246 | /// `av1_get_ext_tx_set_type` (`tx_size_sqr_up == TX_8X8`, `is_inter`) |
| 247 | /// returns `EXT_TX_SET_DCT_IDTX`, whose row is |
| 248 | /// `default_inter_ext_tx_cdf[?][txsize_sqr_map[TX_8X4] == TX_4X4]` -- the |
| 249 | /// same `TX_4X4` inter row [`Luma4Inter`](TxbSet::Luma4Inter) reads. |
| 250 | LumaRect8x4Inter, |
| 251 | /// [`LumaRect8x4Inter`](TxbSet::LumaRect8x4Inter)'s `reduced_tx_set: false` |
| 252 | /// counterpart: `tx_size_sqr == TX_4X4` with `tx_size_sqr_up == TX_8X8`, so |
| 253 | /// `av1_ext_tx_set_lookup[is_inter=1][...]` is `EXT_TX_SET_ALL16` -- sixteen |
| 254 | /// symbols at the `TX_4X4` inter row, the table |
| 255 | /// [`Luma4InterSet1`](TxbSet::Luma4InterSet1) also reads. |
| 256 | LumaRect8x4InterSet1, |
| 257 | /// [`LumaRect16x4`](TxbSet::LumaRect16x4)'s INTER counterpart |
| 258 | /// (lane-inter16ab r2): the same `Luma8` coefficient tables (64 coded |
| 259 | /// positions, `get_txsize_entropy_ctx(TX_16X4)` = TX_8X8), with the |
| 260 | /// INTER `tx_type` table at `txsize_sqr_map[TX_16X4]` = TX_4X4. |
| 261 | /// `av1_get_ext_tx_set_type` (av1/common/idct.c): `tx_size_sqr_up` is |
| 262 | /// TX_16X16 (not > TX_32X32) and `use_reduced_set` picks |
| 263 | /// `EXT_TX_SET_DCT_IDTX` -- three symbols, `inter_tx_type_4`. |
| 264 | LumaRect16x4Inter, |
| 265 | /// [`LumaRect16x4Inter`](TxbSet::LumaRect16x4Inter)'s |
| 266 | /// `reduced_tx_set: false` counterpart: `tx_size_sqr` is TX_4X4, not |
| 267 | /// TX_16X16, so `av1_get_ext_tx_set_type` returns `EXT_TX_SET_ALL16` -- |
| 268 | /// sixteen symbols, `inter_tx_type_4_set1`. |
| 269 | LumaRect16x4Inter1, |
| 270 | } |
| 271 | |
| 272 | /// The tables one transform block is coded with, borrowed from the state for |
| 273 | /// as long as that block is being written. |
| 274 | pub(crate) struct TxbTables<'a> { |
| 275 | /// Side of the transform, in coefficients. |
| 276 | pub side: usize, |
| 277 | /// The all-zero flag, indexed by its own context. |
| 278 | pub txb_skip: &'a mut [[u16; 3]], |
| 279 | /// The end-of-block group, whose alphabet the transform size sets. |
| 280 | pub eob_pt: &'a mut [u16], |
| 281 | /// `eob_pt`'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling table (r5): read |
| 282 | /// instead of `eob_pt` once this TU's `tx_type` is known to be |
| 283 | /// `V_DCT`/`H_DCT`. `None` for any size/set whose `tx_type` alphabet |
| 284 | /// cannot produce those two symbols (chroma, and every inter set). |
| 285 | pub eob_pt_class1: Option<&'a mut [u16]>, |
| 286 | /// The top bit of the offset inside that group. |
| 287 | pub eob_extra: &'a mut [[u16; 3]; 9], |
| 288 | /// A coefficient's base level. |
| 289 | pub base: &'a mut [[u16; 5]; 42], |
| 290 | /// The base level of the last coefficient in the scan. |
| 291 | pub base_eob: &'a mut [[u16; 4]; 4], |
| 292 | /// The base-range tail above level two. |
| 293 | pub br: &'a mut [[u16; 5]; 21], |
| 294 | /// The sign of the DC. |
| 295 | pub dc_sign: &'a mut [[u16; 3]; 3], |
| 296 | /// The transform type, for the one size whose set holds more than one -- |
| 297 | /// a plain slice because the intra 16x16 table's alphabet (five types) |
| 298 | /// and the inter 32x32 table's (two, `TX_SET_INTER_3`) are different |
| 299 | /// sizes. |
| 300 | pub tx_type: Option<&'a mut [u16]>, |
| 301 | } |
| 302 | |
| 303 | /// Every table a key frame's tile writer adapts. |
| 304 | #[derive(Clone)] |
| 305 | pub(crate) struct Cdfs { |
| 306 | /// The partition symbol of a 64x64 superblock. |
| 307 | /// `partition_cdf`'s `BLOCK_128X128` rows (8 symbols). |
| 308 | pub partition_w128: [[u16; 9]; 4], |
| 309 | pub partition_w64: [[u16; 11]; 4], |
| 310 | /// The partition symbol of a 32x32 block. |
| 311 | pub partition_w32: [[u16; 11]; 4], |
| 312 | /// Whether a block carries no residual at all. |
| 313 | /// `txfm_partition_cdf`: an inter block's `txfm_split` flag under |
| 314 | /// `TxMode::Select` (lane-txselect, spec 5.11.17), indexed by |
| 315 | /// `txfm_partition_context` -- see [`cdf::TXFM_PARTITION`]. |
| 316 | pub txfm_partition: [[u16; 3]; 21], |
| 317 | pub skip: [[u16; 3]; 3], |
| 318 | /// The luma mode of a key frame's block, under the two neighbours' modes. |
| 319 | pub kf_y_mode: [[[u16; 14]; 5]; 5], |
| 320 | /// The chroma mode of a block too big to be offered chroma from luma. |
| 321 | pub uv_mode_no_cfl: [[u16; 14]; 13], |
| 322 | /// The chroma mode of a block that is offered it. |
| 323 | pub uv_mode_cfl: [[u16; 15]; 13], |
| 324 | /// The joint sign of a `UV_CFL_PRED` block's U/V alpha. |
| 325 | pub cfl_sign: [u16; 9], |
| 326 | /// A `UV_CFL_PRED` block's per-plane alpha magnitude, by joint-sign context. |
| 327 | pub cfl_alpha: [[u16; 17]; 6], |
| 328 | /// The angle a directional mode is nudged by. |
| 329 | pub angle_delta: [[u16; 8]; 8], |
| 330 | /// The all-zero flag of a 16x16 luma transform, 7 contexts (index 0 for |
| 331 | /// a lone TU whose own bsize equals the block's; 1..6 the |
| 332 | /// `skip_contexts[top][left]` table when `TxMode::Select` splits the |
| 333 | /// block's luma into several smaller transform units, spec |
| 334 | /// `get_txb_ctx_general`). |
| 335 | pub txb_skip_luma_16: [[u16; 3]; 7], |
| 336 | /// The same, for an 8x8 luma transform. |
| 337 | pub txb_skip_luma_8: [[u16; 3]; 7], |
| 338 | /// The same, for a 4x4 luma transform (lane-av1tx4). |
| 339 | pub txb_skip_luma_4: [[u16; 3]; 7], |
| 340 | /// The all-zero flag of an 8x8 chroma transform. |
| 341 | pub txb_skip_chroma_8: [[u16; 3]; 3], |
| 342 | /// The all-zero flag of a 4x4 chroma transform. |
| 343 | pub txb_skip_chroma_4: [[u16; 3]; 3], |
| 344 | /// The end-of-block group of a 16x16 luma transform. |
| 345 | pub eob_pt_256_luma: [u16; 10], |
| 346 | /// The end-of-block group of an 8x8 luma transform. |
| 347 | pub eob_pt_64_luma: [u16; 8], |
| 348 | /// The end-of-block group of an 8x8 chroma transform. |
| 349 | pub eob_pt_64_chroma: [u16; 8], |
| 350 | /// The end-of-block group of a 4x4 chroma transform. |
| 351 | pub eob_pt_16_chroma: [u16; 6], |
| 352 | /// The end-of-block group of a 4x4 luma transform (lane-av1tx4). |
| 353 | pub eob_pt_16_luma: [u16; 6], |
| 354 | /// `eob_pt_16_luma`'s `TX_CLASS_HORIZ`/`TX_CLASS_VERT` sibling, read |
| 355 | /// instead whenever the TU's `tx_type` is `V_DCT`/`H_DCT` (r5). |
| 356 | pub eob_pt_16_luma_class1: [u16; 6], |
| 357 | /// `eob_pt_64_luma`'s class-1 sibling (r5), see `eob_pt_16_luma_class1`. |
| 358 | pub eob_pt_64_luma_class1: [u16; 8], |
| 359 | /// `eob_pt_16_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 360 | pub eob_pt_16_chroma_class1: [u16; 6], |
| 361 | /// `eob_pt_64_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 362 | pub eob_pt_64_chroma_class1: [u16; 8], |
| 363 | /// `eob_pt_128_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 364 | pub eob_pt_128_chroma_class1: [u16; 9], |
| 365 | /// `eob_pt_128_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 366 | pub eob_pt_128_luma_class1: [u16; 9], |
| 367 | /// `eob_pt_32_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 368 | pub eob_pt_32_chroma_class1: [u16; 7], |
| 369 | /// `eob_pt_256_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 370 | pub eob_pt_256_luma_class1: [u16; 10], |
| 371 | /// `eob_pt_256_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 372 | pub eob_pt_256_chroma_class1: [u16; 10], |
| 373 | /// `eob_pt_512_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 374 | pub eob_pt_512_luma_class1: [u16; 11], |
| 375 | /// `eob_pt_512_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 376 | pub eob_pt_512_chroma_class1: [u16; 11], |
| 377 | /// `eob_pt_1024_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 378 | pub eob_pt_1024_luma_class1: [u16; 12], |
| 379 | /// `eob_pt_1024_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see `eob_pt_16_luma_class1`. |
| 380 | pub eob_pt_1024_chroma_class1: [u16; 12], |
| 381 | /// The end-of-block group of a 32-position (4x8/8x4) luma transform |
| 382 | /// (lane-tx4x8). |
| 383 | pub eob_pt_32_luma: [u16; 7], |
| 384 | /// `eob_pt_32_luma`'s class-1 sibling, see `eob_pt_16_luma_class1`. |
| 385 | pub eob_pt_32_luma_class1: [u16; 7], |
| 386 | /// The end-of-block offset bit of a 16x16 luma transform. |
| 387 | pub eob_extra_luma_16: [[u16; 3]; 9], |
| 388 | /// The same, for an 8x8 luma transform. |
| 389 | pub eob_extra_luma_8: [[u16; 3]; 9], |
| 390 | /// The same, for a 4x4 luma transform. |
| 391 | pub eob_extra_luma_4: [[u16; 3]; 9], |
| 392 | /// The same, for an 8x8 chroma transform. |
| 393 | pub eob_extra_chroma_8: [[u16; 3]; 9], |
| 394 | /// The same, for a 4x4 chroma transform. |
| 395 | pub eob_extra_chroma_4: [[u16; 3]; 9], |
| 396 | /// The base level of a 16x16 luma coefficient. |
| 397 | pub base_luma_16: [[u16; 5]; 42], |
| 398 | /// The base level of an 8x8 luma coefficient. |
| 399 | pub base_luma_8: [[u16; 5]; 42], |
| 400 | /// The base level of a 4x4 luma coefficient. |
| 401 | pub base_luma_4: [[u16; 5]; 42], |
| 402 | /// The base level of an 8x8 chroma coefficient. |
| 403 | pub base_chroma_8: [[u16; 5]; 42], |
| 404 | /// The base level of a 4x4 chroma coefficient. |
| 405 | pub base_chroma_4: [[u16; 5]; 42], |
| 406 | /// The last coefficient's base level, for a 16x16 luma transform. |
| 407 | pub base_eob_luma_16: [[u16; 4]; 4], |
| 408 | /// The same, for an 8x8 luma transform. |
| 409 | pub base_eob_luma_8: [[u16; 4]; 4], |
| 410 | /// The same, for a 4x4 luma transform. |
| 411 | pub base_eob_luma_4: [[u16; 4]; 4], |
| 412 | /// The same, for an 8x8 chroma transform. |
| 413 | pub base_eob_chroma_8: [[u16; 4]; 4], |
| 414 | /// The same, for a 4x4 chroma transform. |
| 415 | pub base_eob_chroma_4: [[u16; 4]; 4], |
| 416 | /// The base-range tail of a 16x16 luma coefficient. |
| 417 | pub br_luma_16: [[u16; 5]; 21], |
| 418 | /// The base-range tail of an 8x8 luma coefficient. |
| 419 | pub br_luma_8: [[u16; 5]; 21], |
| 420 | /// The base-range tail of a 4x4 luma coefficient. |
| 421 | pub br_luma_4: [[u16; 5]; 21], |
| 422 | /// The base-range tail of an 8x8 chroma coefficient. |
| 423 | pub br_chroma_8: [[u16; 5]; 21], |
| 424 | /// The base-range tail of a 4x4 chroma coefficient. |
| 425 | pub br_chroma_4: [[u16; 5]; 21], |
| 426 | /// The partition symbol of a 16x16 block. |
| 427 | pub partition_w16: [[u16; 11]; 4], |
| 428 | /// The partition symbol of an 8x8 block (lane-av1-rect): only |
| 429 | /// `PARTITION_NONE` is ever coded against it, but the alphabet still |
| 430 | /// adapts on every read, same as every other partition table. |
| 431 | pub partition_w8: [[u16; 5]; 4], |
| 432 | /// The same as `txb_skip_luma_16`'s 7 contexts, for a 32x32 luma transform. |
| 433 | pub txb_skip_luma_32: [[u16; 3]; 7], |
| 434 | /// The same, for a 64x64 luma transform. |
| 435 | pub txb_skip_luma_64: [[u16; 3]; 7], |
| 436 | /// The all-zero flag of a 16x16 chroma transform. |
| 437 | pub txb_skip_chroma_16: [[u16; 3]; 3], |
| 438 | /// The all-zero flag of a 32x32 chroma transform. |
| 439 | /// SIX contexts, not three: rows 0..3 are libaom's `txb_skip_ctx` 7..9 |
| 440 | /// (chroma transform == its plane block) and rows 3..6 its 10..12 (plane |
| 441 | /// block larger, i.e. a 128x128 block's four TX_32X32 chroma units). |
| 442 | pub txb_skip_chroma_32: [[u16; 3]; 6], |
| 443 | /// The end-of-block group of a luma transform of 1024 positions. |
| 444 | pub eob_pt_1024_luma: [u16; 12], |
| 445 | /// The same, for chroma. |
| 446 | pub eob_pt_1024_chroma: [u16; 12], |
| 447 | /// The end-of-block group of a 16x16 chroma transform. |
| 448 | pub eob_pt_256_chroma: [u16; 10], |
| 449 | /// The end-of-block group of a true 32x16/16x32 rect luma transform |
| 450 | /// (lane-rectwire), see [`TxbSet::LumaRect32x16`]. |
| 451 | pub eob_pt_512_luma: [u16; 11], |
| 452 | /// The end-of-block group of a true 16x8/8x16 rect chroma transform |
| 453 | /// (lane-rectwire), see [`TxbSet::ChromaRect16x8`]. |
| 454 | pub eob_pt_128_chroma: [u16; 9], |
| 455 | /// The end-of-block group of a true 32x16/16x32 rect CHROMA transform |
| 456 | /// (lane-sbpart), see [`TxbSet::ChromaRect32x16`]. |
| 457 | pub eob_pt_512_chroma: [u16; 11], |
| 458 | /// The end-of-block group of a true 16x8/8x16 rect LUMA transform |
| 459 | /// (lane-rectx), see [`TxbSet::LumaRect16x8`]. |
| 460 | pub eob_pt_128_luma: [u16; 9], |
| 461 | /// The end-of-block group of a true 8x4/4x8 rect CHROMA transform |
| 462 | /// (lane-rectx), see [`TxbSet::ChromaRect8x4`]. |
| 463 | pub eob_pt_32_chroma: [u16; 7], |
| 464 | /// The end-of-block offset bit, per table set. |
| 465 | pub eob_extra_luma_32: [[u16; 3]; 9], |
| 466 | /// The same, for a 64x64 luma transform. |
| 467 | pub eob_extra_luma_64: [[u16; 3]; 9], |
| 468 | /// The same, for a 16x16 chroma transform. |
| 469 | pub eob_extra_chroma_16: [[u16; 3]; 9], |
| 470 | /// The same, for a 32x32 chroma transform. |
| 471 | pub eob_extra_chroma_32: [[u16; 3]; 9], |
| 472 | /// The base level of a 32x32 luma coefficient. |
| 473 | pub base_luma_32: [[u16; 5]; 42], |
| 474 | /// The base level of a 64x64 luma coefficient. |
| 475 | pub base_luma_64: [[u16; 5]; 42], |
| 476 | /// The base level of a 16x16 chroma coefficient. |
| 477 | pub base_chroma_16: [[u16; 5]; 42], |
| 478 | /// The base level of a 32x32 chroma coefficient. |
| 479 | pub base_chroma_32: [[u16; 5]; 42], |
| 480 | /// The last coefficient's base level, per table set. |
| 481 | pub base_eob_luma_32: [[u16; 4]; 4], |
| 482 | /// The same, for a 64x64 luma transform. |
| 483 | pub base_eob_luma_64: [[u16; 4]; 4], |
| 484 | /// The same, for a 16x16 chroma transform. |
| 485 | pub base_eob_chroma_16: [[u16; 4]; 4], |
| 486 | /// The same, for a 32x32 chroma transform. |
| 487 | pub base_eob_chroma_32: [[u16; 4]; 4], |
| 488 | /// The base-range tail of a luma coefficient, which a 64x64 transform |
| 489 | /// reads too because its index is clamped at the 32x32 size. |
| 490 | pub br_luma_32: [[u16; 5]; 21], |
| 491 | /// The base-range tail of a 16x16 chroma coefficient. |
| 492 | pub br_chroma_16: [[u16; 5]; 21], |
| 493 | /// The base-range tail of a 32x32 chroma coefficient. |
| 494 | pub br_chroma_32: [[u16; 5]; 21], |
| 495 | /// The DC sign of a luma coefficient, shared by both luma sets. |
| 496 | pub dc_sign_luma: [[u16; 3]; 3], |
| 497 | /// The transform type of a 16x16 intra luma transform, by luma mode. |
| 498 | pub intra_tx_type_16: [[u16; 6]; 13], |
| 499 | /// The transform type of an 8x8 intra luma transform, by luma mode. |
| 500 | pub intra_tx_type_8: [[u16; 6]; 13], |
| 501 | /// The transform type of an 8x8 intra luma transform, by luma mode, when |
| 502 | /// `reduced_tx_set` is false (spec `TX_SET_INTRA_1`, seven types) -- |
| 503 | /// [`Self::intra_tx_type_8`]'s five-type table is only the |
| 504 | /// `reduced_tx_set` row (round 8: a real `aomenc` stream with |
| 505 | /// `reduced_tx_set` off desyncs an 8x8 TU read against this row's |
| 506 | /// wrong-length CDF). |
| 507 | pub intra_tx_type_8_set1: [[u16; 8]; 13], |
| 508 | /// The transform type of a 4x4 intra luma transform, by luma mode |
| 509 | /// (lane-av1tx4): the flat five-symbol `reduced_tx_set` row, byte- |
| 510 | /// identical to [`Self::intra_tx_type_8`]'s own table |
| 511 | /// ([`cdf::INTRA_TX_TYPE_SET2_8`]) -- libaom leaves `TX_4X4` at the same |
| 512 | /// uniform default. |
| 513 | pub intra_tx_type_4: [[u16; 6]; 13], |
| 514 | /// [`Self::intra_tx_type_4`]'s `reduced_tx_set: false` counterpart, same |
| 515 | /// split as [`Self::intra_tx_type_8_set1`]. |
| 516 | pub intra_tx_type_4_set1: [[u16; 8]; 13], |
| 517 | /// The transform type of an `is_inter` 32x32 luma transform (spec |
| 518 | /// `TX_SET_INTER_3`, `TX_32X32` row) -- unlike the intra 16x16 table, it |
| 519 | /// is not indexed by mode. |
| 520 | pub inter_tx_type_32: [u16; 3], |
| 521 | /// The transform type of an `is_inter` 16x16 luma transform under |
| 522 | /// `reduced_tx_set` (spec `TX_SET_INTER_3`, `TX_16X16` row) -- not |
| 523 | /// indexed by mode, same as [`Self::inter_tx_type_32`]. |
| 524 | pub inter_tx_type_16: [u16; 3], |
| 525 | /// The transform type of an `is_inter` 8x8 luma transform under |
| 526 | /// `reduced_tx_set` (spec `TX_SET_INTER_3`, `TX_8X8` row) -- not indexed |
| 527 | /// by mode, same as [`Self::inter_tx_type_32`] (lane-av1inter8). |
| 528 | pub inter_tx_type_8: [u16; 3], |
| 529 | /// [`Self::inter_tx_type_16`]'s `reduced_tx_set: false` counterpart |
| 530 | /// (lane-cdffwd2): the twelve-symbol `EXT_TX_SET_DTT9_IDTX_1DDCT` row, |
| 531 | /// not indexed by mode. |
| 532 | pub inter_tx_type_16_set2: [u16; 13], |
| 533 | /// [`Self::inter_tx_type_8`]'s `reduced_tx_set: false` counterpart |
| 534 | /// (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` row, not |
| 535 | /// indexed by mode. |
| 536 | pub inter_tx_type_8_set1: [u16; 17], |
| 537 | /// The 4x4 counterparts of [`Self::inter_tx_type_8`]/ |
| 538 | /// [`Self::inter_tx_type_8_set1`] (lane-txselect). |
| 539 | pub inter_tx_type_4: [u16; 3], |
| 540 | /// See [`Self::inter_tx_type_4`]. |
| 541 | pub inter_tx_type_4_set1: [u16; 17], |
| 542 | /// The DC sign of a chroma coefficient, shared by both chroma sets. |
| 543 | pub dc_sign_chroma: [[u16; 3]; 3], |
| 544 | /// Whether an inter frame's block is coded as intra. |
| 545 | pub intra_inter: [[u16; 3]; 4], |
| 546 | /// The six binary decisions of an inter block's single reference frame. |
| 547 | pub single_ref: [[[u16; 3]; 6]; 3], |
| 548 | /// Whether a block reads `SINGLE_REFERENCE` or `COMPOUND_REFERENCE` |
| 549 | /// (lane-av1comp, spec 5.11.25's `comp_mode`). |
| 550 | pub comp_mode: [[u16; 3]; 5], |
| 551 | /// Whether a block reads `skip_mode` (lane-av1comp, spec 5.11.29's |
| 552 | /// `skip_mode`), indexed by `av1_get_skip_mode_context`. |
| 553 | pub skip_mode: [[u16; 3]; 3], |
| 554 | /// `use_obmc` (spec 5.11.24's `read_motion_mode`, the `OBMC_CAUSAL`-vs- |
| 555 | /// `SIMPLE_TRANSLATION` two-symbol alphabet libaom's `obmc_cdf` reads |
| 556 | /// whenever `motion_mode_allowed` can't offer `WARPED_CAUSAL` -- |
| 557 | /// lane-motionmode round 1 only reaches this arm, never the three-way |
| 558 | /// `motion_mode_cdf`), indexed by this block's own square bsize: 0 = |
| 559 | /// `BLOCK_8X8`, 1 = `BLOCK_16X16`, 2 = `BLOCK_32X32`, 3 = `BLOCK_64X64` |
| 560 | /// (`default_obmc_cdf`'s own `BLOCK_SIZES_ALL` indices 3/6/9/12 -- |
| 561 | /// this decoder only ever codes those four square sizes). |
| 562 | pub obmc: [[u16; 3]; 17], |
| 563 | /// `motion_mode` (spec 5.11.24's `read_motion_mode`), the 3-symbol |
| 564 | /// `SIMPLE_TRANSLATION`/`OBMC_CAUSAL`/`WARPED_CAUSAL` alphabet read |
| 565 | /// instead of [`Self::obmc`] whenever `motion_mode_allowed` resolves to |
| 566 | /// `WARPED_CAUSAL`-eligible -- same square-bsize indexing as `obmc`. |
| 567 | /// lane-warp round 1. |
| 568 | pub motion_mode: [[u16; 4]; 17], |
| 569 | /// `interintra`, indexed by `size_group_lookup[bsize]` -- see |
| 570 | /// `cdf::INTERINTRA`'s own doc. |
| 571 | pub interintra: [[u16; 3]; 4], |
| 572 | /// `interintra_mode` (II_DC/II_V/II_H/II_SMOOTH), same size-group |
| 573 | /// indexing -- see `cdf::INTERINTRA_MODE` (lane-interintra r1). |
| 574 | pub interintra_mode: [[u16; 5]; 4], |
| 575 | /// `wedge_interintra`, indexed by bsize over `BLOCK_SIZES_ALL` -- see |
| 576 | /// `cdf::WEDGE_INTERINTRA` (lane-interintra r1). |
| 577 | pub wedge_interintra: [[u16; 3]; 22], |
| 578 | /// `compound_type` (`COMPOUND_WEDGE` vs `COMPOUND_DIFFWTD`), indexed by |
| 579 | /// bsize over `BLOCK_SIZES_ALL` -- see `cdf::COMPOUND_TYPE` |
| 580 | /// (lane-maskcomp). |
| 581 | pub compound_type: [[u16; 3]; 22], |
| 582 | /// `wedge_index` (16-ary), indexed by bsize over `BLOCK_SIZES_ALL` -- |
| 583 | /// see `cdf::WEDGE_IDX` (lane-maskcomp). |
| 584 | pub wedge_idx: [[u16; 17]; 22], |
| 585 | /// Which of the eight `INTER_COMPOUND_MODES` a `COMPOUND_REFERENCE` |
| 586 | /// block takes (lane-av1comp, spec 5.11.24's `compound_mode`). |
| 587 | pub inter_compound_mode: [[u16; 9]; 8], |
| 588 | /// Unidirectional vs. bidirectional compound reference pair |
| 589 | /// (lane-av1comp, spec 5.11.25's `comp_reference_type`). |
| 590 | pub comp_ref_type: [[u16; 3]; 5], |
| 591 | /// The three binary decisions of a unidirectional compound pair. |
| 592 | pub uni_comp_ref: [[[u16; 3]; 3]; 3], |
| 593 | /// The three binary decisions of a bidirectional pair's forward ref. |
| 594 | pub comp_ref: [[[u16; 3]; 3]; 3], |
| 595 | /// The two binary decisions of a bidirectional pair's backward ref. |
| 596 | pub comp_bwdref: [[[u16; 3]; 2]; 3], |
| 597 | /// Whether a compound block's `comp_group_idx` picks masked compound |
| 598 | /// (lane-av1comp, spec 5.11.25's `comp_group_idx`). |
| 599 | pub comp_group_idx: [[u16; 3]; 6], |
| 600 | /// Whether a compound block's `compound_idx` picks the simple average |
| 601 | /// over the distance-weighted blend (lane-av1comp, spec 5.11.25's |
| 602 | /// `compound_idx`). |
| 603 | pub compound_idx: [[u16; 3]; 6], |
| 604 | /// The luma mode of an inter frame's intra block, by its size group. |
| 605 | pub y_mode: [[u16; 14]; 4], |
| 606 | /// Whether an inter block codes its motion vector explicitly. |
| 607 | pub new_mv: [[u16; 3]; 6], |
| 608 | /// Whether an inter block's motion vector is the zero vector. |
| 609 | pub zero_mv: [[u16; 3]; 2], |
| 610 | /// Which reference motion vector candidate an inter block takes. |
| 611 | pub ref_mv: [[u16; 3]; 6], |
| 612 | /// The dynamic reference list index of a motion vector prediction. |
| 613 | pub drl_mode: [[u16; 3]; 3], |
| 614 | /// A motion vector's joint (which components change), shared by both |
| 615 | /// components since it is read once per vector, not once per component. |
| 616 | pub mv_joint: [u16; 5], |
| 617 | /// The two motion vector components' own tables: separate owned state, |
| 618 | /// since spec 8.3.2 adapts one component without touching the other. |
| 619 | pub mv_comp: [MvComponentCdfs; 2], |
| 620 | /// libaom's `ndvc` (`av1_init_mv_probs`): the block-vector MV context an |
| 621 | /// intrabc block reads (spec's `MV_INTRABC_CONTEXT`). Same spec-8.4 |
| 622 | /// defaults as [`Self::mv_joint`]/[`Self::mv_comp`], separate adaptation. |
| 623 | pub dv_joint: [u16; 5], |
| 624 | /// [`Self::dv_joint`]'s per-component half. |
| 625 | pub dv_comp: [MvComponentCdfs; 2], |
| 626 | /// The `use_filter_intra` flag, indexed by block-size class (`[0]`=4x4, |
| 627 | /// `[1]`=8x8, `[2]`=16x16, `[3]`=32x32, `[4]`=32x16, `[5]`=16x32, |
| 628 | /// `[6]`=16x8, `[7]`=8x16, `[8]`=4x8, `[9]`=8x4, `[10]`=32x8, `[11]`=8x32) -- |
| 629 | /// see [`cdf::FILTER_INTRA`]. |
| 630 | pub filter_intra: [[u16; 3]; 14], |
| 631 | /// Which `FILTER_INTRA_MODES` entry a `use_filter_intra` block picks. |
| 632 | pub filter_intra_mode: [u16; 6], |
| 633 | /// `TxMode::Select`'s `tx_depth` flag at an 8x8 block, by `tx_size_context` |
| 634 | /// (0..=2) -- see [`cdf::TX_SIZE_CAT0`]. |
| 635 | pub tx_size_cat0: [[u16; 3]; 3], |
| 636 | /// `tx_depth` at a 16x16 block -- see [`cdf::TX_SIZE_CAT1`]. |
| 637 | pub tx_size_cat1: [[u16; 4]; 3], |
| 638 | /// `tx_depth` at a 32x32 block -- see [`cdf::TX_SIZE_CAT2`]. |
| 639 | pub tx_size_cat2: [[u16; 4]; 3], |
| 640 | /// `tx_depth` at a 64x64 block -- see [`cdf::TX_SIZE_CAT3`]. |
| 641 | pub tx_size_cat3: [[u16; 4]; 3], |
| 642 | /// A `SWITCHABLE`-filter inter block's own `interp_filter[dir]` -- see |
| 643 | /// [`cdf::SWITCHABLE_INTERP`]. |
| 644 | pub switchable_interp: [[u16; 4]; 16], |
| 645 | /// A `DC_PRED` block's own palette-use flag -- see [`cdf::PALETTE_Y_MODE`]. |
| 646 | pub palette_y_mode: [[[u16; 3]; 3]; 7], |
| 647 | /// A palette block's own size (2..=8) -- see [`cdf::PALETTE_Y_SIZE`]. |
| 648 | pub palette_y_size: [[u16; 8]; 7], |
| 649 | /// A `UV_DC_PRED` block's own chroma palette-use flag -- see |
| 650 | /// [`cdf::PALETTE_UV_MODE`]. |
| 651 | pub palette_uv_mode: [[u16; 3]; 2], |
| 652 | /// A chroma palette block's own size -- see [`cdf::PALETTE_UV_SIZE`]. |
| 653 | pub palette_uv_size: [[u16; 8]; 7], |
| 654 | /// A palette-Y block's per-pixel colour-index symbol -- see |
| 655 | /// [`cdf::PALETTE_Y_COLOR_INDEX`]. |
| 656 | pub palette_y_color_index: [[[u16; 9]; 5]; 7], |
| 657 | /// A palette-UV block's per-pixel colour-index symbol -- see |
| 658 | /// [`cdf::PALETTE_UV_COLOR_INDEX`]. |
| 659 | pub palette_uv_color_index: [[[u16; 9]; 5]; 7], |
| 660 | /// The `use_intrabc` flag -- see [`cdf::INTRABC`]. |
| 661 | pub intrabc: [u16; 3], |
| 662 | /// A `RESTORE_WIENER`-plane LR unit's `use_wiener` flag -- see |
| 663 | /// [`cdf::RESTORE_WIENER`]. |
| 664 | pub restore_wiener: [u16; 3], |
| 665 | /// A `RESTORE_SGRPROJ`-plane LR unit's `use_sgrproj` flag -- see |
| 666 | /// [`cdf::RESTORE_SGRPROJ`]. |
| 667 | pub restore_sgrproj: [u16; 3], |
| 668 | /// A `RESTORE_SWITCHABLE`-plane LR unit's `restoration_type` -- see |
| 669 | /// [`cdf::RESTORE_SWITCHABLE`]. |
| 670 | pub restore_switchable: [u16; 4], |
| 671 | /// `segment_id` (lane-seg, spec 5.11.8) -- see [`cdf::SEGMENT_ID`]. |
| 672 | pub segment_id: [[u16; 9]; 3], |
| 673 | /// `seg_id_predicted` (lane-seg, spec 5.11.9) -- see [`cdf::SEGMENT_PRED`]. |
| 674 | pub segment_pred: [[u16; 3]; 3], |
| 675 | /// `delta_q_abs` (lane-realworld r4, spec 5.11.10) -- see [`cdf::DELTA_Q`]. |
| 676 | pub delta_q: [u16; 5], |
| 677 | /// `delta_lf_abs`, the single-value form (spec 5.11.11) -- see |
| 678 | /// [`cdf::DELTA_LF`]. Currently unread: `delta_lf_present` still refuses |
| 679 | /// by name in `stream.rs` (the deblocker has no per-block carrier for |
| 680 | /// the result yet), kept here so the struct is ready for that round. |
| 681 | pub delta_lf: [u16; 5], |
| 682 | /// `delta_lf_abs[i]`, the `delta_lf_multi` per-plane/direction form |
| 683 | /// (`FRAME_LF_COUNT = 4`) -- same unread status as [`Self::delta_lf`]. |
| 684 | pub delta_lf_multi: [[u16; 5]; 4], |
| 685 | } |
| 686 | |
| 687 | /// One motion vector component's adapting state (spec 9.4's `Default_Mv_*`, |
| 688 | /// held once per component so that adapting one leaves the other alone). |
| 689 | #[derive(Clone)] |
| 690 | pub(crate) struct MvComponentCdfs { |
| 691 | /// The magnitude class. |
| 692 | pub class: [u16; 12], |
| 693 | /// The integer bit of a small-class magnitude. |
| 694 | pub class0_bit: [u16; 3], |
| 695 | /// The fractional part of a small-class magnitude, by its integer bit. |
| 696 | pub class0_fr: [[u16; 5]; 2], |
| 697 | /// The half-pel bit of a small-class magnitude (spec `mv_class0_hp`), |
| 698 | /// read only when the frame header sets `allow_high_precision_mv` (a |
| 699 | /// real encoder's choice, not this crate's own writer's -- which always |
| 700 | /// leaves the flag off and so never needs this table, but a foreign |
| 701 | /// stream this decoder reads can set it per frame). |
| 702 | pub class0_hp: [u16; 3], |
| 703 | /// One bit of an above-small-class magnitude, by its position. |
| 704 | pub bit: [[u16; 3]; 10], |
| 705 | /// The fractional part of an above-small-class magnitude. |
| 706 | pub fr: [u16; 5], |
| 707 | /// The half-pel bit of an above-small-class magnitude (spec `mv_hp`), |
| 708 | /// same `allow_high_precision_mv` gating as [`Self::class0_hp`]. |
| 709 | pub hp: [u16; 3], |
| 710 | /// The component's sign. |
| 711 | pub sign: [u16; 3], |
| 712 | } |
| 713 | |
| 714 | impl MvComponentCdfs { |
| 715 | fn new() -> MvComponentCdfs { |
| 716 | MvComponentCdfs { |
| 717 | class: cdf::MV_CLASS, |
| 718 | class0_bit: cdf::MV_CLASS0_BIT, |
| 719 | class0_fr: cdf::MV_CLASS0_FR, |
| 720 | class0_hp: cdf::MV_CLASS0_HP, |
| 721 | bit: cdf::MV_BIT, |
| 722 | fr: cdf::MV_FR, |
| 723 | hp: cdf::MV_HP, |
| 724 | sign: cdf::MV_SIGN, |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | /// Picks one of the four q-context variants of a coefficient table |
| 730 | /// (`crate::cdf`'s `_Q0`/`_Q1`/plain/`_Q3` constants), `q_ctx` already reduced |
| 731 | /// to 0..=3 by the caller. |
| 732 | pub(crate) fn pick<T: Copy>(q_ctx: usize, q0: T, q1: T, q2: T, q3: T) -> T { |
| 733 | match q_ctx { |
| 734 | 0 => q0, |
| 735 | 1 => q1, |
| 736 | 2 => q2, |
| 737 | _ => q3, |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | /// `reset_cdf_symbol_counter` (spec 7.20's `save_cdfs`, libaom |
| 742 | /// `av1_reset_cdf_symbol_counters`, `entropy.c`): every adapting table's last |
| 743 | /// entry is a symbol counter that slows [`update_cdf`](crate::msac)'s rate |
| 744 | /// down for a table's first 32 observations. A tile decoded with |
| 745 | /// `disable_frame_end_update_cdf == false` saves its *adapted* table into the |
| 746 | /// reference slots the frame refreshes, but the counters go back to zero |
| 747 | /// first -- forwarding the raw counts (this crate's bug until it was found: |
| 748 | /// the counts climbed unchecked, so every table forwarded across two or more |
| 749 | /// frames adapted *faster* than the real decoder's, a divergence too small to |
| 750 | /// flip any one symbol in a single hop but compounding into a visible |
| 751 | /// mismatch by the third). |
| 752 | fn reset1<const N: usize>(a: &mut [u16; N]) { |
| 753 | a[N - 1] = 0; |
| 754 | } |
| 755 | fn reset2<const N: usize, const M: usize>(a: &mut [[u16; N]; M]) { |
| 756 | a.iter_mut().for_each(reset1); |
| 757 | } |
| 758 | fn reset3<const N: usize, const M: usize, const K: usize>(a: &mut [[[u16; N]; M]; K]) { |
| 759 | a.iter_mut().for_each(reset2); |
| 760 | } |
| 761 | |
| 762 | /// [`reset3`] for a table whose ALPHABET grows with its first index: the |
| 763 | /// palette colour-index CDFs are `[u16; 9]` rows read as `[..=n]` with |
| 764 | /// `n = idx + 2`, so their symbol counter sits at index `n`, not `N - 1`. |
| 765 | fn reset_var_alphabet<const N: usize, const M: usize, const K: usize>( |
| 766 | a: &mut [[[u16; N]; M]; K], |
| 767 | ) { |
| 768 | for (idx, rows) in a.iter_mut().enumerate() { |
| 769 | for row in rows.iter_mut() { |
| 770 | row[idx + 2] = 0; |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | impl MvComponentCdfs { |
| 776 | fn reset_counts(&mut self) { |
| 777 | reset1(&mut self.class); |
| 778 | reset1(&mut self.class0_bit); |
| 779 | reset2(&mut self.class0_fr); |
| 780 | reset1(&mut self.class0_hp); |
| 781 | reset2(&mut self.bit); |
| 782 | reset1(&mut self.fr); |
| 783 | reset1(&mut self.hp); |
| 784 | reset1(&mut self.sign); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | impl Cdfs { |
| 789 | /// Zeroes every table's symbol counter (its last entry), leaving the |
| 790 | /// probabilities themselves untouched -- spec 7.20's `save_cdfs`. Call |
| 791 | /// this on the tile's own end-of-tile adapted state before storing it |
| 792 | /// into a reference slot for cross-frame forwarding; never on a table |
| 793 | /// still being read within the same tile. |
| 794 | pub(crate) fn reset_counts(&mut self) { |
| 795 | reset2(&mut self.partition_w128); |
| 796 | reset2(&mut self.partition_w64); |
| 797 | reset2(&mut self.partition_w32); |
| 798 | reset2(&mut self.txfm_partition); |
| 799 | reset2(&mut self.skip); |
| 800 | reset3(&mut self.kf_y_mode); |
| 801 | reset2(&mut self.uv_mode_no_cfl); |
| 802 | reset2(&mut self.uv_mode_cfl); |
| 803 | reset1(&mut self.cfl_sign); |
| 804 | reset2(&mut self.cfl_alpha); |
| 805 | reset2(&mut self.angle_delta); |
| 806 | reset2(&mut self.txb_skip_luma_16); |
| 807 | reset2(&mut self.txb_skip_luma_8); |
| 808 | reset2(&mut self.txb_skip_luma_4); |
| 809 | reset2(&mut self.txb_skip_chroma_8); |
| 810 | reset2(&mut self.txb_skip_chroma_4); |
| 811 | reset1(&mut self.eob_pt_256_luma); |
| 812 | reset1(&mut self.eob_pt_64_luma); |
| 813 | reset1(&mut self.eob_pt_64_chroma); |
| 814 | reset1(&mut self.eob_pt_16_chroma); |
| 815 | reset1(&mut self.eob_pt_16_luma); |
| 816 | reset1(&mut self.eob_pt_16_luma_class1); |
| 817 | reset1(&mut self.eob_pt_64_luma_class1); |
| 818 | reset1(&mut self.eob_pt_16_chroma_class1); |
| 819 | reset1(&mut self.eob_pt_64_chroma_class1); |
| 820 | reset1(&mut self.eob_pt_128_chroma_class1); |
| 821 | reset1(&mut self.eob_pt_128_luma_class1); |
| 822 | reset1(&mut self.eob_pt_32_chroma_class1); |
| 823 | reset1(&mut self.eob_pt_256_luma_class1); |
| 824 | reset1(&mut self.eob_pt_256_chroma_class1); |
| 825 | reset1(&mut self.eob_pt_512_luma_class1); |
| 826 | reset1(&mut self.eob_pt_512_chroma_class1); |
| 827 | reset1(&mut self.eob_pt_1024_luma_class1); |
| 828 | reset1(&mut self.eob_pt_1024_chroma_class1); |
| 829 | reset1(&mut self.eob_pt_32_luma); |
| 830 | reset1(&mut self.eob_pt_32_luma_class1); |
| 831 | reset2(&mut self.eob_extra_luma_16); |
| 832 | reset2(&mut self.eob_extra_luma_8); |
| 833 | reset2(&mut self.eob_extra_luma_4); |
| 834 | reset2(&mut self.eob_extra_chroma_8); |
| 835 | reset2(&mut self.eob_extra_chroma_4); |
| 836 | reset2(&mut self.base_luma_16); |
| 837 | reset2(&mut self.base_luma_8); |
| 838 | reset2(&mut self.base_luma_4); |
| 839 | reset2(&mut self.base_chroma_8); |
| 840 | reset2(&mut self.base_chroma_4); |
| 841 | reset2(&mut self.base_eob_luma_16); |
| 842 | reset2(&mut self.base_eob_luma_8); |
| 843 | reset2(&mut self.base_eob_luma_4); |
| 844 | reset2(&mut self.base_eob_chroma_8); |
| 845 | reset2(&mut self.base_eob_chroma_4); |
| 846 | reset2(&mut self.br_luma_16); |
| 847 | reset2(&mut self.br_luma_8); |
| 848 | reset2(&mut self.br_luma_4); |
| 849 | reset2(&mut self.br_chroma_8); |
| 850 | reset2(&mut self.br_chroma_4); |
| 851 | reset2(&mut self.partition_w16); |
| 852 | reset2(&mut self.partition_w8); |
| 853 | reset2(&mut self.txb_skip_luma_32); |
| 854 | reset2(&mut self.txb_skip_luma_64); |
| 855 | reset2(&mut self.txb_skip_chroma_16); |
| 856 | reset2(&mut self.txb_skip_chroma_32); |
| 857 | reset1(&mut self.eob_pt_1024_luma); |
| 858 | reset1(&mut self.eob_pt_1024_chroma); |
| 859 | reset1(&mut self.eob_pt_256_chroma); |
| 860 | reset1(&mut self.eob_pt_512_luma); |
| 861 | reset1(&mut self.eob_pt_128_chroma); |
| 862 | reset1(&mut self.eob_pt_512_chroma); |
| 863 | reset1(&mut self.eob_pt_128_luma); |
| 864 | reset1(&mut self.eob_pt_32_chroma); |
| 865 | reset2(&mut self.eob_extra_luma_32); |
| 866 | reset2(&mut self.eob_extra_luma_64); |
| 867 | reset2(&mut self.eob_extra_chroma_16); |
| 868 | reset2(&mut self.eob_extra_chroma_32); |
| 869 | reset2(&mut self.base_luma_32); |
| 870 | reset2(&mut self.base_luma_64); |
| 871 | reset2(&mut self.base_chroma_16); |
| 872 | reset2(&mut self.base_chroma_32); |
| 873 | reset2(&mut self.base_eob_luma_32); |
| 874 | reset2(&mut self.base_eob_luma_64); |
| 875 | reset2(&mut self.base_eob_chroma_16); |
| 876 | reset2(&mut self.base_eob_chroma_32); |
| 877 | reset2(&mut self.br_luma_32); |
| 878 | reset2(&mut self.br_chroma_16); |
| 879 | reset2(&mut self.br_chroma_32); |
| 880 | reset2(&mut self.dc_sign_luma); |
| 881 | reset2(&mut self.intra_tx_type_16); |
| 882 | reset2(&mut self.intra_tx_type_8); |
| 883 | reset2(&mut self.intra_tx_type_8_set1); |
| 884 | reset2(&mut self.intra_tx_type_4); |
| 885 | reset2(&mut self.intra_tx_type_4_set1); |
| 886 | reset1(&mut self.inter_tx_type_32); |
| 887 | reset1(&mut self.inter_tx_type_16); |
| 888 | reset1(&mut self.inter_tx_type_8); |
| 889 | reset1(&mut self.inter_tx_type_16_set2); |
| 890 | reset1(&mut self.inter_tx_type_8_set1); |
| 891 | reset1(&mut self.inter_tx_type_4); |
| 892 | reset1(&mut self.inter_tx_type_4_set1); |
| 893 | reset2(&mut self.dc_sign_chroma); |
| 894 | reset2(&mut self.intra_inter); |
| 895 | reset3(&mut self.single_ref); |
| 896 | reset2(&mut self.comp_mode); |
| 897 | reset2(&mut self.skip_mode); |
| 898 | reset2(&mut self.obmc); |
| 899 | reset2(&mut self.motion_mode); |
| 900 | // lane-interintra r1 (ii-flake-9): the ONE table this list missed -- |
| 901 | // an unreset counter saturates past 15 reads and slows update_cdf's |
| 902 | // rate to >>5 while libaom (reset per frame) stays at >>4; the rows |
| 903 | // drift a few counts apart and the gate flakes only on streams with |
| 904 | // enough switchable-filter reads. Audit: every other Cdfs field was |
| 905 | // covered (script-checked against the struct's field list). |
| 906 | reset2(&mut self.switchable_interp); |
| 907 | reset2(&mut self.interintra); |
| 908 | reset2(&mut self.interintra_mode); |
| 909 | reset2(&mut self.wedge_interintra); |
| 910 | reset2(&mut self.compound_type); |
| 911 | reset2(&mut self.wedge_idx); |
| 912 | reset2(&mut self.inter_compound_mode); |
| 913 | reset2(&mut self.comp_ref_type); |
| 914 | reset3(&mut self.uni_comp_ref); |
| 915 | reset3(&mut self.comp_ref); |
| 916 | reset3(&mut self.comp_bwdref); |
| 917 | reset2(&mut self.comp_group_idx); |
| 918 | reset2(&mut self.compound_idx); |
| 919 | reset2(&mut self.y_mode); |
| 920 | reset2(&mut self.new_mv); |
| 921 | reset2(&mut self.zero_mv); |
| 922 | reset2(&mut self.ref_mv); |
| 923 | reset2(&mut self.drl_mode); |
| 924 | reset1(&mut self.mv_joint); |
| 925 | reset1(&mut self.dv_joint); |
| 926 | self.dv_comp |
| 927 | .iter_mut() |
| 928 | .for_each(MvComponentCdfs::reset_counts); |
| 929 | self.mv_comp |
| 930 | .iter_mut() |
| 931 | .for_each(MvComponentCdfs::reset_counts); |
| 932 | reset2(&mut self.filter_intra); |
| 933 | reset1(&mut self.filter_intra_mode); |
| 934 | reset2(&mut self.tx_size_cat0); |
| 935 | reset2(&mut self.tx_size_cat1); |
| 936 | reset2(&mut self.tx_size_cat2); |
| 937 | reset2(&mut self.tx_size_cat3); |
| 938 | reset3(&mut self.palette_y_mode); |
| 939 | reset2(&mut self.palette_y_size); |
| 940 | reset2(&mut self.palette_uv_mode); |
| 941 | reset2(&mut self.palette_uv_size); |
| 942 | // lane-t900 r22 (class cdf-counter-not-reset): the two colour-index |
| 943 | // tables are the only VARIABLE-ALPHABET ones here -- the reader takes |
| 944 | // `[..=n]` of a `[u16; 9]` row, so `update_cdf`'s symbol counter lives |
| 945 | // at index `n` (= table index + 2), not at the array's last entry. |
| 946 | // `reset3` zeroed slot 8, which no `n < 8` row ever uses, so every |
| 947 | // palette colour-index row crossed a frame boundary with a SATURATED |
| 948 | // count (32) and adapted at rate 6 where libaom, counting from 0, |
| 949 | // adapts at rate 4: the first inter-frame palette block's map desynced |
| 950 | // at its third colour-index symbol (witness `palette_screen_witness.obu`, |
| 951 | // decode-order frame 3, mi(40,0), Y map (0,2)). |
| 952 | reset_var_alphabet(&mut self.palette_y_color_index); |
| 953 | reset_var_alphabet(&mut self.palette_uv_color_index); |
| 954 | reset1(&mut self.intrabc); |
| 955 | reset1(&mut self.restore_wiener); |
| 956 | reset1(&mut self.restore_sgrproj); |
| 957 | reset1(&mut self.restore_switchable); |
| 958 | reset2(&mut self.segment_id); |
| 959 | reset2(&mut self.segment_pred); |
| 960 | reset1(&mut self.delta_q); |
| 961 | reset1(&mut self.delta_lf); |
| 962 | reset2(&mut self.delta_lf_multi); |
| 963 | } |
| 964 | |
| 965 | /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and |
| 966 | /// `init_non_coeff_cdfs`), for coefficient q-context `q_ctx` (0..=3, spec |
| 967 | /// 8.3.2's `Get_Qctx`). The non-coefficient tables do not vary with the |
| 968 | /// quantizer, so they are the same for every `q_ctx`. |
| 969 | pub fn new(q_ctx: usize) -> Cdfs { |
| 970 | Cdfs { |
| 971 | partition_w128: cdf::PARTITION_W128, |
| 972 | partition_w64: cdf::PARTITION_W64, |
| 973 | partition_w32: cdf::PARTITION_W32, |
| 974 | skip: cdf::SKIP, |
| 975 | kf_y_mode: cdf::KF_Y_MODE, |
| 976 | uv_mode_no_cfl: cdf::UV_MODE_NO_CFL, |
| 977 | uv_mode_cfl: cdf::UV_MODE_CFL, |
| 978 | cfl_sign: cdf::CFL_SIGN, |
| 979 | cfl_alpha: cdf::CFL_ALPHA, |
| 980 | angle_delta: cdf::ANGLE_DELTA, |
| 981 | txb_skip_luma_16: pick( |
| 982 | q_ctx, |
| 983 | cdf::TXB_SKIP_LUMA_16_Q0_CTX, |
| 984 | cdf::TXB_SKIP_LUMA_16_Q1_CTX, |
| 985 | cdf::TXB_SKIP_LUMA_16_CTX, |
| 986 | cdf::TXB_SKIP_LUMA_16_Q3_CTX, |
| 987 | ), |
| 988 | txb_skip_luma_8: pick( |
| 989 | q_ctx, |
| 990 | cdf::TXB_SKIP_LUMA_8_Q0_CTX, |
| 991 | cdf::TXB_SKIP_LUMA_8_Q1_CTX, |
| 992 | cdf::TXB_SKIP_LUMA_8_CTX, |
| 993 | cdf::TXB_SKIP_LUMA_8_Q3_CTX, |
| 994 | ), |
| 995 | txb_skip_luma_4: pick( |
| 996 | q_ctx, |
| 997 | cdf::TXB_SKIP_LUMA_4_Q0_CTX, |
| 998 | cdf::TXB_SKIP_LUMA_4_Q1_CTX, |
| 999 | cdf::TXB_SKIP_LUMA_4_CTX, |
| 1000 | cdf::TXB_SKIP_LUMA_4_Q3_CTX, |
| 1001 | ), |
| 1002 | txb_skip_chroma_8: pick( |
| 1003 | q_ctx, |
| 1004 | cdf::TXB_SKIP_CHROMA_8_Q0, |
| 1005 | cdf::TXB_SKIP_CHROMA_8_Q1, |
| 1006 | cdf::TXB_SKIP_CHROMA_8, |
| 1007 | cdf::TXB_SKIP_CHROMA_8_Q3, |
| 1008 | ), |
| 1009 | txb_skip_chroma_4: pick( |
| 1010 | q_ctx, |
| 1011 | cdf::TXB_SKIP_CHROMA_4_Q0, |
| 1012 | cdf::TXB_SKIP_CHROMA_4_Q1, |
| 1013 | cdf::TXB_SKIP_CHROMA_4, |
| 1014 | cdf::TXB_SKIP_CHROMA_4_Q3, |
| 1015 | ), |
| 1016 | eob_pt_256_luma: pick( |
| 1017 | q_ctx, |
| 1018 | cdf::EOB_PT_256_LUMA_Q0, |
| 1019 | cdf::EOB_PT_256_LUMA_Q1, |
| 1020 | cdf::EOB_PT_256_LUMA, |
| 1021 | cdf::EOB_PT_256_LUMA_Q3, |
| 1022 | ), |
| 1023 | eob_pt_64_luma: pick( |
| 1024 | q_ctx, |
| 1025 | cdf::EOB_PT_64_LUMA_Q0, |
| 1026 | cdf::EOB_PT_64_LUMA_Q1, |
| 1027 | cdf::EOB_PT_64_LUMA, |
| 1028 | cdf::EOB_PT_64_LUMA_Q3, |
| 1029 | ), |
| 1030 | eob_pt_64_chroma: pick( |
| 1031 | q_ctx, |
| 1032 | cdf::EOB_PT_64_CHROMA_Q0, |
| 1033 | cdf::EOB_PT_64_CHROMA_Q1, |
| 1034 | cdf::EOB_PT_64_CHROMA, |
| 1035 | cdf::EOB_PT_64_CHROMA_Q3, |
| 1036 | ), |
| 1037 | eob_pt_16_chroma: pick( |
| 1038 | q_ctx, |
| 1039 | cdf::EOB_PT_16_CHROMA_Q0, |
| 1040 | cdf::EOB_PT_16_CHROMA_Q1, |
| 1041 | cdf::EOB_PT_16_CHROMA, |
| 1042 | cdf::EOB_PT_16_CHROMA_Q3, |
| 1043 | ), |
| 1044 | eob_pt_16_luma: pick( |
| 1045 | q_ctx, |
| 1046 | cdf::EOB_PT_16_LUMA_Q0, |
| 1047 | cdf::EOB_PT_16_LUMA_Q1, |
| 1048 | cdf::EOB_PT_16_LUMA, |
| 1049 | cdf::EOB_PT_16_LUMA_Q3, |
| 1050 | ), |
| 1051 | eob_pt_16_luma_class1: pick( |
| 1052 | q_ctx, |
| 1053 | cdf::EOB_PT_16_LUMA_CLASS1_Q0, |
| 1054 | cdf::EOB_PT_16_LUMA_CLASS1_Q1, |
| 1055 | cdf::EOB_PT_16_LUMA_CLASS1, |
| 1056 | cdf::EOB_PT_16_LUMA_CLASS1_Q3, |
| 1057 | ), |
| 1058 | eob_pt_32_luma: pick( |
| 1059 | q_ctx, |
| 1060 | cdf::EOB_PT_32_LUMA_Q0, |
| 1061 | cdf::EOB_PT_32_LUMA_Q1, |
| 1062 | cdf::EOB_PT_32_LUMA, |
| 1063 | cdf::EOB_PT_32_LUMA_Q3, |
| 1064 | ), |
| 1065 | eob_pt_32_luma_class1: pick( |
| 1066 | q_ctx, |
| 1067 | cdf::EOB_PT_32_LUMA_CLASS1_Q0, |
| 1068 | cdf::EOB_PT_32_LUMA_CLASS1_Q1, |
| 1069 | cdf::EOB_PT_32_LUMA_CLASS1, |
| 1070 | cdf::EOB_PT_32_LUMA_CLASS1_Q3, |
| 1071 | ), |
| 1072 | eob_pt_64_luma_class1: pick( |
| 1073 | q_ctx, |
| 1074 | cdf::EOB_PT_64_LUMA_CLASS1_Q0, |
| 1075 | cdf::EOB_PT_64_LUMA_CLASS1_Q1, |
| 1076 | cdf::EOB_PT_64_LUMA_CLASS1, |
| 1077 | cdf::EOB_PT_64_LUMA_CLASS1_Q3, |
| 1078 | ), |
| 1079 | eob_pt_16_chroma_class1: pick( |
| 1080 | q_ctx, |
| 1081 | cdf::EOB_PT_16_CHROMA_CLASS1_Q0, |
| 1082 | cdf::EOB_PT_16_CHROMA_CLASS1_Q1, |
| 1083 | cdf::EOB_PT_16_CHROMA_CLASS1, |
| 1084 | cdf::EOB_PT_16_CHROMA_CLASS1_Q3, |
| 1085 | ), |
| 1086 | eob_pt_64_chroma_class1: pick( |
| 1087 | q_ctx, |
| 1088 | cdf::EOB_PT_64_CHROMA_CLASS1_Q0, |
| 1089 | cdf::EOB_PT_64_CHROMA_CLASS1_Q1, |
| 1090 | cdf::EOB_PT_64_CHROMA_CLASS1, |
| 1091 | cdf::EOB_PT_64_CHROMA_CLASS1_Q3, |
| 1092 | ), |
| 1093 | eob_pt_128_chroma_class1: pick( |
| 1094 | q_ctx, |
| 1095 | cdf::EOB_PT_128_CHROMA_CLASS1_Q0, |
| 1096 | cdf::EOB_PT_128_CHROMA_CLASS1_Q1, |
| 1097 | cdf::EOB_PT_128_CHROMA_CLASS1, |
| 1098 | cdf::EOB_PT_128_CHROMA_CLASS1_Q3, |
| 1099 | ), |
| 1100 | eob_pt_128_luma_class1: pick( |
| 1101 | q_ctx, |
| 1102 | cdf::EOB_PT_128_LUMA_CLASS1_Q0, |
| 1103 | cdf::EOB_PT_128_LUMA_CLASS1_Q1, |
| 1104 | cdf::EOB_PT_128_LUMA_CLASS1, |
| 1105 | cdf::EOB_PT_128_LUMA_CLASS1_Q3, |
| 1106 | ), |
| 1107 | eob_pt_32_chroma_class1: pick( |
| 1108 | q_ctx, |
| 1109 | cdf::EOB_PT_32_CHROMA_CLASS1_Q0, |
| 1110 | cdf::EOB_PT_32_CHROMA_CLASS1_Q1, |
| 1111 | cdf::EOB_PT_32_CHROMA_CLASS1, |
| 1112 | cdf::EOB_PT_32_CHROMA_CLASS1_Q3, |
| 1113 | ), |
| 1114 | eob_pt_256_luma_class1: pick( |
| 1115 | q_ctx, |
| 1116 | cdf::EOB_PT_256_LUMA_CLASS1_Q0, |
| 1117 | cdf::EOB_PT_256_LUMA_CLASS1_Q1, |
| 1118 | cdf::EOB_PT_256_LUMA_CLASS1, |
| 1119 | cdf::EOB_PT_256_LUMA_CLASS1_Q3, |
| 1120 | ), |
| 1121 | eob_pt_256_chroma_class1: pick( |
| 1122 | q_ctx, |
| 1123 | cdf::EOB_PT_256_CHROMA_CLASS1_Q0, |
| 1124 | cdf::EOB_PT_256_CHROMA_CLASS1_Q1, |
| 1125 | cdf::EOB_PT_256_CHROMA_CLASS1, |
| 1126 | cdf::EOB_PT_256_CHROMA_CLASS1_Q3, |
| 1127 | ), |
| 1128 | eob_pt_512_luma_class1: pick( |
| 1129 | q_ctx, |
| 1130 | cdf::EOB_PT_512_LUMA_CLASS1_Q0, |
| 1131 | cdf::EOB_PT_512_LUMA_CLASS1_Q1, |
| 1132 | cdf::EOB_PT_512_LUMA_CLASS1, |
| 1133 | cdf::EOB_PT_512_LUMA_CLASS1_Q3, |
| 1134 | ), |
| 1135 | eob_pt_512_chroma_class1: pick( |
| 1136 | q_ctx, |
| 1137 | cdf::EOB_PT_512_CHROMA_CLASS1_Q0, |
| 1138 | cdf::EOB_PT_512_CHROMA_CLASS1_Q1, |
| 1139 | cdf::EOB_PT_512_CHROMA_CLASS1, |
| 1140 | cdf::EOB_PT_512_CHROMA_CLASS1_Q3, |
| 1141 | ), |
| 1142 | eob_pt_1024_luma_class1: pick( |
| 1143 | q_ctx, |
| 1144 | cdf::EOB_PT_1024_LUMA_CLASS1_Q0, |
| 1145 | cdf::EOB_PT_1024_LUMA_CLASS1_Q1, |
| 1146 | cdf::EOB_PT_1024_LUMA_CLASS1, |
| 1147 | cdf::EOB_PT_1024_LUMA_CLASS1_Q3, |
| 1148 | ), |
| 1149 | eob_pt_1024_chroma_class1: pick( |
| 1150 | q_ctx, |
| 1151 | cdf::EOB_PT_1024_CHROMA_CLASS1_Q0, |
| 1152 | cdf::EOB_PT_1024_CHROMA_CLASS1_Q1, |
| 1153 | cdf::EOB_PT_1024_CHROMA_CLASS1, |
| 1154 | cdf::EOB_PT_1024_CHROMA_CLASS1_Q3, |
| 1155 | ), |
| 1156 | eob_extra_luma_16: pick( |
| 1157 | q_ctx, |
| 1158 | cdf::EOB_EXTRA_LUMA_16_Q0, |
| 1159 | cdf::EOB_EXTRA_LUMA_16_Q1, |
| 1160 | cdf::EOB_EXTRA_LUMA_16, |
| 1161 | cdf::EOB_EXTRA_LUMA_16_Q3, |
| 1162 | ), |
| 1163 | eob_extra_luma_8: pick( |
| 1164 | q_ctx, |
| 1165 | cdf::EOB_EXTRA_LUMA_8_Q0, |
| 1166 | cdf::EOB_EXTRA_LUMA_8_Q1, |
| 1167 | cdf::EOB_EXTRA_LUMA_8, |
| 1168 | cdf::EOB_EXTRA_LUMA_8_Q3, |
| 1169 | ), |
| 1170 | eob_extra_luma_4: pick( |
| 1171 | q_ctx, |
| 1172 | cdf::EOB_EXTRA_LUMA_4_Q0, |
| 1173 | cdf::EOB_EXTRA_LUMA_4_Q1, |
| 1174 | cdf::EOB_EXTRA_LUMA_4, |
| 1175 | cdf::EOB_EXTRA_LUMA_4_Q3, |
| 1176 | ), |
| 1177 | eob_extra_chroma_8: pick( |
| 1178 | q_ctx, |
| 1179 | cdf::EOB_EXTRA_CHROMA_8_Q0, |
| 1180 | cdf::EOB_EXTRA_CHROMA_8_Q1, |
| 1181 | cdf::EOB_EXTRA_CHROMA_8, |
| 1182 | cdf::EOB_EXTRA_CHROMA_8_Q3, |
| 1183 | ), |
| 1184 | eob_extra_chroma_4: pick( |
| 1185 | q_ctx, |
| 1186 | cdf::EOB_EXTRA_CHROMA_4_Q0, |
| 1187 | cdf::EOB_EXTRA_CHROMA_4_Q1, |
| 1188 | cdf::EOB_EXTRA_CHROMA_4, |
| 1189 | cdf::EOB_EXTRA_CHROMA_4_Q3, |
| 1190 | ), |
| 1191 | base_luma_16: pick( |
| 1192 | q_ctx, |
| 1193 | cdf::COEFF_BASE_LUMA_16_Q0, |
| 1194 | cdf::COEFF_BASE_LUMA_16_Q1, |
| 1195 | cdf::COEFF_BASE_LUMA_16, |
| 1196 | cdf::COEFF_BASE_LUMA_16_Q3, |
| 1197 | ), |
| 1198 | base_luma_8: pick( |
| 1199 | q_ctx, |
| 1200 | cdf::COEFF_BASE_LUMA_8_Q0, |
| 1201 | cdf::COEFF_BASE_LUMA_8_Q1, |
| 1202 | cdf::COEFF_BASE_LUMA_8, |
| 1203 | cdf::COEFF_BASE_LUMA_8_Q3, |
| 1204 | ), |
| 1205 | base_luma_4: pick( |
| 1206 | q_ctx, |
| 1207 | cdf::COEFF_BASE_LUMA_4_Q0, |
| 1208 | cdf::COEFF_BASE_LUMA_4_Q1, |
| 1209 | cdf::COEFF_BASE_LUMA_4, |
| 1210 | cdf::COEFF_BASE_LUMA_4_Q3, |
| 1211 | ), |
| 1212 | base_chroma_8: pick( |
| 1213 | q_ctx, |
| 1214 | cdf::COEFF_BASE_CHROMA_8_Q0, |
| 1215 | cdf::COEFF_BASE_CHROMA_8_Q1, |
| 1216 | cdf::COEFF_BASE_CHROMA_8, |
| 1217 | cdf::COEFF_BASE_CHROMA_8_Q3, |
| 1218 | ), |
| 1219 | base_chroma_4: pick( |
| 1220 | q_ctx, |
| 1221 | cdf::COEFF_BASE_CHROMA_4_Q0, |
| 1222 | cdf::COEFF_BASE_CHROMA_4_Q1, |
| 1223 | cdf::COEFF_BASE_CHROMA_4, |
| 1224 | cdf::COEFF_BASE_CHROMA_4_Q3, |
| 1225 | ), |
| 1226 | base_eob_luma_16: pick( |
| 1227 | q_ctx, |
| 1228 | cdf::COEFF_BASE_EOB_LUMA_16_Q0, |
| 1229 | cdf::COEFF_BASE_EOB_LUMA_16_Q1, |
| 1230 | cdf::COEFF_BASE_EOB_LUMA_16, |
| 1231 | cdf::COEFF_BASE_EOB_LUMA_16_Q3, |
| 1232 | ), |
| 1233 | base_eob_luma_8: pick( |
| 1234 | q_ctx, |
| 1235 | cdf::COEFF_BASE_EOB_LUMA_8_Q0, |
| 1236 | cdf::COEFF_BASE_EOB_LUMA_8_Q1, |
| 1237 | cdf::COEFF_BASE_EOB_LUMA_8, |
| 1238 | cdf::COEFF_BASE_EOB_LUMA_8_Q3, |
| 1239 | ), |
| 1240 | base_eob_luma_4: pick( |
| 1241 | q_ctx, |
| 1242 | cdf::COEFF_BASE_EOB_LUMA_4_Q0, |
| 1243 | cdf::COEFF_BASE_EOB_LUMA_4_Q1, |
| 1244 | cdf::COEFF_BASE_EOB_LUMA_4, |
| 1245 | cdf::COEFF_BASE_EOB_LUMA_4_Q3, |
| 1246 | ), |
| 1247 | base_eob_chroma_8: pick( |
| 1248 | q_ctx, |
| 1249 | cdf::COEFF_BASE_EOB_CHROMA_8_Q0, |
| 1250 | cdf::COEFF_BASE_EOB_CHROMA_8_Q1, |
| 1251 | cdf::COEFF_BASE_EOB_CHROMA_8, |
| 1252 | cdf::COEFF_BASE_EOB_CHROMA_8_Q3, |
| 1253 | ), |
| 1254 | base_eob_chroma_4: pick( |
| 1255 | q_ctx, |
| 1256 | cdf::COEFF_BASE_EOB_CHROMA_4_Q0, |
| 1257 | cdf::COEFF_BASE_EOB_CHROMA_4_Q1, |
| 1258 | cdf::COEFF_BASE_EOB_CHROMA_4, |
| 1259 | cdf::COEFF_BASE_EOB_CHROMA_4_Q3, |
| 1260 | ), |
| 1261 | br_luma_16: pick( |
| 1262 | q_ctx, |
| 1263 | cdf::COEFF_BR_LUMA_16_Q0, |
| 1264 | cdf::COEFF_BR_LUMA_16_Q1, |
| 1265 | cdf::COEFF_BR_LUMA_16, |
| 1266 | cdf::COEFF_BR_LUMA_16_Q3, |
| 1267 | ), |
| 1268 | br_luma_8: pick( |
| 1269 | q_ctx, |
| 1270 | cdf::COEFF_BR_LUMA_8_Q0, |
| 1271 | cdf::COEFF_BR_LUMA_8_Q1, |
| 1272 | cdf::COEFF_BR_LUMA_8, |
| 1273 | cdf::COEFF_BR_LUMA_8_Q3, |
| 1274 | ), |
| 1275 | br_luma_4: pick( |
| 1276 | q_ctx, |
| 1277 | cdf::COEFF_BR_LUMA_4_Q0, |
| 1278 | cdf::COEFF_BR_LUMA_4_Q1, |
| 1279 | cdf::COEFF_BR_LUMA_4, |
| 1280 | cdf::COEFF_BR_LUMA_4_Q3, |
| 1281 | ), |
| 1282 | br_chroma_8: pick( |
| 1283 | q_ctx, |
| 1284 | cdf::COEFF_BR_CHROMA_8_Q0, |
| 1285 | cdf::COEFF_BR_CHROMA_8_Q1, |
| 1286 | cdf::COEFF_BR_CHROMA_8, |
| 1287 | cdf::COEFF_BR_CHROMA_8_Q3, |
| 1288 | ), |
| 1289 | br_chroma_4: pick( |
| 1290 | q_ctx, |
| 1291 | cdf::COEFF_BR_CHROMA_4_Q0, |
| 1292 | cdf::COEFF_BR_CHROMA_4_Q1, |
| 1293 | cdf::COEFF_BR_CHROMA_4, |
| 1294 | cdf::COEFF_BR_CHROMA_4_Q3, |
| 1295 | ), |
| 1296 | partition_w16: cdf::PARTITION_W16, |
| 1297 | partition_w8: cdf::PARTITION_W8, |
| 1298 | txb_skip_luma_32: pick( |
| 1299 | q_ctx, |
| 1300 | cdf::TXB_SKIP_LUMA_32_Q0_CTX, |
| 1301 | cdf::TXB_SKIP_LUMA_32_Q1_CTX, |
| 1302 | cdf::TXB_SKIP_LUMA_32_CTX, |
| 1303 | cdf::TXB_SKIP_LUMA_32_Q3_CTX, |
| 1304 | ), |
| 1305 | txb_skip_luma_64: pick( |
| 1306 | q_ctx, |
| 1307 | cdf::TXB_SKIP_LUMA_64_Q0_CTX, |
| 1308 | cdf::TXB_SKIP_LUMA_64_Q1_CTX, |
| 1309 | cdf::TXB_SKIP_LUMA_64_CTX, |
| 1310 | cdf::TXB_SKIP_LUMA_64_Q3_CTX, |
| 1311 | ), |
| 1312 | txb_skip_chroma_16: pick( |
| 1313 | q_ctx, |
| 1314 | cdf::TXB_SKIP_CHROMA_16_Q0, |
| 1315 | cdf::TXB_SKIP_CHROMA_16_Q1, |
| 1316 | cdf::TXB_SKIP_CHROMA_16, |
| 1317 | cdf::TXB_SKIP_CHROMA_16_Q3, |
| 1318 | ), |
| 1319 | txb_skip_chroma_32: { |
| 1320 | let small = pick( |
| 1321 | q_ctx, |
| 1322 | cdf::TXB_SKIP_CHROMA_32_Q0, |
| 1323 | cdf::TXB_SKIP_CHROMA_32_Q1, |
| 1324 | cdf::TXB_SKIP_CHROMA_32, |
| 1325 | cdf::TXB_SKIP_CHROMA_32_Q3, |
| 1326 | ); |
| 1327 | let big = pick( |
| 1328 | q_ctx, |
| 1329 | cdf::TXB_SKIP_CHROMA_32_BIG_Q0, |
| 1330 | cdf::TXB_SKIP_CHROMA_32_BIG_Q1, |
| 1331 | cdf::TXB_SKIP_CHROMA_32_BIG, |
| 1332 | cdf::TXB_SKIP_CHROMA_32_BIG_Q3, |
| 1333 | ); |
| 1334 | [small[0], small[1], small[2], big[0], big[1], big[2]] |
| 1335 | }, |
| 1336 | eob_pt_1024_luma: pick( |
| 1337 | q_ctx, |
| 1338 | cdf::EOB_PT_1024_LUMA_Q0, |
| 1339 | cdf::EOB_PT_1024_LUMA_Q1, |
| 1340 | cdf::EOB_PT_1024_LUMA, |
| 1341 | cdf::EOB_PT_1024_LUMA_Q3, |
| 1342 | ), |
| 1343 | eob_pt_1024_chroma: pick( |
| 1344 | q_ctx, |
| 1345 | cdf::EOB_PT_1024_CHROMA_Q0, |
| 1346 | cdf::EOB_PT_1024_CHROMA_Q1, |
| 1347 | cdf::EOB_PT_1024_CHROMA, |
| 1348 | cdf::EOB_PT_1024_CHROMA_Q3, |
| 1349 | ), |
| 1350 | eob_pt_256_chroma: pick( |
| 1351 | q_ctx, |
| 1352 | cdf::EOB_PT_256_CHROMA_Q0, |
| 1353 | cdf::EOB_PT_256_CHROMA_Q1, |
| 1354 | cdf::EOB_PT_256_CHROMA, |
| 1355 | cdf::EOB_PT_256_CHROMA_Q3, |
| 1356 | ), |
| 1357 | eob_pt_512_luma: pick( |
| 1358 | q_ctx, |
| 1359 | cdf::EOB_PT_512_LUMA_Q0, |
| 1360 | cdf::EOB_PT_512_LUMA_Q1, |
| 1361 | cdf::EOB_PT_512_LUMA, |
| 1362 | cdf::EOB_PT_512_LUMA_Q3, |
| 1363 | ), |
| 1364 | eob_pt_128_chroma: pick( |
| 1365 | q_ctx, |
| 1366 | cdf::EOB_PT_128_CHROMA_Q0, |
| 1367 | cdf::EOB_PT_128_CHROMA_Q1, |
| 1368 | cdf::EOB_PT_128_CHROMA, |
| 1369 | cdf::EOB_PT_128_CHROMA_Q3, |
| 1370 | ), |
| 1371 | eob_pt_128_luma: pick( |
| 1372 | q_ctx, |
| 1373 | cdf::EOB_PT_128_LUMA_Q0, |
| 1374 | cdf::EOB_PT_128_LUMA_Q1, |
| 1375 | cdf::EOB_PT_128_LUMA, |
| 1376 | cdf::EOB_PT_128_LUMA_Q3, |
| 1377 | ), |
| 1378 | eob_pt_32_chroma: pick( |
| 1379 | q_ctx, |
| 1380 | cdf::EOB_PT_32_CHROMA_Q0, |
| 1381 | cdf::EOB_PT_32_CHROMA_Q1, |
| 1382 | cdf::EOB_PT_32_CHROMA, |
| 1383 | cdf::EOB_PT_32_CHROMA_Q3, |
| 1384 | ), |
| 1385 | eob_pt_512_chroma: pick( |
| 1386 | q_ctx, |
| 1387 | cdf::EOB_PT_512_CHROMA_Q0, |
| 1388 | cdf::EOB_PT_512_CHROMA_Q1, |
| 1389 | cdf::EOB_PT_512_CHROMA, |
| 1390 | cdf::EOB_PT_512_CHROMA_Q3, |
| 1391 | ), |
| 1392 | eob_extra_luma_32: pick( |
| 1393 | q_ctx, |
| 1394 | cdf::EOB_EXTRA_LUMA_32_Q0, |
| 1395 | cdf::EOB_EXTRA_LUMA_32_Q1, |
| 1396 | cdf::EOB_EXTRA_LUMA_32, |
| 1397 | cdf::EOB_EXTRA_LUMA_32_Q3, |
| 1398 | ), |
| 1399 | eob_extra_luma_64: pick( |
| 1400 | q_ctx, |
| 1401 | cdf::EOB_EXTRA_LUMA_64_Q0, |
| 1402 | cdf::EOB_EXTRA_LUMA_64_Q1, |
| 1403 | cdf::EOB_EXTRA_LUMA_64, |
| 1404 | cdf::EOB_EXTRA_LUMA_64_Q3, |
| 1405 | ), |
| 1406 | eob_extra_chroma_16: pick( |
| 1407 | q_ctx, |
| 1408 | cdf::EOB_EXTRA_CHROMA_16_Q0, |
| 1409 | cdf::EOB_EXTRA_CHROMA_16_Q1, |
| 1410 | cdf::EOB_EXTRA_CHROMA_16, |
| 1411 | cdf::EOB_EXTRA_CHROMA_16_Q3, |
| 1412 | ), |
| 1413 | eob_extra_chroma_32: pick( |
| 1414 | q_ctx, |
| 1415 | cdf::EOB_EXTRA_CHROMA_32_Q0, |
| 1416 | cdf::EOB_EXTRA_CHROMA_32_Q1, |
| 1417 | cdf::EOB_EXTRA_CHROMA_32, |
| 1418 | cdf::EOB_EXTRA_CHROMA_32_Q3, |
| 1419 | ), |
| 1420 | base_luma_32: pick( |
| 1421 | q_ctx, |
| 1422 | cdf::COEFF_BASE_LUMA_32_Q0, |
| 1423 | cdf::COEFF_BASE_LUMA_32_Q1, |
| 1424 | cdf::COEFF_BASE_LUMA_32, |
| 1425 | cdf::COEFF_BASE_LUMA_32_Q3, |
| 1426 | ), |
| 1427 | base_luma_64: pick( |
| 1428 | q_ctx, |
| 1429 | cdf::COEFF_BASE_LUMA_64_Q0, |
| 1430 | cdf::COEFF_BASE_LUMA_64_Q1, |
| 1431 | cdf::COEFF_BASE_LUMA_64, |
| 1432 | cdf::COEFF_BASE_LUMA_64_Q3, |
| 1433 | ), |
| 1434 | base_chroma_16: pick( |
| 1435 | q_ctx, |
| 1436 | cdf::COEFF_BASE_CHROMA_16_Q0, |
| 1437 | cdf::COEFF_BASE_CHROMA_16_Q1, |
| 1438 | cdf::COEFF_BASE_CHROMA_16, |
| 1439 | cdf::COEFF_BASE_CHROMA_16_Q3, |
| 1440 | ), |
| 1441 | base_chroma_32: pick( |
| 1442 | q_ctx, |
| 1443 | cdf::COEFF_BASE_CHROMA_32_Q0, |
| 1444 | cdf::COEFF_BASE_CHROMA_32_Q1, |
| 1445 | cdf::COEFF_BASE_CHROMA_32, |
| 1446 | cdf::COEFF_BASE_CHROMA_32_Q3, |
| 1447 | ), |
| 1448 | base_eob_luma_32: pick( |
| 1449 | q_ctx, |
| 1450 | cdf::COEFF_BASE_EOB_LUMA_32_Q0, |
| 1451 | cdf::COEFF_BASE_EOB_LUMA_32_Q1, |
| 1452 | cdf::COEFF_BASE_EOB_LUMA_32, |
| 1453 | cdf::COEFF_BASE_EOB_LUMA_32_Q3, |
| 1454 | ), |
| 1455 | base_eob_luma_64: pick( |
| 1456 | q_ctx, |
| 1457 | cdf::COEFF_BASE_EOB_LUMA_64_Q0, |
| 1458 | cdf::COEFF_BASE_EOB_LUMA_64_Q1, |
| 1459 | cdf::COEFF_BASE_EOB_LUMA_64, |
| 1460 | cdf::COEFF_BASE_EOB_LUMA_64_Q3, |
| 1461 | ), |
| 1462 | base_eob_chroma_16: pick( |
| 1463 | q_ctx, |
| 1464 | cdf::COEFF_BASE_EOB_CHROMA_16_Q0, |
| 1465 | cdf::COEFF_BASE_EOB_CHROMA_16_Q1, |
| 1466 | cdf::COEFF_BASE_EOB_CHROMA_16, |
| 1467 | cdf::COEFF_BASE_EOB_CHROMA_16_Q3, |
| 1468 | ), |
| 1469 | base_eob_chroma_32: pick( |
| 1470 | q_ctx, |
| 1471 | cdf::COEFF_BASE_EOB_CHROMA_32_Q0, |
| 1472 | cdf::COEFF_BASE_EOB_CHROMA_32_Q1, |
| 1473 | cdf::COEFF_BASE_EOB_CHROMA_32, |
| 1474 | cdf::COEFF_BASE_EOB_CHROMA_32_Q3, |
| 1475 | ), |
| 1476 | br_luma_32: pick( |
| 1477 | q_ctx, |
| 1478 | cdf::COEFF_BR_LUMA_32_Q0, |
| 1479 | cdf::COEFF_BR_LUMA_32_Q1, |
| 1480 | cdf::COEFF_BR_LUMA_32, |
| 1481 | cdf::COEFF_BR_LUMA_32_Q3, |
| 1482 | ), |
| 1483 | br_chroma_16: pick( |
| 1484 | q_ctx, |
| 1485 | cdf::COEFF_BR_CHROMA_16_Q0, |
| 1486 | cdf::COEFF_BR_CHROMA_16_Q1, |
| 1487 | cdf::COEFF_BR_CHROMA_16, |
| 1488 | cdf::COEFF_BR_CHROMA_16_Q3, |
| 1489 | ), |
| 1490 | br_chroma_32: pick( |
| 1491 | q_ctx, |
| 1492 | cdf::COEFF_BR_CHROMA_32_Q0, |
| 1493 | cdf::COEFF_BR_CHROMA_32_Q1, |
| 1494 | cdf::COEFF_BR_CHROMA_32, |
| 1495 | cdf::COEFF_BR_CHROMA_32_Q3, |
| 1496 | ), |
| 1497 | dc_sign_luma: cdf::DC_SIGN_LUMA, |
| 1498 | intra_tx_type_16: cdf::INTRA_TX_TYPE_SET2_16, |
| 1499 | intra_tx_type_8: cdf::INTRA_TX_TYPE_SET2_8, |
| 1500 | intra_tx_type_8_set1: cdf::INTRA_TX_TYPE_SET1_8, |
| 1501 | intra_tx_type_4: cdf::INTRA_TX_TYPE_SET2_8, |
| 1502 | intra_tx_type_4_set1: cdf::INTRA_TX_TYPE_SET1_4, |
| 1503 | inter_tx_type_32: cdf::INTER_TX_TYPE_SET3_32, |
| 1504 | inter_tx_type_16: cdf::INTER_TX_TYPE_SET3_16, |
| 1505 | inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8, |
| 1506 | inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16, |
| 1507 | inter_tx_type_8_set1: cdf::INTER_TX_TYPE_SET1_8, |
| 1508 | inter_tx_type_4: cdf::INTER_TX_TYPE_SET3_4, |
| 1509 | inter_tx_type_4_set1: cdf::INTER_TX_TYPE_SET1_4, |
| 1510 | dc_sign_chroma: cdf::DC_SIGN_CHROMA, |
| 1511 | intra_inter: cdf::INTRA_INTER, |
| 1512 | single_ref: cdf::SINGLE_REF, |
| 1513 | comp_mode: cdf::COMP_MODE, |
| 1514 | inter_compound_mode: cdf::INTER_COMPOUND_MODE, |
| 1515 | comp_ref_type: cdf::COMP_REF_TYPE, |
| 1516 | uni_comp_ref: cdf::UNI_COMP_REF, |
| 1517 | comp_ref: cdf::COMP_REF, |
| 1518 | comp_bwdref: cdf::COMP_BWDREF, |
| 1519 | txfm_partition: cdf::TXFM_PARTITION, |
| 1520 | skip_mode: cdf::SKIP_MODE, |
| 1521 | obmc: cdf::OBMC, |
| 1522 | motion_mode: cdf::MOTION_MODE, |
| 1523 | interintra: cdf::INTERINTRA, |
| 1524 | interintra_mode: cdf::INTERINTRA_MODE, |
| 1525 | wedge_interintra: cdf::WEDGE_INTERINTRA, |
| 1526 | compound_type: cdf::COMPOUND_TYPE, |
| 1527 | wedge_idx: cdf::WEDGE_IDX, |
| 1528 | comp_group_idx: cdf::COMP_GROUP_IDX, |
| 1529 | compound_idx: cdf::COMPOUND_IDX, |
| 1530 | y_mode: cdf::Y_MODE, |
| 1531 | new_mv: cdf::NEW_MV, |
| 1532 | zero_mv: cdf::ZERO_MV, |
| 1533 | ref_mv: cdf::REF_MV, |
| 1534 | drl_mode: cdf::DRL_MODE, |
| 1535 | mv_joint: cdf::MV_JOINT, |
| 1536 | mv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], |
| 1537 | dv_joint: cdf::MV_JOINT, |
| 1538 | dv_comp: [MvComponentCdfs::new(), MvComponentCdfs::new()], |
| 1539 | filter_intra: cdf::FILTER_INTRA, |
| 1540 | filter_intra_mode: cdf::FILTER_INTRA_MODE, |
| 1541 | tx_size_cat0: cdf::TX_SIZE_CAT0, |
| 1542 | tx_size_cat1: cdf::TX_SIZE_CAT1, |
| 1543 | tx_size_cat2: cdf::TX_SIZE_CAT2, |
| 1544 | tx_size_cat3: cdf::TX_SIZE_CAT3, |
| 1545 | switchable_interp: cdf::SWITCHABLE_INTERP, |
| 1546 | palette_y_mode: cdf::PALETTE_Y_MODE, |
| 1547 | palette_y_size: cdf::PALETTE_Y_SIZE, |
| 1548 | palette_uv_mode: cdf::PALETTE_UV_MODE, |
| 1549 | palette_uv_size: cdf::PALETTE_UV_SIZE, |
| 1550 | palette_y_color_index: cdf::PALETTE_Y_COLOR_INDEX, |
| 1551 | palette_uv_color_index: cdf::PALETTE_UV_COLOR_INDEX, |
| 1552 | intrabc: cdf::INTRABC, |
| 1553 | restore_wiener: cdf::RESTORE_WIENER, |
| 1554 | restore_sgrproj: cdf::RESTORE_SGRPROJ, |
| 1555 | restore_switchable: cdf::RESTORE_SWITCHABLE, |
| 1556 | segment_id: cdf::SEGMENT_ID, |
| 1557 | segment_pred: cdf::SEGMENT_PRED, |
| 1558 | delta_q: cdf::DELTA_Q, |
| 1559 | delta_lf: cdf::DELTA_LF, |
| 1560 | delta_lf_multi: [cdf::DELTA_LF; 4], |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | /// The tables one table set is coded with, borrowed out of the state. |
| 1565 | pub fn txb(&mut self, set: TxbSet, mode: usize) -> TxbTables<'_> { |
| 1566 | match set { |
| 1567 | TxbSet::Luma32 => TxbTables { |
| 1568 | side: 32, |
| 1569 | txb_skip: &mut self.txb_skip_luma_32, |
| 1570 | eob_pt: &mut self.eob_pt_1024_luma, |
| 1571 | eob_extra: &mut self.eob_extra_luma_32, |
| 1572 | base: &mut self.base_luma_32, |
| 1573 | base_eob: &mut self.base_eob_luma_32, |
| 1574 | br: &mut self.br_luma_32, |
| 1575 | dc_sign: &mut self.dc_sign_luma, |
| 1576 | tx_type: None, |
| 1577 | eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), |
| 1578 | }, |
| 1579 | // lane-comppin r4 (REVERTED, see r4's own commit message): |
| 1580 | // `Some(inter_tx_type_32)` looked wrong against aomdec's 32x32 |
| 1581 | // trace (degenerate 1-symbol EC_TXTYPE_VAL=0 read) and matches |
| 1582 | // spec `av1_get_ext_tx_set_type`'s `EXT_TX_SET_DCTONLY` for |
| 1583 | // every tx_size_sqr >= TX_32X32 -- but flipping this to `None` |
| 1584 | // regressed 16 previously-green `ec-av1` tests (full-suite count |
| 1585 | // went 217/217 -> 201/216), and did NOT fix the pin's own |
| 1586 | // eob_pt desync either (still reads 6 instead of aomdec's 5 |
| 1587 | // right after this read, proving eob_pt's own context/table |
| 1588 | // selection is a SEPARATE, still-unfound bug upstream of this |
| 1589 | // one) -- kept `Some` pending a real fix that ports both without |
| 1590 | // breaking the 16. |
| 1591 | TxbSet::Luma32Inter => TxbTables { |
| 1592 | side: 32, |
| 1593 | txb_skip: &mut self.txb_skip_luma_32, |
| 1594 | eob_pt: &mut self.eob_pt_1024_luma, |
| 1595 | eob_extra: &mut self.eob_extra_luma_32, |
| 1596 | base: &mut self.base_luma_32, |
| 1597 | base_eob: &mut self.base_eob_luma_32, |
| 1598 | br: &mut self.br_luma_32, |
| 1599 | dc_sign: &mut self.dc_sign_luma, |
| 1600 | tx_type: Some(self.inter_tx_type_32.as_mut_slice()), |
| 1601 | eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), |
| 1602 | }, |
| 1603 | TxbSet::Luma64 => TxbTables { |
| 1604 | side: 32, |
| 1605 | txb_skip: &mut self.txb_skip_luma_64, |
| 1606 | eob_pt: &mut self.eob_pt_1024_luma, |
| 1607 | eob_extra: &mut self.eob_extra_luma_64, |
| 1608 | base: &mut self.base_luma_64, |
| 1609 | base_eob: &mut self.base_eob_luma_64, |
| 1610 | br: &mut self.br_luma_32, |
| 1611 | dc_sign: &mut self.dc_sign_luma, |
| 1612 | tx_type: None, |
| 1613 | eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1), |
| 1614 | }, |
| 1615 | TxbSet::Luma16 => TxbTables { |
| 1616 | side: 16, |
| 1617 | txb_skip: &mut self.txb_skip_luma_16, |
| 1618 | eob_pt: &mut self.eob_pt_256_luma, |
| 1619 | eob_extra: &mut self.eob_extra_luma_16, |
| 1620 | base: &mut self.base_luma_16, |
| 1621 | base_eob: &mut self.base_eob_luma_16, |
| 1622 | br: &mut self.br_luma_16, |
| 1623 | dc_sign: &mut self.dc_sign_luma, |
| 1624 | tx_type: Some(self.intra_tx_type_16[mode].as_mut_slice()), |
| 1625 | eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), |
| 1626 | }, |
| 1627 | TxbSet::Luma16Inter => TxbTables { |
| 1628 | side: 16, |
| 1629 | txb_skip: &mut self.txb_skip_luma_16, |
| 1630 | eob_pt: &mut self.eob_pt_256_luma, |
| 1631 | eob_extra: &mut self.eob_extra_luma_16, |
| 1632 | base: &mut self.base_luma_16, |
| 1633 | base_eob: &mut self.base_eob_luma_16, |
| 1634 | br: &mut self.br_luma_16, |
| 1635 | dc_sign: &mut self.dc_sign_luma, |
| 1636 | tx_type: Some(self.inter_tx_type_16.as_mut_slice()), |
| 1637 | eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), |
| 1638 | }, |
| 1639 | TxbSet::Luma16InterSet1 => TxbTables { |
| 1640 | side: 16, |
| 1641 | txb_skip: &mut self.txb_skip_luma_16, |
| 1642 | eob_pt: &mut self.eob_pt_256_luma, |
| 1643 | eob_extra: &mut self.eob_extra_luma_16, |
| 1644 | base: &mut self.base_luma_16, |
| 1645 | base_eob: &mut self.base_eob_luma_16, |
| 1646 | br: &mut self.br_luma_16, |
| 1647 | dc_sign: &mut self.dc_sign_luma, |
| 1648 | tx_type: Some(self.inter_tx_type_16_set2.as_mut_slice()), |
| 1649 | eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), |
| 1650 | }, |
| 1651 | TxbSet::Luma8 => TxbTables { |
| 1652 | side: 8, |
| 1653 | txb_skip: &mut self.txb_skip_luma_8, |
| 1654 | eob_pt: &mut self.eob_pt_64_luma, |
| 1655 | eob_extra: &mut self.eob_extra_luma_8, |
| 1656 | base: &mut self.base_luma_8, |
| 1657 | base_eob: &mut self.base_eob_luma_8, |
| 1658 | br: &mut self.br_luma_8, |
| 1659 | dc_sign: &mut self.dc_sign_luma, |
| 1660 | tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()), |
| 1661 | eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), |
| 1662 | }, |
| 1663 | TxbSet::Luma8Set1 => TxbTables { |
| 1664 | side: 8, |
| 1665 | txb_skip: &mut self.txb_skip_luma_8, |
| 1666 | eob_pt: &mut self.eob_pt_64_luma, |
| 1667 | eob_extra: &mut self.eob_extra_luma_8, |
| 1668 | base: &mut self.base_luma_8, |
| 1669 | base_eob: &mut self.base_eob_luma_8, |
| 1670 | br: &mut self.br_luma_8, |
| 1671 | dc_sign: &mut self.dc_sign_luma, |
| 1672 | tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), |
| 1673 | eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), |
| 1674 | }, |
| 1675 | TxbSet::Luma4 => TxbTables { |
| 1676 | side: 4, |
| 1677 | txb_skip: &mut self.txb_skip_luma_4, |
| 1678 | eob_pt: &mut self.eob_pt_16_luma, |
| 1679 | eob_extra: &mut self.eob_extra_luma_4, |
| 1680 | base: &mut self.base_luma_4, |
| 1681 | base_eob: &mut self.base_eob_luma_4, |
| 1682 | br: &mut self.br_luma_4, |
| 1683 | dc_sign: &mut self.dc_sign_luma, |
| 1684 | tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), |
| 1685 | eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), |
| 1686 | }, |
| 1687 | TxbSet::Luma4Inter => TxbTables { |
| 1688 | side: 4, |
| 1689 | txb_skip: &mut self.txb_skip_luma_4, |
| 1690 | eob_pt: &mut self.eob_pt_16_luma, |
| 1691 | eob_extra: &mut self.eob_extra_luma_4, |
| 1692 | base: &mut self.base_luma_4, |
| 1693 | base_eob: &mut self.base_eob_luma_4, |
| 1694 | br: &mut self.br_luma_4, |
| 1695 | dc_sign: &mut self.dc_sign_luma, |
| 1696 | tx_type: Some(self.inter_tx_type_4.as_mut_slice()), |
| 1697 | eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), |
| 1698 | }, |
| 1699 | TxbSet::Luma4InterSet1 => TxbTables { |
| 1700 | side: 4, |
| 1701 | txb_skip: &mut self.txb_skip_luma_4, |
| 1702 | eob_pt: &mut self.eob_pt_16_luma, |
| 1703 | eob_extra: &mut self.eob_extra_luma_4, |
| 1704 | base: &mut self.base_luma_4, |
| 1705 | base_eob: &mut self.base_eob_luma_4, |
| 1706 | br: &mut self.br_luma_4, |
| 1707 | dc_sign: &mut self.dc_sign_luma, |
| 1708 | tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), |
| 1709 | eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), |
| 1710 | }, |
| 1711 | TxbSet::Luma4Set1 => TxbTables { |
| 1712 | side: 4, |
| 1713 | txb_skip: &mut self.txb_skip_luma_4, |
| 1714 | eob_pt: &mut self.eob_pt_16_luma, |
| 1715 | eob_extra: &mut self.eob_extra_luma_4, |
| 1716 | base: &mut self.base_luma_4, |
| 1717 | base_eob: &mut self.base_eob_luma_4, |
| 1718 | br: &mut self.br_luma_4, |
| 1719 | dc_sign: &mut self.dc_sign_luma, |
| 1720 | tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), |
| 1721 | eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1), |
| 1722 | }, |
| 1723 | TxbSet::Luma8Inter => TxbTables { |
| 1724 | side: 8, |
| 1725 | txb_skip: &mut self.txb_skip_luma_8, |
| 1726 | eob_pt: &mut self.eob_pt_64_luma, |
| 1727 | eob_extra: &mut self.eob_extra_luma_8, |
| 1728 | base: &mut self.base_luma_8, |
| 1729 | base_eob: &mut self.base_eob_luma_8, |
| 1730 | br: &mut self.br_luma_8, |
| 1731 | dc_sign: &mut self.dc_sign_luma, |
| 1732 | tx_type: Some(self.inter_tx_type_8.as_mut_slice()), |
| 1733 | eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), |
| 1734 | }, |
| 1735 | TxbSet::Luma8InterSet1 => TxbTables { |
| 1736 | side: 8, |
| 1737 | txb_skip: &mut self.txb_skip_luma_8, |
| 1738 | eob_pt: &mut self.eob_pt_64_luma, |
| 1739 | eob_extra: &mut self.eob_extra_luma_8, |
| 1740 | base: &mut self.base_luma_8, |
| 1741 | base_eob: &mut self.base_eob_luma_8, |
| 1742 | br: &mut self.br_luma_8, |
| 1743 | dc_sign: &mut self.dc_sign_luma, |
| 1744 | tx_type: Some(self.inter_tx_type_8_set1.as_mut_slice()), |
| 1745 | eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), |
| 1746 | }, |
| 1747 | TxbSet::Chroma8 => TxbTables { |
| 1748 | side: 8, |
| 1749 | txb_skip: &mut self.txb_skip_chroma_8, |
| 1750 | eob_pt: &mut self.eob_pt_64_chroma, |
| 1751 | eob_extra: &mut self.eob_extra_chroma_8, |
| 1752 | base: &mut self.base_chroma_8, |
| 1753 | base_eob: &mut self.base_eob_chroma_8, |
| 1754 | br: &mut self.br_chroma_8, |
| 1755 | dc_sign: &mut self.dc_sign_chroma, |
| 1756 | tx_type: None, |
| 1757 | eob_pt_class1: Some(&mut self.eob_pt_64_chroma_class1), |
| 1758 | }, |
| 1759 | TxbSet::Chroma4 => TxbTables { |
| 1760 | side: 4, |
| 1761 | txb_skip: &mut self.txb_skip_chroma_4, |
| 1762 | eob_pt: &mut self.eob_pt_16_chroma, |
| 1763 | eob_extra: &mut self.eob_extra_chroma_4, |
| 1764 | base: &mut self.base_chroma_4, |
| 1765 | base_eob: &mut self.base_eob_chroma_4, |
| 1766 | br: &mut self.br_chroma_4, |
| 1767 | dc_sign: &mut self.dc_sign_chroma, |
| 1768 | tx_type: None, |
| 1769 | eob_pt_class1: Some(&mut self.eob_pt_16_chroma_class1), |
| 1770 | }, |
| 1771 | TxbSet::Chroma16 => TxbTables { |
| 1772 | side: 16, |
| 1773 | txb_skip: &mut self.txb_skip_chroma_16, |
| 1774 | eob_pt: &mut self.eob_pt_256_chroma, |
| 1775 | eob_extra: &mut self.eob_extra_chroma_16, |
| 1776 | base: &mut self.base_chroma_16, |
| 1777 | base_eob: &mut self.base_eob_chroma_16, |
| 1778 | br: &mut self.br_chroma_16, |
| 1779 | dc_sign: &mut self.dc_sign_chroma, |
| 1780 | tx_type: None, |
| 1781 | eob_pt_class1: Some(&mut self.eob_pt_256_chroma_class1), |
| 1782 | }, |
| 1783 | TxbSet::Chroma32 => TxbTables { |
| 1784 | side: 32, |
| 1785 | txb_skip: &mut self.txb_skip_chroma_32, |
| 1786 | eob_pt: &mut self.eob_pt_1024_chroma, |
| 1787 | eob_extra: &mut self.eob_extra_chroma_32, |
| 1788 | base: &mut self.base_chroma_32, |
| 1789 | base_eob: &mut self.base_eob_chroma_32, |
| 1790 | br: &mut self.br_chroma_32, |
| 1791 | dc_sign: &mut self.dc_sign_chroma, |
| 1792 | tx_type: None, |
| 1793 | eob_pt_class1: Some(&mut self.eob_pt_1024_chroma_class1), |
| 1794 | }, |
| 1795 | TxbSet::LumaRect32x8Inter => TxbTables { |
| 1796 | side: 16, |
| 1797 | txb_skip: &mut self.txb_skip_luma_16, |
| 1798 | eob_pt: &mut self.eob_pt_256_luma, |
| 1799 | eob_extra: &mut self.eob_extra_luma_16, |
| 1800 | base: &mut self.base_luma_16, |
| 1801 | base_eob: &mut self.base_eob_luma_16, |
| 1802 | br: &mut self.br_luma_16, |
| 1803 | dc_sign: &mut self.dc_sign_luma, |
| 1804 | tx_type: Some(self.inter_tx_type_8.as_mut_slice()), |
| 1805 | eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), |
| 1806 | }, |
| 1807 | TxbSet::LumaRect32x8 => TxbTables { |
| 1808 | side: 16, |
| 1809 | txb_skip: &mut self.txb_skip_luma_16, |
| 1810 | eob_pt: &mut self.eob_pt_256_luma, |
| 1811 | eob_extra: &mut self.eob_extra_luma_16, |
| 1812 | base: &mut self.base_luma_16, |
| 1813 | base_eob: &mut self.base_eob_luma_16, |
| 1814 | br: &mut self.br_luma_16, |
| 1815 | dc_sign: &mut self.dc_sign_luma, |
| 1816 | tx_type: None, |
| 1817 | eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1), |
| 1818 | }, |
| 1819 | TxbSet::LumaRect32x16Inter => TxbTables { |
| 1820 | side: 32, |
| 1821 | txb_skip: &mut self.txb_skip_luma_32, |
| 1822 | eob_pt: &mut self.eob_pt_512_luma, |
| 1823 | eob_extra: &mut self.eob_extra_luma_32, |
| 1824 | base: &mut self.base_luma_32, |
| 1825 | base_eob: &mut self.base_eob_luma_32, |
| 1826 | br: &mut self.br_luma_32, |
| 1827 | dc_sign: &mut self.dc_sign_luma, |
| 1828 | tx_type: Some(self.inter_tx_type_16.as_mut_slice()), |
| 1829 | eob_pt_class1: Some(&mut self.eob_pt_512_luma_class1), |
| 1830 | }, |
| 1831 | TxbSet::LumaRect32x16 => TxbTables { |
| 1832 | side: 32, |
| 1833 | txb_skip: &mut self.txb_skip_luma_32, |
| 1834 | eob_pt: &mut self.eob_pt_512_luma, |
| 1835 | eob_extra: &mut self.eob_extra_luma_32, |
| 1836 | base: &mut self.base_luma_32, |
| 1837 | base_eob: &mut self.base_eob_luma_32, |
| 1838 | br: &mut self.br_luma_32, |
| 1839 | dc_sign: &mut self.dc_sign_luma, |
| 1840 | tx_type: None, |
| 1841 | eob_pt_class1: Some(&mut self.eob_pt_512_luma_class1), |
| 1842 | }, |
| 1843 | TxbSet::ChromaRect16x8 => TxbTables { |
| 1844 | side: 16, |
| 1845 | txb_skip: &mut self.txb_skip_chroma_16, |
| 1846 | eob_pt: &mut self.eob_pt_128_chroma, |
| 1847 | eob_extra: &mut self.eob_extra_chroma_16, |
| 1848 | base: &mut self.base_chroma_16, |
| 1849 | base_eob: &mut self.base_eob_chroma_16, |
| 1850 | br: &mut self.br_chroma_16, |
| 1851 | dc_sign: &mut self.dc_sign_chroma, |
| 1852 | tx_type: None, |
| 1853 | eob_pt_class1: Some(&mut self.eob_pt_128_chroma_class1), |
| 1854 | }, |
| 1855 | TxbSet::LumaRect4x8 => TxbTables { |
| 1856 | side: 8, |
| 1857 | txb_skip: &mut self.txb_skip_luma_8, |
| 1858 | eob_pt: &mut self.eob_pt_32_luma, |
| 1859 | eob_extra: &mut self.eob_extra_luma_8, |
| 1860 | base: &mut self.base_luma_8, |
| 1861 | base_eob: &mut self.base_eob_luma_8, |
| 1862 | br: &mut self.br_luma_8, |
| 1863 | dc_sign: &mut self.dc_sign_luma, |
| 1864 | tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), |
| 1865 | eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), |
| 1866 | }, |
| 1867 | TxbSet::LumaRect8x4Inter => TxbTables { |
| 1868 | side: 8, |
| 1869 | txb_skip: &mut self.txb_skip_luma_8, |
| 1870 | eob_pt: &mut self.eob_pt_32_luma, |
| 1871 | eob_extra: &mut self.eob_extra_luma_8, |
| 1872 | base: &mut self.base_luma_8, |
| 1873 | base_eob: &mut self.base_eob_luma_8, |
| 1874 | br: &mut self.br_luma_8, |
| 1875 | dc_sign: &mut self.dc_sign_luma, |
| 1876 | tx_type: Some(self.inter_tx_type_4.as_mut_slice()), |
| 1877 | eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), |
| 1878 | }, |
| 1879 | TxbSet::LumaRect8x4InterSet1 => TxbTables { |
| 1880 | side: 8, |
| 1881 | txb_skip: &mut self.txb_skip_luma_8, |
| 1882 | eob_pt: &mut self.eob_pt_32_luma, |
| 1883 | eob_extra: &mut self.eob_extra_luma_8, |
| 1884 | base: &mut self.base_luma_8, |
| 1885 | base_eob: &mut self.base_eob_luma_8, |
| 1886 | br: &mut self.br_luma_8, |
| 1887 | dc_sign: &mut self.dc_sign_luma, |
| 1888 | tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), |
| 1889 | eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), |
| 1890 | }, |
| 1891 | TxbSet::LumaRect4x8Set1 => TxbTables { |
| 1892 | side: 8, |
| 1893 | txb_skip: &mut self.txb_skip_luma_8, |
| 1894 | eob_pt: &mut self.eob_pt_32_luma, |
| 1895 | eob_extra: &mut self.eob_extra_luma_8, |
| 1896 | base: &mut self.base_luma_8, |
| 1897 | base_eob: &mut self.base_eob_luma_8, |
| 1898 | br: &mut self.br_luma_8, |
| 1899 | dc_sign: &mut self.dc_sign_luma, |
| 1900 | tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), |
| 1901 | eob_pt_class1: Some(&mut self.eob_pt_32_luma_class1), |
| 1902 | }, |
| 1903 | TxbSet::ChromaRect32x16 => TxbTables { |
| 1904 | side: 32, |
| 1905 | txb_skip: &mut self.txb_skip_chroma_32, |
| 1906 | eob_pt: &mut self.eob_pt_512_chroma, |
| 1907 | eob_extra: &mut self.eob_extra_chroma_32, |
| 1908 | base: &mut self.base_chroma_32, |
| 1909 | base_eob: &mut self.base_eob_chroma_32, |
| 1910 | br: &mut self.br_chroma_32, |
| 1911 | dc_sign: &mut self.dc_sign_chroma, |
| 1912 | tx_type: None, |
| 1913 | eob_pt_class1: Some(&mut self.eob_pt_512_chroma_class1), |
| 1914 | }, |
| 1915 | TxbSet::LumaRect16x8 => TxbTables { |
| 1916 | side: 16, |
| 1917 | txb_skip: &mut self.txb_skip_luma_16, |
| 1918 | eob_pt: &mut self.eob_pt_128_luma, |
| 1919 | eob_extra: &mut self.eob_extra_luma_16, |
| 1920 | base: &mut self.base_luma_16, |
| 1921 | base_eob: &mut self.base_eob_luma_16, |
| 1922 | br: &mut self.br_luma_16, |
| 1923 | dc_sign: &mut self.dc_sign_luma, |
| 1924 | tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()), |
| 1925 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), |
| 1926 | }, |
| 1927 | TxbSet::LumaRect16x8Set1 => TxbTables { |
| 1928 | side: 16, |
| 1929 | txb_skip: &mut self.txb_skip_luma_16, |
| 1930 | eob_pt: &mut self.eob_pt_128_luma, |
| 1931 | eob_extra: &mut self.eob_extra_luma_16, |
| 1932 | base: &mut self.base_luma_16, |
| 1933 | base_eob: &mut self.base_eob_luma_16, |
| 1934 | br: &mut self.br_luma_16, |
| 1935 | dc_sign: &mut self.dc_sign_luma, |
| 1936 | tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), |
| 1937 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), |
| 1938 | }, |
| 1939 | TxbSet::LumaRect16x4 => TxbTables { |
| 1940 | side: 8, |
| 1941 | txb_skip: &mut self.txb_skip_luma_8, |
| 1942 | eob_pt: &mut self.eob_pt_64_luma, |
| 1943 | eob_extra: &mut self.eob_extra_luma_8, |
| 1944 | base: &mut self.base_luma_8, |
| 1945 | base_eob: &mut self.base_eob_luma_8, |
| 1946 | br: &mut self.br_luma_8, |
| 1947 | dc_sign: &mut self.dc_sign_luma, |
| 1948 | tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()), |
| 1949 | eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), |
| 1950 | }, |
| 1951 | TxbSet::LumaRect16x4Set1 => TxbTables { |
| 1952 | side: 8, |
| 1953 | txb_skip: &mut self.txb_skip_luma_8, |
| 1954 | eob_pt: &mut self.eob_pt_64_luma, |
| 1955 | eob_extra: &mut self.eob_extra_luma_8, |
| 1956 | base: &mut self.base_luma_8, |
| 1957 | base_eob: &mut self.base_eob_luma_8, |
| 1958 | br: &mut self.br_luma_8, |
| 1959 | dc_sign: &mut self.dc_sign_luma, |
| 1960 | tx_type: Some(self.intra_tx_type_4_set1[mode].as_mut_slice()), |
| 1961 | eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), |
| 1962 | }, |
| 1963 | TxbSet::LumaRect16x4Inter => TxbTables { |
| 1964 | side: 8, |
| 1965 | txb_skip: &mut self.txb_skip_luma_8, |
| 1966 | eob_pt: &mut self.eob_pt_64_luma, |
| 1967 | eob_extra: &mut self.eob_extra_luma_8, |
| 1968 | base: &mut self.base_luma_8, |
| 1969 | base_eob: &mut self.base_eob_luma_8, |
| 1970 | br: &mut self.br_luma_8, |
| 1971 | dc_sign: &mut self.dc_sign_luma, |
| 1972 | tx_type: Some(self.inter_tx_type_4.as_mut_slice()), |
| 1973 | eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), |
| 1974 | }, |
| 1975 | TxbSet::LumaRect16x4Inter1 => TxbTables { |
| 1976 | side: 8, |
| 1977 | txb_skip: &mut self.txb_skip_luma_8, |
| 1978 | eob_pt: &mut self.eob_pt_64_luma, |
| 1979 | eob_extra: &mut self.eob_extra_luma_8, |
| 1980 | base: &mut self.base_luma_8, |
| 1981 | base_eob: &mut self.base_eob_luma_8, |
| 1982 | br: &mut self.br_luma_8, |
| 1983 | dc_sign: &mut self.dc_sign_luma, |
| 1984 | tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()), |
| 1985 | eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1), |
| 1986 | }, |
| 1987 | TxbSet::LumaRect16x8Inter => TxbTables { |
| 1988 | side: 16, |
| 1989 | txb_skip: &mut self.txb_skip_luma_16, |
| 1990 | eob_pt: &mut self.eob_pt_128_luma, |
| 1991 | eob_extra: &mut self.eob_extra_luma_16, |
| 1992 | base: &mut self.base_luma_16, |
| 1993 | base_eob: &mut self.base_eob_luma_16, |
| 1994 | br: &mut self.br_luma_16, |
| 1995 | dc_sign: &mut self.dc_sign_luma, |
| 1996 | tx_type: Some(self.inter_tx_type_8.as_mut_slice()), |
| 1997 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), |
| 1998 | }, |
| 1999 | TxbSet::LumaRect16x8InterSet1 => TxbTables { |
| 2000 | side: 16, |
| 2001 | txb_skip: &mut self.txb_skip_luma_16, |
| 2002 | eob_pt: &mut self.eob_pt_128_luma, |
| 2003 | eob_extra: &mut self.eob_extra_luma_16, |
| 2004 | base: &mut self.base_luma_16, |
| 2005 | base_eob: &mut self.base_eob_luma_16, |
| 2006 | br: &mut self.br_luma_16, |
| 2007 | dc_sign: &mut self.dc_sign_luma, |
| 2008 | tx_type: Some(self.inter_tx_type_8_set1.as_mut_slice()), |
| 2009 | eob_pt_class1: Some(&mut self.eob_pt_128_luma_class1), |
| 2010 | }, |
| 2011 | TxbSet::ChromaRect8x4 => TxbTables { |
| 2012 | side: 8, |
| 2013 | txb_skip: &mut self.txb_skip_chroma_8, |
| 2014 | eob_pt: &mut self.eob_pt_32_chroma, |
| 2015 | eob_extra: &mut self.eob_extra_chroma_8, |
| 2016 | base: &mut self.base_chroma_8, |
| 2017 | base_eob: &mut self.base_eob_chroma_8, |
| 2018 | br: &mut self.br_chroma_8, |
| 2019 | dc_sign: &mut self.dc_sign_chroma, |
| 2020 | tx_type: None, |
| 2021 | eob_pt_class1: Some(&mut self.eob_pt_32_chroma_class1), |
| 2022 | }, |
| 2023 | } |
| 2024 | } |
| 2025 | } |
| 2026 | |
| 2027 | #[cfg(test)] |
| 2028 | mod tests { |
| 2029 | use super::*; |
| 2030 | |
| 2031 | /// A 64x64 luma transform reads the 32x32 base-range rows, so the two sets |
| 2032 | /// have to adapt the same table: a decoder keeps one copy, and an encoder |
| 2033 | /// that kept two would drift away from it the first time a level above two |
| 2034 | /// was coded. |
| 2035 | #[test] |
| 2036 | fn the_two_luma_sets_share_the_base_range_table() { |
| 2037 | let mut cdfs = Cdfs::new(2); |
| 2038 | cdfs.txb(TxbSet::Luma64, 0).br[0][0] = 1; |
| 2039 | assert_eq!(cdfs.txb(TxbSet::Luma32, 0).br[0][0], 1); |
| 2040 | } |
| 2041 | |
| 2042 | /// Both luma sets read one DC sign table, and both chroma sets another; |
| 2043 | /// what a luma block adapts must not reach the chroma one. |
| 2044 | #[test] |
| 2045 | fn the_sign_tables_are_shared_within_a_plane_type_and_not_across() { |
| 2046 | let mut cdfs = Cdfs::new(2); |
| 2047 | cdfs.txb(TxbSet::Luma32, 0).dc_sign[1][0] = 1; |
| 2048 | cdfs.txb(TxbSet::Chroma16, 0).dc_sign[2][0] = 2; |
| 2049 | assert_eq!(cdfs.txb(TxbSet::Luma64, 0).dc_sign[1][0], 1); |
| 2050 | assert_eq!(cdfs.txb(TxbSet::Chroma32, 0).dc_sign[2][0], 2); |
| 2051 | assert_ne!(cdfs.txb(TxbSet::Chroma32, 0).dc_sign[1][0], 1); |
| 2052 | assert_ne!(cdfs.txb(TxbSet::Luma64, 0).dc_sign[2][0], 2); |
| 2053 | } |
| 2054 | |
| 2055 | /// The end-of-block table a 1024-position transform reads is shared by both |
| 2056 | /// luma sets and separate from chroma's, which is the same hazard one table |
| 2057 | /// further along. |
| 2058 | #[test] |
| 2059 | fn the_luma_end_of_block_table_is_shared_and_chromas_is_not() { |
| 2060 | let mut cdfs = Cdfs::new(2); |
| 2061 | cdfs.txb(TxbSet::Luma32, 0).eob_pt[0] = 7; |
| 2062 | assert_eq!(cdfs.txb(TxbSet::Luma64, 0).eob_pt[0], 7); |
| 2063 | assert_ne!(cdfs.txb(TxbSet::Chroma32, 0).eob_pt[0], 7); |
| 2064 | } |
| 2065 | |
| 2066 | /// Every set starts from the spec's defaults, so a tile that adapts nothing |
| 2067 | /// writes exactly what a non-adapting one does. |
| 2068 | #[test] |
| 2069 | fn the_state_starts_at_the_defaults() { |
| 2070 | let mut cdfs = Cdfs::new(2); |
| 2071 | assert_eq!( |
| 2072 | cdfs.txb(TxbSet::Luma32, 0).base[3], |
| 2073 | cdf::COEFF_BASE_LUMA_32[3] |
| 2074 | ); |
| 2075 | assert_eq!( |
| 2076 | cdfs.txb(TxbSet::Chroma16, 0).eob_extra[2], |
| 2077 | cdf::EOB_EXTRA_CHROMA_16[2] |
| 2078 | ); |
| 2079 | assert_eq!(cdfs.partition_w64[2], cdf::PARTITION_W64[2]); |
| 2080 | assert_eq!(cdfs.intra_inter, cdf::INTRA_INTER); |
| 2081 | assert_eq!(cdfs.single_ref, cdf::SINGLE_REF); |
| 2082 | assert_eq!(cdfs.comp_mode, cdf::COMP_MODE); |
| 2083 | assert_eq!(cdfs.inter_compound_mode, cdf::INTER_COMPOUND_MODE); |
| 2084 | assert_eq!(cdfs.comp_ref_type, cdf::COMP_REF_TYPE); |
| 2085 | assert_eq!(cdfs.uni_comp_ref, cdf::UNI_COMP_REF); |
| 2086 | assert_eq!(cdfs.comp_ref, cdf::COMP_REF); |
| 2087 | assert_eq!(cdfs.comp_bwdref, cdf::COMP_BWDREF); |
| 2088 | assert_eq!(cdfs.y_mode, cdf::Y_MODE); |
| 2089 | assert_eq!(cdfs.new_mv, cdf::NEW_MV); |
| 2090 | assert_eq!(cdfs.zero_mv, cdf::ZERO_MV); |
| 2091 | assert_eq!(cdfs.ref_mv, cdf::REF_MV); |
| 2092 | assert_eq!(cdfs.drl_mode, cdf::DRL_MODE); |
| 2093 | assert_eq!(cdfs.mv_joint, cdf::MV_JOINT); |
| 2094 | assert_eq!(cdfs.mv_comp[0].class, cdf::MV_CLASS); |
| 2095 | assert_eq!(cdfs.mv_comp[1].sign, cdf::MV_SIGN); |
| 2096 | } |
| 2097 | |
| 2098 | /// A motion vector's two components are separate owned tables: adapting |
| 2099 | /// one component's CDFs must not be visible through the other, the same |
| 2100 | /// hazard the coefficient sets guard against above. |
| 2101 | #[test] |
| 2102 | fn the_mv_components_are_separate_and_do_not_share_adaptation() { |
| 2103 | let mut cdfs = Cdfs::new(2); |
| 2104 | cdfs.mv_comp[0].class[0] = 1; |
| 2105 | cdfs.mv_comp[0].bit[3][0] = 2; |
| 2106 | assert_ne!(cdfs.mv_comp[1].class[0], 1); |
| 2107 | assert_ne!(cdfs.mv_comp[1].bit[3][0], 2); |
| 2108 | assert_eq!(cdfs.mv_comp[1].class[0], cdf::MV_CLASS[0]); |
| 2109 | assert_eq!(cdfs.mv_comp[1].bit[3][0], cdf::MV_BIT[3][0]); |
| 2110 | } |
| 2111 | } |