X-Git-Url: http://git.plutz.net/?p=stereofy;a=blobdiff_plain;f=stereofy.sh;h=4e2da59f3e5077b3acc85307fd7557c23e6a4a0c;hp=919c2a8ae183353037ab4e7d4453c50d5cc4b503;hb=88e97b55f03b5bcb3d12b673f74a1e68296060cd;hpb=749ec4ad5ec7d49addeaffec4241cabc3c6f2833 diff --git a/stereofy.sh b/stereofy.sh index 919c2a8..4e2da59 100755 --- a/stereofy.sh +++ b/stereofy.sh @@ -1,30 +1,46 @@ #!/bin/sh +# Copyright 2011 Paul Hänsch +# This file is part of Stereofy +# +# Stereofy is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Stereofy is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Stereofy. If not, see . algo="d" #algorythm, Dubois by default -model="gm" #color model, green-magenta 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" - ;; - -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|-[fd]mc|-dab) param="$1" - ;; + -d|--dubois) algo="d";; + -f|--full|--full-color) algo="f";; + -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" elif [ -z "$right" ]; then @@ -37,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)) + rhoff=$(($hor / 2)) +elif [ "$hor" -lt 0 ]; then + width=$(($width - $hor / -2)) + lhoff=$(($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"