blib/lib/ICC/Profile.pm

filter: Statementstmt 28.8% 177 / 614 Branchbran 1.8% 5 / 266 Conditioncond 1.3% 1 / 75 MC/DCmcdc 0.0% 0 / 45 Subroutinesub 74.3% 55 / 74 Podpod 87.5% 7 / 8 totaltotal 22.6% 245 / 1082 CC 177 SCAR 60.5
CC
177
Cov
19%
_newICCprofile
1332.0
_readICCprofile
992.0
sdump
420.0
CRAP 424.5
« lib/ICC/Support/Color.pm ↑ Summary lib/ICC/Support/bern.pm »
1 package ICC::Profile;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = 0.7;
7  
8 # revised 2018-09-09
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # global variables
13 1 our (@EXPORT, @EXPORT_OK, %EXPORT_TAGS);
14  
15 # inherit from Exporter and ICC::Shared
16 1 ▶use parent qw(Exporter ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # load library modules
19 BEGIN {
20  
21 # local variables
22 1 ▶ my (@modules, @opt, @export);
Subroutine BEGIN: called CC=4 SCAR=13.9
23  
24 # module list
25 1 @modules = qw(
26 Data::Dumper
27 Digest::MD5
28 ICC::Profile::clro
29 ICC::Profile::clrt
30 ICC::Profile::clut
31 ICC::Profile::curf
32 ICC::Profile::curv
33 ICC::Profile::cvst
34 ICC::Profile::data
35 ICC::Profile::desc
36 ICC::Profile::gbd_
37 ICC::Profile::Generic
38 ICC::Profile::mAB_
39 ICC::Profile::mBA_
40 ICC::Profile::matf
41 ICC::Profile::mft1
42 ICC::Profile::mft2
43 ICC::Profile::mluc
44 ICC::Profile::mpet
45 ICC::Profile::ncl2
46 ICC::Profile::para
47 ICC::Profile::parf
48 ICC::Profile::pseq
49 ICC::Profile::samf
50 ICC::Profile::sf32
51 ICC::Profile::sig_
52 ICC::Profile::text
53 ICC::Profile::vcgt
54 ICC::Profile::view
55 ICC::Profile::XYZ_
56 ICC::Profile::ZXML
57 ICC::Shared
58 ICC::Support::bern
59 ICC::Support::Chart
60 ICC::Support::Color
61 ICC::Support::geo1
62 ICC::Support::geo2
63 ICC::Support::nMIX
64 ICC::Support::nNET
65 ICC::Support::nNET2
66 ICC::Support::nPINT
67 ICC::Support::PCS
68 ICC::Support::ratfunc
69 ICC::Support::rbf
70 ICC::Support::spline
71 );
72  
73 # optional modules
74 1 @opt = qw (
75 ICC::Support::Image
76 ICC::Support::Lapack
77 ICC::Support::Levmar
78 );
79  
80 # disable strict refs (to access exported lists)
81 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 # for each module
84 1 for my $mod (@modules, @opt) {
85
86 # load module
87 48 ▶ eval "use $mod";
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
88
89 # if error
90 48 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 3 45 48
91
92 # if an optional module
93 3 ▶ if (grep {$mod eq $_} @opt) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$mod eq $_;} @opt) { } 3 0 3
94
95 # warn
96 3 print("failed to load optional module $mod\n");
97
98 } else {
99
100 # error
101 0 die("error loading module $mod");
102
103 }
104
105 }
106
107 # get exported list
108 48 @export = @{$mod . '::EXPORT'};
109
110 # add to export list
111 48 push(@EXPORT, @export);
112
113 # match module key
114 48 $mod =~ m/:?(\w+)$/;
115
116 # add to group hash
117 48 $EXPORT_TAGS{lc($1)} = [@export];
118
119 }
120  
121 # restore strict refs
122 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
123  
124 # copy EXPORT list to EXPORT_OK
125 1 @EXPORT_OK = @EXPORT;
126  
127 # add 'all' to group hash
128 1 $EXPORT_TAGS{'all'} = \@EXPORT;
129  
130 }
131  
132 # create new profile object
133 # parameters: ()
134 # parameters: (ref_to_parameter_hash)
135 # parameters: (path_to_profile, [default_profile_path])
136 # parameters: (path_to_TIFF, [default_profile_path])
137 # parameters: (path_to_PSD, [default_profile_path])
138 # supported hash keys: 'version', 'class', 'subclass', 'data', 'PCS', 'render'
139 # returns: (ref_to_profile_object)
140 sub new {
141  
142 # get object class
143 1 ▶ my $class = shift();
Subroutine new: called CC=5 SCAR=20.9
Pod documented
144  
145 # create empty profile object
146 1 my $self = [
147 {}, # object header
148 [], # profile header
149 [] # tag table
150 ];
151  
152 # if one parameter, a hash reference
153 1 ▶ if (@_ == 1 && ref($_[0]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 1 1
elsif (@_) { } 0 1 1
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
154
155 # create new profile from parameter hash
156 0 _newICCprofile($self, @_);
157
158 # if any parameters
159 } elsif (@_) {
160
161 # read data from existing profile
162 0 ▶ _readICCprofile($self, @_) or carp("couldn't read profile: $_[0]\n");
Branch: 1 branch
BranchTrueFalseTotal
_readICCprofile($self, @_) or carp("couldn't read profile: $_[0]\n") 0 0 0
163
164 }
165  
166 # bless object
167 1 bless($self, $class);
168  
169 # return object reference
170 1 return($self);
171  
172 }
173  
174 # get/set reference to header hash
175 # parameters: ([ref_to_new_hash])
176 # returns: (ref_to_hash)
177 sub header {
178  
179 # get object reference
180 0 ▶ my $self = shift();
Subroutine header: not called CC=4 SCAR=30.0
Pod documented
181  
182 # if there are parameters
183 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
184
185 # if one parameter, a hash reference
186 0 ▶ if (@_ == 1 && ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
187
188 # set header to new hash
189 0 $self->[0] = {%{shift()}};
190
191 } else {
192
193 # error
194 0 croak('parameter must be a hash reference');
195
196 }
197
198 }
199  
200 # return reference
201 0 return($self->[0]);
202  
203 }
204  
205 # get/set profile header
206 # parameters: ([ref_to_new_array])
207 # returns: (ref_to_array)
208 sub profile_header {
209  
210 # get object reference
211 0 ▶ my $self = shift();
Subroutine profile_header: not called CC=5 SCAR=34.0
Pod documented
212  
213 # if there are parameters
214 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
215
216 # if one parameter, an array reference
217 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY' && @{$_[0]} == grep {! ref()} @{$_[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY' and @{$_[0];} == grep({not ref $_;} @{$_[0];})) { } 0 0 0
Condition0%0/6
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({not ref $_;} @{$_[0];})
!ll&&!rl&&r
000
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({not ref $_;} @{$_[0];})
@_ == 1 ref $_[0] eq "ARRAY" @{$_[0];} == grep({not ref $_;} @{$_[0];})
Truth table0%0/4
A and B and C
A= @_ == 1B= ref $_[0] eq "ARRAY"C= @{$_[0];} == grep({not ref $_;} @{$_[0];})
ABCresult
0XX0
10X0
1100
1111
218
219 # set header to copy of array
220 0 $self->[1] = [@{shift()}];
221
222 } else {
223
224 # error
225 0 croak('profile header must be an array reference');
226
227 }
228
229 }
230  
231 # return reference
232 0 return($self->[1]);
233  
234 }
235  
236 # get/set profile tag table
237 # parameters: ([ref_to_new_array])
238 # returns: (ref_to_array)
239 sub tag_table {
240  
241 # get object reference
242 0 ▶ my $self = shift();
Subroutine tag_table: not called CC=5 SCAR=34.0
Pod documented
243  
244 # if there are parameters
245 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
246
247 # if one parameter, a 2-D array reference
248 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY' && @{$_[0]} == grep {ref() eq 'ARRAY'} @{$_[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY' and @{$_[0];} == grep({ref $_ eq 'ARRAY';} @{$_[0];})) { } 0 0 0
Condition0%0/6
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
!ll&&!rl&&r
000
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
@_ == 1 ref $_[0] eq "ARRAY" @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
Truth table0%0/4
A and B and C
A= @_ == 1B= ref $_[0] eq "ARRAY"C= @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
ABCresult
0XX0
10X0
1100
1111
249
250 # set tag table to copy of array
251 0 $self->[2] = Storable::dclone(shift());
252
253 } else {
254
255 # error
256 0 croak('profile tag table must be a 2-D array reference');
257
258 }
259
260 }
261  
262 # return reference
263 0 return($self->[2]);
264  
265 }
266  
267 # get/set tag objects
268 # get tag object(s) returns 'undef' if tag signature not found
269 # parameters: (list_of_tag_signatures)
270 # returns: (list_of_tag_objects)
271 # set tag object(s) replaces, adds or deletes tags
272 # hash keys are tag signatures, hash values are object refs
273 # a hash value of 'delete' will delete the tag
274 # parameters: (ref_to_parameter_hash)
275 # returns: (list_of_tag_objects)
276 sub tag {
277  
278 # get object reference
279 0 ▶ my $self = shift();
Subroutine tag: not called CC=18 SCAR=58.3
Pod documented
280  
281 # local variables
282 0 my ($hash, $value, @match, @tags, $rem);
283  
284 # if parameter hash supplied
285 0 ▶ if (@_ == 1 && ref($_[0]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
elsif (@_) { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
286
287 # get hash
288 0 $hash = shift();
289
290 # for each key
291 0 for my $key (keys(%{$hash})) {
292
293 # get value
294 0 $value = $hash->{$key};
295
296 # verify tag signature
297 0 ▶ (length($key) == 4) or croak('tag signature wrong length');
Branch: 1 branch
BranchTrueFalseTotal
length $key == 4 or croak("tag signature wrong length") 0 0 0
298
299 # match tag signature
300 0 @match = grep {$key eq $self->[2][$_][0]} (0 .. $#{$self->[2]});
301
302 # if tag value undefined or an ICC::Profile or ICC::Support object
303 0 ▶ if (! defined($value) || ref($value) =~ m/^ICC::(Profile|Support)::/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $value or ref($value) =~ /^ICC::(Profile|Support)::/) { } 0 0 0
elsif ($value eq 'delete') { } 0 0 0
Condition0%0/3
not defined $value or ref($value) =~ /^ICC::(Profile|Support)::/
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $value or ref($value) =~ /^ICC::(Profile|Support)::/
not defined $value ref($value) =~ /^ICC::(Profile|Support)::/
Truth table0%0/3
not(A) or B
A= not defined $valueB= ref($value) =~ /^ICC::(Profile|Support)::/
ABresult
1X1
011
000
304
305 # if no matches
306 0 ▶ if (@match == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@match == 0) { } 0 0 0
elsif (@match == 1) { } 0 0 0
307
308 # add new tag
309 0 push(@{$self->[2]}, [$key, 0, 0, $value]);
310
311 # if one match
312 } elsif (@match == 1) {
313
314 # modify matched tag
315 0 $self->[2][$match[0]] = [$key, 0, 0, $value];
316
317 # more than one match
318 } else {
319
320 # modify first matched tag
321 0 $self->[2][$match[0]] = [$key, 0, 0, $value];
322
323 # print warning
324 0 carp "tag table contains multiple tags with '$key' signature\n";
325
326 }
327
328 # add tag to list
329 0 push(@tags, $value);
330
331 # if tag value is 'delete'
332 } elsif ($value eq 'delete') {
333
334 # if no matches
335 0 ▶ if (@match == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@match == 0) { } 0 0 0
336
337 # print warning
338 0 carp "tag table contains no '$key' tag(s) to delete\n";
339
340 # one or more matches
341 } else {
342
343 # for each tag
344 0 for my $i (@match) {
345
346 # delete tag
347 0 $rem = splice(@{$self->[2]}, $i, 1);
348
349 # add tag to list
350 0 ▶ push(@tags, defined($rem) ? $rem->[3] : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $rem ? : 0 0 0
351
352 }
353
354 }
355
356 } else {
357
358 # error
359 0 croak("invalid '$key' tag value");
360
361 }
362
363 }
364
365 # if list of tag signatures
366 } elsif (@_) {
367
368 # for each signature
369 0 for my $key (@_) {
370
371 # match tag signature
372 0 @match = grep {$key eq $_->[0]} @{$self->[2]};
373
374 # if no matches
375 0 ▶ if (@match == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@match == 0) { } 0 0 0
elsif (@match == 1) { } 0 0 0
376
377 # add 'undef' to tag list
378 0 push(@tags, undef);
379
380 # if one match
381 } elsif (@match == 1) {
382
383 # add matched tag to tag list
384 0 push(@tags, $match[0][3]);
385
386 # more than one match
387 } else {
388
389 # add first matched tag to tag list
390 0 push(@tags, $match[0][3]);
391
392 # print warning
393 0 carp "tag table contains multiple tags with '$key' signature\n";
394
395 }
396
397 }
398
399 }
400
401 # if list is expected
402 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
403
404 # return tag list
405 0 return(@tags);
406
407 } else {
408
409 # return first tag
410 0 return($tags[0]);
411
412 }
413
414 }
415  
416 # write ICC profile
417 # parameters: (path_to_profile)
418 # parameters: (scalar_reference)
419 sub write {
420  
421 # get object reference
422 0 ▶ my $self = shift();
Subroutine write: not called CC=2 SCAR=17.9
Pod documented
423  
424 # verify parameter count
425 0 ▶ (@_ == 1) or croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or croak("wrong number of parameters") 0 0 0
426  
427 # write profile
428 0 _writeICCprofile($self, @_);
429  
430 # return
431 0 return();
432  
433 }
434  
435 # write ICC profile to scalar
436 # returns: (scalar_reference)
437 sub serialize {
438  
439 # get object reference
440 0 ▶ my $self = shift();
Subroutine serialize: not called CC=1 SCAR=6.9
Pod undocumented
441  
442 # local variable
443 0 my $buf;
444  
445 # write profile
446 0 _writeICCprofile($self, \$buf);
447  
448 # return
449 0 return(\$buf);
450  
451 }
452  
453 # print object contents to string
454 # optional format may contain the characters 'p', 't' and 's'
455 # when the format contains 'p' the profile header will be dumped
456 # when the format contains 't' the profile tag table will be dumped
457 # when the format contains 's' the profile structure will be dumped
458 # when the format is omitted, a default value of 'pts' is used
459 # parameter: ([format])
460 # returns: (string)
461 sub sdump {
462  
463 # get parameters
464 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=20 SCAR=60.4
Pod documented
465  
466 # local variables
467 0 my ($header, $entry, $tag, $fmt, $s, $pt, $st);
468  
469 # resolve parameter to an array reference
470 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
471  
472 # get format string
473 0 ▶ $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'pts';
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
474  
475 # set string to object ID
476 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
477  
478 # if format contains 'p'
479 0 ▶ if ($fmt =~ m/p/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /p/) 0 0 0
480
481 # if profile header contains data
482 0 ▶ if (@{$self->[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[1];}) { } 0 0 0
483
484 # get profile header array
485 0 $header = $self->[1];
486
487 # add header info
488 0 $s .= sprintf("%24s: %d bytes\n", 'Size', $header->[0]);
489 0 $s .= sprintf("%24s: %4s\n", 'Preferred CMM', $header->[1]);
490 0 $s .= sprintf("%24s: %d.%d.%d\n", 'Specification Version', substr($header->[2], 0, 2), substr($header->[2], 2, 1), substr($header->[2], 3, 1));
491 0 $s .= sprintf("%24s: %4s\n", 'Class', $header->[3]);
492 0 $s .= sprintf("%24s: %4s\n", 'Data', $header->[4]);
493 0 $s .= sprintf("%24s: %4s\n", 'PCS', $header->[5]);
494 0 $s .= sprintf("%24s: %04d-%02d-%02d %02d:%02d:%02d\n", 'Created', @{$header}[6 .. 11]);
495 0 $s .= sprintf("%24s: %4s\n", 'Platform', $header->[13]);
496 0 $s .= sprintf("%24s: <0x%08x>\n", 'Flags', $header->[14]);
497 0 $s .= sprintf("%24s: %4s\n", 'Device Manufacturer', $header->[15]);
498 0 $s .= sprintf("%24s: %4s\n", 'Device Model', $header->[16]);
499 0 $s .= sprintf("%24s: <0x%08x> <0x%08x>\n", 'Device Attributes', @{$header}[17 .. 18]);
500 0 $s .= sprintf("%24s: %d\n", 'Rendering Intent', $header->[19]);
501 0 $s .= sprintf("%24s: %7.5f, %7.5f, %7.5f\n", 'PCS Illuminant', map {$_/65536} @{$header}[20 .. 22]);
502 0 $s .= sprintf("%24s: %4s\n", 'Creator', $header->[23]);
503
504 # if no MD5 signature
505 0 ▶ if ($header->[24] eq '00' x 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header->[24] eq '00000000000000000000000000000000') { } 0 0 0
506
507 # print no MD5 signature
508 0 $s .= sprintf("%24s:\n\n", 'MD5 Signature');
509
510 } else {
511
512 # print MD5 signature in 8 byte segments
513 0 $s .= sprintf("%24s: %8s %8s %8s %8s\n\n", 'MD5 Signature', substr($header->[24], 0, 8), substr($header->[24], 8, 8), substr($header->[24], 16, 8), substr($header->[24], 24, 8));
514
515 }
516
517 } else {
518
519 # add message
520 0 $s .= "<header empty>\n";
521
522 }
523
524 }
525  
526 # if format contains 't'
527 0 ▶ if ($fmt =~ m/t/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /t/) 0 0 0
528
529 # if tag table contains data
530 0 ▶ if (@{$self->[2]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[2];}) { } 0 0 0
531
532 # print tag table header
533 0 $s .= " # Tag Object Type Offset Size\n";
534
535 # for each tag table entry
536 0 for my $i (0 .. $#{$self->[2]}) {
537
538 # get tag table entry
539 0 $entry = $self->[2][$i];
540
541 # print tag table entry
542 0 ▶ $s .= sprintf("%4d '%4s' %-24s %8d %8d\n", $i + 1, $entry->[0], ref($entry->[3]) || ' undefined', $entry->[1] || 0, $entry->[2] || 0);
Condition0%0/6
ref $entry->[3] || ' undefined'
l!l
00
$entry->[1] || 0
l!l
00
$entry->[2] || 0
l!l
00
MC/DC0%0/1
ref $entry->[3] || ' undefined'
ref $entry->[3]
MC/DC0%0/1
$entry->[1] || 0
$entry->[1]
MC/DC0%0/1
$entry->[2] || 0
$entry->[2]
Truth table0%0/2
A
A= ref $entry->[3]
Aresult
11
00
Truth table0%0/2
A
A= $entry->[1]
Aresult
11
00
Truth table0%0/2
A
A= $entry->[2]
Aresult
11
00
543
544 }
545
546 # add line ending
547 0 $s .= "\n";
548
549 } else {
550
551 # add message
552 0 $s .= "<tag table empty>\n";
553
554 }
555
556 }
557  
558 # if format contains 's'
559 0 ▶ if ($fmt =~ m/s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /s/) 0 0 0
560
561 # get default parameter
562 0 $pt = $p->[-1];
563
564 # for each tag
565 0 for my $i (0 .. $#{$self->[2]}) {
566
567 # get tag reference
568 0 $tag = $self->[2][$i][3];
569
570 # if tag is undefined
571 0 ▶ if (! defined($tag)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $tag) { } 0 0 0
elsif (not builtin::blessed($tag)) { } 0 0 0
elsif ($tag->can('sdump')) { } 0 0 0
572
573 # append message
574 0 $s .= "\ttag is undefined\n";
575
576 # if tag is not a blessed object
577 } elsif (! Scalar::Util::blessed($tag)) {
578
579 # append message
580 0 $s .= "\ttag is not a blessed object\n";
581
582 # if tag has an 'sdump' method
583 } elsif ($tag->can('sdump')) {
584
585 # get 'sdump' string
586 0 ▶ $st = $tag->sdump(defined($p->[$i + 1]) ? $p->[$i + 1] : $pt);
Branch: 1 branch
BranchTrueFalseTotal
defined $$p[$i + 1] ? : 0 0 0
587
588 # prepend tabs to each line
589 0 $st =~ s/^/\t/mg;
590
591 # append 'sdump' string
592 0 $s .= $st;
593
594 # tag is object without an 'sdump' method
595 } else {
596
597 # append object info
598 0 $s .= sprintf("\t'%s' object, (0x%x)\n", ref($tag), $tag);
599
600 }
601
602 }
603
604 }
605  
606 # return
607 0 return($s);
608  
609 }
610  
611 # create new profile object
612 # parameters: (ref_to_object, parameter_hash)
613 sub _newICCprofile {
614  
615 # get parameters
616 0 ▶ my ($self, $hash) = @_;
Subroutine _newICCprofile: not called CC=36 SCAR=71.9
617  
618 # local variables
619 0 my ($version, $class, $subclass, $dcs, $pcs, $dri) = @{$hash}{qw(version class subclass data PCS render)};
620 0 my ($redcs, $repcs, $vmaj, $vmin);
621  
622 # regular expression to match data color space (table 19, ICC1v43_2010-12)
623 0 $redcs = qr/^(XYZ |Lab |Luv |YCbr|Yxy |RGB |GRAY|HSV |HLS |CMYK|CMY |[2-9A-F]CLR)$/;
624  
625 # regular expression to match profile connection space (section 7.2.7, ICC1v43_2010-12)
626 0 $repcs = qr/^(XYZ |Lab )$/;
627  
628 # resolve version number (optional, default version 2.4)
629 0 ▶ $version = defined($version) ? $version : '02400000';
Branch: 1 branch
BranchTrueFalseTotal
defined $version ? : 0 0 0
630  
631 # verify version number (section 7.2.4, ICC1v43_2010-12)
632 0 ▶ ($version =~ m/^[0-9]{4}0000$/) or croak('invalid version number');
Branch: 1 branch
BranchTrueFalseTotal
$version =~ /^[0-9]{4}0000$/ or croak("invalid version number") 0 0 0
633  
634 # get major revision
635 0 $vmaj = substr($version, 0, 2);
636  
637 # get minor revision
638 0 $vmin = substr($version, 2, 1);
639  
640 # verify profile class (required) (table 18, ICC1v43_2010-12)
641 0 ▶ (defined($class)) or croak('missing profile class parameter');
Branch: 1 branch
BranchTrueFalseTotal
defined $class or croak("missing profile class parameter") 0 0 0
642 0 ▶ ($class =~ m/^(scnr|mntr|prtr|link|spac|abst|nmcl)$/) or croak('invalid profile class');
Branch: 1 branch
BranchTrueFalseTotal
$class =~ /^(scnr|mntr|prtr|link|spac|abst|nmcl)$/ or croak("invalid profile class") 0 0 0
643  
644 # resolve subclass (optional, default 0)
645 0 ▶ $subclass = defined($subclass) ? $subclass : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $subclass ? : 0 0 0
646  
647 # verify data color space (required)
648 0 ▶ (defined($dcs)) or croak('missing data color space parameter');
Branch: 1 branch
BranchTrueFalseTotal
defined $dcs or croak("missing data color space parameter") 0 0 0
649 0 ▶ (($dcs =~ $repcs) || ($class ne 'abst' && $dcs =~ $redcs)) or croak('invalid data color space');
Branch: 1 branch
BranchTrueFalseTotal
$dcs =~ /$repcs/ or $class ne "abst" and $dcs =~ /$redcs/ or croak("invalid data color space") 0 0 0
Condition0%0/6
$dcs =~ /$repcs/ or $class ne "abst" and $dcs =~ /$redcs/
l!l&&r!l&&!r
000
$class ne "abst" and $dcs =~ /$redcs/
!ll&&!rl&&r
000
MC/DC0%0/3
$dcs =~ /$repcs/ or $class ne "abst" and $dcs =~ /$redcs/
$dcs =~ /$repcs/ $class ne "abst" $dcs =~ /$redcs/
Truth table0%0/4
A or B and C
A= $dcs =~ /$repcs/B= $class ne "abst"C= $dcs =~ /$redcs/
ABCresult
1XX1
0111
00X0
0100
650  
651 # verify profile connection space (required)
652 0 ▶ $pcs = $hash->{'PCS'} or croak('missing profile connection space parameter');
Branch: 1 branch
BranchTrueFalseTotal
$pcs = $hash->{"PCS"} or croak("missing profile connection space parameter") 0 0 0
653 0 ▶ (($pcs =~ $repcs) || ($class eq 'link' && $pcs =~ $redcs)) or croak('invalid profile connection space');
Branch: 1 branch
BranchTrueFalseTotal
$pcs =~ /$repcs/ or $class eq "link" and $pcs =~ /$redcs/ or croak("invalid profile connection space") 0 0 0
Condition0%0/6
$pcs =~ /$repcs/ or $class eq "link" and $pcs =~ /$redcs/
l!l&&r!l&&!r
000
$class eq "link" and $pcs =~ /$redcs/
!ll&&!rl&&r
000
MC/DC0%0/3
$pcs =~ /$repcs/ or $class eq "link" and $pcs =~ /$redcs/
$pcs =~ /$repcs/ $class eq "link" $pcs =~ /$redcs/
Truth table0%0/4
A or B and C
A= $pcs =~ /$repcs/B= $class eq "link"C= $pcs =~ /$redcs/
ABCresult
1XX1
0111
00X0
0100
654  
655 # resolve default rendering intent (optional, default 0)
656 0 ▶ $dri = defined($dri) ? $dri : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $dri ? : 0 0 0
657  
658 # verify default rendering intent (table 23, ICC1v43_2010-12)
659 0 ▶ ($dri =~ m/^[0-3]$/) or croak('invalid default rendering intent');
Branch: 1 branch
BranchTrueFalseTotal
$dri =~ /^[0-3]$/ or croak("invalid default rendering intent") 0 0 0
660  
661 # set header (note: size, time and ID are computed when writing profile)
662 0 $self->[1] = [
663 0, # profile size
664 "\x00" x 4, # preferred CMM type signature
665 $version, # profile version number
666 $class, # profile/device class signature
667 $dcs, # data color space
668 $pcs, # profile connection space
669 0, # year
670 0, # month
671 0, # day
672 0, # hour
673 0, # minute
674 0, # second
675 'acsp', # profile file signature
676 'APPL', # primary platform signature
677 0, # flags
678 "\x00" x 4, # device manufacturer
679 "\x00" x 4, # device model
680 0, # attributes
681 0, # attributes (reserved for ICC)
682 $dri, # default rendering intent
683 0x00F6D6, # illuminant X (D50)
684 0x010000, # illuminant Y (D50)
685 0x00D32D, # illuminant Z (D50)
686 'DPLG', # profile creator signature (Doppelganger)
687 '00' x 16 # profile ID (MD5)
688 ];
689  
690 # if an input device profile
691 0 ▶ if ($class eq 'scnr') {
Branch: 6 branches
BranchTrueFalseTotal
if ($class eq 'scnr') { } 0 0 0
elsif ($class eq 'mntr') { } 0 0 0
elsif ($class eq 'prtr') { } 0 0 0
elsif ($class eq 'link') { } 0 0 0
elsif ($class eq 'spac') { } 0 0 0
elsif ($class eq 'abst') { } 0 0 0
692
693 # set tag table
694 0 $self->[2] = [
695 ['desc'],
696 ['cprt'],
697 ['wtpt']
698 ];
699
700 # if subclass 0 (N-component LUT-based input profile)
701 0 ▶ if ($subclass == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($subclass == 0) { } 0 0 0
elsif ($subclass == 1) { } 0 0 0
elsif ($subclass == 2) { } 0 0 0
702
703 # add AToB0Tag
704 0 push(@{$self->[2]},
705 ['A2B0']
706 );
707
708 # if subclass 1 (Three-component matrix-based input profile)
709 } elsif ($subclass == 1) {
710
711 # add additional required tags
712 0 push(@{$self->[2]},
713 ['rXYZ'],
714 ['gXYZ'],
715 ['bXYZ'],
716 ['rTRC'],
717 ['gTRC'],
718 ['bTRC']
719 );
720
721 # if subclass 2 (Monochrome input profile)
722 } elsif ($subclass == 2) {
723
724 # add grayTRCTag
725 0 push(@{$self->[2]},
726 ['kTRC']
727 );
728
729 }
730
731 # if a display device profile
732 } elsif ($class eq 'mntr') {
733
734 # set tag table
735 0 $self->[2] = [
736 ['desc'],
737 ['cprt'],
738 ['wtpt']
739 ];
740
741 # if subclass 0 (N-Component LUT-based display profile)
742 0 ▶ if ($subclass == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($subclass == 0) { } 0 0 0
elsif ($subclass == 1) { } 0 0 0
elsif ($subclass == 2) { } 0 0 0
743
744 # add additional required tags
745 0 push(@{$self->[2]},
746 ['A2B0'],
747 ['B2A0']
748 );
749
750 # if subclass 1 (Three-component matrix-based display profile)
751 } elsif ($subclass == 1) {
752
753 # add additional required tags
754 0 push(@{$self->[2]},
755 ['rXYZ'],
756 ['gXYZ'],
757 ['bXYZ'],
758 ['rTRC'],
759 ['gTRC'],
760 ['bTRC']
761 );
762
763 # if subclass 2 (Monochrome display profile)
764 } elsif ($subclass == 2) {
765
766 # add grayTRCTag
767 0 push(@{$self->[2]},
768 ['kTRC']
769 );
770
771 }
772
773 # if a output device profile
774 } elsif ($class eq 'prtr') {
775
776 # set tag table
777 0 $self->[2] = [
778 ['desc'],
779 ['cprt'],
780 ['wtpt']
781 ];
782
783 # if subclass 0 (N-component LUT-based output profile)
784 0 ▶ if ($subclass == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($subclass == 0) { } 0 0 0
elsif ($subclass == 2) { } 0 0 0
785
786 # add additional required tags
787 0 push(@{$self->[2]},
788 ['A2B0'],
789 ['A2B1'],
790 ['A2B2'],
791 ['B2A0'],
792 ['B2A1'],
793 ['B2A2'],
794 ['gamt']
795 );
796
797 # if data color space is xCLR and version 4
798 0 ▶ if ($dcs =~ m|CLR$| && $vmaj == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dcs =~ /CLR$/ and $vmaj == 4) 0 0 0
Condition0%0/3
$dcs =~ /CLR$/ and $vmaj == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$dcs =~ /CLR$/ and $vmaj == 4
$dcs =~ /CLR$/ $vmaj == 4
Truth table0%0/3
A and B
A= $dcs =~ /CLR$/B= $vmaj == 4
ABresult
0X0
100
111
799
800 # add colorantTableTag
801 0 push(@{$self->[2]},
802 ['clrt']
803 );
804
805 }
806
807 # if subclass 2 (Monochrome output profile)
808 } elsif ($subclass == 2) {
809
810 # add grayTRCTag
811 0 push(@{$self->[2]},
812 ['kTRC']
813 );
814
815 }
816
817 # if a device link profile
818 } elsif ($class eq 'link') {
819
820 # set tag table
821 0 $self->[2] = [
822 ['desc'],
823 ['cprt'],
824 ['pseq'],
825 ['A2B0']
826 ];
827
828 # if data color space is xCLR and version 4
829 0 ▶ if ($dcs =~ m|CLR$| && $vmaj == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dcs =~ /CLR$/ and $vmaj == 4) 0 0 0
Condition0%0/3
$dcs =~ /CLR$/ and $vmaj == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$dcs =~ /CLR$/ and $vmaj == 4
$dcs =~ /CLR$/ $vmaj == 4
Truth table0%0/3
A and B
A= $dcs =~ /CLR$/B= $vmaj == 4
ABresult
0X0
100
111
830
831 # add colorantTableTag
832 0 push(@{$self->[2]},
833 ['clrt']
834 );
835
836 }
837
838 # if data color space is xCLR and version 4
839 0 ▶ if ($pcs =~ m|CLR$| && $vmaj == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pcs =~ /CLR$/ and $vmaj == 4) 0 0 0
Condition0%0/3
$pcs =~ /CLR$/ and $vmaj == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$pcs =~ /CLR$/ and $vmaj == 4
$pcs =~ /CLR$/ $vmaj == 4
Truth table0%0/3
A and B
A= $pcs =~ /CLR$/B= $vmaj == 4
ABresult
0X0
100
111
840
841 # add colorantTableOutTag
842 0 push(@{$self->[2]},
843 ['clot']
844 );
845
846 }
847
848 # if a color space conversion profile
849 } elsif ($class eq 'spac') {
850
851 # set tag table
852 0 $self->[2] = [
853 ['desc'],
854 ['cprt'],
855 ['wtpt'],
856 ['A2B0'],
857 ['B2A0']
858 ];
859
860 # if an abstract profile
861 } elsif ($class eq 'abst') {
862
863 # set tag table
864 0 $self->[2] = [
865 ['desc'],
866 ['cprt'],
867 ['wtpt'],
868 ['A2B0']
869 ];
870
871 # if a named color profile
872 } else {
873
874 # set tag table
875 0 $self->[2] = [
876 ['desc'],
877 ['cprt'],
878 ['wtpt'],
879 ['ncl2']
880 ];
881
882 }
883
884 }
885  
886 # read embedded profile from PSD file
887 # parameters: (file_handle)
888 # returns: (reference_to_buffer)
889 sub _readICCprofilePSD {
890  
891 # get file handle
892 0 ▶ my $fh = shift();
Subroutine _readICCprofilePSD: not called CC=6 SCAR=37.4
893  
894 # local variables
895 0 my ($buf, @header, @res, $end);
896  
897 # seek start of file
898 0 seek($fh, 0, 0);
899  
900 # read the header
901 0 ▶ (read($fh, $buf, 30) == 30) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
read($fh, $buf, 30) == 30 or return 0 0 0 0
902  
903 # unpack the header
904 0 @header = unpack('a4 n x6 n N N n n N', $buf);
905  
906 # verify PSD signature
907 0 ▶ if (($header[0] eq '8BPS') && ($header[1] == 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header[0] eq "8BPS" and $header[1] == 1) 0 0 0
Condition0%0/3
$header[0] eq "8BPS" and $header[1] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$header[0] eq "8BPS" and $header[1] == 1
$header[0] eq "8BPS" $header[1] == 1
Truth table0%0/3
A and B
A= $header[0] eq "8BPS"B= $header[1] == 1
ABresult
0X0
100
111
908
909 # skip to resource size
910 0 seek($fh, $header[7], 1);
911
912 # read resource size
913 0 read($fh, $buf, 4);
914
915 # compute resource block end
916 0 $end = tell($fh) + unpack('N', $buf);
917
918 # while file position < resource block end
919 0 ▶ while (tell($fh) < $end) {
Branch: 1 branch
BranchTrueFalseTotal
if (tell $fh < $end) 0 0 0
920
921 # read resource type, ID and name count
922 0 read($fh, $buf, 7);
923
924 # unpack resource type, ID and name count
925 0 @res = unpack('a4 n C', $buf);
926
927 # read the resource name (Pascal string)
928 0 read($fh, $buf, $res[2] + (1 - $res[2] % 2));
929
930 # save the resource name
931 0 $res[2] = substr($buf, 0, $res[2]);
932
933 # read the resource size
934 0 read($fh, $buf, 4);
935
936 # unpack resource size
937 0 $res[3] = unpack('N', $buf);
938
939 # if ICC profile resource
940 0 ▶ if ($res[1] == 1039) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res[1] == 1039) 0 0 0
941
942 # read profile
943 0 read($fh, $buf, $res[3]);
944
945 # return buffer reference
946 0 return(\$buf);
947
948 }
949
950 # skip to next resource
951 0 seek($fh, $res[3] + (- $res[3] % 2), 1);
952
953 }
954
955 }
956  
957 # return (no profile found)
958 0 return(0);
959  
960 }
961  
962 # read embedded profile from TIFF file
963 # parameters: (file_handle)
964 # returns: (reference_to_buffer)
965 sub _readICCprofileTIFF {
966  
967 # get file handle
968 0 ▶ my $fh = shift();
Subroutine _readICCprofileTIFF: not called CC=13 SCAR=52.0
969  
970 # local variables
971 0 my (@ts, $buf, $short, $long, @header);
972 0 my ($count, @tag, $size);
973  
974 # type size (in bytes)
975 0 @ts = (0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8);
976  
977 # seek start of file
978 0 seek($fh, 0, 0);
979  
980 # read the header
981 0 ▶ (read($fh, $buf, 8) == 8) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
read($fh, $buf, 8) == 8 or return 0 0 0 0
982  
983 # if big-endian (Motorola)
984 0 ▶ if ($buf =~ m|^MM|) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf =~ /^MM/) { } 0 0 0
985
986 # set unpack formats
987 0 $short = 'n';
988 0 $long = 'N';
989
990 # little-endian (Intel)
991 } else {
992
993 # set unpack formats
994 0 $short = 'v';
995 0 $long = 'V';
996
997 }
998  
999 # unpack the header
1000 0 @header = unpack("A2 $short $long", $buf);
1001  
1002 # verify TIFF file signature
1003 0 ▶ if ($header[1] == 42) {
Branch: 1 branch
BranchTrueFalseTotal
if ($header[1] == 42) 0 0 0
1004
1005 # seek first IFD (image file directory)
1006 0 seek($fh, $header[2], 0);
1007
1008 # read number entries
1009 0 read($fh, $buf, 2);
1010
1011 # unpack the directory count
1012 0 $count = unpack("$short", $buf);
1013
1014 # read the directory
1015 0 for (1 .. $count) {
1016
1017 # read first part of IFD entry
1018 0 read($fh, $buf, 8);
1019
1020 # unpack tag, type and count
1021 0 @tag = unpack("$short $short $long", $buf);
1022
1023 # read last part of IFD entry
1024 0 read($fh, $buf, 4);
1025
1026 # determine value/offset size
1027 0 ▶ $size = $ts[$tag[1]] * $tag[2] + (($tag[1] == 2) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$tag[1] == 2 ? : 0 0 0
1028
1029 # if value/offset size > 4 or a single long value
1030 0 ▶ if ($size > 4 || $ts[$tag[1]] == 4) {
Branch: 3 branches
BranchTrueFalseTotal
if ($size > 4 or $ts[$tag[1]] == 4) { } 0 0 0
elsif ($ts[$tag[1]] == 2 and $tag[2] == 1) { } 0 0 0
elsif ($ts[$tag[1]] == 2 and $tag[2] == 2) { } 0 0 0
Condition0%0/3
$size > 4 or $ts[$tag[1]] == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$size > 4 or $ts[$tag[1]] == 4
$size > 4 $ts[$tag[1]] == 4
Truth table0%0/3
A or B
A= $size > 4B= $ts[$tag[1]] == 4
ABresult
1X1
011
000
1031
1032 # unpack value/offset
1033 0 $tag[3] = unpack($long, $buf);
1034
1035 ▶ } elsif ($ts[$tag[1]] == 2 && $tag[2] == 1) {
Condition0%0/3
$ts[$tag[1]] == 2 and $tag[2] == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$ts[$tag[1]] == 2 and $tag[2] == 1
$ts[$tag[1]] == 2 $tag[2] == 1
Truth table0%0/3
A and B
A= $ts[$tag[1]] == 2B= $tag[2] == 1
ABresult
0X0
100
111
1036
1037 # unpack value
1038 0 $tag[3] = unpack($short, $buf);
1039
1040 ▶ } elsif ($ts[$tag[1]] == 2 && $tag[2] == 2) {
Condition0%0/3
$ts[$tag[1]] == 2 and $tag[2] == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$ts[$tag[1]] == 2 and $tag[2] == 2
$ts[$tag[1]] == 2 $tag[2] == 2
Truth table0%0/3
A and B
A= $ts[$tag[1]] == 2B= $tag[2] == 2
ABresult
0X0
100
111
1041
1042 # unpack values
1043 0 $tag[3 .. 4] = unpack("$short $short", $buf);
1044
1045 }
1046
1047 # if ICC profile tag
1048 0 ▶ if ($tag[0] == 34675) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag[0] == 34675) 0 0 0
1049
1050 # seek start of profile
1051 0 seek($fh, $tag[3], 0);
1052  
1053 # read profile
1054 0 read($fh, $buf, $tag[2]);
1055  
1056 # close file
1057 0 close($fh);
1058  
1059 # return reference to buffer
1060 0 return(\$buf);
1061
1062 }
1063
1064 }
1065
1066 }
1067  
1068 # return
1069 0 return(0);
1070  
1071 }
1072  
1073 # read profile data from profile file
1074 # parameters: (ref_to_object, path_to_profile, [path_to_default_profile])
1075 # parameters: (ref_to_object, scalar_reference, [path_to_default_profile])
1076 # returns: (success_flag)
1077 sub _readICCprofile {
1078  
1079 # get parameters
1080 0 ▶ my ($self, $path, $default) = @_;
Subroutine _readICCprofile: not called CC=31 SCAR=69.0
1081  
1082 # local variables
1083 0 my ($fh, $buf, $ref);
1084 0 my (%hash, $type, $class);
1085 0 my ($wtpt, $bkpt, $A2B0, $A2B1);
1086  
1087 # if path a scalar reference
1088 0 ▶ if (ref($path) eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $path eq 'SCALAR') { } 0 0 0
elsif (not ref $path) { } 0 0 0
1089
1090 # open the profile file
1091 0 ▶ open($fh, '<', $path) or croak("unable to read profile from scalar");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $path or croak("unable to read profile from scalar") 0 0 0
1092
1093 # save file type in object header
1094 0 $self->[0]{'file_type'} = 'scalar';
1095
1096 # if path a scalar
1097 } elsif (! ref($path)) {
1098
1099 # replace '~~' with 'ICC' directory path
1100 0 $path =~ s/^~~(?{ICC::Shared::getICCPath})/$^R/;
1101
1102 # filter file path
1103 0 ICC::Shared::filterPath($path);
1104
1105 # open the profile file
1106 0 ▶ open($fh, '<', $path) or croak("unable to read profile from $path");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $path or croak("unable to read profile from $path") 0 0 0
1107
1108 # save path in object header
1109 0 $self->[0]{'file_path'} = $path;
1110  
1111 # save file type in object header
1112 0 $self->[0]{'file_type'} = 'prof';
1113  
1114 } else {
1115
1116 # error
1117 0 croak("invalid path parameter");
1118
1119 }
1120  
1121 # set binary mode
1122 0 binmode($fh);
1123  
1124 # seek to profile file signature
1125 0 seek($fh, 36, 0);
1126  
1127 # read profile file signature
1128 0 read($fh, $buf, 4);
1129  
1130 # if not an ICC profile
1131 0 ▶ if ($buf ne 'acsp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf ne "acsp") 0 0 0
1132
1133 # if TIFF with embedded profile
1134 0 ▶ if ($ref = _readICCprofileTIFF($fh)) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref = _readICCprofileTIFF($fh)) { } 0 0 0
elsif ($ref = _readICCprofilePSD($fh)) { } 0 0 0
elsif (defined $default) { } 0 0 0
1135
1136 # open the profile
1137 0 open($fh, '<', $ref);
1138
1139 # set binary mode
1140 0 binmode($fh);
1141
1142 # save file type in object header
1143 0 $self->[0]{'file_type'} = 'TIFF';
1144  
1145 # if PSD with embedded profile
1146 } elsif ($ref = _readICCprofilePSD($fh)) {
1147
1148 # open the profile
1149 0 open($fh, '<', $ref);
1150
1151 # set binary mode
1152 0 binmode($fh);
1153
1154 # save file type in object header
1155 0 $self->[0]{'file_type'} = '8BPS';
1156  
1157 # if default profile path supplied
1158 } elsif (defined($default)) {
1159
1160 # close current file
1161 0 close($fh);
1162
1163 # filter file path
1164 0 ICC::Shared::filterPath($default);
1165
1166 # open the profile file
1167 0 ▶ open($fh, '<', $default) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $default or return 0 0 0 0
1168
1169 # set binary mode
1170 0 binmode($fh);
1171
1172 # save path in object header
1173 0 $self->[0]{'file_path'} = $default;
1174
1175 # seek to profile file signature
1176 0 seek($fh, 36, 0);
1177
1178 # read profile file signature
1179 0 read($fh, $buf, 4);
1180
1181 # if not an ICC profile
1182 0 ▶ if ($buf ne 'acsp') {
Branch: 1 branch
BranchTrueFalseTotal
if ($buf ne "acsp") 0 0 0
1183
1184 # close file
1185 0 close($fh);
1186
1187 # return
1188 0 return(0);
1189
1190 }
1191
1192 } else {
1193
1194 # close file
1195 0 close($fh);
1196
1197 # return
1198 0 return(0);
1199
1200 }
1201
1202 }
1203  
1204 # read the header
1205 0 ▶ _readICCheader($fh, $self->[1]) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
_readICCheader($fh, $self->[1]) or return 0 0 0 0
1206  
1207 # read the tag table
1208 0 ▶ _readICCtagtable($fh, $self->[2]) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
_readICCtagtable($fh, $self->[2]) or return 0 0 0 0
1209  
1210 # for each tag
1211 0 for my $tag (@{$self->[2]}) {
1212
1213 # if a duplicate tag
1214 0 ▶ if (exists($hash{$tag->[1]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{$tag->[1]}) { } 0 0 0
1215
1216 # use original tag
1217 0 $tag->[3] = $hash{$tag->[1]};
1218
1219 } else {
1220
1221 # seek to start of tag
1222 0 seek($fh, $tag->[1], 0);
1223
1224 # read tag type signature
1225 0 read($fh, $type, 4);
1226
1227 # convert non-word characters to underscores
1228 0 $type =~ s|\W|_|g;
1229
1230 # form class specifier
1231 0 $class = "ICC::Profile::$type";
1232
1233 # if 'class->new_fh' method exists
1234 0 ▶ if ($class->can('new_fh')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('new_fh')) { } 0 0 0
1235
1236 # create specific tag object
1237 0 $tag->[3] = $class->new_fh($self, $fh, $tag);
1238
1239 } else {
1240
1241 # create generic tag object
1242 0 $tag->[3] = ICC::Profile::Generic->new_fh($self, $fh, $tag);
1243
1244 # print message
1245 0 print "tag type $type opened as generic\n";
1246
1247 }
1248
1249 # save tag in hash
1250 0 $hash{$tag->[1]} = $tag->[3];
1251
1252 }
1253
1254 # save white point tag
1255 0 ▶ $wtpt = $tag->[3] if ($tag->[0] eq 'wtpt');
Branch: 1 branch
BranchTrueFalseTotal
if $tag->[0] eq "wtpt" 0 0 0
1256
1257 # save black point tag
1258 0 ▶ $bkpt = $tag->[3] if ($tag->[0] eq 'bkpt');
Branch: 1 branch
BranchTrueFalseTotal
if $tag->[0] eq "bkpt" 0 0 0
1259
1260 # save 'A2B0' tag
1261 0 ▶ $A2B0 = $tag->[3] if ($tag->[0] eq 'A2B0');
Branch: 1 branch
BranchTrueFalseTotal
if $tag->[0] eq "A2B0" 0 0 0
1262
1263 # save 'A2B1' tag
1264 0 ▶ $A2B1 = $tag->[3] if ($tag->[0] eq 'A2B1');
Branch: 1 branch
BranchTrueFalseTotal
if $tag->[0] eq "A2B1" 0 0 0
1265
1266 }
1267  
1268 # close the profile file
1269 0 close($fh);
1270  
1271 # for each tag
1272 0 for my $tag (@{$self->[2]}) {
1273
1274 # if an 'A2Bx', 'B2Ax', or 'gamt' tag
1275 0 ▶ if (($tag->[0] =~ m/^(A2B[0-9A-F]|B2A[0-9A-F]|gamt)$/) && defined($tag->[3])) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag->[0] =~ /^(A2B[0-9A-F]|B2A[0-9A-F]|gamt)$/ and defined $tag->[3]) { } 0 0 0
elsif ($tag->[0] =~ /^(D2B[0-9A-F]|B2D[0-9A-F]|gbd[0-3])$/ and defined $tag->[3]) { } 0 0 0
Condition0%0/3
$tag->[0] =~ /^(A2B[0-9A-F]|B2A[0-9A-F]|gamt)$/ and defined $tag->[3]
!ll&&!rl&&r
000
MC/DC0%0/2
$tag->[0] =~ /^(A2B[0-9A-F]|B2A[0-9A-F]|gamt)$/ and defined $tag->[3]
$tag->[0] =~ /^(A2B[0-9A-F]|B2A[0-9A-F]|gamt)$/ defined $tag->[3]
Truth table0%0/3
A and B
A= $tag->[0] =~ /^(A2B[0-9A-F]|B2A[0-9A-F]|gamt)$/B= defined $tag->[3]
ABresult
0X0
100
111
1276
1277 # add white point XYZ values to tag header (if available)
1278 0 ▶ $tag->[3][0]{'wtpt'} = [@{$wtpt->XYZ}] if defined($wtpt);
Branch: 1 branch
BranchTrueFalseTotal
if defined $wtpt 0 0 0
1279
1280 # add black point XYZ values to tag header (if available)
1281 0 ▶ $tag->[3][0]{'bkpt'} = [@{$bkpt->XYZ}] if defined($bkpt);
Branch: 1 branch
BranchTrueFalseTotal
if defined $bkpt 0 0 0
1282
1283 # add pcs encoding to tag header
1284 0 ▶ $tag->[3][0]{'pcs_encoding'} = _pcs($self, defined($A2B1) ? $A2B1 : $A2B0);
Branch: 1 branch
BranchTrueFalseTotal
defined $A2B1 ? : 0 0 0
1285
1286 # if a 'D2Bx', 'B2Dx' or 'gbdx' tag
1287 ▶ } elsif (($tag->[0] =~ m/^(D2B[0-9A-F]|B2D[0-9A-F]|gbd[0-3])$/) && defined($tag->[3])) {
Condition0%0/3
$tag->[0] =~ /^(D2B[0-9A-F]|B2D[0-9A-F]|gbd[0-3])$/ and defined $tag->[3]
!ll&&!rl&&r
000
MC/DC0%0/2
$tag->[0] =~ /^(D2B[0-9A-F]|B2D[0-9A-F]|gbd[0-3])$/ and defined $tag->[3]
$tag->[0] =~ /^(D2B[0-9A-F]|B2D[0-9A-F]|gbd[0-3])$/ defined $tag->[3]
Truth table0%0/3
A and B
A= $tag->[0] =~ /^(D2B[0-9A-F]|B2D[0-9A-F]|gbd[0-3])$/B= defined $tag->[3]
ABresult
0X0
100
111
1288
1289 # add white point XYZ values to tag header (if available)
1290 0 ▶ $tag->[3][0]{'wtpt'} = [@{$wtpt->XYZ}] if defined($wtpt);
Branch: 1 branch
BranchTrueFalseTotal
if defined $wtpt 0 0 0
1291
1292 # add black point XYZ values to tag header (if available)
1293 0 ▶ $tag->[3][0]{'bkpt'} = [@{$bkpt->XYZ}] if defined($bkpt);
Branch: 1 branch
BranchTrueFalseTotal
if defined $bkpt 0 0 0
1294
1295 # add pcs encoding to tag header (32-bit)
1296 0 ▶ $tag->[3][0]{'pcs_encoding'} = $self->[1][5] eq 'Lab ' ? 3 : 8;
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][5] eq 'Lab ' ? : 0 0 0
1297
1298 }
1299
1300 }
1301  
1302 # return
1303 0 return(1);
1304  
1305 }
1306  
1307 # read ICC header
1308 # parameters: (file_handle, ref_to_header_array)
1309 # returns: (success_flag)
1310 sub _readICCheader {
1311  
1312 # get parameters
1313 0 ▶ my ($fh, $header) = @_;
Subroutine _readICCheader: not called CC=3 SCAR=24.8
1314  
1315 # seek to start of header
1316 0 seek($fh, 0, 0);
1317  
1318 # read the header (128 bytes)
1319 0 ▶ (read($fh, my $buf, 128) == 128) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
read($fh, my $buf, 128) == 128 or return 0 0 0 0
1320  
1321 # unpack the header
1322 0 @{$header} = unpack('N a4 H8 a4 a4 a4 n6 a4 a4 N a4 a4 N2 N N3 a4 H32 x28', $buf);
1323  
1324 # return success if profile file signature verified
1325 0 ▶ return($header->[12] eq 'acsp' ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$header->[12] eq 'acsp' ? : 0 0 0
1326  
1327 }
1328  
1329 # read ICC tag table
1330 # parameters: (file_handle, ref_to_tag_table_array)
1331 # returns: (success_flag)
1332 sub _readICCtagtable {
1333  
1334 # get parameters
1335 0 ▶ my ($fh, $tagtab) = @_;
Subroutine _readICCtagtable: not called CC=4 SCAR=30.0
1336  
1337 # local variables
1338 0 my ($buf, $n);
1339  
1340 # seek to start of tag table
1341 0 seek($fh, 128, 0);
1342  
1343 # read tag count (4 bytes)
1344 0 ▶ (read($fh, $buf, 4) == 4) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
read($fh, $buf, 4) == 4 or return 0 0 0 0
1345  
1346 # unpack tag count
1347 0 $n = unpack('N', $buf);
1348  
1349 # read tag entries
1350 0 for my $i (0 .. $n - 1) {
1351
1352 # read tag entry (12 bytes)
1353 0 ▶ (read($fh, $buf, 12) == 12) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
read($fh, $buf, 12) == 12 or return 0 0 0 0
1354
1355 # unpack tag entry
1356 0 $tagtab->[$i] = [unpack('a4 N N', $buf)];
1357
1358 }
1359  
1360 # return
1361 0 return(1);
1362  
1363 }
1364  
1365 # write ICC profile
1366 # parameters: (ref_to_object, path_to_profile)
1367 sub _writeICCprofile {
1368  
1369 # get parameters
1370 0 ▶ my ($self, $path) = @_;
Subroutine _writeICCprofile: not called CC=20 SCAR=60.4
1371  
1372 # local variables
1373 0 my (@localtime);
1374 0 my ($fh, $fp, $sig, %hash, %dup, $pad);
1375 0 my ($vmaj, $ri, $flags);
1376  
1377 # get profile major version
1378 0 $vmaj = substr($self->[1][2], 0, 2);
1379  
1380 # get localtime
1381 0 @localtime = localtime();
1382  
1383 # set time in profile header
1384 0 @{$self->[1]}[6 .. 11] = (
1385 $localtime[5] + 1900, # year
1386 $localtime[4] + 1, # month
1387 $localtime[3], # day
1388 $localtime[2], # hour
1389 $localtime[1], # minute
1390 $localtime[0], # second
1391 );
1392
1393 # if profile version 4
1394 0 ▶ if ($vmaj == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vmaj == 4) 0 0 0
1395
1396 # convert tags to version 4
1397 0 _to_v4($self);
1398
1399 # save flags
1400 0 $flags = $self->[1][14];
1401
1402 # save rendering intent (clearing upper 16-bits)
1403 0 $ri = $self->[1][19] & 0x0000ffff;
1404
1405 # clear for MD5 calculation
1406 0 $self->[1][14] = 0;
1407 0 $self->[1][19] = 0;
1408
1409 }
1410  
1411 # clear MD5 string
1412 0 $self->[1][24] = "\x00" x 16;
1413  
1414 # for each tag
1415 0 for my $i (0 .. $#{$self->[2]}) {
1416
1417 # get tag signature
1418 0 $sig = $self->[2][$i][0];
1419
1420 # error if duplicate tag
1421 0 ▶ (! exists($dup{$sig})) or croak("duplicate '$sig' tag");
Branch: 1 branch
BranchTrueFalseTotal
exists $dup{$sig} and croak("duplicate '${sig}' tag") 0 0 0
1422
1423 # add tag to duplicate hash
1424 0 $dup{$sig} = '';
1425
1426 # if tag object is defined
1427 0 ▶ if (defined($self->[2][$i][3])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[2][$i][3]) { } 0 0 0
1428
1429 # if tag->size method exists
1430 0 ▶ if ($self->[2][$i][3]->can('size')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[2][$i][3]->can('size')) { } 0 0 0
1431
1432 # set tag size (without padding)
1433 0 $self->[2][$i][2] = $self->[2][$i][3]->size();
1434
1435 # save size with padding to 4-byte boundary
1436 0 $hash{$self->[2][$i][3]} = $self->[2][$i][2] + (-$self->[2][$i][2] % 4);
1437
1438 } else {
1439
1440 # error
1441 0 croak("'$sig' object has no 'size' method");
1442
1443 }
1444
1445 } else {
1446
1447 # error
1448 0 croak("'$sig' object undefined");
1449
1450 }
1451
1452 }
1453  
1454 # compute profile header and tag table size
1455 0 $self->[1][0] = 132 + @{$self->[2]} * 12;
1456  
1457 # for each unique tag
1458 0 for (values(%hash)) {
1459
1460 # add tag size (with padding to 4-byte boundary)
1461 0 $self->[1][0] += $_;
1462
1463 }
1464  
1465 # initialize hash
1466 0 %hash = ();
1467  
1468 # initialize file pointer
1469 0 $fp = 132 + @{$self->[2]} * 12;
1470  
1471 # for each tag
1472 0 for my $tag (@{$self->[2]}) {
1473
1474 # if tag already processed
1475 0 ▶ if (exists($hash{$tag->[3]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{$tag->[3]}) { } 0 0 0
1476
1477 # copy offset
1478 0 $tag->[1] = $hash{$tag->[3]};
1479
1480 } else {
1481
1482 # set offset
1483 0 $tag->[1] = $fp;
1484
1485 # add tag to hash
1486 0 $hash{$tag->[3]} = $fp;
1487
1488 # increment offset with padding to 4-byte boundary
1489 0 $fp += $tag->[2] + (-$tag->[2] % 4);
1490
1491 }
1492
1493 }
1494  
1495 # if path a scalar reference
1496 0 ▶ if (ref($path) eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $path eq 'SCALAR') { } 0 0 0
elsif (not ref $path) { } 0 0 0
1497
1498 # open the profile file
1499 0 ▶ open($fh, '>', $path) or croak("unable to write profile to scalar");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("unable to write profile to scalar") 0 0 0
1500
1501 # if path a scalar
1502 } elsif (! ref($path)) {
1503
1504 # filter file path
1505 0 ICC::Shared::filterPath($path);
1506
1507 # open the profile file
1508 0 ▶ open($fh, '>', $path) or croak("unable to write profile to $path");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("unable to write profile to $path") 0 0 0
1509
1510 } else {
1511
1512 # error
1513 0 croak("invalid path parameter");
1514
1515 }
1516  
1517 # set binary mode
1518 0 binmode($fh);
1519  
1520 # write header
1521 0 _writeICCheader($fh, $self->[1]);
1522  
1523 # write tag table
1524 0 _writeICCtagtable($fh, $self->[2]);
1525  
1526 # initialize hash
1527 0 %hash = ();
1528  
1529 # for each tag
1530 0 for my $tag (@{$self->[2]}) {
1531
1532 # if tag not written
1533 0 ▶ if (! exists($hash{$tag->[3]})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hash{$tag->[3]}) 0 0 0
1534
1535 # if tag is writable
1536 0 ▶ if ($tag->[3]->can('write_fh')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->[3]->can('write_fh')) { } 0 0 0
1537
1538 # write tag
1539 0 $tag->[3]->write_fh($self, $fh, $tag);
1540
1541 # add to hash
1542 0 $hash{$tag->[3]}++;
1543
1544 } else {
1545
1546 # get tag signature
1547 0 $sig = $tag->[0];
1548
1549 # error
1550 0 croak("'$sig' object has no 'write_fh' method");
1551
1552 }
1553
1554 }
1555
1556 }
1557  
1558 # seek EOF (file pointer may be beyond actual EOF)
1559 0 seek($fh, 0, 2);
1560  
1561 # compute padding
1562 0 $pad = $self->[1][0] - tell($fh);
1563  
1564 # check for file overrun
1565 0 ▶ croak('file overrun') if ($pad < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $pad < 0 0 0 0
1566  
1567 # write final padding (if any)
1568 0 ▶ print $fh "\x00" x $pad if ($pad > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $pad > 0 0 0 0
1569  
1570 # close the profile file
1571 0 close($fh);
1572  
1573 # if profile version 4
1574 0 ▶ if ($vmaj == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vmaj == 4) 0 0 0
1575
1576 # re-open the profile file for read-write access
1577 0 open($fh, '+<', $path);
1578
1579 # set binary mode
1580 0 binmode($fh);
1581
1582 # calculate MD5 string
1583 0 $self->[1][24] = Digest::MD5->new->addfile($fh)->hexdigest;
1584
1585 # restore flags
1586 0 $self->[1][14] = $flags;
1587
1588 # restore rendering intent
1589 0 $self->[1][19] = $ri;
1590
1591 # re-write header
1592 0 _writeICCheader($fh, $self->[1]);
1593
1594 # close the profile file
1595 0 close($fh);
1596
1597 }
1598  
1599 # set file creator and type (Mac OSX) if path not a reference
1600 0 ▶ ICC::Shared::setFile($path, 'sync', 'prof') if (! ref($path));
Branch: 1 branch
BranchTrueFalseTotal
if not ref $path 0 0 0
1601  
1602 }
1603  
1604 # write ICC header
1605 # parameters: (file_handle, ref_to_header_array)
1606 sub _writeICCheader {
1607  
1608 # get parameters
1609 0 ▶ my ($fh, $header) = @_;
Subroutine _writeICCheader: not called CC=1 SCAR=6.9
1610  
1611 # seek to start of header
1612 0 seek($fh, 0, 0);
1613  
1614 # write the header (128 bytes)
1615 0 print $fh pack('N a4 H8 a4 a4 a4 n6 a4 a4 N a4 a4 N2 N N3 a4 H32 x28', @{$header});
1616  
1617 }
1618  
1619 # write ICC tag table
1620 # parameters: (file_handle, ref_to_tag_table)
1621 sub _writeICCtagtable {
1622  
1623 # get parameters
1624 0 ▶ my ($fh, $tagtab) = @_;
Subroutine _writeICCtagtable: not called CC=2 SCAR=17.9
1625  
1626 # seek to start of tag table
1627 0 seek($fh, 128, 0);
1628  
1629 # write tag count (4 bytes)
1630 0 print $fh pack('N', $#{$tagtab} + 1);
1631  
1632 # write tag entries
1633 0 for my $tag (@{$tagtab}) {
1634
1635 # write tag entry (12 bytes)
1636 0 print $fh pack('a4 N N', @{$tag}[0 .. 2]);
1637
1638 }
1639
1640 }
1641  
1642 # determine tag PCS encoding from A2B tag
1643 # parameters: (ref_to_profile_object, ref_to_tag_object)
1644 # returns: (pcs_type)
1645 sub _pcs {
1646  
1647 # get parameters
1648 0 ▶ my ($self, $tag) = @_;
Subroutine _pcs: not called CC=7 SCAR=40.3
1649  
1650 # local variables
1651 0 my (@Labmw);
1652  
1653 # if profile PCS is 'XYZ '
1654 0 ▶ if ($self->[1][5] eq 'XYZ ') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[1][5] eq 'XYZ ') { } 0 0 0
elsif ($self->[1][5] eq 'Lab ') { } 0 0 0
1655
1656 # return PCS encoding (16-bit XYZ)
1657 0 return(7);
1658
1659 # if profile PCS is 'Lab '
1660 } elsif ($self->[1][5] eq 'Lab ') {
1661
1662 # if tag is 'mft2'
1663 0 ▶ if (UNIVERSAL::isa($tag, 'ICC::Profile::mft2')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($tag, 'ICC::Profile::mft2')) { } 0 0 0
1664
1665 # get media white L*a*b* value
1666 0 ▶ @Labmw = $tag->transform(($self->[1][4] eq 'RGB ' ? 1 : 0) x $tag->input->cin());
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][4] eq 'RGB ' ? : 0 0 0
1667
1668 # return PCS encoding (16-bit ICC legacy)
1669 0 ▶ return(1) if (_dE(@Labmw, 65280/65535, 32768/65535, 32768/65535) < 0.00195);
Branch: 1 branch
BranchTrueFalseTotal
if _dE(@Labmw, "0.996108949416342", "0.500007629510948", "0.500007629510948") < "0.00195" 0 0 0
1670
1671 # return PCS encoding (Monaco)
1672 0 ▶ return(2) if (_dE(@Labmw, 1, 32768/65535, 32768/65535) < 0.00195);
Branch: 1 branch
BranchTrueFalseTotal
if _dE(@Labmw, 1, "0.500007629510948", "0.500007629510948") < "0.00195" 0 0 0
1673
1674 # print warning
1675 0 print "profile PCS encoding is ambiguous\n";
1676
1677 # return PCS encoding (16-bit legacy)
1678 0 return(1);
1679
1680 } else {
1681
1682 # return PCS encoding (16-bit ICC CIELab)
1683 0 return(0);
1684
1685 }
1686
1687 } else {
1688
1689 # return undefined (might be a device link profile)
1690 0 return();
1691
1692 }
1693
1694 }
1695  
1696 # compute deltaE
1697 # parameters: (array_1, array_2)
1698 sub _dE {
1699  
1700 # return
1701 0 ▶ return(sqrt(($_[0] - $_[3])**2 + (2.55 * ($_[1] - $_[4]))**2 + (2.55 * ($_[2] - $_[5]))**2));
Subroutine _dE: not called CC=1 SCAR=6.9
1702  
1703 }
1704  
1705 # convert 'desc' tags to version 4
1706 # see ICC1v43_2010-12.pdf, section 10.18.3
1707 # parameters: (ref_to_object)
1708 sub _to_v4 {
1709  
1710 # get parameters
1711 0 ▶ my ($self) = shift();
Subroutine _to_v4: not called CC=9 SCAR=45.0
1712  
1713 # for each tag
1714 0 for my $tag (@{$self->[2]}) {
1715
1716 # if 'desc' tag type
1717 0 ▶ if (UNIVERSAL::isa($tag->[3], 'ICC::Profile::desc')) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($tag->[3], 'ICC::Profile::desc')) { } 0 0 0
elsif (UNIVERSAL::isa($tag->[3], 'ICC::Profile::pseq')) { } 0 0 0
elsif ($tag->[0] eq 'cprt' and UNIVERSAL::isa($tag->[3], 'ICC::Profile::text')) { } 0 0 0
1718
1719 # replace with equivalent 'mluc' tag
1720 0 $tag->[3] = ICC::Profile::mluc->new('en', 'US', $tag->[3]->ASCII);
1721
1722 # if 'pseq' tag type
1723 } elsif (UNIVERSAL::isa($tag->[3], 'ICC::Profile::pseq')) {
1724
1725 # convert any 'desc' tags embedded in the 'pseq' tag
1726 #
1727 # for each pds
1728 0 for my $pds (@{$tag->[3][1]}) {
1729
1730 # if profile device manufacturer tag is 'desc' tag type
1731 0 ▶ if (UNIVERSAL::isa($pds->[5], 'ICC::Profile::desc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($pds->[5], "ICC::Profile::desc")) 0 0 0
1732
1733 # replace with equivalent 'mluc' tag
1734 0 $pds->[5] = ICC::Profile::mluc->new('en', 'US', $pds->[5]->ASCII);
1735
1736 }
1737
1738 # if profile device model tag is 'desc' tag type
1739 0 ▶ if (UNIVERSAL::isa($pds->[6], 'ICC::Profile::desc')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($pds->[6], "ICC::Profile::desc")) 0 0 0
1740
1741 # replace with equivalent 'mluc' tag
1742 0 $pds->[6] = ICC::Profile::mluc->new('en', 'US', $pds->[6]->ASCII);
1743
1744 }
1745
1746 }
1747
1748 # if 'cprt' tag is 'text' tag type
1749 ▶ } elsif ($tag->[0] eq 'cprt' && UNIVERSAL::isa($tag->[3], 'ICC::Profile::text')) {
Condition0%0/3
$tag->[0] eq "cprt" and UNIVERSAL::isa($tag->[3], "ICC::Profile::text")
!ll&&!rl&&r
000
MC/DC0%0/2
$tag->[0] eq "cprt" and UNIVERSAL::isa($tag->[3], "ICC::Profile::text")
$tag->[0] eq "cprt" UNIVERSAL::isa($tag->[3], "ICC::Profile::text")
Truth table0%0/3
A and B
A= $tag->[0] eq "cprt"B= UNIVERSAL::isa($tag->[3], "ICC::Profile::text")
ABresult
0X0
100
111
1750
1751 # replace with equivalent 'mluc' tag
1752 0 $tag->[3] = ICC::Profile::mluc->new('en', 'US', $tag->[3]->text);
1753
1754 }
1755
1756 }
1757
1758 }
1759  
1760 1 1;
« lib/ICC/Support/Color.pm ↑ Summary lib/ICC/Support/bern.pm »