diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index c6841476..a639062d 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -1115,6 +1115,1629 @@ pub const MV_HP: [u16; 3] = [16384, 32768, 0]; /// `Default_Mv_Sign_Cdf` (spec 9.4): the sign of a motion vector component. pub const MV_SIGN: [u16; 3] = [16384, 32768, 0]; +// q-context 0/1/3 coefficient CDFs (spec 9.4's `Default_..._Cdf[0]`, +// `[1]` and `[3]`), auto-derived from the same libaom `token_cdfs.h` the +// q-context-2 tables above were transcribed from, and checked by reproducing +// every q-context-2 table above byte-for-byte with the same indexing before +// generating these (see the lane report for the check). + +// q-context 0: base_q_idx 0..=20. + +/// TXB_SKIP_LUMA_64, q-context 0: the same table as [`TXB_SKIP_LUMA_64`], for `base_q_idx` 0..=20. +pub const TXB_SKIP_LUMA_64_Q0: [u16; 3] = [6308, 32768, 0]; +/// TXB_SKIP_LUMA_32, q-context 0: the same table as [`TXB_SKIP_LUMA_32`], for `base_q_idx` 0..=20. +pub const TXB_SKIP_LUMA_32_Q0: [u16; 3] = [17920, 32768, 0]; +/// TXB_SKIP_LUMA_16, q-context 0: the same table as [`TXB_SKIP_LUMA_16`], for `base_q_idx` 0..=20. +pub const TXB_SKIP_LUMA_16_Q0: [u16; 3] = [29957, 32768, 0]; +/// TXB_SKIP_CHROMA_8, q-context 0: the same table as [`TXB_SKIP_CHROMA_8`], for `base_q_idx` 0..=20. +pub const TXB_SKIP_CHROMA_8_Q0: [[u16; 3]; 3] = + [[5403, 32768, 0], [18096, 32768, 0], [30003, 32768, 0]]; +/// TXB_SKIP_CHROMA_16, q-context 0: the same table as [`TXB_SKIP_CHROMA_16`], for `base_q_idx` 0..=20. +pub const TXB_SKIP_CHROMA_16_Q0: [[u16; 3]; 3] = + [[3778, 32768, 0], [15336, 32768, 0], [28981, 32768, 0]]; +/// TXB_SKIP_CHROMA_32, q-context 0: the same table as [`TXB_SKIP_CHROMA_32`], for `base_q_idx` 0..=20. +pub const TXB_SKIP_CHROMA_32_Q0: [[u16; 3]; 3] = + [[1366, 32768, 0], [15628, 32768, 0], [30462, 32768, 0]]; +/// EOB_EXTRA_LUMA_16, q-context 0: the same table as [`EOB_EXTRA_LUMA_16`], for `base_q_idx` 0..=20. +pub const EOB_EXTRA_LUMA_16_Q0: [[u16; 3]; 9] = [ + [23905, 32768, 0], + [17194, 32768, 0], + [16170, 32768, 0], + [17695, 32768, 0], + [13826, 32768, 0], + [15810, 32768, 0], + [12036, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_LUMA_32, q-context 0: the same table as [`EOB_EXTRA_LUMA_32`], for `base_q_idx` 0..=20. +pub const EOB_EXTRA_LUMA_32_Q0: [[u16; 3]; 9] = [ + [27399, 32768, 0], + [16327, 32768, 0], + [18071, 32768, 0], + [19584, 32768, 0], + [20721, 32768, 0], + [18432, 32768, 0], + [19560, 32768, 0], + [10150, 32768, 0], + [8805, 32768, 0], +]; +/// EOB_EXTRA_LUMA_64, q-context 0: the same table as [`EOB_EXTRA_LUMA_64`], for `base_q_idx` 0..=20. +pub const EOB_EXTRA_LUMA_64_Q0: [[u16; 3]; 9] = [ + [23406, 32768, 0], + [21845, 32768, 0], + [18432, 32768, 0], + [16384, 32768, 0], + [17096, 32768, 0], + [12561, 32768, 0], + [17320, 32768, 0], + [22395, 32768, 0], + [21370, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_8, q-context 0: the same table as [`EOB_EXTRA_CHROMA_8`], for `base_q_idx` 0..=20. +pub const EOB_EXTRA_CHROMA_8_Q0: [[u16; 3]; 9] = [ + [20681, 32768, 0], + [20701, 32768, 0], + [15250, 32768, 0], + [15017, 32768, 0], + [14928, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_16, q-context 0: the same table as [`EOB_EXTRA_CHROMA_16`], for `base_q_idx` 0..=20. +pub const EOB_EXTRA_CHROMA_16_Q0: [[u16; 3]; 9] = [ + [23959, 32768, 0], + [20799, 32768, 0], + [19021, 32768, 0], + [16203, 32768, 0], + [17886, 32768, 0], + [14144, 32768, 0], + [12010, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_32, q-context 0: the same table as [`EOB_EXTRA_CHROMA_32`], for `base_q_idx` 0..=20. +pub const EOB_EXTRA_CHROMA_32_Q0: [[u16; 3]; 9] = [ + [24932, 32768, 0], + [20833, 32768, 0], + [12027, 32768, 0], + [16670, 32768, 0], + [19914, 32768, 0], + [15106, 32768, 0], + [17662, 32768, 0], + [13783, 32768, 0], + [28756, 32768, 0], +]; +/// EOB_PT_1024_LUMA, q-context 0: the same table as [`EOB_PT_1024_LUMA`], for `base_q_idx` 0..=20. +pub const EOB_PT_1024_LUMA_Q0: [u16; 12] = [ + 393, 421, 751, 1623, 3160, 6352, 13345, 18047, 22571, 25830, 32768, 0, +]; +/// EOB_PT_1024_CHROMA, q-context 0: the same table as [`EOB_PT_1024_CHROMA`], for `base_q_idx` 0..=20. +pub const EOB_PT_1024_CHROMA_Q0: [u16; 12] = [ + 1865, 1988, 2930, 4242, 10533, 16538, 21354, 27255, 28546, 31784, 32768, 0, +]; +/// EOB_PT_256_LUMA, q-context 0: the same table as [`EOB_PT_256_LUMA`], for `base_q_idx` 0..=20. +pub const EOB_PT_256_LUMA_Q0: [u16; 10] = + [310, 584, 1887, 3589, 6168, 8611, 11352, 15652, 32768, 0]; +/// EOB_PT_256_CHROMA, q-context 0: the same table as [`EOB_PT_256_CHROMA`], for `base_q_idx` 0..=20. +pub const EOB_PT_256_CHROMA_Q0: [u16; 10] = + [2520, 3240, 5952, 8870, 12577, 17558, 19954, 24168, 32768, 0]; +/// EOB_PT_64_CHROMA, q-context 0: the same table as [`EOB_PT_64_CHROMA`], for `base_q_idx` 0..=20. +pub const EOB_PT_64_CHROMA_Q0: [u16; 8] = [3505, 5304, 10086, 13814, 17684, 23370, 32768, 0]; +/// COEFF_BASE_LUMA_16, q-context 0: the same table as [`COEFF_BASE_LUMA_16`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_LUMA_16_Q0: [[u16; 5]; 42] = [ + [5487, 10460, 13708, 32768, 0], + [21597, 28303, 30674, 32768, 0], + [11037, 21953, 26476, 32768, 0], + [8147, 17962, 22952, 32768, 0], + [5242, 13061, 18532, 32768, 0], + [1889, 5208, 8182, 32768, 0], + [26774, 32133, 32590, 32768, 0], + [17844, 29564, 31767, 32768, 0], + [11690, 24438, 29171, 32768, 0], + [7542, 18215, 24459, 32768, 0], + [2993, 8050, 12319, 32768, 0], + [28023, 32328, 32591, 32768, 0], + [18651, 30126, 31954, 32768, 0], + [12164, 25146, 29589, 32768, 0], + [7762, 18530, 24771, 32768, 0], + [3492, 9183, 13920, 32768, 0], + [27591, 32008, 32491, 32768, 0], + [17149, 28853, 31510, 32768, 0], + [11485, 24003, 28860, 32768, 0], + [7697, 18086, 24210, 32768, 0], + [3075, 7999, 12218, 32768, 0], + [28268, 32482, 32654, 32768, 0], + [19631, 31051, 32404, 32768, 0], + [13860, 27260, 31020, 32768, 0], + [9605, 21613, 27594, 32768, 0], + [4876, 12162, 17908, 32768, 0], + [27248, 32316, 32576, 32768, 0], + [18955, 30457, 32075, 32768, 0], + [11824, 23997, 28795, 32768, 0], + [7346, 18196, 24647, 32768, 0], + [3403, 9247, 14111, 32768, 0], + [29711, 32655, 32735, 32768, 0], + [21169, 31394, 32417, 32768, 0], + [13487, 27198, 30957, 32768, 0], + [8828, 21683, 27614, 32768, 0], + [4270, 11451, 17038, 32768, 0], + [28708, 32578, 32731, 32768, 0], + [20120, 31241, 32482, 32768, 0], + [13692, 27550, 31321, 32768, 0], + [9418, 22514, 28439, 32768, 0], + [4999, 13283, 19462, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_LUMA_32, q-context 0: the same table as [`COEFF_BASE_LUMA_32`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_LUMA_32_Q0: [[u16; 5]; 42] = [ + [5141, 7096, 8260, 32768, 0], + [27186, 29022, 29789, 32768, 0], + [6668, 12568, 15682, 32768, 0], + [2172, 6181, 8638, 32768, 0], + [1126, 3379, 4531, 32768, 0], + [443, 1361, 2254, 32768, 0], + [26083, 31153, 32436, 32768, 0], + [13486, 24603, 28483, 32768, 0], + [6508, 14840, 19910, 32768, 0], + [3386, 8800, 13286, 32768, 0], + [1530, 4322, 7054, 32768, 0], + [29639, 32080, 32548, 32768, 0], + [15897, 27552, 30290, 32768, 0], + [8588, 20047, 25383, 32768, 0], + [4889, 13339, 19269, 32768, 0], + [2240, 6871, 10498, 32768, 0], + [28165, 32197, 32517, 32768, 0], + [20735, 30427, 31568, 32768, 0], + [14325, 24671, 27692, 32768, 0], + [5119, 12554, 17805, 32768, 0], + [1810, 5441, 8261, 32768, 0], + [31212, 32724, 32748, 32768, 0], + [23352, 31766, 32545, 32768, 0], + [14669, 27570, 31059, 32768, 0], + [8492, 20894, 27272, 32768, 0], + [3644, 10194, 15204, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_LUMA_64, q-context 0: the same table as [`COEFF_BASE_LUMA_64`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_LUMA_64_Q0: [[u16; 5]; 42] = [ + [601, 983, 1311, 32768, 0], + [18725, 23406, 28087, 32768, 0], + [5461, 8192, 10923, 32768, 0], + [3781, 15124, 21425, 32768, 0], + [2587, 7761, 12072, 32768, 0], + [106, 458, 810, 32768, 0], + [22282, 29710, 31894, 32768, 0], + [8508, 20926, 25984, 32768, 0], + [3726, 12713, 18083, 32768, 0], + [1620, 7112, 10893, 32768, 0], + [729, 2236, 3495, 32768, 0], + [30163, 32474, 32684, 32768, 0], + [18304, 30464, 32000, 32768, 0], + [11443, 26526, 29647, 32768, 0], + [6007, 15292, 21299, 32768, 0], + [2234, 6703, 8937, 32768, 0], + [30954, 32177, 32571, 32768, 0], + [17363, 29562, 31076, 32768, 0], + [9686, 22464, 27410, 32768, 0], + [8192, 16384, 21390, 32768, 0], + [1755, 8046, 11264, 32768, 0], + [31168, 32734, 32748, 32768, 0], + [22486, 31441, 32471, 32768, 0], + [12833, 25627, 29738, 32768, 0], + [6980, 17379, 23122, 32768, 0], + [3111, 8887, 13479, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_8, q-context 0: the same table as [`COEFF_BASE_CHROMA_8`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_CHROMA_8_Q0: [[u16; 5]; 42] = [ + [6037, 16771, 21957, 32768, 0], + [24774, 31704, 32426, 32768, 0], + [16830, 28589, 31056, 32768, 0], + [10602, 22828, 27760, 32768, 0], + [6733, 16829, 23071, 32768, 0], + [3250, 8914, 13556, 32768, 0], + [25582, 32220, 32668, 32768, 0], + [18659, 30342, 32223, 32768, 0], + [12546, 26149, 30515, 32768, 0], + [8420, 20451, 26801, 32768, 0], + [4636, 12420, 18344, 32768, 0], + [27581, 32362, 32639, 32768, 0], + [18987, 30083, 31978, 32768, 0], + [11327, 24248, 29084, 32768, 0], + [7264, 17719, 24120, 32768, 0], + [3995, 10768, 16169, 32768, 0], + [25893, 31831, 32487, 32768, 0], + [16577, 28587, 31379, 32768, 0], + [10189, 22748, 28182, 32768, 0], + [6832, 17094, 23556, 32768, 0], + [3708, 10110, 15334, 32768, 0], + [25904, 32282, 32656, 32768, 0], + [19721, 30792, 32276, 32768, 0], + [12819, 26243, 30411, 32768, 0], + [8572, 20614, 26891, 32768, 0], + [5364, 14059, 20467, 32768, 0], + [26580, 32438, 32677, 32768, 0], + [20852, 31225, 32340, 32768, 0], + [12435, 25700, 29967, 32768, 0], + [8691, 20825, 26976, 32768, 0], + [4446, 12209, 17269, 32768, 0], + [27350, 32429, 32696, 32768, 0], + [21372, 30977, 32272, 32768, 0], + [12673, 25270, 29853, 32768, 0], + [9208, 20925, 26640, 32768, 0], + [5018, 13351, 18732, 32768, 0], + [27351, 32479, 32713, 32768, 0], + [21398, 31209, 32387, 32768, 0], + [12162, 25047, 29842, 32768, 0], + [7896, 18691, 25319, 32768, 0], + [4670, 12882, 18881, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_16, q-context 0: the same table as [`COEFF_BASE_CHROMA_16`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_CHROMA_16_Q0: [[u16; 5]; 42] = [ + [5673, 14302, 19711, 32768, 0], + [26251, 30701, 31834, 32768, 0], + [12782, 23783, 27803, 32768, 0], + [9127, 20657, 25808, 32768, 0], + [6368, 16208, 21462, 32768, 0], + [2465, 7177, 10822, 32768, 0], + [29961, 32563, 32719, 32768, 0], + [18318, 29891, 31949, 32768, 0], + [11361, 24514, 29357, 32768, 0], + [7900, 19603, 25607, 32768, 0], + [4002, 10590, 15546, 32768, 0], + [29637, 32310, 32595, 32768, 0], + [18296, 29913, 31809, 32768, 0], + [10144, 21515, 26871, 32768, 0], + [5358, 14322, 20394, 32768, 0], + [3067, 8362, 13346, 32768, 0], + [28652, 32470, 32676, 32768, 0], + [17538, 30771, 32209, 32768, 0], + [13924, 26882, 30494, 32768, 0], + [10496, 22837, 27869, 32768, 0], + [7236, 16396, 21621, 32768, 0], + [30743, 32687, 32746, 32768, 0], + [23006, 31676, 32489, 32768, 0], + [14494, 27828, 31120, 32768, 0], + [10174, 22801, 28352, 32768, 0], + [6242, 15281, 21043, 32768, 0], + [25817, 32243, 32720, 32768, 0], + [18618, 31367, 32325, 32768, 0], + [13997, 28318, 31878, 32768, 0], + [12255, 26534, 31383, 32768, 0], + [9561, 21588, 28450, 32768, 0], + [28188, 32635, 32724, 32768, 0], + [22060, 32365, 32728, 32768, 0], + [18102, 30690, 32528, 32768, 0], + [14196, 28864, 31999, 32768, 0], + [12262, 25792, 30865, 32768, 0], + [24176, 32109, 32628, 32768, 0], + [18280, 29681, 31963, 32768, 0], + [10205, 23703, 29664, 32768, 0], + [7889, 20025, 27676, 32768, 0], + [6060, 16743, 23970, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_32, q-context 0: the same table as [`COEFF_BASE_CHROMA_32`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_CHROMA_32_Q0: [[u16; 5]; 42] = [ + [2461, 7013, 9371, 32768, 0], + [24749, 29600, 30986, 32768, 0], + [9466, 19037, 22417, 32768, 0], + [3584, 9280, 14400, 32768, 0], + [1505, 3929, 5433, 32768, 0], + [677, 1500, 2736, 32768, 0], + [23987, 30702, 32117, 32768, 0], + [13554, 24571, 29263, 32768, 0], + [6211, 14556, 21155, 32768, 0], + [3135, 10972, 15625, 32768, 0], + [2435, 7127, 11427, 32768, 0], + [31300, 32532, 32550, 32768, 0], + [14757, 30365, 31954, 32768, 0], + [4405, 11612, 18553, 32768, 0], + [580, 4132, 7322, 32768, 0], + [1695, 10169, 14124, 32768, 0], + [30008, 32282, 32591, 32768, 0], + [19244, 30108, 31748, 32768, 0], + [11180, 24158, 29555, 32768, 0], + [5650, 14972, 19209, 32768, 0], + [2114, 5109, 8456, 32768, 0], + [31856, 32716, 32748, 32768, 0], + [23012, 31664, 32572, 32768, 0], + [13694, 26656, 30636, 32768, 0], + [8142, 19508, 26093, 32768, 0], + [4253, 10955, 16724, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BR_LUMA_16, q-context 0: the same table as [`COEFF_BR_LUMA_16`], for `base_q_idx` 0..=20. +pub const COEFF_BR_LUMA_16_Q0: [[u16; 5]; 21] = [ + [10563, 16233, 19763, 32768, 0], + [9794, 16022, 19804, 32768, 0], + [6750, 11945, 15759, 32768, 0], + [4963, 9186, 12752, 32768, 0], + [3845, 7435, 10627, 32768, 0], + [3051, 6085, 8834, 32768, 0], + [1311, 2596, 3830, 32768, 0], + [11246, 16404, 19689, 32768, 0], + [12315, 18911, 22731, 32768, 0], + [10557, 17095, 21289, 32768, 0], + [8136, 14006, 18249, 32768, 0], + [6348, 11474, 15565, 32768, 0], + [5196, 9655, 13400, 32768, 0], + [2349, 4526, 6587, 32768, 0], + [13337, 18730, 21569, 32768, 0], + [19306, 26071, 28882, 32768, 0], + [15952, 23540, 27254, 32768, 0], + [12409, 19934, 24430, 32768, 0], + [9760, 16706, 21389, 32768, 0], + [8004, 14220, 18818, 32768, 0], + [4138, 7794, 10961, 32768, 0], +]; +/// COEFF_BR_LUMA_32, q-context 0: the same table as [`COEFF_BR_LUMA_32`], for `base_q_idx` 0..=20. +pub const COEFF_BR_LUMA_32_Q0: [[u16; 5]; 21] = [ + [2331, 3662, 5244, 32768, 0], + [2891, 4771, 6145, 32768, 0], + [4598, 7623, 9729, 32768, 0], + [3520, 6845, 9199, 32768, 0], + [3417, 6119, 9324, 32768, 0], + [2601, 5412, 7385, 32768, 0], + [600, 1173, 1744, 32768, 0], + [7672, 13286, 17469, 32768, 0], + [4232, 7792, 10793, 32768, 0], + [2915, 5317, 7397, 32768, 0], + [2318, 4356, 6152, 32768, 0], + [2127, 4000, 5554, 32768, 0], + [1850, 3478, 5275, 32768, 0], + [977, 1933, 2843, 32768, 0], + [18280, 24387, 27989, 32768, 0], + [15852, 22671, 26185, 32768, 0], + [13845, 20951, 24789, 32768, 0], + [11055, 17966, 22129, 32768, 0], + [9138, 15422, 19801, 32768, 0], + [7454, 13145, 17456, 32768, 0], + [3370, 6393, 9013, 32768, 0], +]; +/// COEFF_BR_CHROMA_8, q-context 0: the same table as [`COEFF_BR_CHROMA_8`], for `base_q_idx` 0..=20. +pub const COEFF_BR_CHROMA_8_Q0: [[u16; 5]; 21] = [ + [15460, 21696, 25469, 32768, 0], + [12170, 19249, 23191, 32768, 0], + [8723, 15027, 19332, 32768, 0], + [6428, 11704, 15874, 32768, 0], + [4922, 9292, 13052, 32768, 0], + [4139, 7695, 11010, 32768, 0], + [2291, 4508, 6598, 32768, 0], + [19856, 26920, 29828, 32768, 0], + [17923, 25289, 28792, 32768, 0], + [14278, 21968, 26297, 32768, 0], + [10910, 18136, 22950, 32768, 0], + [8423, 14815, 19627, 32768, 0], + [6771, 12283, 16774, 32768, 0], + [4074, 7750, 11081, 32768, 0], + [19852, 26074, 28672, 32768, 0], + [19371, 26110, 28989, 32768, 0], + [16265, 23873, 27663, 32768, 0], + [12758, 20378, 24952, 32768, 0], + [10095, 17098, 21961, 32768, 0], + [8250, 14628, 19451, 32768, 0], + [5205, 9745, 13622, 32768, 0], +]; +/// COEFF_BR_CHROMA_16, q-context 0: the same table as [`COEFF_BR_CHROMA_16`], for `base_q_idx` 0..=20. +pub const COEFF_BR_CHROMA_16_Q0: [[u16; 5]; 21] = [ + [10870, 16684, 20949, 32768, 0], + [9664, 15230, 18680, 32768, 0], + [6886, 12109, 15408, 32768, 0], + [4825, 8900, 12305, 32768, 0], + [3630, 7162, 10314, 32768, 0], + [3036, 6429, 9387, 32768, 0], + [1671, 3296, 4940, 32768, 0], + [13819, 19159, 23026, 32768, 0], + [11984, 19108, 23120, 32768, 0], + [10690, 17210, 21663, 32768, 0], + [7984, 14154, 18333, 32768, 0], + [6868, 12294, 16124, 32768, 0], + [5274, 8994, 12868, 32768, 0], + [2988, 5771, 8424, 32768, 0], + [19736, 26647, 29141, 32768, 0], + [18933, 26070, 28984, 32768, 0], + [15779, 23048, 27200, 32768, 0], + [12638, 20061, 24532, 32768, 0], + [10692, 17545, 22220, 32768, 0], + [9217, 15251, 20054, 32768, 0], + [5078, 9284, 12594, 32768, 0], +]; +/// COEFF_BR_CHROMA_32, q-context 0: the same table as [`COEFF_BR_CHROMA_32`], for `base_q_idx` 0..=20. +pub const COEFF_BR_CHROMA_32_Q0: [[u16; 5]; 21] = [ + [5842, 9229, 10838, 32768, 0], + [2313, 3491, 4276, 32768, 0], + [2998, 6104, 7496, 32768, 0], + [2420, 7447, 9868, 32768, 0], + [3034, 8495, 10923, 32768, 0], + [4076, 8937, 10975, 32768, 0], + [1086, 2370, 3299, 32768, 0], + [9714, 17254, 20444, 32768, 0], + [8543, 13698, 17123, 32768, 0], + [4918, 9007, 11910, 32768, 0], + [4129, 7532, 10553, 32768, 0], + [2364, 5533, 8058, 32768, 0], + [1834, 3546, 5563, 32768, 0], + [1473, 2908, 4133, 32768, 0], + [15405, 21193, 25619, 32768, 0], + [15691, 21952, 26561, 32768, 0], + [12962, 19194, 24165, 32768, 0], + [10272, 17855, 22129, 32768, 0], + [8588, 15270, 20718, 32768, 0], + [8682, 14669, 19500, 32768, 0], + [4870, 9636, 13205, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_16, q-context 0: the same table as [`COEFF_BASE_EOB_LUMA_16`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_EOB_LUMA_16_Q0: [[u16; 4]; 4] = [ + [1786, 12612, 32768, 0], + [30663, 31625, 32768, 0], + [32339, 32468, 32768, 0], + [31148, 31833, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_32, q-context 0: the same table as [`COEFF_BASE_EOB_LUMA_32`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_EOB_LUMA_32_Q0: [[u16; 4]; 4] = [ + [1787, 2532, 32768, 0], + [30832, 31662, 32768, 0], + [31824, 32682, 32768, 0], + [32133, 32569, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_64, q-context 0: the same table as [`COEFF_BASE_EOB_LUMA_64`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_EOB_LUMA_64_Q0: [[u16; 4]; 4] = [ + [1725, 3449, 32768, 0], + [31102, 31935, 32768, 0], + [32457, 32613, 32768, 0], + [32412, 32649, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_8, q-context 0: the same table as [`COEFF_BASE_EOB_CHROMA_8`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_EOB_CHROMA_8_Q0: [[u16; 4]; 4] = [ + [12608, 27820, 32768, 0], + [30680, 32225, 32768, 0], + [30809, 32335, 32768, 0], + [31299, 32423, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_16, q-context 0: the same table as [`COEFF_BASE_EOB_CHROMA_16`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_EOB_CHROMA_16_Q0: [[u16; 4]; 4] = [ + [18857, 23865, 32768, 0], + [31428, 32428, 32768, 0], + [31744, 32373, 32768, 0], + [31775, 32526, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_32, q-context 0: the same table as [`COEFF_BASE_EOB_CHROMA_32`], for `base_q_idx` 0..=20. +pub const COEFF_BASE_EOB_CHROMA_32_Q0: [[u16; 4]; 4] = [ + [13751, 22235, 32768, 0], + [32089, 32409, 32768, 0], + [27084, 27920, 32768, 0], + [29291, 32594, 32768, 0], +]; + +// q-context 1: base_q_idx 21..=60. + +/// TXB_SKIP_LUMA_64, q-context 1: the same table as [`TXB_SKIP_LUMA_64`], for `base_q_idx` 21..=60. +pub const TXB_SKIP_LUMA_64_Q1: [u16; 3] = [26584, 32768, 0]; +/// TXB_SKIP_LUMA_32, q-context 1: the same table as [`TXB_SKIP_LUMA_32`], for `base_q_idx` 21..=60. +pub const TXB_SKIP_LUMA_32_Q1: [u16; 3] = [26726, 32768, 0]; +/// TXB_SKIP_LUMA_16, q-context 1: the same table as [`TXB_SKIP_LUMA_16`], for `base_q_idx` 21..=60. +pub const TXB_SKIP_LUMA_16_Q1: [u16; 3] = [31901, 32768, 0]; +/// TXB_SKIP_CHROMA_8, q-context 1: the same table as [`TXB_SKIP_CHROMA_8`], for `base_q_idx` 21..=60. +pub const TXB_SKIP_CHROMA_8_Q1: [[u16; 3]; 3] = + [[4419, 32768, 0], [16294, 32768, 0], [28345, 32768, 0]]; +/// TXB_SKIP_CHROMA_16, q-context 1: the same table as [`TXB_SKIP_CHROMA_16`], for `base_q_idx` 21..=60. +pub const TXB_SKIP_CHROMA_16_Q1: [[u16; 3]; 3] = + [[4215, 32768, 0], [15756, 32768, 0], [28341, 32768, 0]]; +/// TXB_SKIP_CHROMA_32, q-context 1: the same table as [`TXB_SKIP_CHROMA_32`], for `base_q_idx` 21..=60. +pub const TXB_SKIP_CHROMA_32_Q1: [[u16; 3]; 3] = + [[5583, 32768, 0], [21313, 32768, 0], [29390, 32768, 0]]; +/// EOB_EXTRA_LUMA_16, q-context 1: the same table as [`EOB_EXTRA_LUMA_16`], for `base_q_idx` 21..=60. +pub const EOB_EXTRA_LUMA_16_Q1: [[u16; 3]; 9] = [ + [22409, 32768, 0], + [21012, 32768, 0], + [15650, 32768, 0], + [17395, 32768, 0], + [15469, 32768, 0], + [20205, 32768, 0], + [19511, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_LUMA_32, q-context 1: the same table as [`EOB_EXTRA_LUMA_32`], for `base_q_idx` 21..=60. +pub const EOB_EXTRA_LUMA_32_Q1: [[u16; 3]; 9] = [ + [25991, 32768, 0], + [20314, 32768, 0], + [17731, 32768, 0], + [19678, 32768, 0], + [18649, 32768, 0], + [17307, 32768, 0], + [21798, 32768, 0], + [17549, 32768, 0], + [15630, 32768, 0], +]; +/// EOB_EXTRA_LUMA_64, q-context 1: the same table as [`EOB_EXTRA_LUMA_64`], for `base_q_idx` 21..=60. +pub const EOB_EXTRA_LUMA_64_Q1: [[u16; 3]; 9] = [ + [26605, 32768, 0], + [11304, 32768, 0], + [16726, 32768, 0], + [16560, 32768, 0], + [20866, 32768, 0], + [23524, 32768, 0], + [19878, 32768, 0], + [13469, 32768, 0], + [23084, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_8, q-context 1: the same table as [`EOB_EXTRA_CHROMA_8`], for `base_q_idx` 21..=60. +pub const EOB_EXTRA_CHROMA_8_Q1: [[u16; 3]; 9] = [ + [22117, 32768, 0], + [22028, 32768, 0], + [18650, 32768, 0], + [16042, 32768, 0], + [15885, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_16, q-context 1: the same table as [`EOB_EXTRA_CHROMA_16`], for `base_q_idx` 21..=60. +pub const EOB_EXTRA_CHROMA_16_Q1: [[u16; 3]; 9] = [ + [24220, 32768, 0], + [22480, 32768, 0], + [17737, 32768, 0], + [18916, 32768, 0], + [19268, 32768, 0], + [18412, 32768, 0], + [18844, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_32, q-context 1: the same table as [`EOB_EXTRA_CHROMA_32`], for `base_q_idx` 21..=60. +pub const EOB_EXTRA_CHROMA_32_Q1: [[u16; 3]; 9] = [ + [26585, 32768, 0], + [21469, 32768, 0], + [20432, 32768, 0], + [17735, 32768, 0], + [19280, 32768, 0], + [15235, 32768, 0], + [20297, 32768, 0], + [22471, 32768, 0], + [28997, 32768, 0], +]; +/// EOB_PT_1024_LUMA, q-context 1: the same table as [`EOB_PT_1024_LUMA`], for `base_q_idx` 21..=60. +pub const EOB_PT_1024_LUMA_Q1: [u16; 12] = [ + 696, 948, 3145, 5702, 9706, 13217, 17851, 21856, 25692, 28034, 32768, 0, +]; +/// EOB_PT_1024_CHROMA, q-context 1: the same table as [`EOB_PT_1024_CHROMA`], for `base_q_idx` 21..=60. +pub const EOB_PT_1024_CHROMA_Q1: [u16; 12] = [ + 2672, 3591, 9330, 17084, 22725, 24284, 26527, 28027, 28377, 30876, 32768, 0, +]; +/// EOB_PT_256_LUMA, q-context 1: the same table as [`EOB_PT_256_LUMA`], for `base_q_idx` 21..=60. +pub const EOB_PT_256_LUMA_Q1: [u16; 10] = + [1448, 2109, 4151, 6263, 9329, 13260, 17944, 23300, 32768, 0]; +/// EOB_PT_256_CHROMA, q-context 1: the same table as [`EOB_PT_256_CHROMA`], for `base_q_idx` 21..=60. +pub const EOB_PT_256_CHROMA_Q1: [u16; 10] = [ + 6402, 8148, 12623, 15072, 18728, 22847, 26447, 29377, 32768, 0, +]; +/// EOB_PT_64_CHROMA, q-context 1: the same table as [`EOB_PT_64_CHROMA`], for `base_q_idx` 21..=60. +pub const EOB_PT_64_CHROMA_Q1: [u16; 8] = [8609, 10612, 14624, 18714, 22614, 29024, 32768, 0]; +/// COEFF_BASE_LUMA_16, q-context 1: the same table as [`COEFF_BASE_LUMA_16`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_LUMA_16_Q1: [[u16; 5]; 42] = [ + [7555, 14942, 18501, 32768, 0], + [24410, 31178, 32287, 32768, 0], + [14394, 26738, 30253, 32768, 0], + [8413, 19554, 25195, 32768, 0], + [4766, 12924, 18785, 32768, 0], + [2029, 5806, 9207, 32768, 0], + [26776, 32364, 32663, 32768, 0], + [18732, 29967, 31931, 32768, 0], + [11005, 23786, 28852, 32768, 0], + [6466, 16909, 23510, 32768, 0], + [3044, 8638, 13419, 32768, 0], + [29208, 32582, 32704, 32768, 0], + [20068, 30857, 32208, 32768, 0], + [12003, 25085, 29595, 32768, 0], + [6947, 17750, 24189, 32768, 0], + [3245, 9103, 14007, 32768, 0], + [27359, 32465, 32669, 32768, 0], + [19421, 30614, 32174, 32768, 0], + [11915, 25010, 29579, 32768, 0], + [6950, 17676, 24074, 32768, 0], + [3007, 8473, 13096, 32768, 0], + [29002, 32676, 32735, 32768, 0], + [22102, 31849, 32576, 32768, 0], + [14408, 28009, 31405, 32768, 0], + [9027, 21679, 27931, 32768, 0], + [4694, 12678, 18748, 32768, 0], + [28216, 32528, 32682, 32768, 0], + [20849, 31264, 32318, 32768, 0], + [12756, 25815, 29751, 32768, 0], + [7565, 18801, 24923, 32768, 0], + [3509, 9533, 14477, 32768, 0], + [30133, 32687, 32739, 32768, 0], + [23063, 31910, 32515, 32768, 0], + [14588, 28051, 31132, 32768, 0], + [9085, 21649, 27457, 32768, 0], + [4261, 11654, 17264, 32768, 0], + [29518, 32691, 32748, 32768, 0], + [22451, 31959, 32613, 32768, 0], + [14864, 28722, 31700, 32768, 0], + [9695, 22964, 28716, 32768, 0], + [4932, 13358, 19502, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_LUMA_32, q-context 1: the same table as [`COEFF_BASE_LUMA_32`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_LUMA_32_Q1: [[u16; 5]; 42] = [ + [3078, 6839, 9890, 32768, 0], + [13837, 20450, 24479, 32768, 0], + [5914, 14222, 19328, 32768, 0], + [3866, 10267, 14762, 32768, 0], + [2612, 7208, 11042, 32768, 0], + [1067, 2991, 4776, 32768, 0], + [25817, 31646, 32529, 32768, 0], + [13708, 26338, 30385, 32768, 0], + [7328, 18585, 24870, 32768, 0], + [4691, 13080, 19276, 32768, 0], + [1825, 5253, 8352, 32768, 0], + [29386, 32315, 32624, 32768, 0], + [17160, 29001, 31360, 32768, 0], + [9602, 21862, 27396, 32768, 0], + [5915, 15772, 22148, 32768, 0], + [2786, 7779, 12047, 32768, 0], + [29246, 32450, 32663, 32768, 0], + [18696, 29929, 31818, 32768, 0], + [10510, 23369, 28560, 32768, 0], + [6229, 16499, 23125, 32768, 0], + [2608, 7448, 11705, 32768, 0], + [30753, 32710, 32748, 32768, 0], + [21638, 31487, 32503, 32768, 0], + [12937, 26854, 30870, 32768, 0], + [8182, 20596, 26970, 32768, 0], + [3637, 10269, 15497, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_LUMA_64, q-context 1: the same table as [`COEFF_BASE_LUMA_64`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_LUMA_64_Q1: [[u16; 5]; 42] = [ + [1035, 2807, 4156, 32768, 0], + [13162, 18138, 20939, 32768, 0], + [2696, 6633, 8755, 32768, 0], + [1373, 4161, 6853, 32768, 0], + [1099, 2746, 4716, 32768, 0], + [340, 1021, 1599, 32768, 0], + [22826, 30419, 32135, 32768, 0], + [10395, 21762, 26942, 32768, 0], + [4726, 12407, 17361, 32768, 0], + [2447, 7080, 10593, 32768, 0], + [1227, 3717, 6011, 32768, 0], + [28156, 31424, 31934, 32768, 0], + [16915, 27754, 30373, 32768, 0], + [9148, 20990, 26431, 32768, 0], + [5950, 15515, 21148, 32768, 0], + [2492, 7327, 11526, 32768, 0], + [30602, 32477, 32670, 32768, 0], + [20026, 29955, 31568, 32768, 0], + [11220, 23628, 28105, 32768, 0], + [6652, 17019, 22973, 32768, 0], + [3064, 8536, 13043, 32768, 0], + [31769, 32724, 32748, 32768, 0], + [22230, 30887, 32373, 32768, 0], + [12234, 25079, 29731, 32768, 0], + [7326, 18816, 25353, 32768, 0], + [3933, 10907, 16616, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_8, q-context 1: the same table as [`COEFF_BASE_CHROMA_8`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_CHROMA_8_Q1: [[u16; 5]; 42] = [ + [8639, 19339, 24429, 32768, 0], + [24404, 31837, 32525, 32768, 0], + [16997, 29425, 31784, 32768, 0], + [11253, 24234, 29149, 32768, 0], + [6751, 17394, 24028, 32768, 0], + [3490, 9830, 15191, 32768, 0], + [26283, 32471, 32714, 32768, 0], + [19599, 31168, 32442, 32768, 0], + [13146, 26954, 30893, 32768, 0], + [8214, 20588, 26890, 32768, 0], + [4699, 13081, 19300, 32768, 0], + [28212, 32458, 32669, 32768, 0], + [18594, 30316, 32100, 32768, 0], + [11219, 24408, 29234, 32768, 0], + [6865, 17656, 24149, 32768, 0], + [3678, 10362, 16006, 32768, 0], + [25825, 32136, 32616, 32768, 0], + [17313, 29853, 32021, 32768, 0], + [11197, 24471, 29472, 32768, 0], + [6947, 17781, 24405, 32768, 0], + [3768, 10660, 16261, 32768, 0], + [27352, 32500, 32706, 32768, 0], + [20850, 31468, 32469, 32768, 0], + [14021, 27707, 31133, 32768, 0], + [8964, 21748, 27838, 32768, 0], + [5437, 14665, 21187, 32768, 0], + [26304, 32492, 32698, 32768, 0], + [20409, 31380, 32385, 32768, 0], + [13682, 27222, 30632, 32768, 0], + [8974, 21236, 26685, 32768, 0], + [4234, 11665, 16934, 32768, 0], + [26273, 32357, 32711, 32768, 0], + [20672, 31242, 32441, 32768, 0], + [14172, 27254, 30902, 32768, 0], + [9870, 21898, 27275, 32768, 0], + [5164, 13506, 19270, 32768, 0], + [26725, 32459, 32728, 32768, 0], + [20991, 31442, 32527, 32768, 0], + [13071, 26434, 30811, 32768, 0], + [8184, 20090, 26742, 32768, 0], + [4803, 13255, 19895, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_16, q-context 1: the same table as [`COEFF_BASE_CHROMA_16`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_CHROMA_16_Q1: [[u16; 5]; 42] = [ + [6465, 16958, 21688, 32768, 0], + [25199, 31514, 32360, 32768, 0], + [14774, 27149, 30607, 32768, 0], + [9257, 21438, 26972, 32768, 0], + [5723, 15183, 21882, 32768, 0], + [3150, 8879, 13731, 32768, 0], + [26989, 32262, 32682, 32768, 0], + [17396, 29937, 32085, 32768, 0], + [11387, 24901, 29784, 32768, 0], + [7289, 18821, 25548, 32768, 0], + [3734, 10577, 16086, 32768, 0], + [29728, 32501, 32695, 32768, 0], + [17431, 29701, 31903, 32768, 0], + [9921, 22826, 28300, 32768, 0], + [5896, 15434, 22068, 32768, 0], + [3430, 9646, 14757, 32768, 0], + [28614, 32511, 32705, 32768, 0], + [19364, 30638, 32263, 32768, 0], + [13129, 26254, 30402, 32768, 0], + [8754, 20484, 26440, 32768, 0], + [4378, 11607, 17110, 32768, 0], + [30292, 32671, 32744, 32768, 0], + [21780, 31603, 32501, 32768, 0], + [14314, 27829, 31291, 32768, 0], + [9611, 22327, 28263, 32768, 0], + [4890, 13087, 19065, 32768, 0], + [25862, 32567, 32733, 32768, 0], + [20794, 32050, 32567, 32768, 0], + [17243, 30625, 32254, 32768, 0], + [13283, 27628, 31474, 32768, 0], + [9669, 22532, 28918, 32768, 0], + [27435, 32697, 32748, 32768, 0], + [24922, 32390, 32714, 32768, 0], + [21449, 31504, 32536, 32768, 0], + [16392, 29729, 31832, 32768, 0], + [11692, 24884, 29076, 32768, 0], + [24193, 32290, 32735, 32768, 0], + [18909, 31104, 32563, 32768, 0], + [12236, 26841, 31403, 32768, 0], + [8171, 21840, 29082, 32768, 0], + [7224, 17280, 25275, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_32, q-context 1: the same table as [`COEFF_BASE_CHROMA_32`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_CHROMA_32_Q1: [[u16; 5]; 42] = [ + [5244, 12150, 16906, 32768, 0], + [20486, 26858, 29701, 32768, 0], + [7756, 18317, 23735, 32768, 0], + [3452, 9256, 13146, 32768, 0], + [2020, 5206, 8229, 32768, 0], + [1801, 4993, 7903, 32768, 0], + [27051, 31858, 32531, 32768, 0], + [15988, 27531, 30619, 32768, 0], + [9188, 21484, 26719, 32768, 0], + [6273, 17186, 23800, 32768, 0], + [3108, 9355, 14764, 32768, 0], + [31076, 32520, 32680, 32768, 0], + [18119, 30037, 31850, 32768, 0], + [10244, 22969, 27472, 32768, 0], + [4692, 14077, 19273, 32768, 0], + [3694, 11677, 17556, 32768, 0], + [30060, 32581, 32720, 32768, 0], + [21011, 30775, 32120, 32768, 0], + [11931, 24820, 29289, 32768, 0], + [7119, 17662, 24356, 32768, 0], + [3833, 10706, 16304, 32768, 0], + [31954, 32731, 32748, 32768, 0], + [23913, 31724, 32489, 32768, 0], + [15520, 28060, 31286, 32768, 0], + [11517, 23008, 28571, 32768, 0], + [6193, 14508, 20629, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BR_LUMA_16, q-context 1: the same table as [`COEFF_BR_LUMA_16`], for `base_q_idx` 21..=60. +pub const COEFF_BR_LUMA_16_Q1: [[u16; 5]; 21] = [ + [13549, 19724, 23158, 32768, 0], + [11844, 18382, 22246, 32768, 0], + [7919, 13619, 17773, 32768, 0], + [5486, 10143, 13946, 32768, 0], + [4166, 7983, 11324, 32768, 0], + [3364, 6506, 9427, 32768, 0], + [1598, 3160, 4674, 32768, 0], + [15281, 20979, 23781, 32768, 0], + [14939, 22119, 25952, 32768, 0], + [11363, 18407, 22812, 32768, 0], + [8609, 14857, 19370, 32768, 0], + [6737, 12184, 16480, 32768, 0], + [5506, 10263, 14262, 32768, 0], + [2990, 5786, 8380, 32768, 0], + [20249, 25253, 27417, 32768, 0], + [21070, 27518, 30001, 32768, 0], + [16854, 24469, 28074, 32768, 0], + [12864, 20486, 25000, 32768, 0], + [9962, 16978, 21778, 32768, 0], + [8074, 14338, 19048, 32768, 0], + [4494, 8479, 11906, 32768, 0], +]; +/// COEFF_BR_LUMA_32, q-context 1: the same table as [`COEFF_BR_LUMA_32`], for `base_q_idx` 21..=60. +pub const COEFF_BR_LUMA_32_Q1: [[u16; 5]; 21] = [ + [5705, 10930, 15725, 32768, 0], + [7946, 12765, 16115, 32768, 0], + [6801, 12123, 16226, 32768, 0], + [5462, 10135, 14200, 32768, 0], + [4189, 8011, 11507, 32768, 0], + [3191, 6229, 9408, 32768, 0], + [1057, 2137, 3212, 32768, 0], + [10018, 17067, 21491, 32768, 0], + [7380, 12582, 16453, 32768, 0], + [6068, 10845, 14339, 32768, 0], + [5098, 9198, 12555, 32768, 0], + [4312, 8010, 11119, 32768, 0], + [3700, 6966, 9781, 32768, 0], + [1693, 3326, 4887, 32768, 0], + [18757, 24930, 27774, 32768, 0], + [17648, 24596, 27817, 32768, 0], + [14707, 22052, 26026, 32768, 0], + [11720, 18852, 23292, 32768, 0], + [9357, 15952, 20525, 32768, 0], + [7810, 13753, 18210, 32768, 0], + [3879, 7333, 10328, 32768, 0], +]; +/// COEFF_BR_CHROMA_8, q-context 1: the same table as [`COEFF_BR_CHROMA_8`], for `base_q_idx` 21..=60. +pub const COEFF_BR_CHROMA_8_Q1: [[u16; 5]; 21] = [ + [14899, 21217, 24503, 32768, 0], + [13519, 20283, 24047, 32768, 0], + [9429, 15966, 20365, 32768, 0], + [6700, 12355, 16652, 32768, 0], + [5088, 9704, 13716, 32768, 0], + [4243, 8154, 11731, 32768, 0], + [2702, 5364, 7861, 32768, 0], + [22745, 28388, 30454, 32768, 0], + [20235, 27146, 29922, 32768, 0], + [15896, 23715, 27637, 32768, 0], + [11840, 19350, 24131, 32768, 0], + [9122, 15932, 20880, 32768, 0], + [7488, 13581, 18362, 32768, 0], + [5114, 9568, 13370, 32768, 0], + [20845, 26553, 28932, 32768, 0], + [20981, 27372, 29884, 32768, 0], + [17781, 25335, 28785, 32768, 0], + [13760, 21708, 26297, 32768, 0], + [10975, 18415, 23365, 32768, 0], + [9045, 15789, 20686, 32768, 0], + [6130, 11199, 15423, 32768, 0], +]; +/// COEFF_BR_CHROMA_16, q-context 1: the same table as [`COEFF_BR_CHROMA_16`], for `base_q_idx` 21..=60. +pub const COEFF_BR_CHROMA_16_Q1: [[u16; 5]; 21] = [ + [13960, 19617, 22829, 32768, 0], + [11150, 17341, 21228, 32768, 0], + [7150, 12964, 17190, 32768, 0], + [5331, 10002, 13867, 32768, 0], + [4167, 7744, 11057, 32768, 0], + [3480, 6629, 9646, 32768, 0], + [1883, 3784, 5686, 32768, 0], + [18752, 25660, 28912, 32768, 0], + [16968, 24586, 28030, 32768, 0], + [13520, 21055, 25313, 32768, 0], + [10453, 17626, 22280, 32768, 0], + [8386, 14505, 19116, 32768, 0], + [6742, 12595, 17008, 32768, 0], + [4273, 8140, 11499, 32768, 0], + [22120, 27827, 30233, 32768, 0], + [20563, 27358, 29895, 32768, 0], + [17076, 24644, 28153, 32768, 0], + [13362, 20942, 25309, 32768, 0], + [10794, 17965, 22695, 32768, 0], + [9014, 15652, 20319, 32768, 0], + [5708, 10512, 14497, 32768, 0], +]; +/// COEFF_BR_CHROMA_32, q-context 1: the same table as [`COEFF_BR_CHROMA_32`], for `base_q_idx` 21..=60. +pub const COEFF_BR_CHROMA_32_Q1: [[u16; 5]; 21] = [ + [8278, 13242, 15922, 32768, 0], + [10547, 15867, 18919, 32768, 0], + [9106, 15842, 20609, 32768, 0], + [6833, 13007, 17218, 32768, 0], + [4811, 9712, 13923, 32768, 0], + [3985, 7352, 11128, 32768, 0], + [1688, 3458, 5262, 32768, 0], + [12951, 21861, 26510, 32768, 0], + [9788, 16044, 20276, 32768, 0], + [6309, 11244, 14870, 32768, 0], + [5183, 9349, 12566, 32768, 0], + [4389, 8229, 11492, 32768, 0], + [3633, 6945, 10620, 32768, 0], + [3600, 6847, 9907, 32768, 0], + [21748, 28137, 30255, 32768, 0], + [19436, 26581, 29560, 32768, 0], + [16359, 24201, 27953, 32768, 0], + [13961, 21693, 25871, 32768, 0], + [11544, 18686, 23322, 32768, 0], + [9372, 16462, 20952, 32768, 0], + [6138, 11210, 15390, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_16, q-context 1: the same table as [`COEFF_BASE_EOB_LUMA_16`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_EOB_LUMA_16_Q1: [[u16; 4]; 4] = [ + [2644, 25198, 32768, 0], + [32038, 32451, 32768, 0], + [32639, 32695, 32768, 0], + [32166, 32518, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_32, q-context 1: the same table as [`COEFF_BASE_EOB_LUMA_32`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_EOB_LUMA_32_Q1: [[u16; 4]; 4] = [ + [1044, 2257, 32768, 0], + [30755, 31923, 32768, 0], + [32208, 32693, 32768, 0], + [32244, 32615, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_64, q-context 1: the same table as [`COEFF_BASE_EOB_LUMA_64`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_EOB_LUMA_64_Q1: [[u16; 4]; 4] = [ + [478, 1834, 32768, 0], + [31005, 31987, 32768, 0], + [32317, 32724, 32768, 0], + [30865, 32648, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_8, q-context 1: the same table as [`COEFF_BASE_EOB_CHROMA_8`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_EOB_CHROMA_8_Q1: [[u16; 4]; 4] = [ + [26279, 30968, 32768, 0], + [31142, 32495, 32768, 0], + [31713, 32540, 32768, 0], + [31929, 32594, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_16, q-context 1: the same table as [`COEFF_BASE_EOB_CHROMA_16`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_EOB_CHROMA_16_Q1: [[u16; 4]; 4] = [ + [17187, 27668, 32768, 0], + [31714, 32550, 32768, 0], + [32283, 32678, 32768, 0], + [31930, 32563, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_32, q-context 1: the same table as [`COEFF_BASE_EOB_CHROMA_32`], for `base_q_idx` 21..=60. +pub const COEFF_BASE_EOB_CHROMA_32_Q1: [[u16; 4]; 4] = [ + [21317, 26207, 32768, 0], + [29133, 30868, 32768, 0], + [29311, 31231, 32768, 0], + [29657, 31087, 32768, 0], +]; + +// q-context 3: base_q_idx 121..=255. + +/// TXB_SKIP_LUMA_64, q-context 3: the same table as [`TXB_SKIP_LUMA_64`], for `base_q_idx` 121..=255. +pub const TXB_SKIP_LUMA_64_Q3: [u16; 3] = [31539, 32768, 0]; +/// TXB_SKIP_LUMA_32, q-context 3: the same table as [`TXB_SKIP_LUMA_32`], for `base_q_idx` 121..=255. +pub const TXB_SKIP_LUMA_32_Q3: [u16; 3] = [31671, 32768, 0]; +/// TXB_SKIP_LUMA_16, q-context 3: the same table as [`TXB_SKIP_LUMA_16`], for `base_q_idx` 121..=255. +pub const TXB_SKIP_LUMA_16_Q3: [u16; 3] = [32510, 32768, 0]; +/// TXB_SKIP_CHROMA_8, q-context 3: the same table as [`TXB_SKIP_CHROMA_8`], for `base_q_idx` 121..=255. +pub const TXB_SKIP_CHROMA_8_Q3: [[u16; 3]; 3] = + [[2786, 32768, 0], [11194, 32768, 0], [20155, 32768, 0]]; +/// TXB_SKIP_CHROMA_16, q-context 3: the same table as [`TXB_SKIP_CHROMA_16`], for `base_q_idx` 121..=255. +pub const TXB_SKIP_CHROMA_16_Q3: [[u16; 3]; 3] = + [[3440, 32768, 0], [13117, 32768, 0], [22702, 32768, 0]]; +/// TXB_SKIP_CHROMA_32, q-context 3: the same table as [`TXB_SKIP_CHROMA_32`], for `base_q_idx` 121..=255. +pub const TXB_SKIP_CHROMA_32_Q3: [[u16; 3]; 3] = + [[4656, 32768, 0], [16074, 32768, 0], [24704, 32768, 0]]; +/// EOB_EXTRA_LUMA_16, q-context 3: the same table as [`EOB_EXTRA_LUMA_16`], for `base_q_idx` 121..=255. +pub const EOB_EXTRA_LUMA_16_Q3: [[u16; 3]; 9] = [ + [19941, 32768, 0], + [20527, 32768, 0], + [21470, 32768, 0], + [22487, 32768, 0], + [19558, 32768, 0], + [22354, 32768, 0], + [20331, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_LUMA_32, q-context 3: the same table as [`EOB_EXTRA_LUMA_32`], for `base_q_idx` 121..=255. +pub const EOB_EXTRA_LUMA_32_Q3: [[u16; 3]; 9] = [ + [21442, 32768, 0], + [22358, 32768, 0], + [18503, 32768, 0], + [20291, 32768, 0], + [19945, 32768, 0], + [21294, 32768, 0], + [21178, 32768, 0], + [19400, 32768, 0], + [10556, 32768, 0], +]; +/// EOB_EXTRA_LUMA_64, q-context 3: the same table as [`EOB_EXTRA_LUMA_64`], for `base_q_idx` 121..=255. +pub const EOB_EXTRA_LUMA_64_Q3: [[u16; 3]; 9] = [ + [26064, 32768, 0], + [22098, 32768, 0], + [19613, 32768, 0], + [20525, 32768, 0], + [17595, 32768, 0], + [16618, 32768, 0], + [20497, 32768, 0], + [18989, 32768, 0], + [15513, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_8, q-context 3: the same table as [`EOB_EXTRA_CHROMA_8`], for `base_q_idx` 121..=255. +pub const EOB_EXTRA_CHROMA_8_Q3: [[u16; 3]; 9] = [ + [20125, 32768, 0], + [20559, 32768, 0], + [21707, 32768, 0], + [22296, 32768, 0], + [17333, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_16, q-context 3: the same table as [`EOB_EXTRA_CHROMA_16`], for `base_q_idx` 121..=255. +pub const EOB_EXTRA_CHROMA_16_Q3: [[u16; 3]; 9] = [ + [22752, 32768, 0], + [25006, 32768, 0], + [22075, 32768, 0], + [21576, 32768, 0], + [17740, 32768, 0], + [21690, 32768, 0], + [19211, 32768, 0], + [16384, 32768, 0], + [16384, 32768, 0], +]; +/// EOB_EXTRA_CHROMA_32, q-context 3: the same table as [`EOB_EXTRA_CHROMA_32`], for `base_q_idx` 121..=255. +pub const EOB_EXTRA_CHROMA_32_Q3: [[u16; 3]; 9] = [ + [24648, 32768, 0], + [24949, 32768, 0], + [20708, 32768, 0], + [23905, 32768, 0], + [20501, 32768, 0], + [9558, 32768, 0], + [9423, 32768, 0], + [30365, 32768, 0], + [19253, 32768, 0], +]; +/// EOB_PT_1024_LUMA, q-context 3: the same table as [`EOB_PT_1024_LUMA`], for `base_q_idx` 121..=255. +pub const EOB_PT_1024_LUMA_Q3: [u16; 12] = [ + 6698, 8334, 11961, 15762, 20186, 23862, 27434, 29326, 31082, 32050, 32768, 0, +]; +/// EOB_PT_1024_CHROMA, q-context 3: the same table as [`EOB_PT_1024_CHROMA`], for `base_q_idx` 121..=255. +pub const EOB_PT_1024_CHROMA_Q3: [u16; 12] = [ + 20569, 22426, 25569, 26859, 28053, 28913, 29486, 29724, 29807, 32570, 32768, 0, +]; +/// EOB_PT_256_LUMA, q-context 3: the same table as [`EOB_PT_256_LUMA`], for `base_q_idx` 121..=255. +pub const EOB_PT_256_LUMA_Q3: [u16; 10] = [ + 5348, 7113, 11820, 15924, 22106, 26777, 30334, 31757, 32768, 0, +]; +/// EOB_PT_256_CHROMA, q-context 3: the same table as [`EOB_PT_256_CHROMA`], for `base_q_idx` 121..=255. +pub const EOB_PT_256_CHROMA_Q3: [u16; 10] = [ + 23110, 24597, 27140, 28894, 30167, 30927, 31392, 32094, 32768, 0, +]; +/// EOB_PT_64_CHROMA, q-context 3: the same table as [`EOB_PT_64_CHROMA`], for `base_q_idx` 121..=255. +pub const EOB_PT_64_CHROMA_Q3: [u16; 8] = [24212, 25708, 28268, 30035, 31307, 32049, 32768, 0]; +/// COEFF_BASE_LUMA_16, q-context 3: the same table as [`COEFF_BASE_LUMA_16`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_LUMA_16_Q3: [[u16; 5]; 42] = [ + [7876, 16901, 21741, 32768, 0], + [24001, 31898, 32625, 32768, 0], + [14529, 27959, 31451, 32768, 0], + [8273, 20818, 27258, 32768, 0], + [5278, 14673, 21510, 32768, 0], + [2983, 8843, 14039, 32768, 0], + [28016, 32574, 32732, 32768, 0], + [17471, 30306, 32301, 32768, 0], + [10224, 24063, 29728, 32768, 0], + [6602, 17954, 25052, 32768, 0], + [4002, 11585, 17759, 32768, 0], + [30190, 32634, 32739, 32768, 0], + [17497, 30282, 32270, 32768, 0], + [10229, 23729, 29538, 32768, 0], + [6344, 17211, 24440, 32768, 0], + [3849, 11189, 17108, 32768, 0], + [28570, 32583, 32726, 32768, 0], + [17521, 30161, 32238, 32768, 0], + [10153, 23565, 29378, 32768, 0], + [6455, 17341, 24443, 32768, 0], + [3907, 11042, 17024, 32768, 0], + [30689, 32715, 32748, 32768, 0], + [21546, 31840, 32610, 32768, 0], + [13547, 27581, 31459, 32768, 0], + [8912, 21757, 28309, 32768, 0], + [5548, 15080, 22046, 32768, 0], + [30783, 32540, 32685, 32768, 0], + [17540, 29528, 31668, 32768, 0], + [10160, 21468, 26783, 32768, 0], + [4724, 13393, 20054, 32768, 0], + [2702, 8174, 13102, 32768, 0], + [31648, 32686, 32742, 32768, 0], + [20954, 31094, 32337, 32768, 0], + [12420, 25698, 30179, 32768, 0], + [7304, 19320, 26248, 32768, 0], + [4366, 12261, 18864, 32768, 0], + [31581, 32723, 32748, 32768, 0], + [21373, 31586, 32525, 32768, 0], + [12744, 26625, 30885, 32768, 0], + [7431, 20322, 26950, 32768, 0], + [4692, 13323, 20111, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_LUMA_32, q-context 3: the same table as [`COEFF_BASE_LUMA_32`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_LUMA_32_Q3: [[u16; 5]; 42] = [ + [5992, 14304, 19765, 32768, 0], + [22612, 31238, 32456, 32768, 0], + [13456, 27162, 31087, 32768, 0], + [8001, 20062, 26504, 32768, 0], + [5168, 14105, 20764, 32768, 0], + [2632, 7771, 12385, 32768, 0], + [27034, 32344, 32709, 32768, 0], + [15850, 29415, 31997, 32768, 0], + [9494, 22776, 28841, 32768, 0], + [6151, 16830, 23969, 32768, 0], + [3461, 10039, 15722, 32768, 0], + [30134, 32569, 32731, 32768, 0], + [15638, 29422, 31945, 32768, 0], + [9150, 21865, 28218, 32768, 0], + [5647, 15719, 22676, 32768, 0], + [3402, 9772, 15477, 32768, 0], + [28530, 32586, 32735, 32768, 0], + [17139, 30298, 32292, 32768, 0], + [10200, 24039, 29685, 32768, 0], + [6419, 17674, 24786, 32768, 0], + [3544, 10225, 15824, 32768, 0], + [31333, 32726, 32748, 32768, 0], + [20618, 31487, 32544, 32768, 0], + [12901, 27217, 31232, 32768, 0], + [8624, 21734, 28171, 32768, 0], + [5104, 14191, 20748, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_LUMA_64, q-context 3: the same table as [`COEFF_BASE_LUMA_64`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_LUMA_64_Q3: [[u16; 5]; 42] = [ + [4137, 10847, 15682, 32768, 0], + [17824, 27001, 30058, 32768, 0], + [10204, 22796, 28291, 32768, 0], + [6076, 15935, 22125, 32768, 0], + [3852, 10937, 16816, 32768, 0], + [2252, 6324, 10131, 32768, 0], + [25840, 32016, 32662, 32768, 0], + [15109, 28268, 31531, 32768, 0], + [9385, 22231, 28340, 32768, 0], + [6082, 16672, 23479, 32768, 0], + [3318, 9427, 14681, 32768, 0], + [30594, 32574, 32718, 32768, 0], + [16836, 29552, 31859, 32768, 0], + [9556, 22542, 28356, 32768, 0], + [6305, 16725, 23540, 32768, 0], + [3376, 9895, 15184, 32768, 0], + [29383, 32617, 32745, 32768, 0], + [18891, 30809, 32401, 32768, 0], + [11688, 25942, 30687, 32768, 0], + [7468, 19469, 26651, 32768, 0], + [3909, 11358, 17012, 32768, 0], + [31564, 32736, 32748, 32768, 0], + [20906, 31611, 32600, 32768, 0], + [13191, 27621, 31537, 32768, 0], + [8768, 22029, 28676, 32768, 0], + [5079, 14109, 20906, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_8, q-context 3: the same table as [`COEFF_BASE_CHROMA_8`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_CHROMA_8_Q3: [[u16; 5]; 42] = [ + [8626, 20271, 26216, 32768, 0], + [26707, 32406, 32711, 32768, 0], + [16999, 30329, 32286, 32768, 0], + [11445, 25123, 30286, 32768, 0], + [6411, 18828, 25601, 32768, 0], + [6801, 12458, 20248, 32768, 0], + [29918, 32682, 32748, 32768, 0], + [20649, 31739, 32618, 32768, 0], + [12879, 27773, 31581, 32768, 0], + [7896, 21751, 28244, 32768, 0], + [5260, 14870, 23698, 32768, 0], + [29252, 32593, 32731, 32768, 0], + [17072, 30460, 32294, 32768, 0], + [10653, 24143, 29365, 32768, 0], + [6536, 17490, 23983, 32768, 0], + [4929, 13170, 20085, 32768, 0], + [28137, 32518, 32715, 32768, 0], + [18171, 30784, 32407, 32768, 0], + [11437, 25436, 30459, 32768, 0], + [7252, 18534, 26176, 32768, 0], + [4126, 13353, 20978, 32768, 0], + [31162, 32726, 32748, 32768, 0], + [23017, 32222, 32701, 32768, 0], + [15629, 29233, 32046, 32768, 0], + [9387, 22621, 29480, 32768, 0], + [6922, 17616, 25010, 32768, 0], + [28838, 32265, 32614, 32768, 0], + [19701, 30206, 31920, 32768, 0], + [11214, 22410, 27933, 32768, 0], + [5320, 14177, 23034, 32768, 0], + [5049, 12881, 17827, 32768, 0], + [27484, 32471, 32734, 32768, 0], + [21076, 31526, 32561, 32768, 0], + [12707, 26303, 31211, 32768, 0], + [8169, 21722, 28219, 32768, 0], + [6045, 19406, 27042, 32768, 0], + [27753, 32572, 32745, 32768, 0], + [20832, 31878, 32653, 32768, 0], + [13250, 27356, 31674, 32768, 0], + [7718, 21508, 29858, 32768, 0], + [7209, 18350, 25559, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_16, q-context 3: the same table as [`COEFF_BASE_CHROMA_16`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_CHROMA_16_Q3: [[u16; 5]; 42] = [ + [7833, 18369, 24095, 32768, 0], + [26650, 32273, 32702, 32768, 0], + [16371, 29961, 32191, 32768, 0], + [11055, 24082, 29629, 32768, 0], + [6892, 18644, 25400, 32768, 0], + [5006, 13057, 19240, 32768, 0], + [29834, 32666, 32748, 32768, 0], + [19577, 31335, 32570, 32768, 0], + [12253, 26509, 31122, 32768, 0], + [7991, 20772, 27711, 32768, 0], + [5677, 15910, 23059, 32768, 0], + [30109, 32532, 32720, 32768, 0], + [16747, 30166, 32252, 32768, 0], + [10134, 23542, 29184, 32768, 0], + [5791, 16176, 23556, 32768, 0], + [4362, 10414, 17284, 32768, 0], + [29492, 32626, 32748, 32768, 0], + [19894, 31402, 32525, 32768, 0], + [12942, 27071, 30869, 32768, 0], + [8346, 21216, 27405, 32768, 0], + [6572, 17087, 23859, 32768, 0], + [32035, 32735, 32748, 32768, 0], + [22957, 31838, 32618, 32768, 0], + [14724, 28572, 31772, 32768, 0], + [10364, 23999, 29553, 32768, 0], + [7004, 18433, 25655, 32768, 0], + [27528, 32277, 32681, 32768, 0], + [16959, 31171, 32096, 32768, 0], + [10486, 23593, 27962, 32768, 0], + [8192, 16384, 23211, 32768, 0], + [8937, 17873, 20852, 32768, 0], + [27715, 32002, 32615, 32768, 0], + [15073, 29491, 31676, 32768, 0], + [11264, 24576, 28672, 32768, 0], + [2341, 18725, 23406, 32768, 0], + [7282, 18204, 25486, 32768, 0], + [28547, 32213, 32657, 32768, 0], + [20788, 29773, 32239, 32768, 0], + [6780, 21469, 30508, 32768, 0], + [5958, 14895, 23831, 32768, 0], + [16384, 21845, 27307, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BASE_CHROMA_32, q-context 3: the same table as [`COEFF_BASE_CHROMA_32`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_CHROMA_32_Q3: [[u16; 5]; 42] = [ + [11206, 21090, 26561, 32768, 0], + [28759, 32279, 32671, 32768, 0], + [14171, 27952, 31569, 32768, 0], + [9743, 22907, 29141, 32768, 0], + [6871, 17886, 24868, 32768, 0], + [4960, 13152, 19315, 32768, 0], + [31077, 32661, 32748, 32768, 0], + [19400, 31195, 32515, 32768, 0], + [12752, 26858, 31040, 32768, 0], + [8370, 22098, 28591, 32768, 0], + [5457, 15373, 22298, 32768, 0], + [31697, 32706, 32748, 32768, 0], + [17860, 30657, 32333, 32768, 0], + [12510, 24812, 29261, 32768, 0], + [6180, 19124, 24722, 32768, 0], + [5041, 13548, 17959, 32768, 0], + [31552, 32716, 32748, 32768, 0], + [21908, 31769, 32623, 32768, 0], + [14470, 28201, 31565, 32768, 0], + [9493, 22982, 28608, 32768, 0], + [6858, 17240, 24137, 32768, 0], + [32543, 32752, 32756, 32768, 0], + [24286, 32097, 32666, 32768, 0], + [15958, 29217, 32024, 32768, 0], + [10207, 24234, 29958, 32768, 0], + [6929, 18305, 25652, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], + [8192, 16384, 24576, 32768, 0], +]; +/// COEFF_BR_LUMA_16, q-context 3: the same table as [`COEFF_BR_LUMA_16`], for `base_q_idx` 121..=255. +pub const COEFF_BR_LUMA_16_Q3: [[u16; 5]; 21] = [ + [17113, 23733, 27081, 32768, 0], + [14139, 21406, 25452, 32768, 0], + [8552, 15002, 19776, 32768, 0], + [5871, 11120, 15378, 32768, 0], + [4455, 8616, 12253, 32768, 0], + [3469, 6910, 10386, 32768, 0], + [2255, 4553, 6782, 32768, 0], + [18224, 24376, 27053, 32768, 0], + [19290, 26710, 29614, 32768, 0], + [14936, 22991, 27184, 32768, 0], + [11238, 18951, 23762, 32768, 0], + [8786, 15617, 20588, 32768, 0], + [7317, 13228, 18003, 32768, 0], + [5101, 9512, 13493, 32768, 0], + [22639, 28222, 30210, 32768, 0], + [23216, 29331, 31307, 32768, 0], + [19075, 26762, 29895, 32768, 0], + [15014, 23113, 27457, 32768, 0], + [11938, 19857, 24752, 32768, 0], + [9942, 17280, 22282, 32768, 0], + [7167, 13144, 17752, 32768, 0], +]; +/// COEFF_BR_LUMA_32, q-context 3: the same table as [`COEFF_BR_LUMA_32`], for `base_q_idx` 121..=255. +pub const COEFF_BR_LUMA_32_Q3: [[u16; 5]; 21] = [ + [12162, 18785, 22648, 32768, 0], + [12749, 19697, 23806, 32768, 0], + [8580, 15297, 20346, 32768, 0], + [6169, 11749, 16543, 32768, 0], + [4836, 9391, 13448, 32768, 0], + [3821, 7711, 11613, 32768, 0], + [2228, 4601, 7070, 32768, 0], + [16319, 24725, 28280, 32768, 0], + [15698, 23277, 27168, 32768, 0], + [12726, 20368, 25047, 32768, 0], + [9912, 17015, 21976, 32768, 0], + [7888, 14220, 19179, 32768, 0], + [6777, 12284, 17018, 32768, 0], + [4492, 8590, 12252, 32768, 0], + [23249, 28904, 30947, 32768, 0], + [21050, 27908, 30512, 32768, 0], + [17440, 25340, 28949, 32768, 0], + [14059, 22018, 26541, 32768, 0], + [11288, 18903, 23898, 32768, 0], + [9411, 16342, 21428, 32768, 0], + [6278, 11588, 15944, 32768, 0], +]; +/// COEFF_BR_CHROMA_8, q-context 3: the same table as [`COEFF_BR_CHROMA_8`], for `base_q_idx` 121..=255. +pub const COEFF_BR_CHROMA_8_Q3: [[u16; 5]; 21] = [ + [17616, 24586, 28112, 32768, 0], + [15809, 23299, 27155, 32768, 0], + [10767, 18890, 23793, 32768, 0], + [7727, 14255, 18865, 32768, 0], + [6129, 11926, 16882, 32768, 0], + [4482, 9704, 14861, 32768, 0], + [3277, 7452, 11522, 32768, 0], + [22956, 28551, 30730, 32768, 0], + [22724, 28937, 30961, 32768, 0], + [18467, 26324, 29580, 32768, 0], + [13234, 20713, 25649, 32768, 0], + [11181, 17592, 22481, 32768, 0], + [8291, 18358, 24576, 32768, 0], + [7568, 11881, 14984, 32768, 0], + [24948, 29001, 31147, 32768, 0], + [25674, 30619, 32151, 32768, 0], + [20841, 26793, 29603, 32768, 0], + [14669, 24356, 28666, 32768, 0], + [11334, 23593, 28219, 32768, 0], + [8922, 14762, 22873, 32768, 0], + [8301, 13544, 20535, 32768, 0], +]; +/// COEFF_BR_CHROMA_16, q-context 3: the same table as [`COEFF_BR_CHROMA_16`], for `base_q_idx` 121..=255. +pub const COEFF_BR_CHROMA_16_Q3: [[u16; 5]; 21] = [ + [15820, 22738, 26488, 32768, 0], + [13530, 20885, 25216, 32768, 0], + [8395, 15530, 20452, 32768, 0], + [6574, 12321, 16380, 32768, 0], + [5353, 10419, 14568, 32768, 0], + [4613, 8446, 12381, 32768, 0], + [3440, 7158, 9903, 32768, 0], + [24247, 29051, 31224, 32768, 0], + [22118, 28058, 30369, 32768, 0], + [16498, 24768, 28389, 32768, 0], + [12920, 21175, 26137, 32768, 0], + [10730, 18619, 25352, 32768, 0], + [10187, 16279, 22791, 32768, 0], + [9310, 14631, 22127, 32768, 0], + [24970, 30558, 32057, 32768, 0], + [24801, 29942, 31698, 32768, 0], + [22432, 28453, 30855, 32768, 0], + [19054, 25680, 29580, 32768, 0], + [14392, 23036, 28109, 32768, 0], + [12495, 20947, 26650, 32768, 0], + [12442, 20326, 26214, 32768, 0], +]; +/// COEFF_BR_CHROMA_32, q-context 3: the same table as [`COEFF_BR_CHROMA_32`], for `base_q_idx` 121..=255. +pub const COEFF_BR_CHROMA_32_Q3: [[u16; 5]; 21] = [ + [13981, 20067, 23226, 32768, 0], + [16922, 23580, 26783, 32768, 0], + [11005, 19039, 24487, 32768, 0], + [7389, 14218, 19798, 32768, 0], + [5598, 11505, 17206, 32768, 0], + [6090, 11213, 15659, 32768, 0], + [3820, 7371, 10119, 32768, 0], + [21082, 26925, 29675, 32768, 0], + [21262, 28627, 31128, 32768, 0], + [18392, 26454, 30437, 32768, 0], + [14870, 22910, 27096, 32768, 0], + [12620, 19484, 24908, 32768, 0], + [9290, 16553, 22802, 32768, 0], + [6668, 14288, 20004, 32768, 0], + [27704, 31055, 31949, 32768, 0], + [24709, 29978, 31788, 32768, 0], + [21668, 29264, 31657, 32768, 0], + [18295, 26968, 30074, 32768, 0], + [16399, 24422, 29313, 32768, 0], + [14347, 23026, 28104, 32768, 0], + [12370, 19806, 24477, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_16, q-context 3: the same table as [`COEFF_BASE_EOB_LUMA_16`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_EOB_LUMA_16_Q3: [[u16; 4]; 4] = [ + [19980, 30591, 32768, 0], + [32219, 32597, 32768, 0], + [32581, 32706, 32768, 0], + [31803, 32287, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_32, q-context 3: the same table as [`COEFF_BASE_EOB_LUMA_32`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_EOB_LUMA_32_Q3: [[u16; 4]; 4] = [ + [24647, 30463, 32768, 0], + [32412, 32695, 32768, 0], + [32468, 32720, 32768, 0], + [31269, 32523, 32768, 0], +]; +/// COEFF_BASE_EOB_LUMA_64, q-context 3: the same table as [`COEFF_BASE_EOB_LUMA_64`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_EOB_LUMA_64_Q3: [[u16; 4]; 4] = [ + [12358, 24977, 32768, 0], + [31331, 32385, 32768, 0], + [32634, 32756, 32768, 0], + [30411, 32548, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_8, q-context 3: the same table as [`COEFF_BASE_EOB_CHROMA_8`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_EOB_CHROMA_8_Q3: [[u16; 4]; 4] = [ + [27558, 31151, 32768, 0], + [32020, 32640, 32768, 0], + [32097, 32575, 32768, 0], + [32242, 32719, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_16, q-context 3: the same table as [`COEFF_BASE_EOB_CHROMA_16`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_EOB_CHROMA_16_Q3: [[u16; 4]; 4] = [ + [26473, 30507, 32768, 0], + [32431, 32723, 32768, 0], + [32196, 32611, 32768, 0], + [31588, 32528, 32768, 0], +]; +/// COEFF_BASE_EOB_CHROMA_32, q-context 3: the same table as [`COEFF_BASE_EOB_CHROMA_32`], for `base_q_idx` 121..=255. +pub const COEFF_BASE_EOB_CHROMA_32_Q3: [[u16; 4]; 4] = [ + [28482, 31505, 32768, 0], + [32152, 32701, 32768, 0], + [31732, 32598, 32768, 0], + [31767, 32712, 32768, 0], +]; + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 171de5bb..aa443b01 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -205,11 +205,24 @@ impl MvComponentCdfs { } } +/// Picks one of the four q-context variants of a coefficient table +/// (`crate::cdf`'s `_Q0`/`_Q1`/plain/`_Q3` constants), `q_ctx` already reduced +/// to 0..=3 by the caller. +pub(crate) fn pick(q_ctx: usize, q0: T, q1: T, q2: T, q3: T) -> T { + match q_ctx { + 0 => q0, + 1 => q1, + 2 => q2, + _ => q3, + } +} + impl Cdfs { /// The defaults a key frame starts from (spec 8.4, `init_coeff_cdfs` and - /// `init_non_coeff_cdfs`), for the one quantizer context whose tables this - /// crate carries. - pub fn new() -> Cdfs { + /// `init_non_coeff_cdfs`), for coefficient q-context `q_ctx` (0..=3, spec + /// 8.3.2's `Get_Qctx`). The non-coefficient tables do not vary with the + /// quantizer, so they are the same for every `q_ctx`. + pub fn new(q_ctx: usize) -> Cdfs { Cdfs { partition_w64: cdf::PARTITION_W64, partition_w32: cdf::PARTITION_W32, @@ -218,41 +231,245 @@ impl Cdfs { uv_mode_no_cfl: cdf::UV_MODE_NO_CFL, uv_mode_cfl: cdf::UV_MODE_CFL, angle_delta: cdf::ANGLE_DELTA, - txb_skip_luma_16: [cdf::TXB_SKIP_LUMA_16], - txb_skip_chroma_8: cdf::TXB_SKIP_CHROMA_8, - eob_pt_256_luma: cdf::EOB_PT_256_LUMA, - eob_pt_64_chroma: cdf::EOB_PT_64_CHROMA, - eob_extra_luma_16: cdf::EOB_EXTRA_LUMA_16, - eob_extra_chroma_8: cdf::EOB_EXTRA_CHROMA_8, - base_luma_16: cdf::COEFF_BASE_LUMA_16, - base_chroma_8: cdf::COEFF_BASE_CHROMA_8, - base_eob_luma_16: cdf::COEFF_BASE_EOB_LUMA_16, - base_eob_chroma_8: cdf::COEFF_BASE_EOB_CHROMA_8, - br_luma_16: cdf::COEFF_BR_LUMA_16, - br_chroma_8: cdf::COEFF_BR_CHROMA_8, + txb_skip_luma_16: [pick( + q_ctx, + cdf::TXB_SKIP_LUMA_16_Q0, + cdf::TXB_SKIP_LUMA_16_Q1, + cdf::TXB_SKIP_LUMA_16, + cdf::TXB_SKIP_LUMA_16_Q3, + )], + txb_skip_chroma_8: pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_8_Q0, + cdf::TXB_SKIP_CHROMA_8_Q1, + cdf::TXB_SKIP_CHROMA_8, + cdf::TXB_SKIP_CHROMA_8_Q3, + ), + eob_pt_256_luma: pick( + q_ctx, + cdf::EOB_PT_256_LUMA_Q0, + cdf::EOB_PT_256_LUMA_Q1, + cdf::EOB_PT_256_LUMA, + cdf::EOB_PT_256_LUMA_Q3, + ), + eob_pt_64_chroma: pick( + q_ctx, + cdf::EOB_PT_64_CHROMA_Q0, + cdf::EOB_PT_64_CHROMA_Q1, + cdf::EOB_PT_64_CHROMA, + cdf::EOB_PT_64_CHROMA_Q3, + ), + eob_extra_luma_16: pick( + q_ctx, + cdf::EOB_EXTRA_LUMA_16_Q0, + cdf::EOB_EXTRA_LUMA_16_Q1, + cdf::EOB_EXTRA_LUMA_16, + cdf::EOB_EXTRA_LUMA_16_Q3, + ), + eob_extra_chroma_8: pick( + q_ctx, + cdf::EOB_EXTRA_CHROMA_8_Q0, + cdf::EOB_EXTRA_CHROMA_8_Q1, + cdf::EOB_EXTRA_CHROMA_8, + cdf::EOB_EXTRA_CHROMA_8_Q3, + ), + base_luma_16: pick( + q_ctx, + cdf::COEFF_BASE_LUMA_16_Q0, + cdf::COEFF_BASE_LUMA_16_Q1, + cdf::COEFF_BASE_LUMA_16, + cdf::COEFF_BASE_LUMA_16_Q3, + ), + base_chroma_8: pick( + q_ctx, + cdf::COEFF_BASE_CHROMA_8_Q0, + cdf::COEFF_BASE_CHROMA_8_Q1, + cdf::COEFF_BASE_CHROMA_8, + cdf::COEFF_BASE_CHROMA_8_Q3, + ), + base_eob_luma_16: pick( + q_ctx, + cdf::COEFF_BASE_EOB_LUMA_16_Q0, + cdf::COEFF_BASE_EOB_LUMA_16_Q1, + cdf::COEFF_BASE_EOB_LUMA_16, + cdf::COEFF_BASE_EOB_LUMA_16_Q3, + ), + base_eob_chroma_8: pick( + q_ctx, + cdf::COEFF_BASE_EOB_CHROMA_8_Q0, + cdf::COEFF_BASE_EOB_CHROMA_8_Q1, + cdf::COEFF_BASE_EOB_CHROMA_8, + cdf::COEFF_BASE_EOB_CHROMA_8_Q3, + ), + br_luma_16: pick( + q_ctx, + cdf::COEFF_BR_LUMA_16_Q0, + cdf::COEFF_BR_LUMA_16_Q1, + cdf::COEFF_BR_LUMA_16, + cdf::COEFF_BR_LUMA_16_Q3, + ), + br_chroma_8: pick( + q_ctx, + cdf::COEFF_BR_CHROMA_8_Q0, + cdf::COEFF_BR_CHROMA_8_Q1, + cdf::COEFF_BR_CHROMA_8, + cdf::COEFF_BR_CHROMA_8_Q3, + ), partition_w16: cdf::PARTITION_W16, - txb_skip_luma_32: [cdf::TXB_SKIP_LUMA_32], - txb_skip_luma_64: [cdf::TXB_SKIP_LUMA_64], - txb_skip_chroma_16: cdf::TXB_SKIP_CHROMA_16, - txb_skip_chroma_32: cdf::TXB_SKIP_CHROMA_32, - eob_pt_1024_luma: cdf::EOB_PT_1024_LUMA, - eob_pt_1024_chroma: cdf::EOB_PT_1024_CHROMA, - eob_pt_256_chroma: cdf::EOB_PT_256_CHROMA, - eob_extra_luma_32: cdf::EOB_EXTRA_LUMA_32, - eob_extra_luma_64: cdf::EOB_EXTRA_LUMA_64, - eob_extra_chroma_16: cdf::EOB_EXTRA_CHROMA_16, - eob_extra_chroma_32: cdf::EOB_EXTRA_CHROMA_32, - base_luma_32: cdf::COEFF_BASE_LUMA_32, - base_luma_64: cdf::COEFF_BASE_LUMA_64, - base_chroma_16: cdf::COEFF_BASE_CHROMA_16, - base_chroma_32: cdf::COEFF_BASE_CHROMA_32, - base_eob_luma_32: cdf::COEFF_BASE_EOB_LUMA_32, - base_eob_luma_64: cdf::COEFF_BASE_EOB_LUMA_64, - base_eob_chroma_16: cdf::COEFF_BASE_EOB_CHROMA_16, - base_eob_chroma_32: cdf::COEFF_BASE_EOB_CHROMA_32, - br_luma_32: cdf::COEFF_BR_LUMA_32, - br_chroma_16: cdf::COEFF_BR_CHROMA_16, - br_chroma_32: cdf::COEFF_BR_CHROMA_32, + txb_skip_luma_32: [pick( + q_ctx, + cdf::TXB_SKIP_LUMA_32_Q0, + cdf::TXB_SKIP_LUMA_32_Q1, + cdf::TXB_SKIP_LUMA_32, + cdf::TXB_SKIP_LUMA_32_Q3, + )], + txb_skip_luma_64: [pick( + q_ctx, + cdf::TXB_SKIP_LUMA_64_Q0, + cdf::TXB_SKIP_LUMA_64_Q1, + cdf::TXB_SKIP_LUMA_64, + cdf::TXB_SKIP_LUMA_64_Q3, + )], + txb_skip_chroma_16: pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_16_Q0, + cdf::TXB_SKIP_CHROMA_16_Q1, + cdf::TXB_SKIP_CHROMA_16, + cdf::TXB_SKIP_CHROMA_16_Q3, + ), + txb_skip_chroma_32: pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_32_Q0, + cdf::TXB_SKIP_CHROMA_32_Q1, + cdf::TXB_SKIP_CHROMA_32, + cdf::TXB_SKIP_CHROMA_32_Q3, + ), + eob_pt_1024_luma: pick( + q_ctx, + cdf::EOB_PT_1024_LUMA_Q0, + cdf::EOB_PT_1024_LUMA_Q1, + cdf::EOB_PT_1024_LUMA, + cdf::EOB_PT_1024_LUMA_Q3, + ), + eob_pt_1024_chroma: pick( + q_ctx, + cdf::EOB_PT_1024_CHROMA_Q0, + cdf::EOB_PT_1024_CHROMA_Q1, + cdf::EOB_PT_1024_CHROMA, + cdf::EOB_PT_1024_CHROMA_Q3, + ), + eob_pt_256_chroma: pick( + q_ctx, + cdf::EOB_PT_256_CHROMA_Q0, + cdf::EOB_PT_256_CHROMA_Q1, + cdf::EOB_PT_256_CHROMA, + cdf::EOB_PT_256_CHROMA_Q3, + ), + eob_extra_luma_32: pick( + q_ctx, + cdf::EOB_EXTRA_LUMA_32_Q0, + cdf::EOB_EXTRA_LUMA_32_Q1, + cdf::EOB_EXTRA_LUMA_32, + cdf::EOB_EXTRA_LUMA_32_Q3, + ), + eob_extra_luma_64: pick( + q_ctx, + cdf::EOB_EXTRA_LUMA_64_Q0, + cdf::EOB_EXTRA_LUMA_64_Q1, + cdf::EOB_EXTRA_LUMA_64, + cdf::EOB_EXTRA_LUMA_64_Q3, + ), + eob_extra_chroma_16: pick( + q_ctx, + cdf::EOB_EXTRA_CHROMA_16_Q0, + cdf::EOB_EXTRA_CHROMA_16_Q1, + cdf::EOB_EXTRA_CHROMA_16, + cdf::EOB_EXTRA_CHROMA_16_Q3, + ), + eob_extra_chroma_32: pick( + q_ctx, + cdf::EOB_EXTRA_CHROMA_32_Q0, + cdf::EOB_EXTRA_CHROMA_32_Q1, + cdf::EOB_EXTRA_CHROMA_32, + cdf::EOB_EXTRA_CHROMA_32_Q3, + ), + base_luma_32: pick( + q_ctx, + cdf::COEFF_BASE_LUMA_32_Q0, + cdf::COEFF_BASE_LUMA_32_Q1, + cdf::COEFF_BASE_LUMA_32, + cdf::COEFF_BASE_LUMA_32_Q3, + ), + base_luma_64: pick( + q_ctx, + cdf::COEFF_BASE_LUMA_64_Q0, + cdf::COEFF_BASE_LUMA_64_Q1, + cdf::COEFF_BASE_LUMA_64, + cdf::COEFF_BASE_LUMA_64_Q3, + ), + base_chroma_16: pick( + q_ctx, + cdf::COEFF_BASE_CHROMA_16_Q0, + cdf::COEFF_BASE_CHROMA_16_Q1, + cdf::COEFF_BASE_CHROMA_16, + cdf::COEFF_BASE_CHROMA_16_Q3, + ), + base_chroma_32: pick( + q_ctx, + cdf::COEFF_BASE_CHROMA_32_Q0, + cdf::COEFF_BASE_CHROMA_32_Q1, + cdf::COEFF_BASE_CHROMA_32, + cdf::COEFF_BASE_CHROMA_32_Q3, + ), + base_eob_luma_32: pick( + q_ctx, + cdf::COEFF_BASE_EOB_LUMA_32_Q0, + cdf::COEFF_BASE_EOB_LUMA_32_Q1, + cdf::COEFF_BASE_EOB_LUMA_32, + cdf::COEFF_BASE_EOB_LUMA_32_Q3, + ), + base_eob_luma_64: pick( + q_ctx, + cdf::COEFF_BASE_EOB_LUMA_64_Q0, + cdf::COEFF_BASE_EOB_LUMA_64_Q1, + cdf::COEFF_BASE_EOB_LUMA_64, + cdf::COEFF_BASE_EOB_LUMA_64_Q3, + ), + base_eob_chroma_16: pick( + q_ctx, + cdf::COEFF_BASE_EOB_CHROMA_16_Q0, + cdf::COEFF_BASE_EOB_CHROMA_16_Q1, + cdf::COEFF_BASE_EOB_CHROMA_16, + cdf::COEFF_BASE_EOB_CHROMA_16_Q3, + ), + base_eob_chroma_32: pick( + q_ctx, + cdf::COEFF_BASE_EOB_CHROMA_32_Q0, + cdf::COEFF_BASE_EOB_CHROMA_32_Q1, + cdf::COEFF_BASE_EOB_CHROMA_32, + cdf::COEFF_BASE_EOB_CHROMA_32_Q3, + ), + br_luma_32: pick( + q_ctx, + cdf::COEFF_BR_LUMA_32_Q0, + cdf::COEFF_BR_LUMA_32_Q1, + cdf::COEFF_BR_LUMA_32, + cdf::COEFF_BR_LUMA_32_Q3, + ), + br_chroma_16: pick( + q_ctx, + cdf::COEFF_BR_CHROMA_16_Q0, + cdf::COEFF_BR_CHROMA_16_Q1, + cdf::COEFF_BR_CHROMA_16, + cdf::COEFF_BR_CHROMA_16_Q3, + ), + br_chroma_32: pick( + q_ctx, + cdf::COEFF_BR_CHROMA_32_Q0, + cdf::COEFF_BR_CHROMA_32_Q1, + cdf::COEFF_BR_CHROMA_32, + cdf::COEFF_BR_CHROMA_32_Q3, + ), dc_sign_luma: cdf::DC_SIGN_LUMA, intra_tx_type_16: cdf::INTRA_TX_TYPE_SET2_16, dc_sign_chroma: cdf::DC_SIGN_CHROMA, @@ -351,7 +568,7 @@ mod tests { /// was coded. #[test] fn the_two_luma_sets_share_the_base_range_table() { - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(2); cdfs.txb(TxbSet::Luma64, 0).br[0][0] = 1; assert_eq!(cdfs.txb(TxbSet::Luma32, 0).br[0][0], 1); } @@ -360,7 +577,7 @@ mod tests { /// what a luma block adapts must not reach the chroma one. #[test] fn the_sign_tables_are_shared_within_a_plane_type_and_not_across() { - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(2); cdfs.txb(TxbSet::Luma32, 0).dc_sign[1][0] = 1; cdfs.txb(TxbSet::Chroma16, 0).dc_sign[2][0] = 2; assert_eq!(cdfs.txb(TxbSet::Luma64, 0).dc_sign[1][0], 1); @@ -374,7 +591,7 @@ mod tests { /// further along. #[test] fn the_luma_end_of_block_table_is_shared_and_chromas_is_not() { - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(2); cdfs.txb(TxbSet::Luma32, 0).eob_pt[0] = 7; assert_eq!(cdfs.txb(TxbSet::Luma64, 0).eob_pt[0], 7); assert_ne!(cdfs.txb(TxbSet::Chroma32, 0).eob_pt[0], 7); @@ -384,7 +601,7 @@ mod tests { /// writes exactly what a non-adapting one does. #[test] fn the_state_starts_at_the_defaults() { - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(2); assert_eq!( cdfs.txb(TxbSet::Luma32, 0).base[3], cdf::COEFF_BASE_LUMA_32[3] @@ -411,7 +628,7 @@ mod tests { /// hazard the coefficient sets guard against above. #[test] fn the_mv_components_are_separate_and_do_not_share_adaptation() { - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(2); cdfs.mv_comp[0].class[0] = 1; cdfs.mv_comp[0].bit[3][0] = 2; assert_ne!(cdfs.mv_comp[1].class[0], 1); diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index c2fe7ee6..bb0113f3 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -719,15 +719,14 @@ fn coeffs(levels: &[i32], side: usize) -> Vec { /// Encodes one picture as a key frame. /// -/// `base_q_idx` is the frame's quantizer index, and has to sit in the band -/// whose coefficient CDFs the tile writer carries (61..=120). `deadzone` is the -/// quantizer's rounding offset: 0.5 rounds to nearest, and smaller values trade -/// fidelity for rate. +/// `base_q_idx` is the frame's quantizer index (0..=255); the tile writer +/// picks its coefficient CDFs from one of four q contexts by that index. +/// `deadzone` is the quantizer's rounding offset: 0.5 rounds to nearest, and +/// smaller values trade fidelity for rate. /// /// # Errors /// Returns an error when the picture is not a whole number of 32x32 blocks, -/// when its planes are not 4:2:0 of that size, or when the tile writer refuses -/// the quantizer index. +/// or when its planes are not 4:2:0 of that size. pub fn encode_key_frame(picture: &Picture, base_q_idx: u8, deadzone: f64) -> Result { encode_key_frame_with_modes(picture, base_q_idx, deadzone, &KEY_FRAME_MODES) } @@ -910,7 +909,7 @@ fn encode_key_frame_inner( #[cfg(test)] mod tests { use super::*; - use crate::intra::{D135_PRED, D45_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; + use crate::intra::{D45_PRED, D135_PRED, H_PRED, KEY_FRAME_MODES, NON_DIRECTIONAL, V_PRED}; use std::io::Write; use std::process::{Command, Stdio}; @@ -1029,6 +1028,17 @@ mod tests { assert_eq!(decoded.u, encoded.reconstruction.u, "{width}x{height}: U"); assert_eq!(decoded.v, encoded.reconstruction.v, "{width}x{height}: V"); } + // One q index from each of the four coefficient-CDF contexts + // (0..=20, 21..=60, 61..=120, 121..=255), on a single frame size. + let (width, height) = (64usize, 64usize); + let picture = test_card(width, height); + for &q in &[15u8, 45, 100, 200] { + let encoded = encode_key_frame(&picture, q, 0.5).unwrap(); + let decoded = ffmpeg_decode(&encoded.stream, width, height); + assert_eq!(decoded.y, encoded.reconstruction.y, "q={q}: luma"); + assert_eq!(decoded.u, encoded.reconstruction.u, "q={q}: U"); + assert_eq!(decoded.v, encoded.reconstruction.v, "q={q}: V"); + } } /// One frame of a real clip, scaled to a whole number of 32x32 blocks. @@ -1507,6 +1517,19 @@ mod tests { } previous = Some((encoded.stream.len(), quality)); } + + // Bytes must not jump up across a q-context boundary: a wrong CDF + // table for the far side would show up as a rate discontinuity here, + // even though a coarser quantizer always codes no more than a finer + // one on the same picture. + for &(lo, hi) in &[(20u8, 21u8), (60, 61), (120, 121)] { + let lo_bytes = encode_key_frame(&picture, lo, 0.5).unwrap().stream.len(); + let hi_bytes = encode_key_frame(&picture, hi, 0.5).unwrap().stream.len(); + assert!( + hi_bytes <= lo_bytes, + "q {lo}->{hi} crosses a context boundary: {lo_bytes} -> {hi_bytes} bytes" + ); + } } /// A flat picture is a flat stream: every block predicts its neighbours' @@ -1537,8 +1560,6 @@ mod tests { let mut short = Picture::grey(64, 64); short.u.truncate(10); assert!(encode_key_frame(&short, 100, 0.5).is_err()); - // The tile writer carries the CDFs of one q context only. - assert!(encode_key_frame(&Picture::grey(64, 64), 40, 0.5).is_err()); } /// A frame of real video, rather than a picture built to be easy. diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 34b83f33..ae88875e 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -16,7 +16,7 @@ use ec_core::{Error, Result}; use crate::cdf; use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables}; use crate::msac::SymbolEncoder; -use crate::mvstack::{find_mv_stack, single_ref_ctx, MiGrid, MiInfo}; +use crate::mvstack::{MiGrid, MiInfo, find_mv_stack, single_ref_ctx}; /// `PARTITION_NONE` (spec 6.10.4): the whole block, undivided. const PARTITION_NONE: usize = 0; @@ -81,8 +81,18 @@ const MAX_BR_LEVEL: i32 = NUM_BASE_LEVELS + COEFF_BASE_RANGE; /// followed by that many bits, and the spec's decoder reads at most twenty of /// each, so a level a decoder cannot read back is refused rather than written. const MAX_LEVEL: i32 = MAX_BR_LEVEL + (1 << 19); -/// The q-context band whose default CDFs [`crate::cdf`] carries. -const Q_CTX_2: std::ops::RangeInclusive = 61..=120; + +/// The coefficient q-context (spec 8.3.2's `Get_Qctx`, `Default_..._Cdf`'s +/// leading index) a frame's `base_q_idx` picks its default CDFs from. +/// [`crate::cdf`] carries all four, one constant set per context. +fn q_ctx_of(base_q_idx: u8) -> usize { + match base_q_idx { + 0..=20 => 0, + 21..=60 => 1, + 61..=120 => 2, + _ => 3, + } +} /// Both writers here code whole superblocks only: a partial one forces the /// partition syntax down the block tree, which they do not code yet. @@ -194,8 +204,7 @@ pub fn dc_key_frame_tile( /// Returns an error when the frame is not a whole number of 64x64 superblocks, /// when `levels` does not carry exactly one level per superblock, when a level /// is outside the range the base and base-range syntax carry (`-14..=14` -/// without zero), or when `base_q_idx` is outside the q-context band whose -/// default CDFs this crate carries. +/// without zero). pub fn dc_key_frame_tile_levels( mi_cols: u32, mi_rows: u32, @@ -204,7 +213,29 @@ pub fn dc_key_frame_tile_levels( ) -> Result> { check_superblocks(mi_cols, mi_rows)?; let (sb_cols, sb_rows) = (mi_cols / SB_MI, mi_rows / SB_MI); - check_levels(levels, (sb_cols * sb_rows) as usize, base_q_idx)?; + check_levels(levels, (sb_cols * sb_rows) as usize)?; + let q_ctx = q_ctx_of(base_q_idx); + let txb_skip_luma_64 = crate::cdf_state::pick( + q_ctx, + cdf::TXB_SKIP_LUMA_64_Q0, + cdf::TXB_SKIP_LUMA_64_Q1, + cdf::TXB_SKIP_LUMA_64, + cdf::TXB_SKIP_LUMA_64_Q3, + ); + let base_eob_luma_64_dc = crate::cdf_state::pick( + q_ctx, + cdf::COEFF_BASE_EOB_LUMA_64_Q0[0], + cdf::COEFF_BASE_EOB_LUMA_64_Q1[0], + cdf::COEFF_BASE_EOB_LUMA_64[0], + cdf::COEFF_BASE_EOB_LUMA_64_Q3[0], + ); + let txb_skip_chroma_32_none = crate::cdf_state::pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_32_Q0[0], + cdf::TXB_SKIP_CHROMA_32_Q1[0], + cdf::TXB_SKIP_CHROMA_32[0], + cdf::TXB_SKIP_CHROMA_32_Q3[0], + ); // The sign of the DC each coded block left behind, for the two neighbours // the sign context is read from: one row of them above, and the block to @@ -230,16 +261,17 @@ pub fn dc_key_frame_tile_levels( &mut enc, dc_level, dc_sign_ctx(dc_vote(above[c as usize]) + dc_vote(left)), - &cdf::TXB_SKIP_LUMA_64, - &cdf::COEFF_BASE_EOB_LUMA_64_DC, + q_ctx, + &txb_skip_luma_64, + &base_eob_luma_64_dc, ); // Both chroma transform blocks are all-zero. Their planes carry no // coded coefficient anywhere in the frame, so the neighbour halves // of their context stay 0 and only the offset for a transform block // that covers its whole plane block is left: context 7. - enc.symbol_fixed(1, &cdf::TXB_SKIP_CHROMA_32_NONE); - enc.symbol_fixed(1, &cdf::TXB_SKIP_CHROMA_32_NONE); + enc.symbol_fixed(1, &txb_skip_chroma_32_none); + enc.symbol_fixed(1, &txb_skip_chroma_32_none); above[c as usize] = Some(negative); left = Some(negative); @@ -269,7 +301,29 @@ pub fn split_dc_key_frame_tile( check_superblocks(mi_cols, mi_rows)?; let (sb_cols, sb_rows) = (mi_cols / SB_MI, mi_rows / SB_MI); let (cols, rows) = (sb_cols * 2, sb_rows * 2); - check_levels(levels, (cols * rows) as usize, base_q_idx)?; + check_levels(levels, (cols * rows) as usize)?; + let q_ctx = q_ctx_of(base_q_idx); + let txb_skip_luma_32 = crate::cdf_state::pick( + q_ctx, + cdf::TXB_SKIP_LUMA_32_Q0, + cdf::TXB_SKIP_LUMA_32_Q1, + cdf::TXB_SKIP_LUMA_32, + cdf::TXB_SKIP_LUMA_32_Q3, + ); + let base_eob_luma_32 = crate::cdf_state::pick( + q_ctx, + cdf::COEFF_BASE_EOB_LUMA_32_Q0[0], + cdf::COEFF_BASE_EOB_LUMA_32_Q1[0], + cdf::COEFF_BASE_EOB_LUMA_32[0], + cdf::COEFF_BASE_EOB_LUMA_32_Q3[0], + ); + let txb_skip_chroma_16_0 = crate::cdf_state::pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_16_Q0[0], + cdf::TXB_SKIP_CHROMA_16_Q1[0], + cdf::TXB_SKIP_CHROMA_16[0], + cdf::TXB_SKIP_CHROMA_16_Q3[0], + ); let mut above: Vec> = vec![None; cols as usize]; let mut left: Vec> = vec![None; rows as usize]; @@ -306,11 +360,12 @@ pub fn split_dc_key_frame_tile( &mut enc, dc_level, dc_sign_ctx(dc_vote(above[c as usize]) + dc_vote(left[r as usize])), - &cdf::TXB_SKIP_LUMA_32, - &cdf::COEFF_BASE_EOB_LUMA_32[0], + q_ctx, + &txb_skip_luma_32, + &base_eob_luma_32, ); - enc.symbol_fixed(1, &cdf::TXB_SKIP_CHROMA_16[0]); - enc.symbol_fixed(1, &cdf::TXB_SKIP_CHROMA_16[0]); + enc.symbol_fixed(1, &txb_skip_chroma_16_0); + enc.symbol_fixed(1, &txb_skip_chroma_16_0); above[c as usize] = Some(negative); left[r as usize] = Some(negative); @@ -622,8 +677,7 @@ impl Neighbours { /// that is half outside the frame is left whole, when a block names an intra /// mode a key frame does not code, when a coefficient sits outside its /// transform, repeats a position, carries a zero level or one wider than the -/// Golomb tail reaches, or when `base_q_idx` is outside the q-context band -/// whose default CDFs this crate carries. +/// Golomb tail reaches. pub fn sb_coeff_key_frame_tile( mi_cols: u32, mi_rows: u32, @@ -660,13 +714,6 @@ pub fn sb_coeff_key_frame_tile( ), )); } - if !Q_CTX_2.contains(&base_q_idx) { - return Err(Error::unsupported( - "AV1 tile", - "the coefficient CDFs of only one q context are known, so \ - base_q_idx must be 61..=120", - )); - } let sub_planes = [TxbSet::Luma16, TxbSet::Chroma8, TxbSet::Chroma8]; let split_planes = [TxbSet::Luma32, TxbSet::Chroma16, TxbSet::Chroma16]; @@ -680,7 +727,7 @@ pub fn sb_coeff_key_frame_tile( // The tile adapts every non-literal CDF it writes, exactly as the decoder // adapts the ones it reads, so the frame header leaves `disable_cdf_update` // off. - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(q_ctx_of(base_q_idx)); let mut enc = SymbolEncoder::new(); for sb_r in 0..sb_rows { neighbours.start_row(); @@ -1046,7 +1093,7 @@ pub(crate) fn coeff_bits(grid: &[i32], set: TxbSet) -> f64 { /// and the scan is the same table every time. static SCANS: LazyLock<[Vec; 3]> = LazyLock::new(|| [default_scan(TX8), default_scan(TX16), default_scan(TX32)]); - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(2); let mut coding = cdfs.txb(set, DC_PRED); let scan = match coding.side { TX8 => &SCANS[0], @@ -1066,7 +1113,7 @@ pub(crate) fn coeff_bits(grid: &[i32], set: TxbSet) -> f64 { /// than it is — because the search that reads it runs before the tile knows /// what its neighbours will be. pub(crate) fn partition_bits(side: usize, split: bool) -> f64 { - let cdfs = Cdfs::new(); + let cdfs = Cdfs::new(2); let cdf: &[u16] = match side { SB => &cdfs.partition_w64[0], BLOCK => &cdfs.partition_w32[0], @@ -1265,9 +1312,8 @@ fn neighbour(grid: &[i32], side: usize, row: usize, col: usize) -> i32 { } } -/// Shared by both DC writers: one level per block, none of them zero, and a -/// q index the coefficient CDFs are known for. -fn check_levels(levels: &[i32], blocks: usize, base_q_idx: u8) -> Result<()> { +/// Shared by both DC writers: one level per block, none of them zero. +fn check_levels(levels: &[i32], blocks: usize) -> Result<()> { if levels.len() != blocks { return Err(Error::unsupported( "AV1 tile", @@ -1281,13 +1327,6 @@ fn check_levels(levels: &[i32], blocks: usize, base_q_idx: u8) -> Result<()> { wider levels need the Golomb tail", )); } - if !Q_CTX_2.contains(&base_q_idx) { - return Err(Error::unsupported( - "AV1 tile", - "the coefficient CDFs of only one q context are known, so \ - base_q_idx must be 61..=120", - )); - } Ok(()) } @@ -1301,19 +1340,35 @@ fn write_dc_coeffs( enc: &mut SymbolEncoder, dc_level: i32, sign_ctx: usize, + q_ctx: usize, txb_skip: &[u16], base_eob: &[u16], ) { + use crate::cdf_state::pick; let level = dc_level.abs(); + let eob_pt = pick( + q_ctx, + cdf::EOB_PT_1024_LUMA_Q0, + cdf::EOB_PT_1024_LUMA_Q1, + cdf::EOB_PT_1024_LUMA, + cdf::EOB_PT_1024_LUMA_Q3, + ); + let br = pick( + q_ctx, + cdf::COEFF_BR_LUMA_32_Q0, + cdf::COEFF_BR_LUMA_32_Q1, + cdf::COEFF_BR_LUMA_32, + cdf::COEFF_BR_LUMA_32_Q3, + ); enc.symbol_fixed(0, txb_skip); - enc.symbol_fixed(0, &cdf::EOB_PT_1024_LUMA); + enc.symbol_fixed(0, &eob_pt); enc.symbol_fixed((level.min(NUM_BASE_LEVELS + 1) - 1) as usize, base_eob); if level > NUM_BASE_LEVELS { let mut remaining = level - (NUM_BASE_LEVELS + 1); let mut sent = 0; while sent < COEFF_BASE_RANGE { let k = remaining.min(BR_STEP); - enc.symbol_fixed(k as usize, &cdf::COEFF_BR_LUMA_32[0]); + enc.symbol_fixed(k as usize, &br[0]); if k < BR_STEP { break; } @@ -1369,11 +1424,7 @@ fn intra_inter_ctx(has_above: bool, has_left: bool, above_inter: bool, left_inte /// `CLASS0_SIZE << (class + 2)` (spec 3), the magnitude an `MV_CLASS_n` /// component's own bits start counting from; class zero starts at zero. fn mv_class_base(class: usize) -> i32 { - if class == 0 { - 0 - } else { - 2i32 << (class + 2) - } + if class == 0 { 0 } else { 2i32 << (class + 2) } } /// The class a pre-offset magnitude `z` (`|diff| - 1`) falls in — the inverse @@ -1486,9 +1537,7 @@ fn write_mv( /// superblocks, when `blocks` does not carry exactly one entry per 32x32 /// block, when an intra block names a mode a key frame does not code, when a /// coefficient sits outside its transform or is one the writer cannot code, -/// when a `NEWMV` block's motion vector needs eighth-pel precision, or when -/// `base_q_idx` is outside the q-context band whose default CDFs this crate -/// carries. +/// when a `NEWMV` block's motion vector needs eighth-pel precision. pub fn sb_coeff_inter_frame_tile( mi_cols: u32, mi_rows: u32, @@ -1496,13 +1545,6 @@ pub fn sb_coeff_inter_frame_tile( blocks: &[BlockCoeffs], ) -> Result> { check_superblocks(mi_cols, mi_rows)?; - if !Q_CTX_2.contains(&base_q_idx) { - return Err(Error::unsupported( - "AV1 tile", - "the coefficient CDFs of only one q context are known, so \ - base_q_idx must be 61..=120", - )); - } let (cols, rows) = (mi_cols / BLOCK_MI, mi_rows / BLOCK_MI); if blocks.len() != (cols * rows) as usize { return Err(Error::unsupported( @@ -1533,7 +1575,7 @@ pub fn sb_coeff_inter_frame_tile( let (sb_cols, sb_rows) = (mi_cols / SB_MI, mi_rows / SB_MI); let mut neighbours = Neighbours::new(cols as usize * 2, rows as usize * 2); let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize); - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(q_ctx_of(base_q_idx)); let mut enc = SymbolEncoder::new(); let split_planes = [TxbSet::Luma32, TxbSet::Chroma16, TxbSet::Chroma16]; let scan32 = default_scan(TX32); @@ -1688,8 +1730,8 @@ mod tests { use crate::sequence::sequence_header_obu; use ec_av1_syntax::sequence::SequenceHeader; use ec_av1_syntax::{ - FrameHeader, FrameType, LoopFilterParams, QuantizationParams, TileInfo, TxMode, - PRIMARY_REF_NONE, + FrameHeader, FrameType, LoopFilterParams, PRIMARY_REF_NONE, QuantizationParams, TileInfo, + TxMode, }; use std::io::Write; use std::process::{Command, Stdio}; @@ -2154,7 +2196,6 @@ mod tests { assert!(dc_key_frame_tile(16, 16, 100, 0).is_err()); assert!(dc_key_frame_tile(16, 16, 100, 15).is_err()); assert!(dc_key_frame_tile(16, 16, 100, -15).is_err()); - assert!(dc_key_frame_tile(16, 16, 40, 3).is_err()); } #[test] @@ -2390,7 +2431,7 @@ mod tests { for grid in &grids { write_coeffs( &mut enc, - &mut Cdfs::new().txb(TxbSet::Luma32, 0), + &mut Cdfs::new(2).txb(TxbSet::Luma32, 0), grid, &scan, 0, @@ -3249,10 +3290,6 @@ mod tests { "{name} must be refused" ); } - assert!( - split_coeff_key_frame_tile(16, 16, 200, &empty()).is_err(), - "a q index outside the band whose CDFs are known must be refused" - ); } /// The default scan is written as the rule that generates it rather than a @@ -3734,11 +3771,7 @@ mod tests { (d << 3) | (fr << 1) | 1 }; let mag = mv_class_base(class) + local as i32 + 1; - if sign == 1 { - -mag - } else { - mag - } + if sign == 1 { -mag } else { mag } } /// Decodes one superblock a [`sb_coeff_inter_frame_tile`] payload wrote, @@ -3764,7 +3797,7 @@ mod tests { wrong_y_mode: bool, ) -> (usize, Vec) { let mut dec = crate::msac::tests::SymbolDecoder::new(data); - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(2); let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize); let mut above_skip = [false; 2]; let mut left_skip = [false; 2]; @@ -3977,7 +4010,7 @@ mod tests { /// that kept reading past it would be asserting on garbage. fn decode_first_block_mode(data: &[u8], wrong_y_mode: bool) -> usize { let mut dec = crate::msac::tests::SymbolDecoder::new(data); - let mut cdfs = Cdfs::new(); + let mut cdfs = Cdfs::new(2); dec.symbol(&mut cdfs.partition_w64[0]); dec.symbol(&mut cdfs.partition_w32[0]); dec.symbol(&mut cdfs.skip[0]);