Skip to content

Commit

Permalink
add .rescue_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Nov 6, 2023
1 parent 259c6a2 commit bf27ab0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Prima/Image/Loader.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ sub new
while ( my ($k, $v) = each %opt) {
$events{$k} = $v if $k =~ /^on/;
}
my $rescue = delete $opt{rescue};

my $self = bless {
source => $source,
events => \%events,
options => \%opt,
rescue => $rescue,
};

my ( $l, $ok ) = $self->reload;
Expand Down Expand Up @@ -61,6 +63,11 @@ sub next
my $new_frame;
$new_frame = $opt{index} = delete $self->{rewind_request}
if defined $self->{rewind_request};
if ( $self->{rescue}) {
$new_frame = $opt{index} = $self->{current}
unless defined $new_frame;
$self->reload;
}
my @img = $self->{image}->load( undef, %{ $self->{events} } , %opt, session => 1 );
if ( $img[0] ) {
my $e = $img[0]->{extras};
Expand Down Expand Up @@ -99,11 +106,14 @@ sub current
delete $self->{error};
}

sub rescue_mode { $#_ ? $_[0]->{rescue} = $_[1] : $_[0]->{rescue} }

sub extras { shift->{extras} }
sub frames { shift->{frames} }
sub source { shift->{source} }
sub DESTROY { $_[0]->{image}-> destroy if $_[0]->{image} }


package Prima::Image::Saver;

sub new
Expand Down Expand Up @@ -216,6 +226,11 @@ The C<reload> method does this by reopening the loading session with all the
parameters supplied to C<new>. The programmer thus has a chance to record how
many successful frames were loaded, and only navigate these after the reload.
=item rescue BOOLEAN
If set, reopens the input stream or file on ever new frame.
This may help recover broken frames.
=item source
Return the filename or the file handle passed to the C<new> call.
Expand Down

0 comments on commit bf27ab0

Please sign in to comment.