From d84ad0071680f6c49d31b144b69805bc70fad734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 8 Sep 2026 13:40:31 +0300 Subject: [PATCH] fix(av1): the on-screen palette clamp only applies where the frame's mi dims are known The encoder's own in-process reconstruct runs on a FrameCtx that never saw set_segmentation, so its mi dims are zero and every colour-index map read clamped to 1x1 -- 16 round-trip gates refused with a bogus reference-slot error. Its writer half is unclamped as well, so that path mirrors itself. --- crates/ec-av1/src/decode.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b6352493..897f3397 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -8835,6 +8835,17 @@ fn palette_onscreen( fctx: &crate::decode::FrameCtx, ) -> (usize, usize) { let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get()); + // corner-cut: no mi dims means this is not a real frame decode but the + // ENCODER's own in-process reconstruct (`FrameCtx::for_encoder`, where + // `set_segmentation` never runs), whose writer half + // (`tile::write_color_index_map`) is unclamped too -- the two mirror each + // other, and clamping only one of them read every map as 1x1. Ceiling: + // our encoder still writes a full map for a palette block cut by the + // frame edge, which a conformant decoder reads short. Upgrade path: clamp + // the writer, publish the mi dims on the encoder's ctx, drop this branch. + if mi_rows == 0 || mi_cols == 0 { + return (bw, bh); + } ( bw.min(mi_cols.saturating_sub(mi_c) * MI), bh.min(mi_rows.saturating_sub(mi_r) * MI),