forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

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