Reconstruct palette blocks on 8x8 leaves inside inter frames
Browse files at this commitcdef95e4dce15d5998da5f97c1dbf8cdedc94a2dParent: 4b093b1- feat
- reconstruct palette blocks on 8x8 leaves inside inter frames
4 changed files +93 -7
- crates/ec-av1/fixtures/palette_screen_leaf8_witness.obu +0 -0
- crates/ec-av1/src/decode.rs +28 -0
- crates/ec-av1/src/refusal_inventory.rs +8 -7
- crates/ec-av1/src/stream.rs +57 -0
crates/ec-av1/fixtures/palette_screen_leaf8_witness.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+28 -0
| @@ -24652,6 +24652,15 @@ fn decode_inter_sub8_split4( | ||
| 24652 | 24652 | (ug, vg) |
| 24653 | 24653 | }; |
| 24654 | 24654 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); |
| 24655 | + // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map | |
| 24656 | + // needs EVERY writer): a sub-8x8 group published no palette state, so | |
| 24657 | + // once an 8x8 leaf of the same row can BE a palette block, the group | |
| 24658 | + // left the row's band holding that earlier block's size and the next | |
| 24659 | + // intra block read `av1_get_palette_mode_ctx` one too high (measured: | |
| 24660 | + // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers | |
| 24661 | + // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` | |
| 24662 | + // needs `bsize >= BLOCK_8X8`), so the group always clears. | |
| 24663 | + record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); | |
| 24655 | 24664 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 24656 | 24665 | let bound_h = round_up_even(neighbours.mi_rows); |
| 24657 | 24666 | let bound_w = round_up_even(neighbours.mi_cols); |
| @@ -25053,6 +25062,16 @@ fn decode_intra_sub8_leaf( | ||
| 25053 | 25062 | neighbours.above_uv_mode[c] = uv_predict_mode; |
| 25054 | 25063 | neighbours.left_uv_mode[r] = uv_predict_mode; |
| 25055 | 25064 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, uv_predict_mode); |
| 25065 | + // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map | |
| 25066 | + // needs EVERY writer): a sub-8x8 group published no palette state, so | |
| 25067 | + // once an 8x8 leaf of the same row can BE a palette block, the group | |
| 25068 | + // left the row's band holding that earlier block's size and the next | |
| 25069 | + // intra block read `av1_get_palette_mode_ctx` one too high (measured: | |
| 25070 | + // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers | |
| 25071 | + // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` | |
| 25072 | + // needs `bsize >= BLOCK_8X8`), so the group always clears. | |
| 25073 | + record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); | |
| 25074 | + | |
| 25056 | 25075 | let ac = alpha.map(|_| cfl_ac_q3(y, gpx, gpy, 8)); |
| 25057 | 25076 | let (u_grid, v_grid): (Vec<i32>, Vec<i32>) = if skip { |
| 25058 | 25077 | if alpha.is_some() { |
| @@ -25653,6 +25672,15 @@ fn decode_inter_sub8_rect2( | ||
| 25653 | 25672 | (ug, vg) |
| 25654 | 25673 | }; |
| 25655 | 25674 | neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); |
| 25675 | + // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map | |
| 25676 | + // needs EVERY writer): a sub-8x8 group published no palette state, so | |
| 25677 | + // once an 8x8 leaf of the same row can BE a palette block, the group | |
| 25678 | + // left the row's band holding that earlier block's size and the next | |
| 25679 | + // intra block read `av1_get_palette_mode_ctx` one too high (measured: | |
| 25680 | + // mi(30,30) of decode-order frame 1, ours ctx 1 where libaom gathers | |
| 25681 | + // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` | |
| 25682 | + // needs `bsize >= BLOCK_8X8`), so the group always clears. | |
| 25683 | + record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); | |
| 25656 | 25684 | let round_up_even = |n: usize| n.div_ceil(2) * 2; |
| 25657 | 25685 | let bound_h = round_up_even(neighbours.mi_rows); |
| 25658 | 25686 | let bound_w = round_up_even(neighbours.mi_cols); |
crates/ec-av1/src/refusal_inventory.rsmodified+8 -7
| @@ -46,13 +46,14 @@ const REFUSALS: &[&str] = &[ | ||
| 46 | 46 | "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)", |
| 47 | 47 | "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)", |
| 48 | 48 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", |
| 49 | - // lane-t900 r22: palette RECONSTRUCTION landed for the key-frame paths | |
| 50 | - // (earlier lanes) and for the intra-in-inter square and rect paths (this | |
| 51 | - // one). These two strings survive at exactly two kinds of site: the | |
| 52 | - // `palette.is_none()` guards in `read_intra_mode`/`read_intra_mode_rect` | |
| 53 | - // (defensive -- every caller now passes a real ctx/cache pair), and the | |
| 54 | - // sub-8x8 `decode_inter_block8` leaf, which has no witness stream. | |
| 55 | - "a block that actually uses a palette (UV) -- reconstruction is out of scope", | |
| 49 | + // lane-t900 r23: palette RECONSTRUCTION now covers the key-frame paths | |
| 50 | + // (earlier lanes), the intra-in-inter square/rect paths (r22) and the | |
| 51 | + // 8x8 LEAF inside an inter frame (this round, gate | |
| 52 | + // `a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact`), | |
| 53 | + // which is why the (UV) string is gone from the decoder entirely -- the | |
| 54 | + // leaf was its only site. The (Y) one survives ONLY as the defensive | |
| 55 | + // `palette.is_none()` guard in `read_intra_mode`/`read_intra_mode_rect`; | |
| 56 | + // every caller now passes a real ctx/cache pair, so no stream reaches it. | |
| 56 | 57 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 57 | 58 | "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", |
| 58 | 59 | "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", |
crates/ec-av1/src/stream.rsmodified+57 -0
| @@ -31012,6 +31012,63 @@ mod tests { | ||
| 31012 | 31012 | } |
| 31013 | 31013 | } |
| 31014 | 31014 | |
| 31015 | + /// lane-t900 r23 GATE for the two LIFTED refusals `"a block that actually | |
| 31016 | + /// uses a palette (Y)/(UV) -- reconstruction is out of scope"` at their | |
| 31017 | + /// 8x8-LEAF site ([`crate::decode`]'s `decode_inter_block8` intra arm): | |
| 31018 | + /// a palette block on an 8x8 intra leaf inside an inter frame. | |
| 31019 | + /// | |
| 31020 | + /// Recipe (`fixtures/palette_screen_leaf8_witness.obu`): 256x192, 15 | |
| 31021 | + /// frames, a static two-level 16x16 screen background with a 96x96 patch | |
| 31022 | + /// of hashed 4x4 colour cells that moves non-periodically (so no | |
| 31023 | + /// reference holds it and the encoder codes it INTRA inside the inter | |
| 31024 | + /// frames), `aomenc --tune-content=screen --enable-palette=1 | |
| 31025 | + /// --enable-intrabc=0 --sb-size=64 --cq-level=20 --cpu-used=1 | |
| 31026 | + /// --lag-in-frames=0 --kf-max-dist=9999 --max-partition-size=8` -- the | |
| 31027 | + /// partition cap is what puts the palette on BLOCK_8X8 rather than on the | |
| 31028 | + /// 16x16/16x8 blocks r22's recipe produced. `EC_PALSYN=1` on aomdec | |
| 31029 | + /// counts 25 `bsize=BLOCK_8X8 palette_size>0` blocks past the key frame. | |
| 31030 | + /// | |
| 31031 | + /// What it caught beyond the refusal itself: a sub-8x8 group publishes no | |
| 31032 | + /// palette state, so it left the row's `left_palette_size` band holding an | |
| 31033 | + /// earlier 8x8 palette block's size and `av1_get_palette_mode_ctx` read 1 | |
| 31034 | + /// where libaom gathers 0 (decode-order frame 1, mi(30,30), palette size | |
| 31035 | + /// decoded as 8 instead of 2) -- class `new-map-ignores-tile-edge`, fixed | |
| 31036 | + /// at all three sub-8x8 tails. | |
| 31037 | + #[test] | |
| 31038 | + fn a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact() { | |
| 31039 | + const NAME: &str = | |
| 31040 | + "a_screen_stream_with_palette_8x8_leaves_in_inter_frames_decodes_pixel_exact"; | |
| 31041 | + if !have_ffmpeg() { | |
| 31042 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 31043 | + return; | |
| 31044 | + } | |
| 31045 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | |
| 31046 | + .join("fixtures/palette_screen_leaf8_witness.obu"); | |
| 31047 | + let stream = std::fs::read(&path) | |
| 31048 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | |
| 31049 | + let before = inter8_palette_hits(); | |
| 31050 | + let frames = match decode_stream(&stream) { | |
| 31051 | + Ok(frames) => frames, | |
| 31052 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | |
| 31053 | + }; | |
| 31054 | + let after = inter8_palette_hits(); | |
| 31055 | + let (fired_y, fired_uv) = (after.0 - before.0, after.1 - before.1); | |
| 31056 | + assert!( | |
| 31057 | + fired_y > 0, | |
| 31058 | + "{NAME}: no palette block on an 8x8 leaf inside an inter frame \ | |
| 31059 | + -- the gate is vacuous for the site whose refusal it pins" | |
| 31060 | + ); | |
| 31061 | + assert_eq!(frames.len(), 15, "{NAME}: 15 shown frames"); | |
| 31062 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 256, 192, frames.len()); | |
| 31063 | + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: frame count"); | |
| 31064 | + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 31065 | + assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg"); | |
| 31066 | + assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg"); | |
| 31067 | + assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg"); | |
| 31068 | + } | |
| 31069 | + eprintln!("{NAME}: 15 frames pixel-exact; 8x8-leaf palette y={fired_y} uv={fired_uv}"); | |
| 31070 | + } | |
| 31071 | + | |
| 31015 | 31072 | /// lane-t900 r22 GATE for the LIFTED refusal `"a HORZ/VERT intra strip in |
| 31016 | 31073 | /// a screen-content frame (palette syntax is consumed for square blocks |
| 31017 | 31074 | /// only)"` on its 16x4/4x16 arm: that arm routes through |