API2/Resource/XObject/Image/PNG.pm

filter: Statementstmt 56.6% 154 / 272 Branchbran 60.0% 48 / 80 Conditioncond 44.7% 17 / 38 MC/DCmcdc 14.2% 3 / 21 Subroutinesub 100% 14 / 14 Podpod 33.3% 1 / 3 totaltotal 55.3% 237 / 428 SCAR 60.1
CC
64
Cov
56%
new
265.9
unprocess
60.5
PaethPredictor
4.0
CRAP 409.3
« API2/Basic/PDF/Pages.pm ↑ Summary API2/Page.pm »
1 package PDF::API2::Resource::XObject::Image::PNG;
2  
3 2 ▶use base 'PDF::API2::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 = '2.044'; # VERSION
9  
10 2 ▶use Compress::Zlib;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use POSIX qw(ceil floor);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use PDF::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use PDF::API2::Basic::PDF::Utils;
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 2 ▶eval 'use PDF::API2::XS::ImagePNG';
Subroutine BEGIN: called CC=1 SCAR=1.2
19 2 ▶my $use_xs = $@ ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$@ ? : 2 0 2
20  
21 sub new {
22 5 ▶ my ($class, $pdf, $file, $name, %opts) = @_;
Subroutine new: called CC=41 SCAR=55.8
Pod documented
23 5 my $self;
24  
25 5 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 5 5
26  
27 5 ▶ $self = $class->SUPER::new($pdf, $name || 'Px' . pdfkey());
Condition50%1/2
$name || 'Px' . pdfkey()
l!l
05
MC/DC0%0/1
$name || 'Px' . pdfkey()
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
28 5 ▶ $pdf->new_obj($self) unless $self->is_obj($pdf);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 5 5
29  
30 5 $self->{' apipdf'} = $pdf;
31 5 weaken $self->{' apipdf'};
32  
33 5 my $fh = IO::File->new();
34 5 ▶ if (ref($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file) { } 1 4 5
35 1 $fh = $file;
36 }
37 else {
38 4 ▶ open $fh, '<', $file or die "$!: $file";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file or die "$!: $file" 1 3 4
39 }
40 4 binmode $fh, ':raw';
41  
42 4 my ($buf, $l, $crc, $w, $h, $bpc, $cs, $cm, $fm, $im, $palette, $trns);
43 4 seek($fh, 8, 0);
44 4 $self->{' stream'} = '';
45 4 $self->{' nofilt'} = 1;
46 4 ▶ while (!eof($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $fh) 18 0 18
47 18 read($fh, $buf, 4);
48 18 $l = unpack('N', $buf);
49 18 read($fh, $buf, 4);
50 18 ▶ if ($buf eq 'IHDR') {
Branch: 5 branches
BranchTrueFalseTotal
if ($buf eq 'IHDR') { } 4 14 18
elsif ($buf eq 'PLTE') { } 2 12 14
elsif ($buf eq 'IDAT') { } 4 8 12
elsif ($buf eq 'tRNS') { } 0 8 8
elsif ($buf eq 'IEND') { } 4 4 8
51 4 read($fh, $buf, $l);
52 4 ($w, $h, $bpc, $cs, $cm, $fm, $im) = unpack('NNCCCCC', $buf);
53 4 ▶ die "Unsupported Compression($cm) Method" if $cm;
Branch: 1 branch
BranchTrueFalseTotal
if $cm 0 4 4
54 4 ▶ die "Unsupported Interlace($im) Method" if $im;
Branch: 1 branch
BranchTrueFalseTotal
if $im 0 4 4
55 4 ▶ die "Unsupported Filter($fm) Method" if $fm;
Branch: 1 branch
BranchTrueFalseTotal
if $fm 0 4 4
56 }
57 elsif ($buf eq 'PLTE') {
58 2 read($fh, $buf, $l);
59 2 $palette = $buf;
60 }
61 elsif ($buf eq 'IDAT') {
62 4 read($fh, $buf, $l);
63 4 $self->{' stream'} .= $buf;
64 }
65 elsif ($buf eq 'tRNS') {
66 0 read($fh, $buf, $l);
67 0 $trns = $buf;
68 }
69 elsif ($buf eq 'IEND') {
70 4 last;
71 }
72 else {
73 # skip ahead
74 4 seek($fh, $l, 1);
75 }
76 14 read($fh, $buf, 4);
77 14 $crc = $buf;
78 }
79 4 ▶ close $fh unless ref($file);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $file 3 1 4
80  
81 4 $self->width($w);
82 4 $self->height($h);
83  
84 # BPC = bits per component, and may be 1, 2, 4, 8, or 16 per the PNG spec.
85 # Color types may further restrict the available options. Additionally,
86 # this module doesn't currently support 16-bit components.
87 4 ▶ if ($bpc == 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bpc == 16) 0 4 4
88 0 die '16-bit colors/transparency are not supported.';
89 }
90 4 ▶ unless ($bpc == 1 or $bpc == 2 or $bpc == 4 or $bpc == 8) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($bpc == 1 or $bpc == 2 or $bpc == 4 or $bpc == 8) 0 4 4
Condition66%6/9
$bpc == 1 or $bpc == 2 or $bpc == 4 or $bpc == 8
l!l&&r!l&&!r
220
$bpc == 1 or $bpc == 2 or $bpc == 4
l!l&&r!l&&!r
202
$bpc == 1 or $bpc == 2
l!l&&r!l&&!r
202
MC/DC0%0/4
$bpc == 1 or $bpc == 2 or $bpc == 4 or $bpc == 8
$bpc == 1 $bpc == 2 $bpc == 4 $bpc == 8
Truth table40%2/5
A or B or C or D
A= $bpc == 1B= $bpc == 2C= $bpc == 4D= $bpc == 8
ABCDresult
1XXX1
01XX1
001X1
00011
00000
91 0 die "Invalid component bit depth: $bpc.";
92 }
93  
94 # Grayscale
95 4 ▶ if ($cs == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($cs == 0) { } 0 4 4
elsif ($cs == 2) { } 0 4 4
elsif ($cs == 3) { } 2 2 4
elsif ($cs == 4) { } 0 2 2
elsif ($cs == 6) { } 2 0 2
96 0 $self->filters('FlateDecode');
97 0 $self->colorspace('DeviceGray');
98 0 $self->bpc($bpc);
99 0 my $dict = PDFDict();
100 0 $self->{'DecodeParms'} = PDFArray($dict);
101 0 $dict->{'Predictor'} = PDFNum(15);
102 0 $dict->{'BitsPerComponent'} = PDFNum($bpc);
103 0 $dict->{'Colors'} = PDFNum(1);
104 0 $dict->{'Columns'} = PDFNum($w);
105 0 ▶ if (defined $trns and not $opts{'-notrans'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $trns and not $opts{"-notrans"}) 0 0 0
Condition0%0/3
defined $trns and not $opts{"-notrans"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $trns and not $opts{"-notrans"}
defined $trns not $opts{"-notrans"}
Truth table0%0/3
A and not(B)
A= defined $trnsB= not $opts{"-notrans"}
ABresult
0X0
100
111
106 0 my $m = mMax(unpack('n*', $trns));
107 0 my $n = mMin(unpack('n*', $trns));
108 0 $self->{'Mask'} = PDFArray(PDFNum($n), PDFNum($m));
109 }
110 }
111  
112 # RGB
113 elsif ($cs == 2) {
114 0 $self->filters('FlateDecode');
115 0 $self->colorspace('DeviceRGB');
116 0 $self->bpc($bpc);
117 0 my $dict = PDFDict();
118 0 $self->{'DecodeParms'} = PDFArray($dict);
119 0 $dict->{'Predictor'} = PDFNum(15);
120 0 $dict->{'BitsPerComponent'} = PDFNum($bpc);
121 0 $dict->{'Colors'} = PDFNum(3);
122 0 $dict->{'Columns'} = PDFNum($w);
123 0 ▶ if (defined $trns and not $opts{'-notrans'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $trns and not $opts{"-notrans"}) 0 0 0
Condition0%0/3
defined $trns and not $opts{"-notrans"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $trns and not $opts{"-notrans"}
defined $trns not $opts{"-notrans"}
Truth table0%0/3
A and not(B)
A= defined $trnsB= not $opts{"-notrans"}
ABresult
0X0
100
111
124 0 my @v = unpack('n*', $trns);
125 0 my (@cr, @cg, @cb, $m, $n);
126 0 ▶ while (scalar @v > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @v > 0) 0 0 0
127 0 push @cr, shift(@v);
128 0 push @cg, shift(@v);
129 0 push @cb, shift(@v);
130 }
131 0 @v = ();
132 0 $m = mMax(@cr);
133 0 $n = mMin(@cr);
134 0 push @v, $n, $m;
135 0 $m = mMax(@cg);
136 0 $n = mMin(@cg);
137 0 push @v, $n, $m;
138 0 $m = mMax(@cb);
139 0 $n = mMin(@cb);
140 0 push @v, $n, $m;
141 0 $self->{'Mask'} = PDFArray(map { PDFNum($_) } @v);
142 }
143 }
144  
145 # Palette Index
146 elsif ($cs == 3) {
147 2 my $dict = PDFDict();
148 2 $pdf->new_obj($dict);
149 2 $dict->{'Filter'} = PDFArray(PDFName('FlateDecode'));
150 2 $dict->{' stream'} = $palette;
151 2 $palette = '';
152 2 $self->filters('FlateDecode');
153 2 $self->colorspace(PDFArray(PDFName('Indexed'), PDFName('DeviceRGB'), PDFNum(int(length($dict->{' stream'}) / 3) - 1), $dict));
154 2 $self->bpc($bpc);
155 2 $dict = PDFDict();
156 2 $self->{'DecodeParms'} = PDFArray($dict);
157 2 $dict->{'Predictor'} = PDFNum(15);
158 2 $dict->{'BitsPerComponent'} = PDFNum($bpc);
159 2 $dict->{'Colors'} = PDFNum(1);
160 2 $dict->{'Columns'} = PDFNum($w);
161 2 ▶ if (defined $trns and not $opts{'-notrans'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $trns and not $opts{"-notrans"}) 0 2 2
Condition33%1/3
defined $trns and not $opts{"-notrans"}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $trns and not $opts{"-notrans"}
defined $trns not $opts{"-notrans"}
Truth table33%1/3
A and not(B)
A= defined $trnsB= not $opts{"-notrans"}
ABresult
0X0
100
111
162 0 $trns .= "\xFF" x 256;
163 0 $dict = PDFDict();
164 0 $pdf->new_obj($dict);
165 0 $dict->{'Type'} = PDFName('XObject');
166 0 $dict->{'Subtype'} = PDFName('Image');
167 0 $dict->{'Width'} = PDFNum($w);
168 0 $dict->{'Height'} = PDFNum($h);
169 0 $dict->{'ColorSpace'} = PDFName('DeviceGray');
170 0 $dict->{'Filter'} = PDFArray(PDFName('FlateDecode'));
171 0 $dict->{'BitsPerComponent'} = PDFNum(8);
172 0 $self->{'SMask'} = $dict;
173 0 my $scanline = 1 + ceil($bpc * $w / 8);
174 0 my $bpp = ceil($bpc / 8);
175 0 my $clearstream = unprocess($bpc, $bpp, 1, $w, $h, $scanline, \$self->{' stream'}, $file);
176 0 foreach my $n (0 .. ($h * $w) - 1) {
177 0 vec($dict->{' stream'}, $n, 8) = vec($trns, vec($clearstream, $n, $bpc), 8);
178 }
179 }
180 }
181  
182 # Grayscale + Alpha
183 elsif ($cs == 4) {
184 0 $self->filters('FlateDecode');
185 0 $self->colorspace('DeviceGray');
186 0 $self->bpc($bpc);
187 0 my $dict = PDFDict();
188 0 $self->{'DecodeParms'} = PDFArray($dict);
189 0 $dict->{'BitsPerComponent'} = PDFNum($bpc);
190 0 $dict->{'Colors'} = PDFNum(1);
191 0 $dict->{'Columns'} = PDFNum($w);
192  
193 # The unprocess call below removes the PNG optimizations, so use the
194 # default Predictor (none) instead of PNG optimized (15), as in other
195 # color types.
196 #
197 # $dict->{'Predictor'} = PDFNum(15);
198  
199 0 $dict = PDFDict();
200 0 ▶ unless ($opts{'-notrans'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"-notrans"}) 0 0 0
201 0 $pdf->new_obj($dict);
202 0 $dict->{'Type'} = PDFName('XObject');
203 0 $dict->{'Subtype'} = PDFName('Image');
204 0 $dict->{'Width'} = PDFNum($w);
205 0 $dict->{'Height'} = PDFNum($h);
206 0 $dict->{'ColorSpace'} = PDFName('DeviceGray');
207 0 $dict->{'Filter'} = PDFArray(PDFName('FlateDecode'));
208 0 $dict->{'BitsPerComponent'} = PDFNum($bpc);
209 0 $self->{'SMask'} = $dict;
210 }
211 0 my $scanline = 1 + ceil($bpc * 2 * $w / 8);
212 0 my $bpp = ceil($bpc * 2 / 8);
213 0 my $clearstream = unprocess($bpc, $bpp, 2, $w, $h, $scanline, \$self->{' stream'}, $file);
214 0 delete $self->{' nofilt'};
215 0 delete $self->{' stream'};
216 0 foreach my $n (0 .. ($h * $w) - 1) {
217 0 vec($self->{' stream'}, $n, $bpc) = vec($clearstream, $n * 2, $bpc);
218 0 vec($dict->{' stream'}, $n, $bpc) = vec($clearstream, $n * 2 + 1, $bpc);
219 }
220 }
221  
222 # RGB + Alpha
223 elsif ($cs == 6) {
224 2 $self->filters('FlateDecode');
225 2 $self->colorspace('DeviceRGB');
226 2 $self->bpc($bpc);
227 2 my $dict = PDFDict();
228 2 $self->{'DecodeParms'} = PDFArray($dict);
229 2 $dict->{'BitsPerComponent'} = PDFNum($bpc);
230 2 $dict->{'Colors'} = PDFNum(3);
231 2 $dict->{'Columns'} = PDFNum($w);
232  
233 # The unprocess call below removes the PNG optimizations, so use the
234 # default Predictor (none) instead of PNG optimized (15), as in other
235 # color types.
236 #
237 # $dict->{'Predictor'} = PDFNum(15);
238  
239 2 $dict = PDFDict();
240 2 ▶ unless ($opts{'-notrans'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts{"-notrans"}) 2 0 2
241 2 $pdf->new_obj($dict);
242 2 $dict->{'Type'} = PDFName('XObject');
243 2 $dict->{'Subtype'} = PDFName('Image');
244 2 $dict->{'Width'} = PDFNum($w);
245 2 $dict->{'Height'} = PDFNum($h);
246 2 $dict->{'ColorSpace'} = PDFName('DeviceGray');
247 2 $dict->{'Filter'} = PDFArray(PDFName('FlateDecode'));
248 2 $dict->{'BitsPerComponent'} = PDFNum($bpc);
249 2 $self->{'SMask'} = $dict;
250 }
251 2 my $scanline = 1 + ceil($bpc * 4 * $w / 8);
252 2 my $bpp = ceil($bpc * 4 / 8);
253 2 my $clearstream = unprocess($bpc, $bpp, 4, $w, $h, $scanline, \$self->{' stream'}, $file);
254 2 delete $self->{' nofilt'};
255 2 delete $self->{' stream'};
256  
257 # If possible, use XS to split the Alpha channel from the RGB channels,
258 # which is much faster than doing so in Perl.
259 2 ▶ if ($use_xs and $bpc == 8 and not $ENV{'PDFAPI2_PNG_PP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_xs and $bpc == 8 and not $ENV{'PDFAPI2_PNG_PP'}) { } 0 2 2
Condition33%2/6
$use_xs and $bpc == 8 and not $ENV{"PDFAPI2_PNG_PP"}
!ll&&!rl&&r
200
$use_xs and $bpc == 8
!ll&&!rl&&r
200
MC/DC0%0/3
$use_xs and $bpc == 8 and not $ENV{"PDFAPI2_PNG_PP"}
$use_xs $bpc == 8 not $ENV{"PDFAPI2_PNG_PP"}
Truth table25%1/4
A and B and not(C)
A= $use_xsB= $bpc == 8C= not $ENV{"PDFAPI2_PNG_PP"}
ABCresult
0XX0
10X0
1100
1111
260 # Convert the stream to an array before passing it to XS.
261 # Otherwise, a 0 byte in the stream would terminate the string.
262 0 my @stream = split '', $clearstream;
263 0 my @outstream_array = @{split_channels(\@stream, $w, $h)};
264 0 $self->{' stream'} = pack("C*", splice @outstream_array, 0, ($w * $h * 3));
265 0 $dict->{' stream'} = pack("C*", splice @outstream_array, 0, ($w * $h));
266 }
267 else {
268 2 foreach my $n (0 .. ($h * $w) - 1) {
269 218120 vec($self->{' stream'}, $n * 3, $bpc) = vec($clearstream, ($n * 4), $bpc);
270 218120 vec($self->{' stream'}, $n * 3 + 1, $bpc) = vec($clearstream, ($n * 4) + 1, $bpc);
271 218120 vec($self->{' stream'}, $n * 3 + 2, $bpc) = vec($clearstream, ($n * 4) + 2, $bpc);
272 218120 vec($dict->{' stream'}, $n, $bpc) = vec($clearstream, ($n * 4) + 3, $bpc);
273 }
274 }
275 }
276  
277 # Unknown/Unsupported
278 else {
279 0 die "Unknown PNG color type: $cs.";
280 }
281  
282 4 return $self;
283 }
284  
285 sub PaethPredictor {
286 94240 ▶ my ($a, $b, $c) = @_;
Subroutine PaethPredictor: called CC=4 SCAR=13.9
Pod undocumented
287 94240 my $p = $a + $b - $c;
288 94240 my $pa = abs($p - $a);
289 94240 my $pb = abs($p - $b);
290 94240 my $pc = abs($p - $c);
291 94240 ▶ if (($pa <= $pb) && ($pa <= $pc)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pa <= $pb and $pa <= $pc) { } 82304 11936 94240
elsif ($pb <= $pc) { } 11154 782 11936
Condition100%3/3
$pa <= $pb and $pa <= $pc
!ll&&!rl&&r
1119674082304
MC/DC100%2/2
$pa <= $pb and $pa <= $pc
$pa <= $pb $pa <= $pc
Truth table100%3/3
A and B
A= $pa <= $pbB= $pa <= $pc
ABresult
0X0
100
111
292 82304 return $a;
293 }
294 elsif ($pb <= $pc) {
295 11154 return $b;
296 }
297 else {
298 782 return $c;
299 }
300 }
301  
302 sub unprocess {
303 2 ▶ my ($bpc, $bpp, $comp, $width, $height, $scanline, $sstream, $file) = @_;
Subroutine unprocess: called CC=21 SCAR=41.0
Pod undocumented
304  
305 # If Image::PNG::Libpng is available, use it to uncompress and unfilter the
306 # image data much more quickly.
307 2 ▶ if ($file and not $ENV{'PDFAPI2_PNG_PP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and not $ENV{"PDFAPI2_PNG_PP"}) 1 1 2
Condition66%2/3
$file and not $ENV{"PDFAPI2_PNG_PP"}
!ll&&!rl&&r
011
MC/DC50%1/2
$file and not $ENV{"PDFAPI2_PNG_PP"}
$file not $ENV{"PDFAPI2_PNG_PP"}
Truth table66%2/3
A and not(B)
A= $fileB= not $ENV{"PDFAPI2_PNG_PP"}
ABresult
0X0
100
111
308 1 eval 'require Image::PNG::Libpng';
309 1 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 0 1 1
310 0 my $libpng;
311 0 eval {
312 0 $libpng = Image::PNG::Libpng::read_png_file($file);
313 };
314 0 ▶ return join('', @{$libpng->get_rows()}) if $libpng;
Branch: 1 branch
BranchTrueFalseTotal
if $libpng 0 0 0
315 }
316 }
317  
318 2 my $stream = uncompress($$sstream);
319 2 my $prev = '';
320 2 my $clearstream = '';
321  
322 # The XS code uses a uint8 array so can only handle bpc = 8
323 2 ▶ if ($use_xs and $bpc == 8 and not $ENV{'PDFAPI2_PNG_PP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($use_xs and $bpc == 8 and not $ENV{'PDFAPI2_PNG_PP'}) { } 0 2 2
Condition33%2/6
$use_xs and $bpc == 8 and not $ENV{"PDFAPI2_PNG_PP"}
!ll&&!rl&&r
200
$use_xs and $bpc == 8
!ll&&!rl&&r
200
MC/DC0%0/3
$use_xs and $bpc == 8 and not $ENV{"PDFAPI2_PNG_PP"}
$use_xs $bpc == 8 not $ENV{"PDFAPI2_PNG_PP"}
Truth table25%1/4
A and B and not(C)
A= $use_xsB= $bpc == 8C= not $ENV{"PDFAPI2_PNG_PP"}
ABCresult
0XX0
10X0
1100
1111
324 0 my $clearstream_array = [];
325 0 foreach my $n (0 .. $height - 1) {
326 0 my $line = substr($stream, $n * $scanline, $scanline);
327 0 my $filter = vec($line, 0, 8);
328 0 $line = substr($line, 1);
329  
330 0 my @in_line = split '', $line;
331 0 my @prev_line = split '', $prev;
332 0 my $clear_array = unfilter(\@in_line, \@prev_line, $filter, $bpp);
333 0 $prev = pack("C*", @{$clear_array});
334 0 foreach my $x (0 .. ($width * $comp) - 1) {
335 0 $clearstream_array->[($n * $width * $comp) + $x] = $clear_array->[$x];
336 }
337 2 ▶ no warnings 'uninitialized'; # ignore undefined array elements
Subroutine BEGIN: called CC=1 SCAR=0.0
338 0 $clearstream = pack("C*", @{$clearstream_array});
339 }
340 }
341 else {
342 2 foreach my $n (0 .. $height - 1) {
343 574 my $line = substr($stream, $n * $scanline, $scanline);
344 574 my $filter = vec($line, 0, 8);
345 574 my $clear = '';
346 574 $line = substr($line, 1);
347  
348 # See "Filter Algorithms" in the documentation below for definitions.
349 574 ▶ if ($filter == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($filter == 0) { } 0 574 574
elsif ($filter == 1) { } 18 556 574
elsif ($filter == 2) { } 494 62 556
elsif ($filter == 3) { } 0 62 62
elsif ($filter == 4) { } 62 0 62
350 0 $clear = $line;
351 }
352 elsif ($filter == 1) {
353 18 foreach my $x (0 .. length($line) - 1) {
354 27360 vec($clear, $x, 8) = (vec($line, $x, 8) + vec($clear, $x - $bpp, 8)) % 256;
355 }
356 }
357 elsif ($filter == 2) {
358 494 foreach my $x (0 .. length($line) - 1) {
359 750880 vec($clear, $x, 8) = (vec($line, $x, 8) + vec($prev, $x, 8)) % 256;
360 }
361 }
362 elsif ($filter == 3) {
363 0 foreach my $x (0 .. length($line) - 1) {
364 0 vec($clear, $x, 8) = (vec($line, $x, 8) + floor((vec($clear, $x - $bpp, 8) + vec($prev, $x, 8)) / 2)) % 256;
365 }
366 }
367 elsif ($filter == 4) {
368 62 foreach my $x (0 .. length($line) - 1) {
369 94240 vec($clear,$x,8) = (vec($line, $x, 8) + PaethPredictor(vec($clear, $x - $bpp, 8), vec($prev, $x, 8), vec($prev, $x - $bpp, 8))) % 256;
370 }
371 }
372  
373 574 $prev = $clear;
374 574 foreach my $x (0 .. ($width * $comp) - 1) {
375 872480 vec($clearstream, ($n * $width * $comp) + $x, $bpc) = vec($clear, $x, $bpc);
376 }
377 }
378 }
379 2 return $clearstream;
380 }
381  
382 2 1;
383  
384 __END__
« API2/Basic/PDF/Pages.pm ↑ Summary API2/Page.pm »