forge
Explore
Log in

Don't you dare go Hollow

wip(palette2): r4's rect-strip palette implementation at the cap -- compiles clean, gate not yet written (state unverified by me)

Browse files at this commit

9f6023c1535ea8c1611256c383584b8094795496Ahmet Kaan GümüşParent: ddf6af5
crates/ec-av1/src/decode.rsmodified+236 -62
@@ -1955,12 +1955,27 @@ impl Neighbours {
19551955 /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's
19561956 /// call sites are all square blocks).
19571957 fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) {
1958+ self.record_palette_y_rect(at, side, side, size, colors);
1959+ }
1960+
1961+ /// [`Self::record_palette_y`] with independent above (`w`)/left (`h`)
1962+ /// extents (lane-palette2 r4, mirrors [`Self::record_rect`] vs
1963+ /// [`Self::record`]): a true rect strip's above/left neighbour spans
1964+ /// differ.
1965+ fn record_palette_y_rect(
1966+ &mut self,
1967+ at: (usize, usize),
1968+ w: usize,
1969+ h: usize,
1970+ size: usize,
1971+ colors: [u16; 8],
1972+ ) {
19581973 let (r, c) = at;
1959- for cell in 0..side / SUB {
1974+ for cell in 0..w / SUB {
19601975 self.above_palette_size[c + cell] = size;
19611976 self.above_palette_colors[c + cell] = colors;
19621977 }
1963- for cell in 0..side / SUB {
1978+ for cell in 0..h / SUB {
19641979 self.left_palette_size[r + cell] = size;
19651980 self.left_palette_colors[r + cell] = colors;
19661981 }
@@ -2021,12 +2036,27 @@ impl Neighbours {
20212036 /// (U-channel) palette size/colours -- `size == 0` clears stale state the
20222037 /// same way (lane-palette2 r1).
20232038 fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) {
2039+ self.record_palette_uv_rect(at, side, side, size, colors);
2040+ }
2041+
2042+ /// [`Self::record_palette_uv`] with independent above (`w`)/left (`h`)
2043+ /// extents, in LUMA pixels (lane-palette2 r4, same convention as
2044+ /// [`Self::record_palette_y_rect`] -- the above/left grids are indexed at
2045+ /// luma resolution regardless of which plane the recorded state is for).
2046+ fn record_palette_uv_rect(
2047+ &mut self,
2048+ at: (usize, usize),
2049+ w: usize,
2050+ h: usize,
2051+ size: usize,
2052+ colors: [u16; 8],
2053+ ) {
20242054 let (r, c) = at;
2025- for cell in 0..side / SUB {
2055+ for cell in 0..w / SUB {
20262056 self.above_palette_uv_size[c + cell] = size;
20272057 self.above_palette_uv_colors[c + cell] = colors;
20282058 }
2029- for cell in 0..side / SUB {
2059+ for cell in 0..h / SUB {
20302060 self.left_palette_uv_size[r + cell] = size;
20312061 self.left_palette_uv_colors[r + cell] = colors;
20322062 }
@@ -2638,17 +2668,20 @@ fn palette_bsize_ctx(side: usize) -> Option<usize> {
26382668 }
26392669
26402670 /// [`palette_bsize_ctx`], generalised to a true `bw`x`bh` rect strip
2641-/// (lane-palette2 r1) -- the same `log2(bw*bh) - 6` formula, this decoder's
2642-/// square call sites are just `bw == bh`.
2671+/// (lane-palette2 r4) -- the same `log2(bw*bh) - 6` formula libaom's
2672+/// `num_pels_log2_lookup[bsize] - num_pels_log2_lookup[BLOCK_8X8]` computes
2673+/// for ANY bsize, not just the square ones a hand-picked table happened to
2674+/// enumerate before ([[cdf-row-held-constant]]: a table narrowed to a pinned
2675+/// row breaks the moment its indexing field moves off the diagonal, and a
2676+/// 64x32/32x64 superblock-level strip is exactly such a move). Every AV1
2677+/// block dimension is a power of two, so `bw*bh` always is too and
2678+/// `trailing_zeros` is `log2` exactly. `None` past `av1_allow_palette`'s own
2679+/// bound (`block_size_wide/high <= 64`, `sb_type >= BLOCK_8X8`).
26432680 fn palette_bsize_ctx_wh(bw: usize, bh: usize) -> Option<usize> {
2644- match (bw, bh) {
2645- (8, 8) => Some(0),
2646- (16, 16) => Some(2),
2647- (32, 16) | (16, 32) => Some(3),
2648- (32, 32) => Some(4),
2649- (64, 64) => Some(6),
2650- _ => None,
2681+ if !(8..=64).contains(&bw) || !(8..=64).contains(&bh) {
2682+ return None;
26512683 }
2684+ Some(((bw * bh) as u32).trailing_zeros() as usize - 6)
26522685 }
26532686
26542687 /// A just-decoded palette-Y block's own size, base colours (only the first
@@ -2898,9 +2931,25 @@ fn decode_color_index_map(
28982931 n: usize,
28992932 side: usize,
29002933 uv: bool,
2934+) -> Vec<u8> {
2935+ decode_color_index_map_wh(dec, cdfs, n, side, side, uv)
2936+}
2937+
2938+/// [`decode_color_index_map`], generalised to a true `bw`x`bh` rect strip
2939+/// (lane-palette2 r4): `decode_color_map_tokens`'s own wavefront diagonal
2940+/// (`row = i - j`, `col = j`) walked over `cols = bw`, `rows = bh`
2941+/// independently rather than one shared `side` -- the square call above is
2942+/// just `bw == bh`.
2943+fn decode_color_index_map_wh(
2944+ dec: &mut SymbolDecoder,
2945+ cdfs: &mut Cdfs,
2946+ n: usize,
2947+ bw: usize,
2948+ bh: usize,
2949+ uv: bool,
29012950 ) -> Vec<u8> {
29022951 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
2903- let mut map = vec![0u8; side * side];
2952+ let mut map = vec![0u8; bw * bh];
29042953 if trace {
29052954 let (rng, _) = dec.debug_state();
29062955 eprintln!("EC_PAL row=0 col=0 ctx=-1 n={n} rng={rng}");
@@ -2910,13 +2959,13 @@ fn decode_color_index_map(
29102959 let (rng, _) = dec.debug_state();
29112960 eprintln!("EC_PAL_VAL row=0 col=0 color_idx={} rng={rng}", map[0]);
29122961 }
2913- for i in 1..(2 * side - 1) {
2914- let j_hi = i.min(side - 1);
2915- let j_lo = i.saturating_sub(side - 1);
2962+ for i in 1..(bw + bh - 1) {
2963+ let j_hi = i.min(bw - 1);
2964+ let j_lo = i.saturating_sub(bh - 1);
29162965 for j in (j_lo..=j_hi).rev() {
29172966 let row = i - j;
29182967 let col = j;
2919- let (ctx, color_order) = palette_color_index_context(&map, side, row, col, n);
2968+ let (ctx, color_order) = palette_color_index_context(&map, bw, row, col, n);
29202969 if trace {
29212970 let (rng, _) = dec.debug_state();
29222971 eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}");
@@ -2926,7 +2975,7 @@ fn decode_color_index_map(
29262975 } else {
29272976 dec.symbol(&mut cdfs.palette_y_color_index[n - 2][ctx][..=n])
29282977 };
2929- map[row * side + col] = color_order[symbol];
2978+ map[row * bw + col] = color_order[symbol];
29302979 if trace {
29312980 let (rng, _) = dec.debug_state();
29322981 eprintln!("EC_PAL_VAL row={row} col={col} color_idx={symbol} rng={rng}");
@@ -2936,12 +2985,14 @@ fn decode_color_index_map(
29362985 map
29372986 }
29382987
2939-/// [`read_intra_mode`] for a true `bw`x`bh` rect strip (lane-intradisp r1):
2940-/// identical except the `use_filter_intra` size class comes from
2941-/// [`filter_intra_size_class_rect`] instead of the square-only
2942-/// [`filter_intra_size_class`] -- every other symbol this reads (`skip`,
2943-/// `y_mode`, `angle_delta`, `uv_mode`, `cfl_alphas`) is indexed by mode or
2944-/// neighbour state, never by block size.
2988+/// [`read_intra_mode`] for a true `bw`x`bh` rect strip (lane-intradisp r1,
2989+/// palette wired lane-palette2 r4): identical except the `use_filter_intra`
2990+/// size class comes from [`filter_intra_size_class_rect`] instead of the
2991+/// square-only [`filter_intra_size_class`], and the palette read (when
2992+/// `allow_screen_content_tools`) uses [`palette_bsize_ctx_wh`]/
2993+/// [`decode_color_index_map_wh`] instead of their square-only counterparts --
2994+/// every other symbol this reads (`skip`, `y_mode`, `angle_delta`, `uv_mode`,
2995+/// `cfl_alphas`) is indexed by mode or neighbour state, never by block size.
29452996 #[allow(clippy::too_many_arguments)]
29462997 fn read_intra_mode_rect(
29472998 dec: &mut SymbolDecoder,
@@ -2954,6 +3005,11 @@ fn read_intra_mode_rect(
29543005 enable_filter_intra: bool,
29553006 skip_ctx: usize,
29563007 allow_screen_content_tools: bool,
3008+ // As [`read_intra_mode`]'s own `palette`/`palette_uv_cache` params:
3009+ // `Some((palette_mode_ctx, color_cache))` reconstructs a real palette-Y
3010+ // block here, `None` still reads (and refuses on use) the symbol at ctx 0.
3011+ palette: Option<(usize, &[u16])>,
3012+ palette_uv_cache: &[u16],
29573013 mi_r: usize,
29583014 mi_c: usize,
29593015 ) -> Result<(
@@ -2964,17 +3020,9 @@ fn read_intra_mode_rect(
29643020 i32,
29653021 Option<(i32, i32)>,
29663022 Option<usize>,
3023+ Option<PaletteY>,
3024+ Option<PaletteUv>,
29673025 )> {
2968- // lane-screen consumes palette/intrabc syntax in the SQUARE reader only
2969- // (`palette_bsize_ctx` is keyed on a single side). A rect strip in a
2970- // screen-content frame would therefore skip symbols the encoder wrote and
2971- // desync the tile, so refuse it by name rather than decode it wrong.
2972- if allow_screen_content_tools {
2973- return Err(unsupported(
2974- "a HORZ/VERT intra strip in a screen-content frame (palette syntax \
2975- is consumed for square blocks only)",
2976- ));
2977- }
29783026 let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some();
29793027 macro_rules! istep {
29803028 ($name:literal, $val:expr) => {
@@ -3028,6 +3076,38 @@ fn read_intra_mode_rect(
30283076 0
30293077 };
30303078 istep!("angle_uv", angle_delta_uv);
3079+ // `read_palette_mode_info` (spec 5.11.13), rect-generalised
3080+ // (lane-palette2 r4): same bsize-ctx-gated read as [`read_intra_mode`],
3081+ // just keyed by [`palette_bsize_ctx_wh`] instead of the square-only
3082+ // [`palette_bsize_ctx`]. Order matches spec/libaom exactly: mode/size/
3083+ // colours only here, the colour-index maps deferred past `filter_intra`
3084+ // (see [`read_intra_mode`]'s own comment on why -- `av1_visit_palette`
3085+ // runs from the caller, after the whole mode-info read).
3086+ let mut palette_y_pending: Option<(usize, [u16; 8])> = None;
3087+ let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None;
3088+ if allow_screen_content_tools
3089+ && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh)
3090+ {
3091+ let (mode_ctx, cache) = palette.unwrap_or((0, &[]));
3092+ let use_palette_y =
3093+ mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][mode_ctx]) != 0;
3094+ if use_palette_y {
3095+ if palette.is_none() {
3096+ return Err(unsupported(
3097+ "a block that actually uses a palette (Y) -- reconstruction is out of scope",
3098+ ));
3099+ }
3100+ let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]);
3101+ let colors = read_palette_colors_y(dec, n, cache);
3102+ palette_y_pending = Some((n, colors));
3103+ }
3104+ let palette_uv_mode_ctx = usize::from(use_palette_y);
3105+ if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[palette_uv_mode_ctx]) != 0 {
3106+ let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]);
3107+ let (u_colors, v_colors) = read_palette_colors_uv(dec, n, palette_uv_cache);
3108+ palette_uv_pending = Some((n, u_colors, v_colors));
3109+ }
3110+ }
30313111 let mut filter_intra = None;
30323112 if std::env::var_os("EC_AV1_TRACE").is_some() {
30333113 let (rng, _) = dec.debug_state();
@@ -3052,6 +3132,19 @@ fn read_intra_mode_rect(
30523132 filter_intra = Some(fi_mode);
30533133 }
30543134 }
3135+ // `av1_visit_palette`: plane 0 (Y) then plane 1 (chroma, shared U/V map),
3136+ // same order as [`read_intra_mode`]'s own square path.
3137+ let palette_y = palette_y_pending.map(|(n, colors)| {
3138+ let map = decode_color_index_map_wh(dec, cdfs, n, bw, bh, false);
3139+ PALETTE_HITS.with(|c| c.set(c.get() + 1));
3140+ PALETTE_RECT_HITS.with(|c| c.set(c.get() + 1));
3141+ PaletteY { size: n, colors, map }
3142+ });
3143+ let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| {
3144+ let map = decode_color_index_map_wh(dec, cdfs, n, bw / 2, bh / 2, true);
3145+ PALETTE_UV_HITS.with(|c| c.set(c.get() + 1));
3146+ PaletteUv { size: n, u_colors, v_colors, map }
3147+ });
30553148 Ok((
30563149 skip,
30573150 mode,
@@ -3060,6 +3153,8 @@ fn read_intra_mode_rect(
30603153 angle_delta_uv,
30613154 alpha,
30623155 filter_intra,
3156+ palette_y,
3157+ palette_uv,
30633158 ))
30643159 }
30653160
@@ -3130,7 +3225,9 @@ fn decode_block_rect(
31303225 ) -> Result<()> {
31313226 let (r, c) = at;
31323227 let (px, py) = (c * SUB, r * SUB);
3133- let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) =
3228+ let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
3229+ let palette_uv_cache = neighbours.palette_uv_cache(at);
3230+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =
31343231 read_intra_mode_rect(
31353232 dec,
31363233 cdfs,
@@ -3142,6 +3239,8 @@ fn decode_block_rect(
31423239 enable_filter_intra,
31433240 neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
31443241 allow_screen_content_tools,
3242+ Some((palette_ctx, &palette_cache)),
3243+ &palette_uv_cache,
31453244 r * (SUB / MI),
31463245 c * (SUB / MI),
31473246 )?;
@@ -3208,6 +3307,19 @@ fn decode_block_rect(
32083307 skip as i32
32093308 );
32103309 }
3310+ // As [`decode_block`]'s own [`PALETTE_PRED`] wiring: a palette-Y/UV
3311+ // block's prediction is the reconstructed colour-index map, set fresh
3312+ // right before each `reconstruct_rect` call below (lane-palette2 r4).
3313+ if let Some(ref pyv) = palette_y {
3314+ let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect();
3315+ PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf));
3316+ }
3317+ let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|puv| {
3318+ (
3319+ puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(),
3320+ puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(),
3321+ )
3322+ });
32113323 if skip {
32123324 y.reconstruct_rect(
32133325 px,
@@ -3223,6 +3335,9 @@ fn decode_block_rect(
32233335 smooth_neighbor,
32243336 );
32253337 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
3338+ if let Some((ub, _)) = &palette_uv_bufs {
3339+ PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone()));
3340+ }
32263341 u.reconstruct_rect(
32273342 cpx,
32283343 cpy,
@@ -3236,6 +3351,9 @@ fn decode_block_rect(
32363351 None,
32373352 smooth_neighbor_uv,
32383353 );
3354+ if let Some((_, vb)) = &palette_uv_bufs {
3355+ PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone()));
3356+ }
32393357 v.reconstruct_rect(
32403358 cpx,
32413359 cpy,
@@ -3362,6 +3480,9 @@ fn decode_block_rect(
33623480 smooth_neighbor,
33633481 );
33643482 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
3483+ if let Some((ub, _)) = &palette_uv_bufs {
3484+ PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone()));
3485+ }
33653486 let u_default_tx = default_intra_tx_type(uv_predict_mode as u8);
33663487 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
33673488 let mut u_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode);
@@ -3402,6 +3523,9 @@ fn decode_block_rect(
34023523 None,
34033524 smooth_neighbor_uv,
34043525 );
3526+ if let Some((_, vb)) = &palette_uv_bufs {
3527+ PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone()));
3528+ }
34053529 let v_default_tx = default_intra_tx_type(uv_predict_mode as u8);
34063530 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
34073531 let mut v_coding = cdfs.txb(TxbSet::ChromaRect16x8, uv_predict_mode);
@@ -3446,6 +3570,11 @@ fn decode_block_rect(
34463570 RECT_COEFF_HITS.with(|c| c.set(c.get() + 1));
34473571 }
34483572 }
3573+ let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
3574+ neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors);
3575+ let (puv_size, puv_colors) =
3576+ palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
3577+ neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors);
34493578 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
34503579 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);
34513580 RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1));
@@ -3640,7 +3769,9 @@ fn decode_block_rect64(
36403769 ) -> Result<()> {
36413770 let (r, c) = at;
36423771 let (px, py) = (c * SUB, r * SUB);
3643- let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra) =
3772+ let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache(at);
3773+ let palette_uv_cache = neighbours.palette_uv_cache(at);
3774+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, palette_y, palette_uv) =
36443775 read_intra_mode_rect(
36453776 dec,
36463777 cdfs,
@@ -3659,9 +3790,23 @@ fn decode_block_rect64(
36593790 enable_filter_intra,
36603791 neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
36613792 allow_screen_content_tools,
3793+ Some((palette_ctx, &palette_cache)),
3794+ &palette_uv_cache,
36623795 r * (SUB / MI),
36633796 c * (SUB / MI),
36643797 )?;
3798+ if (palette_y.is_some() || palette_uv.is_some()) && !skip {
3799+ // The luma coefficient path here is the corner-cropped 32x32 real
3800+ // transform embedded in a 64x32/32x64 grid ([`decode_block_rect64`]'s
3801+ // own doc comment) -- a real (non-skip) palette block's residual
3802+ // needs the plain, uncropped rect reader [`decode_block_rect`] already
3803+ // has, not this one's truncation. `skip` (no residual at all) is
3804+ // still supported below (lane-palette2 r4).
3805+ return Err(unsupported(
3806+ "a palette block with a real transform on a superblock-level HORZ/VERT \
3807+ strip (corner-cropped luma coefficients not ported for palette)",
3808+ ));
3809+ }
36653810 let smooth_neighbor =
36663811 is_smooth_mode(neighbours.above_mode[c]) || is_smooth_mode(neighbours.left_mode[r]);
36673812 if smooth_neighbor {
@@ -3702,6 +3847,16 @@ fn decode_block_rect64(
37023847 let (cpx, cpy) = (px / 2, py / 2);
37033848 let (chroma_w, chroma_h) = (bw / 2, bh / 2);
37043849 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);
3850+ if let Some(ref pyv) = palette_y {
3851+ let buf: Vec<u16> = pyv.map.iter().map(|&idx| pyv.colors[idx as usize]).collect();
3852+ PALETTE_PRED.with(|c| *c.borrow_mut() = Some(buf));
3853+ }
3854+ let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|puv| {
3855+ (
3856+ puv.map.iter().map(|&idx| puv.u_colors[idx as usize]).collect(),
3857+ puv.map.iter().map(|&idx| puv.v_colors[idx as usize]).collect(),
3858+ )
3859+ });
37053860 if skip {
37063861 y.reconstruct_rect(
37073862 px,
@@ -3717,6 +3872,9 @@ fn decode_block_rect64(
37173872 smooth_neighbor,
37183873 );
37193874 let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh));
3875+ if let Some((ub, _)) = &palette_uv_bufs {
3876+ PALETTE_PRED.with(|c| *c.borrow_mut() = Some(ub.clone()));
3877+ }
37203878 u.reconstruct_rect(
37213879 cpx,
37223880 cpy,
@@ -3730,6 +3888,9 @@ fn decode_block_rect64(
37303888 None,
37313889 smooth_neighbor_uv,
37323890 );
3891+ if let Some((_, vb)) = &palette_uv_bufs {
3892+ PALETTE_PRED.with(|c| *c.borrow_mut() = Some(vb.clone()));
3893+ }
37333894 v.reconstruct_rect(
37343895 cpx,
37353896 cpy,
@@ -3945,6 +4106,11 @@ fn decode_block_rect64(
39454106 neighbours.record_rect(at, bw, bh, mode, uv_predict_mode, &[luma_levels, u_levels, v_levels]);
39464107 RECT_COEFF_HITS.with(|c| c.set(c.get() + 1));
39474108 }
4109+ let (py_size, py_colors) = palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
4110+ neighbours.record_palette_y_rect(at, bw, bh, py_size, py_colors);
4111+ let (puv_size, puv_colors) =
4112+ palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
4113+ neighbours.record_palette_uv_rect(at, bw, bh, puv_size, puv_colors);
39484114 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
39494115 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);
39504116 SB_RECT_HITS.with(|c| c.set(c.get() + 1));
@@ -4466,32 +4632,40 @@ impl PlaneBuf {
44664632 filter_intra: Option<usize>,
44674633 smooth_neighbor: bool,
44684634 ) {
4469- let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
4470- let mut prediction = vec![0u16; bw * bh];
4471- if let Some(fi_mode) = filter_intra {
4472- crate::intra::predict_filter_intra(
4473- fi_mode,
4474- above.as_deref(),
4475- left.as_deref(),
4476- corner,
4477- bw,
4478- &mut prediction,
4479- );
4635+ // As [`Self::reconstruct`]'s own [`PALETTE_PRED`] override
4636+ // (lane-palette2 r4): a palette block's prediction is the
4637+ // reconstructed colour-index map, needing no edge pixels at all.
4638+ let prediction = if let Some(buf) = PALETTE_PRED.with(|c| c.borrow_mut().take()) {
4639+ buf
44804640 } else {
4481- let enable_edge_filter = ENABLE_EDGE_FILTER.with(std::cell::Cell::get);
4482- predict(
4483- mode as u8,
4484- angle_delta,
4485- above.as_deref(),
4486- left.as_deref(),
4487- corner,
4488- bw,
4489- bh,
4490- enable_edge_filter,
4491- smooth_neighbor,
4492- &mut prediction,
4493- );
4494- }
4641+ let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
4642+ let mut prediction = vec![0u16; bw * bh];
4643+ if let Some(fi_mode) = filter_intra {
4644+ crate::intra::predict_filter_intra(
4645+ fi_mode,
4646+ above.as_deref(),
4647+ left.as_deref(),
4648+ corner,
4649+ bw,
4650+ &mut prediction,
4651+ );
4652+ } else {
4653+ let enable_edge_filter = ENABLE_EDGE_FILTER.with(std::cell::Cell::get);
4654+ predict(
4655+ mode as u8,
4656+ angle_delta,
4657+ above.as_deref(),
4658+ left.as_deref(),
4659+ corner,
4660+ bw,
4661+ bh,
4662+ enable_edge_filter,
4663+ smooth_neighbor,
4664+ &mut prediction,
4665+ );
4666+ }
4667+ prediction
4668+ };
44954669 for row in 0..bh {
44964670 for col in 0..bw {
44974671 let idx = row * bw + col;
crates/ec-av1/src/refusal_inventory.rsmodified+1 -1
@@ -48,8 +48,8 @@ const REFUSALS: &[&str] = &[
4848 "a tx_type symbol outside its CDF's own set: {t}",
4949 "an INTER 32x32 partition type this decoder does not code (value={part32})",
5050 "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)",
51- "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",
5251 "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)",
52+ "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",
5353 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
5454 "a block that actually uses a palette (Y) -- reconstruction is out of scope",
5555 "a block that actually uses intrabc (this decoder never reconstructs one)",