diff --git a/crates/ec-av1/fixtures/palette_screen_leaf8_witness.obu b/crates/ec-av1/fixtures/palette_screen_leaf8_witness.obu new file mode 100644 index 0000000000000000000000000000000000000000..f2cc7a75ea6ebef9479d4fccb6891d30c592d188 GIT binary patch literal 10364 zcmXw*gI^sE!1Zr+Z@Afu%eCySmTlX%-7=QlvTnvr%eHOX=F+P5etysMynn+v=leZa z05CED0D$X$fBCov1hQA7;sD5m001%ofNYcVl2TfVn)zCU%0ivP#9~kR1n+V7!$N{P zf9zMSxZS@J*~>^GqKucqGYVwKXJo`C1ZRhE);}jkPaEXrbba)#zi?|HJ6{Pn)LF3; zfXj!wxHYQ(v`eW!@f05@3r=5$(pn_rUcdA*ypot5!P7LOkg$f~+speo%B@YP6V*P; zzsCQGrYcckb{r~{5TtkQDXaYEyGHm2SUEcdL#g^9>q3K5!#gPQHn)u#&L zb2!25yK>-*Pyt^2{uixVq=QZb4dB$+;fIg^l5&yuYJic-3~#%@$wu^LGE!+1bG*+J z?6q4LZ^jI-3qp78G}i4QdUKkqi!mWP5%X#2%(!gsKrNFQQsk$t&KEM>{DUQ)M7JkR z{xA!R=R8i_)bX{6nq?(knLxFsxseXlWNYvvmLzJPCE;-8EBEp77mCAfeNlSQM?~~8 zA>0P7oT4OMbda!%8_R`%qZXn=1WHcGqmUZ%0<1EwDgiKL)hP>hMPu+p<+;g^dKM>{ zcV>U6T_qrXd=v=rKcX1$DXRN9FKS1$563GM&o$I>{)*yd9MbMKWH|D|Cg9~VK@)sr zC_rJjw!2_nB5XVPo^840FSm5{cp1>2IHENYbvnzhps58CSSK;k;m$R+9pv!bq+s@E z1=C?n42}49zV0^_6D1pE<7oOgHp?`K9V`x<8XPTsVNswfE39tM_QC7G@Bx9WRfGPyP;>h36uCo-b6-gd!z5njtpms<^oR=rJCbi*2Par zKwg$U7b;oM46mnw_&5<RCV4U0D1LLO1@q#-Lyy*Y_JyL}31=+cQ&w>*v2&2MK-O zn=uPxS2lM-1$deA|0a|XcEcT;Z-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t6kvd zehZuU`lf7igru5HT=c;D-rsc}S*dDKIb27uGqXXXIiKMCn_GUJmETp?isGB9UhH64`cVKM9az}u zQDKVUl{tsje!=QlX?iJ = const { std::cell::Cell::new(0) }; } +// lane-t900 r23: as [`INTRA_IN_INTER_PALETTE_Y_HITS`], narrowed to the 8x8 +// LEAF site ([`decode_inter_block8`]'s intra arm) -- the >=16 site fires the +// shared counter too, so only this one proves a gate really reached the leaf +// where the refusal used to sit. +thread_local! { + static INTER8_PALETTE_HITS: std::cell::Cell<(usize, usize)> = + const { std::cell::Cell::new((0, 0)) }; +} + +/// Current values of the 8x8-leaf intra-in-inter palette counters, `(y, uv)`. +pub(crate) fn inter8_palette_hits() -> (usize, usize) { + INTER8_PALETTE_HITS.with(std::cell::Cell::get) +} + /// Current values of the two intra-in-inter palette counters, `(y, uv)`. pub(crate) fn intra_in_inter_palette_hits() -> (usize, usize) { ( @@ -5016,6 +5030,9 @@ impl Neighbours { colors: [u16; 8], ) { let (r, c) = mi; + if crate::envflags::env_flag!("EC_PALPUB") { + eprintln!("EC_PALPUB yrect mi={r},{c} bw={w} bh={h} y={size}"); + } // lane-kf900 r6: mi (4px) granularity, libaom's own -- `palette_size` // lives per mi cell in `MB_MODE_INFO`, and `xd->left_mbmi` is the mi // cell immediately left of the block, not its 16px [`SUB`] cell. The @@ -7023,6 +7040,13 @@ fn record_strip_palette( uv_colors: [u16; 8], ) { let (r, c) = mi; + // lane-t900 r23 rung: every publication of a block's palette state into + // the neighbour bands (`EC_PALPUB=1`) -- the rung that names which decode + // path left a stale `left_palette_size` behind when + // `av1_get_palette_mode_ctx` disagrees with libaom's. + if crate::envflags::env_flag!("EC_PALPUB") { + eprintln!("EC_PALPUB strip mi={r},{c} bw={bw} bh={bh} y={y_size} uv={uv_size}"); + } // lane-kf900 r6: the palette side bands are mi-granular now, so a strip // writes its OWN span on BOTH axes -- the old `last` split-axis rule only // existed because the 16px [`SUB`] cell held one slot for all the strips @@ -24628,6 +24652,15 @@ fn decode_inter_sub8_split4( (ug, vg) }; neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); + // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map + // needs EVERY writer): a sub-8x8 group published no palette state, so + // once an 8x8 leaf of the same row can BE a palette block, the group + // left the row's band holding that earlier block's size and the next + // intra block read `av1_get_palette_mode_ctx` one too high (measured: + // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers + // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` + // needs `bsize >= BLOCK_8X8`), so the group always clears. + record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); let round_up_even = |n: usize| n.div_ceil(2) * 2; let bound_h = round_up_even(neighbours.mi_rows); let bound_w = round_up_even(neighbours.mi_cols); @@ -25029,6 +25062,16 @@ fn decode_intra_sub8_leaf( neighbours.above_uv_mode[c] = uv_predict_mode; neighbours.left_uv_mode[r] = uv_predict_mode; neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode); + // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map + // needs EVERY writer): a sub-8x8 group published no palette state, so + // once an 8x8 leaf of the same row can BE a palette block, the group + // left the row's band holding that earlier block's size and the next + // intra block read `av1_get_palette_mode_ctx` one too high (measured: + // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers + // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` + // needs `bsize >= BLOCK_8X8`), so the group always clears. + record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); + let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8)); let (u_grid, v_grid): (Vec, Vec) = if skip { if alpha.is_some() { @@ -25629,6 +25672,15 @@ fn decode_inter_sub8_rect2( (ug, vg) }; neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); + // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map + // needs EVERY writer): a sub-8x8 group published no palette state, so + // once an 8x8 leaf of the same row can BE a palette block, the group + // left the row's band holding that earlier block's size and the next + // intra block read `av1_get_palette_mode_ctx` one too high (measured: + // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers + // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` + // needs `bsize >= BLOCK_8X8`), so the group always clears. + record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); let round_up_even = |n: usize| n.div_ceil(2) * 2; let bound_h = round_up_even(neighbours.mi_rows); let bound_w = round_up_even(neighbours.mi_cols); @@ -25901,6 +25953,11 @@ fn decode_inter_block8( // neighbour (`Neighbours`' arrays only move once per 16x16 block). // `(0, None)` is intra. let mut leaf_refs: (i8, Option) = (0, None); + // lane-t900 r23: this leaf's own palette state for the neighbour bands + // (`(y_size, y_colors, uv_size, uv_colors)`), all-zero for an inter leaf + // and for an intra one that codes no palette -- same publication the + // >=16 intra-in-inter block makes through [`record_strip_palette`]. + let mut palette_record8: (usize, [u16; 8], usize, [u16; 8]) = (0, [0u16; 8], 0, [0u16; 8]); if is_inter { if reference_select || skip_mode { // lane-inter8 r1: the REAL neighbour references, not a @@ -26526,6 +26583,21 @@ fn decode_inter_block8( ], ) }); + // lane-t900 r23: every leaf stamps its palette state (all-zero for an + // inter leaf or a non-palette intra one, real for a palette block) into + // the mi-granular neighbour bands, so the next intra block's + // `av1_get_palette_mode_ctx` and colour cache see exactly what libaom's + // mode-info grid holds. + record_strip_palette( + neighbours, + leaf_mi, + 8, + 8, + palette_record8.0, + palette_record8.1, + palette_record8.2, + palette_record8.3, + ); neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); if let Some((left, above)) = saved_luma_ctx { for (cell, state) in left.into_iter().enumerate() { @@ -27204,19 +27276,47 @@ fn decode_inter_block8( // leaf (a nonzero `mode` still passes, but `uv_mode` is forced // `DC_PRED` by the refusal just above), same order as libaom's // `read_palette_mode_info` call right after `xd->cfl.store_y`. - if allow_screen_content_tools { - if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[0][0]) != 0 { - return Err(unsupported( - "a block that actually uses a palette (Y) -- reconstruction is out of scope", - )); + // lane-t900 r23: reconstructed, not refused. Same syntax, same + // deferral of the colour-index maps past `use_filter_intra` + // (`av1_visit_palette` runs from `parse_decode_block`, after the whole + // mode-info read) as the >=16 intra-in-inter block's own copy in + // [`decode_inter_block`]; the mode context, the colour cache and the + // `palette_uv_mode` context are this leaf's REAL ones, not the + // hardcoded 0/empty pair the refusal could get away with while no + // neighbour could ever be a palette (class + // [[cdf-row-held-constant]]). `av1_get_palette_bsize_ctx(BLOCK_8X8)` + // = `num_pels_log2_lookup[BLOCK_8X8] - 6` = row 0. + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi(leaf_mi); + let palette_uv_cache = neighbours.palette_uv_cache_mi(leaf_mi); + let mut palette_y_pending: Option<(usize, [u16; 8])> = None; + let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; + if allow_screen_content_tools + && let Some(bsize_ctx) = palette_bsize_ctx(SIDE) + { + let use_palette_y = + mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0; + if use_palette_y { + let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); + palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache))); } // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only - // when `uv_mode == UV_DC_PRED` (decodemv.c) -- unconditional here - // while every non-DC uv_mode was refused a few lines above. - if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { - return Err(unsupported( - "a block that actually uses a palette (UV) -- reconstruction is out of scope", - )); + // when `uv_mode == UV_DC_PRED` (decodemv.c). + let use_palette_uv = uv_mode == DC_PRED + && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0; + if crate::envflags::env_flag!("EC_PALSYN") { + eprintln!( + "EC_PALSYN leaf8 mi={},{} bw=8 bh=8 mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}", + leaf_mi.0, + leaf_mi.1, + palette_y_pending.map_or(0, |(n, _)| n), + u8::from(use_palette_uv), + dec.debug_state().0 + ); + } + if use_palette_uv { + let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); + let (u_colors, v_colors) = read_palette_colors_uv(dec, n, &palette_uv_cache); + palette_uv_pending = Some((n, u_colors, v_colors)); } } // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`, @@ -27235,6 +27335,9 @@ fn decode_inter_block8( let ec_istep8 = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); if mode == DC_PRED && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) + // `av1_filter_intra_allowed` (reconintra.h:77) excludes a + // palette-Y block, so no `use_filter_intra` symbol exists there. + && palette_y_pending.is_none() && let Some(class) = filter_intra_size_class(SIDE) { let use_fi = dec.symbol(&mut cdfs.filter_intra[class]) != 0; @@ -27262,6 +27365,49 @@ fn decode_inter_block8( filter_intra = Some(fi); } } + // lane-t900 r23: `av1_visit_palette` -- the two colour-index maps, Y + // then the shared chroma one, after the WHOLE mode-info read. + let palette_y = palette_y_pending.map(|(n, colors)| { + let map = decode_color_index_map_wh(dec, cdfs, n, SIDE, SIDE, false); + PALETTE_HITS.with(|c| c.set(c.get() + 1)); + INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.set(c.get() + 1)); + INTER8_PALETTE_HITS.with(|c| { + let mut v = c.get(); + v.0 += 1; + c.set(v); + }); + PaletteY { size: n, colors, map } + }); + let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { + // `av1_get_plane_block_size(BLOCK_8X8, 1, 1)` = BLOCK_4X4. + let map = decode_color_index_map_wh(dec, cdfs, n, CHROMA_SIDE, CHROMA_SIDE, true); + PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); + INTRA_IN_INTER_PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); + INTER8_PALETTE_HITS.with(|c| { + let mut v = c.get(); + v.1 += 1; + c.set(v); + }); + PaletteUv { size: n, u_colors, v_colors, map } + }); + palette_record8 = ( + palette_y.as_ref().map_or(0, |p| p.size), + palette_y.as_ref().map_or([0u16; 8], |p| p.colors), + palette_uv.as_ref().map_or(0, |p| p.size), + palette_uv.as_ref().map_or([0u16; 8], |p| p.u_colors), + ); + // A palette block predicts from its own colour-index map, never from + // the block edge (spec 7.11.2/7.11.4) -- these ride the + // [`PALETTE_PRED`] slot into each `reconstruct`/`read_plane` call + // below, exactly as the key-frame and >=16 intra-in-inter paths do. + let palette_y_buf: Option> = + palette_y.as_ref().map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); + let palette_uv_bufs: Option<(Vec, Vec)> = palette_uv.as_ref().map(|p| { + ( + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), + ) + }); mode_for_tx = mode; let (mi_row, mi_col) = leaf_mi; for dr in 0..2 { @@ -27319,6 +27465,19 @@ fn decode_inter_block8( // position: top-right / bottom-left availability is the // block's, narrowed by the unit's offset inside it. let tu_reach = Reach::of_tu(SIDE, SIDE, col * MI, row * MI, tx_px, tx_px, reach); + // This unit's own window on the block's palette prediction + // (the whole-block buffer would be indexed at the wrong + // stride by the first unit). + if let Some(buf) = &palette_y_buf { + PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); + let window: Vec = (0..tx_px) + .flat_map(|i| { + let base = (row * MI + i) * SIDE + col * MI; + buf[base..base + tx_px].iter().copied() + }) + .collect(); + set_palette_pred(window); + } let tu_grid = if skip { y.reconstruct( tu_px, @@ -27370,6 +27529,9 @@ fn decode_inter_block8( } if skip { if !split8 { + if let Some(buf) = &palette_y_buf { + set_palette_pred(buf.clone()); + } y.reconstruct( px, py, @@ -27386,6 +27548,9 @@ fn decode_inter_block8( // CfL's AC contribution is the luma this leaf just reconstructed, // averaged over the 4x4 chroma block (`cfl_ac_q3`, spec 7.11.5). let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE)); + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone()); + } u.reconstruct( cpx, cpy, @@ -27398,6 +27563,9 @@ fn decode_inter_block8( None, smooth_neighbor_uv, ); + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone()); + } v.reconstruct( cpx, cpy, @@ -27421,6 +27589,9 @@ fn decode_inter_block8( // which the `saved_luma_ctx` restore below keeps per-TU. vec![0i32; SIDE * SIDE] } else { + if let Some(buf) = &palette_y_buf { + set_palette_pred(buf.clone()); + } read_plane( dec, cdfs, @@ -27453,6 +27624,9 @@ fn decode_inter_block8( )? }; let ac = alpha.map(|_| cfl_ac_q3(y, px, py, SIDE)); + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone()); + } u_grid = read_plane( dec, cdfs, @@ -27475,6 +27649,9 @@ fn decode_inter_block8( None, smooth_neighbor_uv, )?; + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone()); + } v_grid = read_plane( dec, cdfs, @@ -27516,6 +27693,21 @@ fn decode_inter_block8( ], ) }); + // lane-t900 r23: every leaf stamps its palette state (all-zero for an + // inter leaf or a non-palette intra one, real for a palette block) into + // the mi-granular neighbour bands, so the next intra block's + // `av1_get_palette_mode_ctx` and colour cache see exactly what libaom's + // mode-info grid holds. + record_strip_palette( + neighbours, + leaf_mi, + 8, + 8, + palette_record8.0, + palette_record8.1, + palette_record8.2, + palette_record8.3, + ); neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]); // lane-uv8 r1: this leaf never stamped a mode band at all, so the block // below/right of it read whatever block last wrote the coarse [`SUB`] diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 2b65970f..08c8c727 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -46,13 +46,14 @@ const REFUSALS: &[&str] = &[ "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", - // lane-t900 r22: palette RECONSTRUCTION landed for the key-frame paths - // (earlier lanes) and for the intra-in-inter square and rect paths (this - // one). These two strings survive at exactly two kinds of site: the - // `palette.is_none()` guards in `read_intra_mode`/`read_intra_mode_rect` - // (defensive -- every caller now passes a real ctx/cache pair), and the - // sub-8x8 `decode_inter_block8` leaf, which has no witness stream. - "a block that actually uses a palette (UV) -- reconstruction is out of scope", + // lane-t900 r23: palette RECONSTRUCTION now covers the key-frame paths + // (earlier lanes), the intra-in-inter square/rect paths (r22) and the + // 8x8 LEAF inside an inter frame (this round, gate + // `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`), + // which is why the (UV) string is gone from the decoder entirely -- the + // leaf was its only site. The (Y) one survives ONLY as the defensive + // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect`; + // every caller now passes a real ctx/cache pair, so no stream reaches it. "a block that actually uses a palette (Y) -- reconstruction is out of scope", "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", @@ -124,6 +125,22 @@ const REFUSALS: &[&str] = &[ // What still refuses is the 128-root half of a screen-content frame, whose // body (`decode_block_128rect`) reads no palette syntax and for which no // `--sb-size=128` screen witness exists yet. + // lane-t900 r23 CENSUS for this string's remaining 128-root arm (the + // 16x4/4x16 arm was lifted in r22): its premise is already known to be + // false by the spec -- `read_palette_mode_info` (5.11.46) codes palette + // only for `Block_Width <= 64 && Block_Height <= 64`, so a 128x64/64x128 + // half consumes NO palette syntax and the screen flag changes nothing + // about it. It stays because nothing witnesses it: 6 aomenc encodes at + // `--sb-size=128 --tune-content=screen` (704x320 = 5*128+64 by 2*128+64, + // the edge-forced size r18 proved for the non-screen twin; screen cell + // content at cq 10/20/40, and r18's own panning-texture-plus-fresh-ramp + // shape with `--max-partition-size=128 --enable-ab-partitions=0 + // --enable-1to4-partitions=0`) code ZERO 128-root halves of any kind + // (`intra128_in_inter` and `sb128_rect` both 0 in every stream), so + // lifting it would be a capability claim no gate exercises (class + // `refusal-lifted-without-a-gate`). What is still untried: a 10-bit + // source, and screen content in the forced bands with a NON-screen + // interior. "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", "warp prediction with a scaled reference (superres, unimplemented)", "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 6441223d..03d7cfa2 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -126,6 +126,13 @@ pub fn intra_in_inter_palette_hits() -> (usize, usize) { crate::decode::intra_in_inter_palette_hits() } +/// `(y, uv)` palette blocks reconstructed on an 8x8 LEAF inside an inter +/// frame (lane-t900 r23) -- the site-specific half of +/// [`intra_in_inter_palette_hits`], which a >=16 block also moves. +pub fn inter8_palette_hits() -> (usize, usize) { + crate::decode::inter8_palette_hits() +} + /// lane-rect64port r1: coded 64-level HORZ/VERT intra strips whose luma /// transform unit is the un-split TX_64X32 (orient 0) / TX_32X64 (orient 1). pub fn rect64_corner_tu_hits(orient: usize) -> usize { @@ -31005,6 +31012,63 @@ mod tests { } } + /// lane-t900 r23 GATE for the two LIFTED refusals `"a block that actually + /// uses a palette (Y)/(UV) -- reconstruction is out of scope"` at their + /// 8x8-LEAF site ([`crate::decode`]'s `decode_inter_block8` intra arm): + /// a palette block on an 8x8 intra leaf inside an inter frame. + /// + /// Recipe (`fixtures/palette_screen_leaf8_witness.obu`): 256x192, 15 + /// frames, a static two-level 16x16 screen background with a 96x96 patch + /// of hashed 4x4 colour cells that moves non-periodically (so no + /// reference holds it and the encoder codes it INTRA inside the inter + /// frames), `aomenc --tune-content=screen --enable-palette=1 + /// --enable-intrabc=0 --sb-size=64 --cq-level=20 --cpu-used=1 + /// --lag-in-frames=0 --kf-max-dist=9999 --max-partition-size=8` -- the + /// partition cap is what puts the palette on BLOCK_8X8 rather than on the + /// 16x16/16x8 blocks r22's recipe produced. `EC_PALSYN=1` on aomdec + /// counts 25 `bsize=BLOCK_8X8 palette_size>0` blocks past the key frame. + /// + /// What it caught beyond the refusal itself: a sub-8x8 group publishes no + /// palette state, so it left the row's `left_palette_size` band holding an + /// earlier 8x8 palette block's size and `av1_get_palette_mode_ctx` read 1 + /// where libaom gathers 0 (decode-order frame 1, mi(30,30), palette size + /// decoded as 8 instead of 2) -- class `new-map-ignores-tile-edge`, fixed + /// at all three sub-8x8 tails. + #[test] + fn a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact() { + const NAME: &str = + "a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/palette_screen_leaf8_witness.obu"); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); + let before = inter8_palette_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), + }; + let after = inter8_palette_hits(); + let (fired_y, fired_uv) = (after.0 - before.0, after.1 - before.1); + assert!( + fired_y > 0, + "{NAME}: no palette block on an 8x8 leaf inside an inter frame \ + -- the gate is vacuous for the site whose refusal it pins" + ); + assert_eq!(frames.len(), 15, "{NAME}: 15 shown frames"); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 256, 192, frames.len()); + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: frame count"); + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg"); + assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg"); + assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg"); + } + eprintln!("{NAME}: 15 frames pixel-exact; 8x8-leaf palette y={fired_y} uv={fired_uv}"); + } + /// lane-t900 r22 GATE for the LIFTED refusal `"a HORZ/VERT intra strip in /// a screen-content frame (palette syntax is consumed for square blocks /// only)"` on its 16x4/4x16 arm: that arm routes through