check_leds.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env bash
  2. # Renders a scene headlessly with --leds against tools/openrgb_probe.py (a fake OpenRGB server with one 80 x 10 device)
  3. # and prints the last frame the device got, as a PPM and an upscaled PNG.
  4. #
  5. # Usage: tools/check_leds.sh <binary> <scene dir or pkg> <out dir> [engine args...]
  6. # The scene's frame is compared by eye or with tools/wecompare against the plugin's frame under Wine
  7. # (tools/wecompare/wine/we_led.sh). --leds-no-boost is passed so the raw frame comes out
  8. set -euo pipefail
  9. if [ "$#" -lt 3 ]; then
  10. echo "Usage: $0 <binary> <scene> <out dir> [engine args...]" >&2
  11. exit 1
  12. fi
  13. HERE=$(cd "$(dirname "$0")" && pwd)
  14. BINARY=$1
  15. SCENE=$2
  16. OUT=$3
  17. shift 3
  18. PORT=${LEDS_PROBE_PORT:-16742}
  19. ASSETS=${ASSETS_DIR:-}
  20. rm -rf "$OUT"
  21. mkdir -p "$OUT"
  22. python3 "$HERE/openrgb_probe.py" --port "$PORT" --out "$OUT/frames" > "$OUT/server.log" 2>&1 &
  23. SERVER=$!
  24. trap 'kill $SERVER 2>/dev/null || true' EXIT
  25. sleep 1
  26. extra=()
  27. [ -n "$ASSETS" ] && extra+=(--assets-dir "$ASSETS")
  28. HEADLESS_RENDER_KEEP_RUNNING=1 HEADLESS_RENDER_TIMEOUT=${LEDS_RUN_SECONDS:-12} "$HERE/headless_render.sh" "$BINARY" "$OUT/screenshot.png" \
  29. "${extra[@]}" --fps 30 --leds-server "127.0.0.1:$PORT" --leds-no-boost "$@" "$SCENE" > "$OUT/engine.log" 2>&1 || true
  30. last=$(ls "$OUT"/frames/probe_*.ppm 2>/dev/null | tail -1)
  31. [ -n "$last" ] || { echo "no frame reached the probe server, see $OUT/engine.log" >&2; exit 1; }
  32. cp "$last" "$OUT/frame.ppm"
  33. python3 - "$OUT/frame.ppm" "$OUT/frame.png" <<'PY'
  34. import sys
  35. from PIL import Image
  36. Image.open(sys.argv[1]).resize((800, 100), Image.NEAREST).save(sys.argv[2])
  37. PY
  38. echo "$OUT/frame.ppm"