1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
|
#!/usr/bin/perl
use strict;
die "$0 [-c] <script> [test1 test2 ...]
-t Only test output files (do not generate panoramas, useful to know which test failed
-c Create reference files (should not be usually necessary)
<script> PTmender script
test_n Test to run. If none given all are done
jpeg, tiff, tifflze, tiffdeflate, tiff_m tiff_mask, psd, psd_nomask
\n " if scalar(@ARGV) < 1;
my $stitcher = '../../tools/PTmender';
#my $stitcher = '/usr/local/bin/PTmender';
$, = ' ';
my $arg = shift;
## make sure directories exist
mkdir('./tests');
my $createNewReferences = 0;
my $onlyTest = 0;
while (substr($arg,0,1) eq "-") {
if ($arg eq "-c") {
mkdir('./reference');
$createNewReferences = 1;
} elsif ($arg eq "-t") {
$onlyTest = 1;
}
$arg = shift;
}
open (IN, $arg) || die "Unable to open script $arg\n";
my $found = 0;
my $outputFormat;
my $pre;
my $post;
my $images = 0;
while (<IN>) {
if (/^o/) {
$images ++;
}
if (/^p/) {
# this is the output line
$outputFormat = $_;
$found = 1;
} else {
if (! $found) {
$pre .= $_;
} else {
$post .= $_;
}
}
}
close IN;
my %formats = (
# 'jpeg' => "JPEG q100 g01", # jpeg progressive scan
# 'tiff_none' => "TIFF c:NONE", # simple tiff output
# 'tiff_lzw' => "TIFF c:LZW", # simple tiff output
# 'tiff_deflate' => "TIFF c:DEFLATE", # simple tiff output
'tiff_m' => "TIFF_m", #
# 'tiff_mask' => "TIFF_mask",
'tiff_m_cropped' => "TIFF_m r:CROP",
'tiff_m_uncropped' => "TIFF_m r:UNCROP",
# 'psd' => "PSD",
# 'psd_nomask' => "PSD_nomask",
# 'psd_mask' => "PSD_mask",
# "xinvalid" => 'invalid',
);
my %outputFile = (
'jpeg' => "output.jpg",
'tiff_none' => "output.tif",
'tiff_lzw' => "output.tif",
'tiff_deflate' => "output.tif",
'psd' => "output.psd",
'psd_nomask' => "output.psd",
'psd_mask' => "output.psd",
);
my %savedFile = (
"jpeg" => "jpeg.jpg",
"psd_nomask" => "psd_no_mask.psd",
'psd_mask' => "psd_mask.psd",
"psd" => "psd.psd",
"tiff_none" => "tiff_none.tif",
"tiff_lzw" => "tiff_lzw.tif",
"tiff_deflate" => "tiff_deflate.tif",
);
my $type;
if ($outputFormat =~ /n"/) { #"
$outputFormat = $` ; #`
}
print "Processing $images images\n";
# WHat types of images do we generate? by default all, otherwise use command line parameters
my @toProcess;
if (scalar(@ARGV) > 0 ) {
@toProcess = @ARGV;
print "To perform tests: ", @toProcess , "\n\n";
} else {
@toProcess = sort keys (%formats);
print "To perform all tests: ", @toProcess, "\n\n";
}
# Where do we put the output files?
my $destination;
if ($createNewReferences) {
$destination = 'reference';
} else {
$destination = 'tests';
}
my $testsPassed = 0;
my $testsCount = 0;
foreach $type (@toProcess) {
$testsCount ++;
defined $formats{$type} || die "$type is not a defined test";
print "$type => Output : $formats{$type}\n";
if (! $onlyTest) {
Create_Script($type, $pre, $post, $outputFormat);
Remove_Images("output", "tif", $images, $destination, $type);
print "Creating panorama.. please wait\n";
system ($stitcher, '-o', 'output' , 'temp.txt');
Move_Images("output", "tif", $images, $destination, $type);
}
if (! $createNewReferences) {
my $output = "";
$output = Compare_Images("tif", $images, "tests", "reference", $type);
if ($output eq "") {
printf "\nTest $type................................. passed\n\n";
$testsPassed ++;
} else {
printf "\nTest $type................................. FAILED!!!\n\n";
}
}
}
if (!$createNewReferences) {
my $testsFailed = $testsCount - $testsPassed;
printf "\nSummary: $testsCount tests executed. $testsPassed passed ($testsFailed failed) %5.2f percent passed\n", $testsPassed * 100 /$testsCount;
if ($testsPassed != $testsCount ) {
die "BAD NEWS\n";
}
} else {
printf "\nSummary: $testsCount reference tests executed.\n";
}
sub Compare_Images
{
my ($extension, $count, $newVersion, $reference, $prefixOutput) =@_;
my $i= 0;
my $output;
print "Comparing reference images: $count\n";
for ($i=0; $i < $count; $i++ ) {
my $newFileName = sprintf("$newVersion/${prefixOutput}%04d.", $i) . $extension;
my $fileName = sprintf("$reference/${prefixOutput}%04d.", $i) . $extension;
print "$fileName -> $newFileName\n";
if (! -f "$newFileName") {
printf("Output file $newFileName was not created\n");
return "Output file $newFileName was not created\n";
}
if (! -f "$fileName") {
printf("Reference file $fileName does not exist\n");
return "Reference file $fileName does not exist\n";
}
if ($fileName =~ /\.tif$/) {
$output .= `tiffcmp $fileName $newFileName | grep -v 'Created by Panotools'`;
} else {
$output .= `diff $fileName $newFileName`;
}
}
return $output;
}
sub Move_Images
{
my ($prefix, $extension, $count, $destination, $prefixOutput) =@_;
my $i= 0;
print "Moving reference images: $count\n";
for ($i=0; $i < $count; $i++ ) {
my $fileName = sprintf("${prefix}%04d.", $i) . $extension;
my $newFileName = sprintf("$destination/${prefixOutput}%04d.", $i) . $extension;
print "$fileName -> $newFileName\n";
`mv -f $fileName $newFileName`;
}
}
sub Remove_Images
{
my ($prefix, $extension, $count, $destination, $prefixOutput) =@_;
my $i= 0;
print "Removing old images: $count\n";
for ($i=0; $i < $count; $i++ ) {
my $fileName = sprintf("${prefix}%04d.", $i) . $extension;
my $newFileName = sprintf("$destination/${prefixOutput}%04d.", $i) . $extension;
print "$fileName -> $newFileName\n";
`rm -f $newFileName`;
}
}
sub Create_Script
{
my ($type, $pre, $post, $outputFormat) = @_;
open OUT, ">temp.txt" || die "unable to create output script temp.txt\n";
print OUT $pre;
print OUT "$outputFormat n\"$formats{$type}\"\n";
print OUT $post;
close OUT;
}
sub execute
{
my ($c) = @_;
`$c`;
my $status = ($? >> 8);
die "execution of program [$c] failed: status [$status]" if ($status != 0);
}
|