#!/usr/bin/env bash
#
# Generate the Android launcher-icon mipmaps from the shared Windows icon
# (resources/kat5200.ico, the highest-res source we have at 48x48).  The
# resulting PNGs ARE committed (Android resources), so a regular build needs no
# image tooling; re-run this only when the source art changes.  macOS-only
# (uses sips) -- like cmake/make_icns.cmake.
#
# NOTE: the source tops out at 48x48, so the larger densities are upscaled and
# look soft.  Drop a 512x512+ master in as the source and re-run for crisp icons.

set -euo pipefail
cd "$(dirname "$0")"

SRC="../resources/kat5200.ico"
RES="app/src/main/res"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT

# Pull the largest image out of the .ico into a working PNG.
sips -s format png "$SRC" --out "$TMP/base.png" >/dev/null

gen() {   # density-dir  pixel-size
    mkdir -p "$RES/mipmap-$1"
    sips -z "$2" "$2" "$TMP/base.png" --out "$RES/mipmap-$1/ic_launcher.png" >/dev/null
    echo "  mipmap-$1/ic_launcher.png (${2}x${2})"
}

echo "Generating launcher icons under $RES:"
gen mdpi    48
gen hdpi    72
gen xhdpi   96
gen xxhdpi  144
gen xxxhdpi 192
