ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/ran2tiff.csh
Revision: 2.3
Committed: Mon Aug 25 04:50:32 2008 UTC (15 years, 8 months ago) by greg
Content type: application/x-csh
Branch: MAIN
CVS Tags: rad4R1, rad4R0
Changes since 2.2: +1 -2 lines
Log Message:
Made temporary files safe from malicious attackers

File Contents

# Content
1 #!/bin/csh -fe
2 # Convert Radiance animation frames to TIFF output
3 #
4 set histosiz=200
5 set pfwt=0.9
6 set outdir=""
7 set pcopts=()
8 set tfopts=()
9 if (! $#argv) set argv=(DUMMY)
10 # Process options for pcond and ra_tiff
11 while ("$argv[1]" =~ -*)
12 switch ("$argv[1]")
13 case -W:
14 shift argv
15 set pfwt=$argv[1]
16 breaksw
17 case -H:
18 shift argv
19 set histof=$argv[1]:q
20 breaksw
21 case -D:
22 shift argv
23 if (! -d $argv[1]:q ) then
24 echo "Directory $argv[1] does not exist"
25 exit 1
26 endif
27 set outdir=$argv[1]:q/
28 breaksw
29 case -h*:
30 case -a*:
31 case -v*:
32 case -s*:
33 case -c*:
34 case -l*:
35 set pcopts=($pcopts $argv[1])
36 breaksw
37 case -u:
38 case -d:
39 case -f:
40 set pcopts=($pcopts $argv[1-2])
41 shift argv
42 breaksw
43 case -p:
44 shift argv
45 set pcopts=($pcopts -p $argv[1-6])
46 shift argv; shift argv; shift argv; shift argv; shift argv
47 breaksw
48 case -z:
49 case -b:
50 case -w:
51 set tfopts=($tfopts $argv[1])
52 breaksw
53 case -g:
54 shift argv
55 set tfopts=($tfopts -g $argv[1])
56 breaksw
57 default:
58 echo "$0: bad option: $argv[1]"
59 exit 1
60 endsw
61 shift argv
62 end
63 if ($#argv < 2) then
64 echo Usage: "$0 [-W prev_frame_wt][-H histo][-D dir][pcond opts][ra_tiff opts] frame1 frame2 .."
65 exit 1
66 endif
67 # Get shrunken image luminances
68 set vald=`mktemp -d /tmp/val.XXXXXX`
69 foreach inp ($argv:q)
70 set datf="$inp:t"
71 set datf="$vald/$datf:r.dat"
72 pfilt -1 -x 128 -y 128 -p 1 $inp:q \
73 | pvalue -o -h -H -b -df \
74 | rcalc -if1 -e 'L=$1*179;cond=L-1e-7;$1=log10(L)' \
75 > $datf:q
76 end
77 # Get Min. and Max. log values
78 set Lmin=`cat $vald/*.dat | total -l | rcalc -e '$1=$1-.01'`
79 set Lmax=`cat $vald/*.dat | total -u | rcalc -e '$1=$1+.01'`
80 if ($?histof) then
81 if (-r $histof) then
82 # Fix min/max and translate histogram
83 set Lmin=`sed -n '1p' $histof | rcalc -e 'min(a,b):if(a-b,b,a);$1=min($1,'"$Lmin)"`
84 set Lmax=`sed -n '$p' $histof | rcalc -e 'max(a,b):if(a-b,a,b);$1=max($1,'"$Lmax)"`
85 tabfunc -i hfunc < $histof > $vald/oldhist.cal
86 cnt $histosiz \
87 | rcalc -e "L10=$Lmin+($Lmax-$Lmin)/$histosiz"'*($1+.5)' \
88 -f $vald/oldhist.cal -e '$1=L10;$2=hfunc(L10)' \
89 > $vald/oldhisto.dat
90 endif
91 endif
92 foreach inp ($argv:q)
93 set datf="$inp:t"
94 set datf="$vald/$datf:r.dat"
95 set outp="$inp:t"
96 set outp="$outdir$outp:r.tif"
97 endif
98 histo $Lmin $Lmax $histosiz < $datf > $vald/newhisto.dat
99 if (-f $vald/oldhisto.dat) then
100 rlam $vald/newhisto.dat $vald/oldhisto.dat \
101 | rcalc -e '$1=$1;$2=$2+$4*'$pfwt \
102 > $vald/histo.dat
103 else
104 mv $vald/{new,}histo.dat
105 endif
106 pcond $pcopts -I $inp:q < $vald/histo.dat \
107 | ra_tiff $tfopts - $outp:q
108 mv $vald/{,old}histo.dat
109 end
110 if ($?histof) then
111 cp -f $vald/oldhisto.dat $histof
112 endif
113 rm -rf $vald