Merge the I/O buffering branch
[imager.git] / TIFF / TIFF.pm
CommitLineData
e5ee047b
TC
1package Imager::File::TIFF;
2use strict;
3use Imager;
4use vars qw($VERSION @ISA);
5
6BEGIN {
5fd542c7 7 $VERSION = "0.81";
e5ee047b
TC
8
9 eval {
10 require XSLoader;
11 XSLoader::load('Imager::File::TIFF', $VERSION);
12 1;
13 } or do {
e5ee047b
TC
14 require DynaLoader;
15 push @ISA, 'DynaLoader';
16 bootstrap Imager::File::TIFF $VERSION;
17 };
18}
19
20Imager->register_reader
21 (
22 type=>'tiff',
23 single =>
24 sub {
25 my ($im, $io, %hsh) = @_;
26
27 my $allow_incomplete = $hsh{allow_incomplete};
28 defined $allow_incomplete or $allow_incomplete = 0;
29
30 my $page = $hsh{page};
31 defined $page or $page = 0;
32 $im->{IMG} = i_readtiff_wiol($io, $allow_incomplete, $page);
33
34 unless ($im->{IMG}) {
35 $im->_set_error(Imager->_error_as_msg);
36 return;
37 }
38
39 return $im;
40 },
41 multiple =>
42 sub {
43 my ($io, %hsh) = @_;
44
45 my @imgs = i_readtiff_multi_wiol($io);
46 unless (@imgs) {
47 Imager->_set_error(Imager->_error_as_msg);
48 return;
49 }
50
51 return map bless({ IMG => $_, ERRSTR => undef }, "Imager"), @imgs;
52 },
53 );
54
55Imager->register_writer
56 (
57 type=>'tiff',
58 single =>
59 sub {
60 my ($im, $io, %hsh) = @_;
61
62 $im->_set_opts(\%hsh, "i_", $im);
63 $im->_set_opts(\%hsh, "tiff_", $im);
64 $im->_set_opts(\%hsh, "exif_", $im);
65
66 if (defined $hsh{class} && $hsh{class} eq "fax") {
67 my $fax_fine = $hsh{fax_fine};
68 defined $fax_fine or $fax_fine = 1;
69 if (!i_writetiff_wiol_faxable($im->{IMG}, $io, $fax_fine)) {
70 $im->{ERRSTR} = Imager->_error_as_msg();
71 return undef;
72 }
73 }
74 else {
75 unless (i_writetiff_wiol($im->{IMG}, $io)) {
76 $im->_set_error(Imager->_error_as_msg);
77 return;
78 }
79 }
80 return $im;
81 },
82 multiple =>
83 sub {
84 my ($class, $io, $opts, @ims) = @_;
85
86 Imager->_set_opts($opts, "tiff_", @ims);
87 Imager->_set_opts($opts, "exif_", @ims);
88
89 my @work = map $_->{IMG}, @ims;
90 my $tiff_class = $opts->{class};
91 defined $tiff_class or $tiff_class = "";
92
93 my $result;
94 if ($tiff_class eq "fax") {
95 my $fax_fine = $opts->{fax_fine};
96 defined $fax_fine or $fax_fine = 1;
97 $result = i_writetiff_multi_wiol_faxable($io, $fax_fine, @work);
98 }
99 else {
100 $result = i_writetiff_multi_wiol($io, @work);
101 }
102 unless ($result) {
103 $class->_set_error($class->_error_as_msg);
104 return;
105 }
106
107 return 1;
108 },
109 );
110
111__END__
112
113=head1 NAME
114
115Imager::File::TIFF - read and write TIFF files
116
117=head1 SYNOPSIS
118
119 use Imager;
120
121 my $img = Imager->new;
122 $img->read(file=>"foo.tiff")
123 or die $img->errstr;
124
125 $img->write(file => "foo.tif")
126 or die $img->errstr;
127
128=head1 DESCRIPTION
129
130Imager's TIFF support is documented in L<Imager::Files>.
131
132=head1 AUTHOR
133
5b480b14 134Tony Cook <tonyc@cpan.org>
e5ee047b
TC
135
136=head1 SEE ALSO
137
138Imager, Imager::Files.
139
140=cut