2 # Copyright 2011 Paul Hänsch
3 # This file is part of Stereofy
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.
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.
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/>.
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='' #left image filename
22 right='' #right image file name
23 stereo='' #output image file name
24 vert=0 #vertical justification
25 hor=0 #horizontal justification
26 lvoff=0 #left image vertical crop offset
27 rvoff=0 #right image vertical crop offset
28 lhoff=0 #left image horizontal crop offset
29 rhoff=0 #right image horizontal crop offset
33 -d|--dubois) algo="d";;
34 -f|--full|--full-color) algo="f";;
35 -h|--half|--half-color) algo="d";;
36 -rc|--rc|--red-cyan) model="rc";;
37 -mc|--mc|--magenta-cyan) model="mc";;
38 -gm|--gm|--green-magenta) model="gm";;
39 -ab|--ab|--amber-blue|--yellow-blue) model="ab";;
40 -[dfh]rc|-[dfh]gm|-[fe]mc|-dab) param="$1";;
41 --vjust|-ver|--ver|--vertical) shift 1; vert="$1";;
42 --hjust|-hor|--hor|--horizontal) shift 1; hor="$1";;
43 -*) echo "no such color model" >/dev/stderr; exit 1;;
44 *) if [ -z "$left" ]; then
46 elif [ -z "$right" ]; then
48 elif [ -z "$stereo" ]; then
55 if (echo $vert |egrep -qx '[+-]*[0-9]*[02468]'); then true
57 echo 'vertical alignment must be an even number'
60 if (echo $hor |egrep -qx '[+-]*[0-9]*[02468]'); then true
62 echo 'horizontal alignment must be an even number'
66 [ -z "$param" ] && param="-$algo$model"
67 [ -z "$stereo" ] && stereo="${left}_stereo.jpg"
69 echo -n calculating geometry...
70 geom=$(identify "$left" |sed -rn 's:^.* ([0-9]+x[0-9]+) .*$:\1:gp')
71 width=$(echo $geom |cut -dx -f1)
72 height=$(echo $geom |cut -dx -f2)
74 if [ "$vert" -gt 0 ]; then
75 height=$(($height - $vert / 2))
77 elif [ "$vert" -lt 0 ]; then
78 height=$(($height - $vert / -2))
81 if [ "$hor" -gt 0 ]; then
82 width=$(($width - $hor / 2))
84 elif [ "$hor" -lt 0 ]; then
85 width=$(($width - $hor / -2))
88 geom="${width}x${height}"
89 lcrop="${geom}+${lhoff}+${lvoff}"
90 rcrop="${geom}+${rhoff}+${rvoff}"
92 echo -n setup streaming...
93 tmp=$(tempfile -d /tmp -p strfy)
97 convert "$left" -crop "$lcrop" rgb:- >"$tmp" &
98 echo -n anaglyphing...
99 convert "$right" -crop "$rcrop" rgb:- |anaglyph "$param" "$tmp" /dev/stdin /dev/stdout |convert -depth 8 -size "$geom" rgb:- "$stereo"