cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | # Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization |
| 2 | # dedicated to making software imaging solutions freely available. |
| 3 | # |
| 4 | # You may not use this file except in compliance with the License. You may |
| 5 | # obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.imagemagick.org/script/license.php |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | # |
| 15 | # |
| 16 | # Common subroutines to support tests |
| 17 | # |
| 18 | # Contributed by Bob Friesenhahn <bfriesen@simple.dallas.tx.us> |
| 19 | # |
| 20 | |
| 21 | # |
| 22 | # Test composite method using comparison with a reference image |
| 23 | # |
| 24 | # Usage: testFilterCompare( background image name, background read options, |
| 25 | # composite image name, composite read options, |
| 26 | # composite options,reference image |
| 27 | # normalized_mean_error, |
| 28 | # normalized_maximum_error ); |
| 29 | sub testCompositeCompare { |
| 30 | my ($background_name, |
| 31 | $background_read_options, |
| 32 | $composite_name, |
| 33 | $composite_read_options, |
| 34 | $composite_options, |
| 35 | $refimage_name, |
| 36 | $normalized_mean_error_max, |
| 37 | $normalized_maximum_error_max) = @_; |
| 38 | my ($background, |
| 39 | $composite, |
| 40 | $errorinfo, |
| 41 | $normalized_maximum_error, |
| 42 | $normalized_mean_error, |
| 43 | $refimage, |
| 44 | $status); |
| 45 | |
| 46 | $errorinfo=''; |
| 47 | $status=''; |
| 48 | |
| 49 | #print( $filter, " ...\n" ); |
| 50 | |
| 51 | # Create images |
| 52 | $background=Image::Magick->new; |
| 53 | $composite=Image::Magick->new; |
| 54 | $refimage=Image::Magick->new; |
| 55 | |
| 56 | # Read background image |
| 57 | if ( "$background_read_options" ne "" ) { |
| 58 | print("Set($background_read_options) ...\n"); |
| 59 | eval "\$status=\$background->Set($background_read_options);"; |
| 60 | if ("$status") |
| 61 | { |
| 62 | $errorinfo = "Set($background_read_options): $status"; |
| 63 | goto COMPARE_RUNTIME_ERROR; |
| 64 | } |
| 65 | } |
| 66 | $status=$background->ReadImage($background_name); |
| 67 | if ("$status") |
| 68 | { |
| 69 | $errorinfo = "Readimage ($background_name): $status"; |
| 70 | goto COMPARE_RUNTIME_ERROR; |
| 71 | } |
| 72 | |
| 73 | # Read composite image |
| 74 | if ( "$composite_read_options" ne "" ) { |
| 75 | print("Set($composite_read_options) ...\n"); |
| 76 | eval "\$status=\$composite->Set($composite_read_options);"; |
| 77 | if ("$status") |
| 78 | { |
| 79 | $errorinfo = "Set($composite_read_options): $status"; |
| 80 | goto COMPARE_RUNTIME_ERROR; |
| 81 | } |
| 82 | } |
| 83 | $status=$composite->ReadImage($composite_name); |
| 84 | if ("$status") |
| 85 | { |
| 86 | $errorinfo = "Readimage ($composite_name): $status"; |
| 87 | goto COMPARE_RUNTIME_ERROR; |
| 88 | } |
| 89 | |
| 90 | # Do composition |
| 91 | print("Composite\($composite_options\) ...\n"); |
| 92 | eval "\$status=\$background->Composite(image=>\$composite, $composite_options);"; |
| 93 | if ("$status") |
| 94 | { |
| 95 | $errorinfo = "Composite ($composite_options): $status"; |
| 96 | goto COMPARE_RUNTIME_ERROR; |
| 97 | } |
| 98 | |
| 99 | $background->set(depth=>8); |
| 100 | # if ("$filter" eq "Atop") { |
| 101 | # $background->write(filename=>"$refimage_name", compression=>'None'); |
| 102 | # $background->Display(); |
| 103 | # } |
| 104 | |
| 105 | $status=$refimage->ReadImage("$refimage_name"); |
| 106 | if ("$status") |
| 107 | { |
| 108 | $errorinfo = "Readimage ($refimage_name): $status"; |
| 109 | goto COMPARE_RUNTIME_ERROR; |
| 110 | } |
| 111 | |
| 112 | $status=$background->Difference($refimage); |
| 113 | if ("$status") |
| 114 | { |
| 115 | $errorinfo = "Difference($refimage_name): $status"; |
| 116 | print(" Reference: ", $refimage->Get('columns'), "x", $refimage->Get('rows'), "\n"); |
| 117 | print(" Computed: ", $background->Get('columns'), "x", $background->Get('rows'), "\n"); |
| 118 | goto COMPARE_RUNTIME_ERROR; |
| 119 | } |
| 120 | |
| 121 | $normalized_mean_error=0; |
| 122 | $normalized_mean_error=$background->GetAttribute('mean-error'); |
| 123 | if ( !defined($normalized_mean_error) ) |
| 124 | { |
| 125 | $errorinfo = "GetAttribute('mean-error') returned undefined value!"; |
| 126 | goto COMPARE_RUNTIME_ERROR; |
| 127 | } |
| 128 | $normalized_maximum_error=0; |
| 129 | $normalized_maximum_error=$background->GetAttribute('maximum-error'); |
| 130 | if ( ! defined($normalized_maximum_error) ) |
| 131 | { |
| 132 | $errorinfo = "GetAttribute('maximum-error') returned undefined value!"; |
| 133 | goto COMPARE_RUNTIME_ERROR; |
| 134 | } |
| 135 | if ( ($normalized_mean_error > $normalized_mean_error_max) || |
| 136 | ($normalized_maximum_error > $normalized_maximum_error_max) ) |
| 137 | { |
| 138 | print(" mean-error=$normalized_mean_error, maximum-error=$normalized_maximum_error\n"); |
| 139 | print "not ok $test\n"; |
| 140 | $background->Display(); |
| 141 | undef $background; |
| 142 | undef $composite; |
| 143 | undef $refimage; |
| 144 | return 1 |
| 145 | } |
| 146 | |
| 147 | undef $background; |
| 148 | undef $composite; |
| 149 | undef $refimage; |
| 150 | print "ok $test\n"; |
| 151 | return 0; |
| 152 | |
| 153 | COMPARE_RUNTIME_ERROR: |
| 154 | undef $background; |
| 155 | undef $composite; |
| 156 | undef $refimage; |
| 157 | print(" $errorinfo\n"); |
| 158 | print "not ok $test\n"; |
| 159 | return 1 |
| 160 | } |
| 161 | |
| 162 | # |
| 163 | # Test reading a 16-bit file in which two signatures are possible, |
| 164 | # depending on whether 16-bit pixels data has been enabled |
| 165 | # |
| 166 | # Usage: testRead( read filename, expected ref_8 [, expected ref_16] [, expected ref_32] ); |
| 167 | # |
| 168 | sub testRead { |
| 169 | my( $infile, $ref_8, $ref_16, $ref_32 ) = @_; |
| 170 | |
| 171 | my($image,$magick,$success,$ref_signature); |
| 172 | |
| 173 | $failure=0; |
| 174 | |
| 175 | if ( !defined( $ref_16 ) ) |
| 176 | { |
| 177 | $ref_16 = $ref_8; |
| 178 | } |
| 179 | if ( !defined( $ref_32 ) ) |
| 180 | { |
| 181 | $ref_32 = $ref_16; |
| 182 | } |
| 183 | |
| 184 | if (QuantumDepth == 32) |
| 185 | { |
| 186 | $ref_signature=$ref_32; |
| 187 | } |
| 188 | elsif (QuantumDepth == 16) |
| 189 | { |
| 190 | $ref_signature=$ref_16; |
| 191 | } |
| 192 | else |
| 193 | { |
| 194 | $ref_signature=$ref_8; |
| 195 | } |
| 196 | |
| 197 | $magick=''; |
| 198 | |
| 199 | # |
| 200 | # Test reading from file |
| 201 | # |
| 202 | { |
| 203 | my($image, $signature, $status); |
| 204 | |
| 205 | print( " testing reading from file \"", $infile, "\" ...\n"); |
| 206 | $image=Image::Magick->new; |
| 207 | $image->Set(size=>'512x512'); |
| 208 | $status=$image->ReadImage("$infile"); |
| 209 | if( "$status" && !($status =~ /Exception ((315)|(350))/)) { |
| 210 | print "ReadImage $infile: $status\n"; |
| 211 | ++$failure; |
| 212 | } else { |
| 213 | if( "$status" ) { |
| 214 | print "ReadImage $infile: $status\n"; |
| 215 | } |
| 216 | undef $status; |
| 217 | $magick=$image->Get('magick'); |
| 218 | $signature=$image->Get('signature'); |
| 219 | |
| 220 | if ( $signature ne $ref_signature ) { |
| 221 | print "ReadImage()\n"; |
| 222 | print "Image: $infile, signatures do not match.\n"; |
| 223 | print " Expected: $ref_signature\n"; |
| 224 | print " Computed: $signature\n"; |
| 225 | print " Depth: ", QuantumDepth, "\n"; |
| 226 | ++$failure; |
| 227 | $image->Display(); |
| 228 | } |
| 229 | } |
| 230 | undef $image; |
| 231 | } |
| 232 | |
| 233 | # |
| 234 | # Test reading from blob |
| 235 | # |
| 236 | if (!($infile =~ /\.bz2$/) && !($infile =~ /\.gz$/) && !($infile =~ /\.Z$/)) |
| 237 | { |
| 238 | my(@blob, $blob_length, $image, $signature, $status); |
| 239 | |
| 240 | if( open( FILE, "< $infile")) |
| 241 | { |
| 242 | print( " testing reading from BLOB with magick \"", $magick, "\"...\n"); |
| 243 | binmode( FILE ); |
| 244 | $blob_length = read( FILE, $blob, 10000000 ); |
| 245 | close( FILE ); |
| 246 | if( defined( $blob ) ) { |
| 247 | $image=Image::Magick->new(magick=>$magick); |
| 248 | $status=$image->BlobToImage( $blob ); |
| 249 | undef $blob; |
| 250 | if( "$status" && !($status =~ /Exception ((315)|(350))/)) { |
| 251 | print "BlobToImage $infile: $status\n"; |
| 252 | ++$failure; |
| 253 | } else { |
| 254 | if( "$status" ) { |
| 255 | print "ReadImage $infile: $status\n"; |
| 256 | } |
| 257 | $signature=$image->Get('signature'); |
| 258 | if ( $signature ne $ref_signature ) { |
| 259 | print "BlobToImage()\n"; |
| 260 | print "Image: $infile, signatures do not match.\n"; |
| 261 | print " Expected: $ref_signature\n"; |
| 262 | print " Computed: $signature\n"; |
| 263 | print " Depth: ", QuantumDepth, "\n"; |
| 264 | #$image->Display(); |
| 265 | ++$failure; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | undef $image; |
| 271 | } |
| 272 | |
| 273 | # |
| 274 | # Display test status |
| 275 | # |
| 276 | if ( $failure != 0 ) { |
| 277 | print "not ok $test\n"; |
| 278 | } else { |
| 279 | print "ok $test\n"; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | |
| 284 | # |
| 285 | # Test reading a file, and compare with a reference file |
| 286 | # |
| 287 | sub testReadCompare { |
| 288 | my( $srcimage_name,$refimage_name, $read_options, |
| 289 | $normalized_mean_error_max, $normalized_maximum_error_max) = @_; |
| 290 | my($srcimage, $refimage, $normalized_mean_error, $normalized_maximum_error); |
| 291 | |
| 292 | $errorinfo=''; |
| 293 | |
| 294 | # Create images |
| 295 | $srcimage=Image::Magick->new; |
| 296 | $refimage=Image::Magick->new; |
| 297 | |
| 298 | if ( "$read_options" ne "" ) { |
| 299 | eval "\$status=\$srcimage->Set($read_options);"; |
| 300 | if ("$status") |
| 301 | { |
| 302 | $errorinfo = "Set($read_options): $status"; |
| 303 | warn("$errorinfo"); |
| 304 | goto COMPARE_RUNTIME_ERROR; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | $status=$srcimage->ReadImage("$srcimage_name"); |
| 309 | if ("$status") |
| 310 | { |
| 311 | $errorinfo = "Readimage ($srcimage_name): $status"; |
| 312 | warn("$errorinfo"); |
| 313 | goto COMPARE_RUNTIME_ERROR; |
| 314 | } |
| 315 | |
| 316 | # if ("$srcimage_name" eq "input.tim") { |
| 317 | # $srcimage->write(filename=>"$refimage_name", compression=>'None'); |
| 318 | # } |
| 319 | |
| 320 | #print("writing file $refimage_name\n"); |
| 321 | #$srcimage->Quantize(colors=>256); |
| 322 | #$status=$srcimage->write(filename=>"$refimage_name", compression=>'rle'); |
| 323 | #warn "$status" if $status; |
| 324 | |
| 325 | $status=$refimage->ReadImage("$refimage_name"); |
| 326 | if ("$status") |
| 327 | { |
| 328 | $errorinfo = "Readimage ($refimage_name): $status"; |
| 329 | warn("$errorinfo"); |
| 330 | goto COMPARE_RUNTIME_ERROR; |
| 331 | } |
| 332 | |
| 333 | $srcimage->set(depth=>8); |
| 334 | |
| 335 | # FIXME: The following statement should not be needed. |
| 336 | # $status=$refimage->Set(type=>'TrueColor'); |
| 337 | # if ("$status") |
| 338 | # { |
| 339 | # $errorinfo = "Set(type=>'TrueColor'): $status"; |
| 340 | # goto COMPARE_RUNTIME_ERROR; |
| 341 | # } |
| 342 | |
| 343 | # Verify that $srcimage and $refimage contain the same number of frames. |
| 344 | if ( $#srcimage != $#refimage ) |
| 345 | { |
| 346 | $errorinfo = "Source and reference images contain different number of frames ($#srcimage != $#refimage)"; |
| 347 | warn("$errorinfo"); |
| 348 | goto COMPARE_RUNTIME_ERROR; |
| 349 | } |
| 350 | |
| 351 | # Compare each frame in the sequence. |
| 352 | for ($index = 0; $srcimage->[$index] && $refimage->[$index]; $index++) |
| 353 | { |
| 354 | $status=$srcimage->[$index]->Difference($refimage->[$index]); |
| 355 | if ("$status") |
| 356 | { |
| 357 | $errorinfo = "Difference($refimage_name)->[$index]: $status"; |
| 358 | warn("$errorinfo"); |
| 359 | goto COMPARE_RUNTIME_ERROR; |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | |
| 364 | $normalized_mean_error=0; |
| 365 | $normalized_mean_error=$srcimage->GetAttribute('mean-error'); |
| 366 | if ( !defined($normalized_mean_error) ) |
| 367 | { |
| 368 | $errorinfo = "GetAttribute('mean-error') returned undefined value!"; |
| 369 | warn("$errorinfo"); |
| 370 | goto COMPARE_RUNTIME_ERROR; |
| 371 | } |
| 372 | $normalized_maximum_error=0; |
| 373 | $normalized_maximum_error=$srcimage->GetAttribute('maximum-error'); |
| 374 | if ( ! defined($normalized_maximum_error) ) |
| 375 | { |
| 376 | $errorinfo = "GetAttribute('maximum-error') returned undefined value!"; |
| 377 | warn("$errorinfo"); |
| 378 | goto COMPARE_RUNTIME_ERROR; |
| 379 | } |
| 380 | if ( ($normalized_mean_error > $normalized_mean_error_max) || |
| 381 | ($normalized_maximum_error > $normalized_maximum_error_max) ) |
| 382 | { |
| 383 | print("mean-error=$normalized_mean_error, maximum-error=$normalized_maximum_error\n"); |
| 384 | #$srcimage->Display(); |
| 385 | print "not ok $test\n"; |
| 386 | return 1 |
| 387 | } |
| 388 | |
| 389 | undef $srcimage; |
| 390 | undef $refimage; |
| 391 | print "ok $test\n"; |
| 392 | return 0; |
| 393 | |
| 394 | COMPARE_RUNTIME_ERROR: |
| 395 | undef $srcimage; |
| 396 | undef $refimage; |
| 397 | print "not ok $test\n"; |
| 398 | return 1 |
| 399 | } |
| 400 | |
| 401 | # |
| 402 | # Test reading a file which requires a file size to read (GRAY, RGB, CMYK) |
| 403 | # or supports multiple resolutions (JBIG, JPEG, PCD) |
| 404 | # |
| 405 | # Usage: testRead( read filename, size, depth, expected ref_8 [, expected ref_16] [, expected ref_32] ); |
| 406 | # |
| 407 | sub testReadSized { |
| 408 | my( $infile, $size, $ref_8, $ref_16, $ref_32 ) = @_; |
| 409 | |
| 410 | my($image,$ref_signature); |
| 411 | |
| 412 | if ( !defined( $ref_16 ) ) |
| 413 | { |
| 414 | $ref_16 = $ref_8; |
| 415 | } |
| 416 | if ( !defined( $ref_32 ) ) |
| 417 | { |
| 418 | $ref_32 = $ref_16; |
| 419 | } |
| 420 | |
| 421 | if (QuantumDepth == 32) |
| 422 | { |
| 423 | $ref_signature=$ref_32; |
| 424 | } |
| 425 | elsif (QuantumDepth == 16) |
| 426 | { |
| 427 | $ref_signature=$ref_16; |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | $ref_signature=$ref_8; |
| 432 | } |
| 433 | |
| 434 | $image=Image::Magick->new; |
| 435 | |
| 436 | # Set size attribute |
| 437 | $status=$image->SetAttribute(size=>"$size"); |
| 438 | warn "$status" if "$status"; |
| 439 | |
| 440 | # If depth is not zero, then set it |
| 441 | if ( QuantumDepth != 0 ) { |
| 442 | $status=$image->SetAttribute(depth=>QuantumDepth); |
| 443 | warn "$status" if "$status"; |
| 444 | } |
| 445 | |
| 446 | $status=$image->ReadImage("$infile"); |
| 447 | if( "$status" ) { |
| 448 | print "ReadImage $infile: $status"; |
| 449 | print "not ok $test\n"; |
| 450 | } else { |
| 451 | $signature=$image->Get('signature'); |
| 452 | if ( $signature ne $ref_signature ) { |
| 453 | print "ReadImage()\n"; |
| 454 | print "Image: $infile, signatures do not match.\n"; |
| 455 | print " Expected: $ref_signature\n"; |
| 456 | print " Computed: $signature\n"; |
| 457 | print " Depth: ", QuantumDepth, "\n"; |
| 458 | print "not ok $test\n"; |
| 459 | #$image->Display(); |
| 460 | } else { |
| 461 | print "ok $test\n"; |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | # |
| 467 | # Test writing a file by first reading a source image, writing to a new image, |
| 468 | # reading the written image, and comparing with expected REF_8. |
| 469 | # |
| 470 | # Usage: testReadWrite( read filename, write filename, write options, |
| 471 | # expected ref_8 [, expected ref_16] ); |
| 472 | # |
| 473 | # .e.g |
| 474 | # |
| 475 | # testReadWrite( 'input.jpg', 'output.jpg', q/quality=>80, interlace=>'None'/, |
| 476 | # 'dc0a144a0b9480cd1e93757a30f01ae3' ); |
| 477 | # |
| 478 | # If the REF_8 of the written image is not what is expected, the written |
| 479 | # image is preserved. Otherwise, the written image is removed. |
| 480 | # |
| 481 | sub testReadWrite { |
| 482 | my( $infile, $outfile, $writeoptions, $ref_8, $ref_16, $ref_32 ) = @_; |
| 483 | |
| 484 | my($image); |
| 485 | |
| 486 | if ( !defined( $ref_16 ) ) |
| 487 | { |
| 488 | $ref_16 = $ref_8; |
| 489 | } |
| 490 | if ( !defined( $ref_32 ) ) |
| 491 | { |
| 492 | $ref_32 = $ref_16; |
| 493 | } |
| 494 | |
| 495 | if (QuantumDepth == 32) |
| 496 | { |
| 497 | $ref_signature=$ref_32; |
| 498 | } |
| 499 | elsif (QuantumDepth == 16) |
| 500 | { |
| 501 | $ref_signature=$ref_16; |
| 502 | } |
| 503 | else |
| 504 | { |
| 505 | $ref_signature=$ref_8; |
| 506 | } |
| 507 | |
| 508 | $image=Image::Magick->new; |
| 509 | $status=$image->ReadImage("$infile"); |
| 510 | $signature=$image->Get('signature'); |
| 511 | if( "$status" ) { |
| 512 | print "ReadImage $infile: $status\n"; |
| 513 | print "not ok $test\n"; |
| 514 | } else { |
| 515 | # Write image to file |
| 516 | my $options = 'filename=>"$outfile", ' . "$writeoptions"; |
| 517 | #print "Using options: $options\n"; |
| 518 | eval "\$status=\$image->WriteImage( $options ) ;"; |
| 519 | if( $@ ) { |
| 520 | print "$@\n"; |
| 521 | print "not ok $test\n"; |
| 522 | exit 1; |
| 523 | } |
| 524 | if( "$status" ) { |
| 525 | print "WriteImage $outfile: $status\n"; |
| 526 | print "not ok $test\n"; |
| 527 | } else { |
| 528 | my($image); |
| 529 | |
| 530 | # Read image just written |
| 531 | $image=Image::Magick->new; |
| 532 | $status=$image->ReadImage("$outfile"); |
| 533 | if( "$status" ) { |
| 534 | print "ReadImage $outfile: $status\n"; |
| 535 | print "not ok $test\n"; |
| 536 | } else { |
| 537 | # Check signature |
| 538 | $signature=$image->Get('signature'); |
| 539 | if ( $signature ne $ref_signature ) { |
| 540 | print "ReadImage()\n"; |
| 541 | print "Image: $infile, signatures do not match.\n"; |
| 542 | print " Expected: $ref_signature\n"; |
| 543 | print " Computed: $signature\n"; |
| 544 | print " Depth: ", QuantumDepth, "\n"; |
| 545 | print "not ok $test\n"; |
| 546 | $image->Display(); |
| 547 | } else { |
| 548 | print "ok $test\n"; |
| 549 | ($file = $outfile) =~ s/.*://g; |
| 550 | #unlink "$file"; |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | # |
| 558 | # Test reading a file, and compare with a reference file |
| 559 | # |
| 560 | sub testReadWriteCompare { |
| 561 | my( $srcimage_name, $outimage_name, $refimage_name, |
| 562 | $read_options, $write_options, |
| 563 | $normalized_mean_error_max, $normalized_maximum_error_max) = @_; |
| 564 | my($srcimage, $refimage, $normalized_mean_error, |
| 565 | $normalized_maximum_error); |
| 566 | |
| 567 | $errorinfo=''; |
| 568 | |
| 569 | $image=Image::Magick->new; |
| 570 | $refimage=Image::Magick->new; |
| 571 | |
| 572 | # |
| 573 | # Read the initial image |
| 574 | # |
| 575 | $status=$image->ReadImage($srcimage_name); |
| 576 | if ("$status") |
| 577 | { |
| 578 | $errorinfo = "Readimage ($srcimage_name): $status"; |
| 579 | goto COMPARE_RUNTIME_ERROR; |
| 580 | } |
| 581 | |
| 582 | # |
| 583 | # Write image to output file |
| 584 | # |
| 585 | if ( "$write_options" ne "" ) { |
| 586 | eval "\$status=\$image->Set($write_options);"; |
| 587 | if ("$status") |
| 588 | { |
| 589 | $errorinfo = "Set($write_options): $status"; |
| 590 | goto COMPARE_RUNTIME_ERROR; |
| 591 | } |
| 592 | } |
| 593 | $image->Set(filename=>"$outimage_name"); |
| 594 | |
| 595 | $status=$image->WriteImage( ); |
| 596 | if ("$status") |
| 597 | { |
| 598 | $errorinfo = "WriteImage ($outimage_name): $status"; |
| 599 | goto COMPARE_RUNTIME_ERROR; |
| 600 | } |
| 601 | |
| 602 | undef $image; |
| 603 | $image=Image::Magick->new; |
| 604 | |
| 605 | # |
| 606 | # Read image from output file |
| 607 | # |
| 608 | if ( "$read_options" ne "" ) { |
| 609 | eval "\$status=\$image->Set($read_options);"; |
| 610 | if ("$status") |
| 611 | { |
| 612 | $errorinfo = "Set($read_options): $status"; |
| 613 | goto COMPARE_RUNTIME_ERROR; |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | $image->ReadImage("$outimage_name"); |
| 618 | if ("$status") |
| 619 | { |
| 620 | $errorinfo = "WriteImage ($outimage_name): $status"; |
| 621 | goto COMPARE_RUNTIME_ERROR; |
| 622 | } |
| 623 | |
| 624 | # eval "\$status=\$image->Set($write_options);"; |
| 625 | #$status=$image->write(filename=>"$refimage_name", compression=>'None'); |
| 626 | # warn "$status" if $status; |
| 627 | |
| 628 | # |
| 629 | # Read reference image |
| 630 | # |
| 631 | $status=$refimage->ReadImage("$refimage_name"); |
| 632 | if ("$status") |
| 633 | { |
| 634 | $errorinfo = "Readimage ($refimage_name): $status"; |
| 635 | goto COMPARE_RUNTIME_ERROR; |
| 636 | } |
| 637 | |
| 638 | # |
| 639 | # Compare output file with reference image |
| 640 | # |
| 641 | |
| 642 | $image->set(depth=>8); |
| 643 | |
| 644 | # FIXME: The following statement should not be needed. |
| 645 | # $status=$refimage->Set(type=>'TrueColor'); |
| 646 | # if ("$status") |
| 647 | # { |
| 648 | # $errorinfo = "Set(type=>'TrueColor'): $status"; |
| 649 | # goto COMPARE_RUNTIME_ERROR; |
| 650 | # } |
| 651 | |
| 652 | $status=$image->Difference($refimage); |
| 653 | if ("$status") |
| 654 | { |
| 655 | $errorinfo = "Difference($refimage_name): $status"; |
| 656 | goto COMPARE_RUNTIME_ERROR; |
| 657 | } |
| 658 | |
| 659 | $normalized_mean_error=0; |
| 660 | $normalized_mean_error=$image->GetAttribute('mean-error'); |
| 661 | if ( !defined($normalized_mean_error) ) |
| 662 | { |
| 663 | $errorinfo = "GetAttribute('mean-error') returned undefined value!"; |
| 664 | goto COMPARE_RUNTIME_ERROR; |
| 665 | } |
| 666 | $normalized_maximum_error=0; |
| 667 | $normalized_maximum_error=$image->GetAttribute('maximum-error'); |
| 668 | if ( ! defined($normalized_maximum_error) ) |
| 669 | { |
| 670 | $errorinfo = "GetAttribute('maximum-error') returned undefined value!"; |
| 671 | goto COMPARE_RUNTIME_ERROR; |
| 672 | } |
| 673 | |
| 674 | if ( ($normalized_mean_error > $normalized_mean_error_max) || |
| 675 | ($normalized_maximum_error > $normalized_maximum_error_max) ) |
| 676 | { |
| 677 | print("mean-error=$normalized_mean_error, maximum-error=$normalized_maximum_error\n"); |
| 678 | print "not ok $test\n"; |
| 679 | return 1 |
| 680 | } |
| 681 | |
| 682 | print "ok $test\n"; |
| 683 | undef $image; |
| 684 | undef $refimage; |
| 685 | return 0; |
| 686 | |
| 687 | COMPARE_RUNTIME_ERROR: |
| 688 | warn("$errorinfo"); |
| 689 | print "not ok $test\n"; |
| 690 | undef $image; |
| 691 | undef $refimage; |
| 692 | return 1 |
| 693 | } |
| 694 | |
| 695 | # |
| 696 | # Test writing a file by first reading a source image, writing to a |
| 697 | # new image, and reading the written image. Depends on detecting |
| 698 | # reported errors by ImageMagick |
| 699 | # |
| 700 | # Usage: testReadWrite( read filename, write filename, write options); |
| 701 | # |
| 702 | # .e.g |
| 703 | # |
| 704 | # testReadWrite( 'input.jpg', 'output.jpg', q/quality=>80, 'interlace'=>'None'/ ); |
| 705 | # |
| 706 | # If the read of the written image is not what is expected, the |
| 707 | # written image is preserved. Otherwise, the written image is |
| 708 | # removed. |
| 709 | # |
| 710 | sub testReadWriteNoVerify { |
| 711 | my( $infile, $outfile, $writeoptions) = @_; |
| 712 | |
| 713 | my($image, $images); |
| 714 | |
| 715 | $image=Image::Magick->new; |
| 716 | $status=$image->ReadImage("$infile"); |
| 717 | if( "$status" ) { |
| 718 | print "$status\n"; |
| 719 | print "ReadImage $infile: not ok $test\n"; |
| 720 | } else { |
| 721 | # Write image to file |
| 722 | my $options = 'filename=>"$outfile", ' . $writeoptions; |
| 723 | #print "Using options: $options\n"; |
| 724 | eval "\$status=\$image->WriteImage( $options ) ;"; |
| 725 | if( $@ ) { |
| 726 | print "$@"; |
| 727 | print "not ok $test\n"; |
| 728 | exit 1; |
| 729 | } |
| 730 | if( "$status" ) { |
| 731 | print "WriteImage $outfile: $status\n"; |
| 732 | print "not ok $test\n"; |
| 733 | } else { |
| 734 | my($image); |
| 735 | |
| 736 | # Read image just written |
| 737 | $image=Image::Magick->new; |
| 738 | $status=$image->ReadImage("$outfile"); |
| 739 | if( "$status" ) { |
| 740 | print "ReadImage $outfile: $status\n"; |
| 741 | print "not ok $test\n"; |
| 742 | } else { |
| 743 | print "ok $test\n"; |
| 744 | unlink $outfile; |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | # |
| 751 | # Test writing a file by first reading a source image, writing to a new image, |
| 752 | # reading the written image, and comparing with expected REF_8. |
| 753 | # |
| 754 | # Usage: testReadWriteSized( read filename, |
| 755 | # write filename, |
| 756 | # read filename size, |
| 757 | # read filename depth, |
| 758 | # write options, |
| 759 | # expected ref_8 [,expected ref_16] ); |
| 760 | # |
| 761 | # .e.g |
| 762 | # |
| 763 | # testReadWriteSized( 'input.jpg', 'output.jpg', '70x46', 8, q/quality=>80, |
| 764 | # 'interlace'=>'None'/, 'dc0a144a0b9480cd1e93757a30f01ae3' ); |
| 765 | # |
| 766 | # If the REF_8 of the written image is not what is expected, the written |
| 767 | # image is preserved. Otherwise, the written image is removed. A depth of 0 is |
| 768 | # ignored. |
| 769 | # |
| 770 | sub testReadWriteSized { |
| 771 | my( $infile, $outfile, $size, $readdepth, $writeoptions, $ref_8, $ref_16, |
| 772 | $ref_32 ) = @_; |
| 773 | |
| 774 | my($image, $ref_signature); |
| 775 | |
| 776 | if ( !defined( $ref_16 ) ) |
| 777 | { |
| 778 | $ref_16 = $ref_8; |
| 779 | } |
| 780 | if ( !defined( $ref_32 ) ) |
| 781 | { |
| 782 | $ref_32 = $ref_16; |
| 783 | } |
| 784 | |
| 785 | if (QuantumDepth == 32) |
| 786 | { |
| 787 | $ref_signature=$ref_32; |
| 788 | } |
| 789 | elsif (QuantumDepth == 16) |
| 790 | { |
| 791 | $ref_signature=$ref_16; |
| 792 | } |
| 793 | else |
| 794 | { |
| 795 | $ref_signature=$ref_8; |
| 796 | } |
| 797 | |
| 798 | $image=Image::Magick->new; |
| 799 | |
| 800 | #$image->SetAttribute(debug=>'transform'); |
| 801 | |
| 802 | # Set size attribute |
| 803 | $status=$image->SetAttribute(size=>"$size"); |
| 804 | warn "$status" if "$status"; |
| 805 | |
| 806 | # If read depth is not zero, then set it |
| 807 | if ( $readdepth != 0 ) { |
| 808 | $status=$image->SetAttribute(depth=>$readdepth); |
| 809 | warn "$status" if "$status"; |
| 810 | } |
| 811 | |
| 812 | $status=$image->ReadImage("$infile"); |
| 813 | if( "$status" ) { |
| 814 | print "ReadImage $infile: $status\n"; |
| 815 | print "not ok $test\n"; |
| 816 | } else { |
| 817 | # Write image to file |
| 818 | my $options = 'filename=>"$outfile", ' . "$writeoptions"; |
| 819 | #print "Using options: $options\n"; |
| 820 | eval "\$status=\$image->WriteImage( $options ) ;"; |
| 821 | if( $@ ) { |
| 822 | print "$@\n"; |
| 823 | print "not ok $test\n"; |
| 824 | exit 1; |
| 825 | } |
| 826 | if( "$status" ) { |
| 827 | print "WriteImage $outfile: $status\n"; |
| 828 | print "not ok $test\n"; |
| 829 | } else { |
| 830 | my($image); |
| 831 | |
| 832 | $image=Image::Magick->new; |
| 833 | |
| 834 | if ( $readdepth != 0 ) { |
| 835 | $status=$image->SetAttribute(depth=>$readdepth); |
| 836 | warn "$status" if "$status"; |
| 837 | } |
| 838 | # Set image size attribute |
| 839 | $status=$image->SetAttribute(size=>"$size"); |
| 840 | warn "$status" if "$status"; |
| 841 | |
| 842 | # Read image just written |
| 843 | $status=$image->ReadImage("$outfile"); |
| 844 | if( "$status" ) { |
| 845 | print "ReadImage $outfile: $status\n"; |
| 846 | print "not ok $test\n"; |
| 847 | } else { |
| 848 | # Check signature |
| 849 | $signature=$image->Get('signature'); |
| 850 | |
| 851 | if ( $signature ne $ref_signature ) { |
| 852 | print "ReadImage()\n"; |
| 853 | print "Image: $infile, signatures do not match.\n"; |
| 854 | print " Expected: $ref_signature\n"; |
| 855 | print " Computed: $signature\n"; |
| 856 | print " Depth: ", QuantumDepth, "\n"; |
| 857 | print "not ok $test\n"; |
| 858 | #$image->Display(); |
| 859 | } else { |
| 860 | print "ok $test\n"; |
| 861 | #$image->Display(); |
| 862 | ($file = $outfile) =~ s/.*://g; |
| 863 | unlink "$file"; |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | |
| 870 | # |
| 871 | # Test SetAttribute method |
| 872 | # |
| 873 | # Usage: testSetAttribute( name, attribute); |
| 874 | # |
| 875 | sub testSetAttribute { |
| 876 | my( $srcimage, $name, $attribute ) = @_; |
| 877 | |
| 878 | my($image); |
| 879 | |
| 880 | # Create temporary image |
| 881 | $image=Image::Magick->new; |
| 882 | |
| 883 | $status=$image->ReadImage("$srcimage"); |
| 884 | warn "Readimage: $status" if "$status"; |
| 885 | |
| 886 | # Set image option |
| 887 | print "Image Option : $name=>$attribute\n"; |
| 888 | eval "\$status = \$image->Set('$name'=>'$attribute') ;"; |
| 889 | warn "SetImage: $status" if "$status"; |
| 890 | |
| 891 | # Convert input values to expected output values |
| 892 | $expected=$attribute; |
| 893 | if ($attribute eq 'True' || $attribute eq 'true') { |
| 894 | $expected = 1; |
| 895 | } elsif ($attribute eq 'False' || $attribute eq 'false') { |
| 896 | $expected = 0; |
| 897 | } |
| 898 | |
| 899 | |
| 900 | $value=$image->GetAttribute($name); |
| 901 | |
| 902 | if( defined( $value ) ) { |
| 903 | if ("$expected" eq "$value") { |
| 904 | print "ok $test\n"; |
| 905 | } else { |
| 906 | print "Expected ($expected), Got ($value)\n"; |
| 907 | print "not ok $test\n"; |
| 908 | } |
| 909 | } else { |
| 910 | print "GetAttribute returned undefined value!\n"; |
| 911 | print "not ok $test\n"; |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | # |
| 916 | # Test GetAttribute method |
| 917 | # |
| 918 | # Usage: testGetAttribute( name, expected); |
| 919 | # |
| 920 | sub testGetAttribute { |
| 921 | my( $srcimage, $name, $expected ) = @_; |
| 922 | |
| 923 | my($image); |
| 924 | |
| 925 | # Create temporary image |
| 926 | $image=Image::Magick->new; |
| 927 | |
| 928 | $status=$image->ReadImage("$srcimage"); |
| 929 | warn "Readimage: $status" if "$status"; |
| 930 | |
| 931 | $value=$image->GetAttribute($name); |
| 932 | |
| 933 | if( !defined( $expected ) && !defined( $value ) ) { |
| 934 | # Undefined value is expected |
| 935 | print "ok $test\n"; |
| 936 | } elsif ( !defined( $value ) ) { |
| 937 | print "Expected ($expected), Got (undefined)\n"; |
| 938 | print "not ok $test\n"; |
| 939 | } else { |
| 940 | if ("$expected" eq "$value") { |
| 941 | print "ok $test\n"; |
| 942 | } else { |
| 943 | print "Expected ($expected), Got ($value)\n"; |
| 944 | print "not ok $test\n"; |
| 945 | } |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | # |
| 950 | # Test MontageImage method |
| 951 | # |
| 952 | # Usage: testMontage( input image attributes, montage options, expected REF_8 |
| 953 | # [, expected REF_16] ); |
| 954 | # |
| 955 | sub testMontage { |
| 956 | my( $imageOptions, $montageOptions, $ref_8, $ref_16, $ref_32 ) = @_; |
| 957 | |
| 958 | my($image,$ref_signature); |
| 959 | |
| 960 | if ( !defined( $ref_16 ) ) |
| 961 | { |
| 962 | $ref_16 = $ref_8; |
| 963 | } |
| 964 | if ( !defined( $ref_32 ) ) |
| 965 | { |
| 966 | $ref_32 = $ref_16; |
| 967 | } |
| 968 | |
| 969 | if (QuantumDepth == 32) |
| 970 | { |
| 971 | $ref_signature=$ref_32; |
| 972 | } |
| 973 | elsif (QuantumDepth == 16) |
| 974 | { |
| 975 | $ref_signature=$ref_16; |
| 976 | } |
| 977 | else |
| 978 | { |
| 979 | $ref_signature=$ref_8; |
| 980 | } |
| 981 | |
| 982 | # Create image for image list |
| 983 | $images=Image::Magick->new; |
| 984 | |
| 985 | # Create temporary image |
| 986 | $image=Image::Magick->new; |
| 987 | |
| 988 | my @colors = ( '#000000', '#008000', '#C0C0C0', '#00FF00', |
| 989 | '#808080', '#808000', '#FFFFFF', '#FFFF00', |
| 990 | '#800000', '#000080', '#FF0000', '#0000FF', |
| 991 | '#800080', '#008080', '#FF00FF', '#00FFFF' ); |
| 992 | |
| 993 | my $color; |
| 994 | foreach $color ( @colors ) { |
| 995 | |
| 996 | # Generate image |
| 997 | $image->Set(size=>'50x50'); |
| 998 | #print("\$image->ReadImage(xc:$color);\n"); |
| 999 | $status=$image->ReadImage("xc:$color"); |
| 1000 | if ("$status") { |
| 1001 | warn "Readimage: $status" if "$status"; |
| 1002 | } else { |
| 1003 | # Add image to list |
| 1004 | push( @$images, @$image); |
| 1005 | } |
| 1006 | undef @$image; |
| 1007 | } |
| 1008 | |
| 1009 | # Set image options |
| 1010 | if ("$imageOptions" ne "") { |
| 1011 | print("\$images->Set($imageOptions)\n"); |
| 1012 | eval "\$status = \$images->Set($imageOptions) ;"; |
| 1013 | warn "SetImage: $status" if "$status"; |
| 1014 | } |
| 1015 | |
| 1016 | #print "Border color : ", $images->Get('bordercolor'), "\n"; |
| 1017 | #print "Matte color : ", $images->Get('mattecolor'), "\n"; |
| 1018 | #print "Pen color : ", $images->Get('pen'), "\n"; |
| 1019 | |
| 1020 | # Do montage |
| 1021 | #print "Montage Options: $montageOptions\n"; |
| 1022 | print("\$montage=\$images->Montage( $montageOptions )\n"); |
| 1023 | eval "\$montage=\$images->Montage( $montageOptions ) ;"; |
| 1024 | if( $@ ) { |
| 1025 | print "$@"; |
| 1026 | print "not ok $test\n"; |
| 1027 | return 1; |
| 1028 | } |
| 1029 | |
| 1030 | if( ! ref($montage) ) { |
| 1031 | print "not ok $test\n"; |
| 1032 | } else { |
| 1033 | # Check REF_8 signature |
| 1034 | # $montage->Display(); |
| 1035 | $signature=$montage->GetAttribute('signature'); |
| 1036 | if ( defined( $signature ) ) { |
| 1037 | if ( $signature ne $ref_signature ) { |
| 1038 | print "ReadImage()\n"; |
| 1039 | print "Test $test, signatures do not match.\n"; |
| 1040 | print " Expected: $ref_signature\n"; |
| 1041 | print " Computed: $signature\n"; |
| 1042 | print " Depth: ", QuantumDepth, "\n"; |
| 1043 | $status = $montage->Write("test_${test}_out.miff"); |
| 1044 | warn "Write: $status" if "$status"; |
| 1045 | |
| 1046 | print "not ok $test\n"; |
| 1047 | } else { |
| 1048 | # Check montage directory |
| 1049 | my $directory = $montage->Get('directory'); |
| 1050 | my $expected = join( "\n", @colors ) . "\n"; |
| 1051 | if ( !defined($directory) ) { |
| 1052 | print "ok $test\n"; |
| 1053 | } elsif ( $directory ne $expected) { |
| 1054 | print("Invalid montage directory:\n\"$directory\"\n"); |
| 1055 | print("Expected:\n\"$expected\"\n"); |
| 1056 | print "not ok $test\n"; |
| 1057 | } else { |
| 1058 | # Check montage geometry |
| 1059 | $montage_geom=$montage->Get('montage'); |
| 1060 | if( !defined($montage_geom) ) { |
| 1061 | print("Montage geometry not defined!\n"); |
| 1062 | print "not ok $test\n"; |
| 1063 | } elsif ( $montage_geom !~ /^\d+x\d+\+\d+\+\d+$/ ) { |
| 1064 | print("Montage geometry not in correct format: \"$montage_geom\"\n"); |
| 1065 | print "not ok $test\n"; |
| 1066 | } else { |
| 1067 | print "ok $test\n"; |
| 1068 | } |
| 1069 | } |
| 1070 | } |
| 1071 | } else { |
| 1072 | warn "GetAttribute returned undefined value!"; |
| 1073 | print "not ok $test\n"; |
| 1074 | } |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | # |
| 1079 | # Test filter method using signature compare |
| 1080 | # |
| 1081 | # Usage: testFilterSignature( input image attributes, filter, options, expected REF_8 |
| 1082 | # [, expected REF_16] ); |
| 1083 | # |
| 1084 | sub testFilterSignature { |
| 1085 | my( $srcimage, $filter, $filter_options, $ref_8, $ref_16, $ref_32 ) = @_; |
| 1086 | |
| 1087 | my($image, $ref_signature); |
| 1088 | |
| 1089 | # print( $filter, " ...\n" ); |
| 1090 | |
| 1091 | if ( !defined( $ref_16 ) ) |
| 1092 | { |
| 1093 | $ref_16 = $ref_8; |
| 1094 | } |
| 1095 | if ( !defined( $ref_32 ) ) |
| 1096 | { |
| 1097 | $ref_32 = $ref_16; |
| 1098 | } |
| 1099 | |
| 1100 | if (QuantumDepth == 32) |
| 1101 | { |
| 1102 | $ref_signature=$ref_32; |
| 1103 | } |
| 1104 | elsif (QuantumDepth == 16) |
| 1105 | { |
| 1106 | $ref_signature=$ref_16; |
| 1107 | } |
| 1108 | else |
| 1109 | { |
| 1110 | $ref_signature=$ref_8; |
| 1111 | } |
| 1112 | |
| 1113 | # Create temporary image |
| 1114 | $image=Image::Magick->new; |
| 1115 | |
| 1116 | $status=$image->ReadImage("$srcimage"); |
| 1117 | warn "Readimage: $status" if "$status"; |
| 1118 | |
| 1119 | print("$filter\($filter_options\) ...\n"); |
| 1120 | $image->$filter($filter_options); |
| 1121 | #$image->write(filename=>"reference/filter/$filter.miff", compression=>'None'); |
| 1122 | |
| 1123 | $signature=$image->GetAttribute('signature'); |
| 1124 | if ( defined( $signature ) ) { |
| 1125 | if ( $signature ne $ref_signature ) { |
| 1126 | print "Test $test, signatures do not match.\n"; |
| 1127 | print " Expected: $ref_signature\n"; |
| 1128 | print " Computed: $signature\n"; |
| 1129 | print " Depth: ", QuantumDepth, "\n"; |
| 1130 | #$image->Display(); |
| 1131 | print "not ok $test\n"; |
| 1132 | } else { |
| 1133 | print "ok $test\n"; |
| 1134 | } |
| 1135 | } else { |
| 1136 | warn "GetAttribute returned undefined value!"; |
| 1137 | print "not ok $test\n"; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | # |
| 1142 | # Test filter method using comparison with reference image |
| 1143 | # |
| 1144 | # Usage: testFilterCompare( input image, input image options, reference image, filter, filter options, |
| 1145 | # normalized_mean_error, |
| 1146 | # normalized_maximum_error ); |
| 1147 | sub testFilterCompare { |
| 1148 | my ($srcimage_name, $src_read_options, $refimage_name, $filter, |
| 1149 | $filter_options, $normalized_mean_error_max, |
| 1150 | $normalized_maximum_error_max) = @_; |
| 1151 | my($srcimage, $refimage, $normalized_mean_error, |
| 1152 | $normalized_maximum_error); |
| 1153 | my($status,$errorinfo); |
| 1154 | |
| 1155 | $errorinfo=''; |
| 1156 | $status=''; |
| 1157 | |
| 1158 | #print( $filter, " ...\n" ); |
| 1159 | |
| 1160 | # Create images |
| 1161 | $srcimage=Image::Magick->new; |
| 1162 | $refimage=Image::Magick->new; |
| 1163 | |
| 1164 | if ( "$src_read_options" ne "" ) { |
| 1165 | print("Set($src_read_options) ...\n"); |
| 1166 | eval "\$status=\$srcimage->Set($src_read_options);"; |
| 1167 | if ("$status") |
| 1168 | { |
| 1169 | $errorinfo = "Set($src_read_options): $status"; |
| 1170 | goto COMPARE_RUNTIME_ERROR; |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | $status=$srcimage->ReadImage($srcimage_name); |
| 1175 | #eval "\$status=\$srcimage->ReadImage($srcimage_name);"; |
| 1176 | if ("$status") |
| 1177 | { |
| 1178 | $errorinfo = "Readimage ($srcimage_name): $status"; |
| 1179 | goto COMPARE_RUNTIME_ERROR; |
| 1180 | } |
| 1181 | |
| 1182 | print("$filter\($filter_options\) ...\n"); |
| 1183 | eval "\$status=\$srcimage->$filter($filter_options);"; |
| 1184 | if ("$status") |
| 1185 | { |
| 1186 | $errorinfo = "$filter ($filter_options): $status"; |
| 1187 | goto COMPARE_RUNTIME_ERROR; |
| 1188 | } |
| 1189 | |
| 1190 | $srcimage->set(depth=>8); |
| 1191 | # if ("$filter" eq "Shear") { |
| 1192 | # $srcimage->Display(); |
| 1193 | # $srcimage->write(filename=>"$refimage_name", compression=>'None'); |
| 1194 | # } |
| 1195 | |
| 1196 | $status=$refimage->ReadImage("$refimage_name"); |
| 1197 | if ("$status") |
| 1198 | { |
| 1199 | $errorinfo = "Readimage ($refimage_name): $status"; |
| 1200 | goto COMPARE_RUNTIME_ERROR; |
| 1201 | } |
| 1202 | |
| 1203 | # FIXME: The following statement should not be needed. |
| 1204 | # $status=$refimage->Set(type=>'TrueColor'); |
| 1205 | # if ("$status") |
| 1206 | # { |
| 1207 | # $errorinfo = "Set(type=>'TrueColor'): $status"; |
| 1208 | # goto COMPARE_RUNTIME_ERROR; |
| 1209 | # } |
| 1210 | |
| 1211 | $status=$srcimage->Difference($refimage); |
| 1212 | if ("$status") |
| 1213 | { |
| 1214 | $errorinfo = "Difference($refimage_name): $status"; |
| 1215 | print(" Reference: ", $refimage->Get('columns'), "x", $refimage->Get('rows'), "\n"); |
| 1216 | print(" Computed: ", $srcimage->Get('columns'), "x", $srcimage->Get('rows'), "\n"); |
| 1217 | goto COMPARE_RUNTIME_ERROR; |
| 1218 | } |
| 1219 | |
| 1220 | $normalized_mean_error=0; |
| 1221 | $normalized_mean_error=$srcimage->GetAttribute('mean-error'); |
| 1222 | if ( !defined($normalized_mean_error) ) |
| 1223 | { |
| 1224 | $errorinfo = "GetAttribute('mean-error') returned undefined value!"; |
| 1225 | goto COMPARE_RUNTIME_ERROR; |
| 1226 | } |
| 1227 | $normalized_maximum_error=0; |
| 1228 | $normalized_maximum_error=$srcimage->GetAttribute('maximum-error'); |
| 1229 | if ( ! defined($normalized_maximum_error) ) |
| 1230 | { |
| 1231 | $errorinfo = "GetAttribute('maximum-error') returned undefined value!"; |
| 1232 | goto COMPARE_RUNTIME_ERROR; |
| 1233 | } |
| 1234 | if ( ($normalized_mean_error > $normalized_mean_error_max) || |
| 1235 | ($normalized_maximum_error > $normalized_maximum_error_max) ) |
| 1236 | { |
| 1237 | print(" mean-error=$normalized_mean_error, maximum-error=$normalized_maximum_error\n"); |
| 1238 | print "not ok $test\n"; |
| 1239 | #$srcimage->Display(); |
| 1240 | undef $srcimage; |
| 1241 | undef $refimage; |
| 1242 | return 1 |
| 1243 | } |
| 1244 | |
| 1245 | undef $srcimage; |
| 1246 | undef $refimage; |
| 1247 | print "ok $test\n"; |
| 1248 | return 0; |
| 1249 | |
| 1250 | COMPARE_RUNTIME_ERROR: |
| 1251 | undef $srcimage; |
| 1252 | undef $refimage; |
| 1253 | print(" $errorinfo\n"); |
| 1254 | print "not ok $test\n"; |
| 1255 | return 1 |
| 1256 | } |
| 1257 | 1; |