make_reference_frames.sh 1.9 KB

123456789101112131415161718192021222324252627282930
  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. # ONLY=<id> renders just that wallpaper, VARIANT=<name> writes reference/<id>-<name>.png next to the main one: a wallpaper that
  6. # changes with the date (1078208425 shows a Halloween scene from late October) passes with any of its references.
  7. HERE=$(cd "$(dirname "$0")" && pwd)
  8. binary=${1:-$HERE/../../build/output/linux-wallpaperengine}
  9. payload=${2:-$HOME/.local/share/linuxvm/payload}
  10. tmp=$(mktemp -d)
  11. trap 'rm -rf "$tmp"' EXIT
  12. mkdir -p "$HERE/reference"
  13. for dir in "$payload"/wp-*; do
  14. id=${dir##*wp-}
  15. [ -z "${ONLY:-}" ] || [ "$id" = "$ONLY" ] || continue
  16. name=$id${VARIANT:+-$VARIANT}
  17. type=$(python3 -c "import json,sys; print(json.load(open(sys.argv[1] + '/project.json')).get('type', ''))" "$dir")
  18. case $type in
  19. video) continue ;;
  20. web) export HEADLESS_RENDER_WEB=1 HEADLESS_RENDER_DELAY=700 HEADLESS_RENDER_TIMEOUT=120 ;;
  21. *) unset HEADLESS_RENDER_WEB; export HEADLESS_RENDER_DELAY=150 HEADLESS_RENDER_TIMEOUT=60 ;;
  22. esac
  23. if HEADLESS_RENDER_SIZE=1920x1080 "$HERE/../headless_render.sh" "$binary" "$tmp/$id.png" --assets-dir "$payload/assets" "$dir" > "$tmp/$id.log" 2>&1 \
  24. && [ -s "$tmp/$id.png" ]; then
  25. 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])" \
  26. "$tmp/$id.png" "$HERE/reference/$name.png" && echo "$name ($type): reference written"
  27. else
  28. echo "$id ($type): render failed, see $tmp/$id.log"; cp "$tmp/$id.log" "/tmp/make_reference_$id.log" 2>/dev/null
  29. fi
  30. done