Merge branch 'lane-t900' (78e0079b): palette reconstruction inside inter frames (square intra-in-inter + rect strips), variable-alphabet CDF counter reset; screen witnesses gated byte-exact at 8 and 10 bit
Browse files at this commit8 changed files +374 -35
- crates/ec-av1/examples/decode_probe.rs +2 -0
- crates/ec-av1/fixtures/palette_screen_strip16_witness_10bit.obu +0 -0
- crates/ec-av1/fixtures/palette_screen_witness.obu +0 -0
- crates/ec-av1/fixtures/palette_screen_witness_10bit.obu +0 -0
- crates/ec-av1/src/cdf_state.rs +25 -2
- crates/ec-av1/src/decode.rs +210 -30
- crates/ec-av1/src/refusal_inventory.rs +13 -3
- crates/ec-av1/src/stream.rs +124 -0
crates/ec-av1/examples/decode_probe.rsmodified+2 -0
| @@ -34,6 +34,8 @@ fn main() { | |||
| 34 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); | 34 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 35 | println!("rect4_32: horz={h} vert={v} coded={c}"); | 35 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 36 | println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads()); | 36 | println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads()); |
| 37 | + let (pal_y, pal_uv) = ec_av1::stream::intra_in_inter_palette_hits(); | ||
| 38 | + println!("intra_in_inter_palette: y={pal_y} uv={pal_uv}"); | ||
| 37 | println!( | 39 | println!( |
| 38 | "rect64_corner_tu: 64x32={} 32x64={}", | 40 | "rect64_corner_tu: 64x32={} 32x64={}", |
| 39 | ec_av1::stream::rect64_corner_tu_hits(0), | 41 | ec_av1::stream::rect64_corner_tu_hits(0), |
crates/ec-av1/fixtures/palette_screen_strip16_witness_10bit.obuadded+0 -0
Binary file changed
crates/ec-av1/fixtures/palette_screen_witness.obuadded+0 -0
Binary file changed
crates/ec-av1/fixtures/palette_screen_witness_10bit.obuadded+0 -0
Binary file changed
crates/ec-av1/src/cdf_state.rsmodified+25 -2
| @@ -759,6 +759,19 @@ fn reset3<const N: usize, const M: usize, const K: usize>(a: &mut [[[u16; N]; M] | |||
| 759 | a.iter_mut().for_each(reset2); | 759 | a.iter_mut().for_each(reset2); |
| 760 | } | 760 | } |
| 761 | 761 | ||
| 762 | +/// [`reset3`] for a table whose ALPHABET grows with its first index: the | ||
| 763 | +/// palette colour-index CDFs are `[u16; 9]` rows read as `[..=n]` with | ||
| 764 | +/// `n = idx + 2`, so their symbol counter sits at index `n`, not `N - 1`. | ||
| 765 | +fn reset_var_alphabet<const N: usize, const M: usize, const K: usize>( | ||
| 766 | + a: &mut [[[u16; N]; M]; K], | ||
| 767 | +) { | ||
| 768 | + for (idx, rows) in a.iter_mut().enumerate() { | ||
| 769 | + for row in rows.iter_mut() { | ||
| 770 | + row[idx + 2] = 0; | ||
| 771 | + } | ||
| 772 | + } | ||
| 773 | +} | ||
| 774 | + | ||
| 762 | impl MvComponentCdfs { | 775 | impl MvComponentCdfs { |
| 763 | fn reset_counts(&mut self) { | 776 | fn reset_counts(&mut self) { |
| 764 | reset1(&mut self.class); | 777 | reset1(&mut self.class); |
| @@ -926,8 +939,18 @@ impl Cdfs { | |||
| 926 | reset2(&mut self.palette_y_size); | 939 | reset2(&mut self.palette_y_size); |
| 927 | reset2(&mut self.palette_uv_mode); | 940 | reset2(&mut self.palette_uv_mode); |
| 928 | reset2(&mut self.palette_uv_size); | 941 | reset2(&mut self.palette_uv_size); |
| 929 | - reset3(&mut self.palette_y_color_index); | 942 | + // lane-t900 r22 (class cdf-counter-not-reset): the two colour-index |
| 930 | - reset3(&mut self.palette_uv_color_index); | 943 | + // tables are the only VARIABLE-ALPHABET ones here -- the reader takes |
| 944 | + // `[..=n]` of a `[u16; 9]` row, so `update_cdf`'s symbol counter lives | ||
| 945 | + // at index `n` (= table index + 2), not at the array's last entry. | ||
| 946 | + // `reset3` zeroed slot 8, which no `n < 8` row ever uses, so every | ||
| 947 | + // palette colour-index row crossed a frame boundary with a SATURATED | ||
| 948 | + // count (32) and adapted at rate 6 where libaom, counting from 0, | ||
| 949 | + // adapts at rate 4: the first inter-frame palette block's map desynced | ||
| 950 | + // at its third colour-index symbol (witness `palette_screen_witness.obu`, | ||
| 951 | + // decode-order frame 3, mi(40,0), Y map (0,2)). | ||
| 952 | + reset_var_alphabet(&mut self.palette_y_color_index); | ||
| 953 | + reset_var_alphabet(&mut self.palette_uv_color_index); | ||
| 931 | reset1(&mut self.intrabc); | 954 | reset1(&mut self.intrabc); |
| 932 | reset1(&mut self.restore_wiener); | 955 | reset1(&mut self.restore_wiener); |
| 933 | reset1(&mut self.restore_sgrproj); | 956 | reset1(&mut self.restore_sgrproj); |
crates/ec-av1/src/decode.rsmodified+210 -30
| @@ -1727,6 +1727,24 @@ pub(crate) fn reset_palette_sb_strip_hits() { | |||
| 1727 | PALETTE_SB_STRIP_HITS.with(|c| c.set(0)); | 1727 | PALETTE_SB_STRIP_HITS.with(|c| c.set(0)); |
| 1728 | } | 1728 | } |
| 1729 | 1729 | ||
| 1730 | +// lane-t900 r22: palette blocks reconstructed inside an INTER frame (the | ||
| 1731 | +// intra-in-inter path, `decode_inter_block`/`decode_inter_block8`) -- counted | ||
| 1732 | +// apart from [`PALETTE_HITS`] so a witness gate can prove the INTER-frame | ||
| 1733 | +// capability rather than the key frame's, which every screen stream also | ||
| 1734 | +// carries. | ||
| 1735 | +thread_local! { | ||
| 1736 | + static INTRA_IN_INTER_PALETTE_Y_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1737 | + static INTRA_IN_INTER_PALETTE_UV_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 1738 | +} | ||
| 1739 | + | ||
| 1740 | +/// Current values of the two intra-in-inter palette counters, `(y, uv)`. | ||
| 1741 | +pub(crate) fn intra_in_inter_palette_hits() -> (usize, usize) { | ||
| 1742 | + ( | ||
| 1743 | + INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.get()), | ||
| 1744 | + INTRA_IN_INTER_PALETTE_UV_HITS.with(|c| c.get()), | ||
| 1745 | + ) | ||
| 1746 | +} | ||
| 1747 | + | ||
| 1730 | // lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform | 1748 | // lane-hgkf r2: SKIPPED intra blocks whose `tx_depth` split the luma transform |
| 1731 | // and which are therefore predicted one transform unit at a time (a skipped | 1749 | // and which are therefore predicted one transform unit at a time (a skipped |
| 1732 | // block codes no coefficients, so nothing else in the stream witnesses this | 1750 | // block codes no coefficients, so nothing else in the stream witnesses this |
| @@ -6692,7 +6710,12 @@ fn decode_color_index_map_wh( | |||
| 6692 | let (ctx, color_order) = palette_color_index_context(&map, bw, row, col, n); | 6710 | let (ctx, color_order) = palette_color_index_context(&map, bw, row, col, n); |
| 6693 | if trace { | 6711 | if trace { |
| 6694 | let (rng, _) = dec.debug_state(); | 6712 | let (rng, _) = dec.debug_state(); |
| 6695 | - eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}"); | 6713 | + let row_cdf = if uv { |
| 6714 | + &cdfs.palette_uv_color_index[n - 2][ctx] | ||
| 6715 | + } else { | ||
| 6716 | + &cdfs.palette_y_color_index[n - 2][ctx] | ||
| 6717 | + }; | ||
| 6718 | + eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}", row_cdf[0], row_cdf[n]); | ||
| 6696 | } | 6719 | } |
| 6697 | let symbol = if uv { | 6720 | let symbol = if uv { |
| 6698 | dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) | 6721 | dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) |
| @@ -7715,12 +7738,13 @@ fn decode_intra_rect_in_inter( | |||
| 7715 | // [`INTRA_IN_INTER_MODE`] switches to `read_intra_block_mode_info`'s | 7738 | // [`INTRA_IN_INTER_MODE`] switches to `read_intra_block_mode_info`'s |
| 7716 | // `y_mode[0]` plus the `skip` this caller already read. | 7739 | // `y_mode[0]` plus the `skip` this caller already read. |
| 7717 | if let Some((horz, has_chroma)) = strip16 { | 7740 | if let Some((horz, has_chroma)) = strip16 { |
| 7718 | - if allow_screen_content_tools { | 7741 | + // lane-t900 r22: the screen-content refusal here was STALE (class |
| 7719 | - return Err(unsupported( | 7742 | + // stale-premise): [`decode_rect4_16_strip`] takes |
| 7720 | - "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ | 7743 | + // `allow_screen_content_tools` and reads the whole palette syntax |
| 7721 | - is consumed for square blocks only)", | 7744 | + // (mode/size/colours/colour-index map, its own `palette_ctx_and_cache_mi` |
| 7722 | - )); | 7745 | + // pair) -- the key frame proves that body. Lifted with the 10-bit |
| 7723 | - } | 7746 | + // witness `palette_screen_witness_10bit.obu`, whose inter frames carry |
| 7747 | + // 16x4/4x16 intra strips inside a `--tune-content=screen` frame. | ||
| 7724 | debug_assert_eq!((bw, bh), if horz { (16, 4) } else { (4, 16) }); | 7748 | debug_assert_eq!((bw, bh), if horz { (16, 4) } else { (4, 16) }); |
| 7725 | INTRA_IN_INTER_MODE.with(|c| c.set(Some((0, skip)))); | 7749 | INTRA_IN_INTER_MODE.with(|c| c.set(Some((0, skip)))); |
| 7726 | let res = decode_rect4_16_strip( | 7750 | let res = decode_rect4_16_strip( |
| @@ -8015,24 +8039,35 @@ fn decode_intra_rect_in_inter( | |||
| 8015 | // frame writes `palette_y_mode`/`palette_uv_mode` for every block whose | 8039 | // frame writes `palette_y_mode`/`palette_uv_mode` for every block whose |
| 8016 | // shape [`palette_bsize_ctx_wh`] admits, intra strips included, so | 8040 | // shape [`palette_bsize_ctx_wh`] admits, intra strips included, so |
| 8017 | // skipping the syntax here desynced the tile at the strip's own symbol. | 8041 | // skipping the syntax here desynced the tile at the strip's own symbol. |
| 8018 | - // No block this decoder produces can USE a palette (the arms below refuse | 8042 | + // lane-t900 r22: reconstructed, not refused -- the strip's real mode |
| 8019 | - // by name), so the neighbour mode context is 0 and there is no cache -- | 8043 | + // context and colour cache at its own mi position, and the two |
| 8020 | - // the same stand-in [`read_intra_mode_rect`] uses when its caller has none. | 8044 | + // colour-index maps decoded after `filter_intra` (`av1_visit_palette`), |
| 8045 | + // exactly as [`read_intra_mode_rect`] does on the key-frame path. | ||
| 8046 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi((mi_r, mi_c)); | ||
| 8047 | + let palette_uv_cache = neighbours.palette_uv_cache_mi((mi_r, mi_c)); | ||
| 8048 | + let mut palette_y_pending: Option<(usize, [u16; 8])> = None; | ||
| 8049 | + let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; | ||
| 8021 | if allow_screen_content_tools | 8050 | if allow_screen_content_tools |
| 8022 | && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) | 8051 | && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh) |
| 8023 | { | 8052 | { |
| 8024 | INTRA_RECT_IN_INTER_SCREEN_HITS.with(|c| c.set(c.get() + 1)); | 8053 | INTRA_RECT_IN_INTER_SCREEN_HITS.with(|c| c.set(c.get() + 1)); |
| 8025 | - if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][0]) != 0 { | 8054 | + let use_palette_y = |
| 8026 | - return Err(unsupported( | 8055 | + mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0; |
| 8027 | - "a block that actually uses a palette (Y) -- reconstruction is out of scope", | 8056 | + if use_palette_y { |
| 8028 | - )); | 8057 | + let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); |
| 8058 | + palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache))); | ||
| 8029 | } | 8059 | } |
| 8030 | // A 2:1 strip of at least 8x8 is always a chroma reference, so | 8060 | // A 2:1 strip of at least 8x8 is always a chroma reference, so |
| 8031 | // `read_palette_mode_info`'s `xd->is_chroma_ref` guard holds here. | 8061 | // `read_palette_mode_info`'s `xd->is_chroma_ref` guard holds here. |
| 8032 | - if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { | 8062 | + let use_palette_uv = |
| 8033 | - return Err(unsupported( | 8063 | + uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0; |
| 8034 | - "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 8064 | + if crate::envflags::env_flag!("EC_PALSYN") { |
| 8035 | - )); | 8065 | + eprintln!("EC_PALSYN rect mi={mi_r},{mi_c} bw={bw} bh={bh} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}", use_palette_y as i32, use_palette_uv as i32, dec.debug_state().0); |
| 8066 | + } | ||
| 8067 | + if use_palette_uv { | ||
| 8068 | + let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); | ||
| 8069 | + let (u_colors, v_colors) = read_palette_colors_uv(dec, n, &palette_uv_cache); | ||
| 8070 | + palette_uv_pending = Some((n, u_colors, v_colors)); | ||
| 8036 | } | 8071 | } |
| 8037 | } | 8072 | } |
| 8038 | // lane-fiinter (merged on main for the square intra-in-inter arm): | 8073 | // lane-fiinter (merged on main for the square intra-in-inter arm): |
| @@ -8044,6 +8079,8 @@ fn decode_intra_rect_in_inter( | |||
| 8044 | let mut filter_intra = None; | 8079 | let mut filter_intra = None; |
| 8045 | if mode == DC_PRED | 8080 | if mode == DC_PRED |
| 8046 | && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) | 8081 | && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) |
| 8082 | + // `av1_filter_intra_allowed` excludes a palette-Y block. | ||
| 8083 | + && palette_y_pending.is_none() | ||
| 8047 | && let Some(class) = filter_intra_size_class_rect(bw, bh) | 8084 | && let Some(class) = filter_intra_size_class_rect(bw, bh) |
| 8048 | && dec.symbol(&mut cdfs.filter_intra[class]) != 0 | 8085 | && dec.symbol(&mut cdfs.filter_intra[class]) != 0 |
| 8049 | { | 8086 | { |
| @@ -8051,6 +8088,21 @@ fn decode_intra_rect_in_inter( | |||
| 8051 | INTRA_IN_INTER_FILTER_INTRA_HITS.with(|h| h.set(h.get() + 1)); | 8088 | INTRA_IN_INTER_FILTER_INTRA_HITS.with(|h| h.set(h.get() + 1)); |
| 8052 | filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); | 8089 | filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); |
| 8053 | } | 8090 | } |
| 8091 | + // `av1_visit_palette`: Y's colour-index map then the shared chroma one. | ||
| 8092 | + let palette_y = palette_y_pending.map(|(n, colors)| { | ||
| 8093 | + let map = decode_color_index_map_wh(dec, cdfs, n, bw, bh, false); | ||
| 8094 | + PALETTE_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8095 | + PALETTE_RECT_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8096 | + INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8097 | + PaletteY { size: n, colors, map } | ||
| 8098 | + }); | ||
| 8099 | + let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { | ||
| 8100 | + let (cw, ch) = ((bw / 2).max(4), (bh / 2).max(4)); | ||
| 8101 | + let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, true); | ||
| 8102 | + PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8103 | + INTRA_IN_INTER_PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 8104 | + PaletteUv { size: n, u_colors, v_colors, map } | ||
| 8105 | + }); | ||
| 8054 | // The intra-edge filter type is the NEIGHBOUR's mode (libaom | 8106 | // The intra-edge filter type is the NEIGHBOUR's mode (libaom |
| 8055 | // `get_filt_type`), luma's off the luma neighbours and chroma's off the | 8107 | // `get_filt_type`), luma's off the luma neighbours and chroma's off the |
| 8056 | // chroma ones -- [`decode_block_rect`]'s own pair. | 8108 | // chroma ones -- [`decode_block_rect`]'s own pair. |
| @@ -8127,10 +8179,15 @@ fn decode_intra_rect_in_inter( | |||
| 8127 | filter_intra, | 8179 | filter_intra, |
| 8128 | smooth_neighbor, | 8180 | smooth_neighbor, |
| 8129 | smooth_neighbor_uv, | 8181 | smooth_neighbor_uv, |
| 8130 | - // screen-content frames are refused whole above, so this strip can | 8182 | + palette_y: palette_y |
| 8131 | - // carry no palette. | 8183 | + .as_ref() |
| 8132 | - palette_y: None, | 8184 | + .map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()), |
| 8133 | - palette_uv: None, | 8185 | + palette_uv: palette_uv.as_ref().map(|p| { |
| 8186 | + ( | ||
| 8187 | + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), | ||
| 8188 | + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), | ||
| 8189 | + ) | ||
| 8190 | + }), | ||
| 8134 | }; | 8191 | }; |
| 8135 | decode_rect_split( | 8192 | decode_rect_split( |
| 8136 | dec, | 8193 | dec, |
| @@ -8164,6 +8221,18 @@ fn decode_intra_rect_in_inter( | |||
| 8164 | *cell = tx_h as u8; | 8221 | *cell = tx_h as u8; |
| 8165 | } | 8222 | } |
| 8166 | } | 8223 | } |
| 8224 | + // The strip's own palette state into the mi-granular neighbour bands, so | ||
| 8225 | + // the next block's colour cache and `palette_y_mode` context are libaom's. | ||
| 8226 | + record_strip_palette( | ||
| 8227 | + neighbours, | ||
| 8228 | + (mi_r, mi_c), | ||
| 8229 | + bw, | ||
| 8230 | + bh, | ||
| 8231 | + palette_y.as_ref().map_or(0, |p| p.size), | ||
| 8232 | + palette_y.as_ref().map_or([0u16; 8], |p| p.colors), | ||
| 8233 | + palette_uv.as_ref().map_or(0, |p| p.size), | ||
| 8234 | + palette_uv.as_ref().map_or([0u16; 8], |p| p.u_colors), | ||
| 8235 | + ); | ||
| 8167 | let class = match bw.max(bh) { | 8236 | let class = match bw.max(bh) { |
| 8168 | 64 => 0, | 8237 | 64 => 0, |
| 8169 | 32 => 1, | 8238 | 32 => 1, |
| @@ -20691,6 +20760,13 @@ fn decode_inter_block( | |||
| 20691 | // than one luma transform -- read back by the residual loop, the | 20760 | // than one luma transform -- read back by the residual loop, the |
| 20692 | // coefficient-context write-back and the loop-filter grid fill below. | 20761 | // coefficient-context write-back and the loop-filter grid fill below. |
| 20693 | let mut vartx_leaves: Option<Vec<(usize, usize, usize, usize)>> = None; | 20762 | let mut vartx_leaves: Option<Vec<(usize, usize, usize, usize)>> = None; |
| 20763 | + // lane-t900 r22: this block's own palette state, stamped into the | ||
| 20764 | + // mi-granular neighbour bands at the tail below for EVERY block -- | ||
| 20765 | + // libaom's `MB_MODE_INFO.palette_size` is 0 on an inter block, and | ||
| 20766 | + // `av1_get_palette_cache`/`av1_get_palette_mode_ctx` read those cells, so | ||
| 20767 | + // leaving a previous palette block's colours standing here would feed the | ||
| 20768 | + // next intra block a cache libaom never builds. | ||
| 20769 | + let mut palette_record: (usize, [u16; 8], usize, [u16; 8]) = (0, [0u16; 8], 0, [0u16; 8]); | ||
| 20694 | let at_mi = at; | 20770 | let at_mi = at; |
| 20695 | // lane-vert46 r1: set when this block's chroma was coded as one 32x32 unit | 20771 | // lane-vert46 r1: set when this block's chroma was coded as one 32x32 unit |
| 20696 | // per 64x64 "mu" chunk (any side above 64), so the end-of-block record | 20772 | // per 64x64 "mu" chunk (any side above 64), so the end-of-block record |
| @@ -23376,18 +23452,39 @@ fn decode_inter_block( | |||
| 23376 | // by the block's TRUE footprint -- a rect strip's row is not its | 23452 | // by the block's TRUE footprint -- a rect strip's row is not its |
| 23377 | // enclosing square's, and a 16x4 strip (64 pixels) reads no palette | 23453 | // enclosing square's, and a 16x4 strip (64 pixels) reads no palette |
| 23378 | // symbol at all. | 23454 | // symbol at all. |
| 23455 | + // lane-t900 r22: reconstructed, not refused. Same syntax and same | ||
| 23456 | + // deferral of the colour-index maps past `filter_intra` | ||
| 23457 | + // (`av1_visit_palette` runs from `parse_decode_block`, after the whole | ||
| 23458 | + // mode-info read) as the key frame's [`read_intra_mode`]; the mode | ||
| 23459 | + // context and colour cache are this block's real above/left ones, at | ||
| 23460 | + // its own mi position (`av1_get_palette_mode_ctx`/ | ||
| 23461 | + // `av1_get_palette_cache`), not the hardcoded 0/empty pair the refusal | ||
| 23462 | + // could get away with while no neighbour could ever be a palette. | ||
| 23463 | + let (palette_ctx, palette_cache) = neighbours.palette_ctx_and_cache_mi((rmi, cmi)); | ||
| 23464 | + let palette_uv_cache = neighbours.palette_uv_cache_mi((rmi, cmi)); | ||
| 23465 | + let mut palette_y_pending: Option<(usize, [u16; 8])> = None; | ||
| 23466 | + let mut palette_uv_pending: Option<(usize, [u16; 8], [u16; 8])> = None; | ||
| 23379 | if allow_screen_content_tools | 23467 | if allow_screen_content_tools |
| 23380 | && let Some(bsize_ctx) = palette_bsize_ctx_wh(write_w, write_h) | 23468 | && let Some(bsize_ctx) = palette_bsize_ctx_wh(write_w, write_h) |
| 23381 | { | 23469 | { |
| 23382 | - if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][0]) != 0 { | 23470 | + let use_palette_y = |
| 23383 | - return Err(unsupported( | 23471 | + mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][palette_ctx]) != 0; |
| 23384 | - "a block that actually uses a palette (Y) -- reconstruction is out of scope", | 23472 | + if use_palette_y { |
| 23385 | - )); | 23473 | + let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); |
| 23474 | + palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache))); | ||
| 23386 | } | 23475 | } |
| 23387 | - if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { | 23476 | + if crate::envflags::env_flag!("EC_PALSYN") { |
| 23388 | - return Err(unsupported( | 23477 | + eprintln!("EC_PALSYN_PRE sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} rng={}", palette_y_pending.map_or(0, |(n, _)| n), dec.debug_state().0); |
| 23389 | - "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 23478 | + } |
| 23390 | - )); | 23479 | + let use_palette_uv = |
| 23480 | + uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0; | ||
| 23481 | + if crate::envflags::env_flag!("EC_PALSYN") { | ||
| 23482 | + eprintln!("EC_PALSYN sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} uv={} rng={}", use_palette_y as i32, use_palette_uv as i32, dec.debug_state().0); | ||
| 23483 | + } | ||
| 23484 | + if use_palette_uv { | ||
| 23485 | + let n = 2 + dec.symbol(&mut cdfs.palette_uv_size[bsize_ctx]); | ||
| 23486 | + let (u_colors, v_colors) = read_palette_colors_uv(dec, n, &palette_uv_cache); | ||
| 23487 | + palette_uv_pending = Some((n, u_colors, v_colors)); | ||
| 23391 | } | 23488 | } |
| 23392 | } | 23489 | } |
| 23393 | // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`, | 23490 | // lane-fiinter r1: `read_filter_intra_mode_info` (libaom `decodemv.c`, |
| @@ -23401,6 +23498,9 @@ fn decode_inter_block( | |||
| 23401 | let mut filter_intra = None; | 23498 | let mut filter_intra = None; |
| 23402 | if mode == DC_PRED | 23499 | if mode == DC_PRED |
| 23403 | && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) | 23500 | && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get) |
| 23501 | + // `av1_filter_intra_allowed` (reconintra.h:77) excludes a | ||
| 23502 | + // palette-Y block, so no `use_filter_intra` symbol exists there. | ||
| 23503 | + && palette_y_pending.is_none() | ||
| 23404 | // lane-inter16ab r4 (class sweep): `cdf::FILTER_INTRA`'s row is the | 23504 | // lane-inter16ab r4 (class sweep): `cdf::FILTER_INTRA`'s row is the |
| 23405 | // true `BLOCK_SIZES_ALL` class of this strip, not its square side's. | 23505 | // true `BLOCK_SIZES_ALL` class of this strip, not its square side's. |
| 23406 | && let Some(class) = filter_intra_size_class_rect(write_w, write_h) | 23506 | && let Some(class) = filter_intra_size_class_rect(write_w, write_h) |
| @@ -23410,6 +23510,41 @@ fn decode_inter_block( | |||
| 23410 | INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); | 23510 | INTRA_IN_INTER_FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); |
| 23411 | filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); | 23511 | filter_intra = Some(dec.symbol(&mut cdfs.filter_intra_mode)); |
| 23412 | } | 23512 | } |
| 23513 | + // `av1_visit_palette`: the two colour-index maps, Y then the shared | ||
| 23514 | + // chroma one, after the WHOLE mode-info read. | ||
| 23515 | + let palette_y = palette_y_pending.map(|(n, colors)| { | ||
| 23516 | + let map = decode_color_index_map_wh(dec, cdfs, n, write_w, write_h, false); | ||
| 23517 | + PALETTE_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23518 | + INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23519 | + PaletteY { size: n, colors, map } | ||
| 23520 | + }); | ||
| 23521 | + let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { | ||
| 23522 | + // `av1_get_plane_block_size(bsize, 1, 1)` floors at the 4-px | ||
| 23523 | + // transform, as the rect reader's own copy. | ||
| 23524 | + let (cw, ch) = ((write_w / 2).max(4), (write_h / 2).max(4)); | ||
| 23525 | + let map = decode_color_index_map_wh(dec, cdfs, n, cw, ch, true); | ||
| 23526 | + PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23527 | + INTRA_IN_INTER_PALETTE_UV_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23528 | + PaletteUv { size: n, u_colors, v_colors, map } | ||
| 23529 | + }); | ||
| 23530 | + palette_record = ( | ||
| 23531 | + palette_y.as_ref().map_or(0, |p| p.size), | ||
| 23532 | + palette_y.as_ref().map_or([0u16; 8], |p| p.colors), | ||
| 23533 | + palette_uv.as_ref().map_or(0, |p| p.size), | ||
| 23534 | + palette_uv.as_ref().map_or([0u16; 8], |p| p.u_colors), | ||
| 23535 | + ); | ||
| 23536 | + // A palette block predicts from its own colour-index map, never from | ||
| 23537 | + // the block edge (spec 7.11.2/7.11.4) -- these ride the [`PALETTE_PRED`] | ||
| 23538 | + // slot into each `reconstruct`/`read_plane` call below, exactly as the | ||
| 23539 | + // key-frame paths do. | ||
| 23540 | + let palette_y_buf: Option<Vec<u16>> = | ||
| 23541 | + palette_y.as_ref().map(|p| p.map.iter().map(|&i| p.colors[i as usize]).collect()); | ||
| 23542 | + let palette_uv_bufs: Option<(Vec<u16>, Vec<u16>)> = palette_uv.as_ref().map(|p| { | ||
| 23543 | + ( | ||
| 23544 | + p.map.iter().map(|&i| p.u_colors[i as usize]).collect(), | ||
| 23545 | + p.map.iter().map(|&i| p.v_colors[i as usize]).collect(), | ||
| 23546 | + ) | ||
| 23547 | + }); | ||
| 23413 | mode_for_tx = mode; | 23548 | mode_for_tx = mode; |
| 23414 | block_filter = [3, 3]; | 23549 | block_filter = [3, 3]; |
| 23415 | ref_frame_for_lf = 0; | 23550 | ref_frame_for_lf = 0; |
| @@ -23473,6 +23608,19 @@ fn decode_inter_block( | |||
| 23473 | // bottom-left availability is the block's, narrowed by the | 23608 | // bottom-left availability is the block's, narrowed by the |
| 23474 | // unit's own offset inside it. | 23609 | // unit's own offset inside it. |
| 23475 | let tu_reach = Reach::of_tu(side, side, col * MI, row * MI, tx_px, tx_px, reach); | 23610 | let tu_reach = Reach::of_tu(side, side, col * MI, row * MI, tx_px, tx_px, reach); |
| 23611 | + // This unit's own window on the block's palette prediction | ||
| 23612 | + // (the whole-block buffer would be indexed at the wrong | ||
| 23613 | + // stride by the first unit). | ||
| 23614 | + if let Some(buf) = &palette_y_buf { | ||
| 23615 | + PALETTE_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1)); | ||
| 23616 | + let window: Vec<u16> = (0..tx_px) | ||
| 23617 | + .flat_map(|i| { | ||
| 23618 | + let base = (row * MI + i) * side + col * MI; | ||
| 23619 | + buf[base..base + tx_px].iter().copied() | ||
| 23620 | + }) | ||
| 23621 | + .collect(); | ||
| 23622 | + set_palette_pred(window); | ||
| 23623 | + } | ||
| 23476 | let tu_grid = if skip { | 23624 | let tu_grid = if skip { |
| 23477 | y.reconstruct( | 23625 | y.reconstruct( |
| 23478 | tu_px, | 23626 | tu_px, |
| @@ -23611,6 +23759,9 @@ fn decode_inter_block( | |||
| 23611 | INTRA_128_IN_INTER_HITS.with(|c| c.set(c.get() + 1)); | 23759 | INTRA_128_IN_INTER_HITS.with(|c| c.set(c.get() + 1)); |
| 23612 | } else if skip { | 23760 | } else if skip { |
| 23613 | if !split_luma { | 23761 | if !split_luma { |
| 23762 | + if let Some(buf) = &palette_y_buf { | ||
| 23763 | + set_palette_pred(buf.clone()); | ||
| 23764 | + } | ||
| 23614 | y.reconstruct( | 23765 | y.reconstruct( |
| 23615 | px, | 23766 | px, |
| 23616 | py, | 23767 | py, |
| @@ -23625,6 +23776,9 @@ fn decode_inter_block( | |||
| 23625 | ); | 23776 | ); |
| 23626 | } | 23777 | } |
| 23627 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 23778 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 23779 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 23780 | + set_palette_pred(ub.clone()); | ||
| 23781 | + } | ||
| 23628 | u.reconstruct( | 23782 | u.reconstruct( |
| 23629 | cpx, | 23783 | cpx, |
| 23630 | cpy, | 23784 | cpy, |
| @@ -23637,6 +23791,9 @@ fn decode_inter_block( | |||
| 23637 | None, | 23791 | None, |
| 23638 | smooth_neighbor_uv, | 23792 | smooth_neighbor_uv, |
| 23639 | ); | 23793 | ); |
| 23794 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 23795 | + set_palette_pred(vb.clone()); | ||
| 23796 | + } | ||
| 23640 | v.reconstruct( | 23797 | v.reconstruct( |
| 23641 | cpx, | 23798 | cpx, |
| 23642 | cpy, | 23799 | cpy, |
| @@ -23660,6 +23817,9 @@ fn decode_inter_block( | |||
| 23660 | // which `record_split_luma` ignores for plane 0. | 23817 | // which `record_split_luma` ignores for plane 0. |
| 23661 | vec![0i32; side * side] | 23818 | vec![0i32; side * side] |
| 23662 | } else { | 23819 | } else { |
| 23820 | + if let Some(buf) = &palette_y_buf { | ||
| 23821 | + set_palette_pred(buf.clone()); | ||
| 23822 | + } | ||
| 23663 | read_plane( | 23823 | read_plane( |
| 23664 | dec, | 23824 | dec, |
| 23665 | cdfs, | 23825 | cdfs, |
| @@ -23684,6 +23844,9 @@ fn decode_inter_block( | |||
| 23684 | )? | 23844 | )? |
| 23685 | }; | 23845 | }; |
| 23686 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); | 23846 | let ac = alpha.map(|_| cfl_ac_q3(y, px, py, side)); |
| 23847 | + if let Some((ub, _)) = &palette_uv_bufs { | ||
| 23848 | + set_palette_pred(ub.clone()); | ||
| 23849 | + } | ||
| 23687 | u_grid = read_plane( | 23850 | u_grid = read_plane( |
| 23688 | dec, | 23851 | dec, |
| 23689 | cdfs, | 23852 | cdfs, |
| @@ -23706,6 +23869,9 @@ fn decode_inter_block( | |||
| 23706 | None, | 23869 | None, |
| 23707 | smooth_neighbor_uv, | 23870 | smooth_neighbor_uv, |
| 23708 | )?; | 23871 | )?; |
| 23872 | + if let Some((_, vb)) = &palette_uv_bufs { | ||
| 23873 | + set_palette_pred(vb.clone()); | ||
| 23874 | + } | ||
| 23709 | v_grid = read_plane( | 23875 | v_grid = read_plane( |
| 23710 | dec, | 23876 | dec, |
| 23711 | cdfs, | 23877 | cdfs, |
| @@ -23791,6 +23957,20 @@ fn decode_inter_block( | |||
| 23791 | // mi(40,220): base 1 where libaom gathers 2). Snapshot and restore is | 23957 | // mi(40,220): base 1 where libaom gathers 2). Snapshot and restore is |
| 23792 | // equivalent to not writing them, without threading a flag through both | 23958 | // equivalent to not writing them, without threading a flag through both |
| 23793 | // recorders. | 23959 | // recorders. |
| 23960 | + // lane-t900 r22: every block stamps its palette state (all-zero for an | ||
| 23961 | + // inter block, real for a palette one) into the mi-granular neighbour | ||
| 23962 | + // bands, so the next intra block's `av1_get_palette_mode_ctx` and colour | ||
| 23963 | + // cache see exactly what libaom's mode-info grid holds. | ||
| 23964 | + record_strip_palette( | ||
| 23965 | + neighbours, | ||
| 23966 | + at, | ||
| 23967 | + write_w, | ||
| 23968 | + write_h, | ||
| 23969 | + palette_record.0, | ||
| 23970 | + palette_record.1, | ||
| 23971 | + palette_record.2, | ||
| 23972 | + palette_record.3, | ||
| 23973 | + ); | ||
| 23794 | let saved_chroma_ctx = (!has_chroma).then(|| { | 23974 | let saved_chroma_ctx = (!has_chroma).then(|| { |
| 23795 | NON_CHROMA_REF_CTX_SKIP_HITS.with(|c| c.set(c.get() + 1)); | 23975 | NON_CHROMA_REF_CTX_SKIP_HITS.with(|c| c.set(c.get() + 1)); |
| 23796 | let (w_mi, h_mi) = (write_w / MI, write_h / MI); | 23976 | let (w_mi, h_mi) = (write_w / MI, write_h / MI); |
crates/ec-av1/src/refusal_inventory.rsmodified+13 -3
| @@ -46,6 +46,12 @@ const REFUSALS: &[&str] = &[ | |||
| 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)", | 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 | "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)", | 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 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", | 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. | ||
| 49 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 55 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 50 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", | 56 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 51 | "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", | 57 | "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", |
| @@ -111,9 +117,13 @@ const REFUSALS: &[&str] = &[ | |||
| 111 | // both arms of gate | 117 | // both arms of gate |
| 112 | // `a_real_aomenc_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips` | 118 | // `a_real_aomenc_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips` |
| 113 | // decode ten frames pixel-exact with the strips counted. What still | 119 | // decode ten frames pixel-exact with the strips counted. What still |
| 114 | - // refuses is a 16x4/4x16 strip and a 128-root half, neither of which is | 120 | + // lane-t900 r22 NARROWED it again: the 16x4/4x16 arm is LIFTED (that arm |
| 115 | - // palette-eligible (`palette_bsize_ctx_wh` wants `8 <= min`, `max <= 64`) | 121 | + // routes through `decode_rect4_16_strip`, which reads the palette syntax |
| 116 | - // and neither of which has a witness stream yet. | 122 | + // itself -- the premise was stale), gated by |
| 123 | + // `a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact`. | ||
| 124 | + // What still refuses is the 128-root half of a screen-content frame, whose | ||
| 125 | + // body (`decode_block_128rect`) reads no palette syntax and for which no | ||
| 126 | + // `--sb-size=128` screen witness exists yet. | ||
| 117 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", | 127 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", |
| 118 | "warp prediction with a scaled reference (superres, unimplemented)", | 128 | "warp prediction with a scaled reference (superres, unimplemented)", |
| 119 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", | 129 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", |
crates/ec-av1/src/stream.rsmodified+124 -0
| @@ -119,6 +119,13 @@ pub fn rect_intrabc_reads() -> usize { | |||
| 119 | crate::decode::rect_intrabc_reads() | 119 | crate::decode::rect_intrabc_reads() |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | +/// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900 | ||
| 123 | +/// r22) -- the counter a screen-content witness gate reads to prove it | ||
| 124 | +/// exercises the inter-frame palette path, not the key frame's. | ||
| 125 | +pub fn intra_in_inter_palette_hits() -> (usize, usize) { | ||
| 126 | + crate::decode::intra_in_inter_palette_hits() | ||
| 127 | +} | ||
| 128 | + | ||
| 122 | /// lane-rect64port r1: coded 64-level HORZ/VERT intra strips whose luma | 129 | /// lane-rect64port r1: coded 64-level HORZ/VERT intra strips whose luma |
| 123 | /// transform unit is the un-split TX_64X32 (orient 0) / TX_32X64 (orient 1). | 130 | /// transform unit is the un-split TX_64X32 (orient 0) / TX_32X64 (orient 1). |
| 124 | pub fn rect64_corner_tu_hits(orient: usize) -> usize { | 131 | pub fn rect64_corner_tu_hits(orient: usize) -> usize { |
| @@ -30922,6 +30929,123 @@ mod tests { | |||
| 30922 | ); | 30929 | ); |
| 30923 | } | 30930 | } |
| 30924 | 30931 | ||
| 30932 | + /// lane-t900 r22 GATE: a real `aomenc --tune-content=screen | ||
| 30933 | + /// --enable-palette=1` stream whose INTER frames reconstruct palette | ||
| 30934 | + /// blocks (Y and UV), at both bit depths. | ||
| 30935 | + /// | ||
| 30936 | + /// Recipe (both fixtures, 15 frames, key + 14 inter, 256x192, one tile): | ||
| 30937 | + /// `aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=20 --cpu-used=1 | ||
| 30938 | + /// --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=9999 | ||
| 30939 | + /// --sb-size=64 --tune-content=screen --enable-palette=1 | ||
| 30940 | + /// --enable-intrabc=0 --obu` (plus `--bit-depth=10 --profile=0` for the | ||
| 30941 | + /// twin) over a synthetic screen-like source: two luma levels on a 16x16 | ||
| 30942 | + /// grid, four chroma levels on an 8x8 one, both re-keyed per frame so the | ||
| 30943 | + /// encoder cannot predict the new blocks and codes them INTRA inside the | ||
| 30944 | + /// inter frames. `--enable-palette=0` on the same source is 13% larger, | ||
| 30945 | + /// which is what says the tool is really used. | ||
| 30946 | + /// | ||
| 30947 | + /// What this pins that no key-frame palette gate can: the palette | ||
| 30948 | + /// colour-index CDFs are this decoder's only VARIABLE-ALPHABET tables (the | ||
| 30949 | + /// reader takes `[..=n]` of a `[u16; 9]` row, so `update_cdf`'s counter | ||
| 30950 | + /// lives at index `n`), and `Cdfs::reset_counts` zeroed slot 8 instead -- | ||
| 30951 | + /// so every colour-index row crossed a frame boundary with a SATURATED | ||
| 30952 | + /// count and adapted at rate 6 where libaom, counting from 0, adapts at 4. | ||
| 30953 | + /// The first inter-frame palette block's map desynced at its THIRD | ||
| 30954 | + /// colour-index symbol (decode-order frame 3, mi(40,0), map cell (0,2): | ||
| 30955 | + /// ours cdf0 = 32768-1071, aomdec's = 32768-971, same ctx, same value, | ||
| 30956 | + /// different range). | ||
| 30957 | + #[test] | ||
| 30958 | + fn a_real_aomenc_screen_stream_with_palette_blocks_decodes_pixel_exact() { | ||
| 30959 | + const NAME: &str = | ||
| 30960 | + "a_real_aomenc_screen_stream_with_palette_blocks_decodes_pixel_exact"; | ||
| 30961 | + if !have_ffmpeg() { | ||
| 30962 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 30963 | + return; | ||
| 30964 | + } | ||
| 30965 | + for (fixture, ten_bit) in [ | ||
| 30966 | + ("fixtures/palette_screen_witness.obu", false), | ||
| 30967 | + ("fixtures/palette_screen_witness_10bit.obu", true), | ||
| 30968 | + ] { | ||
| 30969 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(fixture); | ||
| 30970 | + let stream = std::fs::read(&path) | ||
| 30971 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 30972 | + let (width, height) = (256usize, 192usize); | ||
| 30973 | + let before = intra_in_inter_palette_hits(); | ||
| 30974 | + let frames = match decode_stream(&stream) { | ||
| 30975 | + Ok(frames) => frames, | ||
| 30976 | + Err(e) => panic!("{NAME} [{fixture}]: decode_stream refused: {e}"), | ||
| 30977 | + }; | ||
| 30978 | + let after = intra_in_inter_palette_hits(); | ||
| 30979 | + let (fired_y, fired_uv) = (after.0 - before.0, after.1 - before.1); | ||
| 30980 | + assert!( | ||
| 30981 | + fired_y > 0 && fired_uv > 0, | ||
| 30982 | + "{NAME} [{fixture}]: inter-frame palette fired y={fired_y} uv={fired_uv} \ | ||
| 30983 | + -- both planes must fire or the gate is vacuous for the one that did not" | ||
| 30984 | + ); | ||
| 30985 | + assert_eq!(frames.len(), 15, "{NAME} [{fixture}]: 15 shown frames"); | ||
| 30986 | + let ffmpeg_frames = if ten_bit { | ||
| 30987 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | ||
| 30988 | + } else { | ||
| 30989 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | ||
| 30990 | + }; | ||
| 30991 | + assert_eq!( | ||
| 30992 | + ffmpeg_frames.len(), | ||
| 30993 | + frames.len(), | ||
| 30994 | + "{NAME} [{fixture}]: frame count" | ||
| 30995 | + ); | ||
| 30996 | + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 30997 | + assert_eq!(ours.y, theirs.y, "{NAME} [{fixture}]: frame {i} luma vs ffmpeg"); | ||
| 30998 | + assert_eq!(ours.u, theirs.u, "{NAME} [{fixture}]: frame {i} U vs ffmpeg"); | ||
| 30999 | + assert_eq!(ours.v, theirs.v, "{NAME} [{fixture}]: frame {i} V vs ffmpeg"); | ||
| 31000 | + } | ||
| 31001 | + eprintln!( | ||
| 31002 | + "{NAME} [{fixture}]: 15 frames pixel-exact on every plane; \ | ||
| 31003 | + inter-frame palette y={fired_y} uv={fired_uv}" | ||
| 31004 | + ); | ||
| 31005 | + } | ||
| 31006 | + } | ||
| 31007 | + | ||
| 31008 | + /// lane-t900 r22 GATE for the LIFTED refusal `"a HORZ/VERT intra strip in | ||
| 31009 | + /// a screen-content frame (palette syntax is consumed for square blocks | ||
| 31010 | + /// only)"` on its 16x4/4x16 arm: that arm routes through | ||
| 31011 | + /// `decode_rect4_16_strip`, which takes `allow_screen_content_tools` and | ||
| 31012 | + /// reads the whole palette syntax itself, so the refusal was a stale | ||
| 31013 | + /// premise (the key-frame path proves that body). This 10-bit | ||
| 31014 | + /// `--tune-content=screen` stream reached that exact refusal before the | ||
| 31015 | + /// lift and now decodes all 15 frames pixel-exact while 8 inter-frame | ||
| 31016 | + /// palette blocks reconstruct. | ||
| 31017 | + #[test] | ||
| 31018 | + fn a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact() { | ||
| 31019 | + const NAME: &str = | ||
| 31020 | + "a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact"; | ||
| 31021 | + if !have_ffmpeg() { | ||
| 31022 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 31023 | + return; | ||
| 31024 | + } | ||
| 31025 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 31026 | + .join("fixtures/palette_screen_strip16_witness_10bit.obu"); | ||
| 31027 | + let stream = std::fs::read(&path) | ||
| 31028 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 31029 | + let before = intra_in_inter_palette_hits(); | ||
| 31030 | + let frames = match decode_stream(&stream) { | ||
| 31031 | + Ok(frames) => frames, | ||
| 31032 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | ||
| 31033 | + }; | ||
| 31034 | + let fired_y = intra_in_inter_palette_hits().0 - before.0; | ||
| 31035 | + assert!( | ||
| 31036 | + fired_y > 0, | ||
| 31037 | + "{NAME}: no inter-frame palette block -- gate is vacuous" | ||
| 31038 | + ); | ||
| 31039 | + assert_eq!(frames.len(), 15, "{NAME}: 15 shown frames"); | ||
| 31040 | + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, 256, 192, frames.len()); | ||
| 31041 | + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 31042 | + assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg"); | ||
| 31043 | + assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg"); | ||
| 31044 | + assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg"); | ||
| 31045 | + } | ||
| 31046 | + eprintln!("{NAME}: 15 frames pixel-exact; inter-frame palette y={fired_y}"); | ||
| 31047 | + } | ||
| 31048 | + | ||
| 30925 | /// lane-t900 r20 GATE, refusal A -- `"a non-skip rectangular | 31049 | /// lane-t900 r20 GATE, refusal A -- `"a non-skip rectangular |
| 30926 | /// (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"`. | 31050 | /// (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"`. |
| 30927 | /// | 31051 | /// |