Thread allow_screen_content_tools palette consumption into inter-frame intra sub-blocks
Browse files at this commitad21245c77ed172dd20a342073aa44fc4c96a9d2Parent: 384a874- feat
- thread allow_screen_content_tools palette consumption into inter-frame intra sub-blocks
2 changed files +85 -11
- crates/ec-av1/src/decode.rs +77 -0
- crates/ec-av1/src/stream.rs +8 -11
crates/ec-av1/src/decode.rsmodified+77 -0
| @@ -5796,6 +5796,15 @@ fn decode_inter_block( | ||
| 5796 | 5796 | // for every existing (square) caller. |
| 5797 | 5797 | write_w: usize, |
| 5798 | 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 | 5808 | ) -> Result<()> { |
| 5800 | 5809 | let (r, c) = at; |
| 5801 | 5810 | let (px, py) = (c * SUB, r * SUB); |
| @@ -7240,6 +7249,26 @@ fn decode_inter_block( | ||
| 7240 | 7249 | } else { |
| 7241 | 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 | 7272 | mode_for_tx = mode; |
| 7244 | 7273 | block_filter = [3, 3]; |
| 7245 | 7274 | ref_frame_for_lf = 0; |
| @@ -7503,6 +7532,10 @@ fn decode_inter_block8( | ||
| 7503 | 7532 | // `compound_ctx` local, just handed back instead of applied here (this |
| 7504 | 7533 | // fn's `neighbours` recording happens once for the whole straddling |
| 7505 | 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 | 7539 | ) -> Result<(bool, bool, bool, Option<(i8, i8, u8, u8)>)> { |
| 7507 | 7540 | const LAST_FRAME: i8 = 1; |
| 7508 | 7541 | /// `Y_MODE`'s size group (`common_data.h`'s `size_group_lookup[BLOCK_8X8]`). |
| @@ -8295,6 +8328,23 @@ fn decode_inter_block8( | ||
| 8295 | 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 | 8348 | mode_for_tx = mode; |
| 8299 | 8349 | let (mi_row, mi_col) = leaf_mi; |
| 8300 | 8350 | for dr in 0..2 { |
| @@ -8489,6 +8539,7 @@ pub fn decode_inter_frame_tile( | ||
| 8489 | 8539 | true, |
| 8490 | 8540 | false, |
| 8491 | 8541 | false, |
| 8542 | + false, | |
| 8492 | 8543 | ) |
| 8493 | 8544 | .map(|(picture, _, _)| picture) |
| 8494 | 8545 | } |
| @@ -8552,6 +8603,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 8552 | 8603 | // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`). |
| 8553 | 8604 | switchable_motion_mode: bool, |
| 8554 | 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 | 8612 | ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> { |
| 8556 | 8613 | let tpl_frame = tpl_field.map(|field| TplFrameArgs { |
| 8557 | 8614 | field, |
| @@ -8798,6 +8855,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 8798 | 8855 | false, |
| 8799 | 8856 | BLOCK, |
| 8800 | 8857 | BLOCK, |
| 8858 | + allow_screen_content_tools, | |
| 8801 | 8859 | )?; |
| 8802 | 8860 | } |
| 8803 | 8861 | PARTITION_SPLIT => { |
| @@ -8876,6 +8934,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 8876 | 8934 | false, |
| 8877 | 8935 | SUB, |
| 8878 | 8936 | SUB, |
| 8937 | + allow_screen_content_tools, | |
| 8879 | 8938 | )?; |
| 8880 | 8939 | } else { |
| 8881 | 8940 | let ctx16 = neighbours.partition_ctx(at16, SUB); |
| @@ -8943,6 +9002,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 8943 | 9002 | interp_fixed, |
| 8944 | 9003 | switchable_motion_mode, |
| 8945 | 9004 | allow_warped_motion, |
| 9005 | + allow_screen_content_tools, | |
| 8946 | 9006 | )?; |
| 8947 | 9007 | prev_leaf = Some((leaf_mi, skip, is_inter)); |
| 8948 | 9008 | last_skip_mode = skip_mode_leaf; |
| @@ -9052,6 +9112,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9052 | 9112 | // corner-cut rect-flake-1 exposed on HORZ). |
| 9053 | 9113 | BLOCK, |
| 9054 | 9114 | SUB, |
| 9115 | + allow_screen_content_tools, | |
| 9055 | 9116 | )?; |
| 9056 | 9117 | if (r32 * 2 + 1) as u32 * SUB_MI < mi_rows { |
| 9057 | 9118 | decode_inter_block( |
| @@ -9104,6 +9165,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9104 | 9165 | false, |
| 9105 | 9166 | SUB, |
| 9106 | 9167 | SUB, |
| 9168 | + allow_screen_content_tools, | |
| 9107 | 9169 | )?; |
| 9108 | 9170 | if (c32 * 2 + 1) as u32 * SUB_MI < mi_cols { |
| 9109 | 9171 | decode_inter_block( |
| @@ -9156,6 +9218,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9156 | 9218 | false, |
| 9157 | 9219 | SUB, |
| 9158 | 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 | 9277 | true, |
| 9215 | 9278 | BLOCK, |
| 9216 | 9279 | SUB, |
| 9280 | + allow_screen_content_tools, | |
| 9217 | 9281 | )?; |
| 9218 | 9282 | decode_inter_block( |
| 9219 | 9283 | &mut dec, |
| @@ -9261,6 +9325,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9261 | 9325 | true, |
| 9262 | 9326 | BLOCK, |
| 9263 | 9327 | SUB, |
| 9328 | + allow_screen_content_tools, | |
| 9264 | 9329 | )?; |
| 9265 | 9330 | } |
| 9266 | 9331 | PARTITION_VERT => { |
| @@ -9313,6 +9378,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9313 | 9378 | true, |
| 9314 | 9379 | SUB, |
| 9315 | 9380 | BLOCK, |
| 9381 | + allow_screen_content_tools, | |
| 9316 | 9382 | )?; |
| 9317 | 9383 | decode_inter_block( |
| 9318 | 9384 | &mut dec, |
| @@ -9360,6 +9426,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9360 | 9426 | true, |
| 9361 | 9427 | SUB, |
| 9362 | 9428 | BLOCK, |
| 9429 | + allow_screen_content_tools, | |
| 9363 | 9430 | )?; |
| 9364 | 9431 | } |
| 9365 | 9432 | PARTITION_HORZ_A => { |
| @@ -9417,6 +9484,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9417 | 9484 | false, |
| 9418 | 9485 | SUB, |
| 9419 | 9486 | SUB, |
| 9487 | + allow_screen_content_tools, | |
| 9420 | 9488 | )?; |
| 9421 | 9489 | decode_inter_block( |
| 9422 | 9490 | &mut dec, |
| @@ -9468,6 +9536,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9468 | 9536 | false, |
| 9469 | 9537 | SUB, |
| 9470 | 9538 | SUB, |
| 9539 | + allow_screen_content_tools, | |
| 9471 | 9540 | )?; |
| 9472 | 9541 | decode_inter_block( |
| 9473 | 9542 | &mut dec, |
| @@ -9515,6 +9584,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9515 | 9584 | true, |
| 9516 | 9585 | BLOCK, |
| 9517 | 9586 | SUB, |
| 9587 | + allow_screen_content_tools, | |
| 9518 | 9588 | )?; |
| 9519 | 9589 | } |
| 9520 | 9590 | PARTITION_VERT_A => { |
| @@ -9571,6 +9641,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9571 | 9641 | false, |
| 9572 | 9642 | SUB, |
| 9573 | 9643 | SUB, |
| 9644 | + allow_screen_content_tools, | |
| 9574 | 9645 | )?; |
| 9575 | 9646 | decode_inter_block( |
| 9576 | 9647 | &mut dec, |
| @@ -9622,6 +9693,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9622 | 9693 | false, |
| 9623 | 9694 | SUB, |
| 9624 | 9695 | SUB, |
| 9696 | + allow_screen_content_tools, | |
| 9625 | 9697 | )?; |
| 9626 | 9698 | decode_inter_block( |
| 9627 | 9699 | &mut dec, |
| @@ -9669,6 +9741,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9669 | 9741 | true, |
| 9670 | 9742 | SUB, |
| 9671 | 9743 | BLOCK, |
| 9744 | + allow_screen_content_tools, | |
| 9672 | 9745 | )?; |
| 9673 | 9746 | } |
| 9674 | 9747 | PARTITION_VERT_B => { |
| @@ -9722,6 +9795,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9722 | 9795 | true, |
| 9723 | 9796 | SUB, |
| 9724 | 9797 | BLOCK, |
| 9798 | + allow_screen_content_tools, | |
| 9725 | 9799 | )?; |
| 9726 | 9800 | decode_inter_block( |
| 9727 | 9801 | &mut dec, |
| @@ -9773,6 +9847,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9773 | 9847 | false, |
| 9774 | 9848 | SUB, |
| 9775 | 9849 | SUB, |
| 9850 | + allow_screen_content_tools, | |
| 9776 | 9851 | )?; |
| 9777 | 9852 | decode_inter_block( |
| 9778 | 9853 | &mut dec, |
| @@ -9824,6 +9899,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | ||
| 9824 | 9899 | false, |
| 9825 | 9900 | SUB, |
| 9826 | 9901 | SUB, |
| 9902 | + allow_screen_content_tools, | |
| 9827 | 9903 | )?; |
| 9828 | 9904 | } |
| 9829 | 9905 | _ => { |
| @@ -10601,6 +10677,7 @@ mod tests { | ||
| 10601 | 10677 | false, |
| 10602 | 10678 | side, |
| 10603 | 10679 | side, |
| 10680 | + false, | |
| 10604 | 10681 | ) |
| 10605 | 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 | 166 | // (spec 5.11.10/5.11.11, one symbol group per superblock). Refuse |
| 167 | 167 | // before desyncing rather than silently miscode, the same pattern as |
| 168 | 168 | // the CDEF/TxMode::Select refusals above. |
| 169 | - // Key frames now consume (not reconstruct) palette/intrabc syntax | |
| 170 | - // via read_intra_mode, so the arithmetic decoder stays in sync; | |
| 171 | - // decode_inter_block/decode_inter_block8's intra-sub-block branches | |
| 172 | - // still have no such wiring, so a non-key frame with the bit set | |
| 173 | - // still desyncs and must refuse. | |
| 174 | - if header.frame_type != FrameType::Key && header.allow_screen_content_tools { | |
| 175 | - return Err(Error::unsupported( | |
| 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 | - } | |
| 169 | + // lane-screen r2: key frames consume (not reconstruct) palette/ | |
| 170 | + // intrabc syntax via read_intra_mode, and decode_inter_block/ | |
| 171 | + // decode_inter_block8's own intra-sub-block branches now consume | |
| 172 | + // palette the same way (libaom's read_intra_block_mode_info has no | |
| 173 | + // intrabc call at all -- that symbol is intra-frame-only). A | |
| 174 | + // genuine palette/intrabc use still refuses by name deeper in the | |
| 175 | + // block readers, so no whole-frame refusal is needed here anymore. | |
| 180 | 176 | if header.delta.q_present || header.delta.lf_present { |
| 181 | 177 | return Err(Error::unsupported( |
| 182 | 178 | "AV1 decode_stream", |
| @@ -464,6 +460,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> { | ||
| 464 | 460 | header.reduced_tx_set, |
| 465 | 461 | header.is_motion_mode_switchable, |
| 466 | 462 | header.allow_warped_motion, |
| 463 | + header.allow_screen_content_tools, | |
| 467 | 464 | )? |
| 468 | 465 | }; |
| 469 | 466 | // Spec 7.20: `disable_frame_end_update_cdf` stores the frame's |