The intra-mode ablations force the palette off
Browse files at this commitcf280e5aa9eeaf426419a18b70d44d8dbbf227acParent: 55cb55e- test
- the intra-mode ablations force the palette off
1 changed file +27 -0
- crates/ec-av1/src/encode.rs +27 -0
crates/ec-av1/src/encode.rsmodified+27 -0
| @@ -725,6 +725,21 @@ thread_local! { | ||
| 725 | 725 | static SEQ_SCREEN: std::cell::Cell<bool> = const { std::cell::Cell::new(false) }; |
| 726 | 726 | } |
| 727 | 727 | |
| 728 | +thread_local! { | |
| 729 | + /// Overrides [`screen_content`] for the calling thread, which is what the | |
| 730 | + /// intra-MODE ablations use: on a two-colour synthetic picture the palette | |
| 731 | + /// codes every block losslessly, so both arms of a mode ablation reach | |
| 732 | + /// infinite PSNR and the ablation measures nothing at all (the | |
| 733 | + /// `fixture-proves-the-symbol-not-the-signal` class). An environment | |
| 734 | + /// variable cannot do this -- the tests run in one process, in parallel. | |
| 735 | + static SCREEN_FORCE: std::cell::Cell<Option<bool>> = const { std::cell::Cell::new(None) }; | |
| 736 | +} | |
| 737 | + | |
| 738 | +#[cfg(test)] | |
| 739 | +pub(crate) fn force_screen(value: Option<bool>) { | |
| 740 | + SCREEN_FORCE.with(|c| c.set(value)); | |
| 741 | +} | |
| 742 | + | |
| 728 | 743 | pub(crate) fn arm_seq_screen(on: bool) { |
| 729 | 744 | SEQ_SCREEN.with(|c| c.set(on)); |
| 730 | 745 | } |
| @@ -776,6 +791,10 @@ pub(crate) static SCREEN_FRAMES: [std::sync::atomic::AtomicUsize; 2] = | ||
| 776 | 791 | /// cover more than a [`screen_pct`]th of the frame. `width` is the plane's |
| 777 | 792 | /// stride, `true_*` the frame's real (decodable) extent. |
| 778 | 793 | fn screen_content(y: &[u8], width: usize, true_width: usize, true_height: usize) -> bool { |
| 794 | + if let Some(forced) = SCREEN_FORCE.with(std::cell::Cell::get) { | |
| 795 | + SCREEN_FRAMES[usize::from(forced)].fetch_add(1, std::sync::atomic::Ordering::Relaxed); | |
| 796 | + return forced; | |
| 797 | + } | |
| 779 | 798 | if let Ok(v) = std::env::var("EC_AV1_SCREEN") { |
| 780 | 799 | let on = v != "0"; |
| 781 | 800 | SCREEN_FRAMES[usize::from(on)].fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| @@ -6792,6 +6811,10 @@ mod tests { | ||
| 6792 | 6811 | /// A ladder of (luma PSNR, log10 bytes) for one mode set, ordered by |
| 6793 | 6812 | /// fidelity. |
| 6794 | 6813 | fn ladder(picture: &Picture, modes: &[u8], fctx: &crate::decode::FrameCtx) -> Vec<(f64, f64)> { |
| 6814 | + // A mode ablation measures the MODE search: the palette would code | |
| 6815 | + // these synthetic two-colour pictures losslessly under every arm and | |
| 6816 | + // leave nothing to compare (see [`force_screen`]). | |
| 6817 | + force_screen(Some(false)); | |
| 6795 | 6818 | let mut points: Vec<(f64, f64)> = [110u8, 90, 70] |
| 6796 | 6819 | .iter() |
| 6797 | 6820 | .map(|&q| { |
| @@ -6904,6 +6927,10 @@ mod tests { | ||
| 6904 | 6927 | /// The mode picked by the most blocks of a picture, ignoring the first |
| 6905 | 6928 | /// block, which has no neighbours to tell the modes apart with. |
| 6906 | 6929 | fn favourite_mode(picture: &Picture, fctx: &crate::decode::FrameCtx) -> (u8, usize, usize) { |
| 6930 | + // A mode ablation measures the MODE search: the palette would code | |
| 6931 | + // these synthetic two-colour pictures losslessly under every arm and | |
| 6932 | + // leave nothing to compare (see [`force_screen`]). | |
| 6933 | + force_screen(Some(false)); | |
| 6907 | 6934 | let encoded = encode_key_frame_with_ctx(picture, 100, 0.5, fctx).unwrap(); |
| 6908 | 6935 | let blocks = &encoded.modes[1..]; |
| 6909 | 6936 | let mut counts = [0usize; 13]; |