characters
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 386 B |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 6.5 KiB |
|
After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 868 B |
@@ -0,0 +1,140 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
variants=(black blue green grey red white)
|
||||
references=(character_001_isaac character_002_magdalene)
|
||||
|
||||
usage() {
|
||||
printf 'Usage: %s INPUT.png\n' "$(basename "$0")" >&2
|
||||
}
|
||||
|
||||
if [[ $# -ne 1 || "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if command -v magick >/dev/null 2>&1; then
|
||||
im=(magick)
|
||||
elif command -v convert >/dev/null 2>&1; then
|
||||
im=(convert)
|
||||
else
|
||||
printf 'error: ImageMagick is required; expected magick or convert in PATH\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
input="$1"
|
||||
|
||||
if [[ ! -f "$input" ]]; then
|
||||
printf 'error: input file not found: %s\n' "$input" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$(basename -- "$input")" in
|
||||
*.png|*.PNG) ;;
|
||||
*)
|
||||
printf 'error: input must be a PNG file: %s\n' "$input" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
for reference in "${references[@]}"; do
|
||||
reference_base="$script_dir/${reference}.png"
|
||||
if [[ ! -f "$reference_base" ]]; then
|
||||
printf 'error: missing reference file: %s\n' "$reference_base" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
input_dir="$(cd -- "$(dirname -- "$input")" && pwd)"
|
||||
input_name="$(basename -- "$input")"
|
||||
stem="${input_name%.*}"
|
||||
|
||||
case "$stem" in
|
||||
*_black|*_blue|*_green|*_grey|*_red|*_white)
|
||||
stem="${stem%_*}"
|
||||
;;
|
||||
esac
|
||||
|
||||
build_palette_map() {
|
||||
local variant="$1"
|
||||
local reference
|
||||
local reference_base
|
||||
local reference_variant
|
||||
|
||||
for reference in "${references[@]}"; do
|
||||
reference_base="$script_dir/${reference}.png"
|
||||
reference_variant="$script_dir/${reference}_${variant}.png"
|
||||
|
||||
if [[ ! -f "$reference_variant" ]]; then
|
||||
printf 'error: missing reference file: %s\n' "$reference_variant" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
paste \
|
||||
<("${im[@]}" "$reference_base" -depth 8 txt:-) \
|
||||
<("${im[@]}" "$reference_variant" -depth 8 txt:-) |
|
||||
awk -F '\t' -v reference="$reference" '
|
||||
function pixel_hex(line, parts, count, i) {
|
||||
count = split(line, parts, /[[:space:]]+/)
|
||||
for (i = 1; i <= count; i++) {
|
||||
if (parts[i] ~ /^#[[:xdigit:]]{6}([[:xdigit:]]{2})?$/) {
|
||||
return toupper(parts[i])
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
NR == 1 { next }
|
||||
|
||||
{
|
||||
source = pixel_hex($1)
|
||||
target = pixel_hex($2)
|
||||
if (source == "" || target == "" || source == target) {
|
||||
next
|
||||
}
|
||||
print source, target, reference
|
||||
}
|
||||
'
|
||||
done |
|
||||
awk '
|
||||
{
|
||||
source = $1
|
||||
target = $2
|
||||
reference = $3
|
||||
if ((source in targets) && targets[source] != target) {
|
||||
printf "error: conflicting map for %s: %s from %s and %s from %s\n", source, targets[source], sources[source], target, reference > "/dev/stderr"
|
||||
exit 2
|
||||
}
|
||||
targets[source] = target
|
||||
sources[source] = reference
|
||||
}
|
||||
|
||||
END {
|
||||
for (source in targets) {
|
||||
print source, targets[source]
|
||||
}
|
||||
}
|
||||
' |
|
||||
sort
|
||||
}
|
||||
|
||||
for variant in "${variants[@]}"; do
|
||||
output="$input_dir/${stem}_${variant}.png"
|
||||
args=("$input" -alpha on)
|
||||
pair_count=0
|
||||
|
||||
while read -r source target; do
|
||||
[[ -n "$source" && -n "$target" ]] || continue
|
||||
args+=(-fill "$target" -opaque "$source")
|
||||
pair_count=$((pair_count + 1))
|
||||
done < <(build_palette_map "$variant")
|
||||
|
||||
if [[ "$pair_count" -eq 0 ]]; then
|
||||
printf 'error: no palette replacements found for %s\n' "$variant" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
"${im[@]}" "${args[@]}" "$output"
|
||||
printf 'exported %s\n' "$output"
|
||||
done
|
||||