Changeset 7

Show
Ignore:
Timestamp:
25.10.2006 13:44:37 (2 years ago)
Author:
decoder
Message:

Fixed, now detects all the new gifs...
TODO: Correct error handling for the new gif stuff, (retcodes are not checked, and there is a warn in the code)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/devel/FuzzyOcr.pm

    r6 r7  
    370370} 
    371371 
    372 sub deanim { 
    373         my ($infile, $outfile, $errfile) = @_; 
    374         my $info = gif_info($infile); 
    375         my $index = find_dominant_image($info); 
    376  
    377         # Pick frame number $index from the animation and spew to stdout: 
    378         if ($info->{'has_local_color_table'}) { 
    379             # FIXME: Check retcodes and adjust filenames 
    380             my $infile2 = $infile . "-reduced"; 
    381             my $retcode = $t->run_and_catch(sub { 
    382                 qx($App{gifsicle} --colors=255 $infile >$infile2 2>>$errfile); 
    383             }); 
    384  
    385             $retcode = $t->run_and_catch(sub { 
    386                 qx($App{gifsicle} --unoptimize #$index $infile2 >$outfile 2>>$errfile); 
    387             }); 
    388         } 
    389  
    390         else { 
    391             my $retcode = $t->run_and_catch(sub { 
    392                 qx($App{gifsicle} --unoptimize #$index $infile2 >$outfile 2>>$errfile); 
    393             }); 
    394         } 
    395  
    396 
    397  
    398 sub gif_info ($) { 
    399     my ($giffile) = @_; 
     372sub gif_info { 
     373    my ($giffile, $t) = @_; 
    400374     
    401375    my $fd = new IO::Handle; 
     
    404378    my @stderr_data; 
    405379 
    406     $retcode = $t->run_and_catch(sub { 
     380    my $retcode = $t->run_and_catch(sub { 
    407381        @stdout_data = qx($App{gifsicle} --info $giffile); 
    408382    }); 
     383    print "blah4\n"; 
    409384 
    410385    if ($retcode) { 
     
    434409                                      (?: .* \b delay \s+ (\d+(?:\.\d+)?) s)? 
    435410                                      }sx; 
     411        #FIXME: Handle this error 
    436412        $n == $frameno 
    437     foreach my $info (@frameinfo) { 
    438         # We could just match the delays, but we'll also check the image#'s 
    439         # as a sanity check. 
    440         my ($n, $delay) = $info =~ m{ image \s+ \#(\d+) 
    441                                       (?: .* \b delay \s+ (\d+(?:\.\d+)?) s)? 
    442                                       }sx; 
    443         $n == $frameno 
    444             or die ( "Trouble parsing 'gifsicle --info' output." 
     413            or warn ( "Trouble parsing 'gifsicle --info' output." 
    445414                     . "  Expected 'image \#$frameno', found 'image \#$n'\n" ); 
    446415 
     
    925894            if ($image_count gt 1) { 
    926895                debuglog("File contains <$image_count> images, deanimating..."); 
    927                 $tfile2 = $tfile 
     896                my $tfile2 = $tfile; 
     897                my $tfile3 = $tfile; 
    928898 
    929899                if ($tfile2 =~ m/\.gif$/i) { 
    930900                    $tfile2 =~ s/\.gif$/-multi.gif/i; 
     901                    $tfile3 =~ s/\.gif$/-reduced.gif/i; 
    931902                } else { 
    932903                    $tfile2 .= ".gif"; 
    933                 } 
    934  
    935                 deanimate($tfile, $tfile2, $efile) 
     904                    $tfile3 .= "-reduced.gif"; 
     905                } 
     906 
     907                my $info = gif_info($tfile, $t); 
     908                my $index = find_dominant_image($info); 
     909 
     910                # Pick frame number $index from the animation and spew to stdout: 
     911                if ($info->{'has_local_color_table'}) { 
     912                    # FIXME: Check retcodes 
     913                    $retcode = $t->run_and_catch(sub { 
     914                        qx($App{gifsicle} --colors=255 $tfile >$tfile3 2>>$efile); 
     915                    }); 
     916                    print "blah1\n"; 
     917                    $retcode = $t->run_and_catch(sub { 
     918                        qx($App{gifsicle} --unoptimize $tfile3 \'#$index\' >$tfile2 2>>$efile); 
     919                    }); 
     920 
     921                    print "blah2\n"; 
     922                } else { 
     923                    $retcode = $t->run_and_catch(sub { 
     924                        qx($App{gifsicle} --unoptimize $tfile \'#$index\' >$tfile2 2>>$efile); 
     925                    }); 
     926                } 
    936927                $tfile = $tfile2; 
    937928            }