blib/lib/ICC/Profile/ZXML.pm

filter: Statementstmt 31.8% 22 / 69 Branchbran 4.1% 1 / 24 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 6 / 14 Podpod 14.2% 1 / 7 totaltotal 25.2% 30 / 119 CC 14 SCAR 28.2
CC
14
Cov
24%
text
42.0
sdump
30.0
new_fh
6.0
CRAP 16.8
« blib/lib/ICC/Support/nPINT.pm ↑ Summary blib/lib/ICC/Profile/view.pm »
1 package ICC::Profile::ZXML;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 0.22;
7  
8 # revised 2018-08-07
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 2 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 2 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # support modules
19 2 ▶use Compress::Raw::Zlib; # interface to zlib
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # create new ZXML tag object
22 # parameters: ([text_string])
23 # returns: (ref_to_object)
24 sub new {
25  
26 # get object class
27 1 ▶ my $class = shift();
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
28  
29 # create empty ZXML object
30 1 my $self = [
31 {}, # object header
32 '' # zip compressed string
33 ];
34  
35 # if parameter supplied
36 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
37
38 # save it
39 0 $self->[1] = shift();
40
41 }
42  
43 # bless object
44 1 bless($self, $class);
45  
46 # return object reference
47 1 return($self);
48  
49 }
50  
51 # create ZXML tag object from ICC profile
52 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
53 # returns: (ref_to_object)
54 sub new_fh {
55  
56 # get object class
57 0 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
58  
59 # create empty ZXML object
60 0 my $self = [
61 {}, # object header
62 '' # zip compressed string
63 ];
64  
65 # verify 3 parameters
66 0 ▶ (@_ == 3) or croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
67  
68 # read ZXML data from profile
69 0 _readICCZXML($self, @_);
70  
71 # bless object
72 0 bless($self, $class);
73  
74 # return object reference
75 0 return($self);
76  
77 }
78  
79 # writes ZXML tag object to ICC profile
80 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
81 sub write_fh {
82  
83 # verify 4 parameters
84 0 ▶ (@_ == 4) or croak('wrong number of parameters');
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("wrong number of parameters") 0 0 0
85  
86 # write ZXML data to profile
87 0 goto &_writeICCZXML;
88  
89 }
90  
91 # get tag size (for writing to profile)
92 # note: deflates the CxF file and saves result
93 # returns: (tag_size)
94 sub size {
95  
96 # get parameters
97 0 ▶ my ($self) = @_;
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
98  
99 # return size
100 0 return(12 + length($self->[1]));
101  
102 }
103  
104 # get/set zipped data string
105 # parameters: ([data])
106 # returns: (data)
107 sub data {
108  
109 # get object reference
110 0 ▶ my $self = shift();
Subroutine data: not called CC=2 SCAR=17.9
Pod undocumented
111  
112 # if parameter supplied
113 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
114
115 # save it
116 0 $self->[1] = shift();
117
118 }
119  
120 # return text string
121 0 return($self->[1]);
122  
123 }
124  
125 # get/set CxF text string
126 # inflates/deflates zipped data string
127 # parameters: ([text_string])
128 # returns: (text_string)
129 sub text {
130  
131 # get object reference
132 0 ▶ my $self = shift();
Subroutine text: not called CC=6 SCAR=37.4
Pod undocumented
133  
134 # local variables
135 0 my ($cxf, $d, $i, $status);
136  
137 # if parameter supplied
138 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
139
140 # get parameter
141 0 $cxf = shift();
142
143 # make deflation object
144 0 ($d, $status) = Compress::Raw::Zlib::Deflate->new('-AppendOutput' => 1);
145
146 # check status
147 0 ▶ ($status == Z_OK) or croak("zlib error $status creating deflation object");
Branch: 1 branch
BranchTrueFalseTotal
$status == Z_OK() or croak("zlib error $status creating deflation object") 0 0 0
148
149 # deflate the text string (adding 4 nulls)
150 0 $status = $d->deflate(pack('a* x4', $cxf), $self->[1]);
151
152 # check status
153 0 ▶ ($status == Z_OK) or croak("zlib error $status deflating text string");
Branch: 1 branch
BranchTrueFalseTotal
$status == Z_OK() or croak("zlib error $status deflating text string") 0 0 0
154
155 # finish decompression
156 0 $status = $d->flush($self->[1]);
157
158 } else {
159
160 # make inflation object
161 0 ($i, $status) = Compress::Raw::Zlib::Inflate->new();
162
163 # check status
164 0 ▶ ($status == Z_OK) or croak("zlib error $status creating inflation object");
Branch: 1 branch
BranchTrueFalseTotal
$status == Z_OK() or croak("zlib error $status creating inflation object") 0 0 0
165
166 # inflate entire zip string
167 0 $status = $i->inflate($self->[1], $cxf);
168
169 # check status
170 0 ▶ ($status == Z_STREAM_END) or croak("zlib error $status inflating text string");
Branch: 1 branch
BranchTrueFalseTotal
$status == Z_STREAM_END() or croak("zlib error $status inflating text string") 0 0 0
171
172 # trim nulls from end of string
173 0 $cxf = unpack('Z*', $cxf);
174
175 }
176  
177 # return text string
178 0 return($cxf);
179  
180 }
181  
182 # print object contents to string
183 # format is an array structure
184 # parameter: ([format])
185 # returns: (string)
186 sub sdump {
187  
188 # get parameters
189 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
190  
191 # local variables
192 0 my ($s, $fmt);
193  
194 # resolve parameter to an array reference
195 0 ▶ $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : [];
Branch: 2 branches
BranchTrueFalseTotal
defined $p ? : 0 0 0
ref $p eq 'ARRAY' ? : 0 0 0
196  
197 # get format string
198 0 ▶ $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $p->[0] && !ref($p->[0]) ? : 0 0 0
Condition0%0/3
defined $p->[0] and not ref $p->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p->[0] and not ref $p->[0]
defined $p->[0] not ref $p->[0]
Truth table0%0/3
A and not(B)
A= defined $p->[0]B= not ref $p->[0]
ABresult
0X0
100
111
199  
200 # set string to object ID
201 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
202  
203 # return
204 0 return($s);
205  
206 }
207  
208 # read ZXML tag from ICC profile
209 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
210 sub _readICCZXML {
211  
212 # get parameters
213 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCZXML: not called CC=1 SCAR=6.9
214  
215 # local variables
216 0 my ($buf, $a, $b);
217  
218 # save tag signature
219 0 $self->[0]{'signature'} = $tag->[0];
220  
221 # seek start of tag
222 0 seek($fh, $tag->[1], 0);
223  
224 # read tag
225 0 read($fh, $buf, $tag->[2]);
226
227 # unpack zip string
228 0 ($a, $b, $self->[1]) = unpack('x4 N2 a*', $buf);
229  
230 # save prefix values
231 0 $self->[0]{'prefix'} = [$a, $b];
232  
233 }
234  
235 # write ZXML tag to ICC profile
236 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
237 sub _writeICCZXML {
238  
239 # get parameters
240 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCZXML: not called CC=1 SCAR=6.9
241  
242 # seek start of tag
243 0 seek($fh, $tag->[1], 0);
244  
245 # write tag
246 0 print $fh pack('a4 N2 a*', 'ZXML', @{$self->[0]{'prefix'}}, $self->[1]);
247  
248 }
249  
250 2 1;
« blib/lib/ICC/Support/nPINT.pm ↑ Summary blib/lib/ICC/Profile/view.pm »