]> git.plutz.net Git - stereofy/blobdiff - stereofy.sh
swithed the meaning of the hjust parameter back so that the value accords to the...
[stereofy] / stereofy.sh
index 919c2a8ae183353037ab4e7d4453c50d5cc4b503..9b4fcffcf9ca0b5ba5dee49b0a99e9c32e64fd77 100755 (executable)
@@ -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 <http://www.gnu.org/licenses/>.
 
 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))
+  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"