forge
Explore
Log in

Don't you dare go Hollow

Thread allow_screen_content_tools palette consumption into inter-frame intra sub-blocks

Browse files at this commit

ad21245c77ed172dd20a342073aa44fc4c96a9d2Ahmet Kaan GümüşParent: 384a874
  • feat
    • thread allow_screen_content_tools palette consumption into inter-frame intra sub-blocks
Show full message
feat(av1): thread allow_screen_content_tools palette consumption into inter-frame intra sub-blocks

decode_inter_block/decode_inter_block8's intra-sub-block branches (libaom's
read_intra_block_mode_info) now read the same PALETTE_Y_MODE/PALETTE_UV_MODE
symbols read_intra_mode already consumes for key frames, gated by the same
av1_allow_palette bsize check, reusing the palette_bsize_ctx(side)/0-ctx
corner-cut. Confirmed against decodemv.c: read_intra_block_mode_info has NO
use_intrabc call at all (intra-frame-only symbol, av1_read_mode_info
dispatches on frame_is_intra_only) -- narrowed charter's intrabc scope for
this path accordingly. Removed stream.rs:169's remaining
frame_type != Key && allow_screen_content_tools whole-frame refusal now that
both key and non-key intra paths consume the syntax. 231/0 lib suite
unchanged (bit clear on every existing stream -> inert).
crates/ec-av1/src/decode.rsmodified+77 -0
@@ -5796,6 +5796,15 @@ fn decode_inter_block(
5796 // for every existing (square) caller.5796 // for every existing (square) caller.
5797 write_w: usize,5797 write_w: usize,
5798 write_h: usize,5798 write_h: usize,
5799+ // lane-screen r2: this frame header's own `allow_screen_content_tools`
5800+ // bit, threaded to the intra-sub-block branch below -- libaom's
5801+ // `read_intra_block_mode_info` (decodemv.c:1065-1107, the inter-frame
5802+ // counterpart of `read_intra_frame_mode_info`) reads `y_mode_cdf`
5803+ // (never `kf_y_mode_cdf`) and has NO `use_intrabc` call at all (that
5804+ // symbol is intra-frame-only, spec `av1_read_mode_info` dispatches on
5805+ // `frame_is_intra_only`), but it still calls `read_palette_mode_info`
5806+ // under the same `av1_allow_palette` gate as the key-frame path.
5807+ allow_screen_content_tools: bool,
5799 ) -> Result<()> {5808 ) -> Result<()> {
5800 let (r, c) = at;5809 let (r, c) = at;
5801 let (px, py) = (c * SUB, r * SUB);5810 let (px, py) = (c * SUB, r * SUB);
@@ -7240,6 +7249,26 @@ fn decode_inter_block(
7240 } else {7249 } else {
7241 return Err(unsupported("a directional chroma mode (round 2)"));7250 return Err(unsupported("a directional chroma mode (round 2)"));
7242 };7251 };
7252+ // `read_palette_mode_info` (decodemv.c:567, called from
7253+ // `read_intra_block_mode_info` right after `xd->cfl.store_y`, same
7254+ // gating and same corner-cut as `read_intra_mode`'s own copy above
7255+ // -- `palette_mode_ctx`/`palette_uv_mode_ctx` hardcoded 0, provably
7256+ // safe since a nonzero neighbour `palette_size` would already have
7257+ // refused the decode that produced it.
7258+ if allow_screen_content_tools
7259+ && let Some(bsize_ctx) = palette_bsize_ctx(side)
7260+ {
7261+ if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][0]) != 0 {
7262+ return Err(unsupported(
7263+ "a block that actually uses a palette (Y) -- reconstruction is out of scope",
7264+ ));
7265+ }
7266+ if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 {
7267+ return Err(unsupported(
7268+ "a block that actually uses a palette (UV) -- reconstruction is out of scope",
7269+ ));
7270+ }
7271+ }
7243 mode_for_tx = mode;7272 mode_for_tx = mode;
7244 block_filter = [3, 3];7273 block_filter = [3, 3];
7245 ref_frame_for_lf = 0;7274 ref_frame_for_lf = 0;
@@ -7503,6 +7532,10 @@ fn decode_inter_block8(
7503 // `compound_ctx` local, just handed back instead of applied here (this7532 // `compound_ctx` local, just handed back instead of applied here (this
7504 // fn's `neighbours` recording happens once for the whole straddling7533 // fn's `neighbours` recording happens once for the whole straddling
7505 // 16x16 block, after every leaf).7534 // 16x16 block, after every leaf).
7535+ // lane-screen r2: see [`decode_inter_block`]'s own copy of this param --
7536+ // `BLOCK_8X8` (this leaf's fixed size) is always `av1_allow_palette`-
7537+ // eligible (`bsize >= BLOCK_8X8`).
7538+ allow_screen_content_tools: bool,
7506 ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>)> {7539 ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>)> {
7507 const LAST_FRAME: i8 = 1;7540 const LAST_FRAME: i8 = 1;
7508 /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).7541 /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`).
@@ -8295,6 +8328,23 @@ fn decode_inter_block8(
8295 "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)",8328 "a non-DC chroma mode on an 8x8 inter-frame leaf (this encoder never writes one)",
8296 ));8329 ));
8297 }8330 }
8331+ // lane-screen r2: see [`decode_inter_block`]'s own copy -- `mode`/
8332+ // `uv_mode` are both effectively `DC_PRED`-gated already on this
8333+ // leaf (a nonzero `mode` still passes, but `uv_mode` is forced
8334+ // `DC_PRED` by the refusal just above), same order as libaom's
8335+ // `read_palette_mode_info` call right after `xd->cfl.store_y`.
8336+ if allow_screen_content_tools {
8337+ if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[0][0]) != 0 {
8338+ return Err(unsupported(
8339+ "a block that actually uses a palette (Y) -- reconstruction is out of scope",
8340+ ));
8341+ }
8342+ if dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 {
8343+ return Err(unsupported(
8344+ "a block that actually uses a palette (UV) -- reconstruction is out of scope",
8345+ ));
8346+ }
8347+ }
8298 mode_for_tx = mode;8348 mode_for_tx = mode;
8299 let (mi_row, mi_col) = leaf_mi;8349 let (mi_row, mi_col) = leaf_mi;
8300 for dr in 0..2 {8350 for dr in 0..2 {
@@ -8489,6 +8539,7 @@ pub fn decode_inter_frame_tile(
8489 true,8539 true,
8490 false,8540 false,
8491 false,8541 false,
8542+ false,
8492 )8543 )
8493 .map(|(picture, _, _)| picture)8544 .map(|(picture, _, _)| picture)
8494 }8545 }
@@ -8552,6 +8603,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8552 // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`).8603 // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`).
8553 switchable_motion_mode: bool,8604 switchable_motion_mode: bool,
8554 allow_warped_motion: bool,8605 allow_warped_motion: bool,
8606+ // lane-screen r2: this frame header's own `allow_screen_content_tools`
8607+ // bit, threaded to every `decode_inter_block`/`decode_inter_block8`
8608+ // call below -- consumes (never reconstructs) the intra-sub-block
8609+ // palette syntax libaom's `read_intra_block_mode_info` reads under the
8610+ // same `av1_allow_palette` gate as the key-frame path.
8611+ allow_screen_content_tools: bool,
8555 ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> {8612 ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> {
8556 let tpl_frame = tpl_field.map(|field| TplFrameArgs {8613 let tpl_frame = tpl_field.map(|field| TplFrameArgs {
8557 field,8614 field,
@@ -8798,6 +8855,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8798 false,8855 false,
8799 BLOCK,8856 BLOCK,
8800 BLOCK,8857 BLOCK,
8858+ allow_screen_content_tools,
8801 )?;8859 )?;
8802 }8860 }
8803 PARTITION_SPLIT => {8861 PARTITION_SPLIT => {
@@ -8876,6 +8934,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8876 false,8934 false,
8877 SUB,8935 SUB,
8878 SUB,8936 SUB,
8937+ allow_screen_content_tools,
8879 )?;8938 )?;
8880 } else {8939 } else {
8881 let ctx16 = neighbours.partition_ctx(at16, SUB);8940 let ctx16 = neighbours.partition_ctx(at16, SUB);
@@ -8943,6 +9002,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
8943 interp_fixed,9002 interp_fixed,
8944 switchable_motion_mode,9003 switchable_motion_mode,
8945 allow_warped_motion,9004 allow_warped_motion,
9005+ allow_screen_content_tools,
8946 )?;9006 )?;
8947 prev_leaf = Some((leaf_mi, skip, is_inter));9007 prev_leaf = Some((leaf_mi, skip, is_inter));
8948 last_skip_mode = skip_mode_leaf;9008 last_skip_mode = skip_mode_leaf;
@@ -9052,6 +9112,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9052 // corner-cut rect-flake-1 exposed on HORZ).9112 // corner-cut rect-flake-1 exposed on HORZ).
9053 BLOCK,9113 BLOCK,
9054 SUB,9114 SUB,
9115+ allow_screen_content_tools,
9055 )?;9116 )?;
9056 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {9117 if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows {
9057 decode_inter_block(9118 decode_inter_block(
@@ -9104,6 +9165,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9104 false,9165 false,
9105 SUB,9166 SUB,
9106 SUB,9167 SUB,
9168+ allow_screen_content_tools,
9107 )?;9169 )?;
9108 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {9170 if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols {
9109 decode_inter_block(9171 decode_inter_block(
@@ -9156,6 +9218,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9156 false,9218 false,
9157 SUB,9219 SUB,
9158 SUB,9220 SUB,
9221+ allow_screen_content_tools,
9159 )?;9222 )?;
9160 }9223 }
9161 }9224 }
@@ -9214,6 +9277,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9214 true,9277 true,
9215 BLOCK,9278 BLOCK,
9216 SUB,9279 SUB,
9280+ allow_screen_content_tools,
9217 )?;9281 )?;
9218 decode_inter_block(9282 decode_inter_block(
9219 &mut dec,9283 &mut dec,
@@ -9261,6 +9325,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9261 true,9325 true,
9262 BLOCK,9326 BLOCK,
9263 SUB,9327 SUB,
9328+ allow_screen_content_tools,
9264 )?;9329 )?;
9265 }9330 }
9266 PARTITION_VERT => {9331 PARTITION_VERT => {
@@ -9313,6 +9378,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9313 true,9378 true,
9314 SUB,9379 SUB,
9315 BLOCK,9380 BLOCK,
9381+ allow_screen_content_tools,
9316 )?;9382 )?;
9317 decode_inter_block(9383 decode_inter_block(
9318 &mut dec,9384 &mut dec,
@@ -9360,6 +9426,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9360 true,9426 true,
9361 SUB,9427 SUB,
9362 BLOCK,9428 BLOCK,
9429+ allow_screen_content_tools,
9363 )?;9430 )?;
9364 }9431 }
9365 PARTITION_HORZ_A => {9432 PARTITION_HORZ_A => {
@@ -9417,6 +9484,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9417 false,9484 false,
9418 SUB,9485 SUB,
9419 SUB,9486 SUB,
9487+ allow_screen_content_tools,
9420 )?;9488 )?;
9421 decode_inter_block(9489 decode_inter_block(
9422 &mut dec,9490 &mut dec,
@@ -9468,6 +9536,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9468 false,9536 false,
9469 SUB,9537 SUB,
9470 SUB,9538 SUB,
9539+ allow_screen_content_tools,
9471 )?;9540 )?;
9472 decode_inter_block(9541 decode_inter_block(
9473 &mut dec,9542 &mut dec,
@@ -9515,6 +9584,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9515 true,9584 true,
9516 BLOCK,9585 BLOCK,
9517 SUB,9586 SUB,
9587+ allow_screen_content_tools,
9518 )?;9588 )?;
9519 }9589 }
9520 PARTITION_VERT_A => {9590 PARTITION_VERT_A => {
@@ -9571,6 +9641,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9571 false,9641 false,
9572 SUB,9642 SUB,
9573 SUB,9643 SUB,
9644+ allow_screen_content_tools,
9574 )?;9645 )?;
9575 decode_inter_block(9646 decode_inter_block(
9576 &mut dec,9647 &mut dec,
@@ -9622,6 +9693,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9622 false,9693 false,
9623 SUB,9694 SUB,
9624 SUB,9695 SUB,
9696+ allow_screen_content_tools,
9625 )?;9697 )?;
9626 decode_inter_block(9698 decode_inter_block(
9627 &mut dec,9699 &mut dec,
@@ -9669,6 +9741,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9669 true,9741 true,
9670 SUB,9742 SUB,
9671 BLOCK,9743 BLOCK,
9744+ allow_screen_content_tools,
9672 )?;9745 )?;
9673 }9746 }
9674 PARTITION_VERT_B => {9747 PARTITION_VERT_B => {
@@ -9722,6 +9795,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9722 true,9795 true,
9723 SUB,9796 SUB,
9724 BLOCK,9797 BLOCK,
9798+ allow_screen_content_tools,
9725 )?;9799 )?;
9726 decode_inter_block(9800 decode_inter_block(
9727 &mut dec,9801 &mut dec,
@@ -9773,6 +9847,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9773 false,9847 false,
9774 SUB,9848 SUB,
9775 SUB,9849 SUB,
9850+ allow_screen_content_tools,
9776 )?;9851 )?;
9777 decode_inter_block(9852 decode_inter_block(
9778 &mut dec,9853 &mut dec,
@@ -9824,6 +9899,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9824 false,9899 false,
9825 SUB,9900 SUB,
9826 SUB,9901 SUB,
9902+ allow_screen_content_tools,
9827 )?;9903 )?;
9828 }9904 }
9829 _ => {9905 _ => {
@@ -10601,6 +10677,7 @@ mod tests {
10601 false,10677 false,
10602 side,10678 side,
10603 side,10679 side,
10680+ false,
10604 )10681 )
10605 .unwrap();10682 .unwrap();
10606 10683
crates/ec-av1/src/stream.rsmodified+8 -11
@@ -166,17 +166,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
166 // (spec 5.11.10/5.11.11, one symbol group per superblock). Refuse166 // (spec 5.11.10/5.11.11, one symbol group per superblock). Refuse
167 // before desyncing rather than silently miscode, the same pattern as167 // before desyncing rather than silently miscode, the same pattern as
168 // the CDEF/TxMode::Select refusals above.168 // the CDEF/TxMode::Select refusals above.
169- // Key frames now consume (not reconstruct) palette/intrabc syntax169+ // lane-screen r2: key frames consume (not reconstruct) palette/
170- // via read_intra_mode, so the arithmetic decoder stays in sync;170+ // intrabc syntax via read_intra_mode, and decode_inter_block/
171- // decode_inter_block/decode_inter_block8's intra-sub-block branches171+ // decode_inter_block8's own intra-sub-block branches now consume
172- // still have no such wiring, so a non-key frame with the bit set172+ // palette the same way (libaom's read_intra_block_mode_info has no
173- // still desyncs and must refuse.173+ // intrabc call at all -- that symbol is intra-frame-only). A
174- if header.frame_type != FrameType::Key && header.allow_screen_content_tools {174+ // genuine palette/intrabc use still refuses by name deeper in the
175- return Err(Error::unsupported(175+ // block readers, so no whole-frame refusal is needed here anymore.
176- "AV1 decode_stream",
177- "a non-key frame with allow_screen_content_tools set (this decoder's inter path never reads intrabc/palette_mode_info)",
178- ));
179- }
180 if header.delta.q_present || header.delta.lf_present {176 if header.delta.q_present || header.delta.lf_present {
181 return Err(Error::unsupported(177 return Err(Error::unsupported(
182 "AV1 decode_stream",178 "AV1 decode_stream",
@@ -464,6 +460,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
464 header.reduced_tx_set,460 header.reduced_tx_set,
465 header.is_motion_mode_switchable,461 header.is_motion_mode_switchable,
466 header.allow_warped_motion,462 header.allow_warped_motion,
463+ header.allow_screen_content_tools,
467 )?464 )?
468 };465 };
469 // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's466 // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's