-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_write
executable file
·49 lines (42 loc) · 906 Bytes
/
image_write
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
#!/bin/bash
INFO=$'
Usage:
\timage_write H,W [ ... ImageMagick options ... ]
\timage_write H,W,3 [ ... ImageMagick options ... ]
'
case "$1" in
*,*,*,*)
echo "$INFO" 1>&2
exit 1
;;
*,*,3)
SIZE="${1%,*}"
SIZE="${SIZE##*,}x${SIZE%%,*}"
FMT="RGB"
;;
*,*,*)
echo "$INFO" 1>&2
exit 1
;;
*,*)
SIZE="${1##*,}x${1%%,*}"
FMT="GRAY"
;;
*)
echo "$INFO" 1>&2
exit 1
;;
esac
BYTES=$((${1//,/*})) || exit 1
shift
TMPDIR=$(mktemp -d) || exit 1
trap "rm -rf $TMPDIR" EXIT
SCENE=1
while dd bs=1 count=$BYTES of="$TMPDIR/chunk" status=none ; do
READ_BYTES=$(stat -c%s "$TMPDIR/chunk")
[ "x$READ_BYTES" = "x$BYTES" ] || exit 1
convert \
-size "$SIZE" -depth 8 "$FMT:$TMPDIR/chunk" \
-scene "$SCENE" "$@" </dev/null || exit 1
let SCENE=SCENE+1
done || exit 1