#!/bin/sh # This script deliberately written with old-school shell syntax, to # support as many Bourne-like shells as possible. Do not complain that # backticks are deprecated: this is supposed to (potentially) work # on ancient shells that might exist on e.g. an Atari ST or Amiga. It # *does* work on a wide variety of modern shells. # The only required external commands we call are magick, rm, and cat. # If stat is present, it will be called (but no problem, if it's # missing). # Tested with ImageMagick 7.1, but doesn't use any fancy features so # it should work with any fairly recent ImageMagick. SELF="`basename $0`" # allow overriding magick path via environment. if [ "$MAGICK" = "" ]; then MAGICK="magick" fi # only change this if the save file size changes in dla.xex. SIZE="256x170" # ...and if you change that, change this too: FILESIZE="5440" INFILE="$1" OUTFILE="$2" if [ -z "$INFILE" -o -z "$OUTFILE" -o "$INFILE" = "-h" -o "$INFILE" = "--help" ]; then 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 exit 0 fi shift shift if [ ! -e "$INFILE" ]; then cat "$INFILE" > /dev/null # to get an error like "No such file or directory" exit 1 fi # if "stat" is missing, e.g. because we're on a non-GNU system that # lacks the command, just skip the file size check (magick will error # out instead; less user-friendly but no big deal). if stat /dev/null >/dev/null 2>&1; then if [ "`stat -L -c '%s' "$INFILE"`" != "$FILESIZE" ]; then echo "$SELF: '$INFILE' not a DLA file (size != $FILESIZE)." 1>&2 exit 1 fi fi rm -f "$OUTFILE" # 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!) # The "eval" is here to make this script work on the original Bourne # shell (yes, the one from V7 UNIX). Seriously. Even with spaces # in the arguments! eval "$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 echo "$SELF: conversion failed (invalid output file extension?)." 1>&2 exit "$S" fi # if magick "succeeds" but the output file doesn't exist, complain. if [ ! -e "$OUTFILE" ]; then echo "$SELF: conversion failed (probably '$INFILE' is not a DLA) file)." 1>&2 exit 1; 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