| 1 | package PDF::Builder::Resource::XObject::Image::TIFF; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use base 'PDF::Builder::Resource::XObject::Image'; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '3.028'; # VERSION | |||||||||||||||||||||||||||||||||||
| 9 | 2 | our $LAST_UPDATE = '3.027'; # manually update whenever code is changed | |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Compress::Zlib; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use PDF::Builder::Basic::PDF::Utils; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use PDF::Builder::Resource::XObject::Image::TIFF::File; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use PDF::Builder::Util; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||
| 18 | =head1 NAME | ||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||
| 20 | PDF::Builder::Resource::XObject::Image::TIFF - TIFF image support | ||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||
| 22 | Inherits from L<PDF::Builder::Resource::XObject::Image> | ||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||
| 24 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||
| 26 | =head2 new | ||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||
| 28 | $res = PDF::Builder::Resource::XObject::Image::TIFF->new($pdf, $file, %opts) | ||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||
| 30 | =over | ||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | Returns a TIFF-image object. | ||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||
| 34 | If the Graphics::TIFF package is installed, the TIFF_GT library will be used | ||||||||||||||||||||||||||||||||||||
| 35 | instead of the TIFF library. In such a case, use of the TIFF library may be | ||||||||||||||||||||||||||||||||||||
| 36 | forced via the C<nouseGT> flag (see Builder documentation for C<image_tiff()>). | ||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||
| 38 | Options: | ||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||
| 40 | =over | ||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||
| 42 | =item 'name' => 'string' | ||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||
| 44 | This is the name you can give for the TIFF image object. The default is Ixnnnn. | ||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||
| 46 | =back | ||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||
| 48 | Remember that you need to use the Builder.pm method image_tiff in order to | ||||||||||||||||||||||||||||||||||||
| 49 | display a TIFF file. | ||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||
| 51 | =back | ||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||
| 53 | =cut | ||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||
| 55 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=29.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 56 | 4 | my ($class, $pdf, $file, %opts) = @_; | |||||||||||||||||||||||||||||||||||
| 57 | # copy dashed option names to preferred undashed names | ||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (defined $opts{'-nouseGT'} && !defined $opts{'nouseGT'}) { $opts{'nouseGT'} = delete($opts{'-nouseGT'}); } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts{"-nouseGT"} and not defined $opts{"nouseGT"}
MC/DC0%0/2
defined $opts{"-nouseGT"} and not defined $opts{"nouseGT"}
defined $opts{"-nouseGT"}
not defined $opts{"nouseGT"}
Truth table33%1/3
A and not(B)
A= defined $opts{"-nouseGT"}B= not defined $opts{"nouseGT"}
| |||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if (defined $opts{'-name'} && !defined $opts{'name'}) { $opts{'name'} = delete($opts{'-name'}); } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts{"-name"} and not defined $opts{"name"}
MC/DC0%0/2
defined $opts{"-name"} and not defined $opts{"name"}
defined $opts{"-name"}
not defined $opts{"name"}
Truth table33%1/3
A and not(B)
A= defined $opts{"-name"}B= not defined $opts{"name"}
| |||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (defined $opts{'-compress'} && !defined $opts{'compress'}) { $opts{'compress'} = delete($opts{'-compress'}); } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts{"-compress"} and not defined $opts{"compress"}
MC/DC0%0/2
defined $opts{"-compress"} and not defined $opts{"compress"}
defined $opts{"-compress"}
not defined $opts{"compress"}
Truth table33%1/3
A and not(B)
A= defined $opts{"-compress"}B= not defined $opts{"compress"}
| |||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||
| 62 | 4 | my ($name, $compress); | |||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if (exists $opts{'name'}) { $name = $opts{'name'}; } | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 64 | #if (exists $opts{'compress'}) { $compress = $opts{'compress'}; } | ||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||
| 66 | 4 | my $self; | |||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||
| 68 | 4 | my $tif = PDF::Builder::Resource::XObject::Image::TIFF::File->new($file, %opts); | |||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||
| 70 | # dump everything in tif except huge data streams | ||||||||||||||||||||||||||||||||||||
| 71 | # foreach (sort keys %{ $tif }) { | ||||||||||||||||||||||||||||||||||||
| 72 | # if ($_ eq ' stream') { next; } | ||||||||||||||||||||||||||||||||||||
| 73 | # if ($_ eq ' apipdf') { next; } | ||||||||||||||||||||||||||||||||||||
| 74 | # if ($_ eq ' realised') { next; } | ||||||||||||||||||||||||||||||||||||
| 75 | # if ($_ eq ' uid') { next; } | ||||||||||||||||||||||||||||||||||||
| 76 | # if (defined $tif->{$_}) { | ||||||||||||||||||||||||||||||||||||
| 77 | # print "\$tif->{'$_'} = '".($tif->{$_})."'\n"; | ||||||||||||||||||||||||||||||||||||
| 78 | # } else { | ||||||||||||||||||||||||||||||||||||
| 79 | # print "\$tif->{'$_'} = ?\n"; | ||||||||||||||||||||||||||||||||||||
| 80 | # } | ||||||||||||||||||||||||||||||||||||
| 81 | # } | ||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||
| 83 | # in case of problematic things | ||||||||||||||||||||||||||||||||||||
| 84 | # proxy to other modules | ||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | $class = ref($class) if ref($class); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | $self = $class->SUPER::new($pdf, $name || 'Ix'.pdfkey()); | ||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$name || 'Ix' . pdfkey()
MC/DC0%0/1
$name || 'Ix' . pdfkey()
$name
Truth table50%1/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||
| 89 | 3 | ▶ | $pdf->new_obj($self) unless $self->is_obj($pdf); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||
| 91 | 3 | $self->{' apipdf'} = $pdf; | |||||||||||||||||||||||||||||||||||
| 92 | 3 | weaken $self->{' apipdf'}; | |||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||
| 94 | 3 | $self->read_tiff($pdf, $tif); | |||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||
| 96 | 3 | $tif->close(); | |||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||
| 98 | 3 | return $self; | |||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||
| 101 | =head2 usesLib | ||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||
| 103 | $mode = $tif->usesLib() | ||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||
| 105 | =over | ||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||
| 107 | Returns 1 if Graphics::TIFF installed and used, 0 if not installed, or -1 if | ||||||||||||||||||||||||||||||||||||
| 108 | installed but not used (nouseGT option given to C<image_tiff>). | ||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||
| 110 | B<Caution:> this method can only be used I<after> the image object has been | ||||||||||||||||||||||||||||||||||||
| 111 | created. It can't tell you whether Graphics::TIFF is available in | ||||||||||||||||||||||||||||||||||||
| 112 | advance of actually using it, in case you want to use some functionality | ||||||||||||||||||||||||||||||||||||
| 113 | available only in TIFF_GT. See the <PDF::Builder> LA_GT() call if you | ||||||||||||||||||||||||||||||||||||
| 114 | need to know in advance. | ||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||
| 116 | =back | ||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | sub usesLib { | ||||||||||||||||||||||||||||||||||
|
Subroutine
usesLib: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 121 | 2 | my ($self) = shift; | |||||||||||||||||||||||||||||||||||
| 122 | # should be 0 for Graphics::TIFF not installed, or -1 for is installed, | ||||||||||||||||||||||||||||||||||||
| 123 | # but not using it | ||||||||||||||||||||||||||||||||||||
| 124 | 2 | return $self->{'usesGT'}->val(); | |||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | sub handle_generic { | ||||||||||||||||||||||||||||||||||
|
Subroutine
handle_generic: called CC=4 SCAR=20.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 128 | 2 | my ($self, $pdf, $tif) = @_; | |||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||
| 130 | 2 | ▶ | if ($tif->{'filter'}) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 131 | # should we die here ? | ||||||||||||||||||||||||||||||||||||
| 132 | # die "unknown tiff-compression "; | ||||||||||||||||||||||||||||||||||||
| 133 | 0 | $self->filters($tif->{'filter'}); | |||||||||||||||||||||||||||||||||||
| 134 | 0 | $self->{' nofilt'} = 1; | |||||||||||||||||||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||||||||||||||||||
| 136 | 2 | $self->filters('FlateDecode'); | |||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | if (ref($tif->{'imageOffset'})) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 140 | 0 | $self->{' stream'} = ''; | |||||||||||||||||||||||||||||||||||
| 141 | 0 | my $d = scalar @{$tif->{'imageOffset'}}; | |||||||||||||||||||||||||||||||||||
| 142 | 0 | foreach (1 .. $d) { | |||||||||||||||||||||||||||||||||||
| 143 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||
| 144 | 0 | $tif->{'fh'}->seek(shift(@{$tif->{'imageOffset'}}), 0); | |||||||||||||||||||||||||||||||||||
| 145 | 0 | $tif->{'fh'}->read($buf, shift(@{$tif->{'imageLength'}})); | |||||||||||||||||||||||||||||||||||
| 146 | 0 | $self->{' stream'} .= $buf; | |||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||||||||||||||||||
| 149 | 2 | $tif->{'fh'}->seek($tif->{'imageOffset'}, 0); | |||||||||||||||||||||||||||||||||||
| 150 | 2 | $tif->{'fh'}->read($self->{' stream'}, $tif->{'imageLength'}); | |||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||
| 153 | 2 | return $self; | |||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub handle_flate { | ||||||||||||||||||||||||||||||||||
|
Subroutine
handle_flate: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 157 | 0 | my ($self, $pdf, $tif) = @_; | |||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||
| 159 | 0 | $self->filters('FlateDecode'); | |||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | if (ref($tif->{'imageOffset'})) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->{' stream'} = ''; | |||||||||||||||||||||||||||||||||||
| 163 | 0 | my $d = scalar @{$tif->{'imageOffset'}}; | |||||||||||||||||||||||||||||||||||
| 164 | 0 | foreach (1 .. $d) { | |||||||||||||||||||||||||||||||||||
| 165 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||
| 166 | 0 | $tif->{'fh'}->seek(shift(@{$tif->{'imageOffset'}}), 0); | |||||||||||||||||||||||||||||||||||
| 167 | 0 | $tif->{'fh'}->read($buf, shift(@{$tif->{'imageLength'}})); | |||||||||||||||||||||||||||||||||||
| 168 | 0 | $buf = uncompress($buf); | |||||||||||||||||||||||||||||||||||
| 169 | 0 | $self->{' stream'} .= $buf; | |||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||
| 171 | } else { | ||||||||||||||||||||||||||||||||||||
| 172 | 0 | $tif->{'fh'}->seek($tif->{'imageOffset'}, 0); | |||||||||||||||||||||||||||||||||||
| 173 | 0 | $tif->{'fh'}->read($self->{' stream'}, $tif->{'imageLength'}); | |||||||||||||||||||||||||||||||||||
| 174 | 0 | $self->{' stream'} = uncompress($self->{' stream'}); | |||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||
| 177 | 0 | return $self; | |||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | sub handle_lzw { | ||||||||||||||||||||||||||||||||||
|
Subroutine
handle_lzw: called CC=5 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 181 | 1 | my ($self, $pdf, $tif) = @_; | |||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||
| 183 | 1 | $self->{' nofilt'} = 1; | |||||||||||||||||||||||||||||||||||
| 184 | 1 | $self->{'Filter'} = PDFArray(PDFName('LZWDecode')); | |||||||||||||||||||||||||||||||||||
| 185 | 1 | my $decode = PDFDict(); | |||||||||||||||||||||||||||||||||||
| 186 | 1 | $self->{'DecodeParms'} = PDFArray($decode); | |||||||||||||||||||||||||||||||||||
| 187 | 1 | $decode->{'Columns'} = PDFNum($tif->{'imageWidth'}); | |||||||||||||||||||||||||||||||||||
| 188 | 1 | $decode->{'Rows'} = PDFNum($tif->{'imageHeight'}); | |||||||||||||||||||||||||||||||||||
| 189 | 1 | $decode->{'DamagedRowsBeforeError'} = PDFNum(100); | |||||||||||||||||||||||||||||||||||
| 190 | 1 | $decode->{'EndOfLine'} = PDFBool(1); | |||||||||||||||||||||||||||||||||||
| 191 | 1 | $decode->{'EncodedByteAlign'} = PDFBool(1); | |||||||||||||||||||||||||||||||||||
| 192 | 1 | ▶ | if (defined $tif->{'Predictor'} and $tif->{'Predictor'} > 1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $tif->{"Predictor"} and $tif->{"Predictor"} > 1
MC/DC0%0/2
defined $tif->{"Predictor"} and $tif->{"Predictor"} > 1
defined $tif->{"Predictor"}
$tif->{"Predictor"} > 1
Truth table33%1/3
A and B
A= defined $tif->{"Predictor"}B= $tif->{"Predictor"} > 1
| |||||||||||||||||||||||||||||||||||||
| 193 | 0 | $decode->{'Predictor'} = PDFNum($tif->{'Predictor'}); | |||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | if (ref($tif->{'imageOffset'})) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 197 | 0 | $self->{' stream'} = ''; | |||||||||||||||||||||||||||||||||||
| 198 | 0 | my $d = scalar @{$tif->{'imageOffset'}}; | |||||||||||||||||||||||||||||||||||
| 199 | 0 | foreach (1 .. $d) { | |||||||||||||||||||||||||||||||||||
| 200 | 0 | $tif->{'fh'}->seek(shift(@{$tif->{'imageOffset'}}), 0); | |||||||||||||||||||||||||||||||||||
| 201 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||
| 202 | 0 | $tif->{'fh'}->read($buf, shift(@{$tif->{'imageLength'}})); | |||||||||||||||||||||||||||||||||||
| 203 | 0 | my $filter = PDF::Builder::Basic::PDF::Filter::LZWDecode->new(); | |||||||||||||||||||||||||||||||||||
| 204 | 0 | $self->{' stream'} .= $filter->infilt($buf); | |||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $filter = PDF::Builder::Basic::PDF::Filter::LZWDecode->new(); | |||||||||||||||||||||||||||||||||||
| 207 | 0 | $self->{' stream'} = $filter->outfilt($self->{' stream'}); | |||||||||||||||||||||||||||||||||||
| 208 | } else { | ||||||||||||||||||||||||||||||||||||
| 209 | 1 | $tif->{'fh'}->seek($tif->{'imageOffset'}, 0); | |||||||||||||||||||||||||||||||||||
| 210 | 1 | $tif->{'fh'}->read($self->{' stream'}, $tif->{'imageLength'}); | |||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||
| 213 | 1 | return $self; | |||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | sub handle_ccitt { | ||||||||||||||||||||||||||||||||||
|
Subroutine
handle_ccitt: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 217 | 0 | my ($self, $pdf, $tif) = @_; | |||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||
| 219 | 0 | $self->{' nofilt'} = 1; | |||||||||||||||||||||||||||||||||||
| 220 | 0 | $self->{'Filter'} = PDFName('CCITTFaxDecode'); | |||||||||||||||||||||||||||||||||||
| 221 | 0 | $self->{'DecodeParms'} = PDFDict(); | |||||||||||||||||||||||||||||||||||
| 222 | $self->{'DecodeParms'}->{'K'} = ($tif->{'ccitt'} == 4 || | ||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | (($tif->{'g3Options'}||0) & 0x1))? PDFNum(-1): PDFNum(0); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$tif->{"ccitt"} == 4 or ($tif->{"g3Options"} || 0) & 1
$tif->{'g3Options'} || 0
MC/DC0%0/2
$tif->{"ccitt"} == 4 or ($tif->{"g3Options"} || 0) & 1
$tif->{"ccitt"} == 4
$tif->{'g3Options'}
Truth table0%0/3
A or B
A= $tif->{"ccitt"} == 4B= $tif->{'g3Options'}
| |||||||||||||||||||||||||||||||||||||
| 224 | 0 | $self->{'DecodeParms'}->{'Columns'} = PDFNum($tif->{'imageWidth'}); | |||||||||||||||||||||||||||||||||||
| 225 | 0 | $self->{'DecodeParms'}->{'Rows'} = PDFNum($tif->{'imageHeight'}); | |||||||||||||||||||||||||||||||||||
| 226 | $self->{'DecodeParms'}->{'BlackIs1'} = | ||||||||||||||||||||||||||||||||||||
| 227 | 0 | ▶ | PDFBool(($tif->{'whiteIsZero'}||0) == 0? 1: 0); | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$tif->{'whiteIsZero'} || 0
MC/DC0%0/1
$tif->{'whiteIsZero'} || 0
$tif->{'whiteIsZero'}
Truth table0%0/2
A
A= $tif->{'whiteIsZero'}
| |||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if (defined($tif->{'g3Options'}) && ($tif->{'g3Options'} & 0x4)) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $tif->{"g3Options"} and $tif->{"g3Options"} & 4
MC/DC0%0/2
defined $tif->{"g3Options"} and $tif->{"g3Options"} & 4
defined $tif->{"g3Options"}
$tif->{"g3Options"} & 4
Truth table0%0/3
A and B
A= defined $tif->{"g3Options"}B= $tif->{"g3Options"} & 4
| |||||||||||||||||||||||||||||||||||||
| 229 | 0 | $self->{'DecodeParms'}->{'EndOfLine'} = PDFBool(1); | |||||||||||||||||||||||||||||||||||
| 230 | 0 | $self->{'DecodeParms'}->{'EncodedByteAlign'} = PDFBool(1); | |||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||
| 232 | # $self->{'DecodeParms'} = PDFArray($self->{'DecodeParms'}); | ||||||||||||||||||||||||||||||||||||
| 233 | 0 | $self->{'DecodeParms'}->{'DamagedRowsBeforeError'} = PDFNum(100); | |||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if (ref($tif->{'imageOffset'})) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 236 | 0 | die "Chunked CCITT G4 TIFF not supported."; | |||||||||||||||||||||||||||||||||||
| 237 | } else { | ||||||||||||||||||||||||||||||||||||
| 238 | 0 | $tif->{'fh'}->seek($tif->{'imageOffset'}, 0); | |||||||||||||||||||||||||||||||||||
| 239 | 0 | $tif->{'fh'}->read($self->{' stream'}, $tif->{'imageLength'}); | |||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||
| 242 | 0 | return $self; | |||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||
| 245 | 3 | ▶ | sub read_tiff { | ||||||||||||||||||||||||||||||||||
|
Subroutine
read_tiff: called CC=19 SCAR=44.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||
| 246 | 3 | my ($self, $pdf, $tif) = @_; | |||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||
| 248 | 3 | $self->width($tif->{'imageWidth'}); | |||||||||||||||||||||||||||||||||||
| 249 | 3 | $self->height($tif->{'imageHeight'}); | |||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | if ($tif->{'colorSpace'} eq 'Indexed') { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $dict = PDFDict(); | |||||||||||||||||||||||||||||||||||
| 252 | 0 | $pdf->new_obj($dict); | |||||||||||||||||||||||||||||||||||
| 253 | $self->colorspace(PDFArray(PDFName($tif->{'colorSpace'}), | ||||||||||||||||||||||||||||||||||||
| 254 | 0 | PDFName('DeviceRGB'), PDFNum(2**$tif->{'bitsPerSample'}-1), $dict)); | |||||||||||||||||||||||||||||||||||
| 255 | 0 | $dict->{'Filter'} = PDFArray(PDFName('FlateDecode')); | |||||||||||||||||||||||||||||||||||
| 256 | 0 | $tif->{'fh'}->seek($tif->{'colorMapOffset'}, 0); | |||||||||||||||||||||||||||||||||||
| 257 | 0 | my $colormap; | |||||||||||||||||||||||||||||||||||
| 258 | my $straight; | ||||||||||||||||||||||||||||||||||||
| 259 | 0 | $tif->{'fh'}->read($colormap, $tif->{'colorMapLength'}); | |||||||||||||||||||||||||||||||||||
| 260 | 0 | $dict->{' stream'} = ''; | |||||||||||||||||||||||||||||||||||
| 261 | 0 | $straight .= pack('C', ($_/256)) for | |||||||||||||||||||||||||||||||||||
| 262 | unpack($tif->{'short'} . '*', $colormap); | ||||||||||||||||||||||||||||||||||||
| 263 | 0 | foreach my $c (0 .. (($tif->{'colorMapSamples'}/3)-1)) { | |||||||||||||||||||||||||||||||||||
| 264 | 0 | $dict->{' stream'} .= substr($straight, $c, 1); | |||||||||||||||||||||||||||||||||||
| 265 | 0 | $dict->{' stream'} .= substr($straight, $c + ($tif->{'colorMapSamples'}/3), 1); | |||||||||||||||||||||||||||||||||||
| 266 | 0 | $dict->{' stream'} .= substr($straight, $c + ($tif->{'colorMapSamples'}/3)*2, 1); | |||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||
| 268 | } else { | ||||||||||||||||||||||||||||||||||||
| 269 | 3 | $self->colorspace($tif->{'colorSpace'}); | |||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||
| 272 | 3 | $self->{'Interpolate'} = PDFBool(1); | |||||||||||||||||||||||||||||||||||
| 273 | 3 | $self->bits_per_component($tif->{'bitsPerSample'}); | |||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||
| 275 | # swaps 0 and 1 ([0 1] -> [1 0]) in certain cases | ||||||||||||||||||||||||||||||||||||
| 276 | 3 | ▶ | if (($tif->{'whiteIsZero'}||0) == 1 && | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition71%5/7
($tif->{"whiteIsZero"} || 0) == 1 and ($tif->{"filter"} || "") ne "CCITTFaxDecode"
$tif->{'whiteIsZero'} || 0
$tif->{'filter'} || ''
MC/DC50%1/2
($tif->{"whiteIsZero"} || 0) == 1 and ($tif->{"filter"} || "") ne "CCITTFaxDecode"
$tif->{'whiteIsZero'}
$tif->{'filter'}
Truth table66%2/3
A and B
A= $tif->{'whiteIsZero'}B= $tif->{'filter'}
| |||||||||||||||||||||||||||||||||||||
| 277 | ($tif->{'filter'}||'') ne 'CCITTFaxDecode') { | ||||||||||||||||||||||||||||||||||||
| 278 | 1 | $self->{'Decode'} = PDFArray(PDFNum(1), PDFNum(0)); | |||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||
| 281 | # check filters and handle separately | ||||||||||||||||||||||||||||||||||||
| 282 | 3 | ▶ | if (defined $tif->{'filter'} and $tif->{'filter'} eq 'CCITTFaxDecode') { | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
defined $tif->{"filter"} and $tif->{"filter"} eq "CCITTFaxDecode"
MC/DC0%0/2
defined $tif->{"filter"} and $tif->{"filter"} eq "CCITTFaxDecode"
defined $tif->{"filter"}
$tif->{"filter"} eq "CCITTFaxDecode"
Truth table66%2/3
A and B
A= defined $tif->{"filter"}B= $tif->{"filter"} eq "CCITTFaxDecode"
| |||||||||||||||||||||||||||||||||||||
| 283 | 0 | $self->handle_ccitt($pdf, $tif); | |||||||||||||||||||||||||||||||||||
| 284 | ▶ | } elsif (defined $tif->{'filter'} and $tif->{'filter'} eq 'LZWDecode') { | |||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $tif->{"filter"} and $tif->{"filter"} eq "LZWDecode"
MC/DC50%1/2
defined $tif->{"filter"} and $tif->{"filter"} eq "LZWDecode"
defined $tif->{"filter"}
$tif->{"filter"} eq "LZWDecode"
Truth table66%2/3
A and B
A= defined $tif->{"filter"}B= $tif->{"filter"} eq "LZWDecode"
| |||||||||||||||||||||||||||||||||||||
| 285 | 1 | $self->handle_lzw($pdf, $tif); | |||||||||||||||||||||||||||||||||||
| 286 | ▶ | } elsif (defined $tif->{'filter'} and $tif->{'filter'} eq 'FlateDecode') { | |||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $tif->{"filter"} and $tif->{"filter"} eq "FlateDecode"
MC/DC0%0/2
defined $tif->{"filter"} and $tif->{"filter"} eq "FlateDecode"
defined $tif->{"filter"}
$tif->{"filter"} eq "FlateDecode"
Truth table33%1/3
A and B
A= defined $tif->{"filter"}B= $tif->{"filter"} eq "FlateDecode"
| |||||||||||||||||||||||||||||||||||||
| 287 | 0 | $self->handle_flate($pdf, $tif); | |||||||||||||||||||||||||||||||||||
| 288 | } else { | ||||||||||||||||||||||||||||||||||||
| 289 | 2 | $self->handle_generic($pdf, $tif); | |||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||
| 292 | # # dump everything in self except huge data streams | ||||||||||||||||||||||||||||||||||||
| 293 | # foreach (sort keys %{ $self }) { | ||||||||||||||||||||||||||||||||||||
| 294 | # if ($_ eq ' stream') { next; } | ||||||||||||||||||||||||||||||||||||
| 295 | # if ($_ eq ' apipdf') { next; } | ||||||||||||||||||||||||||||||||||||
| 296 | # if ($_ eq ' realised') { next; } | ||||||||||||||||||||||||||||||||||||
| 297 | # if ($_ eq ' uid') { next; } | ||||||||||||||||||||||||||||||||||||
| 298 | # if (defined $self->{$_}) { | ||||||||||||||||||||||||||||||||||||
| 299 | # print "\$self->{'$_'} = '".($self->{$_}->val())."'\n"; | ||||||||||||||||||||||||||||||||||||
| 300 | # } else { | ||||||||||||||||||||||||||||||||||||
| 301 | # print "\$self->{'$_'} = ?\n"; | ||||||||||||||||||||||||||||||||||||
| 302 | # } | ||||||||||||||||||||||||||||||||||||
| 303 | # } | ||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||
| 305 | 3 | ▶ | if ($tif->{'fillOrder'} == 2) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 306 | 0 | my @bl = (); | |||||||||||||||||||||||||||||||||||
| 307 | 0 | foreach my $n (0 .. 255) { | |||||||||||||||||||||||||||||||||||
| 308 | 0 | my $b = $n; | |||||||||||||||||||||||||||||||||||
| 309 | 0 | my $f = 0; | |||||||||||||||||||||||||||||||||||
| 310 | 0 | foreach (0 .. 7) { | |||||||||||||||||||||||||||||||||||
| 311 | 0 | my $bit = 0; | |||||||||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if ($b & 0x1) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 313 | 0 | $bit = 1; | |||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||
| 315 | 0 | $b >>= 1; | |||||||||||||||||||||||||||||||||||
| 316 | 0 | $f <<= 1; | |||||||||||||||||||||||||||||||||||
| 317 | 0 | $f |= $bit; | |||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||
| 319 | 0 | $bl[$n] = $f; | |||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $l = length($self->{' stream'}) - 1; | |||||||||||||||||||||||||||||||||||
| 322 | 0 | foreach my $n (0 .. $l) { | |||||||||||||||||||||||||||||||||||
| 323 | 0 | vec($self->{' stream'}, $n, 8) = $bl[vec($self->{' stream'}, $n, 8)]; | |||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||||||||
| 326 | 3 | $self->{' tiff'} = $tif; | |||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||
| 328 | 3 | return $self; | |||||||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||
| 331 | =head2 tiffTag | ||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||
| 333 | $value = $tif->tiffTag($tag) | ||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||
| 335 | =over | ||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||
| 337 | returns the value of the internal tiff-tag. | ||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||
| 339 | B<Useful Tags:> | ||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||
| 341 | imageDescription, imageId (strings) | ||||||||||||||||||||||||||||||||||||
| 342 | xRes, yRes (dpi; pixel/cm if resUnit==3) | ||||||||||||||||||||||||||||||||||||
| 343 | resUnit | ||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||
| 345 | =back | ||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||
| 347 | =cut | ||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | sub tiffTag { | ||||||||||||||||||||||||||||||||||
|
Subroutine
tiffTag: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 350 | 0 | my ($self, $tag) = @_; | |||||||||||||||||||||||||||||||||||
| 351 | 0 | return $self->{' tiff'}->{$tag}; | |||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||
| 354 | 2 | 1; | |||||||||||||||||||||||||||||||||||