# HG changeset patch # User Axel Jacobs # Date 1323644522 0 # Node ID 02f1d30160d057b5639364c305f93c4679ba043b # Parent ea86d26c63edb283a7626fb6c484db46809560eb Started compamb diff -r ea86d26c63ed -r 02f1d30160d0 bin/compamb.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/compamb.pl Sun Dec 11 23:02:02 2011 +0000 @@ -0,0 +1,86 @@ +#!/bin/perl +# RCSid: $Id: compamb.csh,v 3.7 2008/08/25 04:50:32 greg Exp $ +# +# Compute best ambient value for a scene and append to rad input file +# This is a re-write of Greg's CSH script compamb.csh +# (c) Axel Jacobs, Nov 2011 + +use strict; +use warnings; +use File::Temp qw/ tempdir /; + +my $doexpos = 0; +my $docolor = 0; +my $radfile; +my $oct; + +sub usage() { + print "Usage: $0 [-e] [-c] rad_input_file.rad\n"; + exit 1; +} + +while ($#ARGV > 0) { + $_ = shift @ARGV; + if (m/-e/) { + $doexpos = 1; + } elsif (m/-c/) { + $docolor = 1; + } else { + &usage; + } +} + +if ($#ARGV == 0) { + $radfile = $ARGV[0]; + if (! -f $radfile) { + die ("Cannot open Radiance input file $ARGV[0]\n"); + } +} else { + &usage; +} + +my $td = tempdir( CLEANUP => 1 ); +#set oct=`rad -w -s -e -v 0 $argv[1] QUA=High AMB=$tf.amb OPT=$tf.opt | sed -n 's/^OCTREE= //p'` +my $radout = `rad -w -s -e -v 0 $radfile QUA=High AMB=$td/compamb.amb OPT=$td/compamb.opt`; +exit 1; +#...my $oct = sed -n 's/^OCTREE= //p'` +my $rpictargs = '-av 0 0 0 -aw 16 -dv- -S 1 -x 16 -y 16 -ps 1'; +system "rad -n -s -V $radfile | rpict @$td/compamb.opt $rpictargs $oct | ra_rgbe - '\!pvalue -h -H -d' > $td/compamb.dat"; +#rad -n -s -V $argv[1] \ + #| rpict @$tf.opt -av 0 0 0 -aw 16 -dv- -S 1 -x 16 -y 16 -ps 1 $oct \ + #| ra_rgbe - '\!pvalue -h -H -d' > $tf.dat + +#echo \# Rad input file modified by $0 `date` >> $argv[1] +my $now = localtime(); +open (FHrad, ">>$radfile") or + die("Unable to append to file $radfile\n"); +print FHrad "# Rad input file modified by $0 $now"; + +if ($doexpos == 1) { + my $expo = `total -u $td/compamb.dat | rcalc -e '$1=2/(.265*$1+.670*$2+.065*$3)'`; + #chomp $expo; + #(echo -n 'EXPOSURE= '; \ + #total -u $tf.dat | rcalc -e '$1=2/(.265*$1+.670*$2+.065*$3)') \ + #>> $argv[1] + print FHrad "EXPOSURE= $expo\n"; +} + +#lookamb -h -d $tf.amb | rcalc -e '$1=$10;$2=$11;$3=$12' >> $tf.dat +system ("lookamb -h -d $td/compamb.amb | rcalc -e '$1=$10;$2=$11;$3=$12' >> $td/compamb.dat"); + +#set lavg=`rcalc -e '$1=lum;lum=.265*$1+.670*$2+.065*$3;cond=lum-1e-5' $tf.dat | total -m -p` +my $lavg = `rcalc -e '$1=lum;lum=.265*$1+.670*$2+.065*$3;cond=lum-1e-5' $td/compamb.dat | total -m -p`; + +my $av = "$lavg $lavg $lavg"; +if ($docolor == 1) { + my $cavg = `total -m $td/compamb.dat`; + my ($ravg, $gavg, $bavg) = split(/\t/, $cavg); + my $sf = $lavg / (.265*$ravg + .670*$gavg + .065*$bavg); + #my $av = `rcalc -n -e "r=$ravg;g=$gavg;b=$bavg;sf=$lavg/(.265*r+.670*g+.065*b)" -e '$1=sf*r;$2=sf*g;$3=sf*b'`) + my $av = "$sf*$ravg $sf*$gavg $sf*$bavg"; +} + +print FHrad "render= -av $av"; +close (FHrad); + +#EOF diff -r ea86d26c63ed -r 02f1d30160d0 status/compamb.status --- a/status/compamb.status Sun Dec 11 23:01:21 2011 +0000 +++ b/status/compamb.status Sun Dec 11 23:02:02 2011 +0000 @@ -9,5 +9,5 @@ # 3 .. port is complete and fully tested (comprehensive test script(s) under tests/) # 4 .. port has been included in Radiance HEAD -STATUS = 0 +STATUS = 1