X-Git-Url: http://git.plutz.net/?p=stereofy;a=blobdiff_plain;f=stereofy.sh;h=9b4fcffcf9ca0b5ba5dee49b0a99e9c32e64fd77;hp=a97e5b9af09fc74855680a4620d4e45d3bb1e987;hb=HEAD;hpb=53fedd7fc9e7a2c1eb31bf03b231241950ebb516 diff --git a/stereofy.sh b/stereofy.sh index a97e5b9..9b4fcff 100755 --- a/stereofy.sh +++ b/stereofy.sh @@ -18,20 +18,28 @@ 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 -d|--dubois) algo="d";; -f|--full|--full-color) algo="f";; - -h|--half|--half-color) algo="d";; + -h|--half|--half-color) algo="h";; -rc|--rc|--red-cyan) model="rc";; -mc|--mc|--magenta-cyan) model="mc";; -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" @@ -45,22 +53,57 @@ while [ -n "$1" ]; do shift 1; done +if [ "$model" = 'mc' -a "$algo" != 'f' ]; then + echo 'INFO: using experimental color optimizations for magenta cyan anaglyph images.' + echo ' Specify --full to generate a full-color magenta cyan image.' + algo="e" +fi + +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 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) -echo -n bitmapping... -stream "$left" "$left.bts" -stream "$right" "$right.bts" +if [ "$vert" -gt 0 ]; then + height=$(($height - $vert / 2)) + rvoff=$(($vert / 2)) +elif [ "$vert" -lt 0 ]; then + height=$(($height - $vert / -2)) + lvoff=$(($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 anaglyphing... -anaglyph "$param" "$left.bts" "$right.bts" "$stereo.bts" +echo -n setup streaming... +tmp=$(tempfile -d /tmp -p strfy) +rm "$tmp" +mkfifo "$tmp" -if [ $? = 0 ]; then - echo -n converting... - convert -depth 8 -size "$geom" "rgb:$stereo.bts" "$stereo" -fi +convert "$left" -crop "$lcrop" rgb:- >"$tmp" & +echo -n anaglyphing... +convert "$right" -crop "$rcrop" rgb:- |anaglyph "$param" "$tmp" /dev/stdin /dev/stdout |convert -depth 8 -size "$geom" rgb:- "$stereo" echo cleaning... -rm "$left.bts" "$right.bts" "$stereo.bts" 2>/dev/null +rm "$tmp"