blib/lib/ICC/Profile/cvst.pm

filter: Statementstmt 5.1% 47 / 907 Branchbran 1.7% 6 / 350 Conditioncond 1.5% 2 / 126 MC/DCmcdc 0.0% 0 / 76 Subroutinesub 22.4% 13 / 58 Podpod 3.1% 1 / 32 totaltotal 4.4% 69 / 1549 CC 285 SCAR 53.0
CC
285
Cov
4%
graph
1056.0
photoshop
462.0
_options
380.0
CRAP 200.2
« lib/ICC/Support/nNET.pm ↑ Summary blib/lib/ICC/Support/spline.pm »
1 package ICC::Profile::cvst;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = 0.41;
7  
8 # revised 2018-09-07
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 7 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 7 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # support modules
19 7 ▶use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 # enable static variables
24 7 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 # create new cvst object
27 # array contains curve objects for each channel
28 # file path to 'iso_18620', 'store', or 'text' format curves
29 # curve objects must have 'transform' and 'derivative' methods
30 # parameters: ([ref_to_array])
31 # parameters: ([file_path])
32 # returns: (ref_to_object)
33 sub new {
34  
35 # get object class
36 11 ▶ my $class = shift;
Subroutine new: called CC=6 SCAR=22.9
Pod undocumented
37  
38 # create empty cvst object
39 11 my $self = [
40 {}, # object header
41 [], # curve object array
42 ];
43  
44 # if there are parameters
45 11 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 7 11
46
47 # if one parameter, an array reference
48 4 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 4 0 4
elsif (@_ == 1 and not ref $_[0]) { } 0 0 0
Condition33%1/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
004
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
49
50 # make new cvst object from array
51 4 _new_from_array($self, shift());
52
53 # if one parameter, a scalar
54 ▶ } elsif (@_ == 1 && ! ref($_[0])) {
Condition0%0/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table0%0/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
55
56 # make new cvst object from curve file
57 0 _new_from_file($self, shift());
58
59 } else {
60
61 # error
62 0 croak('\'cvst\' invalid parameter');
63
64 }
65
66 }
67  
68 # bless object
69 11 bless($self, $class);
70  
71 # return object reference
72 11 return($self);
73  
74 }
75  
76 # create inverse 'cvst' object
77 # returns: (ref_to_object)
78 sub inv {
79  
80 # get object
81 0 ▶ my $self = shift();
Subroutine inv: not called CC=3 SCAR=24.8
Pod undocumented
82  
83 # local variables
84 0 my ($array);
85  
86 # for each curve object
87 0 for my $i (0 .. $#{$self->[1]}) {
88
89 # verify curve object has 'inv' method
90 0 ▶ ($self->[1][$i]->can('inv')) or croak('curve element lacks \'inv\' method');
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][$i]->can("inv") or croak("curve element lacks 'inv' method") 0 0 0
91
92 # make inverse curve object
93 0 $array->[$i] = $self->[1][$i]->inv();
94
95 }
96  
97 # return
98 0 return(ICC::Profile::cvst->new($array));
99  
100 }
101  
102 # create cvst object from ICC profile
103 # assumes file handle is positoned at start of cvst data
104 # header information must be read separately by the calling function
105 # parameters: (ref_to_parent_object, file_handle, input_channels, output_channels)
106 # returns: (ref_to_object)
107 sub new_fh {
108  
109 # get object class
110 0 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
111  
112 # create empty cvst object
113 0 my $self = [
114 {}, # object header
115 [], # curve object array
116 ];
117  
118 # verify 3 parameters
119 0 ▶ (@_ == 3) or croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
120  
121 # read cvst data from profile
122 0 _readICCcvst($self, @_);
123  
124 # bless object
125 0 bless($self, $class);
126
127 # return object reference
128 0 return($self);
129  
130 }
131  
132 # writes cvst tag object to ICC profile
133 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
134 sub write_fh {
135  
136 # verify 4 parameters
137 0 ▶ (@_ == 4) or croak('wrong number of parameters');
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("wrong number of parameters") 0 0 0
138  
139 # write cvst data to profile
140 0 goto &_writeICCcvst;
141  
142 }
143  
144 # get cvst size (for writing to profile)
145 # returns: (cvst_size)
146 sub size {
147  
148 # get parameter
149 0 ▶ my $self = shift();
Subroutine size: not called CC=2 SCAR=17.9
Pod undocumented
150  
151 # get size of header and table
152 0 my $size = 12 + 8 * @{$self->[1]};
153  
154 # for each curve object
155 0 for my $crv (@{$self->[1]}) {
156
157 # add size
158 0 $size += $crv->size();
159
160 # adjust to 4-byte boundary
161 0 $size += -$size % 4;
162
163 }
164  
165 # return size
166 0 return($size);
167  
168 }
169  
170 # get number of input channels
171 # returns: (number)
172 sub cin {
173  
174 # get object reference
175 22 ▶ my $self = shift();
Subroutine cin: called CC=1 SCAR=0.0
Pod undocumented
176  
177 # return
178 22 return(scalar(@{$self->[1]}));
179  
180 }
181  
182 # get number of output channels
183 # returns: (number)
184 sub cout {
185  
186 # get object reference
187 10 ▶ my $self = shift();
Subroutine cout: called CC=1 SCAR=0.0
Pod undocumented
188  
189 # return
190 10 return(scalar(@{$self->[1]}));
191  
192 }
193  
194 # transform data
195 # hash key: 'clip'
196 # supported input types:
197 # parameters: (list, [hash])
198 # parameters: (vector, [hash])
199 # parameters: (matrix, [hash])
200 # parameters: (Math::Matrix_object, [hash])
201 # parameters: (structure, [hash])
202 # returns: (same_type_as_input)
203 sub transform {
204  
205 # set hash value (0 or 1)
206 0 ▶ my $h = ref($_[-1]) eq 'HASH' ? 1 : 0;
Subroutine transform: not called CC=12 SCAR=50.5
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 0 0 0
207  
208 # if input a 'Math::Matrix' object
209 0 ▶ if (@_ == $h + 2 && UNIVERSAL::isa($_[1], 'Math::Matrix')) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == $h + 2 and UNIVERSAL::isa($_[1], 'Math::Matrix')) { } 0 0 0
elsif (@_ == $h + 2 and ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (@_ == $h + 1 + grep({&Scalar::Util::looks_like_number($_);} @_)) { } 0 0 0
Condition0%0/3
@_ == $h + 2 and UNIVERSAL::isa($_[1], "Math::Matrix")
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == $h + 2 and UNIVERSAL::isa($_[1], "Math::Matrix")
@_ == $h + 2 UNIVERSAL::isa($_[1], "Math::Matrix")
Truth table0%0/3
A and B
A= @_ == $h + 2B= UNIVERSAL::isa($_[1], "Math::Matrix")
ABresult
0X0
100
111
210
211 # call matrix transform
212 0 &_trans2;
213
214 # if input an array reference
215 ▶ } elsif (@_ == $h + 2 && ref($_[1]) eq 'ARRAY') {
Condition0%0/3
@_ == $h + 2 and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == $h + 2 and ref $_[1] eq "ARRAY"
@_ == $h + 2 ref $_[1] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == $h + 2B= ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
216
217 # if array contains numbers (vector)
218 0 ▶ if (! ref($_[1][0]) && @{$_[1]} == grep {Scalar::Util::looks_like_number($_)} @{$_[1]}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})) { } 0 0 0
elsif (ref $_[1][0] eq 'ARRAY' and @{$_[1];} == grep({ref $_ eq 'ARRAY' and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})) { } 0 0 0
Condition0%0/3
not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
not ref $_[1][0] @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
Truth table0%0/3
not(A) and B
A= not ref $_[1][0]B= @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
ABresult
0X0
100
111
219
220 # call vector transform
221 0 &_trans1;
222
223 # if array contains vectors (2-D array)
224 0 ▶ } elsif (ref($_[1][0]) eq 'ARRAY' && @{$_[1]} == grep {ref($_) eq 'ARRAY' && Scalar::Util::looks_like_number($_->[0])} @{$_[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]) 0 0 0
Condition0%0/3
ref $_[1][0] eq "ARRAY" and @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1][0] eq "ARRAY" and @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
ref $_[1][0] eq "ARRAY" @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
Truth table0%0/3
A and B
A= ref $_[1][0] eq "ARRAY"B= @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
ABresult
0X0
100
111
225
226 # call matrix transform
227 0 &_trans2;
228
229 } else {
230
231 # call structure transform
232 0 &_trans3;
233
234 }
235
236 # if input a list (of numbers)
237 0 } elsif (@_ == $h + 1 + grep {Scalar::Util::looks_like_number($_)} @_) {
238
239 # call list transform
240 0 &_trans0;
241
242 } else {
243
244 # error
245 0 croak('invalid transform input');
246
247 }
248  
249 }
250  
251 # invert data
252 # hash key: 'clip'
253 # supported input types:
254 # parameters: (list, [hash])
255 # parameters: (vector, [hash])
256 # parameters: (matrix, [hash])
257 # parameters: (Math::Matrix_object, [hash])
258 # parameters: (structure, [hash])
259 # returns: (same_type_as_input)
260 sub inverse {
261  
262 # set hash value (0 or 1)
263 0 ▶ my $h = ref($_[-1]) eq 'HASH' ? 1 : 0;
Subroutine inverse: not called CC=12 SCAR=50.5
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 0 0 0
264  
265 # if input a 'Math::Matrix' object
266 0 ▶ if (@_ == $h + 2 && UNIVERSAL::isa($_[1], 'Math::Matrix')) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == $h + 2 and UNIVERSAL::isa($_[1], 'Math::Matrix')) { } 0 0 0
elsif (@_ == $h + 2 and ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (@_ == $h + 1 + grep({&Scalar::Util::looks_like_number($_);} @_)) { } 0 0 0
Condition0%0/3
@_ == $h + 2 and UNIVERSAL::isa($_[1], "Math::Matrix")
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == $h + 2 and UNIVERSAL::isa($_[1], "Math::Matrix")
@_ == $h + 2 UNIVERSAL::isa($_[1], "Math::Matrix")
Truth table0%0/3
A and B
A= @_ == $h + 2B= UNIVERSAL::isa($_[1], "Math::Matrix")
ABresult
0X0
100
111
267
268 # call matrix transform
269 0 &_inv2;
270
271 # if input an array reference
272 ▶ } elsif (@_ == $h + 2 && ref($_[1]) eq 'ARRAY') {
Condition0%0/3
@_ == $h + 2 and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == $h + 2 and ref $_[1] eq "ARRAY"
@_ == $h + 2 ref $_[1] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == $h + 2B= ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
273
274 # if array contains numbers (vector)
275 0 ▶ if (! ref($_[1][0]) && @{$_[1]} == grep {Scalar::Util::looks_like_number($_)} @{$_[1]}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})) { } 0 0 0
elsif (ref $_[1][0] eq 'ARRAY' and @{$_[1];} == grep({ref $_ eq 'ARRAY' and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})) { } 0 0 0
Condition0%0/3
not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
not ref $_[1][0] @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
Truth table0%0/3
not(A) and B
A= not ref $_[1][0]B= @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
ABresult
0X0
100
111
276
277 # call vector transform
278 0 &_inv1;
279
280 # if array contains vectors (2-D array)
281 0 ▶ } elsif (ref($_[1][0]) eq 'ARRAY' && @{$_[1]} == grep {ref($_) eq 'ARRAY' && Scalar::Util::looks_like_number($_->[0])} @{$_[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]) 0 0 0
Condition0%0/3
ref $_[1][0] eq "ARRAY" and @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1][0] eq "ARRAY" and @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
ref $_[1][0] eq "ARRAY" @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
Truth table0%0/3
A and B
A= ref $_[1][0] eq "ARRAY"B= @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
ABresult
0X0
100
111
282
283 # call matrix transform
284 0 &_inv2;
285
286 } else {
287
288 # call structure transform
289 0 &_inv3;
290
291 }
292
293 # if input a list (of numbers)
294 0 } elsif (@_ == $h + 1 + grep {Scalar::Util::looks_like_number($_)} @_) {
295
296 # call list transform
297 0 &_inv0;
298
299 } else {
300
301 # error
302 0 croak('invalid transform input');
303
304 }
305  
306 }
307  
308 # compute Jacobian matrix
309 # hash key 'diag' for diagonal vector
310 # parameters: (input_vector, [hash])
311 # returns: (Jacobian_matrix, [output_vector])
312 sub jacobian {
313  
314 # get parameters
315 0 ▶ my ($self, $in, $hash) = @_;
Subroutine jacobian: not called CC=5 SCAR=34.0
Pod undocumented
316  
317 # local variables
318 0 my (@drv, $out, $jac);
319  
320 # for each channel
321 0 for my $i (0 .. $#{$self->[1]}) {
322
323 # compute derivative
324 0 $drv[$i] = $self->[1][$i]->derivative($in->[$i]);
325
326 # compute transform
327 0 ▶ $out->[$i] = $self->[1][$i]->transform($in->[$i]) if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 0 0 0
328
329 }
330  
331 # if 'diag' enabled
332 0 ▶ if ($hash->{'diag'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{'diag'}) { } 0 0 0
333
334 # make diagonal vector
335 0 $jac = [@drv];
336
337 } else {
338
339 # make diagonal matrix
340 0 $jac = Math::Matrix->diagonal(@drv);
341
342 }
343  
344 # if output values wanted
345 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
346
347 # return Jacobian matrix and output vector
348 0 return($jac, $out);
349
350 } else {
351
352 # return Jacobian matrix only
353 0 return($jac);
354
355 }
356
357 }
358  
359 # compute parametric Jacobian matrix
360 # note: parameters are selected by the 'slice' array
361 # parameters: (input_vector)
362 # returns: (parametric_jacobian_matrix)
363 sub parajac {
364  
365 # get parameters
366 0 ▶ my ($self, $in) = @_;
Subroutine parajac: not called CC=7 SCAR=40.3
Pod undocumented
367  
368 # local variables
369 0 my ($jac, $s, @pj);
370  
371 # verify curve object has 'parametric' method
372 0 ▶ ($self->[1][0]->can('parametric')) or croak("curve object has no 'parametric' method");
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0]->can("parametric") or croak("curve object has no 'parametric' method") 0 0 0
373  
374 # get slice array ref (if any)
375 0 $s = $self->[0]{'slice'};
376  
377 # for each channel
378 0 for my $i (0 .. $#{$self->[1]}) {
379
380 # get parametric partial derivatives
381 0 @pj = $self->[1][$i]->parametric($in->[$i]);
382
383 # for each channel
384 0 for my $j (0 .. $#{$self->[1]}) {
385
386 # if current channel
387 0 ▶ if ($j == $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j == $i) { } 0 0 0
388
389 # if slice defined
390 0 ▶ if ($s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s) { } 0 0 0
391
392 # push slice parameters on matrix row
393 0 push(@{$jac->[$j]}, @pj[@{$s}]);
394
395 } else {
396
397 # push all parameters on matrix row
398 0 push(@{$jac->[$j]}, @pj);
399
400 }
401
402 } else {
403
404 # if slice defined
405 0 ▶ if ($s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s) { } 0 0 0
406
407 # push zeros on matrix row
408 0 push(@{$jac->[$j]}, (0) x @{$s});
409
410 } else {
411
412 # push zeros on matrix row
413 0 push(@{$jac->[$j]}, (0) x @pj);
414
415 }
416
417 }
418
419 }
420
421 }
422  
423 # return Jacobian matrix
424 0 return(bless($jac, 'Math::Matrix'));
425  
426 }
427  
428 # get/set reference to header hash
429 # parameters: ([ref_to_new_hash])
430 # returns: (ref_to_hash)
431 sub header {
432
433 # get object reference
434 0 ▶ my $self = shift();
Subroutine header: not called CC=4 SCAR=30.0
Pod undocumented
435
436 # if there are parameters
437 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
438
439 # if one parameter, a hash reference
440 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
441
442 # set header to new hash
443 0 $self->[0] = {%{shift()}};
444
445 } else {
446
447 # error
448 0 croak('parameter must be a hash reference');
449
450 }
451
452 }
453
454 # return reference
455 0 return($self->[0]);
456
457 }
458  
459 # get/set array reference
460 # parameters: ([ref_to_new_array])
461 # returns: (ref_to_array)
462 sub array {
463  
464 # get object reference
465 65 ▶ my $self = shift();
Subroutine array: called CC=7 SCAR=33.6
Pod undocumented
466  
467 # if one parameter supplied
468 65 ▶ if (@_ == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 0 65 65
elsif (@_) { } 0 65 65
469
470 # verify array reference
471 0 ▶ (ref($_[0]) eq 'ARRAY') or croak('not an array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "ARRAY" or croak("not an array reference") 0 0 0
472  
473 # get array reference
474 0 my $array = shift();
475
476 # for each curve element
477 0 for my $i (0 .. $#{$array}) {
478
479 # verify object has processing methods
480 0 ▶ ($array->[$i]->can('transform') && $array->[$i]->can('derivative')) or croak('curve element lacks \'transform\' or \'derivative\' method');
Branch: 1 branch
BranchTrueFalseTotal
$array->[$i]->can("transform") and $array->[$i]->can("derivative") or croak("curve element lacks 'transform' or 'derivative' method") 0 0 0
Condition0%0/3
$array->[$i]->can("transform") and $array->[$i]->can("derivative")
!ll&&!rl&&r
000
MC/DC0%0/2
$array->[$i]->can("transform") and $array->[$i]->can("derivative")
$array->[$i]->can("transform") $array->[$i]->can("derivative")
Truth table0%0/3
A and B
A= $array->[$i]->can("transform")B= $array->[$i]->can("derivative")
ABresult
0X0
100
111
481
482 # add curve element
483 0 $self->[1][$i] = $array->[$i];
484
485 }
486
487 } elsif (@_) {
488
489 # error
490 0 croak("too many parameters\n");
491
492 }
493
494 # return array reference
495 65 return($self->[1]);
496
497 }
498  
499 # get 'para' or 'parf' curve parameters
500 # returns: (ref_to_array)
501 sub pars {
502  
503 # get object reference
504 0 ▶ my $self = shift();
Subroutine pars: not called CC=4 SCAR=30.0
Pod undocumented
505  
506 # local variables
507 0 my ($pars);
508  
509 # for each curve
510 0 for my $i (0 .. $#{$self->[1]}) {
511
512 # verify curve is a 'para' or 'parf' object
513 0 ▶ (UNIVERSAL::isa($self->[1][$i], 'ICC::Profile::para') || UNIVERSAL::isa($self->[1][$i], 'ICC::Profile::parf')) or croak('curve is not a \'para\' or \'parf\' object');
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para") or UNIVERSAL::isa($self->[1][$i], "ICC::Profile::parf") or croak("curve is not a 'para' or 'parf' object") 0 0 0
Condition0%0/3
UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para") or UNIVERSAL::isa($self->[1][$i], "ICC::Profile::parf")
l!l&&r!l&&!r
000
MC/DC0%0/2
UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para") or UNIVERSAL::isa($self->[1][$i], "ICC::Profile::parf")
UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para") UNIVERSAL::isa($self->[1][$i], "ICC::Profile::parf")
Truth table0%0/3
A or B
A= UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para")B= UNIVERSAL::isa($self->[1][$i], "ICC::Profile::parf")
ABresult
1X1
011
000
514
515 # copy parameters
516 0 $pars->[$i] = [@{$self->[1][$i]->array}];
517
518 }
519  
520 # return parameter array
521 0 return($pars);
522  
523 }
524  
525 # make new 'cvst' object containing 'curv' objects
526 # assumes curve domain/range is (0 - 1)
527 # direction: 0 - normal, 1 - inverse
528 # parameters: (number_of_table_entries, [direction])
529 # returns: (cvst_object)
530 sub curv {
531  
532 # get parameters
533 0 ▶ my ($self, $n, $dir) = @_;
Subroutine curv: not called CC=2 SCAR=17.9
Pod undocumented
534  
535 # local variables
536 0 my ($curv);
537  
538 # for each channel
539 0 for my $i (0 .. $#{$self->[1]}) {
540
541 # create table array
542 0 $curv->[$i] = $self->[1][$i]->curv($n, $dir);
543
544 }
545  
546 # return 'cvst' object
547 0 return(ICC::Profile::cvst->new($curv));
548  
549 }
550  
551 # write Agfa Apogee tone curve file
552 # assumes curve domain/range is (0 - 1)
553 # options parameter may be a hash reference or direction flag
554 # hash keys: 'dir', 'steps'
555 # direction: 0 - normal, 1 - inverse
556 # parameters: (file_path, [options])
557 sub apogee {
558  
559 # get parameters
560 0 ▶ my ($self, $path, $opts) = @_;
Subroutine apogee: not called CC=3 SCAR=24.8
Pod undocumented
561  
562 # local variables
563 0 my ($dir, $steps, %ink);
564 0 my ($dom, $root, @obj);
565 0 my ($i, @out);
566  
567 # process options
568 0 ($dir, $steps) = _options($opts);
569  
570 # set ink hash
571 0 %ink = ('Cyan', 0, 'Magenta', 1, 'Yellow', 2, 'Black', 3);
572  
573 # filter path
574 0 ICC::Shared::filterPath($path);
575  
576 # open curve set template
577 0 ▶ eval {$dom = XML::LibXML->load_xml('location' => ICC::Shared::getICCPath('Templates/Apogee_template.xml'))} or croak('can\'t load Apogee curve template');
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $dom = "XML::LibXML"->load_xml("location", ICC::Shared::getICCPath("Templates/Apogee_template.xml")) } } or croak("can't load Apogee curve template") 0 0 0
578  
579 # get the root element
580 0 $root = $dom->documentElement();
581  
582 # get the 'Curve' nodes
583 0 @obj = $root->findnodes('Curve');
584  
585 # for each 'Curve' node
586 0 for my $n (@obj) {
587
588 # look-up the color index (0 - 3)
589 0 $i = $ink{$n->getAttribute('Name')};
590
591 # set the 'Stimuli' values
592 0 $n->setAttribute('Stimuli', join(' ', @{$steps}));
593
594 # set the 'Measured' values
595 0 $n->setAttribute('Measured', join(' ', @{$steps}));
596
597 # compute and set the 'Wanted' values
598 0 $n->setAttribute('Wanted', join(' ', map {sprintf("%f", 100 * ($self->[1][$i]->_transform($dir, $_/100)))} @{$steps}));
599
600 # compute and set the 'TransferCurve' values
601 0 $n->setAttribute('TransferCurve', join(' ', map {sprintf("%f", 100 * ($self->[1][$i]->_transform($dir, $_/255)))} (0 .. 255)));
602
603 }
604  
605 # add namespace attribute
606 0 $root->setAttribute('xmlns', 'file:///procres');
607  
608 # write XML file
609 0 $dom->toFile($path, 1);
610  
611 }
612  
613 # write device link profile containing tone curves
614 # assumes curve domain/range is (0 - 1)
615 # options parameter may be a hash reference or direction flag
616 # hash key: 'dir'
617 # direction: 0 - normal, 1 - inverse
618 # parameters: (file_path, [options])
619 sub device_link {
620  
621 # get parameters
622 0 ▶ my ($self, $path, $opts) = @_;
Subroutine device_link: not called CC=9 SCAR=45.0
Pod undocumented
623  
624 # local variables
625 0 my ($dir, $n, $sig, $clrt, $profile, $b);
626  
627 # process options
628 0 ($dir) = _options($opts);
629  
630 # get number of channels
631 0 $n = @{$self->[1]};
632  
633 # filter path
634 0 ICC::Shared::filterPath($path);
635  
636 # if grayscale
637 0 ▶ if ($n == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($n == 1) { } 0 0 0
elsif ($n == 3) { } 0 0 0
elsif ($n == 4) { } 0 0 0
638
639 # make signature
640 0 $sig = 'GRAY';
641
642 } elsif ($n == 3) {
643
644 # make signature
645 0 $sig = 'RGB ';
646
647 } elsif ($n == 4) {
648
649 # make signature
650 0 $sig = 'CMYK';
651
652 } else {
653
654 # make signature
655 0 $sig = sprintf("%XCLR", $n);
656
657 # make colorant tag (could be developed further)
658 0 $clrt = ICC::Profile::clrt->new();
659
660 }
661  
662 # make device link profile object
663 0 $profile = ICC::Profile->new({'class' => 'link', 'data' => $sig, 'PCS' => $sig, 'version' => '04200000'});
664  
665 # add copyright tag
666 0 $profile->tag({'cprt' => ICC::Profile::mluc->new('en', 'US', 'Copyright (c) 2004-2018 by William B. Birkett')});
667  
668 # add description tag
669 0 $profile->tag({'desc' => ICC::Profile::mluc->new('en', 'US', 'tone curves')});
670  
671 # add profile sequence tag
672 0 $profile->tag({'pseq' => ICC::Profile::pseq->new()});
673  
674 # for each curve
675 0 for my $i (0 .. $#{$self->[1]}) {
676
677 # if direction is forward and curve is an ICC::Profile object
678 0 ▶ if ($dir == 0 && (UNIVERSAL::isa($self->[1][$i], 'ICC::Profile::curv') || UNIVERSAL::isa($self->[1][$i], 'ICC::Profile::para'))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir == 0 and UNIVERSAL::isa($self->[1][$i], 'ICC::Profile::curv') || UNIVERSAL::isa($self->[1][$i], 'ICC::Profile::para')) { } 0 0 0
Condition0%0/6
$dir == 0 and UNIVERSAL::isa($self->[1][$i], "ICC::Profile::curv") || UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para")
!ll&&!rl&&r
000
UNIVERSAL::isa($self->[1][$i], "ICC::Profile::curv") or UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para")
l!l&&r!l&&!r
000
MC/DC0%0/3
$dir == 0 and UNIVERSAL::isa($self->[1][$i], "ICC::Profile::curv") || UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para")
$dir == 0 UNIVERSAL::isa($self->[1][$i], "ICC::Profile::curv") UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para")
Truth table0%0/4
A and B or C
A= $dir == 0B= UNIVERSAL::isa($self->[1][$i], "ICC::Profile::curv")C= UNIVERSAL::isa($self->[1][$i], "ICC::Profile::para")
ABCresult
0XX0
1000
11X1
1011
679
680 # use curve object as-is
681 0 $b->[$i] = $self->[1][$i];
682
683 } else {
684
685 # use ICC::Profile::curv equivalent
686 0 $b->[$i] = $self->[1][$i]->curv(1285, $dir);
687
688 }
689
690 }
691  
692 # add A2B0 tag (B-curves only)
693 0 $profile->tag({'A2B0' => ICC::Profile::mAB_->new({'b_curves' => ICC::Profile::cvst->new($b)})});
694  
695 # add colorant tags, if nCLR
696 0 ▶ $profile->tag({'clrt' => $clrt, 'clot' => $clrt}) if (defined($clrt));
Branch: 1 branch
BranchTrueFalseTotal
if defined $clrt 0 0 0
697  
698 # write profile
699 0 $profile->write($path);
700  
701 }
702  
703 # write EFI tone curve file
704 # assumes curve domain/range is (0 - 1)
705 # options parameter may be a hash reference or direction flag
706 # hash keys: 'dir', 'steps'
707 # direction: 0 - normal, 1 - inverse
708 # parameters: (file_path, [options])
709 sub efi {
710  
711 # get parameters
712 0 ▶ my ($self, $path, $opts) = @_;
Subroutine efi: not called CC=8 SCAR=42.8
Pod undocumented
713  
714 # local variables
715 0 my ($dir, $steps, @ch, $include, $tt, $t, $fh, $str, $vars);
716  
717 # process options
718 0 ($dir, $steps) = _options($opts);
719  
720 # filter path
721 0 ICC::Shared::filterPath($path);
722  
723 # channel lookup (EFI ink sequence is YMCK)
724 0 @ch = (2, 1, 0, 3, 4, 5, 6, 7);
725  
726 # if ICC::Templates folder is found in @INC (may be relative)
727 0 ▶ if (($include) = grep {-d} map {File::Spec->catdir($_, 'ICC', 'Templates')} @INC) {
Branch: 1 branch
BranchTrueFalseTotal
if (($include) = grep({-d $_;} map({"File::Spec"->catdir($_, "ICC", "Templates");} @INC))) 0 0 0
728
729 # make a template processing object
730 0 $tt = Template->new({
731 'INCLUDE_PATH' => $include,
732 });
733
734 # for each curve
735 0 for my $i (0 .. 7) {
736
737 # open file handle to string
738 0 open($fh, '>', \$str);
739
740 # print header
741 0 print $fh "BEGIN\n";
742
743 # if curve object is defined
744 0 ▶ if (defined($self->[1][$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1][$i]) { } 0 0 0
745
746 # print number of points
747 0 printf $fh "%d\n", scalar(@{$steps});
748
749 # for each curve input
750 0 for my $t (@{$steps}) {
751
752 # print output and input device values
753 0 printf $fh "%.5f %.5f\n", $self->[1][$i]->_transform($dir, $t/100), $t/100;
754
755 }
756
757 # for each integer byte value
758 0 for my $t (0 .. 255) {
759
760 # print input and output values
761 0 printf $fh "%d %.0f\n", $t, 255 * $self->[1][$i]->_transform($dir, $t/255);
762
763 }
764
765 } else {
766
767 # print identity curve
768 0 print $fh "2\n0.00000 0.00000\n1.00000 1.00000\n";
769
770 # for each integer byte value
771 0 for my $t (0 .. 255) {
772
773 # print input and output values
774 0 printf $fh "%d %d\n", $t, $t;
775
776 }
777
778 }
779
780 # print footer
781 0 print $fh "END";
782
783 # add string to template hash
784 0 $vars->{"curve$ch[$i]"} = $str;
785
786 # close file handle
787 0 close($fh);
788
789 }
790
791 # make Time::Piece object
792 0 $t = localtime;
793
794 # add date to template hash
795 0 $vars->{'date'} = $t->strftime('%m-%d-%y');
796
797 # process the template
798 0 ▶ $tt->process('cvst_efi_vcc.tt2', $vars, $path) || CORE::die $tt->error();
Branch: 1 branch
BranchTrueFalseTotal
$tt->process("cvst_efi_vcc.tt2", $vars, $path) or die $tt->error 0 0 0
799
800 }
801
802 }
803  
804 # write Fuji XMF tone curve file
805 # assumes curve domain/range is (0 - 1)
806 # options parameter may be a hash reference or direction flag
807 # hash key: 'dir'
808 # direction: 0 - normal, 1 - inverse
809 # parameters: (file_path, [options])
810 sub fuji_xmf {
811  
812 # get parameters
813 0 ▶ my ($self, $path, $opts) = @_;
Subroutine fuji_xmf: not called CC=5 SCAR=34.0
Pod undocumented
814  
815 # local variables
816 0 my ($dir, $steps, $fh, $rs, @colors, @Tdot);
817  
818 # process options
819 0 ($dir, $steps) = _options($opts);
820  
821 # filter path
822 0 ICC::Shared::filterPath($path);
823  
824 # open the file
825 0 ▶ open($fh, '>', $path) or croak("can't open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("can't open ${path}: $!") 0 0 0
826  
827 # disable :crlf translation
828 0 binmode($fh);
829  
830 # set output record separator (Windows CR-LF)
831 0 $rs = "\015\012";
832  
833 # set color list
834 0 @colors = qw(Cyan Magenta Yellow Black);
835  
836 # print colors
837 0 print $fh join(';', @colors), $rs;
838  
839 # for each step
840 0 for my $j (0 .. 100) {
841
842 # if a valid dot value
843 0 ▶ if (grep {$j == $_} @{$steps}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$j == $_;} @{$steps;}) { } 0 0 0
844
845 # for each channel
846 0 for my $i (0 .. 3) {
847
848 # compute transformed dot value
849 0 $Tdot[$i] = sprintf("%.2f", 100 * ($self->[1][$i]->_transform($dir, $j/100)));
850
851 }
852
853 # print transformed values
854 0 print $fh join(';', @Tdot), $rs;
855
856 } else {
857
858 # print empty line
859 0 print $fh '‐;‐;‐;‐', $rs;
860
861 }
862
863 }
864  
865 # close the file
866 0 close($fh);
867  
868 }
869  
870 # write Harlequin tone curve file
871 # assumes curve domain/range is (0 - 1)
872 # options parameter may be a hash reference or direction flag
873 # hash key: 'dir'
874 # direction: 0 - normal, 1 - inverse
875 # note: values must be entered manually in Harlequin RIP
876 # parameters: (file_path, [options])
877 sub harlequin {
878  
879 # get parameters
880 0 ▶ my ($self, $path, $opts) = @_;
Subroutine harlequin: not called CC=4 SCAR=30.0
Pod undocumented
881  
882 # local variables
883 0 my ($dir, $steps, @files, $fh, $rs, @colors);
884  
885 # process options
886 0 ($dir, $steps) = _options($opts);
887  
888 # filter path
889 0 ICC::Shared::filterPath($path);
890  
891 # open the file
892 0 ▶ open($fh, '>', $path) or croak("can't open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("can't open ${path}: $!") 0 0 0
893  
894 # disable :crlf translation
895 0 binmode($fh);
896  
897 # set output record separator (Windows CR-LF)
898 0 $rs = "\015\012";
899
900 # set color list
901 0 @colors = qw(Cyan Magenta Yellow Black);
902  
903 # for each channel
904 0 for my $i (0 .. 3) {
905
906 # print color
907 0 print $fh "$colors[$i]$rs";
908
909 # for each step
910 0 for my $j (0 .. $#{$steps}) {
911
912 # print input and transformed values
913 0 printf $fh "%7.2f %7.2f$rs", $steps->[$j], 100 * ($self->[1][$i]->_transform($dir, $steps->[$j]/100));
914
915 }
916
917 # print space
918 0 print $fh "$rs$rs";
919
920 }
921  
922 # close the file
923 0 close($fh);
924  
925 }
926  
927 # write HP Indigo tone curve file set
928 # assumes curve domain/range is (0 - 1)
929 # options parameter may be a hash reference or direction flag
930 # hash key: 'dir'
931 # direction: 0 - normal, 1 - inverse
932 # parameters: (folder_path, [options])
933 sub indigo {
934  
935 # get parameters
936 0 ▶ my ($self, $path, $opts) = @_;
Subroutine indigo: not called CC=9 SCAR=45.0
Pod undocumented
937  
938 # local variables
939 0 my ($dir, $steps, $rs, $fh, $file);
940 0 my (@CMYK, $dotr, $dotp);
941  
942 # process options
943 0 ($dir, $steps) = _options($opts);
944  
945 # set output record separator (Windows CR-LF)
946 0 $rs = "\015\012";
947  
948 # filter path
949 0 ICC::Shared::filterPath($path);
950  
951 # make the folder
952 0 File::Path::make_path($path);
953  
954 # ink color array (for building file names)
955 0 @CMYK = qw(Cyan Magenta Yellow Black);
956  
957 # for each color
958 0 for my $i (0 .. 3) {
959
960 # build the file path
961 0 ▶ $file = $^O eq 'MSWin32' ? "$path\\tone_curve-$CMYK[$i].lut" : "$path/tone_curve-$CMYK[$i].lut";
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
962
963 # create the file
964 0 ▶ open($fh, '>', $file) or croak("can't open $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $file or croak("can't open ${file}: $!") 0 0 0
965
966 # disable :crlf translation
967 0 binmode($fh);
968  
969 # for each step
970 0 for my $j (0 .. $#{$steps}) {
971
972 # get reference device value
973 0 $dotr = $steps->[$j]/100;
974
975 # get press device value
976 0 $dotp = $self->[1][$i]->_transform($dir, $dotr);
977
978 # limit %-dot (0 - 100)
979 0 ▶ $dotr = ($dotr < 0) ? 0 : $dotr;
Branch: 1 branch
BranchTrueFalseTotal
$dotr < 0 ? : 0 0 0
980 0 ▶ $dotp = ($dotp < 0) ? 0 : $dotp;
Branch: 1 branch
BranchTrueFalseTotal
$dotp < 0 ? : 0 0 0
981 0 ▶ $dotr = ($dotr > 1) ? 1 : $dotr;
Branch: 1 branch
BranchTrueFalseTotal
$dotr > 1 ? : 0 0 0
982 0 ▶ $dotp = ($dotp > 1) ? 1 : $dotp;
Branch: 1 branch
BranchTrueFalseTotal
$dotp > 1 ? : 0 0 0
983
984 # print step info
985 0 printf $fh "%4.2f\t%6.4f$rs", $dotr, $dotp;
986
987 }
988
989 # close file
990 0 close($fh);
991
992 }
993
994 }
995  
996 # write ISO 18620 (TED) tone curve file
997 # assumes curve domain/range is (0 - 1)
998 # options parameter may be a hash reference or direction flag
999 # hash keys: 'dir', 'steps', 'inks', 'Creator', 'OperatorName',
1000 # 'PressName', 'MediaName', 'TransferCurveSetID', 'Side'
1001 # direction: 0 - normal, 1 - inverse
1002 # parameters: (file_path, [options])
1003 sub iso_18620 {
1004  
1005 # get parameters
1006 0 ▶ my ($self, $path, $opts) = @_;
Subroutine iso_18620: not called CC=13 SCAR=52.0
Pod undocumented
1007  
1008 # local variables
1009 0 my ($dir, $steps, @inks, @attr);
1010 0 my ($doc, $root, $t, $datetime, $curve, @out);
1011  
1012 # process options
1013 0 ($dir, $steps) = _options($opts);
1014  
1015 # set ink colors
1016 0 ▶ @inks = $#{$self->[1]} ? qw(Cyan Magenta Yellow Black) : qw(Black);
Branch: 1 branch
BranchTrueFalseTotal
$#{$$self[1];} ? : 0 0 0
1017  
1018 # for each curve
1019 0 for my $i (0 .. $#{$self->[1]}) {
1020
1021 # set ink value, defaults to 'inkN'
1022 0 ▶ $inks[$i] = $opts->{'inks'}[$i] // $self->[0]{'inks'}[$i] // $inks[$i] // sprintf("ink%d", $i + 1);
Condition0%0/9
(($opts->{"inks"}[$i] // $self->[0]{"inks"}[$i]) // $inks[$i]) // sprintf("ink%d", $i + 1)
l!l&&r!l&&!r
000
($opts->{"inks"}[$i] // $self->[0]{"inks"}[$i]) // $inks[$i]
l!l&&r!l&&!r
000
$opts->{"inks"}[$i] // $self->[0]{"inks"}[$i]
l!l&&r!l&&!r
000
MC/DC0%0/4
(($opts->{"inks"}[$i] // $self->[0]{"inks"}[$i]) // $inks[$i]) // sprintf("ink%d", $i + 1)
$opts->{"inks"}[$i] $self->[0]{"inks"}[$i] $inks[$i] sprintf("ink%d", $i + 1)
Truth table0%0/5
A // B // C // D
A= $opts->{"inks"}[$i]B= $self->[0]{"inks"}[$i]C= $inks[$i]D= sprintf("ink%d", $i + 1)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1023
1024 }
1025  
1026 # filter path
1027 0 ICC::Shared::filterPath($path);
1028  
1029 # list of optional TransferCurveSet attributes
1030 0 @attr = qw(Creator OperatorName PressName MediaName TransferCurveSetID Side);
1031  
1032 # create XML document
1033 0 $doc = XML::LibXML->createDocument('1.0', 'UTF-8');
1034  
1035 # create root element
1036 0 $root = $doc->createElement('TransferCurveSet');
1037  
1038 # add root node
1039 0 $doc->setDocumentElement($root);
1040  
1041 # make Time::Piece object
1042 0 $t = localtime;
1043  
1044 # set 'CreationDate' attribute
1045 0 $root->setAttribute('CreationDate', sprintf("%s%+03d:00", $t->datetime, $t->tzoffset->hours));
1046  
1047 # verify 'Side' attribute
1048 0 ▶ (! defined($opts->{'Side'}) || $opts->{'Side'} eq 'Front' || $opts->{'Side'} eq 'Back') or croak('invalid \'Side\' attribute');
Branch: 1 branch
BranchTrueFalseTotal
not defined $opts->{"Side"} or $opts->{"Side"} eq "Front" or $opts->{"Side"} eq "Back" or croak("invalid 'Side' attribute") 0 0 0
Condition0%0/6
not defined $opts->{"Side"} or $opts->{"Side"} eq "Front" or $opts->{"Side"} eq "Back"
l!l&&r!l&&!r
000
not defined $opts->{"Side"} or $opts->{"Side"} eq "Front"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $opts->{"Side"} or $opts->{"Side"} eq "Front" or $opts->{"Side"} eq "Back"
not defined $opts->{"Side"} $opts->{"Side"} eq "Front" $opts->{"Side"} eq "Back"
Truth table0%0/4
not(A) or B or C
A= not defined $opts->{"Side"}B= $opts->{"Side"} eq "Front"C= $opts->{"Side"} eq "Back"
ABCresult
1XX1
01X1
0011
0000
1049  
1050 # for each optional attribute
1051 0 for my $key (@attr) {
1052
1053 # if attribute contained in hash
1054 0 ▶ if (defined($opts->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{$key}) 0 0 0
1055
1056 # set attribute value
1057 0 $root->setAttribute($key, $opts->{$key});
1058
1059 }
1060
1061 }
1062  
1063 # set 'Creator' attribute, if undefined
1064 0 ▶ $root->setAttribute('Creator', 'ICC-Profile Toolkit') if (! defined($opts->{'Creator'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts->{"Creator"} 0 0 0
1065  
1066 # for each curve
1067 0 for my $i (0 .. $#{$self->[1]}) {
1068
1069 # create curve element
1070 0 $curve = $doc->createElement('TransferCurve');
1071
1072 # set the 'Separation' attribute
1073 0 $curve->setAttribute('Separation', $inks[$i]);
1074
1075 # compute and set the 'Curve' values
1076 0 $curve->setAttribute('Curve', join(' ', map {sprintf("%f %f", $_/100, $self->[1][$i]->_transform($dir, $_/100))} @{$steps}));
1077
1078 # add curve node
1079 0 $root->addChild($curve);
1080
1081 }
1082  
1083 # add namespace attribute
1084 0 $root->setAttribute('xmlns', 'http://www.npes.org/schema/ISO18620/');
1085  
1086 # write XML file
1087 0 $doc->toFile($path, 1);
1088  
1089 }
1090  
1091 # write Photoshop tone curve file
1092 # assumes curve domain/range is (0 - 1)
1093 # options parameter may be a hash reference or direction flag
1094 # hash keys: 'dir', 'steps'
1095 # direction: 0 - normal, 1 - inverse
1096 # note: Photoshop curves must have between 2 and 16 steps
1097 # parameters: (file_path, [options])
1098 sub photoshop {
1099  
1100 # get parameters
1101 0 ▶ my ($self, $path, $opts) = @_;
Subroutine photoshop: not called CC=21 SCAR=61.4
Pod undocumented
1102  
1103 # local variables
1104 0 my ($dir, $steps, $xval, $n, $fh, $x, $y, $xmin, $xmax, $xp, @yx);
1105  
1106 # process options
1107 0 ($dir, $steps) = _options($opts);
1108  
1109 # if 'steps' array supplied
1110 0 ▶ if (@{$steps}) {
Branch: 3 branches
BranchTrueFalseTotal
if (@{$steps;}) { } 0 0 0
elsif (UNIVERSAL::isa($self->[1][0], 'ICC::Support::bern')) { } 0 0 0
elsif (UNIVERSAL::isa($self->[1][0], 'ICC::Support::spline')) { } 0 0 0
1111
1112 # copy step values
1113 0 $xval = [map {$_/100} @{$steps}];
1114
1115 # verify maximum number of curve points
1116 0 ▶ ($#{$xval} < 16) or croak('photoshop curve steps array has more than 16 points');
Branch: 1 branch
BranchTrueFalseTotal
$#{$xval;} < 16 or croak("photoshop curve steps array has more than 16 points") 0 0 0
1117
1118 # verify minimum number of curve points
1119 0 ▶ ($#{$xval} > 0) or croak('photoshop curve steps array has less than 2 points');
Branch: 1 branch
BranchTrueFalseTotal
$#{$xval;} > 0 or croak("photoshop curve steps array has less than 2 points") 0 0 0
1120
1121 # if 'bern' curve objects
1122 } elsif (UNIVERSAL::isa($self->[1][0], 'ICC::Support::bern')) {
1123
1124 # get maximum upper index of Bernstein coefficient arrays
1125 0 ▶ $n = ($#{$self->[1][0]->input} > $#{$self->[1][0]->output}) ? $#{$self->[1][0]->input} : $#{$self->[1][0]->output};
Branch: 1 branch
BranchTrueFalseTotal
$#{$self->[1][0]->input;} > $#{$self->[1][0]->output;} ? : 0 0 0
1126
1127 # compute upper index
1128 0 ▶ $n = 2 * $n < 16 ? 2 * $n : 15;
Branch: 1 branch
BranchTrueFalseTotal
2 * $n < 16 ? : 0 0 0
1129
1130 # make x-value array
1131 0 $xval = [map {$_/$n} (0 .. $n)];
1132
1133 # if 'spline' curve objects
1134 } elsif (UNIVERSAL::isa($self->[1][0], 'ICC::Support::spline')) {
1135
1136 # compute upper index
1137 0 ▶ $n = 2 * $#{$self->[1][0]->output} < 16 ? 2 * $#{$self->[1][0]->output} : 15;
Branch: 1 branch
BranchTrueFalseTotal
2 * $#{$self->[1][0]->output;} < 16 ? : 0 0 0
1138
1139 # make x-value array
1140 0 $xval = [map {$_/$n} (0 .. $n)];
1141
1142 } else {
1143
1144 # use default array (5 points)
1145 0 $xval = [map {$_/4} (0 .. 4)];
1146
1147 }
1148  
1149 # sort the x-values from low to high
1150 0 @{$xval} = sort {$a <=> $b} @{$xval};
1151  
1152 # filter path
1153 0 ICC::Shared::filterPath($path);
1154  
1155 # open the file
1156 0 ▶ open($fh, '>', $path) or croak("can't open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("can't open ${path}: $!") 0 0 0
1157  
1158 # set binary mode
1159 0 binmode($fh);
1160  
1161 # print the version and number of curves (including master curve)
1162 0 print $fh pack('n2', 4, scalar(@{$self->[1]}) + 1);
1163  
1164 # print null master curve
1165 0 print $fh pack('n5', 2, 0, 0, 255, 255);
1166  
1167 # for each channel
1168 0 for my $i (0 .. $#{$self->[1]}) {
1169
1170 # compute min and max x-values (correspond to y-values of 0 and 1)
1171 0 $xmin = $self->[1][$i]->_transform((1 - $dir), 0);
1172 0 $xmax = $self->[1][$i]->_transform((1 - $dir), 1);
1173
1174 # swap min and max if negative curve
1175 0 ▶ ($xmax, $xmin) = ($xmin, $xmax) if ($xmin > $xmax);
Branch: 1 branch
BranchTrueFalseTotal
if $xmin > $xmax 0 0 0
1176
1177 # initialize point array
1178 0 @yx = ();
1179
1180 # initialize previous x-value
1181 0 $xp = -1;
1182
1183 # for each point
1184 0 for my $j (0 .. $#{$xval}) {
1185
1186 # get x-value
1187 0 $x = $xval->[$j];
1188
1189 # limit x-value (previously limited domain 0 - 1)
1190 0 ▶ $x = $x > $xmax ? $xmax : ($x < $xmin ? $xmin : $x);
Branch: 2 branches
BranchTrueFalseTotal
$x > $xmax ? : 0 0 0
$x < $xmin ? : 0 0 0
1191
1192 # skip if x-value same as previous
1193 0 ▶ next if ($x == $xp);
Branch: 1 branch
BranchTrueFalseTotal
if $x == $xp 0 0 0
1194
1195 # set previous x-value
1196 0 $xp = $x;
1197
1198 # get y-value
1199 0 $y = $self->[1][$i]->_transform($dir, $x);
1200
1201 # limit y-value
1202 0 ▶ $y = $y > 1 ? 1 : ($y < 0 ? 0 : $y);
Branch: 2 branches
BranchTrueFalseTotal
$y > 1 ? : 0 0 0
$y < 0 ? : 0 0 0
1203
1204 # push y-x pair on array (Photoshop curve points are [output, input])
1205 0 push(@yx, [$y, $x]);
1206
1207 }
1208
1209 # print number of points
1210 0 print $fh pack('n', scalar(@yx));
1211
1212 # if 3 channels (RGB)
1213 0 ▶ if (@{$self->[1]} == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[1];} == 3) { } 0 0 0
1214
1215 # for each point
1216 0 for (@yx) {
1217
1218 # print point value (y, x), normal for RGB
1219 0 print $fh pack('n2', map {255 * $_ + 0.5} @{$_});
1220
1221 }
1222
1223 } else {
1224
1225 # for each point (in reverse order)
1226 0 for (reverse(@yx)) {
1227
1228 # print point value (y, x), complemented for Grayscale, CMYK, Multichannel
1229 0 print $fh pack('n2', map {255 * (1 - $_) + 0.5} @{$_});
1230
1231 }
1232
1233 }
1234
1235 }
1236  
1237 # close the file
1238 0 close($fh);
1239  
1240 # set file creator and type (OS X only)
1241 0 ICC::Shared::setFile($path, '8BIM', '8BSC');
1242  
1243 }
1244  
1245 # write Prinergy (Harmony) tone curve file
1246 # assumes curve domain/range is (0 - 1)
1247 # options parameter may be a hash reference or direction flag
1248 # hash keys: 'dir', 'Comments', 'CurveSet', 'DefaultFrequency', 'DefaultMedium',
1249 # 'DefaultResolution', 'DefaultSpotFunction', 'Enabled', 'FirstName', 'FreqFrom',
1250 # 'FreqTo', 'FrequencyUsed', 'ID', 'Medium', 'MediumUsed', 'Resolution',
1251 # 'ResolutionUsed', 'ScreeningType', 'ScreeningTypeUsed', 'SpotFunction',
1252 # 'SpotFunctionMode', 'SpotFunctionUsed'
1253 # direction: 0 - normal, 1 - inverse
1254 # parameters: (file_path, [options])
1255 sub prinergy {
1256  
1257 # get parameters
1258 0 ▶ my ($self, $path, $opts) = @_;
Subroutine prinergy: not called CC=7 SCAR=40.3
Pod undocumented
1259  
1260 # local variables
1261 0 my ($dir, $steps, $prinergy, $key);
1262 0 my ($fh, @time, $time, @month, $datetime);
1263 0 my ($rs, @colors, @map);
1264  
1265 # process options
1266 0 ($dir, $steps) = _options($opts);
1267  
1268 # read prinergy hash template
1269 0 $prinergy = YAML::Tiny->read(ICC::Shared::getICCPath('Preferences/Prinergy.yml'))->[0];
1270  
1271 # for each hash key
1272 0 for my $key (keys(%{$prinergy})) {
1273
1274 # set to options value, if defined
1275 0 ▶ $prinergy->{$key} = $opts->{$key} if (defined($opts->{$key}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->{$key} 0 0 0
1276
1277 # set undefined values to null string
1278 0 ▶ $prinergy->{$key} = '' if (! defined($prinergy->{$key}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prinergy->{$key} 0 0 0
1279
1280 }
1281  
1282 # filter path
1283 0 ICC::Shared::filterPath($path);
1284  
1285 # open the file
1286 0 ▶ open($fh, '>', $path) or croak("can't open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("can't open ${path}: $!") 0 0 0
1287  
1288 # disable :crlf translation
1289 0 binmode($fh);
1290  
1291 # set file creator and type (Windows NT SFM values)
1292 0 ICC::Shared::setFile($path, 'LMAN', 'TEXT');
1293  
1294 # get the time
1295 0 @time = localtime(time);
1296  
1297 # print time as string
1298 0 $time = sprintf "%d/%d/%d %2.2d:%2.2d:%2.2d", $time[4]+1, $time[3], $time[5]+1900, $time[2], $time[1], $time[0];
1299  
1300 # make array of months
1301 0 @month = qw(January February March April May June July August September October November December);
1302  
1303 # print datetime as string
1304 0 $datetime = sprintf "%2.2d %s %d %2.2d:%2.2d:%2.2d", $time[3], $month[$time[4]], $time[5]+1900, $time[2], $time[1], $time[0];
1305  
1306 # set output record separator (Windows CR-LF)
1307 0 $rs = "\015\012";
1308  
1309 # print Prinergy header
1310 0 print $fh ";Creo Harmony Database File$rs";
1311 0 print $fh ";1.07$rs";
1312 0 print $fh ";$time$rs";
1313 0 print $fh ";Next Calibration ID = 0001$rs$rs";
1314  
1315 # print 'transfer' table info
1316 printf $fh "[ E %s, %s %s %s %s %s ]$rs", $prinergy->{'FirstName'}, $prinergy->{'DefaultMedium'}, 'CMYK',
1317 0 $prinergy->{'DefaultSpotFunction'}, $prinergy->{'DefaultFrequency'}, $prinergy->{'DefaultResolution'};
1318 0 print $fh "FirstName = $prinergy->{'FirstName'}$rs";
1319 0 print $fh "ID = $prinergy->{'ID'}$rs";
1320 0 print $fh "Enabled = $prinergy->{'Enabled'}$rs";
1321 0 print $fh "CurveSet = $prinergy->{'CurveSet'}$rs";
1322 0 print $fh "DateTime = $datetime$rs";
1323 0 printf $fh "Time = %d$rs", time;
1324 0 print $fh "MediumUsed = $prinergy->{'MediumUsed'}$rs";
1325 0 print $fh "Medium = $prinergy->{'Medium'}$rs";
1326 0 print $fh "ScreeningTypeUsed = $prinergy->{'ScreeningTypeUsed'}$rs";
1327 0 print $fh "ScreeningType = $prinergy->{'ScreeningType'}$rs";
1328 0 print $fh "ResolutionUsed = $prinergy->{'ResolutionUsed'}$rs";
1329 0 print $fh "Resolution = $prinergy->{'Resolution'}$rs";
1330 0 print $fh "FrequencyUsed = $prinergy->{'FrequencyUsed'}$rs";
1331 0 print $fh "FreqFrom = $prinergy->{'FreqFrom'}$rs";
1332 0 print $fh "FreqTo = $prinergy->{'FreqTo'}$rs";
1333 0 print $fh "SpotFunctionUsed = $prinergy->{'SpotFunctionUsed'}$rs";
1334 0 print $fh "SpotFunction = $prinergy->{'SpotFunction'}$rs";
1335 0 print $fh "SpotFunctionMode = $prinergy->{'SpotFunctionMode'}$rs";
1336 0 print $fh "DefaultMedium = $prinergy->{'DefaultMedium'}$rs";
1337 0 print $fh "DefaultResolution = $prinergy->{'DefaultResolution'}$rs";
1338 0 print $fh "DefaultFrequency = $prinergy->{'DefaultFrequency'}$rs";
1339 0 print $fh "DefaultSpotFunction = $prinergy->{'DefaultSpotFunction'}$rs";
1340  
1341 # set color names
1342 0 @colors = qw(Cyan Magenta Yellow Black);
1343  
1344 # set color map (KCMY)
1345 0 @map = (3, 0, 1, 2);
1346  
1347 # for each curve
1348 0 for my $i (0 .. 3) {
1349  
1350 # print curve dropoff
1351 0 printf $fh "Curve%d DropOff = %d$rs", $i + 1, 0;
1352  
1353 # print curve color
1354 0 printf $fh "Curve%d Color = %s$rs", $i + 1, $colors[$map[$i]];
1355  
1356 # print curve start
1357 0 printf $fh "Curve%d = ", $i + 1;
1358  
1359 # print curve points
1360 0 for my $t (@{$steps}) {
1361
1362 # print curve values
1363 0 printf $fh "%d %d ", 1E7 * $t/100 + 0.5, 1E7 * $self->[1][$map[$i]]->_transform($dir, $t/100) + 0.5;
1364
1365 }
1366  
1367 # print curve end
1368 0 print $fh "$rs";
1369  
1370 }
1371  
1372 # print trailing comments
1373 0 print $fh "Comments = $prinergy->{'Comments'}$rs";
1374 0 print $fh "$rs";
1375  
1376 # close the file
1377 0 close($fh);
1378  
1379 }
1380  
1381 # write Rampage tone curve file set
1382 # assumes curve domain/range is (0 - 1)
1383 # options parameter may be a hash reference or direction flag
1384 # hash key: 'dir'
1385 # direction: 0 - normal, 1 - inverse
1386 # parameters: (folder_path, [options])
1387 sub rampage {
1388  
1389 # get parameters
1390 0 ▶ my ($self, $path, $opts) = @_;
Subroutine rampage: not called CC=9 SCAR=45.0
Pod undocumented
1391  
1392 # local variables
1393 0 my ($dir, $steps, $name, $rs, $fh0, $fh1, $file);
1394 0 my (@CMYK, $dotr, $dotp);
1395  
1396 # process options
1397 0 ($dir, $steps) = _options($opts);
1398  
1399 # filter path
1400 0 ICC::Shared::filterPath($path);
1401  
1402 # make the folder, if needed
1403 0 File::Path::make_path($path);
1404  
1405 # get the folder name
1406 0 $name = (File::Spec->splitdir($path))[-1];
1407  
1408 # set output record separator (Windows CR-LF)
1409 0 $rs = "\015\012";
1410  
1411 # ink color array (for building file names)
1412 0 @CMYK = qw(C M Y K);
1413  
1414 # for each color
1415 0 for my $i (0 .. 3) {
1416
1417 # build the DESIRED file path
1418 0 $file = $path . '/' . $name . '_DESIRED_' . $CMYK[$i];
1419
1420 # create the DESIRED file
1421 0 ▶ open($fh0, '>', $file) or croak("can't open $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh0, ">", $file or croak("can't open ${file}: $!") 0 0 0
1422
1423 # disable :crlf translation
1424 0 binmode($fh0);
1425  
1426 # set file creator and type
1427 0 ICC::Shared::setFile($file, 'RamC', 'Clst');
1428
1429 # build the ACT file path
1430 0 $file = $path . '/' . $name . '_ACT_' . $CMYK[$i];
1431
1432 # create the ACT file
1433 0 ▶ open($fh1, '>', $file) or croak("can't open $file: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh1, ">", $file or croak("can't open ${file}: $!") 0 0 0
1434
1435 # disable :crlf translation
1436 0 binmode($fh1);
1437  
1438 # set file creator and type
1439 0 ICC::Shared::setFile($file, 'RamC', 'Clst');
1440
1441 # print DESIRED header
1442 0 print $fh0 "2$rs";
1443 0 print $fh0 "0.0000000000$rs";
1444 0 print $fh0 "0.0000000000$rs";
1445 0 printf $fh0 "%2d$rs", $steps + 1;
1446
1447 # print ACT header
1448 0 print $fh1 "2$rs";
1449 0 print $fh1 "0.0000000000$rs";
1450 0 print $fh1 "0.0000000000$rs";
1451 0 printf $fh1 "%2d$rs", $steps + 1;
1452
1453 # for each step
1454 0 for my $j (0 .. $#{$steps}) {
1455
1456 # get reference %-dot
1457 0 $dotr = $steps->[$j];
1458
1459 # get press %-dot
1460 0 $dotp = 100 * $self->[1][$i]->_transform($dir, $dotr/100);
1461
1462 # limit %-dot (0 - 100)
1463 0 ▶ $dotr = ($dotr < 0) ? 0 : $dotr;
Branch: 1 branch
BranchTrueFalseTotal
$dotr < 0 ? : 0 0 0
1464 0 ▶ $dotp = ($dotp < 0) ? 0 : $dotp;
Branch: 1 branch
BranchTrueFalseTotal
$dotp < 0 ? : 0 0 0
1465 0 ▶ $dotr = ($dotr > 100) ? 100 : $dotr;
Branch: 1 branch
BranchTrueFalseTotal
$dotr > 100 ? : 0 0 0
1466 0 ▶ $dotp = ($dotp > 100) ? 100 : $dotp;
Branch: 1 branch
BranchTrueFalseTotal
$dotp > 100 ? : 0 0 0
1467
1468 # print DESIRED step info
1469 0 printf $fh0 "%3.1f %3.1f$rs", $dotr, $dotp;
1470
1471 # print ACT step info
1472 0 printf $fh1 "%3.1f %3.1f$rs", $dotr, $dotr;
1473
1474 }
1475
1476 # print DESIRED footer
1477 0 print $fh0 "Version: 2.0$rs";
1478
1479 # print ACT footer
1480 0 print $fh1 "Version: 2.0$rs";
1481
1482 # close the DESIRED file
1483 0 close($fh0);
1484
1485 # close the ACT file
1486 0 close($fh1);
1487
1488 }
1489
1490 }
1491  
1492 # write Trueflow tone curve file
1493 # assumes curve domain/range is (0 - 1)
1494 # options parameter may be a hash reference or direction flag
1495 # hash key: 'dir'
1496 # direction: 0 - normal, 1 - inverse
1497 # parameters: (file_path, [options])
1498 sub trueflow {
1499  
1500 # get parameters
1501 0 ▶ my ($self, $path, $opts) = @_;
Subroutine trueflow: not called CC=7 SCAR=40.3
Pod undocumented
1502  
1503 # local variables
1504 0 my ($dir, $steps, @names, @colors, @map);
1505 0 my ($fh, $in, $out, $dg, @lut, $float);
1506  
1507 # process options
1508 0 ($dir, $steps) = _options($opts);
1509  
1510 # set curve names
1511 0 @names = qw(Y M C K);
1512  
1513 # set curve display colors (YMCK)
1514 0 @colors = (0x00ffff, 0xff00ff, 0xffff00, 0x000000);
1515  
1516 # set color map (YMCK)
1517 0 @map = (2, 1, 0, 3);
1518  
1519 # filter path
1520 0 ICC::Shared::filterPath($path);
1521  
1522 # open the file
1523 0 ▶ open($fh, '>', $path) or croak("can't open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("can't open ${path}: $!") 0 0 0
1524  
1525 # set binary mode
1526 0 binmode($fh);
1527  
1528 # print the header
1529 0 print $fh pack('C4a4', 4, 3, 2, 1, 'DGT'); # file signature
1530 0 print $fh pack('V', 256); # offset to first curve
1531 0 print $fh pack('V', 100); #
1532 0 print $fh pack('V', 4); # number of curves
1533 0 print $fh pack('V4', 640, 640, 640, 640); # curve block sizes
1534  
1535 # seek start of first curve
1536 0 seek($fh, 256, 0);
1537  
1538 # loop thru colors (0-3) (YMCK)
1539 0 for my $i (0 .. 3) {
1540
1541 # print curve name
1542 0 print $fh pack('a128', $names[$i]);
1543
1544 # print display color
1545 0 print $fh pack('V', $colors[$i]);
1546
1547 # print curve parameters (LUT_size, dot_gain_steps, dot_gain_table_size)
1548 0 print $fh pack('V3', 256, 15, 240);
1549
1550 # print binary LUT
1551 #
1552 # for each step
1553 0 for my $j (0 .. 255) {
1554
1555 # compute output value
1556 0 $out = $self->[1][$map[$i]]->_transform($dir, $j/255);
1557
1558 # print LUT value (limited and rounded)
1559 0 ▶ print $fh pack('C', 255 * ($out < 0 ? 0 : ($out > 1 ? 1 : $out)) + 0.5);
Branch: 2 branches
BranchTrueFalseTotal
$out < 0 ? : 0 0 0
$out > 1 ? : 0 0 0
1560
1561 }
1562
1563 # print dot gain table
1564 #
1565 # for each tone curve step
1566 0 for my $j (0 .. $#{$steps}) {
1567
1568 # compute input value
1569 0 $in = $steps->[$j]/100;
1570
1571 # compute output value
1572 0 $out = $self->[1][$map[$i]]->_transform($dir, $in);
1573
1574 # compute dot gain (rounded to 0.1%)
1575 0 $dg = POSIX::floor(1000 * ($out - $in) + 0.5)/10;
1576
1577 # print dot gain value (little-endian double)
1578 0 print $fh pack('C2 x6 d<', $steps->[$j], 1, $dg);
1579
1580 }
1581
1582 }
1583  
1584 # close the file
1585 0 close($fh);
1586  
1587 }
1588  
1589 # write Xitron Sierra tone curve file
1590 # assumes curve domain/range is (0 - 1)
1591 # options parameter may be a hash reference or direction flag
1592 # hash key: 'dir'
1593 # direction: 0 - normal, 1 - inverse
1594 # parameters: (file_path, [options])
1595 sub xitron {
1596  
1597 # get parameters
1598 0 ▶ my ($self, $path, $opts) = @_;
Subroutine xitron: not called CC=4 SCAR=30.0
Pod undocumented
1599  
1600 # local variables
1601 0 my ($dir, $steps, $fh, $rs, @colors, @Tdot);
1602  
1603 # process options
1604 0 ($dir, $steps) = _options($opts);
1605  
1606 # filter path
1607 0 ICC::Shared::filterPath($path);
1608  
1609 # open the file
1610 0 ▶ open($fh, '>', $path) or croak("can't open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("can't open ${path}: $!") 0 0 0
1611  
1612 # disable :crlf translation
1613 0 binmode($fh);
1614  
1615 # set output record separator (Windows CR-LF)
1616 0 $rs = "\015\012";
1617  
1618 # set color list
1619 0 @colors = qw(Cyan Magenta Yellow Black);
1620  
1621 # print colors
1622 0 print $fh join(';', @colors), $rs;
1623  
1624 # for each step
1625 0 for my $j (0 .. $#{$steps}) {
1626
1627 # for each channel
1628 0 for my $i (0 .. 3) {
1629
1630 # compute transformed dot value
1631 0 $Tdot[$i] = sprintf("%.4f", 100 * ($self->[1][$i]->_transform($dir, $steps->[$j]/100)));
1632
1633 }
1634
1635 # print transformed values
1636 0 print $fh join(';', @Tdot), $rs;
1637
1638 }
1639  
1640 # close the file
1641 0 close($fh);
1642  
1643 }
1644  
1645 # write tab delimited text tone curve file
1646 # assumes curve domain/range is (0 - 1)
1647 # options parameter may be a hash reference or direction flag
1648 # hash keys: 'dir', 'steps'
1649 # direction: 0 - normal, 1 - inverse
1650 # parameters: (file_path, [options])
1651 sub text {
1652  
1653 # get parameters
1654 0 ▶ my ($self, $path, $opts) = @_;
Subroutine text: not called CC=5 SCAR=34.0
Pod undocumented
1655  
1656 # local variables
1657 0 my ($dir, $steps, $fp, $fh, $rs, @Tdot);
1658  
1659 # process options
1660 0 ($dir, $steps) = _options($opts);
1661  
1662 # check for non-integer values
1663 0 $fp = grep {$_ != int($_)} @{$steps};
1664  
1665 # filter path
1666 0 ICC::Shared::filterPath($path);
1667  
1668 # open the file
1669 0 ▶ open($fh, '>', $path) or croak("can't open $path: $!");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $path or croak("can't open ${path}: $!") 0 0 0
1670  
1671 # disable :crlf translation
1672 0 binmode($fh);
1673  
1674 # set output record separator (Windows CR-LF)
1675 0 $rs = "\015\012";
1676  
1677 # for each step
1678 0 for my $t (@{$steps}) {
1679
1680 # format input value
1681 0 ▶ $Tdot[0] = $fp ? sprintf("%.2f", $t) : $t;
Branch: 1 branch
BranchTrueFalseTotal
$fp ? : 0 0 0
1682
1683 # for each channel
1684 0 for my $i (0 .. $#{$self->[1]}) {
1685
1686 # compute transformed dot value
1687 0 $Tdot[$i + 1] = sprintf("%.2f", 100 * ($self->[1][$i]->_transform($dir, $t/100)));
1688
1689 }
1690
1691 # print step values
1692 0 print $fh join("\t", @Tdot), $rs;
1693
1694 }
1695  
1696 # close the file
1697 0 close($fh);
1698  
1699 }
1700  
1701 # graph tone curves
1702 # assumes curve domain/range is (0 - 1)
1703 # options parameter may be a hash reference or direction flag
1704 # hash keys: 'dir', 'composite', 'titles', 'inks', 'files'
1705 # direction: 0 - normal, 1 - inverse
1706 # parameters: (folder_path, [options])
1707 sub graph {
1708  
1709 # get parameters
1710 0 ▶ my ($self, $path, $opts) = @_;
Subroutine graph: not called CC=32 SCAR=69.6
Pod undocumented
1711  
1712 # local variables
1713 0 my ($dir, $include, $tt, $vars, @colors, @inks, @data, $file, $s, $lib, $js0, $js1, $html);
1714  
1715 # process options
1716 0 ($dir) = _options($opts);
1717  
1718 # if ICC::Templates folder is found in @INC (may be relative)
1719 0 ▶ if (($include) = grep {-d} map {File::Spec->catdir($_, 'ICC', 'Templates')} @INC) {
Branch: 1 branch
BranchTrueFalseTotal
if (($include) = grep({-d $_;} map({"File::Spec"->catdir($_, "ICC", "Templates");} @INC))) 0 0 0
1720
1721 # purify folder path
1722 0 ICC::Shared::filterPath($path);
1723
1724 # make a template processing object
1725 0 $tt = Template->new({
1726 'INCLUDE_PATH' => $include,
1727 'OUTPUT_PATH' => $path,
1728 });
1729
1730 # if gray scale curve
1731 0 ▶ if ($#{$self->[1]} == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($#{$$self[1];} == 0) { } 0 0 0
elsif ($#{$$self[1];} == 1) { } 0 0 0
elsif ($#{$$self[1];} == 2) { } 0 0 0
1732
1733 # set colors
1734 0 @colors = qw(black);
1735 0 @inks = qw(grayscale);
1736
1737 # if duotone curve
1738 0 } elsif ($#{$self->[1]} == 1) {
1739
1740 # set colors (like Excel)
1741 0 @colors = qw(cyan red);
1742
1743 # if RGB curves
1744 0 } elsif ($#{$self->[1]} == 2) {
1745
1746 # set colors
1747 0 @colors = @inks = qw(red green blue);
1748
1749 # if CMYK+ curves
1750 } else {
1751
1752 # set colors
1753 0 @colors = qw(cyan magenta yellow black orange green blue);
1754 0 $colors[2] = '#cc0'; # dark yellow
1755 0 $colors[4] = '#f80'; # orange
1756 0 @inks = qw(cyan magenta yellow black);
1757
1758 }
1759
1760 # for each curve
1761 0 for my $i (0 .. $#{$self->[1]}) {
1762
1763 # set ink value, defaults to 'inkN'
1764 0 ▶ $inks[$i] = $opts->{'inks'}[$i] // $self->[0]{'inks'}[$i] // $inks[$i] // sprintf("ink%d", $i + 1);
Condition0%0/9
(($opts->{"inks"}[$i] // $self->[0]{"inks"}[$i]) // $inks[$i]) // sprintf("ink%d", $i + 1)
l!l&&r!l&&!r
000
($opts->{"inks"}[$i] // $self->[0]{"inks"}[$i]) // $inks[$i]
l!l&&r!l&&!r
000
$opts->{"inks"}[$i] // $self->[0]{"inks"}[$i]
l!l&&r!l&&!r
000
MC/DC0%0/4
(($opts->{"inks"}[$i] // $self->[0]{"inks"}[$i]) // $inks[$i]) // sprintf("ink%d", $i + 1)
$opts->{"inks"}[$i] $self->[0]{"inks"}[$i] $inks[$i] sprintf("ink%d", $i + 1)
Truth table0%0/5
A // B // C // D
A= $opts->{"inks"}[$i]B= $self->[0]{"inks"}[$i]C= $inks[$i]D= sprintf("ink%d", $i + 1)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1765
1766 }
1767
1768 # if 'composite' curve
1769 0 ▶ if ($opts->{'composite'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'composite'}) { } 0 0 0
1770
1771 # for each curve
1772 0 for my $i (0 .. $#{$self->[1]}) {
1773
1774 # compute curve data
1775 0 @data = map {sprintf("%.3f", $self->[1][$i]->_transform($dir, $_/100))} (0 .. 100);
1776
1777 # clip the data
1778 0 ▶ @data = map {$_ < 0.0 ? '0.000' : $_ > 1.0 ? '1.000' : $_} @data;
Branch: 2 branches
BranchTrueFalseTotal
$_ < 0.0 ? : 0 0 0
$_ > 1.0 ? : 0 0 0
1779
1780 # make javascript string of curve data
1781 0 $s->[$i] = '[' . join(', ', @data) . ']';
1782
1783 }
1784
1785 # make composite javascript string of curve data
1786 0 $vars->{'data'} = '[' . join(', ', @{$s}) . ']';
1787
1788 # set graph title
1789 0 ▶ $vars->{'title'} = $opts->{'titles'}[0] // "composite tone curves";
Condition0%0/2
$opts->{"titles"}[0] // "composite tone curves"
l!l
00
MC/DC0%0/1
$opts->{"titles"}[0] // "composite tone curves"
$opts->{"titles"}[0]
Truth table0%0/2
A
A= $opts->{"titles"}[0]
Aresult
11
00
1790
1791 # set graph colors
1792 0 $vars->{'colors'} = '[' . join(', ', map {"'$_'"} @colors) . ']';
1793
1794 # get file name
1795 0 ▶ $file = $opts->{'files'}[0] // 'composite';
Condition0%0/2
$opts->{"files"}[0] // "composite"
l!l
00
MC/DC0%0/1
$opts->{"files"}[0] // "composite"
$opts->{"files"}[0]
Truth table0%0/2
A
A= $opts->{"files"}[0]
Aresult
11
00
1796
1797 # process the template
1798 0 ▶ $tt->process('cvst_graph_svg.tt2', $vars, "$file.html") || CORE::die $tt->error();
Branch: 1 branch
BranchTrueFalseTotal
$tt->process("cvst_graph_svg.tt2", $vars, "$file.html") or die $tt->error 0 0 0
1799
1800 } else {
1801
1802 # for each curve
1803 0 for my $i (0 .. $#{$self->[1]}) {
1804
1805 # compute curve data
1806 0 @data = map {sprintf("%.3f", $self->[1][$i]->_transform($dir, $_/100))} (0 .. 100);
1807
1808 # clip the data
1809 0 ▶ @data = map {$_ < 0.0 ? '0.000' : $_ > 1.0 ? '1.000' : $_} @data;
Branch: 2 branches
BranchTrueFalseTotal
$_ < 0.0 ? : 0 0 0
$_ > 1.0 ? : 0 0 0
1810
1811 # make javascript string of curve data
1812 0 $vars->{'data'} = '[[' . join(', ', @data) . ']]';
1813
1814 # set graph title
1815 0 ▶ $vars->{'title'} = $opts->{'titles'}[$i] // "$inks[$i] tone curve";
Condition0%0/2
$opts->{"titles"}[$i] // "$inks[$i] tone curve"
l!l
00
MC/DC0%0/1
$opts->{"titles"}[$i] // "$inks[$i] tone curve"
$opts->{"titles"}[$i]
Truth table0%0/2
A
A= $opts->{"titles"}[$i]
Aresult
11
00
1816
1817 # set graph color
1818 0 $vars->{'colors'} = "['$colors[$i]']";
1819
1820 # get file name
1821 0 ▶ $file = $opts->{'files'}[$i] // $inks[$i];
Condition0%0/3
$opts->{"files"}[$i] // $inks[$i]
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"files"}[$i] // $inks[$i]
$opts->{"files"}[$i] $inks[$i]
Truth table0%0/3
A // B
A= $opts->{"files"}[$i]B= $inks[$i]
ABresult
1X1
011
000
1822
1823 # process the template
1824 0 ▶ $tt->process('cvst_graph_svg.tt2', $vars, "$file.html") || CORE::die $tt->error();
Branch: 1 branch
BranchTrueFalseTotal
$tt->process("cvst_graph_svg.tt2", $vars, "$file.html") or die $tt->error 0 0 0
1825
1826 }
1827
1828 }
1829
1830 # make path to 'lib' folder
1831 0 ▶ $lib = $path . ($^O eq 'MSWin32' ? '\lib' : '/lib');
Branch: 1 branch
BranchTrueFalseTotal
$^O eq 'MSWin32' ? : 0 0 0
1832
1833 # make 'lib' folder, if none
1834 0 File::Path::make_path($lib);
1835
1836 # match 'ICC' folder path
1837 0 $include =~ m/^(.*)Templates$/;
1838
1839 # if Windows OS
1840 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
1841
1842 # make Rgraph Javascript paths
1843 0 $js0 = '\Javascripts\rgraph\RGraph.svg.common.core.js';
1844 0 $js1 = '\Javascripts\rgraph\RGraph.svg.line.js';
1845
1846 # copy Rgraph Javascripts to 'lib' folder
1847 0 ▶ qx(copy "$1$js0" $lib) if (! -f "$lib$js0");
Branch: 1 branch
BranchTrueFalseTotal
unless -f "$lib$js0" 0 0 0
1848 0 ▶ qx(copy "$1$js1" $lib) if (! -f "$lib$js1");
Branch: 1 branch
BranchTrueFalseTotal
unless -f "$lib$js1" 0 0 0
1849
1850 } else {
1851
1852 # copy Rgraph Javascripts to 'lib' folder (Unix)
1853 0 qx(cp -n "$1/Javascripts/rgraph/RGraph.svg.common.core.js" $lib);
1854 0 qx(cp -n "$1/Javascripts/rgraph/RGraph.svg.line.js" $lib);
1855
1856 }
1857
1858 # if 'composite' curve
1859 0 ▶ if ($opts->{'composite'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'composite'}) { } 0 0 0
1860
1861 # if Windows OS
1862 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
1863
1864 # make html path
1865 0 $html = "$path\\$file.html";
1866
1867 # open graph file in browser
1868 0 qx(start $html);
1869
1870 } else {
1871
1872 # open graph file in browser
1873 0 qx(open "$path/$file.html");
1874
1875 }
1876
1877 } else {
1878
1879 # for each curve
1880 0 for my $i (0 .. $#{$self->[1]}) {
1881
1882 # get file name
1883 0 ▶ $file = $opts->{'files'}[$i] // $inks[$i];
Condition0%0/3
$opts->{"files"}[$i] // $inks[$i]
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->{"files"}[$i] // $inks[$i]
$opts->{"files"}[$i] $inks[$i]
Truth table0%0/3
A // B
A= $opts->{"files"}[$i]B= $inks[$i]
ABresult
1X1
011
000
1884
1885 # if Windows OS
1886 0 ▶ if ($^O eq 'MSWin32') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 0 0
1887
1888 # make html path
1889 0 $html = "$path\\$file.html";
1890
1891 # open graph file in browser
1892 0 qx(start $html);
1893
1894 } else {
1895
1896 # open graph file in browser
1897 0 qx(open "$path/$file.html");
1898
1899 }
1900
1901 # pause for first file (Firefox)
1902 0 ▶ sleep(1) if ($i == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $i == 0 0 0 0
1903
1904 }
1905
1906 }
1907
1908 }
1909
1910 }
1911  
1912 # normalize all curve objects
1913 # sets the domain and range of curves
1914 # parameters: (as_appropriate_for_curve_objects)
1915 sub normalize {
1916  
1917 # get object reference
1918 0 ▶ my $self = shift();
Subroutine normalize: not called CC=3 SCAR=24.8
Pod undocumented
1919  
1920 # for each channel
1921 0 for my $i (0 .. $#{$self->[1]}) {
1922
1923 # if curve object has 'normalize' method
1924 0 ▶ if ($self->[1][$i]->can('normalize')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1][$i]->can('normalize')) { } 0 0 0
1925
1926 # call 'normalize' method
1927 0 $self->[1][$i]->normalize(@_);
1928
1929 } else {
1930
1931 # warning
1932 0 carp('\'normalize\' method not supported by ' . ref($self->[1][$i]) . ' object');
1933
1934 }
1935
1936 }
1937
1938 }
1939  
1940 # update all curve objects
1941 # update internal object elements
1942 # this method used primarily when optimizing
1943 # parameters: (as_appropriate_for_curve_objects)
1944 sub update {
1945  
1946 # get object reference
1947 0 ▶ my $self = shift();
Subroutine update: not called CC=3 SCAR=24.8
Pod undocumented
1948  
1949 # for each channel
1950 0 for my $i (0 .. $#{$self->[1]}) {
1951
1952 # if curve object has 'update' method
1953 0 ▶ if ($self->[1][$i]->can('update')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1][$i]->can('update')) { } 0 0 0
1954
1955 # call 'update' method
1956 0 $self->[1][$i]->update(@_);
1957
1958 } else {
1959
1960 # warning
1961 0 carp('\'update\' method not supported by ' . ref($self->[1][$i]) . ' object');
1962
1963 }
1964
1965 }
1966
1967 }
1968  
1969 # print object contents to string
1970 # format is an array structure
1971 # parameter: ([format])
1972 # returns: (string)
1973 sub sdump {
1974  
1975 # get parameters
1976 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=11 SCAR=48.8
Pod documented
1977  
1978 # local variables
1979 0 my ($element, $fmt, $s, $pt, $st);
1980  
1981 # resolve parameter to an array reference
1982 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
1983  
1984 # get format string
1985 0 ▶ $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 's';
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
1986  
1987 # set string to object ID
1988 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
1989  
1990 # if format contains 'o'
1991 0 ▶ if ($fmt =~ m/s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /s/) 0 0 0
1992
1993 # get default parameter
1994 0 $pt = $p->[-1];
1995
1996 # for each processing element
1997 0 for my $i (0 .. $#{$self->[1]}) {
1998
1999 # get element reference
2000 0 $element = $self->[1][$i];
2001
2002 # if processing element is undefined
2003 0 ▶ if (! defined($element)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $element) { } 0 0 0
elsif (not builtin::blessed($element)) { } 0 0 0
elsif ($element->can('sdump')) { } 0 0 0
2004
2005 # append message
2006 0 $s .= "\tprocessing element is undefined\n";
2007
2008 # if processing element is not a blessed object
2009 } elsif (! Scalar::Util::blessed($element)) {
2010
2011 # append message
2012 0 $s .= "\tprocessing element is not a blessed object\n";
2013
2014 # if processing element has an 'sdump' method
2015 } elsif ($element->can('sdump')) {
2016
2017 # get 'sdump' string
2018 0 ▶ $st = $element->sdump(defined($p->[$i + 1]) ? $p->[$i + 1] : $pt);
Branch: 1 branch
BranchTrueFalseTotal
defined $$p[$i + 1] ? : 0 0 0
2019
2020 # prepend tabs to each line
2021 0 $st =~ s/^/\t/mg;
2022
2023 # append 'sdump' string
2024 0 $s .= $st;
2025
2026 # processing element is object without an 'sdump' method
2027 } else {
2028
2029 # append object info
2030 0 $s .= sprintf("\t'%s' object, (0x%x)\n", ref($element), $element);
2031
2032 }
2033
2034 }
2035
2036 }
2037  
2038 # return
2039 0 return($s);
2040  
2041 }
2042  
2043 # transform list
2044 # parameters: (ref_to_object, list, [hash])
2045 # returns: (list)
2046 sub _trans0 {
2047  
2048 # local variables
2049 0 ▶ my ($self, @out, $hash);
Subroutine _trans0: not called CC=5 SCAR=34.0
2050  
2051 # get object reference
2052 0 $self = shift();
2053  
2054 # get optional hash
2055 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
2056  
2057 # for each channel
2058 0 for my $i (0 .. $#{$self->[1]}) {
2059
2060 # compute transform
2061 0 $out[$i] = $self->[1][$i]->transform($_[$i]);
2062
2063 }
2064  
2065 # clip, if enabled
2066 0 ▶ ICC::Shared::clip_struct(\@out) if ($self->[0]{'clip'} || $hash->{'clip'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0]{"clip"} or $hash->{"clip"} 0 0 0
Condition0%0/3
$self->[0]{"clip"} or $hash->{"clip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"clip"} or $hash->{"clip"}
$self->[0]{"clip"} $hash->{"clip"}
Truth table0%0/3
A or B
A= $self->[0]{"clip"}B= $hash->{"clip"}
ABresult
1X1
011
000
2067  
2068 # return output array
2069 0 return(@out);
2070  
2071 }
2072  
2073 # transform vector
2074 # parameters: (ref_to_object, vector, [hash])
2075 # returns: (vector)
2076 sub _trans1 {
2077  
2078 # get parameters
2079 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans1: not called CC=4 SCAR=30.0
2080  
2081 # local variable
2082 0 my ($out);
2083  
2084 # for each channel
2085 0 for my $i (0 .. $#{$self->[1]}) {
2086
2087 # compute transform
2088 0 $out->[$i] = $self->[1][$i]->transform($in->[$i]);
2089
2090 }
2091  
2092 # clip, if enabled
2093 0 ▶ ICC::Shared::clip_struct($out) if ($self->[0]{'clip'} || $hash->{'clip'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0]{"clip"} or $hash->{"clip"} 0 0 0
Condition0%0/3
$self->[0]{"clip"} or $hash->{"clip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"clip"} or $hash->{"clip"}
$self->[0]{"clip"} $hash->{"clip"}
Truth table0%0/3
A or B
A= $self->[0]{"clip"}B= $hash->{"clip"}
ABresult
1X1
011
000
2094  
2095 # return
2096 0 return($out);
2097  
2098 }
2099  
2100 # transform matrix (2-D array -or- Math::Matrix object)
2101 # parameters: (ref_to_object, matrix, [hash])
2102 # returns: (matrix)
2103 sub _trans2 {
2104  
2105 # get parameters
2106 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans2: not called CC=6 SCAR=37.4
2107  
2108 # local variable
2109 0 my ($out);
2110  
2111 # for each input vector
2112 0 for my $i (0 .. $#{$in}) {
2113
2114 # for each channel
2115 0 for my $j (0 .. $#{$self->[1]}) {
2116
2117 # compute transform
2118 0 $out->[$i][$j] = $self->[1][$j]->transform($in->[$i][$j]);
2119
2120 }
2121
2122 }
2123  
2124 # clip, if enabled
2125 0 ▶ ICC::Shared::clip_struct($out) if ($self->[0]{'clip'} || $hash->{'clip'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0]{"clip"} or $hash->{"clip"} 0 0 0
Condition0%0/3
$self->[0]{"clip"} or $hash->{"clip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"clip"} or $hash->{"clip"}
$self->[0]{"clip"} $hash->{"clip"}
Truth table0%0/3
A or B
A= $self->[0]{"clip"}B= $hash->{"clip"}
ABresult
1X1
011
000
2126  
2127 # return
2128 0 ▶ return(UNIVERSAL::isa($in, 'Math::Matrix') ? bless($out, 'Math::Matrix') : $out);
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($in, 'Math::Matrix') ? : 0 0 0
2129  
2130 }
2131  
2132 # transform structure
2133 # parameters: (ref_to_object, structure, [hash])
2134 # returns: (structure)
2135 sub _trans3 {
2136  
2137 # get parameters
2138 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans3: not called CC=3 SCAR=24.8
2139  
2140 # transform the array structure
2141 0 _crawl($self, $in, my $out = [], $hash);
2142  
2143 # clip, if enabled
2144 0 ▶ ICC::Shared::clip_struct($out) if ($self->[0]{'clip'} || $hash->{'clip'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0]{"clip"} or $hash->{"clip"} 0 0 0
Condition0%0/3
$self->[0]{"clip"} or $hash->{"clip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"clip"} or $hash->{"clip"}
$self->[0]{"clip"} $hash->{"clip"}
Truth table0%0/3
A or B
A= $self->[0]{"clip"}B= $hash->{"clip"}
ABresult
1X1
011
000
2145  
2146 # return
2147 0 return($out);
2148  
2149 }
2150  
2151 # recursive transform
2152 # array structure is traversed until scalar arrays are found and transformed
2153 # parameters: (ref_to_object, input_array_reference, output_array_reference, hash)
2154 sub _crawl {
2155  
2156 # get parameters
2157 0 ▶ my ($self, $in, $out, $hash) = @_;
Subroutine _crawl: not called CC=4 SCAR=30.0
2158  
2159 # if input is a vector (reference to a scalar array)
2160 0 ▶ if (@{$in} == grep {! ref()} @{$in}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$in;} == grep({not ref $_;} @{$in;})) { } 0 0 0
2161
2162 # transform input vector and copy to output
2163 0 @{$out} = @{_trans1($self, $in, $hash)};
2164
2165 } else {
2166
2167 # for each input element
2168 0 for my $i (0 .. $#{$in}) {
2169
2170 # if an array reference
2171 0 ▶ if (ref($in->[$i]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in->[$i] eq 'ARRAY') { } 0 0 0
2172
2173 # transform next level
2174 0 _crawl($self, $in->[$i], $out->[$i] = [], $hash);
2175
2176 } else {
2177
2178 # error
2179 0 croak('invalid transform input');
2180
2181 }
2182
2183 }
2184
2185 }
2186
2187 }
2188  
2189 # invert list
2190 # parameters: (ref_to_object, list, [hash])
2191 # returns: (list)
2192 sub _inv0 {
2193  
2194 # local variables
2195 0 ▶ my ($self, $hash, @out);
Subroutine _inv0: not called CC=5 SCAR=34.0
2196  
2197 # get object reference
2198 0 $self = shift();
2199  
2200 # get optional hash
2201 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
2202  
2203 # for each channel
2204 0 for my $i (0 .. $#{$self->[1]}) {
2205
2206 # compute invert
2207 0 $out[$i] = $self->[1][$i]->inverse($_[$i]);
2208
2209 }
2210  
2211 # clip, if enabled
2212 0 ▶ ICC::Shared::clip_struct(\@out) if ($self->[0]{'clip'} || $hash->{'clip'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0]{"clip"} or $hash->{"clip"} 0 0 0
Condition0%0/3
$self->[0]{"clip"} or $hash->{"clip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"clip"} or $hash->{"clip"}
$self->[0]{"clip"} $hash->{"clip"}
Truth table0%0/3
A or B
A= $self->[0]{"clip"}B= $hash->{"clip"}
ABresult
1X1
011
000
2213  
2214 # return output array
2215 0 return(@out);
2216  
2217 }
2218  
2219 # invert vector
2220 # parameters: (ref_to_object, vector, [hash])
2221 # returns: (vector)
2222 sub _inv1 {
2223  
2224 # get parameters
2225 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _inv1: not called CC=4 SCAR=30.0
2226  
2227 # local variable
2228 0 my ($out);
2229  
2230 # for each channel
2231 0 for my $i (0 .. $#{$self->[1]}) {
2232
2233 # compute invert
2234 0 $out->[$i] = $self->[1][$i]->inverse($in->[$i]);
2235
2236 }
2237  
2238 # clip, if enabled
2239 0 ▶ ICC::Shared::clip_struct($out) if ($self->[0]{'clip'} || $hash->{'clip'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0]{"clip"} or $hash->{"clip"} 0 0 0
Condition0%0/3
$self->[0]{"clip"} or $hash->{"clip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"clip"} or $hash->{"clip"}
$self->[0]{"clip"} $hash->{"clip"}
Truth table0%0/3
A or B
A= $self->[0]{"clip"}B= $hash->{"clip"}
ABresult
1X1
011
000
2240  
2241 # return
2242 0 return($out);
2243  
2244 }
2245  
2246 # invert matrix (2-D array -or- Math::Matrix object)
2247 # parameters: (ref_to_object, matrix, [hash])
2248 # returns: (matrix)
2249 sub _inv2 {
2250  
2251 # get parameters
2252 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _inv2: not called CC=6 SCAR=37.4
2253  
2254 # local variable
2255 0 my ($out);
2256  
2257 # for each input vector
2258 0 for my $i (0 .. $#{$in}) {
2259
2260 # for each channel
2261 0 for my $j (0 .. $#{$self->[1]}) {
2262
2263 # compute invert
2264 0 $out->[$i][$j] = $self->[1][$j]->inverse($in->[$i][$j]);
2265
2266 }
2267
2268 }
2269  
2270 # clip, if enabled
2271 0 ▶ ICC::Shared::clip_struct($out) if ($self->[0]{'clip'} || $hash->{'clip'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0]{"clip"} or $hash->{"clip"} 0 0 0
Condition0%0/3
$self->[0]{"clip"} or $hash->{"clip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"clip"} or $hash->{"clip"}
$self->[0]{"clip"} $hash->{"clip"}
Truth table0%0/3
A or B
A= $self->[0]{"clip"}B= $hash->{"clip"}
ABresult
1X1
011
000
2272  
2273 # return
2274 0 ▶ return(UNIVERSAL::isa($in, 'Math::Matrix') ? bless($out, 'Math::Matrix') : $out);
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($in, 'Math::Matrix') ? : 0 0 0
2275  
2276 }
2277  
2278 # invert structure
2279 # parameters: (ref_to_object, structure, [hash])
2280 # returns: (structure)
2281 sub _inv3 {
2282  
2283 # get parameters
2284 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _inv3: not called CC=3 SCAR=24.8
2285  
2286 # recursive inverse
2287 0 _crawl2($self, $in, my $out = []);
2288  
2289 # clip, if enabled
2290 0 ▶ ICC::Shared::clip_struct($out) if ($self->[0]{'clip'} || $hash->{'clip'});
Branch: 1 branch
BranchTrueFalseTotal
if $self->[0]{"clip"} or $hash->{"clip"} 0 0 0
Condition0%0/3
$self->[0]{"clip"} or $hash->{"clip"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"clip"} or $hash->{"clip"}
$self->[0]{"clip"} $hash->{"clip"}
Truth table0%0/3
A or B
A= $self->[0]{"clip"}B= $hash->{"clip"}
ABresult
1X1
011
000
2291  
2292 # return
2293 0 return($out);
2294  
2295 }
2296  
2297 # recursive inverse
2298 # array structure is traversed until scalar arrays are found and inverted
2299 # parameters: (ref_to_object, input_array_reference, output_array_reference, hash)
2300 sub _crawl2 {
2301
2302 # get parameters
2303 0 ▶ my ($self, $in, $out, $hash) = @_;
Subroutine _crawl2: not called CC=4 SCAR=30.0
2304
2305 # if input is a vector (reference to a scalar array)
2306 0 ▶ if (@{$in} == grep {! ref()} @{$in}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$in;} == grep({not ref $_;} @{$in;})) { } 0 0 0
2307
2308 # invert input vector and copy to output
2309 0 @{$out} = @{_inv1($self, $in, $hash)};
2310
2311 } else {
2312
2313 # for each input element
2314 0 for my $i (0 .. $#{$in}) {
2315
2316 # if an array reference
2317 0 ▶ if (ref($in->[$i]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in->[$i] eq 'ARRAY') { } 0 0 0
2318
2319 # invert next level
2320 0 _crawl2($self, $in->[$i], $out->[$i] = []);
2321
2322 } else {
2323
2324 # error
2325 0 croak('invalid inverse input');
2326
2327 }
2328
2329 }
2330
2331 }
2332
2333 }
2334  
2335 # process the curve output options parameter
2336 # the parameter may be a scalar or hash reference
2337 # output is based on the name of the calling method
2338 # parameter: ([options])
2339 # returns: (direction_flag, steps)
2340 sub _options {
2341  
2342 # get options
2343 0 ▶ my $opts = $_[0];
Subroutine _options: not called CC=19 SCAR=59.4
2344  
2345 # local variable
2346 0 my ($dir, $steps, @ctx, $caller, $n);
2347  
2348 # make hash of standard step ramps (method_name => [ref_to_steps_array, custom_flag])
2349 # steps array contains device values, flag indicate values may be custom
2350 state $std = {
2351 0 'apogee' => [[0 .. 6, (map {5 * $_} 2 .. 18), 94 .. 100], 1],
2352 'device_link' => [[], 0],
2353 0 'efi' => [[0 .. 3, map {5 * $_} 1 .. 20], 0],
2354 'fuji_xmf' => [[0 .. 5, 10, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 95 .. 100], 0],
2355 'harlequin' => [[100, 95, 90, 85, 80, 70, 60, 50, 40, 30, 20, 15, 10, 8, 6, 4, 2, 0], 0],
2356 0 'indigo' => [[map {5 * $_} 0 .. 20], 0],
2357 0 'iso_18620' => [[0, 1, 2, 5, (map {10 * $_} (1 .. 9)), 95, 100], 1],
2358 'photoshop' => [[], 1],
2359 'prinergy' => [[0 .. 100], 0],
2360 0 'rampage' => [[0, 1, 3, (map {5 * $_} 1 .. 19), 97, 99, 100], 0],
2361 0 'trueflow' => [[0, 2, 5, (map {10 * $_} 1 .. 9), 95, 98, 100], 0],
2362 'xitron' => [[0 .. 5, 10, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 95 .. 100], 0],
2363 0 'text' => [[map {$_ * 5} 0 .. 20], 1],
2364 'graph' => [[], 0],
2365 };
2366  
2367 # match caller method name
2368 0 ▶ $ctx[3] =~ m/::(\w+)$/ if (@ctx = caller(1));
Branch: 1 branch
BranchTrueFalseTotal
if @ctx = caller 1 0 0 0
2369  
2370 # set caller, default is 'text'
2371 0 ▶ $caller = defined($1) && exists($std->{$1}) ? $1 : 'text';
Branch: 1 branch
BranchTrueFalseTotal
defined $1 && exists $std->{$1} ? : 0 0 0
Condition0%0/3
defined $1 and exists $std->{$1}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $1 and exists $std->{$1}
defined $1 exists $std->{$1}
Truth table0%0/3
A and B
A= defined $1B= exists $std->{$1}
ABresult
0X0
100
111
2372  
2373 # set default direction (forward)
2374 0 $dir = 0;
2375  
2376 # set default steps value for caller
2377 0 $steps = $std->{$caller}[0];
2378  
2379 # return if options undefined
2380 0 ▶ return($dir, $steps) if (! defined($opts));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opts 0 0 0
2381  
2382 # if options is a scalar
2383 0 ▶ if (! ref($opts)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $opts) { } 0 0 0
elsif (ref $opts eq 'HASH') { } 0 0 0
2384
2385 # set direction
2386 0 ▶ $dir = $opts ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts ? : 0 0 0
2387
2388 # undefine options (for caller, $_[0] is an alias)
2389 0 undef($_[0]);
2390
2391 # if options is a hash ref
2392 } elsif (ref($opts) eq 'HASH') {
2393
2394 # use 'dir' hash value, if any
2395 0 ▶ $dir = $opts->{'dir'} // 0;
Condition0%0/2
$opts->{"dir"} // 0
l!l
00
MC/DC0%0/1
$opts->{"dir"} // 0
$opts->{"dir"}
Truth table0%0/2
A
A= $opts->{"dir"}
Aresult
11
00
2396
2397 # if 'steps' defined in hash
2398 0 ▶ if (defined($opts->{'steps'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts->{"steps"}) 0 0 0
2399
2400 # if custom step values allowed
2401 0 ▶ if ($std->{$caller}[1]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($std->{$caller}[1]) { } 0 0 0
2402
2403 # set steps to hash value
2404 0 $steps = $opts->{'steps'};
2405
2406 # if 'steps' value is a numeric vector
2407 0 ▶ if (ICC::Shared::is_num_vector($steps)) {
Branch: 3 branches
BranchTrueFalseTotal
if (ICC::Shared::is_num_vector($steps)) { } 0 0 0
elsif (&Scalar::Util::looks_like_number($steps)) { } 0 0 0
elsif (not ref $steps) { } 0 0 0
2408
2409 # warn if values out of range (0 - 100)
2410 0 ▶ (0 == grep {$_ < 0 || $_ > 100} @{$steps}) or carp("'steps' value(s) out of range\n");
Branch: 2 branches
BranchTrueFalseTotal
0 == grep({$_ < 0 or $_ > 100;} @{$steps;}) or carp("'steps' value(s) out of range\n") 0 0 0
$_ < 0 or $_ > 100 0 0 0
2411
2412 # if 'steps' value is a number
2413 } elsif (Scalar::Util::looks_like_number($steps)) {
2414
2415 # set upper range
2416 0 $n = int($steps) - 1;
2417
2418 # limit number of steps (1 - 255)
2419 0 ▶ $n = $n < 1 ? 1 : $n > 255 ? 255 : $n;
Branch: 2 branches
BranchTrueFalseTotal
$n < 1 ? : 0 0 0
$n > 255 ? : 0 0 0
2420
2421 # set steps
2422 0 $steps = [map {100 * $_/$n} (0 .. $n)];
2423
2424 # if 'steps' value is a string
2425 } elsif (! ref($steps)) {
2426
2427 # if string a valid key
2428 0 ▶ if (exists($std->{$steps})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $std->{$steps}) { } 0 0 0
2429
2430 # set steps
2431 0 $steps = $std->{$steps}[0];
2432
2433 } else {
2434
2435 # print warning
2436 0 carp("'steps' value '$steps' is invalid, using default steps\n");
2437
2438 # set steps
2439 0 $steps = $std->{$caller}[0];
2440
2441 }
2442
2443 } else {
2444
2445 # print warning
2446 0 carp("'steps' value must be a scalar or an array reference\n");
2447
2448 }
2449
2450 } else {
2451
2452 # print warning
2453 0 carp("custom step values not allowed in $caller curves\n");
2454
2455 }
2456
2457 }
2458
2459 } else {
2460
2461 # print warning
2462 0 carp("options parameter must be a scalar or hash reference\n");
2463
2464 }
2465  
2466 # return
2467 0 return($dir, $steps);
2468  
2469 }
2470  
2471 # read curves from text file
2472 # returns true if successful
2473 # parameters: (ref_to_object, file_handle)
2474 # returns: (flag)
2475 sub _read_text {
2476  
2477 # get parameters
2478 0 ▶ my ($self, $fh) = @_;
Subroutine _read_text: not called CC=7 SCAR=40.3
2479  
2480 # local variables
2481 0 my (@data, @cnt, $n, $last, $f, $mat);
2482  
2483 # localize input record separator
2484 0 local $/ = $self->[0]{'read_rs'};
2485  
2486 # localize loop variable
2487 0 local $_;
2488  
2489 # read the file, line by line
2490 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
2491
2492 # split the line, and filter numeric values
2493 0 push(@data, [grep {Scalar::Util::looks_like_number($_)} split('[\s"]')]);
2494
2495 }
2496  
2497 # for each line
2498 0 for my $line (@data) {
2499
2500 # increment count
2501 0 $cnt[@{$line}]++
2502
2503 }
2504  
2505 # get index with max count
2506 0 ▶ $n = List::Util::reduce {($cnt[$a] // 0) > ($cnt[$b] // 0) ? $a : $b} (1 .. $#cnt);
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
($cnt[$a] // 0) > ($cnt[$b] // 0) ? : 0 0 0
Condition0%0/4
$cnt[$a] // 0
l!l
00
$cnt[$b] // 0
l!l
00
MC/DC0%0/1
$cnt[$a] // 0
$cnt[$a]
MC/DC0%0/1
$cnt[$b] // 0
$cnt[$b]
Truth table0%0/2
A
A= $cnt[$a]
Aresult
11
00
Truth table0%0/2
A
A= $cnt[$b]
Aresult
11
00
2507  
2508 # filter out extraneous lines
2509 0 @data = grep {$n == @{$_}} @data;
2510  
2511 # verify data table size
2512 0 ▶ (@data > 1 && @{$data[0]} > 1) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
@data > 1 and @{$data[0];} > 1 or return 0 0 0 0
Condition0%0/3
@data > 1 and @{$data[0];} > 1
!ll&&!rl&&r
000
MC/DC0%0/2
@data > 1 and @{$data[0];} > 1
@data > 1 @{$data[0];} > 1
Truth table0%0/3
A and B
A= @data > 1B= @{$data[0];} > 1
ABresult
0X0
100
111
2513  
2514 # sort by first value in each line
2515 0 @data = sort {$a->[0] <=> $b->[0]} @data;
2516  
2517 # filter any duplicates
2518 0 ▶ @data = grep {$f = (defined($last) ? $last->[0] != $_->[0] : 1); $last = $_; $f} @data;
Branch: 1 branch
BranchTrueFalseTotal
defined $last ? : 0 0 0
2519  
2520 # convert to device values
2521 0 @data = map {[map {$_/100} @{$_}]} @data;
2522  
2523 # make a transposed matrix of the data
2524 0 $mat = Math::Matrix->new(@data)->transpose();
2525  
2526 # for each channel
2527 0 for my $i (1 .. $#{$mat}) {
2528
2529 # it is assumed the first column of numbers are the input values
2530 # and the remaining columns are output values for each channel
2531
2532 # add a 'spline' curve
2533 0 $self->[1][$i - 1] = ICC::Support::spline->new({'input' => $mat->[0], 'output' => $mat->[$i], 'type' => 'akima'});
2534
2535 }
2536  
2537 # return
2538 0 return(1);
2539  
2540 }
2541  
2542 # read curves from ISO 18620 file
2543 # returns true if successful
2544 # parameters: (ref_to_object, file_handle)
2545 # returns: (flag)
2546 sub _read_iso_18620 {
2547  
2548 # get parameters
2549 0 ▶ my ($self, $fh) = @_;
Subroutine _read_iso_18620: not called CC=7 SCAR=40.3
2550  
2551 # local variables
2552 0 my ($dom, $root, @obj, $k, @sep, $curve, @xy, @x, @y);
2553  
2554 # parse ISO 18620 document
2555 0 ▶ eval{$dom = XML::LibXML->load_xml('IO' => $fh)} || return('failed parsing ISO 18620 document');
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $dom = "XML::LibXML"->load_xml("IO", $fh) } } or return "failed parsing ISO 18620 document" 0 0 0
2556  
2557 # get root element
2558 0 $root = $dom->documentElement();
2559  
2560 # get all nodes (we select later)
2561 0 @obj = $root->findnodes('*');
2562  
2563 # init curve counter
2564 0 $k = 0;
2565  
2566 # for each element
2567 0 for my $s (@obj) {
2568
2569 # if a 'TransferCurve' node
2570 0 ▶ if ($s->nodeName() eq 'TransferCurve') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->nodeName eq "TransferCurve") 0 0 0
2571
2572 # get the Separation attribute
2573 0 $sep[$k] = $s->getAttribute('Separation');
2574
2575 # get the Curve attribute
2576 0 $curve = $s->getAttribute('Curve');
2577
2578 # split the Curve data
2579 0 @xy = split('\s', $curve);
2580
2581 # init value arrays
2582 0 @x = @y = ();
2583
2584 # for each value
2585 0 for my $i (0 .. $#xy) {
2586
2587 # if index is odd
2588 0 ▶ if ($i % 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i % 2) { } 0 0 0
2589
2590 # save as y-value
2591 0 $y[int($i/2)] = $xy[$i];
2592
2593 } else {
2594
2595 # save as x-value
2596 0 $x[int($i/2)] = $xy[$i];
2597
2598 }
2599
2600 }
2601
2602 # add a 'spline' curve to object
2603 0 $self->[1][$k++] = ICC::Support::spline->new({'input' => \@x, 'output' => \@y, 'type' => 'akima'});
2604
2605 }
2606
2607 }
2608  
2609 # add ink sequence
2610 0 $self->[0]{'inks'} = [@sep];
2611  
2612 # return
2613 0 ▶ return($k ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$k ? : 0 0 0
2614  
2615 }
2616  
2617 # read curves from file
2618 # file path to 'iso_18620', 'store', or 'text' format curves
2619 # parameters: (ref_to_object, file_path)
2620 sub _new_from_file {
2621
2622 # get parameters
2623 0 ▶ my ($self, $path) = @_;
Subroutine _new_from_file: not called CC=12 SCAR=50.5
2624
2625 # local variables
2626 0 my ($fh, $buf, $result, $obj);
2627
2628 # filter path name
2629 0 ICC::Shared::filterPath($path);
2630  
2631 # open the file (read-only)
2632 0 ▶ open($fh, '<', $path) or croak("$! when opening file $path");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $path or croak("$! when opening file $path") 0 0 0
2633  
2634 # set binary mode
2635 0 binmode($fh);
2636  
2637 # read start of file
2638 0 ▶ read($fh, $buf, 1024) or croak("file $path is zero length");
Branch: 1 branch
BranchTrueFalseTotal
read $fh, $buf, 1024 or croak("file $path is zero length") 0 0 0
2639  
2640 # reset file pointer
2641 0 seek($fh, 0, 0);
2642  
2643 # if an XML file
2644 0 ▶ if ($buf =~ m/<\?xml.*\?>/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($buf =~ /<\?xml.*\?>/) { } 0 0 0
elsif ($buf =~ /ICC::Profile::cvst/) { } 0 0 0
2645
2646 # read ISO 18620 file
2647 0 ▶ _read_iso_18620($self, $fh) or croak("failed parsing ISO 18620 (XML) file $path");
Branch: 1 branch
BranchTrueFalseTotal
_read_iso_18620($self, $fh) or croak("failed parsing ISO 18620 (XML) file $path") 0 0 0
2648
2649 # save file type
2650 0 $self->[0]{'file_type'} = 'ISO_18620';
2651
2652 # if a Storable file
2653 } elsif ($buf =~ m/ICC::Profile::cvst/) {
2654
2655 # retrieve 'cvst' object from Storable file
2656 0 ▶ ($obj = Storable::fd_retrieve($fh)) or croak("failed retrieving Storable object $path");
Branch: 1 branch
BranchTrueFalseTotal
$obj = Storable::fd_retrieve($fh) or croak("failed retrieving Storable object $path") 0 0 0
2657
2658 # verify a cvst object
2659 0 ▶ (UNIVERSAL::isa($obj, 'ICC::Profile::cvst')) or croak("not a 'cvst' object, retrieved from $path");
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($obj, "ICC::Profile::cvst") or croak("not a 'cvst' object, retrieved from $path") 0 0 0
2660
2661 # copy object elements
2662 0 @{$self} = @{$obj};
2663
2664 # save file type
2665 0 $self->[0]{'file_type'} = 'STORABLE';
2666
2667 } else {
2668
2669 # check for CR-LF (DOS/Windows)
2670 0 ▶ if ($buf =~ m/\015\012/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($buf =~ /\015\012/) { } 0 0 0
elsif ($buf =~ /\012/) { } 0 0 0
elsif ($buf =~ /\015/) { } 0 0 0
2671
2672 # set record separator
2673 0 $self->[0]{'read_rs'} = "\015\012";
2674
2675 # check for LF (Unix/OSX)
2676 } elsif ($buf =~ m/\012/) {
2677
2678 # set record separator
2679 0 $self->[0]{'read_rs'} = "\012";
2680
2681 # check for CR (Mac)
2682 } elsif ($buf =~ m/\015/) {
2683
2684 # set record separator
2685 0 $self->[0]{'read_rs'} = "\015";
2686
2687 # not a text file
2688 } else {
2689
2690 # close the file
2691 0 close($fh);
2692
2693 # error
2694 0 croak('unknown file type');
2695
2696 }
2697
2698 # read text file
2699 0 ▶ _read_text($self, $fh) or croak("failed parsing text file $path");
Branch: 1 branch
BranchTrueFalseTotal
_read_text($self, $fh) or croak("failed parsing text file $path") 0 0 0
2700
2701 # save file type
2702 0 $self->[0]{'file_type'} = 'TEXT';
2703
2704 }
2705  
2706 # close the file
2707 0 close($fh);
2708  
2709 }
2710  
2711 # make new cvst object from array
2712 # parameters: (ref_to_object, ref_to_array)
2713 sub _new_from_array {
2714  
2715 # get parameters
2716 4 ▶ my ($self, $array) = @_;
Subroutine _new_from_array: called CC=4 SCAR=14.9
2717  
2718 # for each curve element
2719 4 for my $i (0 .. $#{$array}) {
2720
2721 # verify object has processing methods
2722 11 ▶ ($array->[$i]->can('transform') && $array->[$i]->can('derivative')) or croak('curve element lacks \'transform\' or \'derivative\' method');
Branch: 1 branch
BranchTrueFalseTotal
$array->[$i]->can("transform") and $array->[$i]->can("derivative") or croak("curve element lacks 'transform' or 'derivative' method") 0 11 11
Condition33%1/3
$array->[$i]->can("transform") and $array->[$i]->can("derivative")
!ll&&!rl&&r
0011
MC/DC0%0/2
$array->[$i]->can("transform") and $array->[$i]->can("derivative")
$array->[$i]->can("transform") $array->[$i]->can("derivative")
Truth table33%1/3
A and B
A= $array->[$i]->can("transform")B= $array->[$i]->can("derivative")
ABresult
0X0
100
111
2723
2724 # add curve element
2725 11 $self->[1][$i] = $array->[$i];
2726
2727 }
2728  
2729 }
2730  
2731 # read cvst tag from ICC profile
2732 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
2733 sub _readICCcvst {
2734  
2735 # get parameters
2736 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCcvst: not called CC=6 SCAR=37.4
2737  
2738 # local variables
2739 0 my ($buf, @mft, $table, $tag2, $type, $class, %hash);
2740  
2741 # set tag signature
2742 0 $self->[0]{'signature'} = $tag->[0];
2743  
2744 # seek start of tag
2745 0 seek($fh, $tag->[1], 0);
2746  
2747 # read tag header
2748 0 read($fh, $buf, 12);
2749  
2750 # unpack header
2751 0 @mft = unpack('a4 x4 n2', $buf);
2752  
2753 # verify tag signature
2754 0 ▶ ($mft[0] eq 'cvst') or croak('wrong tag type');
Branch: 1 branch
BranchTrueFalseTotal
$mft[0] eq "cvst" or croak("wrong tag type") 0 0 0
2755  
2756 # for each curve set element
2757 0 for my $i (0 .. $mft[1] - 1) {
2758
2759 # read positionNumber
2760 0 read($fh, $buf, 8);
2761
2762 # unpack to processing element tag table
2763 0 $table->[$i] = ['cvst', unpack('N2', $buf)];
2764
2765 }
2766  
2767 # for each curve set element
2768 0 for my $i (0 .. $mft[1] - 1) {
2769
2770 # get tag table entry
2771 0 $tag2 = $table->[$i];
2772
2773 # make offset absolute
2774 0 $tag2->[1] += $tag->[1];
2775
2776 # if a duplicate tag
2777 0 ▶ if (exists($hash{$tag2->[1]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{$tag2->[1]}) { } 0 0 0
2778
2779 # use original tag object
2780 0 $self->[1][$i] = $hash{$tag2->[1]};
2781
2782 } else {
2783
2784 # seek to start of tag
2785 0 seek($fh, $tag2->[1], 0);
2786
2787 # read tag type signature
2788 0 read($fh, $type, 4);
2789
2790 # convert non-word characters to underscores
2791 0 $type =~ s|\W|_|g;
2792
2793 # form class specifier
2794 0 $class = "ICC::Profile::$type";
2795
2796 # if 'class->new_fh' method exists
2797 0 ▶ if ($class->can('new_fh')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('new_fh')) { } 0 0 0
2798
2799 # create specific tag object
2800 0 $self->[1][$i] = $class->new_fh($self, $fh, $tag2);
2801
2802 } else {
2803
2804 # create generic tag object
2805 0 $self->[1][$i] = ICC::Profile::Generic->new_fh($self, $fh, $tag2);
2806
2807 # print warning
2808 0 print "curve set element $type opened as generic\n";
2809
2810 }
2811
2812 # save tag object in hash
2813 0 $hash{$tag2->[1]} = $self->[1][$i];
2814
2815 }
2816
2817 }
2818
2819 }
2820  
2821 # write cvst tag to ICC profile
2822 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
2823 sub _writeICCcvst {
2824  
2825 # get parameters
2826 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCcvst: not called CC=8 SCAR=42.8
2827  
2828 # local variables
2829 0 my ($n, $offset, $size, @cept, %hash);
2830  
2831 # get number of curve elements
2832 0 $n = @{$self->[1]};
2833  
2834 # verify number of channels (1 to 15)
2835 0 ▶ ($n > 0 && $n < 16) or croak('unsupported number of channels');
Branch: 1 branch
BranchTrueFalseTotal
$n > 0 and $n < 16 or croak("unsupported number of channels") 0 0 0
Condition0%0/3
$n > 0 and $n < 16
!ll&&!rl&&r
000
MC/DC0%0/2
$n > 0 and $n < 16
$n > 0 $n < 16
Truth table0%0/3
A and B
A= $n > 0B= $n < 16
ABresult
0X0
100
111
2836  
2837 # seek start of tag
2838 0 seek($fh, $tag->[1], 0);
2839  
2840 # write tag type signature and number channels
2841 0 print $fh pack('a4 x4 n2', 'cvst', $n, $n);
2842  
2843 # initialize tag offset
2844 0 $offset = 12 + 8 * $n;
2845  
2846 # for each curve element
2847 0 for my $i (0 .. $#{$self->[1]}) {
2848
2849 # verify curve element is 'curf' object
2850 0 ▶ (UNIVERSAL::isa($self->[1][$i], 'ICC::Profile::curf')) or croak('curve element must a \'curf\' object');
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($self->[1][$i], "ICC::Profile::curf") or croak("curve element must a 'curf' object") 0 0 0
2851
2852 # if tag not in hash
2853 0 ▶ if (! exists($hash{$self->[1][$i]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $hash{$self->[1][$i]}) { } 0 0 0
2854
2855 # get size
2856 0 $size = $self->[1][$i]->size();
2857
2858 # set table entry and add to hash
2859 0 $cept[$i] = $hash{$self->[1][$i]} = [$offset, $size];
2860
2861 # update offset
2862 0 $offset += $size;
2863
2864 # adjust to 4-byte boundary
2865 0 $offset += -$offset % 4;
2866
2867 } else {
2868
2869 # set table entry
2870 0 $cept[$i] = $hash{$self->[1][$i]};
2871
2872 }
2873
2874 # write curve element position entry
2875 0 print $fh pack('N2', @{$cept[$i]});
2876
2877 }
2878  
2879 # initialize hash
2880 0 %hash = ();
2881  
2882 # for each curve element
2883 0 for my $i (0 .. $#{$self->[1]}) {
2884
2885 # if tag not in hash
2886 0 ▶ if (! exists($hash{$self->[1][$i]})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hash{$self->[1][$i]}) 0 0 0
2887
2888 # make offset absolute
2889 0 $cept[$i][0] += $tag->[1];
2890
2891 # write tag
2892 0 $self->[1][$i]->write_fh($self, $fh, ['cvst', $cept[$i][0], $cept[$i][1]]);
2893
2894 # add key to hash
2895 0 $hash{$self->[1][$i]}++;
2896
2897 }
2898
2899 }
2900
2901 }
2902  
2903 7 1;
« lib/ICC/Support/nNET.pm ↑ Summary blib/lib/ICC/Support/spline.pm »