From 28f95f60da07242bb7cfe90b49481de5149258b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 15:53:45 +0300 Subject: [PATCH] feat(av1): palette colour-index CDF tables + 4-site wiring PALETTE_Y_COLOR_INDEX / PALETTE_UV_COLOR_INDEX (entropymode.c), indexed [n-2][color_ctx], transcribed from AOM_CDFn macros with zero-padding past each row's real n+1 entries (call site slices [..=n]). Wired into Cdfs: struct fields, per-frame counter reset (reset3, generic), defaults array. Inert until stage 3-4 reads them. --- crates/ec-av1/src/cdf.rs | 113 +++++++++++++++++++++++++++++++++ crates/ec-av1/src/cdf_state.rs | 10 +++ 2 files changed, 123 insertions(+) diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index 2d9bdbba..fe6c1f89 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -416,6 +416,119 @@ pub const PALETTE_Y_MODE: [[[u16; 3]; 3]; 7] = [ /// this block's own luma palette was used -- always 0 here, see /// [`PALETTE_Y_MODE`]'s doc). pub const PALETTE_UV_MODE: [[u16; 3]; 2] = [[32461, 32768, 0], [21488, 32768, 0]]; +/// `default_palette_y_color_index_cdf` (entropymode.c): the per-pixel colour +/// index symbol for a palette-Y block, indexed `[n-2][color_ctx]` where `n` +/// is the block's palette size (2..=8, `PALETTE_SIZES`) and `color_ctx` is +/// `av1_get_palette_color_index_context`'s 0..=4 output +/// (`PALETTE_COLOR_INDEX_CONTEXTS`). Each row is transcribed straight from +/// its `AOM_CDFn` macro (`n-1` raw probs, then `32768, 0`) and zero-padded +/// out to width 9 (the `n=8` row's real length); the call site slices +/// `[..=n]`, which only ever touches the real prefix, so the trailing zero +/// padding on shorter rows is never read. +pub const PALETTE_Y_COLOR_INDEX: [[[u16; 9]; 5]; 7] = [ + [ + [28710, 32768, 0, 0, 0, 0, 0, 0, 0], + [16384, 32768, 0, 0, 0, 0, 0, 0, 0], + [10553, 32768, 0, 0, 0, 0, 0, 0, 0], + [27036, 32768, 0, 0, 0, 0, 0, 0, 0], + [31603, 32768, 0, 0, 0, 0, 0, 0, 0], + ], + [ + [27877, 30490, 32768, 0, 0, 0, 0, 0, 0], + [11532, 25697, 32768, 0, 0, 0, 0, 0, 0], + [6544, 30234, 32768, 0, 0, 0, 0, 0, 0], + [23018, 28072, 32768, 0, 0, 0, 0, 0, 0], + [31915, 32385, 32768, 0, 0, 0, 0, 0, 0], + ], + [ + [25572, 28046, 30045, 32768, 0, 0, 0, 0, 0], + [9478, 21590, 27256, 32768, 0, 0, 0, 0, 0], + [7248, 26837, 29824, 32768, 0, 0, 0, 0, 0], + [19167, 24486, 28349, 32768, 0, 0, 0, 0, 0], + [31400, 31825, 32250, 32768, 0, 0, 0, 0, 0], + ], + [ + [24779, 26955, 28576, 30282, 32768, 0, 0, 0, 0], + [8669, 20364, 24073, 28093, 32768, 0, 0, 0, 0], + [4255, 27565, 29377, 31067, 32768, 0, 0, 0, 0], + [19864, 23674, 26716, 29530, 32768, 0, 0, 0, 0], + [31646, 31893, 32147, 32426, 32768, 0, 0, 0, 0], + ], + [ + [23132, 25407, 26970, 28435, 30073, 32768, 0, 0, 0], + [7443, 17242, 20717, 24762, 27982, 32768, 0, 0, 0], + [6300, 24862, 26944, 28784, 30671, 32768, 0, 0, 0], + [18916, 22895, 25267, 27435, 29652, 32768, 0, 0, 0], + [31270, 31550, 31808, 32059, 32353, 32768, 0, 0, 0], + ], + [ + [23105, 25199, 26464, 27684, 28931, 30318, 32768, 0, 0], + [6950, 15447, 18952, 22681, 25567, 28563, 32768, 0, 0], + [7560, 23474, 25490, 27203, 28921, 30708, 32768, 0, 0], + [18544, 22373, 24457, 26195, 28119, 30045, 32768, 0, 0], + [31198, 31451, 31670, 31882, 32123, 32391, 32768, 0, 0], + ], + [ + [21689, 23883, 25163, 26352, 27506, 28827, 30195, 32768, 0], + [6892, 15385, 17840, 21606, 24287, 26753, 29204, 32768, 0], + [5651, 23182, 25042, 26518, 27982, 29392, 30900, 32768, 0], + [19349, 22578, 24418, 25994, 27524, 29031, 30448, 32768, 0], + [31028, 31270, 31504, 31705, 31927, 32153, 32392, 32768, 0], + ], +]; +/// `default_palette_uv_color_index_cdf` (entropymode.c): as +/// [`PALETTE_Y_COLOR_INDEX`], for the chroma colour-index map. +pub const PALETTE_UV_COLOR_INDEX: [[[u16; 9]; 5]; 7] = [ + [ + [29089, 32768, 0, 0, 0, 0, 0, 0, 0], + [16384, 32768, 0, 0, 0, 0, 0, 0, 0], + [8713, 32768, 0, 0, 0, 0, 0, 0, 0], + [29257, 32768, 0, 0, 0, 0, 0, 0, 0], + [31610, 32768, 0, 0, 0, 0, 0, 0, 0], + ], + [ + [25257, 29145, 32768, 0, 0, 0, 0, 0, 0], + [12287, 27293, 32768, 0, 0, 0, 0, 0, 0], + [7033, 27960, 32768, 0, 0, 0, 0, 0, 0], + [20145, 25405, 32768, 0, 0, 0, 0, 0, 0], + [30608, 31639, 32768, 0, 0, 0, 0, 0, 0], + ], + [ + [24210, 27175, 29903, 32768, 0, 0, 0, 0, 0], + [9888, 22386, 27214, 32768, 0, 0, 0, 0, 0], + [5901, 26053, 29293, 32768, 0, 0, 0, 0, 0], + [18318, 22152, 28333, 32768, 0, 0, 0, 0, 0], + [30459, 31136, 31926, 32768, 0, 0, 0, 0, 0], + ], + [ + [22980, 25479, 27781, 29986, 32768, 0, 0, 0, 0], + [8413, 21408, 24859, 28874, 32768, 0, 0, 0, 0], + [2257, 29449, 30594, 31598, 32768, 0, 0, 0, 0], + [19189, 21202, 25915, 28620, 32768, 0, 0, 0, 0], + [31844, 32044, 32281, 32518, 32768, 0, 0, 0, 0], + ], + [ + [22217, 24567, 26637, 28683, 30548, 32768, 0, 0, 0], + [7307, 16406, 19636, 24632, 28424, 32768, 0, 0, 0], + [4441, 25064, 26879, 28942, 30919, 32768, 0, 0, 0], + [17210, 20528, 23319, 26750, 29582, 32768, 0, 0, 0], + [30674, 30953, 31396, 31735, 32207, 32768, 0, 0, 0], + ], + [ + [21239, 23168, 25044, 26962, 28705, 30506, 32768, 0, 0], + [6545, 15012, 18004, 21817, 25503, 28701, 32768, 0, 0], + [3448, 26295, 27437, 28704, 30126, 31442, 32768, 0, 0], + [15889, 18323, 21704, 24698, 26976, 29690, 32768, 0, 0], + [30988, 31204, 31479, 31734, 31983, 32325, 32768, 0, 0], + ], + [ + [21442, 23288, 24758, 26246, 27649, 28980, 30563, 32768, 0], + [5863, 14933, 17552, 20668, 23683, 26411, 29273, 32768, 0], + [3415, 25810, 26877, 27990, 29223, 30394, 31618, 32768, 0], + [17965, 20084, 22232, 23974, 26274, 28402, 30390, 32768, 0], + [31190, 31329, 31516, 31679, 31825, 32026, 32322, 32768, 0], + ], +]; /// `default_intrabc_cdf` (entropymode.c): the `use_intrabc` flag on an /// intra frame with `allow_intrabc` set. pub const INTRABC: [u16; 3] = [30531, 32768, 0]; diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index b8b0e0ca..f69b577d 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -431,6 +431,12 @@ pub(crate) struct Cdfs { pub palette_uv_mode: [[u16; 3]; 2], /// A chroma palette block's own size -- see [`cdf::PALETTE_UV_SIZE`]. pub palette_uv_size: [[u16; 8]; 7], + /// A palette-Y block's per-pixel colour-index symbol -- see + /// [`cdf::PALETTE_Y_COLOR_INDEX`]. + pub palette_y_color_index: [[[u16; 9]; 5]; 7], + /// A palette-UV block's per-pixel colour-index symbol -- see + /// [`cdf::PALETTE_UV_COLOR_INDEX`]. + pub palette_uv_color_index: [[[u16; 9]; 5]; 7], /// The `use_intrabc` flag -- see [`cdf::INTRABC`]. pub intrabc: [u16; 3], } @@ -653,6 +659,8 @@ impl Cdfs { reset2(&mut self.palette_y_size); reset2(&mut self.palette_uv_mode); reset2(&mut self.palette_uv_size); + reset3(&mut self.palette_y_color_index); + reset3(&mut self.palette_uv_color_index); reset1(&mut self.intrabc); } @@ -1113,6 +1121,8 @@ impl Cdfs { palette_y_size: cdf::PALETTE_Y_SIZE, palette_uv_mode: cdf::PALETTE_UV_MODE, palette_uv_size: cdf::PALETTE_UV_SIZE, + palette_y_color_index: cdf::PALETTE_Y_COLOR_INDEX, + palette_uv_color_index: cdf::PALETTE_UV_COLOR_INDEX, intrabc: cdf::INTRABC, } }