]> git.imager.perl.org - imager.git/blob - PNG/PNG.pm
simplify XS for i_img_to_pal()
[imager.git] / PNG / PNG.pm
1 package Imager::File::PNG;
2 use strict;
3 use Imager;
4 use vars qw($VERSION @ISA);
5
6 BEGIN {
7   $VERSION = "0.94";
8
9   require XSLoader;
10   XSLoader::load('Imager::File::PNG', $VERSION);
11 }
12
13 Imager->register_reader
14   (
15    type=>'png',
16    single => 
17    sub { 
18      my ($im, $io, %hsh) = @_;
19      my $flags = 0;
20      $hsh{png_ignore_benign_errors}
21        and $flags |= IMPNG_READ_IGNORE_BENIGN_ERRORS;
22      $im->{IMG} = i_readpng_wiol($io, $flags);
23
24      unless ($im->{IMG}) {
25        $im->_set_error(Imager->_error_as_msg);
26        return;
27      }
28      return $im;
29    },
30   );
31
32 Imager->register_writer
33   (
34    type=>'png',
35    single => 
36    sub { 
37      my ($im, $io, %hsh) = @_;
38
39      $im->_set_opts(\%hsh, "i_", $im);
40      $im->_set_opts(\%hsh, "png_", $im);
41
42      unless (i_writepng_wiol($im->{IMG}, $io)) {
43        $im->_set_error(Imager->_error_as_msg);
44        return;
45      }
46      return $im;
47    },
48   );
49
50 __END__
51
52 =head1 NAME
53
54 Imager::File::PNG - read and write PNG files
55
56 =head1 SYNOPSIS
57
58   use Imager;
59
60   my $img = Imager->new;
61   $img->read(file=>"foo.png")
62     or die $img->errstr;
63
64   $img->write(file => "foo.png")
65     or die $img->errstr;
66
67 =head1 DESCRIPTION
68
69 Imager's PNG support is documented in L<Imager::Files>.
70
71 =head1 AUTHOR
72
73 Tony Cook <tonyc@cpan.org>
74
75 =head1 SEE ALSO
76
77 Imager, Imager::Files.
78
79 =cut