algo="d" #algorythm, Dubois by default
model="rc" #color model, red-cyan by default
param="" #leave blank, will be -$algo$model
-left=''
-right=''
-stereo=''
+left='' #left image filename
+right='' #right image file name
+stereo='' #output image file name
+vert=0 #vertical justification
+hor=0 #horizontal justification
+lvoff=0 #left image vertical crop offset
+rvoff=0 #right image vertical crop offset
+lhoff=0 #left image horizontal crop offset
+rhoff=0 #right image horizontal crop offset
while [ -n "$1" ]; do
case "$1" in
-gm|--gm|--green-magenta) model="gm";;
-ab|--ab|--amber-blue|--yellow-blue) model="ab";;
-[dfh]rc|-[dfh]gm|-[fe]mc|-dab) param="$1";;
+ --vjust|-ver|--ver|--vertical) shift 1; vert="$1";;
+ --hjust|-hor|--hor|--horizontal) shift 1; hor="$1";;
-*) echo "no such color model" >/dev/stderr; exit 1;;
*) if [ -z "$left" ]; then
left="$1"
esac
shift 1;
done
+if (echo $vert |egrep -qx '[+-]*[0-9]*[02468]'); then true
+else
+ echo 'vertical alignment must be an even number'
+ exit 1
+fi
+if (echo $hor |egrep -qx '[+-]*[0-9]*[02468]'); then true
+else
+ echo 'horizontal alignment must be an even number'
+ exit 1
+fi
[ -z "$param" ] && param="-$algo$model"
[ -z "$stereo" ] && stereo="${left}_stereo.jpg"
-echo -n preparing...
+echo -n calculating geometry...
geom=$(identify "$left" |sed -rn 's:^.* ([0-9]+x[0-9]+) .*$:\1:gp')
+width=$(echo $geom |cut -dx -f1)
+height=$(echo $geom |cut -dx -f2)
+
+if [ "$vert" -gt 0 ]; then
+ height=$(($height - $vert / 2))
+ lvoff=$(($vert / 3))
+elif [ "$vert" -lt 0 ]; then
+ height=$(($height - $vert / -2))
+ rvoff=$(($vert / -2))
+fi
+if [ "$hor" -gt 0 ]; then
+ width=$(($width - $hor / 2))
+ lhoff=$(($hor / 2))
+elif [ "$hor" -lt 0 ]; then
+ width=$(($width - $hor / -2))
+ rhoff=$(($hor / -2))
+fi
+geom="${width}x${height}"
+lcrop="${geom}+${lhoff}+${lvoff}"
+rcrop="${geom}+${rhoff}+${rvoff}"
+
+echo -n setup streaming...
tmp=$(tempfile -d /tmp -p strfy)
rm "$tmp"
mkfifo "$tmp"
-convert "$left" rgb:- >"$tmp" &
+convert "$left" -crop "$lcrop" rgb:- >"$tmp" &
echo -n anaglyphing...
-convert "$right" rgb:- |anaglyph "$param" "$tmp" /dev/stdin /dev/stdout |convert -depth 8 -size "$geom" rgb:- "$stereo"
+convert "$right" -crop "$rcrop" rgb:- |anaglyph "$param" "$tmp" /dev/stdin /dev/stdout |convert -depth 8 -size "$geom" rgb:- "$stereo"
echo cleaning...
rm "$tmp"