| author | Axel Jacobs <axel@jaloxa.eu> |
| Mon, 14 Apr 2014 22:21:17 +0100 | |
| changeset 73 | 87fa3132a136 |
| parent 22 | 617fa1f9ccb3 |
| permissions | -rw-r--r-- |
| 16 | 1 |
#!/usr/bin/perl |
2 |
||
|
17
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
3 |
# falsecolor_test.pl |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
4 |
# This file is part of the testsuite of the Radiance csh2perl project. |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
5 |
# You may copy and modify this file as basis for other tests. |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
6 |
# |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
7 |
# (c) Axel Jacobs, 26 June 2011 |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
8 |
|
| 16 | 9 |
use strict; |
10 |
use warnings; |
|
11 |
||
12 |
my $script = "falsecolor"; |
|
| 20 | 13 |
my $csh = "../orig/$script.csh"; |
14 |
my $perl = "../bin/$script.perl"; |
|
| 16 | 15 |
print "script: $script\n"; |
16 |
||
17 |
use File::Temp qw/ tempdir /; |
|
18 |
my $tmpdir = tempdir( CLEANUP => 0 ); |
|
19 |
||
20 |
my $img = "data/images/street-rgbe_rle_400x400.hdr"; |
|
21 |
||
|
17
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
22 |
# Options are arrays of [STDIN, command-line options]. |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
23 |
# Please include the pipe symbol as part of STDIN. |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
24 |
# Put a leading space in front of STDIN to line up the output. |
| 16 | 25 |
my @options = ( |
|
17
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
26 |
["", "-ip $img"], |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
27 |
["", "-ip $img -l cd/m2"], # Label now defaults to cd/m2, not nits. |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
28 |
["", "-i $img -p $img -l cd/m2"], |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
29 |
["", "-ip $img -cl -l cd/m2"], |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
30 |
["", "-ip $img -n 10 -l cd/m2"], |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
31 |
["", "-ip $img -s 2000 -l cd/m2"], |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
32 |
[" cat $img |", "-ip - -s 2000 -l cd/m2"], # take image from STDIN. |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
33 |
["", "-ip $img -lw 200 -lh 300 -l cd/m2"], # scale is slightly higher now. |
| 16 | 34 |
); |
35 |
||
36 |
# Run old CSH and new Perl script with different options, |
|
37 |
# compare the resulting images. |
|
|
17
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
38 |
my $total = 0; |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
39 |
my $fail = 0; |
| 16 | 40 |
my $index = 0; |
|
17
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
41 |
my $opts; |
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
42 |
foreach $opts (@options) {
|
|
22
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
43 |
my $stdin = @$opts[0]; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
44 |
my $args = @$opts[1]; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
45 |
$total++; |
|
17
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
46 |
|
|
22
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
47 |
my $cshout = "$tmpdir/${script}_csh$index.hdr";
|
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
48 |
my $cshcmd = "$script.csh $args > $cshout"; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
49 |
print " $stdin $cshcmd\n"; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
50 |
system "$stdin csh ../orig/$cshcmd"; |
| 16 | 51 |
|
|
22
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
52 |
my $perlout = "$tmpdir/${script}_perl$index.hdr";
|
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
53 |
my $perlcmd = "$script.pl $args > $perlout"; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
54 |
print " $stdin $perlcmd\n"; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
55 |
system "$stdin perl ../bin/$perlcmd"; |
| 16 | 56 |
|
|
22
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
57 |
my $diffimg = "$tmpdir/${script}_diff$index.hdr";
|
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
58 |
my $uval = &compare_images("$cshout", "$perlout", "$diffimg");
|
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
59 |
if( $uval > 0 ) {
|
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
60 |
print " Error: Diff image $diffimg contains $uval unique values (should be one).\n"; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
61 |
system "ximage $diffimg"; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
62 |
$fail++; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
63 |
} else {
|
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
64 |
print " Ok: Images $cshout and $perlout are identical.\n"; |
|
617fa1f9ccb3
Removed excessive indentation in falsecolor_test.
Axel Jacobs <axel@jaloxa.eu>
parents:
20
diff
changeset
|
65 |
} |
| 16 | 66 |
} |
|
17
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
67 |
|
|
e4ebb10e4697
Added configurabe STDIN to falsecolor test.
Axel Jacobs <axel@jaloxa.eu>
parents:
16
diff
changeset
|
68 |
print "$fail of $total tests failed.\n"; |
| 16 | 69 |
print "temp dir $tmpdir not removed. Please remove manually.\n"; |
70 |
||
71 |
sub compare_images() {
|
|
72 |
my $in1 = shift; |
|
73 |
my $in2 = shift; |
|
74 |
my $out = shift; |
|
75 |
||
76 |
my $cmd = "pcomb $in1 -s -1 $in2 > $out"; |
|
77 |
print " $cmd\n"; |
|
78 |
system "$cmd"; |
|
79 |
my $unique = `pvalue -h -H -d -u $out`; |
|
80 |
my $unique_cnt = scalar( split( '\n', $unique ) ); |
|
81 |
||
82 |
return $unique_cnt; |
|
83 |
} |
|
84 |
||
85 |
#EOF |