| 1 |
package Imager::File::TIFF; |
| 2 |
use 5.006; |
| 3 |
use strict; |
| 4 |
use Imager; |
| 5 |
|
| 6 |
BEGIN { |
| 7 |
our $VERSION = "1.006"; |
| 8 |
|
| 9 |
require XSLoader; |
| 10 |
XSLoader::load('Imager::File::TIFF', $VERSION); |
| 11 |
} |
| 12 |
|
| 13 |
Imager->register_reader |
| 14 |
( |
| 15 |
type=>'tiff', |
| 16 |
single => |
| 17 |
sub { |
| 18 |
my ($im, $io, %hsh) = @_; |
| 19 |
|
| 20 |
my $allow_incomplete = $hsh{allow_incomplete}; |
| 21 |
defined $allow_incomplete or $allow_incomplete = 0; |
| 22 |
|
| 23 |
my $page = $hsh{page}; |
| 24 |
defined $page or $page = 0; |
| 25 |
$im->{IMG} = i_readtiff_wiol($io, $allow_incomplete, $page); |
| 26 |
|
| 27 |
unless ($im->{IMG}) { |
| 28 |
$im->_set_error(Imager->_error_as_msg); |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
return $im; |
| 33 |
}, |
| 34 |
multiple => |
| 35 |
sub { |
| 36 |
my ($io, %hsh) = @_; |
| 37 |
|
| 38 |
my @imgs = i_readtiff_multi_wiol($io); |
| 39 |
unless (@imgs) { |
| 40 |
Imager->_set_error(Imager->_error_as_msg); |
| 41 |
return; |
| 42 |
} |
| 43 |
|
| 44 |
return map bless({ IMG => $_, ERRSTR => undef }, "Imager"), @imgs; |
| 45 |
}, |
| 46 |
); |
| 47 |
|
| 48 |
Imager->register_writer |
| 49 |
( |
| 50 |
type=>'tiff', |
| 51 |
single => |
| 52 |
sub { |
| 53 |
my ($im, $io, %hsh) = @_; |
| 54 |
|
| 55 |
$im->_set_opts(\%hsh, "i_", $im); |
| 56 |
$im->_set_opts(\%hsh, "tiff_", $im); |
| 57 |
$im->_set_opts(\%hsh, "exif_", $im); |
| 58 |
|
| 59 |
if (defined $hsh{class} && $hsh{class} eq "fax") { |
| 60 |
my $fax_fine = $hsh{fax_fine}; |
| 61 |
defined $fax_fine or $fax_fine = 1; |
| 62 |
if (!i_writetiff_wiol_faxable($im->{IMG}, $io, $fax_fine)) { |
| 63 |
$im->{ERRSTR} = Imager->_error_as_msg(); |
| 64 |
return undef; |
| 65 |
} |
| 66 |
} |
| 67 |
else { |
| 68 |
unless (i_writetiff_wiol($im->{IMG}, $io)) { |
| 69 |
$im->_set_error(Imager->_error_as_msg); |
| 70 |
return; |
| 71 |
} |
| 72 |
} |
| 73 |
return $im; |
| 74 |
}, |
| 75 |
multiple => |
| 76 |
sub { |
| 77 |
my ($class, $io, $opts, @ims) = @_; |
| 78 |
|
| 79 |
Imager->_set_opts($opts, "tiff_", @ims); |
| 80 |
Imager->_set_opts($opts, "exif_", @ims); |
| 81 |
|
| 82 |
my @work = map $_->{IMG}, @ims; |
| 83 |
my $tiff_class = $opts->{class}; |
| 84 |
defined $tiff_class or $tiff_class = ""; |
| 85 |
|
| 86 |
my $result; |
| 87 |
if ($tiff_class eq "fax") { |
| 88 |
my $fax_fine = $opts->{fax_fine}; |
| 89 |
defined $fax_fine or $fax_fine = 1; |
| 90 |
$result = i_writetiff_multi_wiol_faxable($io, $fax_fine, @work); |
| 91 |
} |
| 92 |
else { |
| 93 |
$result = i_writetiff_multi_wiol($io, @work); |
| 94 |
} |
| 95 |
unless ($result) { |
| 96 |
$class->_set_error($class->_error_as_msg); |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
return 1; |
| 101 |
}, |
| 102 |
); |
| 103 |
|
| 104 |
__END__ |
| 105 |
|
| 106 |
=head1 NAME |
| 107 |
|
| 108 |
Imager::File::TIFF - read and write TIFF files |
| 109 |
|
| 110 |
=head1 SYNOPSIS |
| 111 |
|
| 112 |
use Imager; |
| 113 |
|
| 114 |
my $img = Imager->new; |
| 115 |
$img->read(file=>"foo.tiff") |
| 116 |
or die $img->errstr; |
| 117 |
|
| 118 |
$img->write(file => "foo.tif") |
| 119 |
or die $img->errstr; |
| 120 |
|
| 121 |
my @codecs = Imager::File::TIFF->codecs; |
| 122 |
|
| 123 |
=head1 DESCRIPTION |
| 124 |
|
| 125 |
Imager's TIFF support is documented in L<Imager::Files>. |
| 126 |
|
| 127 |
=head1 CLASS METHODS |
| 128 |
|
| 129 |
=over |
| 130 |
|
| 131 |
=item Imager::File::TIFF->codecs |
| 132 |
|
| 133 |
Returns a list of hashrefs, each hash contains: |
| 134 |
|
| 135 |
=over |
| 136 |
|
| 137 |
=item * |
| 138 |
|
| 139 |
C<code> - the numeric TIFF defined identifier for this compression |
| 140 |
codec. |
| 141 |
|
| 142 |
=item * |
| 143 |
|
| 144 |
C<name> - the short name traditionally used by Imager::File::TIFF for |
| 145 |
this compression codec. This may be an empty string if |
| 146 |
Imager::File::TIFF doesn't have a name for this codec. |
| 147 |
|
| 148 |
=item * |
| 149 |
|
| 150 |
C<description> - the C<libtiff> defined name for this codec. You can |
| 151 |
now supply this name in the C<tiff_compression> tag to select this |
| 152 |
compression. |
| 153 |
|
| 154 |
=back |
| 155 |
|
| 156 |
=item Imager::File::TIFF->builddate |
| 157 |
|
| 158 |
The release date of the version of C<libtiff> Imager::File::TIFF was |
| 159 |
built with. eg. C<20230609>. |
| 160 |
|
| 161 |
=item Imager::File::TIFF->buildversion |
| 162 |
|
| 163 |
The version number of C<libtiff> Imager::File::TIFF was built with. |
| 164 |
eg. C<4.5.0>. Only available from C<libtiff> 4.5.0. |
| 165 |
|
| 166 |
=item Imager::File::TIFF->libversion |
| 167 |
|
| 168 |
The version number of C<libtiff> Imager::File::TIFF is running with. |
| 169 |
This should be the same as C<buildversion> at build time, but an |
| 170 |
upgrade to libtiff may result in C<libversion> changing without |
| 171 |
C<buildversion> changing. |
| 172 |
|
| 173 |
=back |
| 174 |
|
| 175 |
=head1 AUTHOR |
| 176 |
|
| 177 |
Tony Cook <[email protected]> |
| 178 |
|
| 179 |
=head1 SEE ALSO |
| 180 |
|
| 181 |
Imager, Imager::Files. |
| 182 |
|
| 183 |
http://www.simplesystems.org/libtiff/ |
| 184 |
|
| 185 |
=cut |