Skip to content

armgit / raea

Public Imported from GitHub
0

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.

A composition that paints no background is black behind it in a video too, as in a PNG

shinyobjectz6f6daa1b3b8c
diff --git a/bench/clear-backdrop/check.sh b/bench/clear-backdrop/check.sh
new file mode 100755
index 00000000..1376b552
--- /dev/null
+++ b/bench/clear-backdrop/check.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+# A composition that paints no background is black behind its content in every output, as a PNG of it always was. A
+# video took the fed path, whose program has no camera, and runtime/view's camera_bg gave raea's old dark blue
+# (13,10,26) for that; the same frame as a PNG was black (#13's sweep met it). The composition, white text on nothing,
+# is rendered to an mp4 and to a PNG: the corner of each must be black (within 3 of 0, the mp4's YUV rounding) and
+# the two must agree. Exits 1 on a failure.
+# bench/clear-backdrop/check.sh (RAEA_BIN: the raea to run, default target/release/raea)
+cd "$(dirname "$0")/../.." || exit 2
+BIN=${RAEA_BIN:-$PWD/target/release/raea}
+export RAEA_SIGN=0 RAEA_MARK=0 RAEA_EXPORT_CACHE=0
+OUT=$(mktemp -d "${TMPDIR:-/tmp}/raea-clear-backdrop.XXXXXX")
+trap 'rm -rf "$OUT"' EXIT
+cat > "$OUT/clear.tsx" <<'TSX'
+import { AbsoluteFill, Composition, registerRoot } from "raea";
+const Shot = () => (<AbsoluteFill><div style={{ color: "#fff", fontSize: 24 }}>x</div></AbsoluteFill>);
+registerRoot(() => <Composition id="clear" component={Shot} width={160} height={160} fps={30} durationInFrames={2} />);
+TSX
+status=0
+corner() { magick "$1" -format "%[fx:int(255*p{120,120}.r+0.5)] %[fx:int(255*p{120,120}.g+0.5)] %[fx:int(255*p{120,120}.b+0.5)]" info:; }
+black() { # PNG WHAT
+ read -r r g b <<< "$(corner "$1")"
+ (( r <= 3 && g <= 3 && b <= 3 )) && echo "ok $2: black ($r,$g,$b)" || { echo "FAIL $2: $r,$g,$b behind the content, wanted black"; status=1; }
+}
+if "$BIN" render "$OUT/clear.tsx" -o "$OUT/clear.mp4" > "$OUT/mp4.log" 2>&1 && ffmpeg -loglevel error -i "$OUT/clear.mp4" -frames:v 1 -y "$OUT/mp4.png"; then
+ black "$OUT/mp4.png" "an mp4"
+else echo "FAIL an mp4: the render failed"; sed 's/^/ /' "$OUT/mp4.log" | tail -4; status=1; fi
+if "$BIN" render "$OUT/clear.tsx" --at 0 -o "$OUT/png" > "$OUT/png.log" 2>&1 && [ -f "$OUT/png/frame-00000.png" ]; then
+ black "$OUT/png/frame-00000.png" "a PNG (--at 0)"
+else echo "FAIL a PNG: the render failed"; sed 's/^/ /' "$OUT/png.log" | tail -4; status=1; fi
+[ $status = 0 ] && echo "PASS a clear composition is black in an mp4 and a PNG"
+exit $status
diff --git a/runtime/view/src/lib.rs b/runtime/view/src/lib.rs
index d5618d4a..b14f942e 100644
--- a/runtime/view/src/lib.rs
+++ b/runtime/view/src/lib.rs
@@ -11,16 +11,17 @@ pub mod masks;
pub mod rows;
pub mod rows2d;
-/// The camera's clear colour (its `bg`, #rrggbb or #rrggbbaa) as a premultiplied RGBA texel; raea's dark blue when it
-/// has none. An alpha under ff (an HTML page's canvas under --alpha, #00000000) stays: it was read as opaque, so the
-/// clear canvas came out black (#32).
+/// The camera's clear colour (its `bg`, #rrggbb or #rrggbbaa) as a premultiplied RGBA texel; black when it has none,
+/// as raea-export's program clears under 2D pages (a fed video's program has no camera: its transparent parts were
+/// raea's dark blue, 13,10,26, where a PNG of the same frame is black). An alpha under ff (an HTML page's canvas under
+/// --alpha, #00000000) stays: it was read as opaque, so the clear canvas came out black (#32).
pub(crate) fn camera_bg(rows: &[raea_core_program::eval::Tup]) -> [u8; 4] {
let hex = rows.iter().find(|t| t.kind == "camera").and_then(|t| match t.vals.get("bg") {
Some(raea_core_program::ir::V::S(s)) => Some(s.trim_start_matches('#').to_string()),
_ => None,
});
let b = |h: &str, i: usize| u8::from_str_radix(h.get(i..i + 2)?, 16).ok();
- let Some((rgb, a)) = hex.and_then(|h| Some(([b(&h, 0)?, b(&h, 2)?, b(&h, 4)?], if h.len() == 8 { b(&h, 6)? } else { 255 }))) else { return [13, 10, 26, 255] };
+ let Some((rgb, a)) = hex.and_then(|h| Some(([b(&h, 0)?, b(&h, 2)?, b(&h, 4)?], if h.len() == 8 { b(&h, 6)? } else { 255 }))) else { return [0, 0, 0, 255] };
let pre = |c: u8| ((c as u32 * a as u32 + 127) / 255) as u8;
[pre(rgb[0]), pre(rgb[1]), pre(rgb[2]), a]
}