mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-06 05:33:38 -10:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0134c591c3 |
No files matched your search
@@ -223,13 +223,15 @@ pub(crate) fn contrast(video: &str, runs: &[Run], w: f64, h: f64, probe: &Probe,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// the same measure `raea world` joins to a text from its render (raea-sys-measure, DR2)
|
// the same measure `raea world` joins to a text from its render (raea-sys-measure, DR2)
|
||||||
let color = r.middle_color();
|
// each colour its words are drawn in (an accent word's beside the line's), held to the lowest
|
||||||
let ratio = if crate::read::native() { crate::read::contrast(video, t, crop, color) } else { raea_sys_measure::contrast(std::path::Path::new(video), t, crop, color) };
|
let measure = |color: &str| if crate::read::native() { crate::read::contrast(video, t, crop, color) } else { raea_sys_measure::contrast(std::path::Path::new(video), t, crop, color) };
|
||||||
let Some(ratio) = ratio else { continue };
|
let worst = r.middle_inks().into_iter().filter_map(|c| measure(c).map(|v| (v, c))).min_by(|a, b| a.0.total_cmp(&b.0));
|
||||||
|
let Some((ratio, color)) = worst else { continue };
|
||||||
|
let word = if color == r.middle_color() { String::new() } else { format!(" (its words in {color})") };
|
||||||
measured += 1;
|
measured += 1;
|
||||||
if ratio < 3.0 {
|
if ratio < 3.0 {
|
||||||
low += 1;
|
low += 1;
|
||||||
issues.push(Issue { rule: "contrast", p: 1, at: Some(t), says: format!("{} is {:.2}:1 against what's behind it; make it at least 3:1 (a band, a shadow for separation, or another colour)", quote(&r.text), (ratio * 100.0).floor() / 100.0) });
|
issues.push(Issue { rule: "contrast", p: 1, at: Some(t), says: format!("{}{word} is {:.2}:1 against what's behind it; make it at least 3:1 (a band, a shadow for separation, or another colour)", quote(&r.text), (ratio * 100.0).floor() / 100.0) });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if measured > 0 && low == 0 {
|
if measured > 0 && low == 0 {
|
||||||
|
|||||||
@@ -71,8 +71,8 @@ fn taste_checks_hold_text_to_the_persons_line() {
|
|||||||
Taste { form: "text-above", value: 62.0, line: "Captions sit clear of the bottom.".into() },
|
Taste { form: "text-above", value: 62.0, line: "Captions sit clear of the bottom.".into() },
|
||||||
Taste { form: "text-hold", value: 2.0, line: "Text holds two seconds".into() },
|
Taste { form: "text-hold", value: 2.0, line: "Text holds two seconds".into() },
|
||||||
]);
|
]);
|
||||||
let low = Run { text: "Render anything.".into(), from: 1.0, to: 4.0, box_: [800.0, 800.0, 300.0, 60.0], boxes: vec![[800.0, 800.0, 300.0, 60.0]], colors: vec![], color: String::new(), size: 48.0 };
|
let low = Run { text: "Render anything.".into(), from: 1.0, to: 4.0, box_: [800.0, 800.0, 300.0, 60.0], boxes: vec![[800.0, 800.0, 300.0, 60.0]], colors: vec![], inks: vec![], color: String::new(), size: 48.0 };
|
||||||
let high = Run { text: "raea".into(), from: 5.0, to: 6.0, box_: [800.0, 300.0, 300.0, 60.0], boxes: vec![[800.0, 300.0, 300.0, 60.0]], colors: vec![], color: String::new(), size: 48.0 };
|
let high = Run { text: "raea".into(), from: 5.0, to: 6.0, box_: [800.0, 300.0, 300.0, 60.0], boxes: vec![[800.0, 300.0, 300.0, 60.0]], colors: vec![], inks: vec![], color: String::new(), size: 48.0 };
|
||||||
let (mut issues, mut passed) = (vec![], vec![]);
|
let (mut issues, mut passed) = (vec![], vec![]);
|
||||||
taste_text(&rules, &[low, high], 1920.0, 1080.0, &mut issues, &mut passed);
|
taste_text(&rules, &[low, high], 1920.0, 1080.0, &mut issues, &mut passed);
|
||||||
let says: Vec<_> = issues.iter().map(|i| (i.rule, i.p, i.at)).collect();
|
let says: Vec<_> = issues.iter().map(|i| (i.rule, i.p, i.at)).collect();
|
||||||
@@ -268,7 +268,7 @@ fn typing_is_one_run_and_cues_find_their_word() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_caption_is_timed_from_the_first_word_it_shows() {
|
fn a_caption_is_timed_from_the_first_word_it_shows() {
|
||||||
let run = |text: &str, from: f64| Run { text: text.into(), from, to: from + 1.0, box_: [0.0; 4], boxes: vec![], colors: vec![], color: String::new(), size: 48.0 };
|
let run = |text: &str, from: f64| Run { text: text.into(), from, to: from + 1.0, box_: [0.0; 4], boxes: vec![], colors: vec![], inks: vec![], color: String::new(), size: 48.0 };
|
||||||
let words: Vec<Word> = [("half", 12.2), ("of", 12.66), ("the", 12.8), ("spend", 12.96)].iter().map(|(t, s)| Word { text: (*t).into(), start: *s, end: *s }).collect();
|
let words: Vec<Word> = [("half", 12.2), ("of", 12.66), ("the", 12.8), ("spend", 12.96)].iter().map(|(t, s)| Word { text: (*t).into(), start: *s, end: *s }).collect();
|
||||||
let (mut issues, mut passed) = (vec![], vec![]);
|
let (mut issues, mut passed) = (vec![], vec![]);
|
||||||
// on with "of": on time, though "spend" (its first word of weight) is said 0.3 s later
|
// on with "of": on time, though "spend" (its first word of weight) is said 0.3 s later
|
||||||
@@ -336,7 +336,7 @@ fn safe_area_tests_the_letters_not_the_box() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_card_sharing_one_word_with_another_line_isnt_held_to_it() {
|
fn a_card_sharing_one_word_with_another_line_isnt_held_to_it() {
|
||||||
let run = |text: &str, from: f64| Run { text: text.into(), from, to: from + 2.0, box_: [0.0; 4], boxes: vec![], colors: vec![], color: String::new(), size: 48.0 };
|
let run = |text: &str, from: f64| Run { text: text.into(), from, to: from + 2.0, box_: [0.0; 4], boxes: vec![], colors: vec![], inks: vec![], color: String::new(), size: 48.0 };
|
||||||
let said = |ws: &[(&str, f64)]| ws.iter().map(|(t, s)| Word { text: (*t).into(), start: *s, end: *s }).collect::<Vec<Word>>();
|
let said = |ws: &[(&str, f64)]| ws.iter().map(|(t, s)| Word { text: (*t).into(), start: *s, end: *s }).collect::<Vec<Word>>();
|
||||||
let words = said(&[("at", 37.9), ("wirestock", 38.2), ("i", 38.9), ("worked", 39.0), ("on", 39.2), ("a", 39.3), ("sora", 39.5), ("campaign", 40.2)]);
|
let words = said(&[("at", 37.9), ("wirestock", 38.2), ("i", 38.9), ("worked", 39.0), ("on", 39.2), ("a", 39.3), ("sora", 39.5), ("campaign", 40.2)]);
|
||||||
let (mut issues, mut passed) = (vec![], vec![]);
|
let (mut issues, mut passed) = (vec![], vec![]);
|
||||||
@@ -426,7 +426,7 @@ fn things_found_are_findings_and_an_unknown_rule_is_not() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn a_moving_text_is_read_where_it_is() {
|
fn a_moving_text_is_read_where_it_is() {
|
||||||
let ink = |f: usize| [56.7 + 4.0 * f as f64, 1000.0, 26.7, 40.0];
|
let ink = |f: usize| [56.7 + 4.0 * f as f64, 1000.0, 26.7, 40.0];
|
||||||
let run = Run { text: "E".into(), from: 0.0, to: 8.0, box_: [996.0, 1000.0, 60.0, 40.0], boxes: (0..240).map(ink).collect(), colors: vec![], color: String::new(), size: 40.0 };
|
let run = Run { text: "E".into(), from: 0.0, to: 8.0, box_: [996.0, 1000.0, 60.0, 40.0], boxes: (0..240).map(ink).collect(), colors: vec![], inks: vec![], color: String::new(), size: 40.0 };
|
||||||
let (t, b) = run.middle(30.0);
|
let (t, b) = run.middle(30.0);
|
||||||
assert_eq!(t, 4.0);
|
assert_eq!(t, 4.0);
|
||||||
assert!((b[0] - 520.0).abs() < 1e-9 && b[1..] == [1000.0, 60.0, 40.0], "{b:?}");
|
assert!((b[0] - 520.0).abs() < 1e-9 && b[1..] == [1000.0, 60.0, 40.0], "{b:?}");
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ pub struct Run {
|
|||||||
/// its colour on each of those frames, beside `boxes`: a text can change colour while it reads the same (a step
|
/// its colour on each of those frames, beside `boxes`: a text can change colour while it reads the same (a step
|
||||||
/// chip lighting up, grey on dark to dark on yellow), and its contrast is its colour on the frame it's measured at
|
/// chip lighting up, grey on dark to dark on yellow), and its contrast is its colour on the frame it's measured at
|
||||||
pub colors: Vec<String>,
|
pub colors: Vec<String>,
|
||||||
|
/// the colours its words are drawn in on each of those frames, beside `colors`, when any differs from the line's (the
|
||||||
|
/// manifest's `inks`: a caption's accent word); empty when every word is in the line's colour
|
||||||
|
pub inks: Vec<Vec<String>>,
|
||||||
/// its colour on its last frame
|
/// its colour on its last frame
|
||||||
pub color: String,
|
pub color: String,
|
||||||
pub size: f64,
|
pub size: f64,
|
||||||
@@ -70,6 +73,20 @@ impl Run {
|
|||||||
_ => &self.color,
|
_ => &self.color,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Every colour its words are drawn in on that frame: the line's, and an accent span's beside it (12-06: a line
|
||||||
|
/// recorded only by its own colour hid a dark word on a dark plate)
|
||||||
|
pub fn middle_inks(&self) -> Vec<&str> {
|
||||||
|
let n = self.boxes.len();
|
||||||
|
let mut all = vec![self.middle_color()];
|
||||||
|
let at = if n > 1 && self.inks.len() == n { self.inks.get(n / 2) } else { self.inks.last() };
|
||||||
|
for i in at.into_iter().flatten() {
|
||||||
|
if !all.contains(&i.as_str()) {
|
||||||
|
all.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
all
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The brand kit the cut was styled from (brand/ at or above the manifest's or the video's folder, as render finds
|
/// The brand kit the cut was styled from (brand/ at or above the manifest's or the video's folder, as render finds
|
||||||
@@ -129,18 +146,21 @@ pub fn text_runs(manifest: &Value) -> Vec<Run> {
|
|||||||
});
|
});
|
||||||
let mut r = match found {
|
let mut r = match found {
|
||||||
Some(i) => open.remove(i),
|
Some(i) => open.remove(i),
|
||||||
None => Run { text: text.clone(), from: t, to: t, box_: b, boxes: Vec::new(), colors: Vec::new(), color: String::new(), size: 0.0 },
|
None => Run { text: text.clone(), from: t, to: t, box_: b, boxes: Vec::new(), colors: Vec::new(), inks: Vec::new(), color: String::new(), size: 0.0 },
|
||||||
};
|
};
|
||||||
let color = x["color"].as_str().unwrap_or("rgb(255, 255, 255)").to_string();
|
let color = x["color"].as_str().unwrap_or("rgb(255, 255, 255)").to_string();
|
||||||
|
let inks: Vec<String> = x["inks"].as_array().map(|a| a.iter().filter_map(Value::as_str).map(String::from).collect()).unwrap_or_default();
|
||||||
if text.len() > r.text.len() {
|
if text.len() > r.text.len() {
|
||||||
r.boxes.clear();
|
r.boxes.clear();
|
||||||
r.colors.clear();
|
r.colors.clear();
|
||||||
|
r.inks.clear();
|
||||||
}
|
}
|
||||||
if text.len() >= r.text.len() {
|
if text.len() >= r.text.len() {
|
||||||
r.text = text;
|
r.text = text;
|
||||||
r.box_ = b;
|
r.box_ = b;
|
||||||
r.boxes.push(ink.unwrap_or(b));
|
r.boxes.push(ink.unwrap_or(b));
|
||||||
r.colors.push(color.clone());
|
r.colors.push(color.clone());
|
||||||
|
r.inks.push(inks);
|
||||||
}
|
}
|
||||||
r.to = t + 1.0 / fps;
|
r.to = t + 1.0 / fps;
|
||||||
r.color = color;
|
r.color = color;
|
||||||
@@ -348,4 +368,17 @@ mod tests {
|
|||||||
assert_eq!(runs[0].color, "rgb(10, 10, 11)", "its last colour");
|
assert_eq!(runs[0].color, "rgb(10, 10, 11)", "its last colour");
|
||||||
assert_eq!(runs[0].middle_color(), "rgb(169, 169, 174)", "the frame contrast measures is still grey");
|
assert_eq!(runs[0].middle_color(), "rgb(169, 169, 174)", "the frame contrast measures is still grey");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_line_with_an_accent_word_is_measured_in_both_colours() {
|
||||||
|
// a white caption with one word in dark red: the manifest's line colour alone hid the red word
|
||||||
|
let m = json!({"fps": 10.0, "frames": (0..4).map(|f| json!({"frame": f, "text": [
|
||||||
|
{"text": "Stay out longer.", "box": [100, 1400, 880, 90], "size": 84, "color": "rgb(255, 255, 255)", "inks": ["rgb(255, 255, 255)", "rgb(120, 0, 0)"]}
|
||||||
|
]})).collect::<Vec<_>>()});
|
||||||
|
let runs = text_runs(&m);
|
||||||
|
assert_eq!(runs[0].middle_inks(), vec!["rgb(255, 255, 255)", "rgb(120, 0, 0)"]);
|
||||||
|
// a line drawn in its own colour only has no inks, and is measured in that colour alone
|
||||||
|
let plain = json!({"fps": 10.0, "frames": [{"frame": 0, "text": [{"text": "raea", "box": [0, 0, 10, 10], "size": 40, "color": "rgb(1, 2, 3)"}]}]});
|
||||||
|
assert_eq!(text_runs(&plain)[0].middle_inks(), vec!["rgb(1, 2, 3)"]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -37,8 +37,8 @@ A whole video made from the same inputs as an earlier one is copied from the exp
|
|||||||
and the command says so.
|
and the command says so.
|
||||||
|
|
||||||
Every render writes its manifest beside its output: `OUT.render.json` (`DIR/NAME.render.json` for a folder of
|
Every render writes its manifest beside its output: `OUT.render.json` (`DIR/NAME.render.json` for a folder of
|
||||||
frames), or where `--manifest` says. It holds what each frame showed as laid out (each text's words, box, colour and
|
frames), or where `--manifest` says. It holds what each frame showed as laid out (each text's words, box, colour, the
|
||||||
size, each video's source and time, each picture's box), the sounds heard and what the render found. `raea check`
|
colours its words are drawn in when one differs, such as a caption's accent word, and size, each video's source and time, each picture's box), the sounds heard and what the render found. `raea check`
|
||||||
reads it, and so does [`raea world`](world.md), which measures the output against it when a check asks.
|
reads it, and so does [`raea world`](world.md), which measures the output against it when a check asks.
|
||||||
|
|
||||||
A render checks what it draws: 3D parts passing into each other (the clipping check), how its 3D is staged (3D type
|
A render checks what it draws: 3D parts passing into each other (the clipping check), how its 3D is staged (3D type
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ impl BlitzPage {
|
|||||||
let alpha = |n: blitz_dom::NodeId| alpha(doc, n);
|
let alpha = |n: blitz_dom::NodeId| alpha(doc, n);
|
||||||
let stamps = |n: blitz_dom::NodeId, entry: &mut serde_json::Value| stamps(doc, n, entry);
|
let stamps = |n: blitz_dom::NodeId, entry: &mut serde_json::Value| stamps(doc, n, entry);
|
||||||
let (mut videos, mut text, mut pictures) = (Vec::new(), Vec::new(), Vec::new());
|
let (mut videos, mut text, mut pictures) = (Vec::new(), Vec::new(), Vec::new());
|
||||||
let mut owned: Vec<(blitz_dom::NodeId, Vec<String>)> = Vec::new();
|
// each owner's words, and the colour each is drawn in (its text node's parent's: a caption's accent span)
|
||||||
|
let mut owned: Vec<(blitz_dom::NodeId, Vec<String>, Vec<String>)> = Vec::new();
|
||||||
// the whole document: a composition's sequences and screens are pages of their own under the root's
|
// the whole document: a composition's sequences and screens are pages of their own under the root's
|
||||||
let mut stack = vec![doc.root_node().id];
|
let mut stack = vec![doc.root_node().id];
|
||||||
while let Some(n) = stack.pop() {
|
while let Some(n) = stack.pop() {
|
||||||
@@ -121,19 +122,20 @@ impl BlitzPage {
|
|||||||
if node.parent.is_none_or(|p| alpha(p) <= 0.01) {
|
if node.parent.is_none_or(|p| alpha(p) <= 0.01) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
match owned.iter_mut().find(|(o, _)| *o == owner) {
|
let ink = node.parent.and_then(|p| doc.get_node(p)).and_then(|x| x.primary_styles()).filter(|_| !words.trim().is_empty()).map(|s| css(s.clone_color()));
|
||||||
Some((_, ws)) => ws.push(words.to_string()),
|
match owned.iter_mut().find(|(o, _, _)| *o == owner) {
|
||||||
None => owned.push((owner, vec![words.to_string()])),
|
Some((_, ws, inks)) => {
|
||||||
|
ws.push(words.to_string());
|
||||||
|
inks.extend(ink);
|
||||||
|
}
|
||||||
|
None => owned.push((owner, vec![words.to_string()], ink.into_iter().collect())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (owner, words) in owned {
|
for (owner, words, inks) in owned {
|
||||||
let Some(words) = run_text(&words) else { continue };
|
let Some(words) = run_text(&words) else { continue };
|
||||||
let (Some(b), Some(node)) = (rect(owner), doc.get_node(owner)) else { continue };
|
let (Some(b), Some(node)) = (rect(owner), doc.get_node(owner)) else { continue };
|
||||||
let Some(s) = node.primary_styles() else { continue };
|
let Some(s) = node.primary_styles() else { continue };
|
||||||
let c = s.clone_color().to_color_space(style::color::ColorSpace::Srgb);
|
let color = css(s.clone_color());
|
||||||
let [cr, cg, cb] = [c.components.0, c.components.1, c.components.2].map(|v| (v.clamp(0.0, 1.0) * 255.0).round());
|
|
||||||
let ca = c.alpha;
|
|
||||||
let color = if ca >= 1.0 { format!("rgb({cr}, {cg}, {cb})") } else { format!("rgba({cr}, {cg}, {cb}, {})", (ca * 1000.0).round() / 1000.0) };
|
|
||||||
let font = s.get_font();
|
let font = s.get_font();
|
||||||
let align = match s.clone_text_align() {
|
let align = match s.clone_text_align() {
|
||||||
TextAlignKeyword::Center | TextAlignKeyword::MozCenter => "center",
|
TextAlignKeyword::Center | TextAlignKeyword::MozCenter => "center",
|
||||||
@@ -153,6 +155,17 @@ impl BlitzPage {
|
|||||||
}
|
}
|
||||||
let mut t = json!({"text": words, "box": [r(b.x), r(b.y), r(w), r(h)], "opacity": (alpha(owner) * 100.0).round() / 100.0,
|
let mut t = json!({"text": words, "box": [r(b.x), r(b.y), r(w), r(h)], "opacity": (alpha(owner) * 100.0).round() / 100.0,
|
||||||
"color": color, "size": font.font_size.computed_size().px() as f64, "weight": font.font_weight.value() as f64, "align": align});
|
"color": color, "size": font.font_size.computed_size().px() as f64, "weight": font.font_weight.value() as f64, "align": align});
|
||||||
|
// the colours its words are drawn in, when any differs from the line's (an accent span, a word lit as it's
|
||||||
|
// said): contrast measures each, so a dark word on a dark plate is found though the line's colour is light
|
||||||
|
let mut drawn: Vec<String> = Vec::new();
|
||||||
|
for i in inks {
|
||||||
|
if !drawn.contains(&i) {
|
||||||
|
drawn.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if drawn.iter().any(|i| *i != color) {
|
||||||
|
t["inks"] = json!(drawn);
|
||||||
|
}
|
||||||
// where the letters are across the lines (each line's offset is its alignment's), as a box of its own: a
|
// where the letters are across the lines (each line's offset is its alignment's), as a box of its own: a
|
||||||
// centred line in a full-width box is tested by this, not the box (raea check's safe-area rule, #89)
|
// centred line in a full-width box is tested by this, not the box (raea check's safe-area rule, #89)
|
||||||
if let Some(l) = node.element_data().and_then(|e| e.inline_layout_data.as_ref()) {
|
if let Some(l) = node.element_data().and_then(|e| e.inline_layout_data.as_ref()) {
|
||||||
@@ -406,6 +419,13 @@ fn svg_runs(g: &usvg::Group, a: f64) -> Vec<(String, usvg::Rect, f64)> {
|
|||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A computed colour as CSS (`rgb(…)`, or `rgba(…)` when it isn't opaque), as the manifest writes text colours
|
||||||
|
fn css(c: style::color::AbsoluteColor) -> String {
|
||||||
|
let c = c.to_color_space(style::color::ColorSpace::Srgb);
|
||||||
|
let [cr, cg, cb] = [c.components.0, c.components.1, c.components.2].map(|v| (v.clamp(0.0, 1.0) * 255.0).round());
|
||||||
|
if c.alpha >= 1.0 { format!("rgb({cr}, {cg}, {cb})") } else { format!("rgba({cr}, {cg}, {cb}, {})", (c.alpha * 1000.0).round() / 1000.0) }
|
||||||
|
}
|
||||||
|
|
||||||
/// A run's words from its text nodes, in order: joined by a space, as caption words set one a span are; or, when every
|
/// A run's words from its text nodes, in order: joined by a space, as caption words set one a span are; or, when every
|
||||||
/// one is a single letter (a word revealed letter by letter, its spaces spans of their own), as the letters read
|
/// one is a single letter (a word revealed letter by letter, its spaces spans of their own), as the letters read
|
||||||
/// ("49 BC", not "4 9 B C"). None when the run is only white space.
|
/// ("49 BC", not "4 9 B C"). None when the run is only white space.
|
||||||
|
|||||||
Reference in new issue
Block a user