API2/Basic/PDF/Filter/LZWDecode.pm

filter: Statementstmt 17.1% 11 / 64 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 50.0% 3 / 6 Podpod 66.6% 2 / 3 totaltotal 14.0% 16 / 114 SCAR 53.9
CC
17
Cov
11%
infilt
210.0
read_dat
20.0
new
2.0
CRAP 220.0
« API2/Resource/CIDFont/TrueType.pm ↑ Summary API2/Annotation.pm »
1 package PDF::API2::Basic::PDF::Filter::LZWDecode;
2  
3 43 ▶use base 'PDF::API2::Basic::PDF::Filter::FlateDecode';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 43 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 43 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 43 our $VERSION = '2.044'; # VERSION
9  
10 sub new {
11 0 ▶ my ($class, $decode_parms) = @_;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
12 0 my $self = {
13 DecodeParms => $decode_parms,
14 };
15  
16 0 $self->{'table'} = [map { pack('C', $_) } (0 .. 255, 0, 0)];
17 0 $self->{'initial_code_length'} = 9;
18 0 $self->{'code_length'} = 9;
19 0 $self->{'clear_table'} = 256;
20 0 $self->{'eod_marker'} = 257;
21 0 $self->{'next_code'} = 258;
22  
23 0 bless $self, $class;
24 0 return $self;
25 }
26  
27 sub infilt {
28 0 ▶ my ($self, $data, $is_last) = @_;
Subroutine infilt: not called CC=14 SCAR=53.5
Pod documented
29 0 my ($code, $result);
30 0 my $partial_code = $self->{'partial_code'};
31 0 my $partial_bits = $self->{'partial_bits'};
32  
33 0 my $early_change = 1;
34 0 ▶ if ($self->{'DecodeParms'} and $self->{'DecodeParms'}->{'EarlyChange'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"DecodeParms"} and $self->{"DecodeParms"}{"EarlyChange"}) 0 0 0
Condition0%0/3
$self->{"DecodeParms"} and $self->{"DecodeParms"}{"EarlyChange"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"DecodeParms"} and $self->{"DecodeParms"}{"EarlyChange"}
$self->{"DecodeParms"} $self->{"DecodeParms"}{"EarlyChange"}
Truth table0%0/3
A and B
A= $self->{"DecodeParms"}B= $self->{"DecodeParms"}{"EarlyChange"}
ABresult
0X0
100
111
35 0 $early_change = $self->{'DecodeParms'}->{'EarlyChange'}->val();
36 }
37  
38 0 ▶ while ($data ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data ne "") 0 0 0
39 0 ($code, $partial_code, $partial_bits) = $self->read_dat(\$data, $partial_code, $partial_bits, $self->{'code_length'});
40 0 ▶ last unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 0 0 0
41  
42 0 ▶ unless ($early_change) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($early_change) 0 0 0
43 0 ▶ if ($self->{'next_code'} == (1 << $self->{'code_length'}) and $self->{'code_length'} < 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"next_code"} == 1 << $self->{"code_length"} and $self->{"code_length"} < 12) 0 0 0
Condition0%0/3
$self->{"next_code"} == 1 << $self->{"code_length"} and $self->{"code_length"} < 12
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"next_code"} == 1 << $self->{"code_length"} and $self->{"code_length"} < 12
$self->{"next_code"} == 1 << $self->{"code_length"} $self->{"code_length"} < 12
Truth table0%0/3
A and B
A= $self->{"next_code"} == 1 << $self->{"code_length"}B= $self->{"code_length"} < 12
ABresult
0X0
100
111
44 0 $self->{'code_length'}++;
45 }
46 }
47  
48 0 ▶ if ($code == $self->{'clear_table'}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($code == $self->{'clear_table'}) { } 0 0 0
elsif ($code == $self->{'eod_marker'}) { } 0 0 0
elsif ($code > $self->{'eod_marker'}) { } 0 0 0
49 0 $self->{'code_length'} = $self->{'initial_code_length'};
50 0 $self->{'next_code'} = $self->{'eod_marker'} + 1;
51 0 next;
52 }
53 elsif ($code == $self->{'eod_marker'}) {
54 0 last;
55 }
56 elsif ($code > $self->{'eod_marker'}) {
57 0 $self->{'table'}[$self->{'next_code'}] = $self->{'table'}[$code];
58 0 $self->{'table'}[$self->{'next_code'}] .= substr($self->{'table'}[$code + 1], 0, 1);
59 0 $result .= $self->{'table'}[$self->{'next_code'}];
60 0 $self->{'next_code'}++;
61 }
62 else {
63 0 $self->{'table'}[$self->{'next_code'}] = $self->{'table'}[$code];
64 0 $result .= $self->{'table'}[$self->{'next_code'}];
65 0 $self->{'next_code'}++;
66 }
67  
68 0 ▶ if ($early_change) {
Branch: 1 branch
BranchTrueFalseTotal
if ($early_change) 0 0 0
69 0 ▶ if ($self->{'next_code'} == (1 << $self->{'code_length'}) and $self->{'code_length'} < 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"next_code"} == 1 << $self->{"code_length"} and $self->{"code_length"} < 12) 0 0 0
Condition0%0/3
$self->{"next_code"} == 1 << $self->{"code_length"} and $self->{"code_length"} < 12
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"next_code"} == 1 << $self->{"code_length"} and $self->{"code_length"} < 12
$self->{"next_code"} == 1 << $self->{"code_length"} $self->{"code_length"} < 12
Truth table0%0/3
A and B
A= $self->{"next_code"} == 1 << $self->{"code_length"}B= $self->{"code_length"} < 12
ABresult
0X0
100
111
70 0 $self->{'code_length'}++;
71 }
72 }
73 }
74 0 $self->{'partial_code'} = $partial_code;
75 0 $self->{'partial_bits'} = $partial_bits;
76 0 return $result;
77 }
78  
79 sub read_dat {
80 0 ▶ my ($self, $data_ref, $partial_code, $partial_bits, $code_length) = @_;
Subroutine read_dat: not called CC=4 SCAR=30.0
Pod undocumented
81 0 ▶ $partial_bits = 0 unless defined $partial_bits;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $partial_bits 0 0 0
82  
83 0 ▶ while ($partial_bits < $code_length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($partial_bits < $code_length) 0 0 0
84 0 ▶ return (undef, $partial_code, $partial_bits) unless length($$data_ref);
Branch: 1 branch
BranchTrueFalseTotal
unless length $$data_ref 0 0 0
85 0 $partial_code = ($partial_code << 8) + unpack('C', $$data_ref);
86 0 substr($$data_ref, 0, 1) = '';
87 0 $partial_bits += 8;
88 }
89  
90 0 my $code = $partial_code >> ($partial_bits - $code_length);
91 0 $partial_code &= (1 << ($partial_bits - $code_length)) - 1;
92 0 $partial_bits -= $code_length;
93  
94 0 return ($code, $partial_code, $partial_bits);
95 }
96  
97 43 1;
« API2/Resource/CIDFont/TrueType.pm ↑ Summary API2/Annotation.pm »