]> git.plutz.net Git - stereofy/blob - stereofy.sh
51cbfb15c1579d9ed02deb0f08ddbc3e73f8ebd2
[stereofy] / stereofy.sh
1 #!/bin/sh
2 # Copyright 2011 Paul Hänsch
3 # This file is part of Stereofy
4 #
5 # Stereofy is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Stereofy is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Stereofy.  If not, see <http://www.gnu.org/licenses/>.
17
18 algo="d"   #algorythm, Dubois by default
19 model="rc" #color model, red-cyan by default
20 param=""   #leave blank, will be -$algo$model
21 left=''
22 right=''
23 stereo=''
24
25 while [ -n "$1" ]; do
26   case "$1" in
27     -d|--dubois) algo="d";;
28     -f|--full|--full-color) algo="f";;
29     -h|--half|--half-color) algo="d";;
30     -rc|--rc|--red-cyan) model="rc";;
31     -mc|--mc|--magenta-cyan) model="mc";;
32     -gm|--gm|--green-magenta) model="gm";;
33     -ab|--ab|--amber-blue|--yellow-blue) model="ab";;
34     -[dfh]rc|-[dfh]gm|-[fe]mc|-dab) param="$1";;
35     -*) echo "no such color model" >/dev/stderr; exit 1;;
36     *)  if [ -z "$left" ]; then
37           left="$1"
38         elif [ -z "$right" ]; then
39           right="$1"
40         elif [ -z "$stereo" ]; then
41           stereo="$1"
42         fi
43         ;;
44   esac
45   shift 1;
46 done
47
48 [ -z "$param" ] && param="-$algo$model"
49 [ -z "$stereo" ] && stereo="${left}_stereo.jpg"
50
51 echo -n preparing...
52 geom=$(identify "$left" |sed -rn 's:^.* ([0-9]+x[0-9]+) .*$:\1:gp')
53 tmp=$(tempfile -d /tmp -p strfy)
54 rm "$tmp"
55 mkfifo "$tmp"
56
57 convert "$left" rgb:- >"$tmp" &
58 echo -n anaglyphing...
59 convert "$right" rgb:- |anaglyph "$param" "$tmp" /dev/stdin /dev/stdout |convert -depth 8 -size "$geom" rgb:- "$stereo"
60
61 echo cleaning...
62 rm "$tmp"