#!/usr/bin/env bash

set -eu

INPUTS="$(find . -mindepth 1 -maxdepth 1 -name "*.fsf")"

ITERATIONS=5000
# 360p:        640x360
# 720p:        1280x720
# Full-HD:     1920x1080
# Ultra-HD 4K: 3840x2160
# Ultra-HD 8K: 7680x4320
RESOLUTIONS="1280x720 1920x1080 3840x2160 7680x4320"
FORMAT="webp"

for resolution in ${RESOLUTIONS} ; do
   width="${resolution/x*/}"
   height="${resolution/*x/}"
   echo "Computing resolution ${width} × ${height}:"
   mkdir -p "${resolution}"

   for input in ${INPUTS} ; do
      output="${resolution}/${input/.fsf/.${FORMAT}}"
      clifractgen -W "${width}" -H "${height}" -M ${ITERATIONS} "${input}" "${output}"
   done
done
