#!/usr/bin/env bash
# run-tool-all.sh <in-dir> <out-dir>: runs the live Add watermark page (wm-run.cjs) on every setting of the test matrix.
# Optional third argument: a matrix file with the same columns (default: the built-in matrix 1 below).
# Columns: name video logo position size opacity. Positions: 0 bottom right, 1 bottom left, 2 top right, 3 top left, 4 center.
set -u
in="$1"; out="$2"; mx="${3:-}"; here="$(cd "$(dirname "$0")" && pwd)"
mkdir -p "$out"
while read -r name video logo pos size op; do
  [ -z "$name" ] && continue
  [ -s "$out/$name.mp4" ] && { echo "$name: exists, skipped"; continue; }
  echo "== $name $video $logo pos=$pos size=$size opacity=$op"
  node "$here/wm-run.cjs" "$in/$video.mp4" "$in/$logo.png" "$out/$name.mp4" "$pos" "$size" "$op" "$out/$name.png" 2>&1 | grep -E "labels|finished|FAIL"
done < <(if [ -n "$mx" ]; then cat "$mx"; else cat <<'M'
p0 white logo-black-box 0 18 100
p1 white logo-black-box 1 18 100
p2 white logo-black-box 2 18 100
p3 white logo-black-box 3 18 100
p4 white logo-black-box 4 18 100
o10 white logo-black-box 0 18 10
o30 white logo-black-box 0 18 30
o50 white logo-black-box 0 18 50
o80 white logo-black-box 0 18 80
s5 white logo-black-box 0 5 100
s10 white logo-black-box 0 10 100
s30 white logo-black-box 0 30 100
s50 white logo-black-box 0 50 100
r18 land logo-fernwick 0 18 80
r08 land logo-fernwick 0 8 80
r12 land logo-fernwick 0 12 80
r30 land logo-fernwick 0 30 80
r18o30 land logo-fernwick 0 18 30
v18 vert logo-fernwick 0 18 80
v18c vert logo-fernwick 4 18 80
M
fi)
echo ALL-DONE
