Skip to content

Commit

Permalink
beautify API
Browse files Browse the repository at this point in the history
  • Loading branch information
dk committed Nov 3, 2023
1 parent ed33536 commit 608035a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
7 changes: 4 additions & 3 deletions Prima/Classes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -986,10 +986,11 @@ sub save_stream
sub has_codec
{
my $what = $_[1];
for ( map { $_->{fileShortType} } @{ Prima::Image->codecs }) {
return 1 if m/$what/;
my @ret;
for ( @{ Prima::Image->codecs }) {
push @ret, $_ if $_->{fileShortType} =~ m/$what/;
}
return 0;
return wantarray ? @ret : $ret[0];
}

package Prima::Icon;
Expand Down
23 changes: 14 additions & 9 deletions Prima/Image/Animate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ sub new

sub detect_animation
{
my (undef, $extras) = @_;
my (undef, $extras, $min_frames) = @_;

$min_frames //= 2;
return undef unless # more than 1 frame?
$extras &&
defined($extras->{codecID}) &&
$extras->{frames} &&
$extras->{frames} > 1;
$extras->{frames} >= $min_frames;
my $c = Prima::Image->codecs($extras-> {codecID}) or return 0;
return undef unless $c;

Expand Down Expand Up @@ -68,13 +70,13 @@ sub load
blending => 1,
%args,
);
warn $@ if @i && !$i[-1];

return unless @i;
return (undef, $@) unless @i && $i[-1];

my $model = $class->detect_animation($i[0]->{extras}) or return;
$model = 'Prima::Image::Animate::' . $model;
my $model = $class->detect_animation($i[0]->{extras}, 1);
return (undef, "not a recognized image or animation") unless $model;

$model = 'Prima::Image::Animate::' . $model;
return $model-> new( images => \@i);
} else {
my ($l,$error) = Prima::Image::Loader->new(
Expand All @@ -84,15 +86,18 @@ sub load
blending => 1,
%args,
);
warn($error), return unless $l;
return (undef, $error) unless $l;

my $model = $class->detect_animation($l->{extras}) or return;
$model = 'Prima::Image::Animate::' . $model;
my $model = $class->detect_animation($l->{extras});
return (undef, "not a recognized image or animation") unless $model;

$model = 'Prima::Image::Animate::' . $model;
return $model-> new( loader => $l );
}
}

sub loader { shift->{loader} }

sub add
{
my ( $self, $image) = @_;
Expand Down

0 comments on commit 608035a

Please sign in to comment.