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.

3.8 KB
Raw Blame
#!/bin/bash
# P15's fixtures, written into fixtures.ts as data: URLs (so both sides read the same bytes with no file serving):
# one picture, 96x72, four coloured quadrants and a white bar across its top left, in every image format Bevy decodes
# (bevy_image's features); a short VP9 video of three solid colours with a poster; a tone as audio. Run it again only
# to change the fixtures (it needs ImageMagick and ffmpeg):
#   bash sdk/ui/parity/cases/p15-media/fixtures.sh
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
tmp=$(mktemp -d "${TMPDIR:-/tmp}/p15-fixtures.XXXXXX")
trap 'rm -rf "$tmp"' EXIT
cd "$tmp"

# the picture: quadrants rose, green, blue, amber; a white bar 40x8 at (8, 8)
magick -size 48x36 xc:'#e11d48' xc:'#16a34a' +append \( -size 48x36 xc:'#2563eb' xc:'#f59e0b' +append \) -append \
  -fill white -draw 'rectangle 8,8 47,15' -strip -define png:color-type=2 base.png
magick base.png -quality 95 -sampling-factor 4:4:4 base.jpg
cwebp -quiet -lossless base.png -o base.webp
magick base.png base.gif
magick base.png -define bmp:format=bmp3 base.bmp
magick base.png -compress none base.tga
magick base.png base.qoi
magick base.png -compress none base.tif
magick base.png base.ppm
magick base.png base.ff
magick base.png -define dds:compression=none base.dds
# EXR holds linear light: the picture linearised (16-bit), then stored as floats (ffmpeg's EXR writer copies values; this
# ImageMagick has no EXR delegate)
magick base.png -colorspace RGB -depth 16 -strip -define png:color-type=2 base-linear.png
ffmpeg -loglevel error -y -i base-linear.png -pix_fmt gbrpf32le base.exr
magick base.png base.hdr
# Radiance's shared exponent rounds a dark channel next to a bright one (amber's blue 11 -> 0): the oracle for the HDR
# case is the picture the file holds, back in sRGB as a PNG
magick base.hdr -colorspace sRGB -depth 8 -strip -define png:color-type=2 base-hdr.png
magick base.png -define icon:auto-resize=64 base.ico

# the video: 1 s at 10 fps, a third each of rose, green, blue, 96x72; its poster amber
for c in e11d48 16a34a 2563eb; do magick -size 96x72 xc:"#$c" "v-$c.png"; done
ffmpeg -loglevel error -y -f lavfi -i "color=c=0xe11d48:s=96x72:d=0.4,format=yuv420p" -f lavfi -i "color=c=0x16a34a:s=96x72:d=0.3,format=yuv420p" \
  -f lavfi -i "color=c=0x2563eb:s=96x72:d=0.3,format=yuv420p" -filter_complex "[0][1][2]concat=n=3:v=1:a=0,fps=10" \
  -c:v libvpx-vp9 -lossless 1 -row-mt 1 video.webm
magick -size 96x72 xc:'#f59e0b' poster.png
# the audio: 0.5 s of 440 Hz
ffmpeg -loglevel error -y -f lavfi -i "sine=frequency=440:duration=0.5" -c:a libopus audio.webm

b64() { base64 < "$1" | tr -d '\n'; }
{
  echo "// Generated by fixtures.sh: P15's media as data: URLs (one picture in every format Bevy decodes, a video, a"
  echo "// sound). Don't edit; run the script."
  echo "/** 96x72: quadrants rose, green / blue, amber; a white bar 40x8 at (8, 8). */"
  echo "export const W = 96, H = 72;"
  for f in png:image/png jpg:image/jpeg webp:image/webp gif:image/gif bmp:image/bmp tga:image/x-tga qoi:image/qoi \
    tif:image/tiff ppm:image/x-portable-pixmap ff:image/farbfeld dds:image/vnd-ms.dds exr:image/x-exr \
    hdr:image/vnd.radiance ico:image/x-icon; do
    ext=${f%%:*} mime=${f#*:}
    up=$(echo "$ext" | tr a-z A-Z); echo "export const $up = \"data:$mime;base64,$(b64 "base.$ext")\";"
  done
  echo "/** The HDR picture as the file holds it (its oracle), as PNG. */"
  echo "export const HDR_PNG = \"data:image/png;base64,$(b64 base-hdr.png)\";"
  echo "/** 1 s at 10 fps: rose to 0.4 s, green to 0.7, blue to the end (VP9, lossless). */"
  echo "export const VIDEO = \"data:video/webm;base64,$(b64 video.webm)\";"
  echo "/** a 96x72 amber poster */"
  echo "export const POSTER = \"data:image/png;base64,$(b64 poster.png)\";"
  echo "export const AUDIO = \"data:audio/webm;base64,$(b64 audio.webm)\";"
} > "$here/fixtures.ts"
wc -c "$here/fixtures.ts"