make_reference_frames.sh 1.6 KB

1234567891011121314151617181920212223242526
  1. #!/bin/bash
  2. # make_reference_frames.sh [binary] [payload dir] - renders the test wallpapers of the VM payload headlessly at 1920x1080 and keeps
  3. # a 192x108 copy of each in reference/<id>.png, what check_frame.py --reference compares the VM screenshots with (upside down,
  4. # wrong crop). Video wallpapers are left out, their frame depends on the moment of the shot. Needs a GPU render node.
  5. HERE=$(cd "$(dirname "$0")" && pwd)
  6. binary=${1:-$HERE/../../build/output/linux-wallpaperengine}
  7. payload=${2:-$HOME/.local/share/linuxvm/payload}
  8. tmp=$(mktemp -d)
  9. trap 'rm -rf "$tmp"' EXIT
  10. mkdir -p "$HERE/reference"
  11. for dir in "$payload"/wp-*; do
  12. id=${dir##*wp-}
  13. type=$(python3 -c "import json,sys; print(json.load(open(sys.argv[1] + '/project.json')).get('type', ''))" "$dir")
  14. case $type in
  15. video) continue ;;
  16. web) export HEADLESS_RENDER_WEB=1 HEADLESS_RENDER_DELAY=700 HEADLESS_RENDER_TIMEOUT=120 ;;
  17. *) unset HEADLESS_RENDER_WEB; export HEADLESS_RENDER_DELAY=150 HEADLESS_RENDER_TIMEOUT=60 ;;
  18. esac
  19. if HEADLESS_RENDER_SIZE=1920x1080 "$HERE/../headless_render.sh" "$binary" "$tmp/$id.png" --assets-dir "$payload/assets" "$dir" > "$tmp/$id.log" 2>&1 \
  20. && [ -s "$tmp/$id.png" ]; then
  21. python3 -I -c "import sys; from PIL import Image; Image.open(sys.argv[1]).convert('RGB').resize((192, 108), Image.LANCZOS).save(sys.argv[2])" \
  22. "$tmp/$id.png" "$HERE/reference/$id.png" && echo "$id ($type): reference written"
  23. else
  24. echo "$id ($type): render failed, see $tmp/$id.log"; cp "$tmp/$id.log" "/tmp/make_reference_$id.log" 2>/dev/null
  25. fi
  26. done