From 03d0151c7932d0c4baaf3ee080e0cad7e1beef41 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 18:30:05 +0300 Subject: [PATCH] fix(av1): compile the r1 UV-palette WIP + gate it against a real aomenc stream read_intra_mode's 8x8-leaf call site was still on the pre-UV 8-arg tuple/ 13-arg signature after r1's mid-edit commit -- fixed by threading the same None-palette-uv/&[] corner-cut that call site already used for palette_y. Everything else r1 wrote (read_palette_colors_uv, PaletteUv reconstruction into both chroma planes, record_palette_uv neighbour tracking) was already correct once it compiled. Added a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact: testsrc2 at the same square-only recipe as the palette-Y gate, hard-asserting palette_uv_hits moved before checking pixel-exactness against ffmpeg (2 UV palette blocks fire; both frames match luma/U/V exactly). refusal_inventory.rs needed no edit -- "a block that actually uses a palette (UV)" is still genuinely present at two other call sites (the HORZ/VERT rect-strip and inter-frame 8x8-leaf paths), which stay refused and are out of this round's scope (steps 2/3). --- crates/ec-av1/src/decode.rs | 3 +- crates/ec-av1/src/stream.rs | 118 ++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 1 deletion(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index e574b7be..d85fadde 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4391,7 +4391,7 @@ fn decode_leaf8( // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other // `decode_block` caller at 16x16 and up. - let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y) = + let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y, _palette_uv) = read_intra_mode( dec, cdfs, @@ -4404,6 +4404,7 @@ fn decode_leaf8( allow_screen_content_tools, allow_intrabc, None, + &[], leaf_mi.0, leaf_mi.1, )?; diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index a2276602..e5c6229c 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -1707,6 +1707,124 @@ mod tests { assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg"); } + /// A real `aomenc` palette-**UV** fixture (lane-palette2 r2): `testsrc2` + /// (the multicoloured AV1 test pattern -- flat, few-colour, repetitive + /// per-region colour *and* chroma, unlike `smptebars=hue=s=0` above, + /// which flattened chroma to a single value specifically to avoid + /// exercising this path). Same square-only recipe as the palette-Y gate + /// (`--enable-rect-partitions=0`/`-ab-`/`-1to4-`, fixed 32x32 partition) + /// so a UV palette block never lands inside the still-refused HORZ/VERT + /// screen-content strip. HARD-asserts [`decode::palette_uv_hits`] moved + /// -- a stream that never reads a real UV palette block would decode (or + /// not) by construction without proving this milestone at all + /// ([[gate-blind-to-feature]]). + #[test] + fn a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let source = "testsrc2=size=64x64:rate=25"; + fn render(source: &str) -> Vec { + Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + source, + "-pix_fmt", + "yuv420p", + "-t", + "0.16", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run") + .stdout + } + let y4m_a = render(source); + let y4m_b = render(source); + assert_eq!( + y4m_a, y4m_b, + "testsrc2 must render byte-identical across two runs" + ); + let y4m = y4m_a; + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=30", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--tune-content=screen", + "--enable-palette=1", + "--enable-intrabc=0", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=32", + "--max-partition-size=32", + "--enable-filter-intra=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-tx-size-search=0", + "--loopfilter-control=0", + "--obu", + "-o", + "-", + "-", + ]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = decode::palette_uv_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), + }; + assert!( + decode::palette_uv_hits() > before, + "palette_uv_mode never fired decoding this stream -- gate is vacuous" + ); + let frame_count = frames.len(); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, frame_count); + for i in 0..frame_count { + assert_eq!(frames[i].y, ffmpeg_frames[i].y, "luma vs ffmpeg, frame {i}"); + assert_eq!(frames[i].u, ffmpeg_frames[i].u, "U vs ffmpeg, frame {i}"); + assert_eq!(frames[i].v, ffmpeg_frames[i].v, "V vs ffmpeg, frame {i}"); + } + } + /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s /// harness, but with the deblocking filter left *on* (no /// `--loopfilter-control=0`) at a crf high enough that libaom actually