Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
raea check's flashing screen is a crate of its own, raea-app-check-flash, so the check has room for #89's fixes
shinyobjectz2b8b43a4205d
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 43e4e491..1f073eb9 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -116,4 +116,4 @@ jobs:# debug info off: with it the test binaries of the app crates filled 27 GB of a runner's disk (#90)env:CARGO_PROFILE_TEST_DEBUG: "0"- run: cargo test --locked -p raea-io-media -p raea-core-fonts -p raea-native -p raea-core-brief -p raea-core-k -p raea-bundle -p raea-app-check -p raea-app-workspace -p raea-app-tools -p raea-app-targets+ run: cargo test --locked -p raea-io-media -p raea-core-fonts -p raea-native -p raea-core-brief -p raea-core-k -p raea-bundle -p raea-app-check -p raea-app-check-flash -p raea-app-workspace -p raea-app-tools -p raea-app-targetsdiff --git a/Cargo.lock b/Cargo.lockindex e532e9e2..d0505b4c 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -13615,6 +13615,7 @@ dependencies = [name = "raea-app-check"version = "0.1.0"dependencies = [+ "raea-app-check-flash","raea-core-brief","raea-core-facts","raea-io-trace",@@ -13622,6 +13623,10 @@ dependencies = ["serde_json",]+[[package]]+name = "raea-app-check-flash"+version = "0.1.0"+[[package]]name = "raea-app-ci"version = "0.1.0"diff --git a/Cargo.toml b/Cargo.tomlindex 214abb9a..132a50ab 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -156,6 +156,7 @@ members = ["runtime/scene2d","runtime/shared","apps/check",+ "apps/check/flash","apps/direction","apps/notes","apps/sound",diff --git a/apps/check/Cargo.toml b/apps/check/Cargo.tomlindex 1d65d447..b6ebae0f 100644--- a/apps/check/Cargo.toml+++ b/apps/check/Cargo.toml@@ -15,4 +15,6 @@ raea-core-facts = { path = "../../core/facts" }raea-io-trace = { path = "../../io/trace" }# caption contrast and loudness, measured as `raea world` measures a render (DR2)raea-sys-measure = { path = "../../systems/measure" }+# the flashing screen (WCAG 2.3.1), split out to keep this crate small+raea-app-check-flash = { path = "flash" }serde_json = "1"diff --git a/apps/check/flash/Cargo.toml b/apps/check/flash/Cargo.tomlnew file mode 100644index 00000000..0443ac41--- /dev/null+++ b/apps/check/flash/Cargo.toml@@ -0,0 +1,7 @@+[package]+name = "raea-app-check-flash"+version = "0.1.0"+edition = "2024"+license = "FSL-1.1-ALv2"+publish = false+description = "`raea check`'s flashing screen (WCAG 2.3.1): opposing swings in a frame's windows, from decoded RGB"diff --git a/apps/check/flash/src/lib.rs b/apps/check/flash/src/lib.rsnew file mode 100644index 00000000..c4bc6030--- /dev/null+++ b/apps/check/flash/src/lib.rs@@ -0,0 +1,232 @@+//! The flashing screen behind `raea check` (apps/check flash.rs feeds it the decoded frames): a pure measure of pixels,+//! in a crate of its own so the check stays small (tools/size.sh).++/// Flashing past WCAG 2.3.1: more than three flashes in any one second, over enough of the frame to matter. A flash is a+/// pair of opposing changes in the same pixels, so a shape sliding past isn't one. Each window, a third of the frame wide+/// and high, stands in for WCAG's quarter of a 10-degree field (the real area depends on the screen and how far away it+/// is, which a file doesn't say), and a quarter of its pixels must swing together: by 0.10 relative luminance with the+/// darker end under 0.80, or by 20 of saturated red ((R-G-B)*320, where R/(R+G+B) is at least 0.8). Every decoded frame+/// counts, on its own timestamp, and the picture is sampled twice, by area and by point, so fine patterns don't average+/// away. A screen for review, not a Harding or PEAT certification; an interlaced picture isn't split into its fields.+const FLASH_MOST: usize = 6;+const FLASH_PAIR_S: f64 = 1.0 + 1e-9;++/// A pixel in one measure: its value, and whether it can count. Red's value runs on through the saturation line, and a change+/// counts when either end of it is saturated; a one-level step across the line isn't a jump from zero.+#[derive(Clone, Copy)]+struct Px {+ value: f32,+ counts: bool,+}++struct Swing {+ at: f64,+ direction: f32,+ moved: Vec<bool>,+ plain: bool,+ kept: bool,+}++/// One window's swings in one measure: the ones an opposite swing within a second moves back in the same pixels. The+/// general measure leaves out swings where another quarter of the window moved the other way at once (a moving pattern).+struct Swings {+ by: f32,+ under: f32,+ mixed_counts: bool,+ pivot: Vec<Px>,+ extreme: Vec<Px>,+ at: f64,+ direction: f32,+ recent: std::collections::VecDeque<Swing>,+ ends: Vec<f64>,+}++impl Swings {+ fn new(by: f32, under: f32, mixed_counts: bool) -> Swings {+ Swings { by, under, mixed_counts, pivot: Vec::new(), extreme: Vec::new(), at: 0.0, direction: 0.0, recent: Default::default(), ends: Vec::new() }+ }++ fn moves(&self, a: Px, b: Px, direction: f32) -> bool {+ (b.value - a.value) * direction >= self.by && a.value.min(b.value) < self.under && (a.counts || b.counts)+ }++ fn changed(&self, earlier: &[Px], later: &[Px], direction: f32) -> bool {+ earlier.iter().zip(later).filter(|(a, b)| self.moves(**a, **b, direction)).count() * 4 >= earlier.len()+ }++ fn push(&mut self, t: f64, px: &[Px]) {+ if self.pivot.is_empty() {+ self.pivot = px.to_vec();+ self.extreme = px.to_vec();+ self.at = t;+ return;+ }+ if self.direction == 0.0 {+ for direction in [1.0, -1.0] {+ if self.changed(&self.pivot, px, direction) {+ self.direction = direction;+ self.extreme = px.to_vec();+ self.at = t;+ break;+ }+ }+ return;+ }+ if self.changed(&self.extreme, px, -self.direction) {+ self.record();+ self.pivot = std::mem::replace(&mut self.extreme, px.to_vec());+ self.at = t;+ self.direction = -self.direction;+ } else if self.changed(&self.pivot, px, self.direction) && self.went_further(px) {+ self.extreme = px.to_vec();+ }+ }++ /// Whether the pixels swinging from the pivot went further than the saved extreme, judged on those pixels alone: the+ /// rest of the window can dim by less than counts and still outweigh a patch that's flashing.+ fn went_further(&self, px: &[Px]) -> bool {+ let further: f32 = self.pivot.iter().zip(px).zip(&self.extreme).filter(|((p, n), _)| self.moves(**p, **n, self.direction)).map(|((_, n), e)| (n.value - e.value) * self.direction).sum();+ further > 0.0+ }++ fn record(&mut self) {+ if !self.changed(&self.pivot, &self.extreme, self.direction) {+ return;+ }+ let moved: Vec<bool> = self.pivot.iter().zip(&self.extreme).map(|(a, b)| self.moves(*a, *b, self.direction)).collect();+ let plain = self.mixed_counts || !self.changed(&self.pivot, &self.extreme, -self.direction);+ let (at, direction) = (self.at, self.direction);+ let mut kept = false;+ for other in self.recent.iter_mut().rev() {+ if at - other.at > FLASH_PAIR_S {+ break;+ }+ let same = moved.iter().zip(&other.moved).filter(|(x, y)| **x && **y).count();+ if other.direction == -direction && same * 4 >= moved.len() {+ other.kept = true;+ kept = true;+ }+ }+ self.recent.push_back(Swing { at, direction, moved, plain, kept });+ while self.recent.front().is_some_and(|s| at - s.at > FLASH_PAIR_S) {+ self.retire();+ }+ }++ /// The oldest swing leaves the second it could still pair within; only the seconds' ends are kept for good.+ fn retire(&mut self) {+ if let Some(s) = self.recent.pop_front()+ && s.plain+ && s.kept+ {+ self.ends.push(s.at);+ }+ }++ /// The most swings in any one second, and when that second starts.+ fn busiest(&mut self) -> (usize, f64) {+ if self.direction != 0.0 {+ self.record();+ self.direction = 0.0;+ }+ while !self.recent.is_empty() {+ self.retire();+ }+ self.ends.sort_by(f64::total_cmp);+ let (mut best, mut from, mut j) = (0, 0.0, 0);+ for i in 0..self.ends.len() {+ while self.ends[i] - self.ends[j] >= 1.0 - 1e-9 {+ j += 1;+ }+ if i - j + 1 > best {+ (best, from) = (i - j + 1, self.ends[j]);+ }+ }+ (best, from)+ }+}++/// Frames of two pictures side by side, each `w` by `h` RGB: the area sample and the point sample of one frame.+pub struct FlashScreen {+ w: usize,+ h: usize,+ last: Vec<u8>,+ linear: Vec<f32>,+ luma: Vec<Px>,+ red: Vec<Px>,+ cut: Vec<Px>,+ windows: Vec<(usize, usize, Swings, Swings)>,+}++impl FlashScreen {+ pub fn new(w: usize, h: usize) -> FlashScreen {+ let (ww, wh) = (w / 3, h / 3);+ let places = |size: usize, window: usize| {+ let mut at: Vec<usize> = (0..=size - window).step_by((size / 6).max(1)).collect();+ at.push(size - window);+ at.dedup();+ at+ };+ let mut windows = Vec::new();+ for sample in 0..2 {+ for &y in &places(h, wh) {+ for &x in &places(w, ww) {+ windows.push((x + sample * w, y, Swings::new(0.10, 0.80, false), Swings::new(20.0, f32::INFINITY, true)));+ }+ }+ }+ let linear = (0..=255u32)+ .map(|c| {+ let c = c as f32 / 255.0;+ if c <= 0.04045 { c / 12.92 } else { ((c + 0.055) / 1.055).powf(2.4) }+ })+ .collect();+ FlashScreen { w, h, last: Vec::new(), linear, luma: Vec::new(), red: Vec::new(), cut: Vec::new(), windows }+ }++ pub fn push(&mut self, rgb: &[u8], t: f64) {+ if rgb == self.last {+ return;+ }+ self.luma.clear();+ self.red.clear();+ for px in rgb.chunks_exact(3) {+ let (r, g, b) = (self.linear[px[0] as usize], self.linear[px[1] as usize], self.linear[px[2] as usize]);+ self.luma.push(Px { value: 0.2126 * r + 0.7152 * g + 0.0722 * b, counts: true });+ let sum = r + g + b + 1e-9;+ self.red.push(Px { value: ((r - g - b) * 320.0).max(0.0), counts: r / sum >= 0.8 });+ }+ let (stride, ww, wh) = (self.w * 2, self.w / 3, self.h / 3);+ for (x, y, general, saturated) in &mut self.windows {+ self.cut.clear();+ for r in 0..wh {+ self.cut.extend_from_slice(&self.luma[(*y + r) * stride + *x..][..ww]);+ }+ general.push(t, &self.cut);+ self.cut.clear();+ for r in 0..wh {+ self.cut.extend_from_slice(&self.red[(*y + r) * stride + *x..][..ww]);+ }+ saturated.push(t, &self.cut);+ }+ self.last.clear();+ self.last.extend_from_slice(rgb);+ }++ /// (swings in the worst second, when it starts, which measure) when past the limit+ pub fn finish(mut self) -> Option<(usize, f64, &'static str)> {+ let mut worst: Option<(usize, f64, &'static str)> = None;+ for (_, _, general, saturated) in &mut self.windows {+ for (swings, kind) in [(general, "general"), (saturated, "red")] {+ let (n, from) = swings.busiest();+ if n > FLASH_MOST && worst.is_none_or(|w| n > w.0) {+ worst = Some((n, from, kind));+ }+ }+ }+ worst+ }+}++#[cfg(test)]+mod tests;diff --git a/apps/check/flash/src/tests.rs b/apps/check/flash/src/tests.rsnew file mode 100644index 00000000..cbf5175c--- /dev/null+++ b/apps/check/flash/src/tests.rs@@ -0,0 +1,100 @@+use super::*;++/// a 96x54 picture drawn by `paint(frame index, sample, x, y)`, sample 0 the area sample and 1 the point sample, for+/// `frames` frames at `fps`+fn flash_samples(frames: usize, fps: f64, paint: impl Fn(usize, usize, usize, usize) -> [u8; 3]) -> Option<(usize, f64, &'static str)> {+ let (w, h) = (96, 54);+ let mut screen = FlashScreen::new(w, h);+ for f in 0..frames {+ let mut rgb = Vec::with_capacity(w * 2 * h * 3);+ for y in 0..h {+ for sample in 0..2 {+ for x in 0..w {+ rgb.extend_from_slice(&paint(f, sample, x, y));+ }+ }+ }+ screen.push(&rgb, f as f64 / fps);+ }+ screen.finish()+}++fn flash_of(seconds: usize, paint: impl Fn(usize, usize, usize) -> [u8; 3]) -> Option<(usize, f64, &'static str)> {+ flash_samples(seconds * 60, 60.0, move |f, _, x, y| paint(f, x, y))+}++/// two colours taking turns `hz` times a second, over a box of the frame+fn turns(hz: usize, on: [u8; 3], off: [u8; 3], bx: (usize, usize, usize, usize)) -> Option<(usize, f64, &'static str)> {+ flash_of(3, move |f, x, y| {+ let inside = x >= bx.0 && x < bx.0 + bx.2 && y >= bx.1 && y < bx.1 + bx.3;+ if inside && f * hz * 2 / 60 % 2 == 0 { on } else { off }+ })+}++#[test]+fn flashing_is_found_past_three_a_second_and_not_at_it() {+ let (white, black) = ([255, 255, 255], [0, 0, 0]);+ let all = (0, 0, 96, 54);+ assert_eq!(turns(3, white, black, all), None, "three a second is the limit, not past it");+ let (swings, _, kind) = turns(4, white, black, all).expect("four a second");+ assert_eq!((swings / 2, kind), (4, "general"));+ // a small box: under a quarter of any window, and then over it+ assert_eq!(turns(5, white, black, (40, 20, 10, 10)), None);+ assert!(turns(5, white, black, (30, 18, 32, 18)).is_some());+ // too small a change, and both ends too bright for WCAG to count it+ assert_eq!(turns(5, [60, 60, 60], [30, 30, 30], all), None);+ assert_eq!(turns(5, [255, 255, 255], [235, 235, 235], all), None);+ // a dark saturated red: too dim to count as a general flash, past the limit as a red one+ assert_eq!(turns(5, [150, 0, 0], black, all).map(|t| t.2), Some("red"));+}++#[test]+fn a_flash_of_single_frames_counts_at_any_frame_rate() {+ // 120 fps with one white frame in every 30: four flashes a second, each gone within a sixtieth of a second+ let found = flash_samples(360, 120.0, |f, _, _, _| if f % 30 == 1 { [255, 255, 255] } else { [0, 0, 0] });+ assert_eq!(found.map(|(swings, _, kind)| (swings / 2, kind)), Some((4, "general")));+}++#[test]+fn a_flash_the_area_sample_averages_away_is_found_in_the_point_sample() {+ let found = flash_samples(180, 60.0, |f, sample, _, _| {+ if sample == 0 {+ return [128, 128, 128];+ }+ if f * 5 * 2 / 60 % 2 == 0 { [255, 255, 255] } else { [0, 0, 0] }+ });+ assert!(found.is_some(), "the same flash in the point sample alone");+}+++#[test]+fn a_shape_sliding_past_and_ordinary_cuts_are_not_flashing() {+ let (white, black) = ([255, 255, 255], [0, 0, 0]);+ assert_eq!(flash_of(3, move |f, x, _| if x < f { white } else { black }), None, "one wipe across the frame");+ assert_eq!(flash_of(4, move |f, _, _| if (f / 30) % 2 == 0 { white } else { black }), None, "a cut every half second");+}++#[test]+fn a_patch_strobing_while_its_background_dims_is_still_found() {+ // a third of a window: 0 then 124 on a 148 background, then the background settles at 124 and the patch cycles 124 and 160.+ // The background's drop is under the 0.10 that counts, but it outweighs the patch in the window's mean.+ let found = flash_samples(180, 60.0, |f, _, x, y| {+ let patch = x < 16 && y < 12;+ let level = match (patch, f) {+ (true, 0) => 0,+ (true, 1) => 124,+ (true, _) => if (f - 2) * 5 * 2 / 60 % 2 == 0 { 160 } else { 124 },+ (false, 0 | 1) => 148,+ (false, _) => 124,+ };+ [level, level, level]+ });+ assert!(found.is_some(), "the patch flashes five times a second");+}++#[test]+fn a_colour_crossing_the_saturation_line_is_not_a_red_flash() {+ // one level of green moves the pixel across R/(R+G+B) = 0.8 and hardly changes its red at all+ let found = flash_samples(180, 60.0, |f, _, _, _| if f * 5 * 2 / 60 % 2 == 0 { [100, 49, 0] } else { [100, 50, 0] });+ assert_eq!(found, None);+}diff --git a/apps/check/src/flash.rs b/apps/check/src/flash.rsindex 092dba14..3a79f9a1 100644--- a/apps/check/src/flash.rs+++ b/apps/check/src/flash.rs@@ -1,232 +1,9 @@use super::*;+use raea_app_check_flash::FlashScreen;-/// Flashing past WCAG 2.3.1: more than three flashes in any one second, over enough of the frame to matter. A flash is a-/// pair of opposing changes in the same pixels, so a shape sliding past isn't one. Each window, a third of the frame wide-/// and high, stands in for WCAG's quarter of a 10-degree field (the real area depends on the screen and how far away it-/// is, which a file doesn't say), and a quarter of its pixels must swing together: by 0.10 relative luminance with the-/// darker end under 0.80, or by 20 of saturated red ((R-G-B)*320, where R/(R+G+B) is at least 0.8). Every decoded frame-/// counts, on its own timestamp, and the picture is sampled twice, by area and by point, so fine patterns don't average-/// away. A screen for review, not a Harding or PEAT certification; an interlaced picture isn't split into its fields.+/// The width each frame is decoded at for the flashing screen (raea-app-check-flash: its rule and its windows), twice over:+/// the area sample and the point sample side by sideconst FLASH_W: usize = 192;-const FLASH_MOST: usize = 6;-const FLASH_PAIR_S: f64 = 1.0 + 1e-9;--/// A pixel in one measure: its value, and whether it can count. Red's value runs on through the saturation line, and a change-/// counts when either end of it is saturated; a one-level step across the line isn't a jump from zero.-#[derive(Clone, Copy)]-struct Px {- value: f32,- counts: bool,-}--struct Swing {- at: f64,- direction: f32,- moved: Vec<bool>,- plain: bool,- kept: bool,-}--/// One window's swings in one measure: the ones an opposite swing within a second moves back in the same pixels. The-/// general measure leaves out swings where another quarter of the window moved the other way at once (a moving pattern).-struct Swings {- by: f32,- under: f32,- mixed_counts: bool,- pivot: Vec<Px>,- extreme: Vec<Px>,- at: f64,- direction: f32,- recent: std::collections::VecDeque<Swing>,- ends: Vec<f64>,-}--impl Swings {- fn new(by: f32, under: f32, mixed_counts: bool) -> Swings {- Swings { by, under, mixed_counts, pivot: Vec::new(), extreme: Vec::new(), at: 0.0, direction: 0.0, recent: Default::default(), ends: Vec::new() }- }-- fn moves(&self, a: Px, b: Px, direction: f32) -> bool {- (b.value - a.value) * direction >= self.by && a.value.min(b.value) < self.under && (a.counts || b.counts)- }-- fn changed(&self, earlier: &[Px], later: &[Px], direction: f32) -> bool {- earlier.iter().zip(later).filter(|(a, b)| self.moves(**a, **b, direction)).count() * 4 >= earlier.len()- }-- fn push(&mut self, t: f64, px: &[Px]) {- if self.pivot.is_empty() {- self.pivot = px.to_vec();- self.extreme = px.to_vec();- self.at = t;- return;- }- if self.direction == 0.0 {- for direction in [1.0, -1.0] {- if self.changed(&self.pivot, px, direction) {- self.direction = direction;- self.extreme = px.to_vec();- self.at = t;- break;- }- }- return;- }- if self.changed(&self.extreme, px, -self.direction) {- self.record();- self.pivot = std::mem::replace(&mut self.extreme, px.to_vec());- self.at = t;- self.direction = -self.direction;- } else if self.changed(&self.pivot, px, self.direction) && self.went_further(px) {- self.extreme = px.to_vec();- }- }-- /// Whether the pixels swinging from the pivot went further than the saved extreme, judged on those pixels alone: the- /// rest of the window can dim by less than counts and still outweigh a patch that's flashing.- fn went_further(&self, px: &[Px]) -> bool {- let further: f32 = self.pivot.iter().zip(px).zip(&self.extreme).filter(|((p, n), _)| self.moves(**p, **n, self.direction)).map(|((_, n), e)| (n.value - e.value) * self.direction).sum();- further > 0.0- }-- fn record(&mut self) {- if !self.changed(&self.pivot, &self.extreme, self.direction) {- return;- }- let moved: Vec<bool> = self.pivot.iter().zip(&self.extreme).map(|(a, b)| self.moves(*a, *b, self.direction)).collect();- let plain = self.mixed_counts || !self.changed(&self.pivot, &self.extreme, -self.direction);- let (at, direction) = (self.at, self.direction);- let mut kept = false;- for other in self.recent.iter_mut().rev() {- if at - other.at > FLASH_PAIR_S {- break;- }- let same = moved.iter().zip(&other.moved).filter(|(x, y)| **x && **y).count();- if other.direction == -direction && same * 4 >= moved.len() {- other.kept = true;- kept = true;- }- }- self.recent.push_back(Swing { at, direction, moved, plain, kept });- while self.recent.front().is_some_and(|s| at - s.at > FLASH_PAIR_S) {- self.retire();- }- }-- /// The oldest swing leaves the second it could still pair within; only the seconds' ends are kept for good.- fn retire(&mut self) {- if let Some(s) = self.recent.pop_front()- && s.plain- && s.kept- {- self.ends.push(s.at);- }- }-- /// The most swings in any one second, and when that second starts.- fn busiest(&mut self) -> (usize, f64) {- if self.direction != 0.0 {- self.record();- self.direction = 0.0;- }- while !self.recent.is_empty() {- self.retire();- }- self.ends.sort_by(f64::total_cmp);- let (mut best, mut from, mut j) = (0, 0.0, 0);- for i in 0..self.ends.len() {- while self.ends[i] - self.ends[j] >= 1.0 - 1e-9 {- j += 1;- }- if i - j + 1 > best {- (best, from) = (i - j + 1, self.ends[j]);- }- }- (best, from)- }-}--/// Frames of two pictures side by side, each `w` by `h` RGB: the area sample and the point sample of one frame.-pub(crate) struct FlashScreen {- w: usize,- h: usize,- last: Vec<u8>,- linear: Vec<f32>,- luma: Vec<Px>,- red: Vec<Px>,- cut: Vec<Px>,- windows: Vec<(usize, usize, Swings, Swings)>,-}--impl FlashScreen {- pub(crate) fn new(w: usize, h: usize) -> FlashScreen {- let (ww, wh) = (w / 3, h / 3);- let places = |size: usize, window: usize| {- let mut at: Vec<usize> = (0..=size - window).step_by((size / 6).max(1)).collect();- at.push(size - window);- at.dedup();- at- };- let mut windows = Vec::new();- for sample in 0..2 {- for &y in &places(h, wh) {- for &x in &places(w, ww) {- windows.push((x + sample * w, y, Swings::new(0.10, 0.80, false), Swings::new(20.0, f32::INFINITY, true)));- }- }- }- let linear = (0..=255u32)- .map(|c| {- let c = c as f32 / 255.0;- if c <= 0.04045 { c / 12.92 } else { ((c + 0.055) / 1.055).powf(2.4) }- })- .collect();- FlashScreen { w, h, last: Vec::new(), linear, luma: Vec::new(), red: Vec::new(), cut: Vec::new(), windows }- }-- pub(crate) fn push(&mut self, rgb: &[u8], t: f64) {- if rgb == self.last {- return;- }- self.luma.clear();- self.red.clear();- for px in rgb.chunks_exact(3) {- let (r, g, b) = (self.linear[px[0] as usize], self.linear[px[1] as usize], self.linear[px[2] as usize]);- self.luma.push(Px { value: 0.2126 * r + 0.7152 * g + 0.0722 * b, counts: true });- let sum = r + g + b + 1e-9;- self.red.push(Px { value: ((r - g - b) * 320.0).max(0.0), counts: r / sum >= 0.8 });- }- let (stride, ww, wh) = (self.w * 2, self.w / 3, self.h / 3);- for (x, y, general, saturated) in &mut self.windows {- self.cut.clear();- for r in 0..wh {- self.cut.extend_from_slice(&self.luma[(*y + r) * stride + *x..][..ww]);- }- general.push(t, &self.cut);- self.cut.clear();- for r in 0..wh {- self.cut.extend_from_slice(&self.red[(*y + r) * stride + *x..][..ww]);- }- saturated.push(t, &self.cut);- }- self.last.clear();- self.last.extend_from_slice(rgb);- }-- /// (swings in the worst second, when it starts, which measure) when past the limit- pub(crate) fn finish(mut self) -> Option<(usize, f64, &'static str)> {- let mut worst: Option<(usize, f64, &'static str)> = None;- for (_, _, general, saturated) in &mut self.windows {- for (swings, kind) in [(general, "general"), (saturated, "red")] {- let (n, from) = swings.busiest();- if n > FLASH_MOST && worst.is_none_or(|w| n > w.0) {- worst = Some((n, from, kind));- }- }- }- worst- }-}/// Every decoded frame, once: -fps_mode from FFmpeg 5.1 on, -vsync before it.fn passthrough() -> [&'static str; 2] {diff --git a/apps/check/src/tests.rs b/apps/check/src/tests.rsindex 75999dd6..644cd892 100644--- a/apps/check/src/tests.rs+++ b/apps/check/src/tests.rs@@ -292,72 +292,6 @@ fn a_sign_the_camera_carries_off_isnt_clipped_but_a_title_held_off_is() {assert_eq!(rules, vec![("safe-area", "THE NIGHT MARKET".to_string()), ("clipped", "WIDE".to_string())]);}-/// a 96x54 picture drawn by `paint(frame index, sample, x, y)`, sample 0 the area sample and 1 the point sample, for-/// `frames` frames at `fps`-fn flash_samples(frames: usize, fps: f64, paint: impl Fn(usize, usize, usize, usize) -> [u8; 3]) -> Option<(usize, f64, &'static str)> {- let (w, h) = (96, 54);- let mut screen = FlashScreen::new(w, h);- for f in 0..frames {- let mut rgb = Vec::with_capacity(w * 2 * h * 3);- for y in 0..h {- for sample in 0..2 {- for x in 0..w {- rgb.extend_from_slice(&paint(f, sample, x, y));- }- }- }- screen.push(&rgb, f as f64 / fps);- }- screen.finish()-}--fn flash_of(seconds: usize, paint: impl Fn(usize, usize, usize) -> [u8; 3]) -> Option<(usize, f64, &'static str)> {- flash_samples(seconds * 60, 60.0, move |f, _, x, y| paint(f, x, y))-}--/// two colours taking turns `hz` times a second, over a box of the frame-fn turns(hz: usize, on: [u8; 3], off: [u8; 3], bx: (usize, usize, usize, usize)) -> Option<(usize, f64, &'static str)> {- flash_of(3, move |f, x, y| {- let inside = x >= bx.0 && x < bx.0 + bx.2 && y >= bx.1 && y < bx.1 + bx.3;- if inside && f * hz * 2 / 60 % 2 == 0 { on } else { off }- })-}--#[test]-fn flashing_is_found_past_three_a_second_and_not_at_it() {- let (white, black) = ([255, 255, 255], [0, 0, 0]);- let all = (0, 0, 96, 54);- assert_eq!(turns(3, white, black, all), None, "three a second is the limit, not past it");- let (swings, _, kind) = turns(4, white, black, all).expect("four a second");- assert_eq!((swings / 2, kind), (4, "general"));- // a small box: under a quarter of any window, and then over it- assert_eq!(turns(5, white, black, (40, 20, 10, 10)), None);- assert!(turns(5, white, black, (30, 18, 32, 18)).is_some());- // too small a change, and both ends too bright for WCAG to count it- assert_eq!(turns(5, [60, 60, 60], [30, 30, 30], all), None);- assert_eq!(turns(5, [255, 255, 255], [235, 235, 235], all), None);- // a dark saturated red: too dim to count as a general flash, past the limit as a red one- assert_eq!(turns(5, [150, 0, 0], black, all).map(|t| t.2), Some("red"));-}--#[test]-fn a_flash_of_single_frames_counts_at_any_frame_rate() {- // 120 fps with one white frame in every 30: four flashes a second, each gone within a sixtieth of a second- let found = flash_samples(360, 120.0, |f, _, _, _| if f % 30 == 1 { [255, 255, 255] } else { [0, 0, 0] });- assert_eq!(found.map(|(swings, _, kind)| (swings / 2, kind)), Some((4, "general")));-}--#[test]-fn a_flash_the_area_sample_averages_away_is_found_in_the_point_sample() {- let found = flash_samples(180, 60.0, |f, sample, _, _| {- if sample == 0 {- return [128, 128, 128];- }- if f * 5 * 2 / 60 % 2 == 0 { [255, 255, 255] } else { [0, 0, 0] }- });- assert!(found.is_some(), "the same flash in the point sample alone");-}-#[test]fn a_frame_gets_its_exact_time_from_the_log() {// lines FFmpeg 9.0.2 logged with -loglevel level+info@@ -382,37 +316,6 @@ fn only_a_lines_own_severity_counts_as_an_error() {assert_eq!(log_level("frame= 300 fps=0.0"), None);}-#[test]-fn a_shape_sliding_past_and_ordinary_cuts_are_not_flashing() {- let (white, black) = ([255, 255, 255], [0, 0, 0]);- assert_eq!(flash_of(3, move |f, x, _| if x < f { white } else { black }), None, "one wipe across the frame");- assert_eq!(flash_of(4, move |f, _, _| if (f / 30) % 2 == 0 { white } else { black }), None, "a cut every half second");-}--#[test]-fn a_patch_strobing_while_its_background_dims_is_still_found() {- // a third of a window: 0 then 124 on a 148 background, then the background settles at 124 and the patch cycles 124 and 160.- // The background's drop is under the 0.10 that counts, but it outweighs the patch in the window's mean.- let found = flash_samples(180, 60.0, |f, _, x, y| {- let patch = x < 16 && y < 12;- let level = match (patch, f) {- (true, 0) => 0,- (true, 1) => 124,- (true, _) => if (f - 2) * 5 * 2 / 60 % 2 == 0 { 160 } else { 124 },- (false, 0 | 1) => 148,- (false, _) => 124,- };- [level, level, level]- });- assert!(found.is_some(), "the patch flashes five times a second");-}--#[test]-fn a_colour_crossing_the_saturation_line_is_not_a_red_flash() {- // one level of green moves the pixel across R/(R+G+B) = 0.8 and hardly changes its red at all- let found = flash_samples(180, 60.0, |f, _, _, _| if f * 5 * 2 / 60 % 2 == 0 { [100, 49, 0] } else { [100, 50, 0] });- assert_eq!(found, None);-}/// A centred line in a left: 0; right: 0 box isn't in the left zone: its letters are tested where the render recorded/// them (#89); a left-aligned one is, the finding naming the edge, and a manifest without ink is tested by the box.diff --git a/engine/render/src/engine/open.rs b/engine/render/src/engine/open.rsindex b5daf6a2..14cf203d 100644--- a/engine/render/src/engine/open.rs+++ b/engine/render/src/engine/open.rs@@ -43,10 +43,9 @@ impl Engine {let mut app = App::new();let group = DefaultPlugins.set(WindowPlugin { primary_window: None, exit_condition: ExitCondition::DontExit, close_when_requested: false, ..default() })- // quiet on a good run: bevy_log's "Could not set global logger" (raea_io_trace owns `log` in a play- // or a render, and its records go there, as meant) and a pass-timing readback that missed a frame- // (RenderDiagnosticsPlugin's "Failed to download render statistics buffer": one second's bevy_passes lost)- // and bevy_time's "did not receive the time from the render world" (raea steps Time by frame)+ // quiet on a good run: bevy_log's "Could not set global logger" (raea_io_trace owns `log` in a play or a render, and its+ // records go there, as meant), a pass-timing readback that missed a frame (RenderDiagnosticsPlugin's "Failed to download render+ // statistics buffer": one second's bevy_passes lost) and bevy_time's "did not receive the time from the render world" (raea steps Time by frame).set(bevy::log::LogPlugin { level: bevy::log::Level::WARN, filter: format!("{}bevy_log=off,bevy_asset::io::web=error,bevy_asset::io::source=error,fontdb=error,bevy_render::diagnostic::internal=error,bevy_time=error", bevy::log::DEFAULT_FILTER), ..default() })// glTF models (scene3d) load from the paths their rows name, which are the edit's files wherever they are.// Hot reload (Bevy's file_watcher, in the bevy-all build) only when asked, RAEA_BEVY_WATCH=1: a render or adiff --git a/tools/layers.toml b/tools/layers.tomlindex 90d7a550..5b9023ba 100644--- a/tools/layers.toml+++ b/tools/layers.toml@@ -144,6 +144,7 @@ raea-runtime-scene2d = "runtime"raea-runtime-shared = "runtime"raea-page = "runtime"raea-app-check = "apps"+raea-app-check-flash = "apps"raea-app-direction = "apps"raea-app-notes = "apps"raea-app-sound = "apps"