1 # Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization
2 # dedicated to making software imaging solutions freely available.
4 # You may not use this file except in compliance with the License. You may
5 # obtain a copy of the License at
7 # http://www.imagemagick.org/script/license.php
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.
16 # Common subroutines to support tests
18 # Contributed by Bob Friesenhahn <bfriesen@simple.dallas.tx.us>
22 # Test composite method using comparison with a reference image
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 {
31 $background_read_options,
33 $composite_read_options,
36 $normalized_mean_error_max,
37 $normalized_maximum_error_max) = @_;
41 $normalized_maximum_error,
42 $normalized_mean_error,
49 #print( $filter, " ...\n" );
52 $background=Image::Magick->new;
53 $composite=Image::Magick->new;
54 $refimage=Image::Magick->new;
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);";
62 $errorinfo = "Set($background_read_options): $status";
63 goto COMPARE_RUNTIME_ERROR;
66 $status=$background->ReadImage($background_name);
69 $errorinfo = "Readimage ($background_name): $status";
70 goto COMPARE_RUNTIME_ERROR;
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);";
79 $errorinfo = "Set($composite_read_options): $status";
80 goto COMPARE_RUNTIME_ERROR;
83 $status=$composite->ReadImage($composite_name);
86 $errorinfo = "Readimage ($composite_name): $status";
87 goto COMPARE_RUNTIME_ERROR;
91 print("Composite\($composite_options\) ...\n");
92 eval "\$status=\$background->Composite(image=>\$composite, $composite_options);";
95 $errorinfo = "Composite ($composite_options): $status";
96 goto COMPARE_RUNTIME_ERROR;
100 $background->set(depth=>8);
101 # if ("$filter" eq "Atop") {
102 # $background->write(filename=>"$refimage_name", compression=>'None');
103 # $background->Display();
106 $status=$refimage->ReadImage("$refimage_name");
109 $errorinfo = "Readimage ($refimage_name): $status";
110 goto COMPARE_RUNTIME_ERROR;
113 $status=$background->Difference($refimage);
116 $errorinfo = "Difference($refimage_name): $status";
117 print(" Reference: ", $refimage->Get('columns'), "x", $refimage->Get('rows'), "\n");
118 print(" Computed: ", $background->Get('columns'), "x", $background->Get('rows'), "\n");
119 goto COMPARE_RUNTIME_ERROR;
122 $normalized_mean_error=0;
123 $normalized_mean_error=$background->GetAttribute('mean-error');
124 if ( !defined($normalized_mean_error) )
126 $errorinfo = "GetAttribute('mean-error') returned undefined value!";
127 goto COMPARE_RUNTIME_ERROR;
129 $normalized_maximum_error=0;
130 $normalized_maximum_error=$background->GetAttribute('maximum-error');
131 if ( ! defined($normalized_maximum_error) )
133 $errorinfo = "GetAttribute('maximum-error') returned undefined value!";
134 goto COMPARE_RUNTIME_ERROR;
136 if ( ($normalized_mean_error > $normalized_mean_error_max) ||
137 ($normalized_maximum_error > $normalized_maximum_error_max) )
139 print(" mean-error=$normalized_mean_error, maximum-error=$normalized_maximum_error\n");
140 print "not ok $test\n";
141 $background->Display();
154 COMPARE_RUNTIME_ERROR:
158 print(" $errorinfo\n");
159 print "not ok $test\n";
164 # Test reading a 16-bit file in which two signatures are possible,
165 # depending on whether 16-bit pixels data has been enabled
167 # Usage: testRead( read filename, expected ref_8 [, expected ref_16] [, expected ref_32] );
170 my( $infile, $ref_8, $ref_16, $ref_32 ) = @_;
172 my($image,$magick,$success,$ref_signature);
176 if ( !defined( $ref_16 ) )
180 if ( !defined( $ref_32 ) )
185 if (QuantumDepth == 32)
187 $ref_signature=$ref_32;
189 elsif (QuantumDepth == 16)
191 $ref_signature=$ref_16;
195 $ref_signature=$ref_8;
201 # Test reading from file
204 my($image, $signature, $status);
206 print( " testing reading from file \"", $infile, "\" ...\n");
207 $image=Image::Magick->new;
208 $image->Set(size=>'512x512');
209 $status=$image->ReadImage("$infile");
210 if( "$status" && !($status =~ /Exception ((315)|(350))/)) {
211 print "ReadImage $infile: $status\n";
215 print "ReadImage $infile: $status\n";
218 $magick=$image->Get('magick');
219 $signature=$image->Get('signature');
221 if ( $signature ne $ref_signature ) {
222 print "ReadImage()\n";
223 print "Image: $infile, signatures do not match.\n";
224 print " Expected: $ref_signature\n";
225 print " Computed: $signature\n";
226 print " Depth: ", QuantumDepth, "\n";
235 # Test reading from blob
237 if (!($infile =~ /\.bz2$/) && !($infile =~ /\.gz$/) && !($infile =~ /\.Z$/))
239 my(@blob, $blob_length, $image, $signature, $status);
241 if( open( FILE, "< $infile"))
243 print( " testing reading from BLOB with magick \"", $magick, "\"...\n");
245 $blob_length = read( FILE, $blob, 10000000 );
247 if( defined( $blob ) ) {
248 $image=Image::Magick->new(magick=>$magick);
249 $status=$image->BlobToImage( $blob );
251 if( "$status" && !($status =~ /Exception ((315)|(350))/)) {
252 print "BlobToImage $infile: $status\n";
256 print "ReadImage $infile: $status\n";
258 $signature=$image->Get('signature');
259 if ( $signature ne $ref_signature ) {
260 print "BlobToImage()\n";
261 print "Image: $infile, signatures do not match.\n";
262 print " Expected: $ref_signature\n";
263 print " Computed: $signature\n";
264 print " Depth: ", QuantumDepth, "\n";
275 # Display test status
277 if ( $failure != 0 ) {
278 print "not ok $test\n";
286 # Test reading a file, and compare with a reference file
288 sub testReadCompare {
289 my( $srcimage_name,$refimage_name, $read_options,
290 $normalized_mean_error_max, $normalized_maximum_error_max) = @_;
291 my($srcimage, $refimage, $normalized_mean_error, $normalized_maximum_error);
296 $srcimage=Image::Magick->new;
297 $refimage=Image::Magick->new;
299 if ( "$read_options" ne "" ) {
300 eval "\$status=\$srcimage->Set($read_options);";
303 $errorinfo = "Set($read_options): $status";
305 goto COMPARE_RUNTIME_ERROR;
309 $status=$srcimage->ReadImage("$srcimage_name");
312 $errorinfo = "Readimage ($srcimage_name): $status";
314 goto COMPARE_RUNTIME_ERROR;
317 # if ("$srcimage_name" eq "input.tim") {
318 # $srcimage->write(filename=>"$refimage_name", compression=>'None');
321 #print("writing file $refimage_name\n");
322 #$srcimage->Quantize(colors=>256);
323 #$status=$srcimage->write(filename=>"$refimage_name", compression=>'rle');
324 #warn "$status" if $status;
326 $status=$refimage->ReadImage("$refimage_name");
329 $errorinfo = "Readimage ($refimage_name): $status";
331 goto COMPARE_RUNTIME_ERROR;
335 $srcimage->set(depth=>8);
337 # FIXME: The following statement should not be needed.
338 # $status=$refimage->Set(type=>'TrueColor');
341 # $errorinfo = "Set(type=>'TrueColor'): $status";
342 # goto COMPARE_RUNTIME_ERROR;
345 # Verify that $srcimage and $refimage contain the same number of frames.
346 if ( $#srcimage != $#refimage )
348 $errorinfo = "Source and reference images contain different number of frames ($#srcimage != $#refimage)";
350 goto COMPARE_RUNTIME_ERROR;
353 # Compare each frame in the sequence.
354 for ($index = 0; $srcimage->[$index] && $refimage->[$index]; $index++)
356 $status=$srcimage->[$index]->Difference($refimage->[$index]);
359 $errorinfo = "Difference($refimage_name)->[$index]: $status";
361 goto COMPARE_RUNTIME_ERROR;
366 $normalized_mean_error=0;
367 $normalized_mean_error=$srcimage->GetAttribute('mean-error');
368 if ( !defined($normalized_mean_error) )
370 $errorinfo = "GetAttribute('mean-error') returned undefined value!";
372 goto COMPARE_RUNTIME_ERROR;
374 $normalized_maximum_error=0;
375 $normalized_maximum_error=$srcimage->GetAttribute('maximum-error');
376 if ( ! defined($normalized_maximum_error) )
378 $errorinfo = "GetAttribute('maximum-error') returned undefined value!";
380 goto COMPARE_RUNTIME_ERROR;
382 if ( ($normalized_mean_error > $normalized_mean_error_max) ||
383 ($normalized_maximum_error > $normalized_maximum_error_max) )
385 print("mean-error=$normalized_mean_error, maximum-error=$normalized_maximum_error\n");
386 #$srcimage->Display();
387 print "not ok $test\n";
396 COMPARE_RUNTIME_ERROR:
399 print "not ok $test\n";
404 # Test reading a file which requires a file size to read (GRAY, RGB, CMYK)
405 # or supports multiple resolutions (JBIG, JPEG, PCD)
407 # Usage: testRead( read filename, size, depth, expected ref_8 [, expected ref_16] [, expected ref_32] );
410 my( $infile, $size, $ref_8, $ref_16, $ref_32 ) = @_;
412 my($image,$ref_signature);
414 if ( !defined( $ref_16 ) )
418 if ( !defined( $ref_32 ) )
423 if (QuantumDepth == 32)
425 $ref_signature=$ref_32;
427 elsif (QuantumDepth == 16)
429 $ref_signature=$ref_16;
433 $ref_signature=$ref_8;
436 $image=Image::Magick->new;
439 $status=$image->SetAttribute(size=>"$size");
440 warn "$status" if "$status";
442 # If depth is not zero, then set it
443 if ( QuantumDepth != 0 ) {
444 $status=$image->SetAttribute(depth=>QuantumDepth);
445 warn "$status" if "$status";
448 $status=$image->ReadImage("$infile");
450 print "ReadImage $infile: $status";
451 print "not ok $test\n";
453 $signature=$image->Get('signature');
454 if ( $signature ne $ref_signature ) {
455 print "ReadImage()\n";
456 print "Image: $infile, signatures do not match.\n";
457 print " Expected: $ref_signature\n";
458 print " Computed: $signature\n";
459 print " Depth: ", QuantumDepth, "\n";
460 print "not ok $test\n";
469 # Test writing a file by first reading a source image, writing to a new image,
470 # reading the written image, and comparing with expected REF_8.
472 # Usage: testReadWrite( read filename, write filename, write options,
473 # expected ref_8 [, expected ref_16] );
477 # testReadWrite( 'input.jpg', 'output.jpg', q/quality=>80, interlace=>'None'/,
478 # 'dc0a144a0b9480cd1e93757a30f01ae3' );
480 # If the REF_8 of the written image is not what is expected, the written
481 # image is preserved. Otherwise, the written image is removed.
484 my( $infile, $outfile, $writeoptions, $ref_8, $ref_16, $ref_32 ) = @_;
488 if ( !defined( $ref_16 ) )
492 if ( !defined( $ref_32 ) )
497 if (QuantumDepth == 32)
499 $ref_signature=$ref_32;
501 elsif (QuantumDepth == 16)
503 $ref_signature=$ref_16;
507 $ref_signature=$ref_8;
510 $image=Image::Magick->new;
511 $status=$image->ReadImage("$infile");
512 $signature=$image->Get('signature');
514 print "ReadImage $infile: $status\n";
515 print "not ok $test\n";
517 # Write image to file
518 my $options = 'filename=>"$outfile", ' . "$writeoptions";
519 #print "Using options: $options\n";
520 eval "\$status=\$image->WriteImage( $options ) ;";
523 print "not ok $test\n";
527 print "WriteImage $outfile: $status\n";
528 print "not ok $test\n";
532 # Read image just written
533 $image=Image::Magick->new;
534 $status=$image->ReadImage("$outfile");
536 print "ReadImage $outfile: $status\n";
537 print "not ok $test\n";
540 $signature=$image->Get('signature');
541 if ( $signature ne $ref_signature ) {
542 print "ReadImage()\n";
543 print "Image: $infile, signatures do not match.\n";
544 print " Expected: $ref_signature\n";
545 print " Computed: $signature\n";
546 print " Depth: ", QuantumDepth, "\n";
547 print "not ok $test\n";
551 ($file = $outfile) =~ s/.*://g;
560 # Test reading a file, and compare with a reference file
562 sub testReadWriteCompare {
563 my( $srcimage_name, $outimage_name, $refimage_name,
564 $read_options, $write_options,
565 $normalized_mean_error_max, $normalized_maximum_error_max) = @_;
566 my($srcimage, $refimage, $normalized_mean_error,
567 $normalized_maximum_error);
571 $image=Image::Magick->new;
572 $refimage=Image::Magick->new;
575 # Read the initial image
577 $status=$image->ReadImage($srcimage_name);
580 $errorinfo = "Readimage ($srcimage_name): $status";
581 goto COMPARE_RUNTIME_ERROR;
585 # Write image to output file
587 if ( "$write_options" ne "" ) {
588 eval "\$status=\$image->Set($write_options);";
591 $errorinfo = "Set($write_options): $status";
592 goto COMPARE_RUNTIME_ERROR;
595 $image->Set(filename=>"$outimage_name");
597 $status=$image->WriteImage( );
600 $errorinfo = "WriteImage ($outimage_name): $status";
601 goto COMPARE_RUNTIME_ERROR;
605 $image=Image::Magick->new;
608 # Read image from output file
610 if ( "$read_options" ne "" ) {
611 eval "\$status=\$image->Set($read_options);";
614 $errorinfo = "Set($read_options): $status";
615 goto COMPARE_RUNTIME_ERROR;
619 $image->ReadImage("$outimage_name");
622 $errorinfo = "WriteImage ($outimage_name): $status";
623 goto COMPARE_RUNTIME_ERROR;
626 # eval "\$status=\$image->Set($write_options);";
627 #$status=$image->write(filename=>"$refimage_name", compression=>'None');
628 # warn "$status" if $status;
631 # Read reference image
633 $status=$refimage->ReadImage("$refimage_name");
636 $errorinfo = "Readimage ($refimage_name): $status";
637 goto COMPARE_RUNTIME_ERROR;
641 # Compare output file with reference image
645 $image->set(depth=>8);
647 # FIXME: The following statement should not be needed.
648 # $status=$refimage->Set(type=>'TrueColor');
651 # $errorinfo = "Set(type=>'TrueColor'): $status";
652 # goto COMPARE_RUNTIME_ERROR;
655 $status=$image->Difference($refimage);
658 $errorinfo = "Difference($refimage_name): $status";
659 goto COMPARE_RUNTIME_ERROR;
662 $normalized_mean_error=0;
663 $normalized_mean_error=$image->GetAttribute('mean-error');
664 if ( !defined($normalized_mean_error) )
666 $errorinfo = "GetAttribute('mean-error') returned undefined value!";
667 goto COMPARE_RUNTIME_ERROR;
669 $normalized_maximum_error=0;
670 $normalized_maximum_error=$image->GetAttribute('maximum-error');
671 if ( ! defined($normalized_maximum_error) )
673 $errorinfo = "GetAttribute('maximum-error') returned undefined value!";
674 goto COMPARE_RUNTIME_ERROR;
677 if ( ($normalized_mean_error > $normalized_mean_error_max) ||
678 ($normalized_maximum_error > $normalized_maximum_error_max) )
680 print("mean-error=$normalized_mean_error, maximum-error=$normalized_maximum_error\n");
681 print "not ok $test\n";
690 COMPARE_RUNTIME_ERROR:
692 print "not ok $test\n";
699 # Test writing a file by first reading a source image, writing to a
700 # new image, and reading the written image. Depends on detecting
701 # reported errors by ImageMagick
703 # Usage: testReadWrite( read filename, write filename, write options);
707 # testReadWrite( 'input.jpg', 'output.jpg', q/quality=>80, 'interlace'=>'None'/ );
709 # If the read of the written image is not what is expected, the
710 # written image is preserved. Otherwise, the written image is
713 sub testReadWriteNoVerify {
714 my( $infile, $outfile, $writeoptions) = @_;
718 $image=Image::Magick->new;
719 $status=$image->ReadImage("$infile");
722 print "ReadImage $infile: not ok $test\n";
724 # Write image to file
725 my $options = 'filename=>"$outfile", ' . $writeoptions;
726 #print "Using options: $options\n";
727 eval "\$status=\$image->WriteImage( $options ) ;";
730 print "not ok $test\n";
734 print "WriteImage $outfile: $status\n";
735 print "not ok $test\n";
739 # Read image just written
740 $image=Image::Magick->new;
741 $status=$image->ReadImage("$outfile");
743 print "ReadImage $outfile: $status\n";
744 print "not ok $test\n";
754 # Test writing a file by first reading a source image, writing to a new image,
755 # reading the written image, and comparing with expected REF_8.
757 # Usage: testReadWriteSized( read filename,
759 # read filename size,
760 # read filename depth,
762 # expected ref_8 [,expected ref_16] );
766 # testReadWriteSized( 'input.jpg', 'output.jpg', '70x46', 8, q/quality=>80,
767 # 'interlace'=>'None'/, 'dc0a144a0b9480cd1e93757a30f01ae3' );
769 # If the REF_8 of the written image is not what is expected, the written
770 # image is preserved. Otherwise, the written image is removed. A depth of 0 is
773 sub testReadWriteSized {
774 my( $infile, $outfile, $size, $readdepth, $writeoptions, $ref_8, $ref_16,
777 my($image, $ref_signature);
779 if ( !defined( $ref_16 ) )
783 if ( !defined( $ref_32 ) )
788 if (QuantumDepth == 32)
790 $ref_signature=$ref_32;
792 elsif (QuantumDepth == 16)
794 $ref_signature=$ref_16;
798 $ref_signature=$ref_8;
801 $image=Image::Magick->new;
803 #$image->SetAttribute(debug=>'transform');
806 $status=$image->SetAttribute(size=>"$size");
807 warn "$status" if "$status";
809 # If read depth is not zero, then set it
810 if ( $readdepth != 0 ) {
811 $status=$image->SetAttribute(depth=>$readdepth);
812 warn "$status" if "$status";
815 $status=$image->ReadImage("$infile");
817 print "ReadImage $infile: $status\n";
818 print "not ok $test\n";
820 # Write image to file
821 my $options = 'filename=>"$outfile", ' . "$writeoptions";
822 #print "Using options: $options\n";
823 eval "\$status=\$image->WriteImage( $options ) ;";
826 print "not ok $test\n";
830 print "WriteImage $outfile: $status\n";
831 print "not ok $test\n";
835 $image=Image::Magick->new;
837 if ( $readdepth != 0 ) {
838 $status=$image->SetAttribute(depth=>$readdepth);
839 warn "$status" if "$status";
841 # Set image size attribute
842 $status=$image->SetAttribute(size=>"$size");
843 warn "$status" if "$status";
845 # Read image just written
846 $status=$image->ReadImage("$outfile");
848 print "ReadImage $outfile: $status\n";
849 print "not ok $test\n";
852 $signature=$image->Get('signature');
854 if ( $signature ne $ref_signature ) {
855 print "ReadImage()\n";
856 print "Image: $infile, signatures do not match.\n";
857 print " Expected: $ref_signature\n";
858 print " Computed: $signature\n";
859 print " Depth: ", QuantumDepth, "\n";
860 print "not ok $test\n";
865 ($file = $outfile) =~ s/.*://g;
874 # Test SetAttribute method
876 # Usage: testSetAttribute( name, attribute);
878 sub testSetAttribute {
879 my( $srcimage, $name, $attribute ) = @_;
883 # Create temporary image
884 $image=Image::Magick->new;
886 $status=$image->ReadImage("$srcimage");
887 warn "Readimage: $status" if "$status";
890 print "Image Option : $name=>$attribute\n";
891 eval "\$status = \$image->Set('$name'=>'$attribute') ;";
892 warn "SetImage: $status" if "$status";
894 # Convert input values to expected output values
895 $expected=$attribute;
896 if ($attribute eq 'True' || $attribute eq 'true') {
898 } elsif ($attribute eq 'False' || $attribute eq 'false') {
903 $value=$image->GetAttribute($name);
905 if( defined( $value ) ) {
906 if ("$expected" eq "$value") {
909 print "Expected ($expected), Got ($value)\n";
910 print "not ok $test\n";
913 print "GetAttribute returned undefined value!\n";
914 print "not ok $test\n";
919 # Test GetAttribute method
921 # Usage: testGetAttribute( name, expected);
923 sub testGetAttribute {
924 my( $srcimage, $name, $expected ) = @_;
928 # Create temporary image
929 $image=Image::Magick->new;
931 $status=$image->ReadImage("$srcimage");
932 warn "Readimage: $status" if "$status";
934 $value=$image->GetAttribute($name);
936 if( !defined( $expected ) && !defined( $value ) ) {
937 # Undefined value is expected
939 } elsif ( !defined( $value ) ) {
940 print "Expected ($expected), Got (undefined)\n";
941 print "not ok $test\n";
943 if ("$expected" eq "$value") {
946 print "Expected ($expected), Got ($value)\n";
947 print "not ok $test\n";
953 # Test MontageImage method
955 # Usage: testMontage( input image attributes, montage options, expected REF_8
956 # [, expected REF_16] );
959 my( $imageOptions, $montageOptions, $ref_8, $ref_16, $ref_32 ) = @_;
961 my($image,$ref_signature);
963 if ( !defined( $ref_16 ) )
967 if ( !defined( $ref_32 ) )
972 if (QuantumDepth == 32)
974 $ref_signature=$ref_32;
976 elsif (QuantumDepth == 16)
978 $ref_signature=$ref_16;
982 $ref_signature=$ref_8;
985 # Create image for image list
986 $images=Image::Magick->new;
988 # Create temporary image
989 $image=Image::Magick->new;
991 my @colors = ( '#000000', '#008000', '#C0C0C0', '#00FF00',
992 '#808080', '#808000', '#FFFFFF', '#FFFF00',
993 '#800000', '#000080', '#FF0000', '#0000FF',
994 '#800080', '#008080', '#FF00FF', '#00FFFF' );
997 foreach $color ( @colors ) {
1000 $image->Set(size=>'50x50');
1001 #print("\$image->ReadImage(xc:$color);\n");
1002 $status=$image->ReadImage("xc:$color");
1004 warn "Readimage: $status" if "$status";
1007 push( @$images, @$image);
1013 if ("$imageOptions" ne "") {
1014 print("\$images->Set($imageOptions)\n");
1015 eval "\$status = \$images->Set($imageOptions) ;";
1016 warn "SetImage: $status" if "$status";
1019 #print "Border color : ", $images->Get('bordercolor'), "\n";
1020 #print "Matte color : ", $images->Get('mattecolor'), "\n";
1021 #print "Pen color : ", $images->Get('pen'), "\n";
1024 #print "Montage Options: $montageOptions\n";
1025 print("\$montage=\$images->Montage( $montageOptions )\n");
1026 eval "\$montage=\$images->Montage( $montageOptions ) ;";
1029 print "not ok $test\n";
1033 if( ! ref($montage) ) {
1034 print "not ok $test\n";
1036 # Check REF_8 signature
1037 # $montage->Display();
1038 $signature=$montage->GetAttribute('signature');
1039 if ( defined( $signature ) ) {
1040 if ( $signature ne $ref_signature ) {
1041 print "ReadImage()\n";
1042 print "Test $test, signatures do not match.\n";
1043 print " Expected: $ref_signature\n";
1044 print " Computed: $signature\n";
1045 print " Depth: ", QuantumDepth, "\n";
1046 $status = $montage->Write("test_${test}_out.miff");
1047 warn "Write: $status" if "$status";
1049 print "not ok $test\n";
1051 # Check montage directory
1052 my $directory = $montage->Get('directory');
1053 my $expected = join( "\n", @colors ) . "\n";
1054 if ( !defined($directory) ) {
1056 } elsif ( $directory ne $expected) {
1057 print("Invalid montage directory:\n\"$directory\"\n");
1058 print("Expected:\n\"$expected\"\n");
1059 print "not ok $test\n";
1061 # Check montage geometry
1062 $montage_geom=$montage->Get('montage');
1063 if( !defined($montage_geom) ) {
1064 print("Montage geometry not defined!\n");
1065 print "not ok $test\n";
1066 } elsif ( $montage_geom !~ /^\d+x\d+\+\d+\+\d+$/ ) {
1067 print("Montage geometry not in correct format: \"$montage_geom\"\n");
1068 print "not ok $test\n";
1075 warn "GetAttribute returned undefined value!";
1076 print "not ok $test\n";
1082 # Test filter method using signature compare
1084 # Usage: testFilterSignature( input image attributes, filter, options, expected REF_8
1085 # [, expected REF_16] );
1087 sub testFilterSignature {
1088 my( $srcimage, $filter, $filter_options, $ref_8, $ref_16, $ref_32 ) = @_;
1090 my($image, $ref_signature);
1092 # print( $filter, " ...\n" );
1094 if ( !defined( $ref_16 ) )
1098 if ( !defined( $ref_32 ) )
1103 if (QuantumDepth == 32)
1105 $ref_signature=$ref_32;
1107 elsif (QuantumDepth == 16)
1109 $ref_signature=$ref_16;
1113 $ref_signature=$ref_8;
1116 # Create temporary image
1117 $image=Image::Magick->new;
1119 $status=$image->ReadImage("$srcimage");
1120 warn "Readimage: $status" if "$status";
1122 print("$filter\($filter_options\) ...\n");
1123 $image->$filter($filter_options);
1124 #$image->write(filename=>"reference/filter/$filter.miff", compression=>'None');
1126 $signature=$image->GetAttribute('signature');
1127 if ( defined( $signature ) ) {
1128 if ( $signature ne $ref_signature ) {
1129 print "Test $test, signatures do not match.\n";
1130 print " Expected: $ref_signature\n";
1131 print " Computed: $signature\n";
1132 print " Depth: ", QuantumDepth, "\n";
1134 print "not ok $test\n";
1139 warn "GetAttribute returned undefined value!";
1140 print "not ok $test\n";
1145 # Test filter method using comparison with reference image
1147 # Usage: testFilterCompare( input image, input image options, reference image, filter, filter options,
1148 # normalized_mean_error,
1149 # normalized_maximum_error );
1150 sub testFilterCompare {
1151 my ($srcimage_name, $src_read_options, $refimage_name, $filter,
1152 $filter_options, $normalized_mean_error_max,
1153 $normalized_maximum_error_max) = @_;
1154 my($srcimage, $refimage, $normalized_mean_error,
1155 $normalized_maximum_error);
1156 my($status,$errorinfo);
1161 #print( $filter, " ...\n" );
1164 $srcimage=Image::Magick->new;
1165 $refimage=Image::Magick->new;
1167 if ( "$src_read_options" ne "" ) {
1168 print("Set($src_read_options) ...\n");
1169 eval "\$status=\$srcimage->Set($src_read_options);";
1172 $errorinfo = "Set($src_read_options): $status";
1173 goto COMPARE_RUNTIME_ERROR;
1177 $status=$srcimage->ReadImage($srcimage_name);
1178 #eval "\$status=\$srcimage->ReadImage($srcimage_name);";
1181 $errorinfo = "Readimage ($srcimage_name): $status";
1182 goto COMPARE_RUNTIME_ERROR;
1185 print("$filter\($filter_options\) ...\n");
1186 eval "\$status=\$srcimage->$filter($filter_options);";
1189 $errorinfo = "$filter ($filter_options): $status";
1190 goto COMPARE_RUNTIME_ERROR;
1194 $srcimage->set(depth=>8);
1195 # if ("$filter" eq "Shear") {
1196 # $srcimage->Display();
1197 # $srcimage->write(filename=>"$refimage_name", compression=>'None');
1200 $status=$refimage->ReadImage("$refimage_name");
1203 $errorinfo = "Readimage ($refimage_name): $status";
1204 goto COMPARE_RUNTIME_ERROR;
1207 # FIXME: The following statement should not be needed.
1208 # $status=$refimage->Set(type=>'TrueColor');
1211 # $errorinfo = "Set(type=>'TrueColor'): $status";
1212 # goto COMPARE_RUNTIME_ERROR;
1215 $status=$srcimage->Difference($refimage);
1218 $errorinfo = "Difference($refimage_name): $status";
1219 print(" Reference: ", $refimage->Get('columns'), "x", $refimage->Get('rows'), "\n");
1220 print(" Computed: ", $srcimage->Get('columns'), "x", $srcimage->Get('rows'), "\n");
1221 goto COMPARE_RUNTIME_ERROR;
1224 $normalized_mean_error=0;
1225 $normalized_mean_error=$srcimage->GetAttribute('mean-error');
1226 if ( !defined($normalized_mean_error) )
1228 $errorinfo = "GetAttribute('mean-error') returned undefined value!";
1229 goto COMPARE_RUNTIME_ERROR;
1231 $normalized_maximum_error=0;
1232 $normalized_maximum_error=$srcimage->GetAttribute('maximum-error');
1233 if ( ! defined($normalized_maximum_error) )
1235 $errorinfo = "GetAttribute('maximum-error') returned undefined value!";
1236 goto COMPARE_RUNTIME_ERROR;
1238 if ( ($normalized_mean_error > $normalized_mean_error_max) ||
1239 ($normalized_maximum_error > $normalized_maximum_error_max) )
1241 print(" mean-error=$normalized_mean_error, maximum-error=$normalized_maximum_error\n");
1242 print "not ok $test\n";
1243 #$srcimage->Display();
1254 COMPARE_RUNTIME_ERROR:
1257 print(" $errorinfo\n");
1258 print "not ok $test\n";