From 13cd4ea9ad63e0fb197922d84b6545c4e4b22c14 Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 10 Nov 2011 17:11:56 +0000 Subject: [PATCH] support for vertical and horizontal justification svn path=/trunk/; revision=8 --- stereofy.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/stereofy.sh b/stereofy.sh index 51cbfb1..9b54bb7 100755 --- a/stereofy.sh +++ b/stereofy.sh @@ -18,9 +18,15 @@ 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 @@ -32,6 +38,8 @@ while [ -n "$1" ]; do -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" @@ -44,19 +52,51 @@ while [ -n "$1" ]; do 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" -- 2.39.2