blib/lib/ICC/Profile.pm

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