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