Changeset 25

Show
Ignore:
Timestamp:
01.11.2006 19:19:25 (2 years ago)
Author:
jorge
Message:

Address warnings and timeouts when running gifsicle

Files:

Legend:

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

    r18 r25  
    3131    # Pick frame number $index from the animation and spew to stdout: 
    3232    if ($info->{'has_local_color_table'}) { 
    33         # FIXME: Check retcodes 
     33        debuglog("deanimate: Image has local_color_table, reducing to 255 colors"); 
    3434        my $retcode = $t->run_and_catch(sub { 
    35             qx($conf->{"focr_bin_gifsicle"} --colors=255 $tfile >$tfile3 2>>$efile); 
     35            qx($conf->{focr_bin_gifsicle} --colors=255 $tfile >$tfile3 2>>$efile); 
    3636        }); 
    37         $retcode = $t->run_and_catch(sub { 
    38             qx($conf->{"focr_bin_gifsicle"} --unoptimize $tfile3 \'#$index\' >$tfile2 2>>$efile); 
    39         }); 
    40     } else { 
    41         my $retcode = $t->run_and_catch(sub { 
    42             qx($conf->{"focr_bin_gifsicle"} --unoptimize $tfile \'#$index\' >$tfile2 2>>$efile); 
    43         }); 
     37        if ($retcode) { 
     38            debuglog("$conf->{'focr_bin_gifinter'}: Timed out [$retcode], image not reduced!"); 
     39        } else { 
     40            $tfile = $tfile3; 
     41        } 
     42    } 
     43    my $retcode = $t->run_and_catch(sub { 
     44        qx($conf->{focr_bin_gifsicle} --unoptimize $tfile \'#$index\' >$tfile2 2>>$efile); 
     45    }); 
     46    if ($retcode) { 
     47        debuglog("$conf->{focr_bin_gifinter}: cannot extract image#${index}"); 
     48        return $tfile; 
    4449    } 
    4550    return $tfile2; 
     
    5560    my @stderr_data; 
    5661 
     62    my %info = ( 
     63        'error' => 0, 
     64        'loop' => 0, 
     65        'loop_count' => 0, 
     66        'delays' => [], 
     67        'has_local_color_table' => 0 
     68    ); 
     69 
     70 
    5771    my $retcode = $t->run_and_catch(sub { 
    5872        @stdout_data = qx($conf->{"focr_bin_gifsicle"} --info $giffile); 
     
    6074 
    6175    if ($retcode) { 
    62         #FIXME: WARN HERE 
    63     } 
     76        debuglog("$conf->{'focr_bin_gifsicle'}: Timed out [$retcode], data unavailable..."); 
     77    } else { 
     78        my $output = join("", @stdout_data); 
     79        my ($globalinfo, @frameinfo) 
     80            = split /^ \s+ \+ \s+ (?=image \s+ \#\d+)/mx, $output; 
    6481 
    65     my $output = join("", @stdout_data); 
    66      
    67     my ($globalinfo, @frameinfo) 
    68         = split /^ \s+ \+ \s+ (?=image \s+ \#\d+)/mx, $output; 
     82        if ($globalinfo =~ /^ \s* loop \s+ (forever|count \s+ (\d+))/mx) { 
     83            $info{'loop'} = 1; 
     84            $info{'loop_count'} = $2 ? ($2 + 0) : 0; 
     85        } 
    6986 
    70     my %info = ( 'loop' => 0, 
    71                  'loop_count' => 0, 
    72                  'delays' => [], 
    73                  'has_local_color_table' => 0 ); 
    74  
    75     if ($globalinfo =~ /^ \s* loop \s+ (forever|count \s+ (\d+))/mx) { 
    76         $info{'loop'} = 1; 
    77         $info{'loop_count'} = $2 ? ($2 + 0) : 0; 
    78     } 
    79  
    80     my $frameno = 0; 
    81     foreach my $info (@frameinfo) { 
    82         # We could just match the delays, but we'll also check the image#'s 
    83         # as a sanity check. 
    84         my ($n, $delay) = $info =~ m{ image \s+ \#(\d+) 
     87        my $frameno = 0; 
     88        foreach my $info (@frameinfo) { 
     89            # We could just match the delays, but we'll also check the image#'s 
     90            # as a sanity check. 
     91            my ($n, $delay) = $info =~ m{ image \s+ \#(\d+) 
    8592                                      (?: .* \b delay \s+ (\d+(?:\.\d+)?) s)? 
    8693                                      }sx; 
    87         #FIXME: Handle this error 
    88         $n == $frameno 
    89             or debuglog ( "Trouble parsing 'gifsicle --info' output.\n" 
    90                      . "  Expected 'image \#$frameno', found 'image \#$n'" ); 
    91  
    92         $info{'delays'}->[$frameno++] = $delay ? $delay + 0.0 : 0.0; 
    93         $info{'has_local_color_table'} ||= $output =~ /local\s+color\s+table/; 
     94            if ($n != $frameno) { 
     95                debuglog ( "Trouble parsing 'gifsicle --info' output.\n" 
     96                     . "  Expected 'image \#$frameno', found 'image \#$n', skipping..." ); 
     97                $info{'error'}++; 
     98            } else { 
     99                $info{'delays'}->[$frameno++] = $delay ? $delay + 0.0 : 0.0; 
     100                $info{'has_local_color_table'} ||= $output =~ /local\s+color\s+table/; 
     101            } 
     102        } 
    94103    } 
    95104