From 72e6cbfc6a4b4606f11a6d5285de65238dc0dbd4 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 9 Nov 2022 17:12:04 -0500 Subject: Added dla2csv, dla2img. Split up docs. --- dla2img.sh | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100755 dla2img.sh (limited to 'dla2img.sh') 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 < + +[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 -- cgit v1.2.3