gl_utils.pm (1409B)
1 # 2 # Shared utilities for citrun_gl testing. 3 # - ok_image, an image diff and show function 4 # 5 use Modern::Perl; 6 use File::Compare; # compare 7 use Imager; # new 8 use Test::More; # pass, fail, diag 9 10 11 # 12 # Compares the image given as the first argument with the image given as the 13 # second argument and saves the result into the directory given as the third 14 # argument. 15 # 16 # If differences are found, show an ascii art picture of the differences and try 17 # and launch a graphical viewer too. 18 # 19 sub ok_image { 20 my $output_file = shift; 21 my $output_good = shift; 22 my $tmp_dir = shift; 23 24 if (compare( $output_file, $output_good )) { 25 my $a = Imager->new( file => $output_good ) or die Imager->errstr; 26 my $b = Imager->new( file => $output_file ) or die Imager->errstr; 27 my $diff = $a->difference( other => $b ); 28 29 my $diff_file = "$tmp_dir/diff.tga"; 30 $diff->write( file => $diff_file ) or die $diff->errstr; 31 32 # Try and show an ascii art picture of the differences. 33 if (open( my $cmd_out, '-|', "img2txt", "-f", "utf8", $diff_file )) { 34 diag("diff $diff_file"); 35 diag("--- t/gl/basic.tga"); 36 diag("+++ $output_file"); 37 diag($_) while (<$cmd_out>); 38 close( $cmd_out ); 39 } else { 40 die "\\-> Maybe try installing `libcaca`."; 41 } 42 43 system("imlib2_view $diff_file"); 44 #system("xdg-open $diff_file"); 45 46 fail( 'is render file identical' ); 47 } 48 else { 49 pass( 'is render file identical' ); 50 } 51 } 52 53 1;