aboutsummaryrefslogtreecommitdiff
path: root/dla2img.sh
diff options
context:
space:
mode:
Diffstat (limited to 'dla2img.sh')
-rwxr-xr-xdla2img.sh68
1 files changed, 68 insertions, 0 deletions
diff --git a/dla2img.sh b/dla2img.sh
new file mode 100755
index 0000000..f765b69
--- /dev/null
+++ b/dla2img.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+
+# This script tested with bash 5.1, zsh 5.8, ksh 93u, and dash 0.5.11.4.
+# If your environment doesn't have a shell compatible with one of those,
+# I can't help you.
+
+SELF="$(basename $0)"
+
+# allow overriding magick path via environment.
+MAGICK=${MAGICK:-magick}
+
+# only change this if the save file size changes in dla.xex.
+SIZE="256x170"
+
+usage() {
+ cat <<EOF
+$SELF - convert saved files from dla.xex to image files.
+
+Usage: $SELF [dla-file] [image-file] <magick-arguments ...>
+
+[dla-file] is a file created by the Save option in dla.xex.
+
+[image-file] is the output file: any image file that ImageMagick
+knows how to create. Image type is determined by filename extension,
+e.g. "filename.png" or "filename.bmp". Try "magick -list format|less"
+to see the the full list.
+
+If any arguments after the [image-file] are present, they will be
+passed to the magick executable as-is. The most useful argument here
+is probably -trim, which will automatically crop the black borders
+around the image. See the ImageMagick documentation for the full list
+of supported arguments.
+
+See also: https://slackware.uk/~urchlay/repos/dla-asm
+EOF
+}
+
+INFILE="$1"
+OUTFILE="$2"
+
+if [ -z "$INFILE" -o -z "$OUTFILE" -o "$INFILE" = "-h" -o "$INFILE" = "--help" ]; then
+ usage
+ exit 0
+fi
+
+shift 2
+
+# do the conversion... if $OUTFILE has an unknown extension, we will
+# not get an error, and the conversion will succeed (the output will
+# just be a copy of the input!)
+$MAGICK convert -size "$SIZE" -depth 1 "$@" gray:"$INFILE" "$OUTFILE"
+
+# if magick fails, exit with its error status (it already printed its
+# error messages to stderr).
+S="$?"
+if [ "$S" != "0" ]; then
+ exit "$S"
+fi
+
+# if magick "succeeds" but the output is identical to the input, let
+# the user know.
+if cmp "$INFILE" "$OUTFILE" >/dev/null 2>&1; then
+ rm -f "$OUTFILE"
+ echo "$SELF: Unsupported filename extension; see ImageMagick docs." 1>&2
+ exit 1
+fi
+
+exit 0