blob: f765b69ea16add3c28b0aa3f0df67dc8bd06eddb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
|