lib/ICC/Support/Chart.pm

filter: Statementstmt 18.4% 731 / 3973 Branchbran 13.7% 317 / 2302 Conditioncond 6.6% 67 / 1015 MC/DCmcdc 3.0% 18 / 584 Subroutinesub 36.0% 57 / 158 Podpod 96.9% 63 / 65 totaltotal 15.4% 1253 / 8097 CC 1703 SCAR 76.1
CC
1703
Cov
15%
writeTIFF
13572.0
_readChartTIFF
8372.0
add_udf
4556.0
CRAP 2017.3
↑ Summary blib/lib/ICC/Support/Chart.pm »
1 package ICC::Support::Chart;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 1.71;
7  
8 # revised 2018-03-29
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 2 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 2 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # support modules
19 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use File::Glob;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # enable static variables
28 2 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # create new chart object
31 # parameters: ([hash])
32 # parameters: (ref_to_data_array, [hash])
33 # parameters: (path_to_file, [hash])
34 # parameters: (path_to_folder, [hash])
35 # returns: (ref_to_chart_object) -or- (ref_to_chart_object, error_string)
36 sub new {
37  
38 # get object class
39 29 ▶ my $class = shift();
Subroutine new: called CC=20 SCAR=33.2
Pod documented
40  
41 # local variables
42 29 my ($self, $hash, $array, $format, $offset, $path, $files, $result, $error);
43  
44 # create empty chart object
45 29 $self = [
46 {}, # object header
47 [[]], # chart data
48 [[]], # colorimetry data
49 [], # header lines
50 {}, # SAMPLE_ID hash
51 ];
52  
53 # get optional hash
54 29 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 1 28 29
55  
56 # if there are additional parameters
57 29 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 22 7 29
elsif (defined $hash) { } 0 7 7
58
59 # if first parameter is an array or a Math::Matrix object
60 22 ▶ if (ref($_[0]) eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix')) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY' or UNIVERSAL::isa($_[0], 'Math::Matrix')) { } 1 21 22
elsif (not ref $_[0]) { } 21 0 21
Condition66%2/3
ref $_[0] eq "ARRAY" or UNIVERSAL::isa($_[0], "Math::Matrix")
l!l&&r!l&&!r
1021
MC/DC50%1/2
ref $_[0] eq "ARRAY" or UNIVERSAL::isa($_[0], "Math::Matrix")
ref $_[0] eq "ARRAY" UNIVERSAL::isa($_[0], "Math::Matrix")
Truth table66%2/3
A or B
A= ref $_[0] eq "ARRAY"B= UNIVERSAL::isa($_[0], "Math::Matrix")
ABresult
1X1
011
000
61
62 # get array reference
63 1 $array = shift();
64
65 # get format header from hash
66 1 $format = $hash->{'format'};
67
68 # copy format header to object, if defined
69 1 ▶ $self->[1][0] = [@{$format}] if defined($format);
Branch: 1 branch
BranchTrueFalseTotal
if defined $format 0 1 1
70
71 # set array offset
72 1 ▶ $offset = defined($format) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $format ? : 0 1 1
73
74 # for each row
75 1 for my $i (0 .. $#{$array}) {
76
77 # copy array
78 4 $self->[1][$i + $offset] = [@{$array->[$i]}];
79
80 }
81
82 # if first parameter is a scalar
83 } elsif (! ref($_[0])) {
84
85 # get path
86 21 $path = shift();
87
88 # save path in object header
89 21 $self->[0]{'file_path'} = $path;
90
91 # get file list
92 21 $files = _files($path);
93
94 # no files
95 21 ▶ if (@{$files} == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (@{$files;} == 0) { } 0 21 21
elsif (@{$files;} == 1) { } 19 2 21
96
97 # invalid path
98 0 carp($error = "no files in path: $path\n");
99
100 # one file
101 21 } elsif (@{$files} == 1) {
102
103 # read chart
104 19 ▶ ($result = _readChart($self, $files->[0], $hash)) && carp($error = "chart $files->[0] $result\n");
Branch: 1 branch
BranchTrueFalseTotal
$result = _readChart($self, $files->[0], $hash) and carp($error = "chart $files->[0] $result\n") 0 19 19
105
106 # add colorimetric metadata
107 19 _addColorMeta($self);
108
109 # multiple files
110 } else {
111
112 # if folder handling undefined or 'AVG'
113 2 ▶ if (! defined($hash->{'folder'}) || $hash->{'folder'} eq 'AVG') {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $hash->{'folder'} or $hash->{'folder'} eq 'AVG') { } 1 1 2
elsif ($hash->{'folder'} eq 'APPEND') { } 1 0 1
Condition66%2/3
not defined $hash->{"folder"} or $hash->{"folder"} eq "AVG"
l!l&&r!l&&!r
101
MC/DC50%1/2
not defined $hash->{"folder"} or $hash->{"folder"} eq "AVG"
not defined $hash->{"folder"} $hash->{"folder"} eq "AVG"
Truth table66%2/3
not(A) or B
A= not defined $hash->{"folder"}B= $hash->{"folder"} eq "AVG"
ABresult
1X1
011
000
114
115 # read average chart
116 1 ▶ _readChartAvg($self, $files, $hash) || carp($error = "no valid charts in path: $path\n");
Branch: 1 branch
BranchTrueFalseTotal
_readChartAvg($self, $files, $hash) or carp($error = "no valid charts in path: $path\n") 0 1 1
117
118 # if folder handling 'APPEND'
119 } elsif ($hash->{'folder'} eq 'APPEND') {
120
121 # read appended chart
122 1 ▶ _readChartAppend($self, $files, $hash) || carp($error = "no valid charts in path: $path\n");
Branch: 1 branch
BranchTrueFalseTotal
_readChartAppend($self, $files, $hash) or carp($error = "no valid charts in path: $path\n") 0 1 1
123
124 } else {
125
126 # invalid folder handling
127 0 carp($error = "invalid folder handling: $hash->{'folder'}\n");
128
129 }
130
131 }
132
133 } else {
134
135 # invalid parameter(s)
136 0 carp($error = "invalid parameter(s)");
137
138 }
139
140 # make SAMPLE_ID hash
141 22 _makeSampleID($self);
142
143 # if hash defined
144 } elsif (defined($hash)) {
145
146 # make patch set
147 0 ▶ ($result = _makePatchSet($self, $hash)) && carp($error = "failed making patch set - $result\n");
Branch: 1 branch
BranchTrueFalseTotal
$result = _makePatchSet($self, $hash) and carp($error = "failed making patch set - $result\n") 0 0 0
148
149 }
150  
151 # bless object
152 29 bless($self, $class);
153  
154 # return
155 29 ▶ return(wantarray() ? ($self, $error) : $self);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 29 29
156  
157 }
158  
159 # get/set reference to header hash
160 # parameters: ([ref_to_new_hash])
161 # returns: (ref_to_hash)
162 sub header {
163  
164 # get object reference
165 2 ▶ my $self = shift();
Subroutine header: called CC=4 SCAR=14.8
Pod documented
166  
167 # if there are parameters
168 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
169
170 # if one parameter, a hash reference
171 1 ▶ if (@_ == 1 && ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 1 0 1
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
172
173 # set header to copy of hash
174 1 $self->[0] = {%{shift()}};
175
176 } else {
177
178 # error
179 0 croak('parameter must be a hash reference');
180
181 }
182
183 }
184  
185 # return reference
186 2 return($self->[0]);
187  
188 }
189  
190 # get/set reference to data array
191 # note: row 0 contains the DATA_FORMAT field names
192 # note: set updates the SAMPLE_ID hash and colorimetry array
193 # parameters: ([ref_to_new_array])
194 # returns: (ref_to_array)
195 sub array {
196  
197 # get object reference
198 2 ▶ my $self = shift();
Subroutine array: called CC=6 SCAR=18.4
Pod documented
199  
200 # if there are parameters
201 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
202
203 # if one parameter, an array reference
204 1 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 1 0 1
Condition33%1/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
001
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
205
206 # get array reference
207 1 my $array = shift();
208
209 # initialize data array
210 1 $self->[1] = [];
211
212 # if array is not empty
213 1 ▶ if (@{$array}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$array;}) 1 0 1
214
215 # for each row
216 1 for my $i (0 .. $#{$array}) {
217
218 # copy to object
219 4 $self->[1][$i] = [@{$array->[$i]}];
220
221 }
222
223 # make SAMPLE_ID hash
224 1 _makeSampleID($self);
225
226 # add colorimetric metadata
227 1 _addColorMeta($self);
228
229 }
230
231 } else {
232
233 # error
234 0 croak('parameter must be an array reference');
235
236 }
237
238 }
239  
240 # return reference
241 2 return($self->[1]);
242  
243 }
244  
245 # get data array size
246 # returns: (number_rows)
247 # returns: (number_rows, number_columns)
248 sub size {
249  
250 # get object reference
251 0 ▶ my $self = shift();
Subroutine size: not called CC=2 SCAR=17.9
Pod documented
252  
253 # return array or scalar
254 0 ▶ return(wantarray ? ($#{$self->[1]}, $#{$self->[1][0]} + 1) : $#{$self->[1]});
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
255  
256 }
257  
258 # get data matrix size
259 # returns: (number_rows)
260 # returns: (number_rows, number_columns)
261 sub matrix_size {
262  
263 # get object reference
264 0 ▶ my $self = shift();
Subroutine matrix_size: not called CC=3 SCAR=24.8
Pod documented
265  
266 # get row length from data
267 0 my $rows = _getRowLength($self);
268  
269 # compute columns
270 0 ▶ my $cols = $rows ? POSIX::ceil($#{$self->[1]}/$rows) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$rows ? : 0 0 0
271  
272 # return array or scalar
273 0 ▶ wantarray ? return($rows, $cols) : return($rows);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
274  
275 }
276  
277 # get row slice from SAMPLE_ID values
278 # id_keys is a list of scalars and/or array references
279 # row_slice is reference to an array of row indices
280 # note: returns undef if any key is missing
281 # parameters: (id_keys)
282 # returns: (row_slice)
283 sub rows {
284  
285 # get object reference
286 3 ▶ my $self = shift();
Subroutine rows: called CC=2 SCAR=6.9
Pod documented
287  
288 # local variable
289 3 my (@keys, @rows);
290  
291 # flatten id key list
292 3 @keys = @{ICC::Shared::flatten(@_)};
293  
294 # get row list using SAMPLE_ID hash
295 3 @rows = @{$self->[4]}{@keys};
296  
297 # return row slice or undef if any rows are missing
298 3 ▶ return((grep {! defined()} @rows) ? undef : \@rows);
Branch: 1 branch
BranchTrueFalseTotal
grep({not defined $_;} @rows) ? : 1 2 3
299  
300 }
301  
302 # get column slice from DATA_FORMAT keys
303 # format_keys is a list of scalars and/or array references
304 # column_slice is reference to an array of column indices
305 # note: tries to match ignoring context if exact match fails
306 # note: returns 'undef' if any column is missing
307 # parameters: (format_keys)
308 # returns: (column_slice)
309 sub cols {
310  
311 # get object reference
312 291 ▶ my $self = shift();
Subroutine cols: called CC=6 SCAR=18.1
Pod documented
313  
314 # local variables
315 291 my (@keys, %fmt, @cols);
316  
317 # flatten format key list
318 291 @keys = @{ICC::Shared::flatten(@_)};
319  
320 # make lookup hash
321 291 ▶ %fmt = map {defined($self->[1][0][$_]) ? ($self->[1][0][$_], $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[1][0][$_] ? : 8523 0 8523
322  
323 # lookup format keys in hash
324 291 @cols = @fmt{@keys};
325  
326 # if any columns undefined
327 291 ▶ if (grep {! defined()} @cols) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not defined $_;} @cols) 192 99 291
328
329 # make lookup hash without context prefixes
330 192 ▶ %fmt = map {(defined($self->[1][0][$_]) && $self->[1][0][$_] =~ m/^(.*?)\|?([^\|\n]*)$/) ? ($2, $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[1][0][$_] && $self->[1][0][$_] =~ /^(.*?)\|?([^\|\n]*)$/ ? : 5869 0 5869
Condition33%1/3
defined $self->[1][0][$_] and $self->[1][0][$_] =~ /^(.*?)\|?([^\|\n]*)$/
!ll&&!rl&&r
005869
MC/DC0%0/2
defined $self->[1][0][$_] and $self->[1][0][$_] =~ /^(.*?)\|?([^\|\n]*)$/
defined $self->[1][0][$_] $self->[1][0][$_] =~ /^(.*?)\|?([^\|\n]*)$/
Truth table33%1/3
A and B
A= defined $self->[1][0][$_]B= $self->[1][0][$_] =~ /^(.*?)\|?([^\|\n]*)$/
ABresult
0X0
100
111
331
332 # lookup format keys in hash
333 192 @cols = @fmt{@keys};
334
335 }
336  
337 # return column slice or undef if any columns undefined
338 291 ▶ return((grep {! defined()} @cols) ? undef : \@cols);
Branch: 1 branch
BranchTrueFalseTotal
grep({not defined $_;} @cols) ? : 162 129 291
339  
340 }
341  
342 # get DATA_FORMAT keys from column slice
343 # column_slice is a list of scalars and/or array references
344 # format_keys is an array reference
345 # note: returns 'undef' if any key is missing
346 # parameters: (column_slice)
347 # returns: (format_keys)
348 sub fmt_keys {
349  
350 # get object reference
351 6 ▶ my $self = shift();
Subroutine fmt_keys: called CC=5 SCAR=18.5
Pod documented
352  
353 # local variable
354 6 my (@keys);
355  
356 # if column slice an empty array reference ([])
357 6 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY' && @{$_[0]} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY' and @{$_[0];} == 0) { } 0 6 6
Condition33%2/6
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == 0
!ll&&!rl&&r
600
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
600
MC/DC0%0/3
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == 0
@_ == 1 ref $_[0] eq "ARRAY" @{$_[0];} == 0
Truth table25%1/4
A and B and C
A= @_ == 1B= ref $_[0] eq "ARRAY"C= @{$_[0];} == 0
ABCresult
0XX0
10X0
1100
1111
358
359 # get all format keys
360 0 @keys = @{$self->[1][0]};
361
362 } else {
363
364 # get format keys per flattened slice
365 6 @keys = map {$self->[1][0][$_]} @{ICC::Shared::flatten(@_)};
366
367 }
368  
369 # return format keys or undef if any keys are missing
370 6 ▶ return((grep {! defined()} @keys) ? undef : \@keys);
Branch: 1 branch
BranchTrueFalseTotal
grep({not defined $_;} @keys) ? : 1 5 6
371  
372 }
373  
374 # get/set context
375 # 'undef' indicates no context (get or set)
376 # returned context may be a scalar or an array
377 # parameter: (column_slice) => returns: (context)
378 # parameters: (column_slice, context) => returns: (modified_keys)
379 sub context {
380  
381 # get object reference
382 7 ▶ my $self = shift();
Subroutine context: called CC=11 SCAR=24.2
Pod documented
383  
384 # local variables
385 7 my ($cols, $context, @cx);
386  
387 # return if no parameters supplied
388 7 ▶ return(undef) if (@_ == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 0 0 7 7
389  
390 # get column slice
391 7 $cols = ICC::Shared::flatten(shift());
392  
393 # use all columns if slice is empty
394 7 ▶ $cols = [0 .. $#{$self->[1][0]}] if (@{$cols} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @{$cols;} == 0 0 7 7
395  
396 # if no context parameter
397 7 ▶ if (@_ == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 0) { } 4 3 7
398
399 # match contexts
400 4 ▶ @cx = map {$self->[1][0][$_] =~ m/^(.*)\|/ ? $1 : undef} @{$cols};
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(.*)\|/ ? : 8 8 16
401
402 # return array if wanted
403 4 ▶ return(@cx) if (wantarray);
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 2 2 4
404
405 # warn if columns have different contexts
406 2 ▶ (@cx == grep {(! defined($cx[0]) && ! defined($_)) || ($cx[0] eq $_)} @cx) || warn('columns have different contexts');
Branch: 2 branches
BranchTrueFalseTotal
@cx == grep({not defined $cx[0] || defined $_ or $cx[0] eq $_;} @cx) or warn "columns have different contexts" 0 2 2
not defined $cx[0] || defined $_ or $cx[0] eq $_ 4 4 8
Condition66%2/3
defined $cx[0] || defined $_
l!l&&r!l&&!r
404
MC/DC50%1/2
defined $cx[0] || defined $_
defined $cx[0] defined $_
Truth table66%2/3
A || B
A= defined $cx[0]B= defined $_
ABresult
1X1
011
000
407
408 # return context of first column
409 2 return($cx[0]);
410
411 } else {
412
413 # get context
414 3 $context = shift();
415
416 # for each column
417 3 for my $i (0 .. $#{$cols}) {
418
419 # if context is defined
420 12 ▶ if (defined($context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context) { } 8 4 12
421
422 # replace current context
423 8 $self->[1][0][$cols->[$i]] =~ s/^(?:.*\|)?(.*)$/$context\|$1/;
424
425 # if context is 'undef'
426 } else {
427
428 # remove current context
429 4 $self->[1][0][$cols->[$i]] =~ s/^.*\|//;
430
431 }
432
433 }
434
435 # return modified keys
436 3 return([@{$self->[1][0]}[@{$cols}]]);
437
438 }
439
440 }
441  
442 # test for a specified data class
443 # returns list of matched indices or count
444 # context parameter of '|' matches fields with no context
445 # parameters: (class, [context])
446 # returns: (list -or- count)
447 sub test {
448  
449 # get parameters
450 255 ▶ my ($self, $class, $context) = @_;
Subroutine test: called CC=9 SCAR=24.2
Pod documented
451  
452 # local variables
453 255 my (%regex, @fields);
454  
455 # hash of compiled regex
456 255 %regex = (
457 'RGB' => qr/^(?:(.*)\|)?RGB_[RGB]$/,
458 'CMYK' => qr/^(?:(.*)\|)?CMYK_[CMYK]$/,
459 'XYZ' => qr/^(?:(.*)\|)?XYZ_[XYZ]$/,
460 'XYY' => qr/^(?:(.*)\|)?XYY_(?:X|Y|CAPY)$/,
461 'LAB' => qr/^(?:(.*)\|)?LAB_[LAB]$/,
462 'LCH' => qr/^(?:(.*)\|)?LAB_[LCH]$/,
463 'NCLR' => qr/^(?:(.*)\|)?[2-9A-F]CLR_[1-9A-F]$/,
464 'SPECTRAL' => qr/^(?:(.*)\|)?(?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)\d{3}$/,
465 'SPOT' => qr/^(?:(.*)\|)?SPOT_\d+$/,
466 'DENSITY' => qr/^(?:(.*)\|)?D_(?:RED|GREEN|BLUE|VIS)$/,
467 'STDEVXYZ' => qr/^(?:(.*)\|)?STDEV_[XYZ]$/,
468 'STDEVLAB' => qr/^(?:(.*)\|)?STDEV_[LAB]$/,
469 'MEAN_DE' => qr/^(?:(.*)\|)?MEAN_DE$/,
470 'ID' => qr/^(?:(.*)\|)?(?:SAMPLE_ID|SampleID)$/,
471 'NAME' => qr/^(?:(.*)\|)?SAMPLE_NAME$/,
472 'DEVICE' => qr/^(?:(.*)\|)?(?:RGB_[RGB]|CMYK_[CMYK]|[2-9A-F]CLR_[1-9A-F])$/,
473 );
474  
475 # verify class
476 255 ▶ (! ref($class) && exists($regex{$class})) || croak('invalid data class');
Branch: 1 branch
BranchTrueFalseTotal
not ref $class and exists $regex{$class} or croak("invalid data class") 0 255 255
Condition33%1/3
not ref $class and exists $regex{$class}
!ll&&!rl&&r
00255
MC/DC0%0/2
not ref $class and exists $regex{$class}
not ref $class exists $regex{$class}
Truth table33%1/3
not(A) and B
A= not ref $classB= exists $regex{$class}
ABresult
0X0
100
111
477  
478 # if context is undefined
479 255 ▶ if (! defined($context)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $context) { } 120 135 255
elsif ($context eq '|') { } 0 135 135
480
481 # match format fields (ignoring context)
482 120 @fields = grep {$self->[1][0][$_] =~ /$regex{$class}/} (0 .. $#{$self->[1][0]});
483
484 # if context is '|'
485 } elsif ($context eq '|') {
486
487 # match format fields (no context)
488 0 ▶ @fields = grep {$self->[1][0][$_] =~ /$regex{$class}/ && ! defined($1)} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$_] =~ /$regex{$class}/ and not defined $1 0 0 0
489
490 } else {
491
492 # match format fields (matching context)
493 135 ▶ @fields = grep {$self->[1][0][$_] =~ /$regex{$class}/ && defined($1) && ($1 eq $context)} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$_] =~ /$regex{$class}/ and defined $1 and $1 eq $context 258 3762 4020
Condition100%3/3
$self->[1][0][$_] =~ /$regex{$class}/ and defined $1
!ll&&!rl&&r
374913258
MC/DC100%2/2
$self->[1][0][$_] =~ /$regex{$class}/ and defined $1
$self->[1][0][$_] =~ /$regex{$class}/ defined $1
Truth table100%3/3
A and B
A= $self->[1][0][$_] =~ /$regex{$class}/B= defined $1
ABresult
0X0
100
111
494
495 }
496  
497 # return (list -or- count)
498 255 ▶ return(wantarray() ? @fields : scalar(@fields));
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 255 255
499  
500 }
501  
502 # get/set keyword value(s)
503 # CGATS ASCII file header lines are stored as an array in the object header
504 # most lines contain a keyword followed by a value, which this methods gets/sets
505 # a keyword may be used more than once, so the value parameter is an array
506 # if the keyword doesn't exist, a new line is added when setting its value
507 # if the keyword is enclosed by angle brackets, existing lines are removed
508 # parameters: () => returns: (file_header_array_reference)
509 # parameters: (keyword) => returns: (value_array)
510 # parameters: (keyword, value_array) => returns: (original_value_array)
511 sub keyword {
512  
513 # get parameters
514 66 ▶ my ($self, $key, @values) = @_;
Subroutine keyword: called CC=11 SCAR=35.6
Pod documented
515  
516 # local variables
517 66 my ($del, @ix, @current);
518  
519 # if no keyword, return file header array reference
520 66 ▶ (defined($key)) || return($self->[3]);
Branch: 1 branch
BranchTrueFalseTotal
defined $key or return $self->[3] 0 66 66
521  
522 # set delete flag, stripping angle brackets (if any)
523 66 $del = ($key =~ s/^<(.*)>$/$1/);
524  
525 # get indices of existing keyword (if any)
526 66 @ix = grep {$self->[3][$_][0] eq $key} (0 .. $#{$self->[3]});
527  
528 # get current values array (if any)
529 66 @current = map {$self->[3][$_][1]} @ix;
530  
531 # if delete flag set
532 66 ▶ if ($del) {
Branch: 1 branch
BranchTrueFalseTotal
if ($del) 0 66 66
533
534 # while indices
535 0 ▶ while (@ix) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ix) 0 0 0
536
537 # delete array element
538 0 splice(@{$self->[3]}, pop(@ix), 1);
539
540 }
541
542 }
543  
544 # if there are supplied values
545 66 ▶ if (@values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@values) 0 66 66
546
547 # for each value
548 0 for (@values) {
549
550 # if not a number or already quoted
551 0 ▶ if (! m/^([\d.-]+|".*")$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/^([\d.-]+|".*")$/) 0 0 0
552
553 # remove any quotes
554 0 s/"//g;
555
556 # enclose in quotes
557 0 $_ = "\"$_\"";
558
559 }
560
561 }
562
563 # while indices and values
564 0 ▶ while (@ix && @values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ix and @values) 0 0 0
Condition0%0/3
@ix and @values
!ll&&!rl&&r
000
MC/DC0%0/2
@ix and @values
@ix @values
Truth table0%0/3
A and B
A= @ixB= @values
ABresult
0X0
100
111
565
566 # set keyword/value entry
567 0 $self->[3][shift(@ix)] = [$key, shift(@values)];
568
569 }
570
571 # for each remaining value (if any)
572 0 for (@values) {
573
574 # add keyword/value entry
575 0 push(@{$self->[3]}, [$key, $_]);
576
577 }
578
579 }
580  
581 # return current values array, or scalar
582 66 ▶ return(wantarray ? @current : $current[0]);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 9 57 66
583  
584 }
585  
586 # get/set CREATED value
587 # adds CREATED keyword when setting, if none
588 # parameters: () # gets date/time from CREATED value
589 # parameters: (string) # sets/adds CREATED keyword/value
590 # parameters: (Time::Piece_object) # sets/adds CREATED keyword/value
591 # returns: (Time::Piece_object) # default is localtime
592 sub created {
593  
594 # get parameters
595 0 ▶ my ($self, $t) = @_;
Subroutine created: not called CC=8 SCAR=42.8
Pod documented
596  
597 # local variables
598 0 my (@ix, $datetime);
599  
600 # get indices of existing CREATED lines (if any)
601 0 @ix = grep {$self->[3][$_][0] eq 'CREATED'} (0 .. $#{$self->[3]});
602  
603 # print warning if more than one CREATED line
604 0 ▶ print "warning: more than one CREATED keyword\n" if (@ix > 1);
Branch: 1 branch
BranchTrueFalseTotal
if @ix > 1 0 0 0
605  
606 # if date/time parameter given
607 0 ▶ if (defined($t)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $t) { } 0 0 0
608
609 # make Time::Piece object if reference is a scalar
610 0 ▶ $t = _makeTimePiece($t) if (! ref($t));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $t 0 0 0
611
612 # if not a Time::Piece object
613 0 ▶ if (ref($t) ne 'Time::Piece') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t ne "Time::Piece") 0 0 0
614
615 # print warning
616 0 print "warning: invalid date/time parameter, using localtime instead\n";
617
618 # use local time
619 0 $t = localtime();
620
621 }
622
623 # make ISO 8601 datetime string from Time::Piece object
624 0 $datetime = $t->strftime('%Y-%m-%dT%T%z');
625 0 substr($datetime, -2, 0, ':');
626
627 # if CREATED lines
628 0 ▶ if (@ix) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ix) { } 0 0 0
629
630 # replace value in first CREATED line
631 0 $self->[3][$ix[0]][1] = "\"$datetime\"";
632
633 } else {
634
635 # if keyword lines exist
636 0 ▶ if (@{$self->[3]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[3];}) { } 0 0 0
637
638 # insert CREATED line (as second line)
639 0 splice(@{$self->[3]}, 1, 0, ['CREATED', "\"$datetime\""]);
640
641 } else {
642
643 # add CREATED line
644 0 $self->[3][0] = ['CREATED', "\"$datetime\""];
645
646 }
647
648 }
649
650 # no parameter
651 } else {
652
653 # if CREATED lines
654 0 ▶ if (@ix) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ix) { } 0 0 0
655
656 # make Time::Piece object from first CREATED value
657 0 $t = _makeTimePiece($self->[3][$ix[0]][1]);
658
659 } else {
660
661 # print warning
662 0 print "warning: no CREATED keyword, returning localtime instead\n";
663
664 # use local time
665 0 $t = localtime();
666
667 }
668
669 }
670  
671 # return Time::Piece object
672 0 return($t);
673  
674 }
675  
676 # get/set data array slice
677 # row_slice and column_slice may be either a scalar or array reference
678 # replacement_data is reference to a 2-D array of replacement values
679 # replacement data dimensions must match size of row_slice and column_slice
680 # data_slice is reference to a 2-D array, selected by row_slice and column_slice
681 # parameters: ([row_slice, [column_slice, [replacement_data]]])
682 # return: (data_slice)
683 sub slice {
684  
685 # get parameters
686 5 ▶ my ($self, $rows, $cols, $data) = @_;
Subroutine slice: called CC=3 SCAR=11.0
Pod documented
687  
688 # select all rows if row slice undefined
689 5 ▶ $rows = [] if (! defined($rows));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rows 1 4 5
690  
691 # select all fields if column slice undefined
692 5 ▶ $cols = [] if (! defined($cols));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cols 2 3 5
693  
694 # call get/set subroutine
695 5 _getset($self, 1, $rows, $cols, $data);
696  
697 }
698  
699 # get/set colorimetry array slice
700 # row_slice and column_slice may be either a scalar or array reference
701 # replacement_data is reference to a 2-D array of replacement values
702 # replacement data dimensions must match size of row_slice and column_slice
703 # data_slice is reference to a 2-D array, selected by row_slice and column_slice
704 # parameters: ([row_slice, [column_slice, [replacement_data]]])
705 # return: (data_slice)
706 sub colorimetry {
707  
708 # get parameters
709 0 ▶ my ($self, $rows, $cols, $data) = @_;
Subroutine colorimetry: not called CC=5 SCAR=34.0
Pod documented
710  
711 # flatten row slice
712 0 ▶ $rows = defined($rows) ? ICC::Shared::flatten($rows) : [];
Branch: 1 branch
BranchTrueFalseTotal
defined $rows ? : 0 0 0
713  
714 # select all rows if row slice empty
715 0 ▶ $rows = [0 .. $#{$self->[2]}] if (@{$rows} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @{$rows;} == 0 0 0 0
716  
717 # flatten column slice
718 0 ▶ $cols = defined($cols) ? ICC::Shared::flatten($cols) : [];
Branch: 1 branch
BranchTrueFalseTotal
defined $cols ? : 0 0 0
719  
720 # select all fields if column slice empty
721 0 ▶ $cols = [0 .. $#{$self->[1][0]}] if (@{$cols} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @{$cols;} == 0 0 0 0
722  
723 # call get/set subroutine
724 0 _getset($self, 2, $rows, $cols, $data);
725  
726 }
727  
728 # get/set SAMPLE_ID data
729 # optional hash contains supplementary parameters
730 # row_slice and column_slice are 1-D array references
731 # data_slice is a Math::Matrix object (2-D array)
732 # replacement_data is a Math::Matrix object or 2-D array
733 # parameters: ([hash]) => returns: (column_slice)
734 # parameters: (row_slice, [hash]) => returns: (data_slice)
735 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
736 sub id {
737  
738 # local variables
739 23 ▶ my ($hash, %fmt, $cols);
Subroutine id: called CC=7 SCAR=19.5
Pod documented
740  
741 # get optional hash
742 23 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 9 14 23
743  
744 # get remaining parameters
745 23 my ($self, $rows, $data) = @_;
746  
747 # make lookup hash (context| -or- '||' => column)
748 23 ▶ %fmt = map {($self->[1][0][$_] =~ m/^(.*\|)?(?:SAMPLE_ID|SampleID|ID)$/) ? (defined($1) ? $1 : '||', $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 2 branches
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(.*\|)?(?:SAMPLE_ID|SampleID|ID)$/ ? : 11 596 607
defined $1 ? : 0 11 11
749  
750 # if context defined
751 23 ▶ if (defined($hash->{'context'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'context'}) { } 9 14 23
752
753 # get id column with context
754 9 $cols = $fmt{"$hash->{'context'}|"};
755
756 } else {
757
758 # get id column without context
759 14 $cols = $fmt{'||'};
760
761 # if id column undefined
762 14 ▶ if (! defined($cols)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cols) 4 10 14
763
764 # make lookup hash ignoring context ('||' => column)
765 4 ▶ %fmt = map {($self->[1][0][$_] =~ m/^(?:.*\|)?(?:SAMPLE_ID|SampleID|ID)$/) ? ('||', $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(?:.*\|)?(?:SAMPLE_ID|SampleID|ID)$/ ? : 0 128 128
766
767 # get id column
768 4 $cols = $fmt{'||'};
769
770 }
771
772 }
773  
774 # call get/set subroutine
775 23 _getset($self, 1, $rows, $cols, $data);
776  
777 }
778  
779 # get/set SAMPLE_NAME data
780 # optional hash contains supplementary parameters
781 # row_slice and column_slice are 1-D array references
782 # data_slice is a Math::Matrix object (2-D array)
783 # replacement_data is a Math::Matrix object or 2-D array
784 # parameters: ([hash]) => returns: (column_slice)
785 # parameters: (row_slice, [hash]) => returns: (data_slice)
786 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
787 sub name {
788  
789 # local variables
790 23 ▶ my ($hash, $cols);
Subroutine name: called CC=3 SCAR=11.0
Pod documented
791  
792 # get optional hash
793 23 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 9 14 23
794  
795 # get remaining parameters
796 23 my ($self, $rows, $data) = @_;
797  
798 # get column slice, adding optional context prefix
799 23 ▶ $cols = cols($self, defined($hash->{'context'}) ? "$hash->{'context'}|SAMPLE_NAME" : 'SAMPLE_NAME');
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 9 14 23
800  
801 # call get/set subroutine
802 23 _getset($self, 1, $rows, $cols, $data);
803  
804 }
805  
806 # get/set RGB data
807 # optional hash contains supplementary parameters
808 # row_slice and column_slice are 1-D array references
809 # data_slice is a Math::Matrix object (2-D array)
810 # replacement_data is a Math::Matrix object or 2-D array
811 # parameters: ([hash]) => returns: (column_slice)
812 # parameters: (row_slice, [hash]) => returns: (data_slice)
813 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
814 sub rgb {
815  
816 # local variables
817 67 ▶ my ($hash, $cols);
Subroutine rgb: called CC=3 SCAR=11.0
Pod documented
818  
819 # get optional hash
820 67 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 31 36 67
821  
822 # get remaining parameters
823 67 my ($self, $rows, $data) = @_;
824  
825 # get column slice, adding optional context prefix
826 67 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(RGB_R RGB_G RGB_B));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 93 108 201
827  
828 # call get/set subroutine
829 67 _getset($self, 1, $rows, $cols, $data);
830  
831 }
832  
833 # get/set CMYK data
834 # optional hash contains supplementary parameters
835 # row_slice and column_slice are 1-D array references
836 # data_slice is a Math::Matrix object (2-D array)
837 # replacement_data is a Math::Matrix object or 2-D array
838 # parameters: ([hash]) => returns: (column_slice)
839 # parameters: (row_slice, [hash]) => returns: (data_slice)
840 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
841 sub cmyk {
842  
843 # local variables
844 67 ▶ my ($hash, $cols);
Subroutine cmyk: called CC=3 SCAR=11.0
Pod documented
845  
846 # get optional hash
847 67 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 31 36 67
848  
849 # get remaining parameters
850 67 my ($self, $rows, $data) = @_;
851  
852 # get column slice, adding optional context prefix
853 67 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(CMYK_C CMYK_M CMYK_Y CMYK_K));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 124 144 268
854  
855 # call get/set subroutine
856 67 _getset($self, 1, $rows, $cols, $data);
857  
858 }
859  
860 # get/set 6CLR data
861 # optional hash contains supplementary parameters
862 # row_slice and column_slice are 1-D array references
863 # data_slice is a Math::Matrix object (2-D array)
864 # replacement_data is a Math::Matrix object or 2-D array
865 # parameters: ([hash]) => returns: (column_slice)
866 # parameters: (row_slice, [hash]) => returns: (data_slice)
867 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
868 sub hex {
869  
870 # local variables
871 33 ▶ my ($hash, $cols);
Subroutine hex: called CC=3 SCAR=11.0
Pod documented
872  
873 # get optional hash
874 33 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 12 21 33
875  
876 # get remaining parameters
877 33 my ($self, $rows, $data) = @_;
878  
879 # get column slice, adding optional context prefix
880 33 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(6CLR_1 6CLR_2 6CLR_3 6CLR_4 6CLR_5 6CLR_6));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 72 126 198
881  
882 # call get/set subroutine
883 33 _getset($self, 1, $rows, $cols, $data);
884  
885 }
886  
887 # get/set nCLR data
888 # optional hash contains supplementary parameters
889 # row_slice and column_slice are 1-D array references
890 # data_slice and replacement_data are 2-D array references
891 # parameters: ([hash]) => returns: (column_slice)
892 # parameters: (row_slice, [hash]) => returns: (data_slice)
893 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
894 sub nCLR {
895  
896 # local variables
897 38 ▶ my ($hash, $context, %fmt, %fmt2, $chan, @cols);
Subroutine nCLR: called CC=13 SCAR=25.7
Pod documented
898  
899 # get optional hash
900 38 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 21 17 38
901  
902 # get remaining parameters
903 38 my ($self, $rows, $data) = @_;
904  
905 # get the context
906 38 $context = $hash->{'context'};
907  
908 # make lookup hash (key => column)
909 38 ▶ %fmt = map {($self->[1][0][$_] =~ m/^(?:.*\|)?[2-9A-F]CLR_[1-9A-F]$/) ? ($self->[1][0][$_], $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(?:.*\|)?[2-9A-F]CLR_[1-9A-F]$/ ? : 120 1213 1333
910  
911 # make lookup hash (prefix -or- '||' => channels)
912 38 ▶ %fmt2 = map {($self->[1][0][$_] =~ m/^(.*\|)?([2-9A-F])CLR_[1-9A-F]$/) ? (defined($1) ? ($1, $2) : ('||', $2)) : ()} (0 .. $#{$self->[1][0]});
Branch: 2 branches
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(.*\|)?([2-9A-F])CLR_[1-9A-F]$/ ? : 120 1213 1333
defined $1 ? : 66 54 120
913  
914 # if context defined
915 38 ▶ if (defined($context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context) { } 21 17 38
916
917 # get the number of channels
918 21 ▶ ($chan = $fmt2{"$context|"}) || return();
Branch: 1 branch
BranchTrueFalseTotal
$chan = $fmt2{"$context|"} or return () 14 7 21
919
920 # append format
921 7 $chan .= 'CLR_';
922
923 # get column slice (selected from %fmt columns)
924 7 @cols = grep {$self->[1][0][$_] =~ m/^$context\|$chan[1-9A-F]$/} values(%fmt);
925
926 } else {
927
928 # if number of channels undefined
929 17 ▶ if (! defined($chan = $fmt2{'||'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined($chan = $fmt2{'||'})) { } 8 9 17
930
931 # make lookup hash ignoring prefix (key => column)
932 8 ▶ %fmt = map {($self->[1][0][$_] =~ m/^(?:.*\|)?([2-9A-F]CLR_[1-9A-F])$/) ? ($1, $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(?:.*\|)?([2-9A-F]CLR_[1-9A-F])$/ ? : 12 253 265
933
934 # make lookup hash ('||' => channels)
935 8 ▶ %fmt2 = map {($self->[1][0][$_] =~ m/^(?:.*\|)?([2-9A-F])CLR_[1-9A-F]$/) ? ('||', $1) : ()} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(?:.*\|)?([2-9A-F])CLR_[1-9A-F]$/ ? : 12 253 265
936
937 # get the number of channels
938 8 ▶ ($chan = $fmt2{'||'}) || return();
Branch: 1 branch
BranchTrueFalseTotal
$chan = $fmt2{"||"} or return () 6 2 8
939
940 # append format
941 2 $chan .= 'CLR_';
942
943 # get column slice (selected from %fmt columns)
944 2 @cols = grep {$self->[1][0][$_] =~ m/^(?:.*\|)?$chan[1-9A-F]$/} values(%fmt);
945
946 } else {
947
948 # append format
949 9 $chan .= 'CLR_';
950
951 # get column slice (selected from %fmt columns)
952 9 @cols = grep {$self->[1][0][$_] =~ m/^$chan[1-9A-F]$/} values(%fmt);
953
954 }
955
956 }
957  
958 # sort by color channel (1-9, A-F)
959 18 @cols = sort {substr($self->[1][0][$a], -1) cmp substr($self->[1][0][$b], -1)} @cols;
960  
961 # match last format key
962 18 $self->[1][0][$cols[-1]] =~ m/([2-9A-F])CLR_([1-9A-F])$/;
963  
964 # verify number of format keys
965 18 ▶ (CORE::hex($1) == @cols && CORE::hex($2) == @cols) || croak('wrong number of nCLR keys');
Branch: 1 branch
BranchTrueFalseTotal
CORE::hex $1 == @cols and CORE::hex $2 == @cols or croak("wrong number of nCLR keys") 0 18 18
Condition33%1/3
CORE::hex $1 == @cols and CORE::hex $2 == @cols
!ll&&!rl&&r
0018
MC/DC0%0/2
CORE::hex $1 == @cols and CORE::hex $2 == @cols
CORE::hex $1 == @cols CORE::hex $2 == @cols
Truth table33%1/3
A and B
A= CORE::hex $1 == @colsB= CORE::hex $2 == @cols
ABresult
0X0
100
111
966  
967 # call get/set subroutine
968 18 _getset($self, 1, $rows, \@cols, $data);
969  
970 }
971  
972 # get/set device data
973 # device data is either RGB, CMYK or nCLR
974 # device values have range (0 - 1)
975 # optional hash contains supplementary parameters
976 # row_slice and column_slice are 1-D array references
977 # data_slice is a Math::Matrix object (2-D array)
978 # replacement_data is a Math::Matrix object or 2-D array
979 # parameters: ([hash]) => returns: (column_slice)
980 # parameters: (row_slice, [hash]) => returns: (data_slice)
981 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
982 sub device {
983  
984 # local variables
985 36 ▶ my ($hash, $cols, $mult);
Subroutine device: called CC=6 SCAR=17.9
Pod documented
986  
987 # get optional hash
988 36 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 19 17 36
989  
990 # get remaining parameters
991 36 my ($self, $rows, $data) = @_;
992  
993 # get column slice or return empty
994 36 ▶ $cols = rgb($self, $hash) || cmyk($self, $hash) || nCLR($self, $hash) || return();
Condition100%8/8
rgb($self, $hash) || cmyk($self, $hash) || nCLR($self, $hash) || (return ())
l!l
306
rgb($self, $hash) or cmyk($self, $hash) or nCLR($self, $hash)
l!l&&r!l&&!r
2196
rgb($self, $hash) or cmyk($self, $hash)
l!l&&r!l&&!r
91215
MC/DC100%3/3
rgb($self, $hash) || cmyk($self, $hash) || nCLR($self, $hash) || (return ())
rgb($self, $hash) cmyk($self, $hash) nCLR($self, $hash)
Truth table100%4/4
A or B or C
A= rgb($self, $hash)B= cmyk($self, $hash)C= nCLR($self, $hash)
ABCresult
1XX1
01X1
0011
0000
995  
996 # set multiplier (255 if RGB, else 100)
997 30 ▶ $mult = ($self->[1][0][$cols->[0]] =~ m/RGB_R$/) ? 255 : 100;
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$cols->[0]] =~ /RGB_R$/ ? : 9 21 30
998  
999 # call get/set subroutine
1000 30 ▶ _getset($self, 1, $rows, $cols, $data, sub {map {defined($_) ? $_/$mult : $_} @_}, sub {map {defined($_) ? $_ * $mult : $_} @_});
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 2 branches
BranchTrueFalseTotal
defined $_ ? : 338 0 338
defined $_ ? : 78 0 78
1001  
1002 }
1003  
1004 # get/set CTV data
1005 # optional hash contains supplementary parameters
1006 # row_slice and column_slice are 1-D array references
1007 # data_slice is a Math::Matrix object (2-D array)
1008 # replacement_data is a Math::Matrix object or 2-D array
1009 # parameters: ([hash]) => returns: (column_slice)
1010 # parameters: (row_slice, [hash]) => returns: (data_slice)
1011 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
1012 sub ctv {
1013  
1014 # local variables
1015 17 ▶ my ($hash, $cols);
Subroutine ctv: called CC=3 SCAR=11.0
Pod documented
1016  
1017 # get optional hash
1018 17 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 9 8 17
1019  
1020 # get remaining parameters
1021 17 my ($self, $rows, $data) = @_;
1022  
1023 # get column slice, adding optional context prefix
1024 17 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(CTV));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 9 8 17
1025  
1026 # call get/set subroutine
1027 17 _getset($self, 1, $rows, $cols, $data);
1028  
1029 }
1030  
1031 # get/set L*a*b* data
1032 # optional hash contains supplementary parameters
1033 # row_slice and column_slice are 1-D array references
1034 # data_slice is a Math::Matrix object (2-D array)
1035 # replacement_data is a Math::Matrix object or 2-D array
1036 # parameters: ([hash]) => returns: (column_slice)
1037 # parameters: (row_slice, [hash]) => returns: (data_slice)
1038 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
1039 sub lab {
1040  
1041 # local variables
1042 29 ▶ my ($hash, $cols);
Subroutine lab: called CC=3 SCAR=11.0
Pod documented
1043  
1044 # get optional hash
1045 29 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 12 17 29
1046  
1047 # get remaining parameters
1048 29 my ($self, $rows, $data) = @_;
1049  
1050 # get column slice, adding optional context prefix
1051 29 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(LAB_L LAB_A LAB_B));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 36 51 87
1052  
1053 # call get/set subroutine
1054 29 _getset($self, 1, $rows, $cols, $data, _lab_encoding($self, $hash));
1055  
1056 }
1057  
1058 # get/set XYZ data
1059 # optional hash contains supplementary parameters
1060 # row_slice and column_slice are 1-D array references
1061 # data_slice is a Math::Matrix object (2-D array)
1062 # replacement_data is a Math::Matrix object or 2-D array
1063 # parameters: ([hash]) => returns: (column_slice)
1064 # parameters: (row_slice, [hash]) => returns: (data_slice)
1065 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
1066 sub xyz {
1067  
1068 # local variables
1069 23 ▶ my ($hash, $cols);
Subroutine xyz: called CC=3 SCAR=11.0
Pod documented
1070  
1071 # get optional hash
1072 23 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 9 14 23
1073  
1074 # get remaining parameters
1075 23 my ($self, $rows, $data) = @_;
1076  
1077 # get column slice, adding optional context prefix
1078 23 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(XYZ_X XYZ_Y XYZ_Z));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 27 42 69
1079  
1080 # call get/set subroutine
1081 23 _getset($self, 1, $rows, $cols, $data, _xyz_encoding($self, $cols, $hash));
1082  
1083 }
1084  
1085 # get/set density data
1086 # optional hash contains supplementary parameters
1087 # row_slice and column_slice are 1-D array references
1088 # data_slice is a Math::Matrix object (2-D array)
1089 # replacement_data is a Math::Matrix object or 2-D array
1090 # parameters: ([hash]) => returns: (column_slice)
1091 # parameters: (row_slice, [hash]) => returns: (data_slice)
1092 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
1093 sub density {
1094  
1095 # local variables
1096 17 ▶ my ($hash, $cols);
Subroutine density: called CC=3 SCAR=11.0
Pod documented
1097  
1098 # get optional hash
1099 17 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 9 8 17
1100  
1101 # get remaining parameters
1102 17 my ($self, $rows, $data) = @_;
1103  
1104 # get column slice
1105 17 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(D_RED D_GREEN D_BLUE D_VIS));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 36 32 68
1106  
1107 # call get/set subroutine
1108 17 _getset($self, 1, $rows, $cols, $data, _density_encoding($self, $hash));
1109  
1110 }
1111  
1112 # get/set reflectance/transmittance data
1113 # optional hash contains supplementary parameters
1114 # row_slice and column_slice are 1-D array references
1115 # data_slice is a Math::Matrix object (2-D array)
1116 # replacement_data is a Math::Matrix object or 2-D array
1117 # parameters: ([hash]) => returns: (column_slice)
1118 # parameters: (row_slice, [hash]) => returns: (data_slice)
1119 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
1120 sub rgbv {
1121  
1122 # local variables
1123 0 ▶ my ($hash, $cols);
Subroutine rgbv: not called CC=3 SCAR=24.8
Pod documented
1124  
1125 # get optional hash
1126 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
1127  
1128 # get remaining parameters
1129 0 my ($self, $rows, $data) = @_;
1130  
1131 # get column slice
1132 0 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(R_RED R_GREEN R_BLUE R_VIS));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 0 0 0
1133  
1134 # call get/set subroutine
1135 0 _getset($self, 1, $rows, $cols, $data, _rgbv_encoding($self, $hash));
1136  
1137 }
1138  
1139 # get/set spectral data
1140 # optional hash contains supplementary parameters
1141 # row_slice and column_slice are 1-D array references
1142 # data_slice is a Math::Matrix object (2-D array)
1143 # replacement_data is a Math::Matrix object or 2-D array
1144 # parameters: ([hash]) => returns: (column_slice)
1145 # parameters: (row_slice, [hash]) => returns: (data_slice)
1146 # parameters: (row_slice, replacement_data, [hash]) => returns: (column_slice)
1147 sub spectral {
1148  
1149 # local variables
1150 45 ▶ my ($hash, $fields, $cols);
Subroutine spectral: called CC=3 SCAR=11.0
Pod documented
1151  
1152 # get optional hash
1153 45 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 18 27 45
1154  
1155 # get remaining parameters
1156 45 my ($self, $rows, $data) = @_;
1157  
1158 # get spectral fields array
1159 45 $fields = _spectral($self, $hash->{'context'});
1160  
1161 # get column slice from spectral fields array
1162 45 ▶ $cols = defined($fields) ? [map {$_->[0]} @{$fields}] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $fields ? : 37 8 45
1163  
1164 # call get/set subroutine
1165 45 _getset($self, 1, $rows, $cols, $data);
1166  
1167 }
1168  
1169 # get spectral wavelength array
1170 # array is sorted (low to high)
1171 # parameters: ([hash])
1172 # returns: (ref_to_wavelength_array)
1173 sub wavelength {
1174  
1175 # get parameters
1176 0 ▶ my ($self, $hash) = @_;
Subroutine wavelength: not called CC=2 SCAR=17.9
Pod documented
1177  
1178 # get spectral fields array or return empty
1179 0 ▶ my $fields = _spectral($self, $hash->{'context'}) || return();
Condition0%0/2
_spectral($self, $hash->{'context'}) || (return ())
l!l
00
MC/DC0%0/1
_spectral($self, $hash->{'context'}) || (return ())
_spectral($self, $hash->{'context'})
Truth table0%0/2
A
A= _spectral($self, $hash->{'context'})
Aresult
11
00
1180  
1181 # return
1182 0 return([map {$_->[1]} @{$fields}]);
1183  
1184 }
1185  
1186 # get spectral wavelength range
1187 # structure is [start_nm, end_nm, increment]
1188 # parameters: ([hash])
1189 # returns: (range)
1190 sub nm {
1191  
1192 # get parameters
1193 0 ▶ my ($self, $hash) = @_;
Subroutine nm: not called CC=4 SCAR=30.0
Pod documented
1194
1195 # local variables
1196 0 my ($fields, $inc);
1197  
1198 # get spectral fields array or return empty
1199 0 ▶ $fields = _spectral($self, $hash->{'context'}) || return();
Condition0%0/2
_spectral($self, $hash->{'context'}) || (return ())
l!l
00
MC/DC0%0/1
_spectral($self, $hash->{'context'}) || (return ())
_spectral($self, $hash->{'context'})
Truth table0%0/2
A
A= _spectral($self, $hash->{'context'})
Aresult
11
00
1200  
1201 # compute increment
1202 0 $inc = $fields->[1][1] - $fields->[0][1];
1203  
1204 # verify wavelength increment
1205 0 ▶ ($inc > 0 && abs($#{$fields} * $inc - $fields->[-1][1] + $fields->[0][1]) < 1E-12) || warn('inconsistent wavelength values');
Branch: 1 branch
BranchTrueFalseTotal
$inc > 0 and abs $#{$fields;} * $inc - $fields->[-1][1] + $fields->[0][1] < "1e-12" or warn "inconsistent wavelength values" 0 0 0
Condition0%0/3
$inc > 0 and abs $#{$fields;} * $inc - $fields->[-1][1] + $fields->[0][1] < "1e-12"
!ll&&!rl&&r
000
MC/DC0%0/2
$inc > 0 and abs $#{$fields;} * $inc - $fields->[-1][1] + $fields->[0][1] < "1e-12"
$inc > 0 abs $#{$fields;} * $inc - $fields->[-1][1] + $fields->[0][1] < "1e-12"
Truth table0%0/3
A and B
A= $inc > 0B= abs $#{$fields;} * $inc - $fields->[-1][1] + $fields->[0][1] < "1e-12"
ABresult
0X0
100
111
1206  
1207 # return range
1208 0 return([$fields->[0][1], $fields->[-1][1], $inc]);
1209  
1210 }
1211  
1212 # get illuminant white point
1213 # parameters: ([hash])
1214 # returns: (XYZ_vector)
1215 sub iwtpt {
1216  
1217 # get parameters
1218 0 ▶ my ($self, $hash) = @_;
Subroutine iwtpt: not called CC=3 SCAR=24.8
Pod documented
1219  
1220 # local variables
1221 0 my ($encode, $cols, $iwtpt, $get);
1222  
1223 # extract encoding hash
1224 0 $encode = {'encoding' => delete($hash->{'encoding'})};
1225  
1226 # get XYZ or L*a*b* column slice
1227 0 ▶ $cols = xyz($self, $hash) || lab($self, $hash) || croak('illuminant white point XYZ or L*a*b* column slice undefined');
Condition0%0/6
xyz($self, $hash) || lab($self, $hash) || croak('illuminant white point XYZ or L*a*b* column slice undefined')
l!l&&r!l&&!r
000
xyz($self, $hash) or lab($self, $hash)
l!l&&r!l&&!r
000
MC/DC0%0/3
xyz($self, $hash) || lab($self, $hash) || croak('illuminant white point XYZ or L*a*b* column slice undefined')
xyz($self, $hash) lab($self, $hash) croak('illuminant white point XYZ or L*a*b* column slice undefined')
Truth table0%0/4
A or B || C
A= xyz($self, $hash)B= lab($self, $hash)C= croak('illuminant white point XYZ or L*a*b* column slice undefined')
ABCresult
1XX1
01X1
0011
0000
1228  
1229 # get illuminant white point
1230 0 $iwtpt = _illumWP($self, $cols, $hash);
1231  
1232 # get code reference
1233 0 ($get) = _xyz_encoding($self, $cols, $encode);
1234  
1235 # return encoded XYZ vector
1236 0 return([&$get(@{$iwtpt})]);
1237  
1238 }
1239  
1240 # get media white point
1241 # parameters: ([hash])
1242 # returns: (XYZ_vector)
1243 sub wtpt {
1244  
1245 # get parameters
1246 0 ▶ my ($self, $hash) = @_;
Subroutine wtpt: not called CC=5 SCAR=34.0
Pod documented
1247  
1248 # local variables
1249 0 my ($encode, $cols, $get);
1250  
1251 # extract encoding hash
1252 0 $encode = {'encoding' => delete($hash->{'encoding'})};
1253  
1254 # get XYZ or L*a*b* column slice
1255 0 ▶ $cols = xyz($self, $hash) || lab($self, $hash) || croak('white point XYZ or L*a*b* column slice undefined');
Condition0%0/6
xyz($self, $hash) || lab($self, $hash) || croak('white point XYZ or L*a*b* column slice undefined')
l!l&&r!l&&!r
000
xyz($self, $hash) or lab($self, $hash)
l!l&&r!l&&!r
000
MC/DC0%0/3
xyz($self, $hash) || lab($self, $hash) || croak('white point XYZ or L*a*b* column slice undefined')
xyz($self, $hash) lab($self, $hash) croak('white point XYZ or L*a*b* column slice undefined')
Truth table0%0/4
A or B || C
A= xyz($self, $hash)B= lab($self, $hash)C= croak('white point XYZ or L*a*b* column slice undefined')
ABCresult
1XX1
01X1
0011
0000
1256  
1257 # if media white point undefined in colorimetry array
1258 0 ▶ if (! defined($self->[2][3][$cols->[0]])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->[2][3][$cols->[0]]) 0 0 0
1259
1260 # compute media white point or return undefined
1261 0 ▶ (_mediaWP($self, $cols, $hash)) || return();
Branch: 1 branch
BranchTrueFalseTotal
_mediaWP($self, $cols, $hash) or return () 0 0 0
1262
1263 }
1264  
1265 # get code reference
1266 0 ($get) = _xyz_encoding($self, $cols, $encode);
1267  
1268 # return encoded XYZ vector
1269 0 return([&$get(@{$self->[2][3]}[@{$cols}])]);
1270  
1271 }
1272  
1273 # get media black point
1274 # parameters: ([hash])
1275 # returns: (XYZ_vector)
1276 sub bkpt {
1277  
1278 # get parameters
1279 0 ▶ my ($self, $hash) = @_;
Subroutine bkpt: not called CC=5 SCAR=34.0
Pod documented
1280  
1281 # local variables
1282 0 my ($encode, $cols, $get);
1283  
1284 # extract encoding hash
1285 0 $encode = {'encoding' => delete($hash->{'encoding'})};
1286  
1287 # get XYZ or L*a*b* column slice
1288 0 ▶ $cols = xyz($self, $hash) || lab($self, $hash) || croak('black point XYZ or L*a*b* column slice undefined');
Condition0%0/6
xyz($self, $hash) || lab($self, $hash) || croak('black point XYZ or L*a*b* column slice undefined')
l!l&&r!l&&!r
000
xyz($self, $hash) or lab($self, $hash)
l!l&&r!l&&!r
000
MC/DC0%0/3
xyz($self, $hash) || lab($self, $hash) || croak('black point XYZ or L*a*b* column slice undefined')
xyz($self, $hash) lab($self, $hash) croak('black point XYZ or L*a*b* column slice undefined')
Truth table0%0/4
A or B || C
A= xyz($self, $hash)B= lab($self, $hash)C= croak('black point XYZ or L*a*b* column slice undefined')
ABCresult
1XX1
01X1
0011
0000
1289  
1290 # if media black point undefined in colorimetry array
1291 0 ▶ if (! defined($self->[2][4][$cols->[0]])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->[2][4][$cols->[0]]) 0 0 0
1292
1293 # compute media black point or return undefined
1294 0 ▶ (_mediaBP($self, $cols, $hash)) || return();
Branch: 1 branch
BranchTrueFalseTotal
_mediaBP($self, $cols, $hash) or return () 0 0 0
1295
1296 }
1297  
1298 # get code reference
1299 0 ($get) = _xyz_encoding($self, $cols, $encode);
1300  
1301 # return encoded XYZ vector
1302 0 return([&$get(@{$self->[2][4]}[@{$cols}])]);
1303  
1304 }
1305  
1306 # compute media OBA index
1307 # requires M1 and M2 measurements
1308 # requires device values -or- sample number
1309 # optional hash keys are 'sample', 'device', and 'context'
1310 # parameters: ([hash])
1311 # returns: (oba_index)
1312 # returns: (M1_XYZ_vector, M2_XYZ_vector)
1313 sub oba_index {
1314  
1315 # get parameters
1316 0 ▶ my ($self, $hash) = @_;
Subroutine oba_index: not called CC=22 SCAR=62.3
Pod documented
1317  
1318 # local variables
1319 0 my ($sample, $dev, $mwv, $wps, $wpdata, $context1, $context2, $m1, $m2, @xyz1, @xyz2, $nm, $color);
1320  
1321 # if 'sample' defined
1322 0 ▶ if (defined($hash->{'sample'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'sample'}) { } 0 0 0
1323
1324 # get sample from hash
1325 0 $sample = $hash->{'sample'};
1326
1327 # if valid sample number
1328 0 ▶ if (Scalar::Util::looks_like_number($sample) && $sample == int($sample) && $sample > 0 && $sample <= $#{$self->[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($sample) and $sample == int $sample and $sample > 0 and $sample <= $#{$$self[1];}) { } 0 0 0
Condition0%0/9
&Scalar::Util::looks_like_number($sample) and $sample == int $sample and $sample > 0 and $sample <= $#{$$self[1];}
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($sample) and $sample == int $sample and $sample > 0
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($sample) and $sample == int $sample
!ll&&!rl&&r
000
MC/DC0%0/4
&Scalar::Util::looks_like_number($sample) and $sample == int $sample and $sample > 0 and $sample <= $#{$$self[1];}
&Scalar::Util::looks_like_number($sample) $sample == int $sample $sample > 0 $sample <= $#{$$self[1];}
Truth table0%0/5
A and B and C and D
A= &Scalar::Util::looks_like_number($sample)B= $sample == int $sampleC= $sample > 0D= $sample <= $#{$$self[1];}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1329
1330 # get sample data row
1331 0 $wpdata = $self->[1][$sample];
1332
1333 } else {
1334
1335 # warn
1336 0 warn('invalid sample number');
1337
1338 # return empty
1339 0 return();
1340
1341 }
1342
1343 } else {
1344
1345 # if device data (using 'device' context)
1346 0 ▶ if ($dev = device($self, {'context' => $hash->{'device'}})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dev = device($self, {'context', $hash->{'device'}})) { } 0 0 0
1347
1348 # set media white device value (255 if RGB, 0 otherwise)
1349 0 ▶ $mwv = ($self->[1][0][$dev->[0]] =~ m/RGB_R$/) ? 255 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$dev->[0]] =~ /RGB_R$/ ? : 0 0 0
1350
1351 # if paper white samples found
1352 0 ▶ if ($wps = find($self, sub {@_ == grep {$_ == $mwv} @_}, [], $dev)) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($wps = find($self, sub { @_ == grep({$_ == $mwv;} @_); } , scalar [], $dev)) { } 0 0 0
1353
1354 # add average paper white sample row
1355 0 add_avg($self, $wps);
1356
1357 # get sample data row
1358 0 $wpdata = pop(@{$self->[1]});
1359
1360 } else {
1361
1362 # warn
1363 0 warn('no paper white samples');
1364
1365 # return empty
1366 0 return();
1367
1368 }
1369
1370 } else {
1371
1372 # warn
1373 0 warn('no sample value or device data');
1374
1375 # return empty
1376 0 return();
1377
1378 }
1379
1380 }
1381  
1382 # if 'context' defined
1383 0 ▶ if (defined($hash->{'context'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'context'}) { } 0 0 0
1384
1385 # if context an array reference containing two scalars
1386 0 ▶ if (ref($hash->{'context'}) eq 'ARRAY' && ! ref($hash->{'context'}->[0]) && ! ref($hash->{'context'}->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{'context'} eq 'ARRAY' and not ref $hash->{'context'}[0] and not ref $hash->{'context'}[1]) { } 0 0 0
Condition0%0/6
ref $hash->{"context"} eq "ARRAY" and not ref $hash->{"context"}[0] and not ref $hash->{"context"}[1]
!ll&&!rl&&r
000
ref $hash->{"context"} eq "ARRAY" and not ref $hash->{"context"}[0]
!ll&&!rl&&r
000
MC/DC0%0/3
ref $hash->{"context"} eq "ARRAY" and not ref $hash->{"context"}[0] and not ref $hash->{"context"}[1]
ref $hash->{"context"} eq "ARRAY" not ref $hash->{"context"}[0] not ref $hash->{"context"}[1]
Truth table0%0/4
A and not(B) and not(C)
A= ref $hash->{"context"} eq "ARRAY"B= not ref $hash->{"context"}[0]C= not ref $hash->{"context"}[1]
ABCresult
0XX0
10X0
1100
1111
1387
1388 # get specified 'M1' context
1389 0 $context1 = $hash->{'context'}->[0];
1390
1391 # get specified 'M2' context
1392 0 $context2 = $hash->{'context'}->[1];
1393
1394 } else {
1395
1396 # warn
1397 0 warn('OBA context is an array reference containing M1 and M2 contexts');
1398
1399 # return empty
1400 0 return();
1401
1402 }
1403
1404 } else {
1405
1406 # use standard 'M1' context
1407 0 $context1 = 'M1_Measurement';
1408
1409 # use standard 'M2' context
1410 0 $context2 = 'M2_Measurement';
1411
1412 }
1413  
1414 # if M1 and M2 spectral data
1415 0 ▶ if (($m1 = spectral($self, {'context' => $context1})) && ($m2 = spectral($self, {'context' => $context2}))) {
Branch: 3 branches
BranchTrueFalseTotal
if ($m1 = spectral($self, {'context', $context1}) and $m2 = spectral($self, {'context', $context2})) { } 0 0 0
elsif ($m1 = xyz($self, {'context', $context1}) and $m2 = xyz($self, {'context', $context2})) { } 0 0 0
elsif ($m1 = lab($self, {'context', $context1}) and $m2 = lab($self, {'context', $context2})) { } 0 0 0
Condition0%0/3
$m1 = spectral($self, {"context", $context1}) and $m2 = spectral($self, {"context", $context2})
!ll&&!rl&&r
000
MC/DC0%0/2
$m1 = spectral($self, {"context", $context1}) and $m2 = spectral($self, {"context", $context2})
$m1 = spectral($self, {"context", $context1}) $m2 = spectral($self, {"context", $context2})
Truth table0%0/3
A and B
A= $m1 = spectral($self, {"context", $context1})B= $m2 = spectral($self, {"context", $context2})
ABresult
0X0
100
111
1416
1417 # get spectral range
1418 0 $nm = nm($self, {'context' => $context1});
1419
1420 # if increment is 10 or 20 nm
1421 0 ▶ if ($nm->[2] == 10 || $nm->[2] == 20) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nm->[2] == 10 or $nm->[2] == 20) { } 0 0 0
Condition0%0/3
$nm->[2] == 10 or $nm->[2] == 20
l!l&&r!l&&!r
000
MC/DC0%0/2
$nm->[2] == 10 or $nm->[2] == 20
$nm->[2] == 10 $nm->[2] == 20
Truth table0%0/3
A or B
A= $nm->[2] == 10B= $nm->[2] == 20
ABresult
1X1
011
000
1422
1423 # make ASTM color object
1424 0 $color = ICC::Support::Color->new({'illuminant' => 'D50', 'increment' => $nm->[2]});
1425
1426 } else {
1427
1428 # make CIE color object
1429 0 $color = ICC::Support::Color->new({'illuminant' => ['CIE', 'D50'], 'increment' => $nm->[2]});
1430
1431 }
1432
1433 # compute M1 and M2 XYZ values
1434 0 @xyz1 = $color->transform(@{$wpdata}[@{$m1}]);
1435 0 @xyz2 = $color->transform(@{$wpdata}[@{$m2}]);
1436
1437 # if M1 and M2 XYZ data
1438 ▶ } elsif (($m1 = xyz($self, {'context' => $context1})) && ($m2 = xyz($self, {'context' => $context2}))) {
Condition0%0/3
$m1 = xyz($self, {"context", $context1}) and $m2 = xyz($self, {"context", $context2})
!ll&&!rl&&r
000
MC/DC0%0/2
$m1 = xyz($self, {"context", $context1}) and $m2 = xyz($self, {"context", $context2})
$m1 = xyz($self, {"context", $context1}) $m2 = xyz($self, {"context", $context2})
Truth table0%0/3
A and B
A= $m1 = xyz($self, {"context", $context1})B= $m2 = xyz($self, {"context", $context2})
ABresult
0X0
100
111
1439
1440 # get M1 and M2 XYZ values (assumes D50 illumination)
1441 0 @xyz1 = @{$wpdata}[@{$m1}];
1442 0 @xyz2 = @{$wpdata}[@{$m2}];
1443
1444 # if M1 and M2 L*a*b* data
1445 ▶ } elsif (($m1 = lab($self, {'context' => $context1})) && ($m2 = lab($self, {'context' => $context2}))) {
Condition0%0/3
$m1 = lab($self, {"context", $context1}) and $m2 = lab($self, {"context", $context2})
!ll&&!rl&&r
000
MC/DC0%0/2
$m1 = lab($self, {"context", $context1}) and $m2 = lab($self, {"context", $context2})
$m1 = lab($self, {"context", $context1}) $m2 = lab($self, {"context", $context2})
Truth table0%0/3
A and B
A= $m1 = lab($self, {"context", $context1})B= $m2 = lab($self, {"context", $context2})
ABresult
0X0
100
111
1446
1447 # compute M1 and M2 XYZ values (D50 illumination)
1448 0 @xyz1 = ICC::Shared::_Lab2XYZ(@{$wpdata}[@{$m1}], ICC::Shared::D50);
1449 0 @xyz2 = ICC::Shared::_Lab2XYZ(@{$wpdata}[@{$m2}], ICC::Shared::D50);
1450
1451 } else {
1452
1453 # warn
1454 0 warn('M1 and M2 data required for OBA index');
1455
1456 # return empty
1457 0 return();
1458
1459 }
1460  
1461 # return array (XYZ media white points) or scalar (OBA index)
1462 0 ▶ return(wantarray ? (\@xyz1, \@xyz2) : ($xyz1[2] - $xyz2[2])/82.49);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1463  
1464 }
1465  
1466 # get chromatic adaptation transform (CAT) object
1467 # a CAT is optionally created when adding XYZ data
1468 # optional hash contains supplementary parameters
1469 # parameters: ([hash])
1470 # returns: (CAT_object)
1471 sub cat {
1472  
1473 # get parameters
1474 0 ▶ my ($self, $hash) = @_;
Subroutine cat: not called CC=5 SCAR=34.0
Pod documented
1475  
1476 # local variables
1477 0 my ($cols, $cat);
1478  
1479 # get column slice, adding optional context prefix
1480 0 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(XYZ_X XYZ_Y XYZ_Z));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 0 0 0
1481  
1482 # return if slice undefined
1483 0 ▶ return() if (! defined($cols));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cols 0 0 0
1484  
1485 # get CAT or illuminant
1486 0 $cat = $self->[2][2][$cols->[0]];
1487  
1488 # return CAT if defined
1489 0 ▶ return((defined($cat) && UNIVERSAL::isa($cat, 'ICC::Profile::matf')) ? $cat : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $cat && UNIVERSAL::isa($cat, 'ICC::Profile::matf') ? : 0 0 0
Condition0%0/3
defined $cat and UNIVERSAL::isa($cat, "ICC::Profile::matf")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cat and UNIVERSAL::isa($cat, "ICC::Profile::matf")
defined $cat UNIVERSAL::isa($cat, "ICC::Profile::matf")
Truth table0%0/3
A and B
A= defined $catB= UNIVERSAL::isa($cat, "ICC::Profile::matf")
ABresult
0X0
100
111
1490  
1491 }
1492  
1493 # get Color object
1494 # a Color object is created when adding XYZ data from spectral data
1495 # optional hash contains supplementary parameters
1496 # parameters: ([hash])
1497 # returns: (Color_object)
1498 sub color {
1499  
1500 # get parameters
1501 0 ▶ my ($self, $hash) = @_;
Subroutine color: not called CC=5 SCAR=34.0
Pod documented
1502  
1503 # local variables
1504 0 my ($cols, $color);
1505  
1506 # get column slice, adding optional context prefix
1507 0 ▶ $cols = cols($self, map {defined($hash->{'context'}) ? "$hash->{'context'}|$_" : $_} qw(XYZ_X XYZ_Y XYZ_Z));
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'context'} ? : 0 0 0
1508  
1509 # return if slice undefined
1510 0 ▶ return() if (! defined($cols));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cols 0 0 0
1511  
1512 # get CAT or illuminant
1513 0 $color = $self->[2][1][$cols->[0]];
1514  
1515 # return CAT if defined
1516 0 ▶ return((defined($color) && UNIVERSAL::isa($color, 'ICC::Support::Color')) ? $color : ());
Branch: 1 branch
BranchTrueFalseTotal
defined $color && UNIVERSAL::isa($color, 'ICC::Support::Color') ? : 0 0 0
Condition0%0/3
defined $color and UNIVERSAL::isa($color, "ICC::Support::Color")
!ll&&!rl&&r
000
MC/DC0%0/2
defined $color and UNIVERSAL::isa($color, "ICC::Support::Color")
defined $color UNIVERSAL::isa($color, "ICC::Support::Color")
Truth table0%0/3
A and B
A= defined $colorB= UNIVERSAL::isa($color, "ICC::Support::Color")
ABresult
0X0
100
111
1517  
1518 }
1519  
1520 # append rows to data array
1521 # data matrix is the 2-D array of data values to be appended
1522 # column slice is a reference to an array of data matrix column indices
1523 # parameters: (data_matrix, [column_slice])
1524 # returns: (row_slice)
1525 sub add_rows {
1526  
1527 # get parameters
1528 0 ▶ my ($self, $matrix, $cols) = @_;
Subroutine add_rows: not called CC=3 SCAR=24.8
Pod documented
1529  
1530 # set offset to upper index + 1, or 0 if a new object (row 0 is empty)
1531 0 ▶ my $offset = $#{$self->[1]} || @{$self->[1][0]} ? $#{$self->[1]} + 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$#{$$self[1];} || @{$self->[1][0];} ? : 0 0 0
Condition0%0/3
$#{$$self[1];} or @{$self->[1][0];}
l!l&&r!l&&!r
000
MC/DC0%0/2
$#{$$self[1];} or @{$self->[1][0];}
$#{$$self[1];} @{$self->[1][0];}
Truth table0%0/3
A or B
A= $#{$$self[1];}B= @{$self->[1][0];}
ABresult
1X1
011
000
1532  
1533 # call 'splice_rows'
1534 0 splice_rows($self, $offset, 0, $matrix, $cols);
1535  
1536 # return row slice
1537 0 return([$offset .. ($offset + $#{$matrix})]);
1538  
1539 }
1540  
1541 # append columns to data array
1542 # data matrix is the 2-D array of data values to be appended
1543 # header is a reference to an array of DATA_FORMAT keywords
1544 # parameters: (data_matrix, [header])
1545 # returns: (column_slice)
1546 sub add_cols {
1547  
1548 # get parameters
1549 0 ▶ my ($self, $matrix, $header) = @_;
Subroutine add_cols: not called CC=9 SCAR=45.0
Pod documented
1550  
1551 # verify matrix a 2-D array or Math::Matrix object
1552 0 ▶ (ref($matrix) eq 'ARRAY' && ref($matrix->[0]) eq 'ARRAY') || (UNIVERSAL::isa($matrix, 'Math::Matrix')) || croak ('invalid matrix parameter');
Branch: 1 branch
BranchTrueFalseTotal
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix") or croak("invalid matrix parameter") 0 0 0
Condition0%0/6
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix")
l!l&&r!l&&!r
000
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix")
ref $matrix eq "ARRAY" ref $matrix->[0] eq "ARRAY" UNIVERSAL::isa($matrix, "Math::Matrix")
Truth table0%0/5
A and B or C
A= ref $matrix eq "ARRAY"B= ref $matrix->[0] eq "ARRAY"C= UNIVERSAL::isa($matrix, "Math::Matrix")
ABCresult
11X1
0X11
1011
0X00
1000
1553  
1554 # if header supplied
1555 0 ▶ if (defined($header)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $header) 0 0 0
1556
1557 # verify header is 1-D array of scalars
1558 0 ▶ (ref($header) eq 'ARRAY' && @{$header} == grep {! ref()} @{$header}) || croak('invalid header parameter');
Branch: 1 branch
BranchTrueFalseTotal
ref $header eq "ARRAY" and @{$header;} == grep({not ref $_;} @{$header;}) or croak("invalid header parameter") 0 0 0
Condition0%0/3
ref $header eq "ARRAY" and @{$header;} == grep({not ref $_;} @{$header;})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $header eq "ARRAY" and @{$header;} == grep({not ref $_;} @{$header;})
ref $header eq "ARRAY" @{$header;} == grep({not ref $_;} @{$header;})
Truth table0%0/3
A and B
A= ref $header eq "ARRAY"B= @{$header;} == grep({not ref $_;} @{$header;})
ABresult
0X0
100
111
1559
1560 # verify header and matrix have same number of columns
1561 0 ▶ (@{$header} == @{$matrix->[0]}) || croak('header and matrix have different number of columns');
Branch: 1 branch
BranchTrueFalseTotal
@{$header;} == @{$matrix->[0];} or croak("header and matrix have different number of columns") 0 0 0
1562
1563 # add header to matrix
1564 0 $matrix = [$header, @{$matrix}];
1565
1566 }
1567  
1568 # warn if matrix and object have different number of rows
1569 0 ▶ (@{$matrix} == @{$self->[1]}) || carp('matrix and object have different number of rows');
Branch: 1 branch
BranchTrueFalseTotal
@{$matrix;} == @{$self->[1];} or carp("matrix and object have different number of rows") 0 0 0
1570  
1571 # set offset to upper index + 1
1572 0 my $offset = $#{$self->[1][0]} + 1;
1573  
1574 # call 'splice_cols'
1575 0 splice_cols($self, $offset, 0, $matrix);
1576  
1577 # return column slice
1578 0 return([$offset .. ($offset + $#{$matrix->[0]})]);
1579  
1580 }
1581  
1582 # add average sample
1583 # assumes device values (if any) are same for each sample
1584 # averages measurement values - spectral, XYZ, L*a*b* or density
1585 # L*a*b* values are converted to xyz for averaging, then back to L*a*b*
1586 # density values are converted to reflectance for averaging, then back to density
1587 # returns row slice of the appended average sample
1588 # parameters: (row_slice, [hash])
1589 # returns: (row_slice)
1590 sub add_avg {
1591  
1592 # get parameters
1593 0 ▶ my ($self, $rows, $hash) = @_;
Subroutine add_avg: not called CC=5 SCAR=34.0
Pod documented
1594  
1595 # local variables
1596 0 my ($c1, $c2, $c3, @id, @name);
1597  
1598 # flatten row slice
1599 0 $rows = ICC::Shared::flatten($rows);
1600  
1601 # resolve empty row slice
1602 0 ▶ $rows = [1 .. $#{$self->[1]}] if (@{$rows} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @{$rows;} == 0 0 0 0
1603  
1604 # get averaging groups
1605 0 ($c1, $c2, $c3) = _avg_groups($self, $hash);
1606  
1607 # for each format field
1608 0 for my $i (0 .. $#{$self->[1][0]}) {
1609
1610 # add column if SAMPLE_ID field
1611 0 ▶ push(@id, $i) if ($self->[1][0][$i] =~ m/^(?:.*\|)?(?:SAMPLE_ID|SampleID)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /^(?:.*\|)?(?:SAMPLE_ID|SampleID)$/ 0 0 0
1612
1613 # add column if SAMPLE_NAME field
1614 0 ▶ push(@name, $i) if ($self->[1][0][$i] =~ m/^(?:.*\|)?SAMPLE_NAME$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /^(?:.*\|)?SAMPLE_NAME$/ 0 0 0
1615
1616 }
1617  
1618 # return average sample
1619 0 return([_add_avg($self, $rows, $c1, $c2, $c3, \@id, \@name, $hash)]);
1620  
1621 }
1622  
1623 # add format keys
1624 # keys are appended to row 0 of the data array
1625 # note: format_keys is a list of scalars and/or array references
1626 # note: format_keys are saved as given, with or without context
1627 # parameters: (format_keys)
1628 # returns: (column_slice)
1629 sub add_fmt {
1630  
1631 # get parameters
1632 16 ▶ my $self = shift();
Subroutine add_fmt: called CC=2 SCAR=6.9
Pod documented
1633  
1634 # local variables
1635 16 my (@keys, $i, %fmt);
1636  
1637 # flatten format key list
1638 16 @keys = @{ICC::Shared::flatten(@_)};
1639  
1640 # get upper column index
1641 16 $i = $#{$self->[1][0]};
1642  
1643 # make format lookup hash of existing keys
1644 16 %fmt = map {$self->[1][0][$_], $_} (0 .. $#{$self->[1][0]});
1645  
1646 # warn if duplicate keys
1647 16 ▶ warn('adding duplicate format key(s)') if (grep {exists($fmt{$_})} @keys);
Branch: 1 branch
BranchTrueFalseTotal
if grep {exists $fmt{$_};} @keys 0 16 16
1648  
1649 # push format keys onto format row
1650 16 push(@{$self->[1][0]}, @keys);
1651  
1652 # return slice array reference
1653 16 return([$i + 1 .. $#{$self->[1][0]}]);
1654  
1655 }
1656  
1657 # append CTV data to data array
1658 # computed from L*a*b* data, XYZ data, or spectral data
1659 # if CTV data already exists, return those slices
1660 # adds L*a*b* data, and XYZ data if missing
1661 # parameters: ([hash])
1662 # returns: (column_slice)
1663 sub add_ctv {
1664  
1665 # get parameters
1666 0 ▶ my ($self, $hash) = @_;
Subroutine add_ctv: not called CC=26 SCAR=65.5
Pod documented
1667  
1668 # local variables
1669 0 my ($context, $added, $cols, $Lab, $color);
1670 0 my ($iwtpt, $WPxyz, @wtpt, $dev, $mwv, $coef, @Ls);
1671 0 my ($den, $a, $b, $c, $d, $e, $f, $mat);
1672  
1673 # get base context
1674 0 $context = $hash->{'context'};
1675  
1676 # get added context
1677 0 ▶ $added = defined($hash->{'added'}) ? $hash->{'added'} : $context;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'added'} ? : 0 0 0
1678  
1679 # return column slice if CTV data already exists
1680 0 ▶ return($cols) if ($cols = _cols($self, map {defined($added) ? "$added|$_" : $_} qw(CTV)));
Branch: 2 branches
BranchTrueFalseTotal
if $cols = _cols($self, map({defined $added ? "$added|$_" : $_;} "CTV")) 0 0 0
defined $added ? : 0 0 0
1681  
1682 # if L*a*b* exists, or is added
1683 0 ▶ if ($Lab = (_cols($self, map {defined($context) ? "$context|$_" : $_} qw(LAB_L LAB_A LAB_B)) || add_lab($self, $hash))) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Lab = _cols($self, map({defined $context ? "$context|$_" : $_;} 'LAB_L', 'LAB_A', 'LAB_B')) || add_lab($self, $hash)) { } 0 0 0
defined $context ? : 0 0 0
Condition0%0/3
_cols($self, map({defined $context ? "$context|$_" : $_;} 'LAB_L', 'LAB_A', 'LAB_B')) || add_lab($self, $hash)
l!l&&r!l&&!r
000
MC/DC0%0/2
_cols($self, map({defined $context ? "$context|$_" : $_;} 'LAB_L', 'LAB_A', 'LAB_B')) || add_lab($self, $hash)
_cols($self, map({defined $context ? "$context|$_" : $_;} 'LAB_L', 'LAB_A', 'LAB_B')) add_lab($self, $hash)
Truth table0%0/3
A || B
A= _cols($self, map({defined $context ? "$context|$_" : $_;} 'LAB_L', 'LAB_A', 'LAB_B'))B= add_lab($self, $hash)
ABresult
1X1
011
000
1684
1685 # get L*a*b* colorimetry hash
1686 0 $color = $self->[2][6][$Lab->[0]];
1687
1688 # for each possible colorimetry key
1689 0 for my $key (qw(illuminant observer increment bandpass cat)) {
1690
1691 # if key is specified
1692 0 ▶ if (defined($hash->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{$key}) 0 0 0
1693
1694 # if YAML strings differ
1695 0 ▶ if (YAML::Tiny::Dump($hash->{$key}) ne YAML::Tiny::Dump($color->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (YAML::Tiny::Dump($hash->{$key}) ne YAML::Tiny::Dump($color->{$key})) 0 0 0
1696
1697 # print warning
1698 0 warn("$key parameter differs from source");
1699
1700 }
1701
1702 }
1703
1704 }
1705
1706 # if 'context' and 'added' keys are undefined, and L*a*b* source has context
1707 0 ▶ if (! defined($added) && $self->[1][0][$Lab->[0]] =~ m/^(.*)\|/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $added and $self->[1][0][$Lab->[0]] =~ /^(.*)\|/) 0 0 0
Condition0%0/3
not defined $added and $self->[1][0][$Lab->[0]] =~ /^(.*)\|/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $added and $self->[1][0][$Lab->[0]] =~ /^(.*)\|/
not defined $added $self->[1][0][$Lab->[0]] =~ /^(.*)\|/
Truth table0%0/3
not(A) and B
A= not defined $addedB= $self->[1][0][$Lab->[0]] =~ /^(.*)\|/
ABresult
0X0
100
111
1708
1709 # set 'added' to L*a*b* context
1710 0 $added = $1;
1711
1712 }
1713
1714 # add CTV columns slice
1715 0 ▶ $cols = add_fmt($self, map {defined($added) ? "$added|$_" : $_} qw(CTV));
Branch: 1 branch
BranchTrueFalseTotal
defined $added ? : 0 0 0
1716
1717 # get supplied illuminant white point
1718 0 $iwtpt = $hash->{'iwtpt'};
1719
1720 # if supplied illuminant white point is valid
1721 0 ▶ if (defined($iwtpt) && (3 == grep {defined() && ! ref() && $_ > 0} @{$iwtpt})) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $iwtpt and 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})) { } 0 0 0
elsif (3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$$self[2][2];}[@{$Lab;}])) { } 0 0 0
defined $_ and not ref $_ and $_ > 0 0 0 0
Condition0%0/6
defined $iwtpt and 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})
!ll&&!rl&&r
000
defined $_ and not ref $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $iwtpt and 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})
defined $iwtpt 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})
MC/DC0%0/2
defined $_ and not ref $_
defined $_ not ref $_
Truth table0%0/3
A and B
A= defined $iwtptB= 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $_B= not ref $_
ABresult
0X0
100
111
1722
1723 # use it
1724 0 $WPxyz = $iwtpt;
1725
1726 # if XYZ illuminant white point is valid
1727 0 ▶ } elsif (3 == grep {defined() && ! ref() && $_ > 0} @{$self->[2][2]}[@{$Lab}]) {
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and not ref $_ and $_ > 0 0 0 0
Condition0%0/3
defined $_ and not ref $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and not ref $_
defined $_ not ref $_
Truth table0%0/3
A and not(B)
A= defined $_B= not ref $_
ABresult
0X0
100
111
1728
1729 # use it
1730 0 $WPxyz = [@{$self->[2][2]}[@{$Lab}]];
1731
1732 } else {
1733
1734 # use D50
1735 0 $WPxyz = ICC::Shared::D50;
1736
1737 }
1738
1739 # if media white point undefined in colorimetry array
1740 0 ▶ if (! defined($self->[2][3][$Lab->[0]])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->[2][3][$Lab->[0]]) 0 0 0
1741
1742 # compute media white point or return undefined
1743 0 ▶ (_mediaWP($self, $Lab, $hash)) || return();
Branch: 1 branch
BranchTrueFalseTotal
_mediaWP($self, $Lab, $hash) or return () 0 0 0
1744
1745 }
1746
1747 # get media white point (Lx, Ly, Lz)
1748 0 @wtpt = ICC::Shared::_xyz2Lxyz($self->[2][3][$Lab->[0]]/$WPxyz->[0], $self->[2][3][$Lab->[1]]/$WPxyz->[1], $self->[2][3][$Lab->[2]]/$WPxyz->[2]);
1749
1750 # get device column slice
1751 0 $dev = device($self, {'context' => $hash->{'device'}});
1752
1753 # set media white device value (255 if RGB, 0 otherwise)
1754 0 ▶ $mwv = ($self->[1][0][$dev->[0]] =~ m/RGB_R$/) ? 255 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$dev->[0]] =~ /RGB_R$/ ? : 0 0 0
1755
1756 # set origin
1757 0 $self->[2][0][$cols->[0]] = $Lab;
1758
1759 # save media white CTV (0)
1760 0 $self->[2][3][$cols->[0]] = 0;
1761
1762 # save colorimetry hash
1763 0 @{$self->[2][6]}[$cols->[0]] = $color;
1764
1765 # get coefficient array
1766 0 ▶ $coef = defined($hash->{'coef'}) ? $hash->{'coef'} : [1, 1, 1, 0, 0, 0];
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'coef'} ? : 0 0 0
1767
1768 # compute denominator
1769 0 $den = $coef->[0]**2 + $coef->[1]**2 + $coef->[2]**2;
1770
1771 # compute matrix elements
1772 0 $a = ($coef->[0]**2 + $coef->[4]**2 + $coef->[5]**2)/$den;
1773 0 $b = ($coef->[1]**2 + $coef->[3]**2 + $coef->[5]**2)/$den;
1774 0 $c = ($coef->[2]**2 + $coef->[3]**2 + $coef->[4]**2)/$den;
1775 0 $d = -$coef->[5]**2/$den;
1776 0 $e = -$coef->[4]**2/$den;
1777 0 $f = -$coef->[3]**2/$den;
1778
1779 # make Mahalanobis matrix
1780 0 $mat = [
1781 [$a, $d, $e],
1782 [$d, $b, $f],
1783 [$e, $f, $c]
1784 ];
1785
1786 # bless the object
1787 0 bless($mat, 'Math::Matrix');
1788
1789 # for each sample
1790 0 for my $i (1 .. $#{$self->[1]}) {
1791
1792 # if all device channels are white
1793 0 ▶ if (@{$dev} == grep {$_ == $mwv} @{$self->[1][$i]}[@{$dev}]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$dev;} == grep({$_ == $mwv;} @{$$self[1][$i];}[@{$dev;}])) { } 0 0 0
1794
1795 # save CTV (0)
1796 0 $self->[1][$i][$cols->[0]] = 0;
1797
1798 } else {
1799
1800 # compute sample Lx, Ly, Lz values
1801 0 @Ls = ICC::Shared::_Lab2Lxyz(@{$self->[1][$i]}[@{$Lab}]);
1802
1803 # save CTV (computed as Mahalanobis distance)
1804 0 $self->[1][$i][$cols->[0]] = _mahal(\@wtpt, \@Ls, $mat);
1805
1806 }
1807
1808 }
1809
1810 } else {
1811
1812 # warn
1813 0 warn('spectral, XYZ or L*a*b* data is required');
1814
1815 # return empty
1816 0 return();
1817
1818 }
1819  
1820 # return column slice
1821 0 return($cols);
1822  
1823 }
1824  
1825 # append L*a*b* data to data array
1826 # computed from XYZ data or spectral data
1827 # if L*a*b* data already exists, returns that slice
1828 # adds XYZ data, if only spectral data exists
1829 # parameter: ([hash])
1830 # returns: (column_slice)
1831 sub add_lab {
1832  
1833 # get parameters
1834 0 ▶ my ($self, $hash) = @_;
Subroutine add_lab: not called CC=21 SCAR=61.4
Pod documented
1835  
1836 # local variables
1837 0 my ($context, $added, $cols, $xyz, $color, $iwtpt, $WPxyz);
1838  
1839 # get base context
1840 0 $context = $hash->{'context'};
1841  
1842 # get added context
1843 0 ▶ $added = defined($hash->{'added'}) ? $hash->{'added'} : $context;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'added'} ? : 0 0 0
1844  
1845 # return column slice if L*a*b* data already exists
1846 0 ▶ return($cols) if ($cols = _cols($self, map {defined($added) ? "$added|$_" : $_} qw(LAB_L LAB_A LAB_B)));
Branch: 2 branches
BranchTrueFalseTotal
if $cols = _cols($self, map({defined $added ? "$added|$_" : $_;} "LAB_L", "LAB_A", "LAB_B")) 0 0 0
defined $added ? : 0 0 0
1847  
1848 # if XYZ data exists, or is added
1849 0 ▶ if ($xyz = (_cols($self, map {defined($context) ? "$context|$_" : $_} qw(XYZ_X XYZ_Y XYZ_Z)) || add_xyz($self, $hash))) {
Branch: 2 branches
BranchTrueFalseTotal
if ($xyz = _cols($self, map({defined $context ? "$context|$_" : $_;} 'XYZ_X', 'XYZ_Y', 'XYZ_Z')) || add_xyz($self, $hash)) { } 0 0 0
defined $context ? : 0 0 0
Condition0%0/3
_cols($self, map({defined $context ? "$context|$_" : $_;} 'XYZ_X', 'XYZ_Y', 'XYZ_Z')) || add_xyz($self, $hash)
l!l&&r!l&&!r
000
MC/DC0%0/2
_cols($self, map({defined $context ? "$context|$_" : $_;} 'XYZ_X', 'XYZ_Y', 'XYZ_Z')) || add_xyz($self, $hash)
_cols($self, map({defined $context ? "$context|$_" : $_;} 'XYZ_X', 'XYZ_Y', 'XYZ_Z')) add_xyz($self, $hash)
Truth table0%0/3
A || B
A= _cols($self, map({defined $context ? "$context|$_" : $_;} 'XYZ_X', 'XYZ_Y', 'XYZ_Z'))B= add_xyz($self, $hash)
ABresult
1X1
011
000
1850
1851 # get XYZ colorimetry hash
1852 0 $color = $self->[2][6][$xyz->[0]];
1853
1854 # for each possible colorimetry key
1855 0 for my $key (qw(illuminant observer increment bandpass cat)) {
1856
1857 # if key is specified
1858 0 ▶ if (defined($hash->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{$key}) 0 0 0
1859
1860 # if YAML strings differ
1861 0 ▶ if (YAML::Tiny::Dump($hash->{$key}) ne YAML::Tiny::Dump($color->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (YAML::Tiny::Dump($hash->{$key}) ne YAML::Tiny::Dump($color->{$key})) 0 0 0
1862
1863 # print warning
1864 0 warn("$key parameter differs from source");
1865
1866 }
1867
1868 }
1869
1870 }
1871
1872 # if 'context' and 'added' keys are undefined, and XYZ source has context
1873 0 ▶ if (! defined($added) && $self->[1][0][$xyz->[0]] =~ m/^(.*)\|/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $added and $self->[1][0][$xyz->[0]] =~ /^(.*)\|/) 0 0 0
Condition0%0/3
not defined $added and $self->[1][0][$xyz->[0]] =~ /^(.*)\|/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $added and $self->[1][0][$xyz->[0]] =~ /^(.*)\|/
not defined $added $self->[1][0][$xyz->[0]] =~ /^(.*)\|/
Truth table0%0/3
not(A) and B
A= not defined $addedB= $self->[1][0][$xyz->[0]] =~ /^(.*)\|/
ABresult
0X0
100
111
1874
1875 # set 'added' to XYZ context
1876 0 $added = $1;
1877
1878 }
1879
1880 # add L*a*b* columns slice
1881 0 ▶ $cols = add_fmt($self, map {defined($added) ? "$added|$_" : $_} qw(LAB_L LAB_A LAB_B));
Branch: 1 branch
BranchTrueFalseTotal
defined $added ? : 0 0 0
1882
1883 # get supplied illuminant white point
1884 0 $iwtpt = $hash->{'iwtpt'};
1885
1886 # if supplied illuminant white point is valid
1887 0 ▶ if (defined($iwtpt) && (3 == grep {defined() && ! ref() && $_ > 0} @{$iwtpt})) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $iwtpt and 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})) { } 0 0 0
elsif (3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$$self[2][2];}[@{$xyz;}])) { } 0 0 0
defined $_ and not ref $_ and $_ > 0 0 0 0
Condition0%0/6
defined $iwtpt and 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})
!ll&&!rl&&r
000
defined $_ and not ref $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $iwtpt and 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})
defined $iwtpt 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})
MC/DC0%0/2
defined $_ and not ref $_
defined $_ not ref $_
Truth table0%0/3
A and B
A= defined $iwtptB= 3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$iwtpt;})
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $_B= not ref $_
ABresult
0X0
100
111
1888
1889 # use it
1890 0 $WPxyz = $iwtpt;
1891
1892 # if XYZ illuminant white point is valid
1893 0 ▶ } elsif (3 == grep {defined() && ! ref() && $_ > 0} @{$self->[2][2]}[@{$xyz}]) {
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and not ref $_ and $_ > 0 0 0 0
Condition0%0/3
defined $_ and not ref $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and not ref $_
defined $_ not ref $_
Truth table0%0/3
A and not(B)
A= defined $_B= not ref $_
ABresult
0X0
100
111
1894
1895 # use it
1896 0 $WPxyz = [@{$self->[2][2]}[@{$xyz}]];
1897
1898 } else {
1899
1900 # use D50
1901 0 $WPxyz = ICC::Shared::D50;
1902
1903 }
1904
1905 # set origin
1906 0 @{$self->[2][0]}[@{$cols}] = ($xyz) x 3;
1907
1908 # save illuminant white point
1909 0 @{$self->[2][2]}[@{$cols}] = @{$WPxyz};
1910
1911 # save colorimetry hash
1912 0 @{$self->[2][6]}[@{$cols}] = ($color) x 3;
1913
1914 # for each sample
1915 0 for my $s (1 .. $#{$self->[1]}) {
1916
1917 # compute L*a*b* values from XYZ values
1918 0 @{$self->[1][$s]}[@{$cols}] = ICC::Shared::_XYZ2Lab(@{$self->[1][$s]}[@{$xyz}], $WPxyz);
1919
1920 }
1921
1922 } else {
1923
1924 # warn
1925 0 warn('spectral or XYZ data is required');
1926
1927 # return empty
1928 0 return();
1929
1930 }
1931  
1932 # return column slice
1933 0 return($cols);
1934  
1935 }
1936  
1937 # append XYZ data to data array
1938 # computed from spectral data or L*a*b* data
1939 # if XYZ data already exists, returns that slice
1940 # default colorimetry is D50, 2 degree observer
1941 # parameters: ([hash])
1942 # returns: (column_slice)
1943 sub add_xyz {
1944  
1945 # get parameters
1946 0 ▶ my ($self, $hash) = @_;
Subroutine add_xyz: not called CC=45 SCAR=76.4
Pod documented
1947  
1948 # local variables
1949 0 my ($oba, $spec1, $spec2, $context, $added);
1950 0 my ($spec, $color, $illum, $specv, $nm, $cols);
1951 0 my ($cat, $spectral, $xyz, $Lab, @WPlab, $WPxyz);
1952  
1953 # if 'oba' defined
1954 0 ▶ if (defined($hash->{'oba'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'oba'}) { } 0 0 0
1955
1956 # get oba factor
1957 0 $oba = $hash->{'oba'};
1958
1959 # if 'context' defined
1960 0 ▶ if (defined($hash->{'context'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'context'}) { } 0 0 0
1961
1962 # if context an array reference containing two scalars
1963 0 ▶ if (ref($hash->{'context'}) eq 'ARRAY' && ! ref($hash->{'context'}->[0]) && ! ref($hash->{'context'}->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{'context'} eq 'ARRAY' and not ref $hash->{'context'}[0] and not ref $hash->{'context'}[1]) { } 0 0 0
Condition0%0/6
ref $hash->{"context"} eq "ARRAY" and not ref $hash->{"context"}[0] and not ref $hash->{"context"}[1]
!ll&&!rl&&r
000
ref $hash->{"context"} eq "ARRAY" and not ref $hash->{"context"}[0]
!ll&&!rl&&r
000
MC/DC0%0/3
ref $hash->{"context"} eq "ARRAY" and not ref $hash->{"context"}[0] and not ref $hash->{"context"}[1]
ref $hash->{"context"} eq "ARRAY" not ref $hash->{"context"}[0] not ref $hash->{"context"}[1]
Truth table0%0/4
A and not(B) and not(C)
A= ref $hash->{"context"} eq "ARRAY"B= not ref $hash->{"context"}[0]C= not ref $hash->{"context"}[1]
ABCresult
0XX0
10X0
1100
1111
1964
1965 # get specified 'M1' spectral slice
1966 0 $spec1 = spectral($self, {'context' => $hash->{'context'}->[0]});
1967
1968 # get specified 'M2' spectral slice
1969 0 $spec2 = spectral($self, {'context' => $hash->{'context'}->[1]});
1970
1971 # use specified 'M2' context
1972 0 $context = $hash->{'context'}->[1];
1973
1974 } else {
1975
1976 # warn
1977 0 warn('OBA context is an array reference containing M1 and M2 contexts');
1978
1979 # return empty
1980 0 return();
1981
1982 }
1983
1984 } else {
1985
1986 # get spectral slice using standard 'M1' context
1987 0 $spec1 = spectral($self, {'context' => 'M1_Measurement'});
1988
1989 # get spectral slice using standard 'M2' context
1990 0 $spec2 = spectral($self, {'context' => 'M2_Measurement'});
1991
1992 # use standard 'M2' context
1993 0 $context = 'M2_Measurement';
1994
1995 }
1996
1997 # verify spectral slices
1998 0 ▶ if (! $spec1 || ! $spec2 || $#{$spec1} != $#{$spec2}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $spec1 && $spec2 or $#{$spec1;} != $#{$spec2;}) 0 0 0
Condition0%0/6
not $spec1 && $spec2 or $#{$spec1;} != $#{$spec2;}
l!l&&r!l&&!r
000
$spec1 && $spec2
!ll&&!rl&&r
000
MC/DC0%0/3
not $spec1 && $spec2 or $#{$spec1;} != $#{$spec2;}
$spec1 $spec2 $#{$spec1;} != $#{$spec2;}
Truth table0%0/4
not(A && B) or C
A= $spec1B= $spec2C= $#{$spec1;} != $#{$spec2;}
ABCresult
0XX1
10X1
1111
1100
1999
2000 # warn
2001 0 warn('M1 and M2 spectral data required for OBA effect');
2002
2003 # return empty
2004 0 return();
2005
2006 }
2007
2008 # get added context
2009 0 ▶ $added = defined($hash->{'added'}) ? $hash->{'added'} : 'OBA';
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'added'} ? : 0 0 0
2010
2011 } else {
2012
2013 # get base context
2014 0 $context = $hash->{'context'};
2015
2016 # get added context
2017 0 ▶ $added = defined($hash->{'added'}) ? $hash->{'added'} : $context;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'added'} ? : 0 0 0
2018
2019 }
2020  
2021 # return column slice if XYZ data already exists
2022 0 ▶ return($cols) if ($cols = _cols($self, map {defined($added) ? "$added|$_" : $_} qw(XYZ_X XYZ_Y XYZ_Z)));
Branch: 2 branches
BranchTrueFalseTotal
if $cols = _cols($self, map({defined $added ? "$added|$_" : $_;} "XYZ_X", "XYZ_Y", "XYZ_Z")) 0 0 0
defined $added ? : 0 0 0
2023  
2024 # if spectral data exists
2025 0 ▶ if (test($self, 'SPECTRAL', $context)) {
Branch: 2 branches
BranchTrueFalseTotal
if (test($self, 'SPECTRAL', $context)) { } 0 0 0
elsif (test($self, 'LAB', $context)) { } 0 0 0
2026
2027 # get spectral slice
2028 0 $spec = spectral($self, {'context' => $context});
2029
2030 # add chart wavelength range to hash
2031 0 $hash->{'range'} = nm($self, {'context' => $context});
2032
2033 # make empty 'Color.pm' object
2034 0 $color = ICC::Support::Color->new();
2035
2036 # if illuminant is defined, an array reference
2037 0 ▶ if (defined($hash->{'illuminant'}) && ref($hash->{'illuminant'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'illuminant'} and ref $hash->{'illuminant'} eq 'ARRAY') { } 0 0 0
Condition0%0/3
defined $hash->{"illuminant"} and ref $hash->{"illuminant"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash->{"illuminant"} and ref $hash->{"illuminant"} eq "ARRAY"
defined $hash->{"illuminant"} ref $hash->{"illuminant"} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $hash->{"illuminant"}B= ref $hash->{"illuminant"} eq "ARRAY"
ABresult
0X0
100
111
2038
2039 # if illuminant is ['DATA'] (ProfileMaker convention)
2040 0 ▶ if (defined($hash->{'illuminant'}->[0]) && $hash->{'illuminant'}->[0] eq 'DATA') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"illuminant"}[0] and $hash->{"illuminant"}[0] eq "DATA") 0 0 0
Condition0%0/3
defined $hash->{"illuminant"}[0] and $hash->{"illuminant"}[0] eq "DATA"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash->{"illuminant"}[0] and $hash->{"illuminant"}[0] eq "DATA"
defined $hash->{"illuminant"}[0] $hash->{"illuminant"}[0] eq "DATA"
Truth table0%0/3
A and B
A= defined $hash->{"illuminant"}[0]B= $hash->{"illuminant"}[0] eq "DATA"
ABresult
0X0
100
111
2041
2042 # verify chart object contains illuminant data
2043 0 ▶ (defined($self->[0]{'illuminant'}) && ref($self->[0]{'illuminant'}) eq 'ARRAY') || croak('no illuminant data');
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[0]{"illuminant"} and ref $self->[0]{"illuminant"} eq "ARRAY" or croak("no illuminant data") 0 0 0
Condition0%0/3
defined $self->[0]{"illuminant"} and ref $self->[0]{"illuminant"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[0]{"illuminant"} and ref $self->[0]{"illuminant"} eq "ARRAY"
defined $self->[0]{"illuminant"} ref $self->[0]{"illuminant"} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $self->[0]{"illuminant"}B= ref $self->[0]{"illuminant"} eq "ARRAY"
ABresult
0X0
100
111
2044
2045 # make new chart object from illuminant data
2046 0 $illum = ICC::Support::Chart->new($self->[0]{'illuminant'});
2047
2048 # get spectral values
2049 0 ▶ ($specv = $illum->spectral([1])->[0]) || croak('illuminant chart has no spectral data');
Branch: 1 branch
BranchTrueFalseTotal
$specv = $illum->spectral([1])->[0] or croak("illuminant chart has no spectral data") 0 0 0
2050
2051 # get wavelength range
2052 0 $nm = $illum->nm();
2053
2054 # update 'illuminant' value in hash
2055 0 $hash->{'illuminant'} = [$nm, $specv];
2056
2057 }
2058
2059 # initialize object for CIE method
2060 0 ICC::Support::Color::_cie($color, $hash);
2061
2062 } else {
2063
2064 # initialize object for ASTM method
2065 0 ICC::Support::Color::_astm($color, $hash);
2066
2067 }
2068
2069 # if 'context' and 'added' keys are undefined, and spectral source has context
2070 0 ▶ if (! defined($added) && $self->[1][0][$spec->[0]] =~ m/^(.*)\|/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $added and $self->[1][0][$spec->[0]] =~ /^(.*)\|/) 0 0 0
Condition0%0/3
not defined $added and $self->[1][0][$spec->[0]] =~ /^(.*)\|/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $added and $self->[1][0][$spec->[0]] =~ /^(.*)\|/
not defined $added $self->[1][0][$spec->[0]] =~ /^(.*)\|/
Truth table0%0/3
not(A) and B
A= not defined $addedB= $self->[1][0][$spec->[0]] =~ /^(.*)\|/
ABresult
0X0
100
111
2071
2072 # set 'added' to spectral context
2073 0 $added = $1;
2074
2075 }
2076
2077 # add XYZ columns slice
2078 0 ▶ $cols = add_fmt($self, map {defined($added) ? "$added|$_" : $_} qw(XYZ_X XYZ_Y XYZ_Z));
Branch: 1 branch
BranchTrueFalseTotal
defined $added ? : 0 0 0
2079
2080 # set origin
2081 0 @{$self->[2][0]}[@{$cols}] = ($spec) x 3;
2082
2083 # save reference to Color.pm object
2084 0 @{$self->[2][1]}[@{$cols}] = ($color) x 3;
2085
2086 # if chromatic adaptation transform (cat) is specified
2087 0 ▶ if (defined($hash->{'cat'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"cat"}) 0 0 0
2088
2089 # if cat is 'matf' object
2090 0 ▶ if (UNIVERSAL::isa($hash->{'cat'}, 'ICC::Profile::matf')) {
Branch: 4 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($hash->{'cat'}, 'ICC::Profile::matf')) { } 0 0 0
elsif ($hash->{'cat'} eq 'bradford') { } 0 0 0
elsif ($hash->{'cat'} eq 'cat02') { } 0 0 0
elsif ($hash->{'cat'} eq 'quasi') { } 0 0 0
2091
2092 # use it
2093 0 $cat = $hash->{'cat'};
2094
2095 # if cat is 'bradford'
2096 } elsif ($hash->{'cat'} eq 'bradford') {
2097
2098 # make 'bradford' object
2099 0 $cat = ICC::Profile::matf->bradford($color->iwtpt());
2100
2101 # if cat is 'cat02'
2102 } elsif ($hash->{'cat'} eq 'cat02') {
2103
2104 # make 'cat02' object
2105 0 $cat = ICC::Profile::matf->cat02($color->iwtpt());
2106
2107 # if cat is 'quasi'
2108 } elsif ($hash->{'cat'} eq 'quasi') {
2109
2110 # make 'quasi' object
2111 0 $cat = ICC::Profile::matf->quasi($color->iwtpt());
2112
2113 } else {
2114
2115 # warn
2116 0 warn('invalid cat type');
2117
2118 }
2119
2120 }
2121
2122 # if cat defined
2123 0 ▶ if (defined($cat)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cat) { } 0 0 0
2124
2125 # save cat reference
2126 0 @{$self->[2][2]}[@{$cols}] = ($cat) x 3;
2127
2128 } else {
2129
2130 # save white point
2131 0 @{$self->[2][2]}[@{$cols}] = @{$color->iwtpt()};
2132
2133 }
2134
2135 # save colorimetry hash
2136 0 ▶ @{$self->[2][6]}[@{$cols}] = ({map {defined($hash->{$_}) ? ($_, $hash->{$_}) : ()} qw(illuminant observer bandpass method ibandpass imethod oba cat increment range encoding)}) x 3;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{$_} ? : 0 0 0
2137
2138 # for each sample
2139 0 for my $i (1 .. $#{$self->[1]}) {
2140
2141 # get spectral slice
2142 0 $spectral->[$i - 1] = [@{$self->[1][$i]}[@{$spec}]];
2143
2144 }
2145
2146 # transform to XYZ data (hash may contain 'encoding' key)
2147 0 $xyz = ICC::Support::Color::_trans2($color, $spectral, $hash);
2148
2149 # add OBA effect, if enabled
2150 0 ▶ _add_oba($self, $spec1, $spec2, $xyz, $oba, $hash) if $oba;
Branch: 1 branch
BranchTrueFalseTotal
if $oba 0 0 0
2151
2152 # for each sample
2153 0 for my $i (1 .. $#{$self->[1]}) {
2154
2155 # if cat defined
2156 0 ▶ if (defined($cat)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cat) { } 0 0 0
2157
2158 # set XYZ slice with cat
2159 0 @{$self->[1][$i]}[@{$cols}] = ICC::Profile::matf::_trans0($cat, @{$xyz->[$i - 1]});
2160
2161 } else {
2162
2163 # set XYZ slice
2164 0 @{$self->[1][$i]}[@{$cols}] = @{$xyz->[$i - 1]};
2165
2166 }
2167
2168 }
2169
2170 # if L*a*b* data exists
2171 } elsif (test($self, 'LAB', $context)) {
2172
2173 # warn if illuminant is specified
2174 0 ▶ (! defined($hash->{'illuminant'})) || warn('illuminant specified but no spectral data!');
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{"illuminant"} and warn "illuminant specified but no spectral data!" 0 0 0
2175
2176 # get L*a*b* slice
2177 0 ▶ $Lab = cols($self, map {defined($context) ? "$context|$_" : $_} qw(LAB_L LAB_A LAB_B));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
2178
2179 # if 'context' and 'added' keys are undefined, and L*a*b* source has context
2180 0 ▶ if (! defined($added) && $self->[1][0][$Lab->[0]] =~ m/^(.*)\|/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $added and $self->[1][0][$Lab->[0]] =~ /^(.*)\|/) 0 0 0
Condition0%0/3
not defined $added and $self->[1][0][$Lab->[0]] =~ /^(.*)\|/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $added and $self->[1][0][$Lab->[0]] =~ /^(.*)\|/
not defined $added $self->[1][0][$Lab->[0]] =~ /^(.*)\|/
Truth table0%0/3
not(A) and B
A= not defined $addedB= $self->[1][0][$Lab->[0]] =~ /^(.*)\|/
ABresult
0X0
100
111
2181
2182 # set 'added' to L*a*b* context
2183 0 $added = $1;
2184
2185 }
2186
2187 # get L*a*b* white point values
2188 0 @WPlab = @{$self->[2][2]}[@{$Lab}];
2189
2190 # use scalar values or D50
2191 0 ▶ $WPxyz = (3 == grep {defined() && ! ref() && $_ > 0} @WPlab) ? [@WPlab] : ICC::Shared::D50;
Branch: 2 branches
BranchTrueFalseTotal
3 == grep({defined $_ and not ref $_ and $_ > 0;} @WPlab) ? : 0 0 0
defined $_ and not ref $_ and $_ > 0 0 0 0
Condition0%0/3
defined $_ and not ref $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and not ref $_
defined $_ not ref $_
Truth table0%0/3
A and not(B)
A= defined $_B= not ref $_
ABresult
0X0
100
111
2192
2193 # add XYZ columns slice
2194 0 ▶ $cols = add_fmt($self, map {defined($added) ? "$added|$_" : $_} qw(XYZ_X XYZ_Y XYZ_Z));
Branch: 1 branch
BranchTrueFalseTotal
defined $added ? : 0 0 0
2195
2196 # set origin
2197 0 @{$self->[2][0]}[@{$cols}] = ($Lab) x 3;
2198
2199 # save illuminant white point
2200 0 @{$self->[2][2]}[@{$cols}] = @{$WPxyz};
2201
2202 # for each sample
2203 0 for my $s (1 .. $#{$self->[1]}) {
2204
2205 # compute XYZ values from L*a*b* values
2206 0 @{$self->[1][$s]}[@{$cols}] = ICC::Shared::_Lab2XYZ(@{$self->[1][$s]}[@{$Lab}], $WPxyz);
2207
2208 }
2209
2210 } else {
2211
2212 # warn
2213 0 warn('spectral or L*a*b* data is required');
2214
2215 # return empty
2216 0 return();
2217
2218 }
2219  
2220 # return column slice
2221 0 return($cols);
2222  
2223 }
2224  
2225 # append ISO 5-3 density data to data array
2226 # computed from spectral data only
2227 # if density data already exists, return that slice
2228 # default status is 'T', encoding is 'density'
2229 # parameters: ([hash])
2230 # returns: (column_slice)
2231 sub add_density {
2232  
2233 # get parameters
2234 0 ▶ my ($self, $hash) = @_;
Subroutine add_density: not called CC=15 SCAR=54.8
Pod documented
2235  
2236 # local variables
2237 0 my ($context, $added, $encode, $fp, $cols, $spec, $temp, $color, $spectral, $rgbv);
2238  
2239 # get base context
2240 0 $context = $hash->{'context'};
2241  
2242 # get added context
2243 0 ▶ $added = defined($hash->{'added'}) ? $hash->{'added'} : $context;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'added'} ? : 0 0 0
2244  
2245 # get encoding
2246 0 ▶ $encode = $hash->{'encoding'} // 'density';
Condition0%0/2
$hash->{"encoding"} // "density"
l!l
00
MC/DC0%0/1
$hash->{"encoding"} // "density"
$hash->{"encoding"}
Truth table0%0/2
A
A= $hash->{"encoding"}
Aresult
11
00
2247  
2248 # if invalid encoding
2249 0 ▶ if ($encode ne 'density' && $encode ne 'linear') {
Branch: 1 branch
BranchTrueFalseTotal
if ($encode ne "density" and $encode ne "linear") 0 0 0
Condition0%0/3
$encode ne "density" and $encode ne "linear"
!ll&&!rl&&r
000
MC/DC0%0/2
$encode ne "density" and $encode ne "linear"
$encode ne "density" $encode ne "linear"
Truth table0%0/3
A and B
A= $encode ne "density"B= $encode ne "linear"
ABresult
0X0
100
111
2250
2251 # warn
2252 0 warn('invalid density encoding, using \'density\'');
2253
2254 # set encoding
2255 0 $encode = 'density';
2256
2257 }
2258  
2259 # set format prefix
2260 0 ▶ $fp = $encode eq 'density' ? 'D' : 'R';
Branch: 1 branch
BranchTrueFalseTotal
$encode eq 'density' ? : 0 0 0
2261  
2262 # return column slice if density/reflectance data already exists
2263 0 ▶ return($cols) if ($cols = cols($self, map {defined($added) ? "$added|$fp$_" : "$fp$_"} qw(_RED _GREEN _BLUE _VIS)));
Branch: 2 branches
BranchTrueFalseTotal
if $cols = cols($self, map({defined $added ? "$added|$fp$_" : "$fp$_";} "_RED", "_GREEN", "_BLUE", "_VIS")) 0 0 0
defined $added ? : 0 0 0
2264  
2265 # if spectral data
2266 0 ▶ if (test($self, 'SPECTRAL', $context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (test($self, 'SPECTRAL', $context)) { } 0 0 0
2267
2268 # get spectral slice
2269 0 $spec = spectral($self, $hash);
2270
2271 # make copy of hash
2272 0 $temp = Storable::dclone($hash);
2273
2274 # add chart wavelength range to hash
2275 0 $temp->{'range'} = nm($self, $hash);
2276
2277 # make empty 'Color.pm' object
2278 0 $color = ICC::Support::Color->new();
2279
2280 # initialize object for ISO 5-3 method
2281 0 ICC::Support::Color::_iso($color, $temp);
2282
2283 # if 'context' and 'added' keys are undefined, and spectral source has context
2284 0 ▶ if (! defined($added) && $self->[1][0][$spec->[0]] =~ m/^(.*)\|/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $added and $self->[1][0][$spec->[0]] =~ /^(.*)\|/) 0 0 0
Condition0%0/3
not defined $added and $self->[1][0][$spec->[0]] =~ /^(.*)\|/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $added and $self->[1][0][$spec->[0]] =~ /^(.*)\|/
not defined $added $self->[1][0][$spec->[0]] =~ /^(.*)\|/
Truth table0%0/3
not(A) and B
A= not defined $addedB= $self->[1][0][$spec->[0]] =~ /^(.*)\|/
ABresult
0X0
100
111
2285
2286 # set 'added' to spectral context
2287 0 $added = $1;
2288
2289 }
2290
2291 # add density/reflectance columns slice
2292 0 ▶ $cols = add_fmt($self, map {defined($added) ? "$added|$fp$_" : "$fp$_"} qw(_RED _GREEN _BLUE _VIS));
Branch: 1 branch
BranchTrueFalseTotal
defined $added ? : 0 0 0
2293
2294 # set origin
2295 0 @{$self->[2][0]}[@{$cols}] = ($spec) x 4;
2296
2297 # save reference to Color.pm object
2298 0 @{$self->[2][1]}[@{$cols}] = ($color) x 4;
2299
2300 # save colorimetry hash
2301 0 ▶ @{$self->[2][6]}[@{$cols}] = ({map {defined($temp->{$_}) ? ($_, $temp->{$_}) : ()} qw(status increment range encoding)}) x 4;
Branch: 1 branch
BranchTrueFalseTotal
defined $temp->{$_} ? : 0 0 0
2302
2303 # for each sample
2304 0 for my $i (1 .. $#{$self->[1]}) {
2305
2306 # get spectral slice
2307 0 $spectral->[$i - 1] = [@{$self->[1][$i]}[@{$spec}]];
2308
2309 }
2310
2311 # set encoding
2312 0 $temp->{'encoding'} = $encode;
2313
2314 # transform to density/reflectance data (per encoding)
2315 0 $rgbv = ICC::Support::Color::_trans2($color, $spectral, $temp);
2316
2317 # for each sample
2318 0 for my $i (1 .. $#{$self->[1]}) {
2319
2320 # set data values
2321 0 @{$self->[1][$i]}[@{$cols}] = @{$rgbv->[$i - 1]};
2322
2323 }
2324
2325 } else {
2326
2327 # warn
2328 0 warn('spectral data is required');
2329
2330 # return empty
2331 0 return();
2332
2333 }
2334  
2335 # return column slice
2336 0 return($cols);
2337  
2338 }
2339  
2340 # add computed values to data array
2341 # processing is done by a user-defined function (udf)
2342 # data groups are defined by one or more column slice(s)
2343 # supported hash keys: 'element', 'sample', 'device', 'rows', 'start', 'added'
2344 # either an 'element' udf or a 'sample' udf are required, but not both
2345 # an 'element' udf computes a single value from single slice value(s)
2346 # a 'sample' udf computes all values at once from slice value array(s)
2347 # setting the 'device' flag converts RGB/CMYK/nCLR values to device values
2348 # the 'rows' parameter is the row slice computed, default is all rows
2349 # the 'start' parameter is the first column computed, default is to append
2350 # the 'added' parameter may be a scalar or an array reference
2351 # an 'added' scalar will be used as a context prefix
2352 # an 'added' array must be the same size as the columns added
2353 # parameters: (column_slice_0, column_slice_1, ... hash)
2354 # returns: (added_column_slice)
2355 sub add_udf {
2356  
2357 # local variables
2358 0 ▶ my ($self, $hash, @cs, $rows, $m, $n, @div, $udfe, $udfs);
Subroutine add_udf: not called CC=67 SCAR=84.2
Pod documented
2359 0 my (@p, @u, @s, $cx, $added);
2360  
2361 # get object reference
2362 0 $self = shift();
2363  
2364 # get parameter hash
2365 0 $hash = pop();
2366  
2367 # verify a hash reference
2368 0 ▶ (ref($hash) eq 'HASH') || croak('last parameter must be a hash reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $hash eq "HASH" or croak("last parameter must be a hash reference") 0 0 0
2369  
2370 # verify number of slices
2371 0 ▶ (@cs = @_) || croak('one or more column slices are required');
Branch: 1 branch
BranchTrueFalseTotal
@cs = or croak("one or more column slices are required") 0 0 0
2372  
2373 # get row slice, all rows by default
2374 0 ▶ $rows = defined($hash->{'rows'}) ? $hash->{'rows'} : [];
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'rows'} ? : 0 0 0
2375  
2376 # if row slice an empty array reference
2377 0 ▶ if (ref($rows) eq 'ARRAY' && @{$rows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/3
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rows eq "ARRAY" and @{$rows;} == 0
ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/3
A and B
A= ref $rows eq "ARRAY"B= @{$rows;} == 0
ABresult
0X0
100
111
2378
2379 # use all rows
2380 0 $rows = [1 .. $#{$self->[1]}];
2381
2382 } else {
2383
2384 # flatten row slice
2385 0 $rows = ICC::Shared::flatten($rows);
2386
2387 # verify row slice contents
2388 0 ▶ (@{$rows} == grep {Scalar::Util::looks_like_number($_) && int($_) == $_ && $_ > 0 && $_ <= $#{$self->[1]}} @{$rows}) || croak('invalid row slice');
Branch: 2 branches
BranchTrueFalseTotal
@{$rows;} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ > 0 and $_ <= $#{$$self[1];};} @{$rows;}) or croak("invalid row slice") 0 0 0
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ > 0 and $_ <= $#{$$self[1];} 0 0 0
Condition0%0/6
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ > 0
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($_) and int $_ == $_
!ll&&!rl&&r
000
MC/DC0%0/3
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ > 0
&Scalar::Util::looks_like_number($_) int $_ == $_ $_ > 0
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($_)B= int $_ == $_C= $_ > 0
ABCresult
0XX0
10X0
1100
1111
2389
2390 }
2391  
2392 # get starting column, append by default
2393 0 ▶ $n = defined($hash->{'start'}) ? $hash->{'start'} : $#{$self->[1][0]} + 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'start'} ? : 0 0 0
2394  
2395 # if an array reference (slice), use the first value
2396 0 ▶ $n = $n->[0] if (ref($n) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $n eq "ARRAY" 0 0 0
2397  
2398 # verify starting column
2399 0 ▶ (Scalar::Util::looks_like_number($n) && int($n) eq $n && $n >= 0) || croak('invalid \'start\' parameter');
Branch: 1 branch
BranchTrueFalseTotal
&Scalar::Util::looks_like_number($n) and int $n eq $n and $n >= 0 or croak("invalid 'start' parameter") 0 0 0
Condition0%0/6
&Scalar::Util::looks_like_number($n) and int $n eq $n and $n >= 0
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($n) and int $n eq $n
!ll&&!rl&&r
000
MC/DC0%0/3
&Scalar::Util::looks_like_number($n) and int $n eq $n and $n >= 0
&Scalar::Util::looks_like_number($n) int $n eq $n $n >= 0
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($n)B= int $n eq $nC= $n >= 0
ABCresult
0XX0
10X0
1100
1111
2400  
2401 # if 'device' flag
2402 0 ▶ if ($hash->{'device'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{"device"}) 0 0 0
2403
2404 # for each data format
2405 0 for my $i (0 .. $#{$self->[1][0]}) {
2406
2407 # set divisor to 255 for RGB data
2408 0 ▶ $div[$i] = 255 if ($self->[1][0][$i] =~ m/RGB_[RGB]$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /RGB_[RGB]$/ 0 0 0
2409
2410 # set divisor to 100 for CMYK data
2411 0 ▶ $div[$i] = 100 if ($self->[1][0][$i] =~ m/CMYK_[CMYK]$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /CMYK_[CMYK]$/ 0 0 0
2412
2413 # set divisor to 100 for nCLR data
2414 0 ▶ $div[$i] = 100 if ($self->[1][0][$i] =~ m/[2-9A-F]CLR_[1-9A-F]$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /[2-9A-F]CLR_[1-9A-F]$/ 0 0 0
2415 }
2416
2417 }
2418  
2419 # get udf CODE refs
2420 0 $udfe = $hash->{'element'};
2421 0 $udfs = $hash->{'sample'};
2422  
2423 # if both udfs defined
2424 0 ▶ if (defined($udfe) && defined($udfs)) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $udfe and defined $udfs) { } 0 0 0
elsif (defined $udfe) { } 0 0 0
elsif (defined $udfs) { } 0 0 0
Condition0%0/3
defined $udfe and defined $udfs
!ll&&!rl&&r
000
MC/DC0%0/2
defined $udfe and defined $udfs
defined $udfe defined $udfs
Truth table0%0/3
A and B
A= defined $udfeB= defined $udfs
ABresult
0X0
100
111
2425
2426 # error
2427 0 croak('both \'element\' and \'sample\' udfs are defined');
2428
2429 # if 'element' udf defined
2430 } elsif (defined($udfe)) {
2431
2432 # verify udf is a code reference
2433 0 ▶ (ref($udfe) eq 'CODE') || croak('\'element\' udf is not a CODE reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $udfe eq "CODE" or croak("'element' udf is not a CODE reference") 0 0 0
2434
2435 # for each parameter
2436 0 for my $i (0 .. $#cs) {
2437
2438 # if an array reference
2439 0 ▶ if (ref($cs[$i]) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $cs[$i] eq 'ARRAY') { } 0 0 0
elsif (not ref $cs[$i]) { } 0 0 0
2440
2441 # if first slice
2442 0 ▶ if (! defined($m)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $m) { } 0 0 0
2443
2444 # get upper index
2445 0 $m = $#{$cs[0]};
2446
2447 # compute added slice
2448 0 @s = ($n .. $n + $m);
2449
2450 } else {
2451
2452 # verify slice size
2453 0 ▶ ($#{$cs[$i]} == $m) || croak('column slices are different sizes');
Branch: 1 branch
BranchTrueFalseTotal
$#{$cs[$i];} == $m or croak("column slices are different sizes") 0 0 0
2454
2455 }
2456
2457 # verify a valid column slice
2458 0 ▶ (ref($cs[$i]) eq 'ARRAY' || @{$cs[$i]} == grep {Scalar::Util::looks_like_number($_) && int($_) == $_ && $_ >= 0 && $_ <= $#{$self->[1][0]}} @{$cs[$i]}) || croak('invalid column slice');
Branch: 2 branches
BranchTrueFalseTotal
ref $cs[$i] eq "ARRAY" or @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];}) or croak("invalid column slice") 0 0 0
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];} 0 0 0
Condition0%0/9
ref $cs[$i] eq "ARRAY" or @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];})
l!l&&r!l&&!r
000
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($_) and int $_ == $_
!ll&&!rl&&r
000
MC/DC0%0/2
ref $cs[$i] eq "ARRAY" or @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];})
ref $cs[$i] eq "ARRAY" @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];})
MC/DC0%0/3
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0
&Scalar::Util::looks_like_number($_) int $_ == $_ $_ >= 0
Truth table0%0/3
A or B
A= ref $cs[$i] eq "ARRAY"B= @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];})
ABresult
1X1
011
000
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($_)B= int $_ == $_C= $_ >= 0
ABCresult
0XX0
10X0
1100
1111
2459
2460 # if a scalar
2461 } elsif (! ref($cs[$i])) {
2462
2463 # verify a valid column index
2464 0 ▶ (Scalar::Util::looks_like_number($cs[$i]) && int($cs[$i]) == $cs[$i] && $cs[$i] >= 0 && $cs[$i] <= $#{$self->[1][0]}) || croak('invalid column index');
Branch: 1 branch
BranchTrueFalseTotal
&Scalar::Util::looks_like_number($cs[$i]) and int $cs[$i] == $cs[$i] and $cs[$i] >= 0 and $cs[$i] <= $#{$$self[1][0];} or croak("invalid column index") 0 0 0
Condition0%0/9
&Scalar::Util::looks_like_number($cs[$i]) and int $cs[$i] == $cs[$i] and $cs[$i] >= 0 and $cs[$i] <= $#{$$self[1][0];}
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($cs[$i]) and int $cs[$i] == $cs[$i] and $cs[$i] >= 0
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($cs[$i]) and int $cs[$i] == $cs[$i]
!ll&&!rl&&r
000
MC/DC0%0/4
&Scalar::Util::looks_like_number($cs[$i]) and int $cs[$i] == $cs[$i] and $cs[$i] >= 0 and $cs[$i] <= $#{$$self[1][0];}
&Scalar::Util::looks_like_number($cs[$i]) int $cs[$i] == $cs[$i] $cs[$i] >= 0 $cs[$i] <= $#{$$self[1][0];}
Truth table0%0/5
A and B and C and D
A= &Scalar::Util::looks_like_number($cs[$i])B= int $cs[$i] == $cs[$i]C= $cs[$i] >= 0D= $cs[$i] <= $#{$$self[1][0];}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2465
2466 } else {
2467
2468 # error
2469 0 croak('parameter must be a scalar or an array reference');
2470
2471 }
2472
2473 }
2474
2475 # verify at least one column slice parameter
2476 0 ▶ (defined($m)) || croak('at least one column slice is required');
Branch: 1 branch
BranchTrueFalseTotal
defined $m or croak("at least one column slice is required") 0 0 0
2477
2478 # for each sample
2479 0 for my $i (@{$rows}) {
2480
2481 # for each column index
2482 0 for my $j (0 .. $m) {
2483
2484 # for each parameter
2485 0 for my $k (0 .. $#cs) {
2486
2487 # get column index (slice -or- scalar)
2488 0 ▶ $cx = (ref($cs[$k]) eq 'ARRAY') ? $cs[$k][$j] : $cs[$k];
Branch: 1 branch
BranchTrueFalseTotal
ref $cs[$k] eq 'ARRAY' ? : 0 0 0
2489
2490 # get parameter value
2491 0 $p[$k] = $self->[1][$i][$cx];
2492
2493 # adjust device values, if divisor defined
2494 0 ▶ $p[$k] /= $div[$cx] if defined($div[$cx]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $div[$cx] 0 0 0
2495
2496 }
2497
2498 # call 'element' udf
2499 0 $self->[1][$i][$n + $j] = &$udfe(@p, $j);
2500
2501 }
2502
2503 }
2504
2505 # if 'sample' udf defined
2506 } elsif (defined($udfs)) {
2507
2508 # verify udf is a code reference
2509 0 ▶ (ref($udfs) eq 'CODE') || croak('\'sample\' udf is not a CODE reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $udfs eq "CODE" or croak("'sample' udf is not a CODE reference") 0 0 0
2510
2511 # for each parameter
2512 0 for my $i (0 .. $#cs) {
2513
2514 # verify a valid column slice
2515 0 ▶ (ref($cs[$i]) eq 'ARRAY' || @{$cs[$i]} == grep {Scalar::Util::looks_like_number($_) && int($_) == $_ && $_ >= 0 && $_ <= $#{$self->[1][0]}} @{$cs[$i]}) || croak('invalid column slice');
Branch: 2 branches
BranchTrueFalseTotal
ref $cs[$i] eq "ARRAY" or @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];}) or croak("invalid column slice") 0 0 0
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];} 0 0 0
Condition0%0/9
ref $cs[$i] eq "ARRAY" or @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];})
l!l&&r!l&&!r
000
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($_) and int $_ == $_
!ll&&!rl&&r
000
MC/DC0%0/2
ref $cs[$i] eq "ARRAY" or @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];})
ref $cs[$i] eq "ARRAY" @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];})
MC/DC0%0/3
&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0
&Scalar::Util::looks_like_number($_) int $_ == $_ $_ >= 0
Truth table0%0/3
A or B
A= ref $cs[$i] eq "ARRAY"B= @{$cs[$i];} == grep({&Scalar::Util::looks_like_number($_) and int $_ == $_ and $_ >= 0 and $_ <= $#{$$self[1][0];};} @{$cs[$i];})
ABresult
1X1
011
000
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($_)B= int $_ == $_C= $_ >= 0
ABCresult
0XX0
10X0
1100
1111
2516
2517 }
2518
2519 # verify at least one parameter
2520 0 ▶ (@cs) || croak('at least one column slice is required');
Branch: 1 branch
BranchTrueFalseTotal
@cs or croak("at least one column slice is required") 0 0 0
2521
2522 # for each sample
2523 0 for my $i (@{$rows}) {
2524
2525 # for each column slice
2526 0 for my $j (0 .. $#cs) {
2527
2528 # for each slice element
2529 0 for my $k (0 .. $#{$cs[$j]}) {
2530
2531 # get column index
2532 0 $cx = $cs[$j][$k];
2533
2534 # get parameter value
2535 0 $p[$j][$k] = $self->[1][$i][$cx];
2536
2537 # adjust device values, if divisor defined
2538 0 ▶ $p[$j][$k] /= $div[$cx] if defined($div[$cx]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $div[$cx] 0 0 0
2539
2540 }
2541
2542 }
2543
2544 # if first sample
2545 0 ▶ if (! defined($m)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $m) { } 0 0 0
2546
2547 # call 'sample' udf
2548 0 @u = &$udfs(@p);
2549
2550 # get upper index
2551 0 $m = $#u;
2552
2553 # compute added slice
2554 0 @s = ($n .. $n + $m);
2555
2556 # copy values to object
2557 0 @{$self->[1][$i]}[@s] = @u;
2558
2559 } else {
2560
2561 # call 'sample' udf
2562 0 @{$self->[1][$i]}[@s] = &$udfs(@p);
2563
2564 }
2565
2566 }
2567
2568 } else {
2569
2570 # error
2571 0 croak('no udf is defined');
2572
2573 }
2574  
2575 # get 'added' parameter, default is 'udf', could be undefined
2576 0 ▶ $added = exists($hash->{'added'}) ? $hash->{'added'} : 'udf';
Branch: 1 branch
BranchTrueFalseTotal
exists $hash->{'added'} ? : 0 0 0
2577  
2578 # if 'added' is undefined
2579 0 ▶ if (! defined($added)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $added) { } 0 0 0
elsif (not ref $added) { } 0 0 0
elsif (ref $added eq 'ARRAY' and @{$added;} == @s) { } 0 0 0
2580
2581 # if 'element' udf -or- size of first column slice equals number of added columns
2582 0 ▶ if (defined($udfe) || @{$cs[0]} == @s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $udfe or @{$cs[0];} == @s) { } 0 0 0
Condition0%0/3
defined $udfe or @{$cs[0];} == @s
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $udfe or @{$cs[0];} == @s
defined $udfe @{$cs[0];} == @s
Truth table0%0/3
A or B
A= defined $udfeB= @{$cs[0];} == @s
ABresult
1X1
011
000
2583
2584 # add data format stripping context from first column slice
2585 0 @{$self->[1][0]}[@s] = map {m/^(?:.*\|)?(.*)$/; $1} @{$self->[1][0]}[@{$cs[0]}];
2586
2587 } else {
2588
2589 # add data format as 'colxxx'
2590 0 @{$self->[1][0]}[@s] = map {"col$_"} @s;
2591
2592 }
2593
2594 # if 'added' a scalar
2595 } elsif (! ref($added)) {
2596
2597 # if 'element' udf -or- size of first column slice equals number of added columns
2598 0 ▶ if (defined($udfe) || @{$cs[0]} == @s) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $udfe or @{$cs[0];} == @s) { } 0 0 0
Condition0%0/3
defined $udfe or @{$cs[0];} == @s
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $udfe or @{$cs[0];} == @s
defined $udfe @{$cs[0];} == @s
Truth table0%0/3
A or B
A= defined $udfeB= @{$cs[0];} == @s
ABresult
1X1
011
000
2599
2600 # add data format using 'added' as context with first column slice format keys
2601 0 @{$self->[1][0]}[@s] = map {m/^(?:.*\|)?(.*)$/; "$added|$1"} @{$self->[1][0]}[@{$cs[0]}];
2602
2603 } else {
2604
2605 # add data format using 'added' as context to 'colxxx'
2606 0 @{$self->[1][0]}[@s] = map {"$added|col$_"} @s;
2607
2608 }
2609
2610 # if 'added' is an array ref and size equals number of added columns
2611 0 ▶ } elsif (ref($added) eq 'ARRAY' && @{$added} == @s) {
Condition0%0/3
ref $added eq "ARRAY" and @{$added;} == @s
!ll&&!rl&&r
000
MC/DC0%0/2
ref $added eq "ARRAY" and @{$added;} == @s
ref $added eq "ARRAY" @{$added;} == @s
Truth table0%0/3
A and B
A= ref $added eq "ARRAY"B= @{$added;} == @s
ABresult
0X0
100
111
2612
2613 # add data format using 'added' as array
2614 0 @{$self->[1][0]}[@s] = @{$added};
2615
2616 } else {
2617
2618 # error
2619 0 croak('invalid \'added\' parameter');
2620
2621 }
2622  
2623 # return added column slice
2624 0 return([@s]);
2625  
2626 }
2627  
2628 # append date column to data array
2629 # adds same date/time to each sample
2630 # supported hash keys: 'date', 'format', 'added'
2631 # parameter: ([hash])
2632 # returns: (column_slice)
2633 sub add_date {
2634  
2635 # get parameters
2636 0 ▶ my ($self, $hash) = @_;
Subroutine add_date: not called CC=9 SCAR=45.0
Pod documented
2637  
2638 # local variables
2639 0 my ($cols, $added, $date, $fmt, $str);
2640  
2641 # get added context
2642 0 $added = $hash->{'added'};
2643  
2644 # return column slice if date column already exists
2645 0 ▶ return($cols) if ($cols = _cols($self, defined($added) ? "$added|CREATED" : 'CREATED'));
Branch: 2 branches
BranchTrueFalseTotal
if $cols = _cols($self, defined $added ? "$added|CREATED" : "CREATED") 0 0 0
defined $added ? : 0 0 0
2646  
2647 # add date column slice
2648 0 ▶ $cols = add_fmt($self, defined($added) ? "$added|CREATED" : 'CREATED');
Branch: 1 branch
BranchTrueFalseTotal
defined $added ? : 0 0 0
2649  
2650 # if date supplied
2651 0 ▶ if (defined($date = $hash->{'date'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($date = $hash->{'date'})) { } 0 0 0
2652
2653 # if date is a number
2654 0 ▶ if (Scalar::Util::looks_like_number($date)) {
Branch: 2 branches
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($date)) { } 0 0 0
elsif (ref $date ne 'Time::Piece') { } 0 0 0
2655
2656 # make Time::Piece object
2657 0 $date = localtime($date);
2658
2659 # if date not a Time::Piece object
2660 } elsif (ref($date) ne 'Time::Piece') {
2661
2662 # error
2663 0 croak('invalid date parameter');
2664 }
2665
2666 } else {
2667
2668 # use 'CREATED' value from chart
2669 0 $date = created($self);
2670
2671 }
2672  
2673 # compute the date/time string (same for each sample)
2674 0 ▶ $str = defined($fmt = $hash->{'format'}) ? $date->strftime($fmt) : $date->epoch();
Branch: 1 branch
BranchTrueFalseTotal
defined($fmt = $hash->{'format'}) ? : 0 0 0
2675  
2676 # for each row
2677 0 for my $i (1 .. $#{$self->[1]}) {
2678
2679 # set the date time string
2680 0 $self->[1][$i][$cols->[0]] = $str;
2681
2682 }
2683  
2684 # return column slice
2685 0 return($cols);
2686  
2687 }
2688  
2689 # splice rows into data array
2690 # offset and length are as used by Perl's 'splice' function
2691 # data matrix is the 2-D array of data values to be spliced
2692 # column slice is a reference to an array of data matrix column indices
2693 # parameters: ([offset, [length, [data_matrix, [column_slice]]]])
2694 # returns: (removed_data_matrix)
2695 sub splice_rows {
2696  
2697 # get parameters
2698 0 ▶ my ($self, $offset, $length, $matrix, $cols) = @_;
Subroutine splice_rows: not called CC=22 SCAR=62.3
Pod documented
2699  
2700 # local variables
2701 0 my (@ix, @list, @s, $removed);
2702  
2703 # if offset supplied
2704 0 ▶ if (defined($offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) 0 0 0
2705
2706 # verify offset a scalar
2707 0 ▶ (! ref($offset) && (int($offset) == $offset)) || croak('invalid offset parameter');
Branch: 1 branch
BranchTrueFalseTotal
not ref $offset and int $offset == $offset or croak("invalid offset parameter") 0 0 0
Condition0%0/3
not ref $offset and int $offset == $offset
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $offset and int $offset == $offset
not ref $offset int $offset == $offset
Truth table0%0/3
not(A) and B
A= not ref $offsetB= int $offset == $offset
ABresult
0X0
100
111
2708
2709 }
2710  
2711 # if length supplied
2712 0 ▶ if (defined($length)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) 0 0 0
2713
2714 # verify length an integer scalar
2715 0 ▶ (! ref($length) && int($length) == $length) || croak('invalid length parameter');
Branch: 1 branch
BranchTrueFalseTotal
not ref $length and int $length == $length or croak("invalid length parameter") 0 0 0
Condition0%0/3
not ref $length and int $length == $length
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $length and int $length == $length
not ref $length int $length == $length
Truth table0%0/3
not(A) and B
A= not ref $lengthB= int $length == $length
ABresult
0X0
100
111
2716
2717 }
2718  
2719 # if matrix supplied
2720 0 ▶ if (defined($matrix)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $matrix) 0 0 0
2721
2722 # verify matrix a 2-D array or Math::Matrix object
2723 0 ▶ (ref($matrix) eq 'ARRAY' && ref($matrix->[0]) eq 'ARRAY') || (UNIVERSAL::isa($matrix, 'Math::Matrix')) || croak ('invalid matrix parameter');
Branch: 1 branch
BranchTrueFalseTotal
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix") or croak("invalid matrix parameter") 0 0 0
Condition0%0/6
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix")
l!l&&r!l&&!r
000
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix")
ref $matrix eq "ARRAY" ref $matrix->[0] eq "ARRAY" UNIVERSAL::isa($matrix, "Math::Matrix")
Truth table0%0/5
A and B or C
A= ref $matrix eq "ARRAY"B= ref $matrix->[0] eq "ARRAY"C= UNIVERSAL::isa($matrix, "Math::Matrix")
ABCresult
11X1
0X11
1011
0X00
1000
2724
2725 }
2726  
2727 # if column slice supplied
2728 0 ▶ if (defined($cols)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cols) { } 0 0 0
2729
2730 # verify column slice an array reference
2731 0 ▶ (ref($cols) eq 'ARRAY') || croak('invalid cols parameter');
Branch: 1 branch
BranchTrueFalseTotal
ref $cols eq "ARRAY" or croak("invalid cols parameter") 0 0 0
2732
2733 # verify length, offset and matrix supplied
2734 0 ▶ (defined($length) && defined($offset) && defined($matrix)) || croak('cols requires length, offset and matrix');
Branch: 1 branch
BranchTrueFalseTotal
defined $length and defined $offset and defined $matrix or croak("cols requires length, offset and matrix") 0 0 0
Condition0%0/6
defined $length and defined $offset and defined $matrix
!ll&&!rl&&r
000
defined $length and defined $offset
!ll&&!rl&&r
000
MC/DC0%0/3
defined $length and defined $offset and defined $matrix
defined $length defined $offset defined $matrix
Truth table0%0/4
A and B and C
A= defined $lengthB= defined $offsetC= defined $matrix
ABCresult
0XX0
10X0
1100
1111
2735
2736 # flatten column slice
2737 0 @ix = @{ICC::Shared::flatten($cols)};
2738
2739 # make splice list using column slice
2740 0 @list = map {@s[@ix] = @{$_}; [@s]} @{$matrix};
2741
2742 # splice the data
2743 0 $removed = [splice(@{$self->[1]}, $offset, $length, @list)];
2744
2745 } else {
2746
2747 # if matrix supplied
2748 0 ▶ if (defined($matrix)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $matrix) { } 0 0 0
2749
2750 # verify length, offset
2751 0 ▶ (defined($length) && defined($offset)) || croak('matrix requires length and offset');
Branch: 1 branch
BranchTrueFalseTotal
defined $length and defined $offset or croak("matrix requires length and offset") 0 0 0
Condition0%0/3
defined $length and defined $offset
!ll&&!rl&&r
000
MC/DC0%0/2
defined $length and defined $offset
defined $length defined $offset
Truth table0%0/3
A and B
A= defined $lengthB= defined $offset
ABresult
0X0
100
111
2752
2753 # make splice list from full matrix
2754 0 @list = map {[@{$_}]} @{$matrix};
2755
2756 # splice the data
2757 0 $removed = [splice(@{$self->[1]}, $offset, $length, @list)];
2758
2759 } else {
2760
2761 # if length supplied
2762 0 ▶ if (defined($length)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) { } 0 0 0
2763
2764 # verify offset supplied
2765 0 ▶ (defined($offset)) || croak('length requires offset');
Branch: 1 branch
BranchTrueFalseTotal
defined $offset or croak("length requires offset") 0 0 0
2766  
2767 # splice the data
2768 0 $removed = [splice(@{$self->[1]}, $offset, $length)];
2769
2770 } else {
2771
2772 # if offset supplied
2773 0 ▶ if (defined($offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) { } 0 0 0
2774
2775 # splice the data
2776 0 $removed = [splice(@{$self->[1]}, $offset)];
2777
2778 } else {
2779
2780 # get data array reference
2781 0 $removed = $self->[1];
2782
2783 # init data array
2784 0 $self->[1] = [[]];
2785
2786 # init colorimetry array
2787 0 $self->[2] = [[]];
2788
2789 }
2790
2791 }
2792
2793 }
2794
2795 }
2796  
2797 # update the SAMPLE_ID hash
2798 0 _makeSampleID($self);
2799  
2800 # return removed data
2801 0 return(bless($removed, 'Math::Matrix'));
2802  
2803 }
2804  
2805 # splice columns into data array
2806 # offset and length are as used by Perl's 'splice' function
2807 # data matrix is the 2-D array of data values to be spliced
2808 # row slice is a reference to an array of data matrix row indices
2809 # parameters: ([offset, [length, [data_matrix, [row_slice]]]])
2810 # returns: (removed_data_matrix)
2811 sub splice_cols {
2812  
2813 # get parameters
2814 0 ▶ my ($self, $offset, $length, $matrix, $rows) = @_;
Subroutine splice_cols: not called CC=37 SCAR=72.5
Pod documented
2815  
2816 # local variables
2817 0 my (@ix, @s, @filler, $removed);
2818  
2819 # if offset supplied
2820 0 ▶ if (defined($offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) 0 0 0
2821
2822 # verify offset a scalar
2823 0 ▶ (! ref($offset) && (int($offset) == $offset)) || croak('invalid offset parameter');
Branch: 1 branch
BranchTrueFalseTotal
not ref $offset and int $offset == $offset or croak("invalid offset parameter") 0 0 0
Condition0%0/3
not ref $offset and int $offset == $offset
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $offset and int $offset == $offset
not ref $offset int $offset == $offset
Truth table0%0/3
not(A) and B
A= not ref $offsetB= int $offset == $offset
ABresult
0X0
100
111
2824
2825 }
2826  
2827 # if length supplied
2828 0 ▶ if (defined($length)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) 0 0 0
2829
2830 # verify length an integer scalar
2831 0 ▶ (! ref($length) && int($length) == $length) || croak('invalid length parameter');
Branch: 1 branch
BranchTrueFalseTotal
not ref $length and int $length == $length or croak("invalid length parameter") 0 0 0
Condition0%0/3
not ref $length and int $length == $length
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $length and int $length == $length
not ref $length int $length == $length
Truth table0%0/3
not(A) and B
A= not ref $lengthB= int $length == $length
ABresult
0X0
100
111
2832
2833 }
2834  
2835 # if matrix supplied
2836 0 ▶ if (defined($matrix)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $matrix) 0 0 0
2837
2838 # verify matrix a 2-D array or Math::Matrix object
2839 0 ▶ (ref($matrix) eq 'ARRAY' && ref($matrix->[0]) eq 'ARRAY') || (UNIVERSAL::isa($matrix, 'Math::Matrix')) || croak ('invalid matrix parameter');
Branch: 1 branch
BranchTrueFalseTotal
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix") or croak("invalid matrix parameter") 0 0 0
Condition0%0/6
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix")
l!l&&r!l&&!r
000
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
ref $matrix eq "ARRAY" and ref $matrix->[0] eq "ARRAY" or UNIVERSAL::isa($matrix, "Math::Matrix")
ref $matrix eq "ARRAY" ref $matrix->[0] eq "ARRAY" UNIVERSAL::isa($matrix, "Math::Matrix")
Truth table0%0/5
A and B or C
A= ref $matrix eq "ARRAY"B= ref $matrix->[0] eq "ARRAY"C= UNIVERSAL::isa($matrix, "Math::Matrix")
ABCresult
11X1
0X11
1011
0X00
1000
2840
2841 }
2842  
2843 # if row slice supplied
2844 0 ▶ if (defined($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rows) { } 0 0 0
2845
2846 # verify row slice an array reference
2847 0 ▶ (ref($rows) eq 'ARRAY') || croak('invalid cols parameter');
Branch: 1 branch
BranchTrueFalseTotal
ref $rows eq "ARRAY" or croak("invalid cols parameter") 0 0 0
2848
2849 # verify length, offset and matrix supplied
2850 0 ▶ (defined($length) && defined($offset) && defined($matrix)) || croak('rows requires length, offset and matrix');
Branch: 1 branch
BranchTrueFalseTotal
defined $length and defined $offset and defined $matrix or croak("rows requires length, offset and matrix") 0 0 0
Condition0%0/6
defined $length and defined $offset and defined $matrix
!ll&&!rl&&r
000
defined $length and defined $offset
!ll&&!rl&&r
000
MC/DC0%0/3
defined $length and defined $offset and defined $matrix
defined $length defined $offset defined $matrix
Truth table0%0/4
A and B and C
A= defined $lengthB= defined $offsetC= defined $matrix
ABCresult
0XX0
10X0
1100
1111
2851
2852 # flatten row slice
2853 0 @ix = @{ICC::Shared::flatten($rows)};
2854
2855 # make list of matrix row refs
2856 0 @s[@ix] = @{$matrix};
2857
2858 # make filler data
2859 0 @filler = (undef) x @{$matrix->[0]};
2860
2861 # for each data row
2862 0 for my $i (0 .. $#{$self->[1]}) {
2863
2864 # if matrix data defined
2865 0 ▶ if (defined($s[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s[$i]) { } 0 0 0
2866
2867 # splice matrix data
2868 0 $removed->[$i] = [splice(@{$self->[1][$i]}, $offset, $length, @{$s[$i]})];
2869
2870 } else {
2871
2872 # splice filler data
2873 0 $removed->[$i] = [splice(@{$self->[1][$i]}, $offset, $length, @filler)];
2874
2875 }
2876
2877 }
2878
2879 # for each colorimetry row
2880 0 for my $i (0 .. $#{$self->[2]}) {
2881
2882 # splice filler data
2883 0 ▶ splice(@{$self->[2][$i]}, $offset, $length, @filler) if (defined($self->[2][$i][$offset]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->[2][$i][$offset] 0 0 0
2884
2885 }
2886
2887 } else {
2888
2889 # if matrix supplied
2890 0 ▶ if (defined($matrix)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $matrix) { } 0 0 0
2891
2892 # verify length, offset
2893 0 ▶ (defined($length) && defined($offset)) || croak('matrix requires length and offset');
Branch: 1 branch
BranchTrueFalseTotal
defined $length and defined $offset or croak("matrix requires length and offset") 0 0 0
Condition0%0/3
defined $length and defined $offset
!ll&&!rl&&r
000
MC/DC0%0/2
defined $length and defined $offset
defined $length defined $offset
Truth table0%0/3
A and B
A= defined $lengthB= defined $offset
ABresult
0X0
100
111
2894
2895 # make filler data
2896 0 @filler = (undef) x @{$matrix->[0]};
2897
2898 # for each data row
2899 0 for my $i (0 .. $#{$self->[1]}) {
2900
2901 # if matrix data defined
2902 0 ▶ if (defined($matrix->[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $matrix->[$i]) { } 0 0 0
2903
2904 # splice matrix data
2905 0 $removed->[$i] = [splice(@{$self->[1][$i]}, $offset, $length, @{$matrix->[$i]})];
2906
2907 } else {
2908
2909 # splice filler data
2910 0 $removed->[$i] = [splice(@{$self->[1][$i]}, $offset, $length, @filler)];
2911
2912 }
2913
2914 }
2915
2916 # for each colorimetry row
2917 0 for my $i (0 .. $#{$self->[2]}) {
2918
2919 # splice filler data
2920 0 ▶ splice(@{$self->[2][$i]}, $offset, $length, @filler) if (defined($self->[2][$i][$offset]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->[2][$i][$offset] 0 0 0
2921
2922 }
2923
2924 } else {
2925
2926 # if length supplied
2927 0 ▶ if (defined($length)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $length) { } 0 0 0
2928
2929 # verify offset supplied
2930 0 ▶ (defined($offset)) || croak('length requires offset');
Branch: 1 branch
BranchTrueFalseTotal
defined $offset or croak("length requires offset") 0 0 0
2931
2932 # for each data row
2933 0 for my $i (0 .. $#{$self->[1]}) {
2934
2935 # splice the data
2936 0 $removed->[$i] = [splice(@{$self->[1][$i]}, $offset, $length)];
2937
2938 }
2939
2940 # for each colorimetry row
2941 0 for my $i (0 .. $#{$self->[2]}) {
2942
2943 # splice filler data
2944 0 ▶ splice(@{$self->[2][$i]}, $offset, $length) if (defined($self->[2][$i][$offset]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->[2][$i][$offset] 0 0 0
2945
2946 }
2947
2948 } else {
2949
2950 # if offset supplied
2951 0 ▶ if (defined($offset)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $offset) { } 0 0 0
2952
2953 # for each data row
2954 0 for my $i (0 .. $#{$self->[1]}) {
2955
2956 # splice the data
2957 0 $removed->[$i] = [splice(@{$self->[1][$i]}, $offset)];
2958
2959 }
2960
2961 # for each colorimetry row
2962 0 for my $i (0 .. $#{$self->[2]}) {
2963
2964 # splice filler data
2965 0 ▶ splice(@{$self->[2][$i]}, $offset) if (defined($self->[2][$i][$offset]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->[2][$i][$offset] 0 0 0
2966
2967 }
2968
2969 } else {
2970
2971 # get data array reference
2972 0 $removed = $self->[1];
2973
2974 # init data array
2975 0 $self->[1] = [[]];
2976
2977 # init colorimetry array
2978 0 $self->[2] = [[]];
2979
2980 }
2981
2982 }
2983
2984 }
2985
2986 }
2987  
2988 # initialize SAMPLE_ID hash if no SAMPLE_ID field
2989 0 ▶ $self->[4] = {} if (0 == test($self, 'ID'));
Branch: 1 branch
BranchTrueFalseTotal
if 0 == test($self, "ID") 0 0 0
2990  
2991 # return removed data
2992 0 return(bless($removed, 'Math::Matrix'));
2993  
2994 }
2995  
2996 # remove rows from data array
2997 # parameters: (row_slice)
2998 # returns: (removed_data_matrix)
2999 sub remove_rows {
3000  
3001 # get parameters
3002 0 ▶ my ($self, $rows) = @_;
Subroutine remove_rows: not called CC=9 SCAR=45.0
Pod documented
3003  
3004 # local variables
3005 0 my ($f, $up, @r, @s, $removed);
3006  
3007 # return empty matrix if row slice undefined
3008 0 ▶ return(bless([[]], 'Math::Matrix')) if (! defined($rows));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rows 0 0 0
3009  
3010 # flatten row slice
3011 0 $f = ICC::Shared::flatten($rows);
3012  
3013 # if row slice is empty
3014 0 ▶ if (! defined($f->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $f->[0]) 0 0 0
3015
3016 # remove all rows, except row 0 (DATA_FORMAT)
3017 0 $removed = [splice(@{$self->[1]}, 1)];
3018
3019 # clear SAMPLE_ID hash
3020 0 $self->[4] = {};
3021
3022 # return removed data
3023 0 return(bless($removed, 'Math::Matrix'));
3024
3025 }
3026  
3027 # get upper row index
3028 0 $up = $#{$self->[1]};
3029  
3030 # verify row slice
3031 0 ▶ (grep {$_ != int($_) || $_ < 1 || $_ > $up} @{$f}) && carp('row slice contains invalid index value(s)');
Branch: 2 branches
BranchTrueFalseTotal
grep {$_ != int $_ or $_ < 1 or $_ > $up;} @{$f;} and carp("row slice contains invalid index value(s)") 0 0 0
$_ != int $_ or $_ < 1 or $_ > $up 0 0 0
Condition0%0/3
$_ != int $_ or $_ < 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ != int $_ or $_ < 1
$_ != int $_ $_ < 1
Truth table0%0/3
A or B
A= $_ != int $_B= $_ < 1
ABresult
1X1
011
000
3032  
3033 # initialize slice (always keep row 0)
3034 0 @s = (0);
3035  
3036 # for each row
3037 0 for my $i (1 .. $up) {
3038
3039 # if index contained in row slice
3040 0 ▶ if (grep {$i == $_} @{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$i == $_;} @{$f;}) { } 0 0 0
3041
3042 # add to slice (remove)
3043 0 push(@r, $i);
3044
3045 } else {
3046
3047 # add to slice (keep)
3048 0 push(@s, $i)
3049
3050 }
3051
3052 }
3053  
3054 # if rows to remove
3055 0 ▶ if (@r) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r) { } 0 0 0
3056
3057 # set removed data (@r)
3058 0 $removed = [@{$self->[1]}[@r]];
3059
3060 # set kept data (@s)
3061 0 $self->[1] = [@{$self->[1]}[@s]];
3062
3063 # update the SAMPLE_ID hash
3064 0 _makeSampleID($self);
3065
3066 } else {
3067
3068 # set removed data (none)
3069 0 $removed = [[]];
3070
3071 }
3072  
3073 # return removed data
3074 0 return(bless($removed, 'Math::Matrix'));
3075  
3076 }
3077  
3078 # remove columns from data array
3079 # parameters: (column_slice)
3080 # returns: (removed_data_matrix)
3081 sub remove_cols {
3082  
3083 # get parameters
3084 0 ▶ my ($self, $cols) = @_;
Subroutine remove_cols: not called CC=12 SCAR=50.5
Pod documented
3085  
3086 # local variables
3087 0 my ($f, $up, @r, @s, $removed, $kept, $color);
3088  
3089 # return empty matrix if column slice undefined
3090 0 ▶ return(bless([[]], 'Math::Matrix')) if (! defined($cols));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $cols 0 0 0
3091  
3092 # flatten column slice
3093 0 $f = ICC::Shared::flatten($cols);
3094  
3095 # if columns slice is empty
3096 0 ▶ if (! defined($f->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $f->[0]) 0 0 0
3097
3098 # copy all rows
3099 0 $removed = [@{$self->[1]}];
3100
3101 # clear data array
3102 0 $self->[1] =[[]];
3103
3104 # clear colorimetry array
3105 0 $self->[2] = [[]];
3106
3107 # clear SAMPLE_ID hash
3108 0 $self->[4] = {};
3109
3110 # return removed data
3111 0 return(bless($removed, 'Math::Matrix'));
3112
3113 }
3114  
3115 # get upper column index
3116 0 $up = $#{$self->[1][0]};
3117  
3118 # verify column slice
3119 0 ▶ (grep {$_ != int($_) || $_ < 0 || $_ > $up} @{$f}) && carp('column slice contains invalid index value(s)');
Branch: 2 branches
BranchTrueFalseTotal
grep {$_ != int $_ or $_ < 0 or $_ > $up;} @{$f;} and carp("column slice contains invalid index value(s)") 0 0 0
$_ != int $_ or $_ < 0 or $_ > $up 0 0 0
Condition0%0/3
$_ != int $_ or $_ < 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ != int $_ or $_ < 0
$_ != int $_ $_ < 0
Truth table0%0/3
A or B
A= $_ != int $_B= $_ < 0
ABresult
1X1
011
000
3120  
3121 # for each column
3122 0 for my $i (0 .. $up) {
3123
3124 # if index contained in column slice
3125 0 ▶ if (grep {$i == $_} @{$f}) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$i == $_;} @{$f;}) { } 0 0 0
3126
3127 # add to slice (remove)
3128 0 push(@r, $i);
3129
3130 } else {
3131
3132 # add to slice (keep)
3133 0 push(@s, $i)
3134
3135 }
3136
3137 }
3138  
3139 # if columns to remove
3140 0 ▶ if (@r) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r) { } 0 0 0
3141
3142 # for each data row
3143 0 for my $i (0 .. $#{$self->[1]}) {
3144
3145 # set removed data (@r)
3146 0 $removed->[$i] = [@{$self->[1][$i]}[@r]];
3147
3148 # set kept data (@s)
3149 0 $kept->[$i] = [@{$self->[1][$i]}[@s]];
3150
3151 }
3152
3153 # update object data
3154 0 $self->[1] = $kept;
3155
3156 # for each colorimetry row
3157 0 for my $i (0 .. $#{$self->[2]}) {
3158
3159 # set kept colorimetry (@s)
3160 0 $color->[$i] = [@{$self->[2][$i]}[@s]];
3161
3162 }
3163
3164 # update colorimetry data
3165 0 $self->[2] = $color;
3166
3167 # initialize SAMPLE_ID hash if no SAMPLE_ID field
3168 0 ▶ $self->[4] = {} if (0 == test($self, 'ID'));
Branch: 1 branch
BranchTrueFalseTotal
if 0 == test($self, "ID") 0 0 0
3169
3170 } else {
3171
3172 # set removed data (none)
3173 0 $removed = [[]];
3174
3175 }
3176  
3177 # return removed data
3178 0 return(bless($removed, 'Math::Matrix'));
3179  
3180 }
3181  
3182 # get sample selection based on 2-D location
3183 # indices are one-based, with origin at the upper left
3184 # row matrix slice may contain indices of undefined rows
3185 # entire chart is used when the row and column indices are omitted
3186 # chart row length is provided as a parameter, or obtained from the data
3187 # parameters: ([upper_row_index, lower_row_index, left_column_index, right_column_index], [chart_row_length])
3188 # returns: (row_matrix_slice)
3189 sub select_matrix {
3190  
3191 # get object reference
3192 0 ▶ my $self = shift();
Subroutine select_matrix: not called CC=31 SCAR=69.0
Pod documented
3193  
3194 # local variables
3195 0 my ($sn, $cmax, @rows, @cols, $matrix);
3196 0 my ($row_length, $upper, $lower, $left, $right);
3197  
3198 # get number of samples
3199 0 $sn = $#{$self->[1]};
3200  
3201 # if 0 or 4 parameters
3202 0 ▶ if (@_ == 0 || @_ == 4) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 0 or @_ == 4) { } 0 0 0
elsif (@_ == 1 or @_ == 5) { } 0 0 0
Condition0%0/3
@_ == 0 or @_ == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 0 or @_ == 4
@_ == 0 @_ == 4
Truth table0%0/3
A or B
A= @_ == 0B= @_ == 4
ABresult
1X1
011
000
3203
3204 # get row length from data
3205 0 $row_length = _getRowLength($self);
3206
3207 # if 1 or 5 parameters
3208 ▶ } elsif (@_ == 1 || @_ == 5) {
Condition0%0/3
@_ == 1 or @_ == 5
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 5
@_ == 1 @_ == 5
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 5
ABresult
1X1
011
000
3209
3210 # get row length
3211 0 $row_length = pop();
3212
3213 # verify row length
3214 0 ▶ (Scalar::Util::looks_like_number($row_length) && $row_length == int($row_length) && $row_length > 0) || croak('invalid chart row length');
Branch: 1 branch
BranchTrueFalseTotal
&Scalar::Util::looks_like_number($row_length) and $row_length == int $row_length and $row_length > 0 or croak("invalid chart row length") 0 0 0
Condition0%0/6
&Scalar::Util::looks_like_number($row_length) and $row_length == int $row_length and $row_length > 0
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($row_length) and $row_length == int $row_length
!ll&&!rl&&r
000
MC/DC0%0/3
&Scalar::Util::looks_like_number($row_length) and $row_length == int $row_length and $row_length > 0
&Scalar::Util::looks_like_number($row_length) $row_length == int $row_length $row_length > 0
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($row_length)B= $row_length == int $row_lengthC= $row_length > 0
ABCresult
0XX0
10X0
1100
1111
3215
3216 } else {
3217
3218 # error
3219 0 croak('wrong number of parameters');
3220
3221 }
3222
3223 # if row and column parameters provided
3224 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 0 0 0
3225
3226 # get row and column parameters
3227 0 ($upper, $lower, $left, $right) = @_;
3228
3229 # verify upper and lower indices
3230 0 ▶ (! ref($upper) && $upper == int($upper) && $upper > 0 && $upper <= $row_length) || warn('invalid upper row index');
Branch: 1 branch
BranchTrueFalseTotal
not ref $upper and $upper == int $upper and $upper > 0 and $upper <= $row_length or warn "invalid upper row index" 0 0 0
Condition0%0/9
not ref $upper and $upper == int $upper and $upper > 0 and $upper <= $row_length
!ll&&!rl&&r
000
not ref $upper and $upper == int $upper and $upper > 0
!ll&&!rl&&r
000
not ref $upper and $upper == int $upper
!ll&&!rl&&r
000
MC/DC0%0/4
not ref $upper and $upper == int $upper and $upper > 0 and $upper <= $row_length
not ref $upper $upper == int $upper $upper > 0 $upper <= $row_length
Truth table0%0/5
not(A) and B and C and D
A= not ref $upperB= $upper == int $upperC= $upper > 0D= $upper <= $row_length
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3231 0 ▶ (! ref($lower) && $lower == int($lower) && $lower > 0 && $lower <= $row_length) || warn('invalid lower row index');
Branch: 1 branch
BranchTrueFalseTotal
not ref $lower and $lower == int $lower and $lower > 0 and $lower <= $row_length or warn "invalid lower row index" 0 0 0
Condition0%0/9
not ref $lower and $lower == int $lower and $lower > 0 and $lower <= $row_length
!ll&&!rl&&r
000
not ref $lower and $lower == int $lower and $lower > 0
!ll&&!rl&&r
000
not ref $lower and $lower == int $lower
!ll&&!rl&&r
000
MC/DC0%0/4
not ref $lower and $lower == int $lower and $lower > 0 and $lower <= $row_length
not ref $lower $lower == int $lower $lower > 0 $lower <= $row_length
Truth table0%0/5
not(A) and B and C and D
A= not ref $lowerB= $lower == int $lowerC= $lower > 0D= $lower <= $row_length
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3232
3233 # get maximum column index
3234 0 ▶ $cmax = $sn % $row_length ? int($sn/$row_length) + 1 : int($sn/$row_length);
Branch: 1 branch
BranchTrueFalseTotal
$sn % $row_length ? : 0 0 0
3235
3236 # verify left and right indices
3237 0 ▶ (! ref($left) && $left == int($left) && $left > 0 && $left <= $cmax) || warn('invalid left column index');
Branch: 1 branch
BranchTrueFalseTotal
not ref $left and $left == int $left and $left > 0 and $left <= $cmax or warn "invalid left column index" 0 0 0
Condition0%0/9
not ref $left and $left == int $left and $left > 0 and $left <= $cmax
!ll&&!rl&&r
000
not ref $left and $left == int $left and $left > 0
!ll&&!rl&&r
000
not ref $left and $left == int $left
!ll&&!rl&&r
000
MC/DC0%0/4
not ref $left and $left == int $left and $left > 0 and $left <= $cmax
not ref $left $left == int $left $left > 0 $left <= $cmax
Truth table0%0/5
not(A) and B and C and D
A= not ref $leftB= $left == int $leftC= $left > 0D= $left <= $cmax
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3238 0 ▶ (! ref($right) && $right == int($right) && $right > 0 && $right <= $cmax) || warn('invalid right column index');
Branch: 1 branch
BranchTrueFalseTotal
not ref $right and $right == int $right and $right > 0 and $right <= $cmax or warn "invalid right column index" 0 0 0
Condition0%0/9
not ref $right and $right == int $right and $right > 0 and $right <= $cmax
!ll&&!rl&&r
000
not ref $right and $right == int $right and $right > 0
!ll&&!rl&&r
000
not ref $right and $right == int $right
!ll&&!rl&&r
000
MC/DC0%0/4
not ref $right and $right == int $right and $right > 0 and $right <= $cmax
not ref $right $right == int $right $right > 0 $right <= $cmax
Truth table0%0/5
not(A) and B and C and D
A= not ref $rightB= $right == int $rightC= $right > 0D= $right <= $cmax
ABCDresult
0XXX0
10XX0
110X0
11100
11111
3239
3240 # if upper index < lower index
3241 0 ▶ if ($upper < $lower) {
Branch: 1 branch
BranchTrueFalseTotal
if ($upper < $lower) { } 0 0 0
3242
3243 # make rows array
3244 0 @rows = ($upper .. $lower);
3245
3246 } else {
3247
3248 # make rows array
3249 0 @rows = reverse($lower .. $upper);
3250
3251 }
3252
3253 # if left index < right index
3254 0 ▶ if ($left < $right) {
Branch: 1 branch
BranchTrueFalseTotal
if ($left < $right) { } 0 0 0
3255
3256 # make columns array
3257 0 @cols = ($left .. $right);
3258
3259 } else {
3260
3261 # make columns array
3262 0 @cols = reverse($right .. $left);
3263
3264 }
3265
3266 # use entire chart
3267 } else {
3268
3269 # make rows array
3270 0 @rows = (1 .. $row_length);
3271
3272 # if chart is rectangular
3273 0 ▶ if ($sn % $row_length == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sn % $row_length == 0) { } 0 0 0
3274
3275 # make columns array
3276 0 @cols = (1 .. $sn/$row_length);
3277
3278 } else {
3279
3280 # warning
3281 0 warn('chart is not rectangular');
3282
3283 # make columns array
3284 0 @cols = (1 .. int($sn/$row_length) + 1);
3285
3286 }
3287
3288 }
3289  
3290 # for each row
3291 0 for my $i (0 .. $#rows) {
3292
3293 # for each column
3294 0 for my $j (0 .. $#cols) {
3295
3296 # set matrix element
3297 0 $matrix->[$j][$i] = ($cols[$j] - 1) * $row_length + $rows[$i];
3298
3299 }
3300
3301 }
3302  
3303 # return row matrix slice
3304 0 return(bless($matrix, 'Math::Matrix'));
3305  
3306 }
3307  
3308 # get sample selection using template
3309 # samples are matched by their device values
3310 # supported hash keys: 'dups', 'rows', 'context', 'template_context', 'sid_context', 'method', 'copy'
3311 # duplicate handling: 0 - sample average (default), 1 - FIFO, 2 - LIFO, 3 - first sample, 4 - last sample
3312 # parameters: (template_chart_object, [hash])
3313 # returns: (row_matrix_slice, [sid_matrix_slice])
3314 sub select_template {
3315  
3316 # get parameters
3317 0 ▶ my ($self, $template, $hash) = @_;
Subroutine select_template: not called CC=45 SCAR=76.4
Pod documented
3318  
3319 # local variables
3320 0 my ($row_length, $dups, $copys, $copyt);
3321 0 my ($devcs, $devct, $devs, $devt);
3322 0 my ($sx, $c1, $c2, $c3, $n, @src, $cmp);
3323 0 my ($target, $low, $high, $interval, @m, $nomatch);
3324 0 my ($rows, $avg, $matrix, $devp, $sidt, $sid);
3325  
3326 # verify template is a chart object
3327 0 ▶ (UNIVERSAL::isa($template, 'ICC::Support::Chart')) || croak('template not an ICC::Support::Chart object');
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($template, "ICC::Support::Chart") or croak("template not an ICC::Support::Chart object") 0 0 0
3328  
3329 # get template row length
3330 0 $row_length = _getRowLength($template, $hash);
3331  
3332 # set duplicate handling
3333 0 ▶ $dups = defined($hash->{'dups'}) ? $hash->{'dups'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'dups'} ? : 0 0 0
3334  
3335 # if copy slice is defined
3336 0 ▶ if (defined($hash->{'copy'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"copy"}) 0 0 0
3337
3338 # flatten the copy slice
3339 0 $copys = ICC::Shared::flatten($hash->{'copy'});
3340
3341 # add copied fields to template
3342 0 $copyt = add_fmt($template, @{$self->[1][0]}[@{$copys}]);
3343
3344 }
3345  
3346 # verify parameters
3347 0 ▶ (! ref($row_length) && $row_length == int($row_length) && $row_length > 0) || croak('invalid chart_row_length parameter');
Branch: 1 branch
BranchTrueFalseTotal
not ref $row_length and $row_length == int $row_length and $row_length > 0 or croak("invalid chart_row_length parameter") 0 0 0
Condition0%0/6
not ref $row_length and $row_length == int $row_length and $row_length > 0
!ll&&!rl&&r
000
not ref $row_length and $row_length == int $row_length
!ll&&!rl&&r
000
MC/DC0%0/3
not ref $row_length and $row_length == int $row_length and $row_length > 0
not ref $row_length $row_length == int $row_length $row_length > 0
Truth table0%0/4
not(A) and B and C
A= not ref $row_lengthB= $row_length == int $row_lengthC= $row_length > 0
ABCresult
0XX0
10X0
1100
1111
3348 0 ▶ ($dups == int($dups) && $dups >= 0 && $dups <= 4) || croak('invalid duplicate_handling parameter');
Branch: 1 branch
BranchTrueFalseTotal
$dups == int $dups and $dups >= 0 and $dups <= 4 or croak("invalid duplicate_handling parameter") 0 0 0
Condition0%0/6
$dups == int $dups and $dups >= 0 and $dups <= 4
!ll&&!rl&&r
000
$dups == int $dups and $dups >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$dups == int $dups and $dups >= 0 and $dups <= 4
$dups == int $dups $dups >= 0 $dups <= 4
Truth table0%0/4
A and B and C
A= $dups == int $dupsB= $dups >= 0C= $dups <= 4
ABCresult
0XX0
10X0
1100
1111
3349  
3350 # get object device column slice
3351 0 $devcs = device($self, $hash);
3352  
3353 # get template device column slice
3354 0 $devct = device($template, {'context' => $hash->{'template_context'}});
3355  
3356 # verify object and template column slices
3357 0 ▶ (defined($devcs)) || croak ('object device data missing');
Branch: 1 branch
BranchTrueFalseTotal
defined $devcs or croak("object device data missing") 0 0 0
3358 0 ▶ (defined($devct)) || croak ('template device data missing');
Branch: 1 branch
BranchTrueFalseTotal
defined $devct or croak("template device data missing") 0 0 0
3359 0 ▶ ($#{$devcs} == $#{$devct}) || croak('object and template have different number of channels');
Branch: 1 branch
BranchTrueFalseTotal
$#{$devcs;} == $#{$devct;} or croak("object and template have different number of channels") 0 0 0
3360  
3361 # get object device values
3362 0 $devs = device($self, [], $hash);
3363  
3364 # get template device values
3365 0 $devt = device($template, [], {'context' => $hash->{'template_context'}});
3366  
3367 # get index of next object sample
3368 0 $sx = $#{$self->[1]} + 1;
3369  
3370 # get averaging groups if duplicates are averaged
3371 0 ▶ ($c1, $c2, $c3) = _avg_groups($self, $hash) if ($dups == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $dups == 0 0 0 0
3372  
3373 # get number of channels
3374 0 $n = @{$devcs};
3375  
3376 # initialize sample list
3377 0 @src = ();
3378  
3379 # for each sample
3380 0 for my $i (0 .. $#{$devs}) {
3381
3382 # if all device values defined
3383 0 ▶ if ($n == grep {defined()} @{$devs->[$i]}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == grep({defined $_;} @{$$devs[$i];})) 0 0 0
3384
3385 # add sample to source list
3386 0 push(@src, [@{$devs->[$i]}, $i + 1]);
3387
3388 }
3389
3390 }
3391  
3392 # sort object device values
3393 @src = sort {
3394
3395 # for each channel
3396 0 for my $i (0 .. $#{$a}) {
3397
3398 # quit loop if device values are unequal
3399 0 ▶ last if ($cmp = $a->[$i] <=> $b->[$i])
Branch: 1 branch
BranchTrueFalseTotal
if $cmp = $ICC::Support::Chart::a->[$i] <=> $ICC::Support::Chart::b->[$i] 0 0 0
3400
3401 # use last comparison for sort test
3402 } $cmp
3403
3404 } @src;
3405  
3406 # for each template sample
3407 0 for my $i (0 .. $#{$devt}) {
3408
3409 # initialize search indices
3410 0 $low = 0;
3411 0 $high = $#src;
3412
3413 # initialize no match flag
3414 0 $nomatch = 0;
3415
3416 # for each channel
3417 0 for my $j (0 .. $#{$devt->[0]}) {
3418
3419 # get the target value
3420 0 $target = $devt->[$i][$j];
3421
3422 # locate interval containing or bounding the target value
3423 0 $interval = _bin_search(\@src, $target, $j, $low, $high);
3424
3425 # find indices matching the target value
3426 0 @m = grep {$src[$_][$j] == $target} @{$interval};
3427
3428 # if no object values exactly match the target value
3429 0 ▶ if (@m == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@m == 0) 0 0 0
3430
3431 # sort interval indices by distance to target value
3432 0 @m = sort {$a->[1] <=> $b->[1]} map {[$_, abs($src[$_][$j] - $target)]} @{$interval};
3433
3434 # if distance to closest object value > 0.00201
3435 0 ▶ if (abs($target - $src[$m[0][0]][$j]) > 0.00201) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $target - $src[$m[0][0]][$j] > "0.00201") 0 0 0
3436
3437 # print warning
3438 0 print "no match to template sample $i\n";
3439 0 print "device values: @{$devt->[$i]}\n";
3440
3441 # set no match flag
3442 0 $nomatch = 1;
3443
3444 # quit channel loop
3445 0 last;
3446
3447 }
3448
3449 # set target to closest object value
3450 0 $target = $src[$m[0][0]][$j];
3451
3452 # locate interval containing the target value
3453 0 $interval = _bin_search(\@src, $target, $j, $low, $high);
3454
3455 # find indices matching the target value
3456 0 @m = grep {$src[$_][$j] == $target} @{$interval};
3457
3458 }
3459
3460 # update interval
3461 0 $low = $m[0];
3462 0 $high = $m[-1];
3463
3464 }
3465
3466 # if no match found
3467 0 ▶ if ($nomatch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nomatch) 0 0 0
3468
3469 # locate nearest object sample(s) using linear search
3470 0 ($low, $high) = _lin_search(\@src, $devt->[$i]);
3471
3472 # print message
3473 0 print "closest match is object sample $src[$low][-1]\n";
3474 0 print "device values @{$src[$low]}[0 .. $#{$devt->[0]}]\n";
3475
3476 }
3477
3478 # single sample
3479 0 ▶ if ($low == $high) {
Branch: 1 branch
BranchTrueFalseTotal
if ($low == $high) { } 0 0 0
3480
3481 # set matrix element to first row matching object sample
3482 0 $matrix->[$i/$row_length][$i % $row_length] = $src[$low][-1];
3483
3484 # duplicate samples
3485 } else {
3486
3487 # duplicates are averaged
3488 0 ▶ if ($dups == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($dups == 0) { } 0 0 0
elsif ($dups == 1) { } 0 0 0
elsif ($dups == 2) { } 0 0 0
elsif ($dups == 3) { } 0 0 0
elsif ($dups == 4) { } 0 0 0
3489
3490 # for each appended avg sample
3491 0 for my $j ($sx .. $#{$self->[1]}) {
3492
3493 # set avg
3494 0 $avg = $j;
3495
3496 # get device values
3497 0 $devp = $self->device([$j]);
3498
3499 # for each channel
3500 0 for my $k (0 .. $#{$devp->[0]}) {
3501
3502 # clear avg if device values differ
3503 0 ▶ $avg = 0 if ($devp->[0][$k] != $devt->[$i][$k]);
Branch: 1 branch
BranchTrueFalseTotal
if $devp->[0][$k] != $devt->[$i][$k] 0 0 0
3504
3505 }
3506
3507 # quit loop if device values match
3508 0 ▶ last if ($avg);
Branch: 1 branch
BranchTrueFalseTotal
if $avg 0 0 0
3509
3510 }
3511
3512 # if existing avg sample found
3513 0 ▶ if ($avg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($avg) { } 0 0 0
3514
3515 # set matrix element to existing avg sample
3516 0 $matrix->[$i/$row_length][$i % $row_length] = $avg;
3517
3518 } else {
3519
3520 # make row slice of duplicate samples
3521 0 $rows = [map {$src[$_][-1]} ($low .. $high)];
3522
3523 # set matrix element to new avg sample
3524 0 $matrix->[$i/$row_length][$i % $row_length] = _add_avg($self, $rows, $c1, $c2, $c3);
3525
3526 }
3527
3528 # use FIFO sample
3529 } elsif ($dups == 1) {
3530
3531 # from low to high
3532 0 for my $j ($low .. $high) {
3533
3534 # if index > 0
3535 0 ▶ if ($src[$j][-1] > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src[$j][-1] > 0) 0 0 0
3536
3537 # set matrix element to object sample index
3538 0 $matrix->[$i/$row_length][$i % $row_length] = $src[$j][-1];
3539
3540 # invert sample index to indicate it was used
3541 0 $src[$j][-1] = - $src[$j][-1];
3542
3543 # quit loop
3544 0 last;
3545
3546 }
3547
3548 }
3549
3550 # if matrix element undefined
3551 0 ▶ if (! defined($matrix->[$i/$row_length][$i % $row_length])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$matrix[$i / $row_length][$i % $row_length]) 0 0 0
3552
3553 # print message
3554 0 print "FIFO stack empty for @{$devt->[$i]}\n";
3555 0 print "using last stack sample\n";
3556
3557 # set matrix element to last row matching object sample
3558 0 $matrix->[$i/$row_length][$i % $row_length] = - $src[$high][-1];
3559
3560 }
3561
3562 # use LIFO sample
3563 } elsif ($dups == 2) {
3564
3565 # from high to low
3566 0 for my $j (reverse($low .. $high)) {
3567
3568 # if index > 0
3569 0 ▶ if ($src[$j][-1] > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($src[$j][-1] > 0) 0 0 0
3570
3571 # set matrix element to object sample index
3572 0 $matrix->[$i/$row_length][$i % $row_length] = $src[$j][-1];
3573
3574 # invert sample index to indicate it was used
3575 0 $src[$j][-1] = - $src[$j][-1];
3576
3577 # quit loop
3578 0 last;
3579
3580 }
3581
3582 }
3583
3584 # if matrix element undefined
3585 0 ▶ if (! defined($matrix->[$i/$row_length][$i % $row_length])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $$matrix[$i / $row_length][$i % $row_length]) 0 0 0
3586
3587 # print message
3588 0 print "LIFO stack empty for @{$devt->[$i]}\n";
3589 0 print "using last stack sample\n";
3590
3591 # set matrix element to first row matching object sample
3592 0 $matrix->[$i/$row_length][$i % $row_length] = - $src[$low][-1];
3593
3594 }
3595
3596 # use first duplicate sample
3597 } elsif ($dups == 3) {
3598
3599 # set matrix element to first row matching object sample
3600 0 $matrix->[$i/$row_length][$i % $row_length] = $src[$low][-1];
3601
3602 # use last duplicate sample
3603 } elsif ($dups == 4) {
3604
3605 # set matrix element to last row matching object sample
3606 0 $matrix->[$i/$row_length][$i % $row_length] = $src[$high][-1];
3607
3608 } else {
3609
3610 # error
3611 0 croak('invalid duplicate handling');
3612
3613 }
3614
3615 }
3616
3617 # if 'copy' slice defined
3618 0 ▶ if (defined($copys)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $copys) 0 0 0
3619
3620 # get the object row
3621 0 $n = $matrix->[$i/$row_length][$i % $row_length];
3622
3623 # copy selected values from object to template
3624 0 @{$template->[1][$i + 1]}[@{$copyt}] = @{$self->[1][$n]}[@{$copys}];
3625
3626 # if device values differ
3627 0 ▶ if ($nomatch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nomatch) 0 0 0
3628
3629 # copy device values from object to template
3630 0 @{$template->[1][$i + 1]}[@{$devct}] = @{$self->[1][$n]}[@{$devcs}];
3631
3632 }
3633
3634 }
3635
3636 }
3637  
3638 # if sid-matrix is wanted and template has sid values
3639 0 ▶ if (wantarray() && ($sidt = id($template, [], {'context' => $hash->{'sid_context'}}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray and $sidt = id($template, scalar [], {'context', $hash->{'sid_context'}})) { } 0 0 0
Condition0%0/3
wantarray and $sidt = id($template, scalar [], {"context", $hash->{"sid_context"}})
!ll&&!rl&&r
000
MC/DC0%0/2
wantarray and $sidt = id($template, scalar [], {"context", $hash->{"sid_context"}})
wantarray $sidt = id($template, scalar [], {"context", $hash->{"sid_context"}})
Truth table0%0/3
A and B
A= wantarrayB= $sidt = id($template, scalar [], {"context", $hash->{"sid_context"}})
ABresult
0X0
100
111
3640
3641 # for each template sample
3642 0 for my $i (0 .. $#{$sidt}) {
3643
3644 # set sid matrix element to sid slice value
3645 0 $sid->[$i/$row_length][$i % $row_length] = $sidt->[$i][0];
3646
3647 }
3648
3649 # return row matrix slice and sid matrix slice
3650 0 return(bless($matrix, 'Math::Matrix'), bless($sid, 'Math::Matrix'));
3651
3652 } else {
3653
3654 # return row matrix slice
3655 0 return(bless($matrix, 'Math::Matrix'));
3656
3657 }
3658  
3659 }
3660  
3661 # get sample selection
3662 # array of data values is supplied to code block
3663 # sample is included if code block returns 'true' value
3664 # default row_slice is all samples
3665 # default column_slice is all columns
3666 # parameters: (code_reference, row_slice, column_slice)
3667 # returns: (row_slice)
3668 sub find {
3669  
3670 # get parameters
3671 0 ▶ my ($self, $code, $rows, $cols) = @_;
Subroutine find: not called CC=9 SCAR=45.0
Pod documented
3672  
3673 # local variables
3674 0 my (@s);
3675  
3676 # verify code reference
3677 0 ▶ (ref($code) eq 'CODE') || croak('selection parameter must be a code reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $code eq "CODE" or croak("selection parameter must be a code reference") 0 0 0
3678  
3679 # if row slice undefined or empty
3680 0 ▶ if (! defined($rows) || (ref($rows) eq 'ARRAY' && @{$rows} == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rows or ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/6
not defined $rows or ref $rows eq "ARRAY" and @{$rows;} == 0
l!l&&r!l&&!r
000
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $rows or ref $rows eq "ARRAY" and @{$rows;} == 0
not defined $rows ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/4
not(A) or B and C
A= not defined $rowsB= ref $rows eq "ARRAY"C= @{$rows;} == 0
ABCresult
1XX1
0111
00X0
0100
3681
3682 # use all rows
3683 0 $rows = [1 .. $#{$self->[1]}];
3684
3685 } else {
3686
3687 # flatten slice
3688 0 $rows = ICC::Shared::flatten($rows);
3689
3690 }
3691  
3692 # if column slice undefined or empty
3693 0 ▶ if (! defined($cols) || (ref($cols) eq 'ARRAY' && @{$cols} == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $cols or ref $cols eq 'ARRAY' and @{$cols;} == 0) { } 0 0 0
Condition0%0/6
not defined $cols or ref $cols eq "ARRAY" and @{$cols;} == 0
l!l&&r!l&&!r
000
ref $cols eq "ARRAY" and @{$cols;} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $cols or ref $cols eq "ARRAY" and @{$cols;} == 0
not defined $cols ref $cols eq "ARRAY" @{$cols;} == 0
Truth table0%0/4
not(A) or B and C
A= not defined $colsB= ref $cols eq "ARRAY"C= @{$cols;} == 0
ABCresult
1XX1
0111
00X0
0100
3694
3695 # use all columns
3696 0 $cols = [0 .. $#{$self->[1][0]}];
3697
3698 } else {
3699
3700 # flatten slice
3701 0 $cols = ICC::Shared::flatten($cols);
3702
3703 }
3704  
3705 # select samples
3706 0 @s = grep {&$code(@{$self->[1][$_]}[@{$cols}])} @{$rows};
3707  
3708 # return selection, or undef if none selected
3709 0 ▶ return(scalar(@s) ? \@s : undef);
Branch: 1 branch
BranchTrueFalseTotal
scalar @s ? : 0 0 0
3710  
3711 }
3712  
3713 # get sample selection based on device values
3714 # array of device values is supplied to code block
3715 # sample is included if code block returns 'true' value
3716 # default row_slice is all samples
3717 # context may be specified with parameter hash
3718 # parameters: (code_reference, [row_slice], [hash])
3719 # returns: (row_slice)
3720 sub ramp {
3721  
3722 # local variables
3723 0 ▶ my ($hash, $cols, $mult, @s);
Subroutine ramp: not called CC=9 SCAR=45.0
Pod documented
3724  
3725 # get optional hash
3726 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
3727  
3728 # get remaining parameters
3729 0 my ($self, $code, $rows) = @_;
3730  
3731 # verify code reference
3732 0 ▶ (ref($code) eq 'CODE') || croak('selection parameter must be a code reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $code eq "CODE" or croak("selection parameter must be a code reference") 0 0 0
3733  
3734 # if row slice undefined or empty
3735 0 ▶ if (! defined($rows) || (ref($rows) eq 'ARRAY' && @{$rows} == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rows or ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/6
not defined $rows or ref $rows eq "ARRAY" and @{$rows;} == 0
l!l&&r!l&&!r
000
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $rows or ref $rows eq "ARRAY" and @{$rows;} == 0
not defined $rows ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/4
not(A) or B and C
A= not defined $rowsB= ref $rows eq "ARRAY"C= @{$rows;} == 0
ABCresult
1XX1
0111
00X0
0100
3736
3737 # use all rows
3738 0 $rows = [1 .. $#{$self->[1]}];
3739
3740 } else {
3741
3742 # flatten slice
3743 0 $rows = ICC::Shared::flatten($rows);
3744
3745 }
3746  
3747 # get device column slice
3748 0 ▶ (defined($cols = device($self, $hash))) || croak('device values required');
Branch: 1 branch
BranchTrueFalseTotal
defined($cols = device($self, $hash)) or croak("device values required") 0 0 0
3749  
3750 # set multiplier (255 if RGB, else 100)
3751 0 ▶ $mult = ($self->[1][0][$cols->[0]] =~ m/RGB_R$/) ? 255 : 100;
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$cols->[0]] =~ /RGB_R$/ ? : 0 0 0
3752  
3753 # select samples
3754 0 @s = grep {&$code(map {$_/$mult} @{$self->[1][$_]}[@{$cols}])} @{$rows};
3755  
3756 # return selection, or undef if none selected
3757 0 ▶ return(scalar(@s) ? \@s : undef);
Branch: 1 branch
BranchTrueFalseTotal
scalar @s ? : 0 0 0
3758  
3759 }
3760  
3761 # get sample selection based on L*a*b* values
3762 # array of L*a*b* values is supplied to code block
3763 # sample is included if code block returns 'true' value
3764 # default row_slice is all samples
3765 # context may be specified with parameter hash
3766 # parameters: (code_reference, [row_slice], [hash])
3767 # returns: (row_slice)
3768 sub range {
3769  
3770 # local variables
3771 0 ▶ my ($hash, $cols, @s);
Subroutine range: not called CC=8 SCAR=42.8
Pod documented
3772  
3773 # get optional hash
3774 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
3775  
3776 # get remaining parameters
3777 0 my ($self, $code, $rows) = @_;
3778  
3779 # verify code reference
3780 0 ▶ (ref($code) eq 'CODE') || croak('selection parameter must be a code reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $code eq "CODE" or croak("selection parameter must be a code reference") 0 0 0
3781  
3782 # if row slice undefined or empty
3783 0 ▶ if (! defined($rows) || (ref($rows) eq 'ARRAY' && @{$rows} == 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rows or ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/6
not defined $rows or ref $rows eq "ARRAY" and @{$rows;} == 0
l!l&&r!l&&!r
000
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
not defined $rows or ref $rows eq "ARRAY" and @{$rows;} == 0
not defined $rows ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/4
not(A) or B and C
A= not defined $rowsB= ref $rows eq "ARRAY"C= @{$rows;} == 0
ABCresult
1XX1
0111
00X0
0100
3784
3785 # use all rows
3786 0 $rows = [1 .. $#{$self->[1]}];
3787
3788 } else {
3789
3790 # flatten slice
3791 0 $rows = ICC::Shared::flatten($rows);
3792
3793 }
3794  
3795 # get L*a*b* column slice
3796 0 ▶ (defined($cols = lab($self, $hash))) || croak('L*a*b* values required');
Branch: 1 branch
BranchTrueFalseTotal
defined($cols = lab($self, $hash)) or croak("L*a*b* values required") 0 0 0
3797  
3798 # select samples
3799 0 @s = grep {&$code(@{$self->[1][$_]}[@{$cols}])} @{$rows};
3800  
3801 # return selection, or undef if none selected
3802 0 ▶ return(scalar(@s) ? \@s : undef);
Branch: 1 branch
BranchTrueFalseTotal
scalar @s ? : 0 0 0
3803  
3804 }
3805  
3806 # generate randomized sample slice
3807 # parameter: ([row_slice])
3808 # returns: (row_slice)
3809 sub randomize {
3810  
3811 # get parameters
3812 0 ▶ my ($self, $rows) = @_;
Subroutine randomize: not called CC=7 SCAR=40.3
Pod documented
3813  
3814 # if row slice defined
3815 0 ▶ if (defined($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rows) { } 0 0 0
3816
3817 # if row slice an empty array reference
3818 0 ▶ if (ref($rows) eq 'ARRAY' && @{$rows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/3
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rows eq "ARRAY" and @{$rows;} == 0
ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/3
A and B
A= ref $rows eq "ARRAY"B= @{$rows;} == 0
ABresult
0X0
100
111
3819
3820 # use all rows
3821 0 $rows = [1 .. $#{$self->[1]}];
3822
3823 } else {
3824
3825 # flatten row slice
3826 0 $rows = ICC::Shared::flatten($rows);
3827
3828 # verify row slice contents
3829 0 ▶ (@{$rows} == grep {! ref() && $_ == int($_) && $_ >= 0} @{$rows}) || croak('invalid row slice');
Branch: 2 branches
BranchTrueFalseTotal
@{$rows;} == grep({not ref $_ and $_ == int $_ and $_ >= 0;} @{$rows;}) or croak("invalid row slice") 0 0 0
not ref $_ and $_ == int $_ and $_ >= 0 0 0 0
Condition0%0/3
not ref $_ and $_ == int $_
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $_ and $_ == int $_
not ref $_ $_ == int $_
Truth table0%0/3
not(A) and B
A= not ref $_B= $_ == int $_
ABresult
0X0
100
111
3830
3831 }
3832
3833 # return row slice, randomized
3834 0 return([List::Util::shuffle(@{$rows})]);
3835
3836 } else {
3837
3838 # return all samples, randomized
3839 0 return([List::Util::shuffle(1 .. $#{$self->[1]})]);
3840
3841 }
3842  
3843 }
3844  
3845 # analyze chart device values
3846 # creates an array structure with an element for each device channel.
3847 # each element contains a hash, a keys array, and a ramp array.
3848 # hash keys are device values, and hash values are arrays of samples.
3849 # if row-slice is omitted, all samples are used.
3850 # if the dup_flag is false (default), a new sample is added
3851 # containing average measurement values, and the new sample
3852 # is substituted for the anonymous array of duplicates.
3853 # if the dup_flag is true, duplicate samples are included in
3854 # array of samples grouped within anonymous arrays.
3855 # dup_flag and/or device context are specified with parameter hash
3856 # parameters: ([row_slice], [hash])
3857 # returns: (ref_to_structure)
3858 sub analyze {
3859  
3860 # get object reference
3861 0 ▶ my $self = shift();
Subroutine analyze: not called CC=30 SCAR=68.4
Pod documented
3862  
3863 # local variables
3864 0 my ($hash, $rows, $dup, $ramp, $dev, $c1, $c2, $c3, @id, @name, $mult);
3865 0 my (@d, %dev_hash, $key, $avg, $value, $struct);
3866  
3867 # get optional hash
3868 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
3869  
3870 # get device column slice
3871 0 ▶ ($dev = device($self, $hash)) || croak('chart has no device values');
Branch: 1 branch
BranchTrueFalseTotal
$dev = device($self, $hash) or croak("chart has no device values") 0 0 0
3872  
3873 # get row slice
3874 0 ▶ $rows = shift() if (ref($_[0]) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "ARRAY" 0 0 0
3875  
3876 # flatten row slice
3877 0 ▶ $rows = $rows ? ICC::Shared::flatten($rows) : [];
Branch: 1 branch
BranchTrueFalseTotal
$rows ? : 0 0 0
3878  
3879 # use all samples if slice is empty
3880 0 ▶ $rows = [1 .. $#{$self->[1]}] if (@{$rows} == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @{$rows;} == 0 0 0 0
3881  
3882 # get dup flag
3883 0 ▶ $dup = defined($hash->{'dups'}) ? $hash->{'dups'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'dups'} ? : 0 0 0
3884  
3885 # get ramp value
3886 0 ▶ $ramp = defined($hash->{'ramp'}) ? $hash->{'ramp'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'ramp'} ? : 0 0 0
3887  
3888 # get averaging groups
3889 0 ($c1, $c2, $c3) = _avg_groups($self, $hash);
3890  
3891 # for each column
3892 0 for my $i (0 .. $#{$self->[1][0]}) {
3893
3894 # add column if SAMPLE_ID field
3895 0 ▶ push(@id, $i) if ($self->[1][0][$i] =~ m/^(?:.*\|)?(?:SAMPLE_ID|SampleID)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /^(?:.*\|)?(?:SAMPLE_ID|SampleID)$/ 0 0 0
3896
3897 # add column if SAMPLE_NAME field
3898 0 ▶ push(@name, $i) if ($self->[1][0][$i] =~ m/^(?:.*\|)?SAMPLE_NAME$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /^(?:.*\|)?SAMPLE_NAME$/ 0 0 0
3899
3900 }
3901  
3902 # set device multiplier (255 for RGB values, otherwise 100)
3903 0 ▶ $mult = ($self->[1][0][$dev->[0]] =~ m/^(?:.*\|)?RGB_[RGB]$/) ? 255 : 100;
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$dev->[0]] =~ /^(?:.*\|)?RGB_[RGB]$/ ? : 0 0 0
3904  
3905 # for each sample
3906 0 for my $i (0 .. $#{$rows}) {
3907
3908 # get device values
3909 0 @d = @{$self->[1][$rows->[$i]]}[@{$dev}];
3910
3911 # divide by multiplier (setting -0 to 0)
3912 0 ▶ @d = map {$_ == 0 ? 0 : $_/$mult} @d;
Branch: 1 branch
BranchTrueFalseTotal
$_ == 0 ? : 0 0 0
3913
3914 # make device value key
3915 0 $key = join(':', @d);
3916
3917 # if key exists
3918 0 ▶ if (exists($dev_hash{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $dev_hash{$key}) { } 0 0 0
3919
3920 # add sample to existing hash entry
3921 0 push(@{$dev_hash{$key}}, $rows->[$i]);
3922
3923 } else {
3924
3925 # add device hash entry
3926 0 $dev_hash{$key} = [$rows->[$i]];
3927
3928 }
3929
3930 }
3931  
3932 # if dup flag is not set
3933 0 ▶ if (! $dup) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dup) 0 0 0
3934
3935 # for each key
3936 0 for my $key (keys(%dev_hash)) {
3937
3938 # if duplicate samples
3939 0 ▶ if (@{$dev_hash{$key}} > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$dev_hash{$key};} > 1) 0 0 0
3940
3941 # if measurement data
3942 0 ▶ if (@{$c1} || @{$c2} || @{$c3}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$c1;} or @{$c2;} or @{$c3;}) { } 0 0 0
Condition0%0/6
@{$c1;} or @{$c2;} or @{$c3;}
l!l&&r!l&&!r
000
@{$c1;} or @{$c2;}
l!l&&r!l&&!r
000
MC/DC0%0/3
@{$c1;} or @{$c2;} or @{$c3;}
@{$c1;} @{$c2;} @{$c3;}
Truth table0%0/4
A or B or C
A= @{$c1;}B= @{$c2;}C= @{$c3;}
ABCresult
1XX1
01X1
0011
0000
3943
3944 # add average sample
3945 0 $avg = _add_avg($self, $dev_hash{$key}, $c1, $c2, $c3, \@id, \@name);
3946
3947 # update hash to average sample
3948 0 $dev_hash{$key} = [$avg];
3949
3950 } else {
3951
3952 # update hash to first sample
3953 0 $dev_hash{$key} = [$dev_hash{$key}[0]];
3954
3955 }
3956
3957 }
3958
3959 }
3960
3961 # update the SAMPLE_ID hash
3962 0 _makeSampleID($self);
3963
3964 }
3965  
3966 # make empty structure
3967 0 $struct = [map {[{}, [], []]} (0 .. $#{$dev})];
3968  
3969 # for each key
3970 0 for my $key (keys(%dev_hash)) {
3971
3972 # split key to device values
3973 0 @d = split(/:/, $key);
3974
3975 # get value
3976 0 $value = $dev_hash{$key};
3977
3978 # resolve single value to scalar
3979 0 ▶ $value = $value->[0] if (@{$value} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if @{$value;} == 1 0 0 0
3980
3981 # for each device channel
3982 0 for my $i (0 .. $#d) {
3983
3984 # if key exists
3985 0 ▶ if (exists($struct->[$i][0]{$d[$i]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $struct->[$i][0]{$d[$i]}) { } 0 0 0
3986
3987 # add sample to hash entry
3988 0 push(@{$struct->[$i][0]{$d[$i]}}, $value);
3989
3990 } else {
3991
3992 # add hash entry
3993 0 $struct->[$i][0]{$d[$i]} = [$value];
3994
3995 # add device value to keys array
3996 0 push(@{$struct->[$i][1]}, $d[$i]);
3997
3998 }
3999
4000 # if all other device values equal ramp value
4001 0 ▶ if (@d == grep {$_ == $i || $d[$_] == $ramp} (0 .. $#d)) {
Branch: 2 branches
BranchTrueFalseTotal
if (@d == grep({$_ == $i or $d[$_] == $ramp;} 0 .. $#d)) 0 0 0
$_ == $i or $d[$_] == $ramp 0 0 0
4002
4003 # add sample to ramp array
4004 0 push(@{$struct->[$i][2]}, $value);
4005
4006 }
4007
4008 }
4009
4010 }
4011  
4012 # for each device channel
4013 0 for my $i (0 .. $#{$dev}) {
4014
4015 # sort keys array (decreasing frequency)
4016 0 $struct->[$i][1] = [sort {@{$struct->[$i][0]{$b}} <=> @{$struct->[$i][0]{$a}}} @{$struct->[$i][1]}];
4017
4018 # sort ramp array (increasing values)
4019 0 ▶ $struct->[$i][2] = [sort {$self->[1][(! ref($a) ? $a : $a->[0])][$dev->[$i]] <=> $self->[1][(! ref($b) ? $b : $b->[0])][$dev->[$i]]} @{$struct->[$i][2]}];
Branch: 2 branches
BranchTrueFalseTotal
!ref($a) ? : 0 0 0
!ref($b) ? : 0 0 0
4020
4021 }
4022  
4023 # return
4024 0 return($struct);
4025  
4026 }
4027  
4028 # write chart to ISO 28178 (CGATS.17) ASCII file
4029 # optional slice parameters are either scalars, array references or 'Math::Matrix' objects
4030 # optional hash parameter keys: 'sid', 'append'
4031 # parameters: (path_to_file, [row_slice, [column_slice]], [hash])
4032 sub write {
4033  
4034 # local variables
4035 0 ▶ my ($hash, $row_length, $m, $n, @files, $sid, $fh, $rs, @fields);
Subroutine write: not called CC=54 SCAR=80.0
Pod documented
4036 0 my (%cspec, $keyword, $value, $source, $std_key, @s, $sidx, $append);
4037 0 my ($null, $undef);
4038  
4039 # get optional hash parameter
4040 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
4041  
4042 # get remaining parameters
4043 0 my ($self, $path, $rows, $cols) = @_;
4044  
4045 # if row slice defined
4046 0 ▶ if (defined($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rows) { } 0 0 0
4047
4048 # if row slice an empty array reference
4049 0 ▶ if (ref($rows) eq 'ARRAY' && @{$rows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/3
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rows eq "ARRAY" and @{$rows;} == 0
ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/3
A and B
A= ref $rows eq "ARRAY"B= @{$rows;} == 0
ABresult
0X0
100
111
4050
4051 # use all rows
4052 0 $rows = [1 .. $#{$self->[1]}];
4053
4054 } else {
4055
4056 # get row length if row slice is Math::Matrix object
4057 0 ▶ $row_length = @{$rows->[0]} if (UNIVERSAL::isa($rows, 'Math::Matrix'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($rows, "Math::Matrix") 0 0 0
4058
4059 # flatten row slice
4060 0 $rows = ICC::Shared::flatten($rows);
4061
4062 }
4063
4064 } else {
4065
4066 # use all rows
4067 0 $rows = [1 .. $#{$self->[1]}];
4068
4069 }
4070  
4071 # get number of rows
4072 0 $m = @{$rows};
4073  
4074 # warn if invalid samples
4075 0 ▶ (@{$rows} == grep {$_ == int($_) && $_ != 0 && defined($self->[1][$_])} @{$rows})|| warn('row slice contains invalid samples');
Branch: 2 branches
BranchTrueFalseTotal
@{$rows;} == grep({$_ == int $_ and $_ != 0 and defined $self->[1][$_];} @{$rows;}) or warn "row slice contains invalid samples" 0 0 0
$_ == int $_ and $_ != 0 and defined $self->[1][$_] 0 0 0
Condition0%0/3
$_ == int $_ and $_ != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$_ == int $_ and $_ != 0
$_ == int $_ $_ != 0
Truth table0%0/3
A and B
A= $_ == int $_B= $_ != 0
ABresult
0X0
100
111
4076  
4077 # if column slice defined
4078 0 ▶ if (defined($cols)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cols) { } 0 0 0
4079
4080 # if column slice an empty array reference
4081 0 ▶ if (ref($cols) eq 'ARRAY' && @{$cols} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cols eq 'ARRAY' and @{$cols;} == 0) { } 0 0 0
Condition0%0/3
ref $cols eq "ARRAY" and @{$cols;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $cols eq "ARRAY" and @{$cols;} == 0
ref $cols eq "ARRAY" @{$cols;} == 0
Truth table0%0/3
A and B
A= ref $cols eq "ARRAY"B= @{$cols;} == 0
ABresult
0X0
100
111
4082
4083 # use all columns
4084 0 $cols = [0 .. $#{$self->[1][0]}];
4085
4086 } else {
4087
4088 # flatten column slice
4089 0 $cols = ICC::Shared::flatten($cols);
4090
4091 }
4092
4093 } else {
4094
4095 # use all columns
4096 0 $cols = [0 .. $#{$self->[1][0]}];
4097
4098 }
4099  
4100 # get number of columns
4101 0 $n = @{$cols};
4102  
4103 # filter column slice
4104 0 ▶ @{$cols} = grep {$_ == int($_) && defined($self->[1][0][$_])} @{$cols};
Branch: 1 branch
BranchTrueFalseTotal
$_ == int $_ and defined $self->[1][0][$_] 0 0 0
4105  
4106 # warn if invalid fields
4107 0 ▶ ($n == @{$cols}) || warn('column slice contains invalid fields');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$cols;} or warn "column slice contains invalid fields" 0 0 0
4108  
4109 # if 'sid' hash value defined
4110 0 ▶ if (defined($sid = $hash->{'sid'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($sid = $hash->{"sid"})) 0 0 0
4111
4112 # if array reference or Math::Matrix object
4113 0 ▶ if (ref($sid) eq 'ARRAY' || UNIVERSAL::isa($sid, 'Math::Matrix')) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sid eq 'ARRAY' or UNIVERSAL::isa($sid, 'Math::Matrix')) { } 0 0 0
elsif ($sid eq 'row') { } 0 0 0
Condition0%0/3
ref $sid eq "ARRAY" or UNIVERSAL::isa($sid, "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $sid eq "ARRAY" or UNIVERSAL::isa($sid, "Math::Matrix")
ref $sid eq "ARRAY" UNIVERSAL::isa($sid, "Math::Matrix")
Truth table0%0/3
A or B
A= ref $sid eq "ARRAY"B= UNIVERSAL::isa($sid, "Math::Matrix")
ABresult
1X1
011
000
4114
4115 # flatten 'sid' slice
4116 0 $sid = ICC::Shared::flatten($sid);
4117
4118 # warn row slice and sid slice are different sizes
4119 0 ▶ ($m == @{$sid}) || warn('row slice and sid slice are different sizes');
Branch: 1 branch
BranchTrueFalseTotal
$m == @{$sid;} or warn "row slice and sid slice are different sizes" 0 0 0
4120
4121 } elsif ($sid eq 'row') {
4122
4123 # use sequential row list
4124 0 $sid = [1 .. $m];
4125
4126 } else {
4127
4128 # error
4129 0 croak('invalid \'sid\' hash value');
4130
4131 }
4132
4133 }
4134  
4135 # resolve file list from path
4136 0 ▶ (defined($path) && (! ref($path)) && (@files = File::Glob::bsd_glob($path))) || croak("invalid path: $path, stopped");
Branch: 1 branch
BranchTrueFalseTotal
defined $path and not ref $path and @files = File::Glob::bsd_glob($path) or croak("invalid path: $path, stopped") 0 0 0
Condition0%0/6
defined $path and not ref $path and @files = File::Glob::bsd_glob($path)
!ll&&!rl&&r
000
defined $path and not ref $path
!ll&&!rl&&r
000
MC/DC0%0/3
defined $path and not ref $path and @files = File::Glob::bsd_glob($path)
defined $path not ref $path @files = File::Glob::bsd_glob($path)
Truth table0%0/4
A and not(B) and C
A= defined $pathB= not ref $pathC= @files = File::Glob::bsd_glob($path)
ABCresult
0XX0
10X0
1100
1111
4137  
4138 # verify file path is unique
4139 0 ▶ (@files == 1) || warn('file path not unique');
Branch: 1 branch
BranchTrueFalseTotal
@files == 1 or warn "file path not unique" 0 0 0
4140  
4141 # open the file
4142 0 ▶ open($fh, '>', $files[0]) || croak("$! when opening $files[0], stopped");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $files[0] or croak("$! when opening $files[0], stopped") 0 0 0
4143  
4144 # get the record separator
4145 0 ▶ $rs = $self->[0]{'write_rs'} || $self->[0]{'read_rs'} || "\n";
Condition0%0/5
$self->[0]{'write_rs'} || $self->[0]{'read_rs'} || "\n"
l!l
00
$self->[0]{"write_rs"} or $self->[0]{"read_rs"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{'write_rs'} || $self->[0]{'read_rs'} || "\n"
$self->[0]{"write_rs"} $self->[0]{"read_rs"}
Truth table0%0/3
A or B
A= $self->[0]{"write_rs"}B= $self->[0]{"read_rs"}
ABresult
1X1
011
000
4146  
4147 # initialize color specification hash
4148 # so lines with 'FileInformation' source are printed
4149 0 %cspec = ('FileInformation' => 1);
4150  
4151 # add referenced sources to color specification hash
4152 0 ▶ for (@{$self->[2][5]}[@{$cols}]) {$cspec{$_}++ if defined()};
Branch: 1 branch
BranchTrueFalseTotal
if defined $_ 0 0 0
4153  
4154 # for each header line
4155 0 for (@{$self->[3]}) {
4156
4157 # get keyword, value and source
4158 0 ($keyword, $value, $source) = @{$_};
4159
4160 # if keyword defined and length > 0
4161 0 ▶ if (defined($keyword) && length($keyword)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $keyword and length $keyword) { } 0 0 0
Condition0%0/3
defined $keyword and length $keyword
!ll&&!rl&&r
000
MC/DC0%0/2
defined $keyword and length $keyword
defined $keyword length $keyword
Truth table0%0/3
A and B
A= defined $keywordB= length $keyword
ABresult
0X0
100
111
4162
4163 # make uppercase
4164 0 $keyword = uc($keyword);
4165
4166 # skip certain keywords
4167 0 ▶ next if ($keyword =~ m/KEYWORD|NUMBER_OF_FIELDS|NUMBER_OF_SETS/);
Branch: 1 branch
BranchTrueFalseTotal
if $keyword =~ /KEYWORD|NUMBER_OF_FIELDS|NUMBER_OF_SETS/ 0 0 0
4168 0 ▶ next if (defined($row_length) && $keyword =~ m/LGOROWLENGTH/);
Branch: 1 branch
BranchTrueFalseTotal
if defined $row_length and $keyword =~ /LGOROWLENGTH/ 0 0 0
Condition0%0/3
defined $row_length and $keyword =~ /LGOROWLENGTH/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $row_length and $keyword =~ /LGOROWLENGTH/
defined $row_length $keyword =~ /LGOROWLENGTH/
Truth table0%0/3
A and B
A= defined $row_lengthB= $keyword =~ /LGOROWLENGTH/
ABresult
0X0
100
111
4169
4170 # if no source or referenced source
4171 0 ▶ if (! defined($source) || $cspec{$source}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $source or $cspec{$source}) 0 0 0
Condition0%0/3
not defined $source or $cspec{$source}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $source or $cspec{$source}
not defined $source $cspec{$source}
Truth table0%0/3
not(A) or B
A= not defined $sourceB= $cspec{$source}
ABresult
1X1
011
000
4172
4173 # if value defined and length > 0
4174 0 ▶ if (defined($value) && length($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and length $value) { } 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
4175
4176 # print keyword/value
4177 0 print $fh "$keyword\t$value$rs";
4178
4179 } else {
4180
4181 # print keyword only
4182 0 print $fh "$keyword$rs";
4183
4184 }
4185
4186 }
4187
4188 } else {
4189
4190 # print empty line
4191 0 print $fh "$rs";
4192
4193 }
4194
4195 }
4196  
4197 # get format fields
4198 0 @fields = @{$self->[1][0]}[@{$cols}];
4199  
4200 # remove any context, trim leading and trailing white space, and replace spaces with underscores
4201 0 for (@fields) {s/^.*\|//; s/^\s*(.*?)\s*$/$1/; s/ /_/g}
4202  
4203 # make standard format keyword regex (per ISO 28178 and common usage)
4204 0 $std_key = '^(?:' . join('|', qw(SAMPLE_ID SAMPLE_NO STRING RGB_[RGB] CMYK_[CMYK] [2-9A-F]CLR_[1-9A-F] PC\d+_\d+ SPOT_\d+
4205 (?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)\d{3} D_(?:RED|GREEN|BLUE|VIS|MAJOR_FILTER) XYZ_[XYZ] XYY_(?:X|Y|CAPY)
4206 LAB_[LABCH] LAB_DE LAB_DE_94 LAB_DE_CMC LAB_DE_2000 MEAN_DE STDDEV_[XYZ] STDDEV_[LAB] CHI_SQD_PAR)) . ')$';
4207  
4208 # for each format field
4209 0 for (@fields) {
4210
4211 # if not a standard keyword
4212 0 ▶ if (! /$std_key/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (/$std_key/) 0 0 0
4213
4214 # print KEYWORD
4215 0 printf $fh "KEYWORD\t%s$rs", $_;
4216
4217 }
4218
4219 }
4220  
4221 # if 'sid' slice defined
4222 0 ▶ if (defined($sid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sid) 0 0 0
4223
4224 # if 'SAMPLE_ID' keyword(s)
4225 0 ▶ if (@s = grep {uc($fields[$_]) eq 'SAMPLE_ID'} (0 .. $#fields)) {
Branch: 1 branch
BranchTrueFalseTotal
if (@s = grep({uc $fields[$_] eq 'SAMPLE_ID';} 0 .. $#fields)) { } 0 0 0
4226
4227 # save index of first match
4228 0 $sidx = $s[0];
4229
4230 } else {
4231
4232 # insert 'SAMPLE_ID' keyword
4233 0 unshift(@fields, 'SAMPLE_ID');
4234
4235 }
4236
4237 }
4238  
4239 # print LGOROWLENGTH (if $row_length defined)
4240 0 ▶ printf $fh "LGOROWLENGTH\t%d$rs", $row_length if (defined($row_length));
Branch: 1 branch
BranchTrueFalseTotal
if defined $row_length 0 0 0
4241  
4242 # print NUMBER_OF_FIELDS
4243 0 printf $fh "NUMBER_OF_FIELDS\t%d$rs", scalar(@fields);
4244  
4245 # print BEGIN_DATA_FORMAT
4246 0 print $fh 'BEGIN_DATA_FORMAT', $rs;
4247  
4248 # print format string (if any)
4249 0 ▶ print $fh join("\t", @fields), $rs if (@fields);
Branch: 1 branch
BranchTrueFalseTotal
if @fields 0 0 0
4250  
4251 # print END_DATA_FORMAT
4252 0 print $fh 'END_DATA_FORMAT', $rs;
4253  
4254 # print NUMBER_OF_SETS
4255 0 printf $fh "NUMBER_OF_SETS\t%d$rs", scalar(@{$rows});
4256  
4257 # print BEGIN_DATA
4258 0 print $fh 'BEGIN_DATA', $rs;
4259  
4260 # get null replacement value
4261 0 ▶ $null = $hash->{'null'} // 'null';
Condition0%0/2
$hash->{"null"} // "null"
l!l
00
MC/DC0%0/1
$hash->{"null"} // "null"
$hash->{"null"}
Truth table0%0/2
A
A= $hash->{"null"}
Aresult
11
00
4262  
4263 # get undef replacement value
4264 0 ▶ $undef = $hash->{'undef'} // 'undef';
Condition0%0/2
$hash->{"undef"} // "undef"
l!l
00
MC/DC0%0/1
$hash->{"undef"} // "undef"
$hash->{"undef"}
Truth table0%0/2
A
A= $hash->{"undef"}
Aresult
11
00
4265  
4266 # for each row
4267 0 for my $i (0 .. $#{$rows}) {
4268
4269 # get data fields, replacing null and undefined values
4270 0 ▶ @fields = map {defined() ? length() ? $_ : $null : $undef} @{$self->[1][$rows->[$i]]}[@{$cols}];
Branch: 2 branches
BranchTrueFalseTotal
defined $_ ? : 0 0 0
length $_ ? : 0 0 0
4271
4272 # trim leading and trailing white space, and replace spaces with underscores
4273 0 for (@fields) {s/^\s*(.*?)\s*$/$1/; s/ /_/g};
4274
4275 # if 'sid' slice defined
4276 0 ▶ if (defined($sid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sid) 0 0 0
4277
4278 # if 'sid' index defined
4279 0 ▶ if (defined($sidx)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sidx) { } 0 0 0
4280
4281 # replace 'sid' value
4282 0 $fields[$sidx] = $sid->[$i];
4283
4284 } else {
4285
4286 # insert 'sid' value
4287 0 unshift(@fields, $sid->[$i]);
4288 }
4289
4290 }
4291
4292 # print the data record
4293 0 print $fh join("\t", @fields), $rs;
4294
4295 }
4296  
4297 # print END_DATA
4298 0 print $fh 'END_DATA', $rs;
4299  
4300 # if 'append' hash value defined
4301 0 ▶ if (defined($append = $hash->{'append'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($append = $hash->{"append"})) 0 0 0
4302
4303 # replace line endings, if any
4304 0 $append =~ s/\n/$rs/g;
4305
4306 # print appended data
4307 0 print $fh $append;
4308
4309 }
4310  
4311 # close the file
4312 0 close($fh);
4313  
4314 }
4315  
4316 # write chart to CxF3 file
4317 # optional slice parameters are either scalars, array references or 'Math::Matrix' objects
4318 # optional hash parameter keys: 'cc:FileInformation'
4319 # parameters: (path_to_file, [row_slice, [column_slice]], [hash])
4320 sub writeCxF3 {
4321  
4322 # local variables
4323 0 ▶ my ($hash, $row_length, $n);
Subroutine writeCxF3: not called CC=34 SCAR=70.8
Pod documented
4324 0 my ($dom, $root, $ns, $nsURI);
4325 0 my ($datetime, $id, $ops, $objcol);
4326 0 my ($prefix, $nid, $obj, $xpath, $node);
4327 0 my (%lookup, @data, @files, $sub, $spot);
4328  
4329 # get optional hash parameter
4330 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
4331  
4332 # get remaining parameters
4333 0 my ($self, $path, $rows, $cols) = @_;
4334  
4335 # if row slice defined
4336 0 ▶ if (defined($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rows) { } 0 0 0
4337
4338 # if row slice an empty array reference
4339 0 ▶ if (ref($rows) eq 'ARRAY' && @{$rows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/3
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rows eq "ARRAY" and @{$rows;} == 0
ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/3
A and B
A= ref $rows eq "ARRAY"B= @{$rows;} == 0
ABresult
0X0
100
111
4340
4341 # use all rows
4342 0 $rows = [1 .. $#{$self->[1]}];
4343
4344 } else {
4345
4346 # get row length if row slice is Math::Matrix object
4347 0 ▶ $row_length = @{$rows->[0]} if (UNIVERSAL::isa($rows, 'Math::Matrix'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($rows, "Math::Matrix") 0 0 0
4348
4349 # flatten row slice
4350 0 $rows = ICC::Shared::flatten($rows);
4351
4352 }
4353
4354 } else {
4355
4356 # set array reference to all rows
4357 0 $rows = [1 .. $#{$self->[1]}];
4358
4359 }
4360  
4361 # get number of rows
4362 0 $n = @{$rows};
4363  
4364 # filter row slice
4365 0 ▶ @{$rows} = grep {$_ == int($_) && $_ != 0 && defined($self->[1][$_])} @{$rows};
Branch: 1 branch
BranchTrueFalseTotal
$_ == int $_ and $_ != 0 and defined $self->[1][$_] 0 0 0
Condition0%0/3
$_ == int $_ and $_ != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$_ == int $_ and $_ != 0
$_ == int $_ $_ != 0
Truth table0%0/3
A and B
A= $_ == int $_B= $_ != 0
ABresult
0X0
100
111
4366  
4367 # warn if invalid samples
4368 0 ▶ ($n == @{$rows}) || warn('row slice contains invalid samples');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$rows;} or warn "row slice contains invalid samples" 0 0 0
4369  
4370 # open CxF3 template
4371 0 ▶ eval {$dom = XML::LibXML->load_xml('location' => ICC::Shared::getICCPath('Templates/CxF3_template.xml'))} || croak('can\'t load CxF3 template');
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $dom = "XML::LibXML"->load_xml("location", ICC::Shared::getICCPath("Templates/CxF3_template.xml")) } } or croak("can't load CxF3 template") 0 0 0
4372  
4373 # get the root element
4374 0 $root = $dom->documentElement();
4375  
4376 # get the namespace prefix and URI
4377 0 $ns = $root->prefix();
4378 0 $nsURI = $root->namespaceURI();
4379  
4380 # make 'FileInformation' nodes
4381 0 $datetime = _makeCxF3fileinfo($self, $root, $ns, $nsURI, $hash);
4382  
4383 # make write operations array from column slice
4384 # array structure: [[[class, prefix, XPath, [sub_paths], [columns], {attributes}, sort_order], ...], ...]
4385 0 $ops = _makeCxF3writeops($self, $root, $ns, $cols);
4386  
4387 # make 'ColorSpecification' nodes
4388 0 _makeCxF3colorspec($self, $root, $ns, $nsURI, $ops);
4389  
4390 # get the 'ObjectCollection' node
4391 0 ($objcol) = $root->findnodes("$ns:Resources/$ns:ObjectCollection");
4392  
4393 # init object Id index
4394 0 $id = 1;
4395  
4396 # for each group of operations
4397 0 for my $i (0 .. $#{$ops}) {
4398
4399 # get prefix (ObjectType)
4400 0 $prefix = $ops->[$i][0][1];
4401
4402 # initialize name Id
4403 0 $nid = 0;
4404
4405 # for each row in slice
4406 0 for my $j (@{$rows}) {
4407
4408 # increment name Id
4409 0 $nid++;
4410
4411 # add 'Object' node
4412 0 $obj = $objcol->appendChild(XML::LibXML::Element->new("$ns:Object"));
4413 0 $obj->setAttribute('ObjectType', $prefix);
4414 0 $obj->setAttribute('Name', "$prefix$nid");
4415 0 $obj->setAttribute('Id', "c$id");
4416 0 $obj->setNamespace($nsURI, $ns);
4417
4418 # add 'CreationDate' node
4419 0 $node = $obj->appendChild(XML::LibXML::Element->new("$ns:CreationDate"));
4420 0 $node->appendText($datetime);
4421 0 $node->setNamespace($nsURI, $ns);
4422
4423 # init XPath node hash
4424 0 %lookup = ();
4425
4426 # for each operation in the group
4427 0 for my $k (0 .. $#{$ops->[$i]}) {
4428
4429 # set current node to Object
4430 0 $node = $obj;
4431
4432 # initialize XPath
4433 0 $xpath = undef;
4434
4435 # for each XPath segment
4436 0 for (split(/\//, $ops->[$i][$k][2])) {
4437
4438 # add segment to XPath
4439 0 ▶ $xpath = defined($xpath) ? "$xpath/$_" : $_;
Branch: 1 branch
BranchTrueFalseTotal
defined $xpath ? : 0 0 0
4440
4441 # if segment exists
4442 0 ▶ if (exists($lookup{$xpath})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lookup{$xpath}) { } 0 0 0
4443
4444 # use node
4445 0 $node = $lookup{$xpath};
4446
4447 } else {
4448
4449 # add node
4450 0 $node = $node->appendChild(XML::LibXML::Element->new($_));
4451 0 $node->setNamespace($nsURI, $ns);
4452
4453 # add hash entry (except Tag elements)
4454 0 ▶ $lookup{$xpath} = $node if ($_ ne "$ns:Tag");
Branch: 1 branch
BranchTrueFalseTotal
if $_ ne "${ns}:Tag" 0 0 0
4455
4456 }
4457
4458 }
4459
4460 # for each attribute key (if any)
4461 0 for (keys(%{$ops->[$i][$k][5]})) {
4462
4463 # set node attribute using either data element or hash value
4464 0 ▶ $node->setAttribute($_, (ref($ops->[$i][$k][5]{$_}) eq 'ARRAY') ? $self->[1][$j][$ops->[$i][$k][5]{$_}[0]] : $ops->[$i][$k][5]{$_});
Branch: 1 branch
BranchTrueFalseTotal
ref $ops->[$i][$k][5]{$_} eq 'ARRAY' ? : 0 0 0
4465
4466 }
4467
4468 # get data
4469 0 @data = @{$self->[1][$j]}[@{$ops->[$i][$k][4]}];
4470
4471 # warn on undefined data
4472 0 ▶ (@data == grep {defined()} @data) || warn("undefined data in sample $j when writing CxF3 file");
Branch: 1 branch
BranchTrueFalseTotal
@data == grep({defined $_;} @data) or warn "undefined data in sample $j when writing CxF3 file" 0 0 0
4473
4474 # if subpaths
4475 0 ▶ if (@{$ops->[$i][$k][3]}) {
Branch: 3 branches
BranchTrueFalseTotal
if (@{$ops->[$i][$k][3];}) { } 0 0 0
elsif (@data == 1) { } 0 0 0
elsif (@data > 1) { } 0 0 0
4476
4477 # for each subpath
4478 0 for my $s (0 .. $#{$ops->[$i][$k][3]}) {
4479
4480 # add node
4481 # CxF3 schema requires integer values for RGB data
4482 0 $sub = $node->appendChild(XML::LibXML::Element->new($ops->[$i][$k][3][$s]));
4483 0 ▶ $sub->appendText($ops->[$i][$k][0] eq 'RGB' ? int($data[$s] + 0.5) : $data[$s]);
Branch: 1 branch
BranchTrueFalseTotal
$ops->[$i][$k][0] eq 'RGB' ? : 0 0 0
4484 0 $sub->setNamespace($nsURI, $ns);
4485
4486 }
4487
4488 # if NCLR class
4489 0 ▶ if ($ops->[$i][$k][0] eq 'NCLR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ops->[$i][$k][0] eq "NCLR") 0 0 0
4490
4491 # for each spot color
4492 0 for my $s (4 .. $#data) {
4493
4494 # add SpotColor elements
4495 0 $spot = $node->appendChild(XML::LibXML::Element->new("$ns:SpotColor"));
4496 0 $spot->setNamespace($nsURI, $ns);
4497 0 $sub = $spot->appendChild(XML::LibXML::Element->new("$ns:Name"));
4498 0 $sub->appendText('Spot' . ($s + 1));
4499 0 $sub->setNamespace($nsURI, $ns);
4500 0 $sub = $spot->appendChild(XML::LibXML::Element->new("$ns:Percentage"));
4501 0 $sub->appendText($data[$s]);
4502 0 $sub->setNamespace($nsURI, $ns);
4503
4504 }
4505
4506 }
4507
4508 # no subpaths and one data value
4509 } elsif (@data == 1) {
4510
4511 # add data as text content
4512 0 $node->appendText($data[0]);
4513
4514 # no subpaths and multiple data values
4515 } elsif (@data > 1) {
4516
4517 # if DENSITY class
4518 0 ▶ if ($ops->[$i][$k][0] eq 'DENSITY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ops->[$i][$k][0] eq 'DENSITY') { } 0 0 0
4519
4520 ##### to be done
4521
4522 } else {
4523
4524 # join data and add as text content
4525 0 $node->appendText(join(' ', @data));
4526
4527 }
4528
4529 }
4530
4531 }
4532
4533 # add Name attribute to TagCollection element
4534 0 ▶ $lookup{"$ns:TagCollection"}->setAttribute('Name', 'Location') if exists($lookup{"$ns:TagCollection"});
Branch: 1 branch
BranchTrueFalseTotal
if exists $lookup{"${ns}:TagCollection"} 0 0 0
4535
4536 # if nothing was added to Object
4537 0 ▶ if ($node->isSameNode($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isSameNode($obj)) { } 0 0 0
4538
4539 # unbind the node
4540 0 $node->unbindNode();
4541
4542 } else {
4543
4544 # increment Object Id
4545 0 $id++;
4546
4547 }
4548
4549 }
4550
4551 }
4552  
4553 # validate the CxF3 document
4554 0 ▶ _validateCxF3($dom) if (defined($hash->{'validate'}) && $hash->{'validate'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash->{"validate"} and $hash->{"validate"} 0 0 0
Condition0%0/3
defined $hash->{"validate"} and $hash->{"validate"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash->{"validate"} and $hash->{"validate"}
defined $hash->{"validate"} $hash->{"validate"}
Truth table0%0/3
A and B
A= defined $hash->{"validate"}B= $hash->{"validate"}
ABresult
0X0
100
111
4555  
4556 # resolve file list from path
4557 0 ▶ (@files = File::Glob::bsd_glob($path)) || croak('invalid file path');
Branch: 1 branch
BranchTrueFalseTotal
@files = File::Glob::bsd_glob($path) or croak("invalid file path") 0 0 0
4558  
4559 # verify file path is unique
4560 0 ▶ (@files == 1) || warn('file path not unique');
Branch: 1 branch
BranchTrueFalseTotal
@files == 1 or warn "file path not unique" 0 0 0
4561  
4562 # write CxF3 file
4563 0 $dom->toFile($files[0], 1);
4564  
4565 }
4566  
4567 # write chart data array as delimited ASCII file (for Excel, R, MATLAB, etc.)
4568 # optional slice parameters are either scalars, array references or 'Math::Matrix' objects
4569 # optional hash parameter keys: 'header', 'sep', 'eol', and 'undef'
4570 # parameters: (path_to_file, [row_slice, [column_slice]], [hash])
4571 sub writeASCII {
4572  
4573 # local variables
4574 0 ▶ my ($hash, $row_length, $n, @files, $fh);
Subroutine writeASCII: not called CC=32 SCAR=69.6
Pod documented
4575 0 my ($fs, $rs, $undef, $hdr, @fields);
4576  
4577 # get optional hash parameter
4578 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
4579  
4580 # get remaining parameters
4581 0 my ($self, $path, $rows, $cols) = @_;
4582  
4583 # if row slice defined
4584 0 ▶ if (defined($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rows) { } 0 0 0
4585
4586 # if row slice an empty array reference
4587 0 ▶ if (ref($rows) eq 'ARRAY' && @{$rows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/3
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rows eq "ARRAY" and @{$rows;} == 0
ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/3
A and B
A= ref $rows eq "ARRAY"B= @{$rows;} == 0
ABresult
0X0
100
111
4588
4589 # use all rows
4590 0 $rows = [1 .. $#{$self->[1]}];
4591
4592 } else {
4593
4594 # get row length if row slice is Math::Matrix object
4595 0 ▶ $row_length = @{$rows->[0]} if (UNIVERSAL::isa($rows, 'Math::Matrix'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($rows, "Math::Matrix") 0 0 0
4596
4597 # flatten row slice
4598 0 $rows = ICC::Shared::flatten($rows);
4599
4600 }
4601
4602 } else {
4603
4604 # use all rows
4605 0 $rows = [1 .. $#{$self->[1]}];
4606
4607 }
4608  
4609 # get number of rows
4610 0 $n = @{$rows};
4611  
4612 # filter row slice
4613 0 ▶ @{$rows} = grep {$_ == int($_) && $_ != 0 && defined($self->[1][$_])} @{$rows};
Branch: 1 branch
BranchTrueFalseTotal
$_ == int $_ and $_ != 0 and defined $self->[1][$_] 0 0 0
Condition0%0/3
$_ == int $_ and $_ != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$_ == int $_ and $_ != 0
$_ == int $_ $_ != 0
Truth table0%0/3
A and B
A= $_ == int $_B= $_ != 0
ABresult
0X0
100
111
4614  
4615 # warn if invalid samples
4616 0 ▶ ($n == @{$rows}) || warn('row slice contains invalid samples');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$rows;} or warn "row slice contains invalid samples" 0 0 0
4617  
4618 # if column slice defined
4619 0 ▶ if (defined($cols)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cols) { } 0 0 0
4620
4621 # if column slice an empty array reference
4622 0 ▶ if (ref($cols) eq 'ARRAY' && @{$cols} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cols eq 'ARRAY' and @{$cols;} == 0) { } 0 0 0
Condition0%0/3
ref $cols eq "ARRAY" and @{$cols;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $cols eq "ARRAY" and @{$cols;} == 0
ref $cols eq "ARRAY" @{$cols;} == 0
Truth table0%0/3
A and B
A= ref $cols eq "ARRAY"B= @{$cols;} == 0
ABresult
0X0
100
111
4623
4624 # use all columns
4625 0 $cols = [0 .. $#{$self->[1][0]}];
4626
4627 } else {
4628
4629 # flatten column slice
4630 0 $cols = ICC::Shared::flatten($cols);
4631
4632 }
4633
4634 } else {
4635
4636 # use all columns
4637 0 $cols = [0 .. $#{$self->[1][0]}];
4638
4639 }
4640  
4641 # get number of columns
4642 0 $n = @{$cols};
4643  
4644 # filter column slice
4645 0 ▶ @{$cols} = grep {$_ == int($_) && defined($self->[1][0][$_])} @{$cols};
Branch: 1 branch
BranchTrueFalseTotal
$_ == int $_ and defined $self->[1][0][$_] 0 0 0
4646  
4647 # warn if invalid fields
4648 0 ▶ ($n == @{$cols}) || warn('column slice contains invalid fields');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$cols;} or warn "column slice contains invalid fields" 0 0 0
4649  
4650 # resolve file list from path
4651 0 ▶ (defined($path) && (! ref($path)) && (@files = File::Glob::bsd_glob($path))) || croak("invalid path: $path, stopped");
Branch: 1 branch
BranchTrueFalseTotal
defined $path and not ref $path and @files = File::Glob::bsd_glob($path) or croak("invalid path: $path, stopped") 0 0 0
Condition0%0/6
defined $path and not ref $path and @files = File::Glob::bsd_glob($path)
!ll&&!rl&&r
000
defined $path and not ref $path
!ll&&!rl&&r
000
MC/DC0%0/3
defined $path and not ref $path and @files = File::Glob::bsd_glob($path)
defined $path not ref $path @files = File::Glob::bsd_glob($path)
Truth table0%0/4
A and not(B) and C
A= defined $pathB= not ref $pathC= @files = File::Glob::bsd_glob($path)
ABCresult
0XX0
10X0
1100
1111
4652  
4653 # verify file path is unique
4654 0 ▶ (@files == 1) || warn('file path not unique');
Branch: 1 branch
BranchTrueFalseTotal
@files == 1 or warn "file path not unique" 0 0 0
4655  
4656 # open the file
4657 0 ▶ open($fh, '>', $files[0]) || croak("$! when opening $files[0], stopped");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $files[0] or croak("$! when opening $files[0], stopped") 0 0 0
4658  
4659 # get header mode
4660 0 ▶ $hdr = $hash->{'header'} || 1;
Condition0%0/2
$hash->{'header'} || 1
l!l
00
MC/DC0%0/1
$hash->{'header'} || 1
$hash->{'header'}
Truth table0%0/2
A
A= $hash->{'header'}
Aresult
11
00
4661  
4662 # get the field separator
4663 0 ▶ $fs = $hash->{'sep'} || "\t";
Condition0%0/2
$hash->{'sep'} || "\t"
l!l
00
MC/DC0%0/1
$hash->{'sep'} || "\t"
$hash->{'sep'}
Truth table0%0/2
A
A= $hash->{'sep'}
Aresult
11
00
4664  
4665 # get the record separator
4666 0 ▶ $rs = $hash->{'eol'} || "\n";
Condition0%0/2
$hash->{'eol'} || "\n"
l!l
00
MC/DC0%0/1
$hash->{'eol'} || "\n"
$hash->{'eol'}
Truth table0%0/2
A
A= $hash->{'eol'}
Aresult
11
00
4667  
4668 # get the undefined string
4669 0 ▶ $undef = $hash->{'undef'} || '';
Condition0%0/2
$hash->{'undef'} || ''
l!l
00
MC/DC0%0/1
$hash->{'undef'} || ''
$hash->{'undef'}
Truth table0%0/2
A
A= $hash->{'undef'}
Aresult
11
00
4670  
4671 # if header enabled
4672 0 ▶ if ($hdr) {
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr) 0 0 0
4673
4674 # if format fields, replacing undefined values
4675 0 ▶ if (@fields = map {defined() ? $_ : $undef} @{$self->[1][0]}[@{$cols}]) {
Branch: 2 branches
BranchTrueFalseTotal
if (@fields = map({defined $_ ? $_ : $undef;} @{$$self[1][0];}[@{$cols;}])) 0 0 0
defined $_ ? : 0 0 0
4676
4677 # if header mode 2, remove contexts
4678 0 ▶ if ($hdr == 2) {for (@fields) {s/^.*\|//}};
Branch: 1 branch
BranchTrueFalseTotal
if ($hdr == 2) 0 0 0
4679
4680 # trim leading and trailing white space, and replace spaces with underscores
4681 0 for (@fields) {s/^\s*(.*?)\s*$/$1/; s/ /_/g};
4682
4683 # print format record
4684 0 print $fh join($fs, @fields), $rs;
4685
4686 }
4687
4688 }
4689  
4690 # for each row
4691 0 for my $i (@{$rows}) {
4692
4693 # get data fields, replacing undefined values
4694 0 ▶ @fields = map {defined() ? $_ : $undef} @{$self->[1][$i]}[@{$cols}];
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
4695
4696 # trim leading and trailing white space, and replace spaces with underscores
4697 0 for (@fields) {s/^\s*(.*?)\s*$/$1/; s/ /_/g};
4698
4699 # print the data record
4700 0 print $fh join($fs, @fields), $rs;
4701
4702 }
4703  
4704 # close the file
4705 0 close($fh);
4706  
4707 }
4708  
4709 # write TIFF file
4710 # RGB, CMYK, and CIE L*a*b* color spaces supported
4711 # 8-bit, 16-bit or 32-bit, Intel or Motorola byte order supported
4712 # alpha and spot channels in RGB and CMYK files supported
4713 # supported hash keys: 'width', 'height', 'gap', 'left', 'right', 'rows', 'bits', 'dither', 'endian', 'xres', 'yres', 'unit'
4714 # parameters: (path_to_file, [row_slice, [column_slice]], [hash])
4715 sub writeTIFF {
4716  
4717 # local variables
4718 0 ▶ my ($hash, $trows, $tcols, $n, @files, $fh);
Subroutine writeTIFF: not called CC=116 SCAR=95.2
Pod documented
4719 0 my ($base, $cs, %fields, @alpha, $pi, $rcols, $fmt, $mult, $mab, $samples);
4720 0 my ($width, $height, $gap, $left, $right, $bits, $xres, $yres, $unit);
4721 0 my ($le, $short, $long, $fp, $max, $minab, $maxab);
4722 0 my ($tags, $imagewidth, $bytecount, $stripsize);
4723 0 my ($ifd, $data, @cmyk, @spot);
4724  
4725 # get optional hash
4726 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
4727  
4728 # get remaining parameters
4729 0 my ($self, $path, $rows, $cols) = @_;
4730  
4731 # if row slice defined
4732 0 ▶ if (defined($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rows) { } 0 0 0
4733
4734 # if row slice an empty array reference
4735 0 ▶ if (ref($rows) eq 'ARRAY' && @{$rows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/3
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rows eq "ARRAY" and @{$rows;} == 0
ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/3
A and B
A= ref $rows eq "ARRAY"B= @{$rows;} == 0
ABresult
0X0
100
111
4736
4737 # use all rows
4738 0 $rows = [1 .. $#{$self->[1]}];
4739
4740 } else {
4741
4742 # get row length if row slice is Math::Matrix object
4743 0 ▶ $trows = @{$rows->[0]} if (UNIVERSAL::isa($rows, 'Math::Matrix'));
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::isa($rows, "Math::Matrix") 0 0 0
4744
4745 # flatten row slice
4746 0 $rows = ICC::Shared::flatten($rows);
4747
4748 }
4749
4750 } else {
4751
4752 # use all rows
4753 0 $rows = [1 .. $#{$self->[1]}];
4754
4755 }
4756  
4757 # get number of rows
4758 0 $n = @{$rows};
4759  
4760 # filter row slice
4761 0 ▶ @{$rows} = grep {$_ == int($_) && $_ != 0 && defined($self->[1][$_])} @{$rows};
Branch: 1 branch
BranchTrueFalseTotal
$_ == int $_ and $_ != 0 and defined $self->[1][$_] 0 0 0
Condition0%0/3
$_ == int $_ and $_ != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$_ == int $_ and $_ != 0
$_ == int $_ $_ != 0
Truth table0%0/3
A and B
A= $_ == int $_B= $_ != 0
ABresult
0X0
100
111
4762  
4763 # warn if invalid samples
4764 0 ▶ ($n == @{$rows}) || warn('row slice contains invalid samples');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$rows;} or warn "row slice contains invalid samples" 0 0 0
4765  
4766 # get target row length, if not defined by row matrix
4767 0 ▶ $trows = _getRowLength($self, $hash) if (! defined($trows));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trows 0 0 0
4768  
4769 # limit to number of samples
4770 0 ▶ $trows = $trows > $n ? $n : $trows;
Branch: 1 branch
BranchTrueFalseTotal
$trows > $n ? : 0 0 0
4771  
4772 # verify row length
4773 0 ▶ ($trows == int($trows) && $trows > 0) || croak('invalid row length, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$trows == int $trows and $trows > 0 or croak("invalid row length, stopped") 0 0 0
Condition0%0/3
$trows == int $trows and $trows > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$trows == int $trows and $trows > 0
$trows == int $trows $trows > 0
Truth table0%0/3
A and B
A= $trows == int $trowsB= $trows > 0
ABresult
0X0
100
111
4774  
4775 # compute target columns
4776 0 ▶ $tcols = int($n/$trows) + ($n % $trows ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$n % $trows ? : 0 0 0
4777  
4778 # if column slice defined
4779 0 ▶ if (defined($cols)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cols) { } 0 0 0
4780
4781 # if column slice an empty array reference
4782 0 ▶ if (ref($cols) eq 'ARRAY' && @{$cols} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cols eq 'ARRAY' and @{$cols;} == 0) { } 0 0 0
Condition0%0/3
ref $cols eq "ARRAY" and @{$cols;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $cols eq "ARRAY" and @{$cols;} == 0
ref $cols eq "ARRAY" @{$cols;} == 0
Truth table0%0/3
A and B
A= ref $cols eq "ARRAY"B= @{$cols;} == 0
ABresult
0X0
100
111
4783
4784 # use all columns
4785 0 $cols = [0 .. $#{$self->[1][0]}];
4786
4787 } else {
4788
4789 # flatten column slice
4790 0 $cols = ICC::Shared::flatten($cols);
4791
4792 }
4793
4794 } else {
4795
4796 # use all columns
4797 0 $cols = [0 .. $#{$self->[1][0]}];
4798
4799 }
4800  
4801 # get number of columns
4802 0 $n = @{$cols};
4803  
4804 # filter column slice
4805 0 ▶ @{$cols} = grep {$_ == int($_) && defined($self->[1][0][$_])} @{$cols};
Branch: 1 branch
BranchTrueFalseTotal
$_ == int $_ and defined $self->[1][0][$_] 0 0 0
4806  
4807 # warn if invalid fields
4808 0 ▶ ($n == @{$cols}) || warn('column slice contains invalid fields');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$cols;} or warn "column slice contains invalid fields" 0 0 0
4809  
4810 # for each column in slice
4811 0 for (@{$self->[1][0]}[@{$cols}]) {
4812
4813 # if a supported color space
4814 0 ▶ if (m/^((?:.*\|)?(RGB|CMYK|[4-9A-F]CLR|LAB)_)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^((?:.*\|)?(RGB|CMYK|[4-9A-F]CLR|LAB)_)/) 0 0 0
4815
4816 # set base and color space
4817 0 $base = $1;
4818 0 $cs = $2;
4819
4820 # quit loop
4821 0 last();
4822
4823 }
4824
4825 }
4826  
4827 # verify color space
4828 0 ▶ (defined($cs)) || croak('column slice does not contain a supported color space, stopped');
Branch: 1 branch
BranchTrueFalseTotal
defined $cs or croak("column slice does not contain a supported color space, stopped") 0 0 0
4829  
4830 # get bits per sample and verify
4831 0 ▶ $bits = defined($hash->{'bits'}) ? $hash->{'bits'} : 16;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'bits'} ? : 0 0 0
4832 0 ▶ ($bits == 8 || $bits == 16 || $bits == 32) || croak('invalid \'bits\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 or $bits == 16 or $bits == 32 or croak("invalid 'bits' parameter, stopped") 0 0 0
Condition0%0/6
$bits == 8 or $bits == 16 or $bits == 32
l!l&&r!l&&!r
000
$bits == 8 or $bits == 16
l!l&&r!l&&!r
000
MC/DC0%0/3
$bits == 8 or $bits == 16 or $bits == 32
$bits == 8 $bits == 16 $bits == 32
Truth table0%0/4
A or B or C
A= $bits == 8B= $bits == 16C= $bits == 32
ABCresult
1XX1
01X1
0011
0000
4833  
4834 # set little-endian flag from system config
4835 0 $le = ($Config{'byteorder'} =~ m/1234/);
4836  
4837 # if endian parameter provided
4838 0 ▶ if (defined($hash->{'endian'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"endian"}) 0 0 0
4839  
4840 # if little-endian
4841 0 ▶ if ($hash->{'endian'} eq 'little') {
Branch: 2 branches
BranchTrueFalseTotal
if ($hash->{'endian'} eq 'little') { } 0 0 0
elsif ($hash->{'endian'} eq 'big') { } 0 0 0
4842
4843 # set flag
4844 0 $le = 1;
4845
4846 # if big-endian
4847 } elsif ($hash->{'endian'} eq 'big') {
4848
4849 # clear flag
4850 0 $le = 0;
4851
4852 } else {
4853
4854 # warn
4855 0 warn('invalid \'endian\' parameter');
4856
4857 }
4858
4859 }
4860  
4861 # if little-endian
4862 0 ▶ if ($le) {
Branch: 1 branch
BranchTrueFalseTotal
if ($le) { } 0 0 0
4863
4864 # set 'pack' formats
4865 0 $short = 'v';
4866 0 $long = 'V';
4867 0 $fp = 'f<';
4868
4869 } else {
4870
4871 # set 'pack' formats
4872 0 $short = 'n';
4873 0 $long = 'N';
4874 0 $fp = 'f>';
4875
4876 }
4877  
4878 # make lookup hash of column slice fields
4879 0 ▶ %fields = map {defined($self->[1][0][$_]) ? ($self->[1][0][$_], $_) : ()} @{$cols};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[1][0][$_] ? : 0 0 0
4880  
4881 # if color space is RGB
4882 0 ▶ if ($cs eq 'RGB') {
Branch: 4 branches
BranchTrueFalseTotal
if ($cs eq 'RGB') { } 0 0 0
elsif ($cs eq 'CMYK' and $bits != 32) { } 0 0 0
elsif ($cs =~ /^([4-9A-F])CLR$/ and $bits != 32) { } 0 0 0
elsif ($cs eq 'LAB' and $bits != 32) { } 0 0 0
4883
4884 # set photometric interpretation
4885 0 $pi = 2;
4886
4887 # get alpha channels (if any)
4888 0 ▶ @alpha = map {defined($fields{"$base$_"}) ? $fields{"$base$_"} : ()} ('A', 'A0' .. 'A9');
Branch: 1 branch
BranchTrueFalseTotal
defined $fields{"$base$_"} ? : 0 0 0
4889
4890 # get refined column slice (including alpha channels)
4891 0 $rcols = [(map {$fields{"$base$_"}} qw(R G B)), @alpha];
4892
4893 # set pack format (8, 16 or 32 bits)
4894 0 ▶ $fmt = ($bits == 8) ? 'C*' : ($bits == 16) ? "$short*" : "$fp*";
Branch: 2 branches
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
$bits == 16 ? : 0 0 0
4895
4896 # set multiplier (8, 16 or 32 bits)
4897 0 ▶ $mult = ($bits == 8) ? 1 : ($bits == 16) ? 257 : 1/255;
Branch: 2 branches
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
$bits == 16 ? : 0 0 0
4898
4899 # if color space is CMYK (8 or 16 bits)
4900 ▶ } elsif ($cs eq 'CMYK' && $bits != 32) {
Condition0%0/3
$cs eq "CMYK" and $bits != 32
!ll&&!rl&&r
000
MC/DC0%0/2
$cs eq "CMYK" and $bits != 32
$cs eq "CMYK" $bits != 32
Truth table0%0/3
A and B
A= $cs eq "CMYK"B= $bits != 32
ABresult
0X0
100
111
4901
4902 # set photometric interpretation
4903 0 $pi = 5;
4904
4905 # get refined column slice
4906 0 $rcols = [map {$fields{"$base$_"}} qw(C M Y K)];
4907
4908 # set pack format (8 or 16 bits)
4909 0 ▶ $fmt = ($bits == 8) ? 'C*' : "$short*";
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
4910
4911 # set multiplier (8 or 16 bits)
4912 0 ▶ $mult = ($bits == 8) ? 2.55 : 655.35;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
4913
4914 # if color space is nCLR (8 or 16 bits)
4915 ▶ } elsif ($cs =~ m/^([4-9A-F])CLR$/ && $bits != 32) {
Condition0%0/3
$cs =~ /^([4-9A-F])CLR$/ and $bits != 32
!ll&&!rl&&r
000
MC/DC0%0/2
$cs =~ /^([4-9A-F])CLR$/ and $bits != 32
$cs =~ /^([4-9A-F])CLR$/ $bits != 32
Truth table0%0/3
A and B
A= $cs =~ /^([4-9A-F])CLR$/B= $bits != 32
ABresult
0X0
100
111
4916
4917 # set photometric interpretation
4918 0 $pi = 5;
4919
4920 # get refined column slice
4921 0 $rcols = [map {$fields{sprintf('%s%x', $base, $_)}} (1 .. CORE::hex($1))];
4922
4923 # set pack format (8 or 16 bits)
4924 0 ▶ $fmt = ($bits == 8) ? 'C*' : "$short*";
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
4925
4926 # set multiplier (8 or 16 bits)
4927 0 ▶ $mult = ($bits == 8) ? 2.55 : 655.35;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
4928
4929 # if color space if L*a*b* (8 or 16 bits)
4930 ▶ } elsif ($cs eq 'LAB' && $bits != 32) {
Condition0%0/3
$cs eq "LAB" and $bits != 32
!ll&&!rl&&r
000
MC/DC0%0/2
$cs eq "LAB" and $bits != 32
$cs eq "LAB" $bits != 32
Truth table0%0/3
A and B
A= $cs eq "LAB"B= $bits != 32
ABresult
0X0
100
111
4931
4932 # set photometric interpretation
4933 0 $pi = 8;
4934
4935 # get refined column slice
4936 0 $rcols = [map {$fields{"$base$_"}} qw(L A B)];
4937
4938 # set pack format (8 or 16 bits)
4939 0 ▶ $fmt = ($bits == 8) ? '(Ccc)*' : "$short*";
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
4940
4941 # set multipliers (8 or 16 bits)
4942 0 ▶ $mult = ($bits == 8) ? 2.55 : 655.35; # L*
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
4943 0 ▶ $mab = ($bits == 8) ? 1 : 256; # a* and b*
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
4944
4945 } else {
4946
4947 # error
4948 0 croak('invalid TIFF format');
4949
4950 }
4951  
4952 # verify all fields defined
4953 0 ▶ (@{$rcols} == grep {defined()} @{$rcols}) || croak('column slice has missing fields, stopped');
Branch: 1 branch
BranchTrueFalseTotal
@{$rcols;} == grep({defined $_;} @{$rcols;}) or croak("column slice has missing fields, stopped") 0 0 0
4954  
4955 # set number of samples
4956 0 $samples = @{$rcols};
4957  
4958 # get the sample patch width and verify
4959 0 ▶ $width = defined($hash->{'width'}) ? $hash->{'width'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'width'} ? : 0 0 0
4960 0 ▶ ($width == int($width) && $width > 0) || croak('invalid \'width\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$width == int $width and $width > 0 or croak("invalid 'width' parameter, stopped") 0 0 0
Condition0%0/3
$width == int $width and $width > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$width == int $width and $width > 0
$width == int $width $width > 0
Truth table0%0/3
A and B
A= $width == int $widthB= $width > 0
ABresult
0X0
100
111
4961  
4962 # get the sample patch height and verify
4963 0 ▶ $height = defined($hash->{'height'}) ? $hash->{'height'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'height'} ? : 0 0 0
4964 0 ▶ ($height == int($height) && $height > 0) || croak('invalid \'height\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$height == int $height and $height > 0 or croak("invalid 'height' parameter, stopped") 0 0 0
Condition0%0/3
$height == int $height and $height > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$height == int $height and $height > 0
$height == int $height $height > 0
Truth table0%0/3
A and B
A= $height == int $heightB= $height > 0
ABresult
0X0
100
111
4965  
4966 # get the sample patch gap and verify
4967 0 ▶ $gap = defined($hash->{'gap'}) ? $hash->{'gap'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'gap'} ? : 0 0 0
4968 0 ▶ ($gap == int($gap) && $gap >= 0) || croak('invalid \'gap\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$gap == int $gap and $gap >= 0 or croak("invalid 'gap' parameter, stopped") 0 0 0
Condition0%0/3
$gap == int $gap and $gap >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$gap == int $gap and $gap >= 0
$gap == int $gap $gap >= 0
Truth table0%0/3
A and B
A= $gap == int $gapB= $gap >= 0
ABresult
0X0
100
111
4969  
4970 # get the left edge width and verify
4971 0 ▶ $left = defined($hash->{'left'}) ? $hash->{'left'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'left'} ? : 0 0 0
4972 0 ▶ ($left =~ m/^([0-9]+)(?:\.([0-9]+))?$/ && (! defined($2) || $1 >= $2)) || croak('invalid \'left\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$left =~ /^([0-9]+)(?:\.([0-9]+))?$/ and !defined($2) || $1 >= $2 or croak("invalid 'left' parameter, stopped") 0 0 0
Condition0%0/6
$left =~ /^([0-9]+)(?:\.([0-9]+))?$/ and !defined($2) || $1 >= $2
!ll&&!rl&&r
000
not defined $2 or $1 >= $2
l!l&&r!l&&!r
000
MC/DC0%0/3
$left =~ /^([0-9]+)(?:\.([0-9]+))?$/ and !defined($2) || $1 >= $2
$left =~ /^([0-9]+)(?:\.([0-9]+))?$/ not defined $2 $1 >= $2
Truth table0%0/4
A and not(B) or C
A= $left =~ /^([0-9]+)(?:\.([0-9]+))?$/B= not defined $2C= $1 >= $2
ABCresult
0XX0
1000
11X1
1011
4973 0 ▶ $left = [$1, defined($2) ? $2 : 0];
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 0 0
4974  
4975 # get the right edge width and verify
4976 0 ▶ $right = defined($hash->{'right'}) ? $hash->{'right'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'right'} ? : 0 0 0
4977 0 ▶ ($right =~ m/^([0-9]+)(?:\.([0-9]+))?$/ && (! defined($2) || $1 >= $2)) || croak('invalid \'right\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$right =~ /^([0-9]+)(?:\.([0-9]+))?$/ and !defined($2) || $1 >= $2 or croak("invalid 'right' parameter, stopped") 0 0 0
Condition0%0/6
$right =~ /^([0-9]+)(?:\.([0-9]+))?$/ and !defined($2) || $1 >= $2
!ll&&!rl&&r
000
not defined $2 or $1 >= $2
l!l&&r!l&&!r
000
MC/DC0%0/3
$right =~ /^([0-9]+)(?:\.([0-9]+))?$/ and !defined($2) || $1 >= $2
$right =~ /^([0-9]+)(?:\.([0-9]+))?$/ not defined $2 $1 >= $2
Truth table0%0/4
A and not(B) or C
A= $right =~ /^([0-9]+)(?:\.([0-9]+))?$/B= not defined $2C= $1 >= $2
ABCresult
0XX0
1000
11X1
1011
4978 0 ▶ $right = [$1, defined($2) ? $2 : 0];
Branch: 1 branch
BranchTrueFalseTotal
defined $2 ? : 0 0 0
4979  
4980 # get the x-resolution and verify
4981 0 ▶ $xres = defined($hash->{'xres'}) ? $hash->{'xres'} : 72;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'xres'} ? : 0 0 0
4982 0 ▶ ($xres > 0 && $xres <= 4E4) || croak('invalid \'xres\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$xres > 0 and $xres <= 40000 or croak("invalid 'xres' parameter, stopped") 0 0 0
Condition0%0/3
$xres > 0 and $xres <= 40000
!ll&&!rl&&r
000
MC/DC0%0/2
$xres > 0 and $xres <= 40000
$xres > 0 $xres <= 40000
Truth table0%0/3
A and B
A= $xres > 0B= $xres <= 40000
ABresult
0X0
100
111
4983  
4984 # get the y-resolution and verify
4985 0 ▶ $yres = defined($hash->{'yres'}) ? $hash->{'yres'} : 72;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'yres'} ? : 0 0 0
4986 0 ▶ ($yres > 0 && $yres <= 4E4) || croak('invalid \'yres\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$yres > 0 and $yres <= 40000 or croak("invalid 'yres' parameter, stopped") 0 0 0
Condition0%0/3
$yres > 0 and $yres <= 40000
!ll&&!rl&&r
000
MC/DC0%0/2
$yres > 0 and $yres <= 40000
$yres > 0 $yres <= 40000
Truth table0%0/3
A and B
A= $yres > 0B= $yres <= 40000
ABresult
0X0
100
111
4987  
4988 # get the resolution unit and verify
4989 0 ▶ $unit = defined($hash->{'unit'}) ? $hash->{'unit'} : 2;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'unit'} ? : 0 0 0
4990 0 ▶ ($unit == 1 || $unit == 2 || $unit == 3) || croak('invalid \'unit\' parameter, stopped');
Branch: 1 branch
BranchTrueFalseTotal
$unit == 1 or $unit == 2 or $unit == 3 or croak("invalid 'unit' parameter, stopped") 0 0 0
Condition0%0/6
$unit == 1 or $unit == 2 or $unit == 3
l!l&&r!l&&!r
000
$unit == 1 or $unit == 2
l!l&&r!l&&!r
000
MC/DC0%0/3
$unit == 1 or $unit == 2 or $unit == 3
$unit == 1 $unit == 2 $unit == 3
Truth table0%0/4
A or B or C
A= $unit == 1B= $unit == 2C= $unit == 3
ABCresult
1XX1
01X1
0011
0000
4991  
4992 # compute image width
4993 0 $imagewidth = $tcols * $width + ($tcols - 1) * $gap + $left->[0] - $left->[1] + $right->[0] - $right->[1];
4994  
4995 # compute strip byte count
4996 0 $bytecount = $imagewidth * $height * $samples * $bits/8;
4997  
4998 # compute strip size (strips must begin on word boundary)
4999 0 $stripsize = $bytecount + $bytecount % 2;
5000  
5001 # set image tags [type, data]
5002 0 $tags->{'256'} = [3, $imagewidth]; # ImageWidth
5003 0 $tags->{'257'} = [3, $trows * $height]; # ImageLength
5004 0 $tags->{'258'} = [3, ($bits) x $samples]; # BitsPerSample
5005 0 $tags->{'259'} = [3, 1]; # Compression
5006 0 $tags->{'262'} = [3, $pi]; # PhotometricInterpretation
5007 0 $tags->{'273'} = [4, map {$_ * $stripsize + 8} (0 .. $trows - 1)]; # StripOffsets
5008 0 $tags->{'277'} = [3, $samples]; # SamplesPerPixel
5009 0 $tags->{'278'} = [3, $height]; # RowsPerStrip
5010 0 $tags->{'279'} = [4, ($bytecount) x $trows]; # StripByteCounts
5011 0 $tags->{'282'} = [5, $xres * 1E4, 1E4]; # XResolution
5012 0 $tags->{'283'} = [5, $yres * 1E4, 1E4]; # YResolution
5013 0 $tags->{'296'} = [3, $unit]; # ResolutionUnit
5014 0 ▶ $tags->{'339'} = [3, (3) x $samples] if ($bits == 32); # SampleFormat
Branch: 1 branch
BranchTrueFalseTotal
if $bits == 32 0 0 0
5015  
5016 # resolve file list from path
5017 0 ▶ (defined($path) && (! ref($path)) && (@files = File::Glob::bsd_glob($path))) || croak("invalid path: $path, stopped");
Branch: 1 branch
BranchTrueFalseTotal
defined $path and not ref $path and @files = File::Glob::bsd_glob($path) or croak("invalid path: $path, stopped") 0 0 0
Condition0%0/6
defined $path and not ref $path and @files = File::Glob::bsd_glob($path)
!ll&&!rl&&r
000
defined $path and not ref $path
!ll&&!rl&&r
000
MC/DC0%0/3
defined $path and not ref $path and @files = File::Glob::bsd_glob($path)
defined $path not ref $path @files = File::Glob::bsd_glob($path)
Truth table0%0/4
A and not(B) and C
A= defined $pathB= not ref $pathC= @files = File::Glob::bsd_glob($path)
ABCresult
0XX0
10X0
1100
1111
5018  
5019 # verify file path is unique
5020 0 ▶ (@files == 1) || warn('file path not unique');
Branch: 1 branch
BranchTrueFalseTotal
@files == 1 or warn "file path not unique" 0 0 0
5021  
5022 # open the file
5023 0 ▶ open($fh, '>', $files[0]) || croak("$! when opening $files[0], stopped");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $files[0] or croak("$! when opening $files[0], stopped") 0 0 0
5024  
5025 # set binary mode
5026 0 binmode($fh);
5027  
5028 # write TIFF header
5029 0 ▶ print $fh pack("A2$short$long", $le ? 'II' : 'MM', 42, $ifd = $trows * $stripsize + 8);
Branch: 1 branch
BranchTrueFalseTotal
$le ? : 0 0 0
5030  
5031 # set min/max values
5032 0 ▶ $max = ($bits == 8) ? 255 : ($bits == 16) ? 65535 : 1;
Branch: 2 branches
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
$bits == 16 ? : 0 0 0
5033 0 ▶ $minab = ($bits == 8) ? -128 : -32768;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
5034 0 ▶ $maxab = ($bits == 8) ? 127 : 32767;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
5035  
5036 # for each strip
5037 0 for my $i (0 .. $trows - 1) {
5038
5039 # for each patch in strip
5040 0 for my $j (0 .. $tcols - 1) {
5041
5042 # if patch in row slice
5043 0 ▶ if (defined($rows->[$trows * $j + $i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$rows[$trows * $j + $i]) { } 0 0 0
5044
5045 # if L*a*b* data
5046 0 ▶ if ($pi == 8) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pi == 8) { } 0 0 0
elsif ($pi == 5 and @{$rcols;} > 4) { } 0 0 0
5047
5048 # get the data
5049 0 $data->[$j][0] = $mult * $self->[1][$rows->[$trows * $j + $i]][$rcols->[0]];
5050 0 $data->[$j][1] = $mab * $self->[1][$rows->[$trows * $j + $i]][$rcols->[1]];
5051 0 $data->[$j][2] = $mab * $self->[1][$rows->[$trows * $j + $i]][$rcols->[2]];
5052
5053 # limit the data
5054 0 ▶ $data->[$j][0] = $data->[$j][0] < 0 ? 0 : ($data->[$j][0] > $max ? $max : $data->[$j][0]);
Branch: 2 branches
BranchTrueFalseTotal
$data->[$j][0] < 0 ? : 0 0 0
$data->[$j][0] > $max ? : 0 0 0
5055 0 ▶ $data->[$j][1] = $data->[$j][1] < $minab ? $minab : ($data->[$j][1] > $maxab ? $maxab : $data->[$j][1]);
Branch: 2 branches
BranchTrueFalseTotal
$data->[$j][1] < $minab ? : 0 0 0
$data->[$j][1] > $maxab ? : 0 0 0
5056 0 ▶ $data->[$j][2] = $data->[$j][2] < $minab ? $minab : ($data->[$j][2] > $maxab ? $maxab : $data->[$j][2]);
Branch: 2 branches
BranchTrueFalseTotal
$data->[$j][2] < $minab ? : 0 0 0
$data->[$j][2] > $maxab ? : 0 0 0
5057
5058 # if CMYK + spot data
5059 0 ▶ } elsif ($pi == 5 && @{$rcols} > 4) {
Condition0%0/3
$pi == 5 and @{$rcols;} > 4
!ll&&!rl&&r
000
MC/DC0%0/2
$pi == 5 and @{$rcols;} > 4
$pi == 5 @{$rcols;} > 4
Truth table0%0/3
A and B
A= $pi == 5B= @{$rcols;} > 4
ABresult
0X0
100
111
5060
5061 # get CMYK values
5062 0 @cmyk = @{$self->[1][$rows->[$trows * $j + $i]]}[@{$rcols}[0 .. 3]];
5063
5064 # get spot values
5065 0 @spot = @{$self->[1][$rows->[$trows * $j + $i]]}[@{$rcols}[4 .. $#{$rcols}]];
5066
5067 # get the data (spot channels are inverted)
5068 0 $data->[$j] = [(map {$_ * $mult} @cmyk), (map {(100 - $_) * $mult} @spot)];
5069
5070 # limit the data
5071 0 ▶ @{$data->[$j]} = map {$_ < 0 ? 0 : ($_ > $max ? $max : $_)} @{$data->[$j]};
Branch: 2 branches
BranchTrueFalseTotal
$_ < 0 ? : 0 0 0
$_ > $max ? : 0 0 0
5072
5073 # RGB data
5074 } else {
5075
5076 # get the data
5077 0 $data->[$j] = [map {$_ * $mult} @{$self->[1][$rows->[$trows * $j + $i]]}[@{$rcols}]];
5078
5079 # limit the data (8 or 16 bits)
5080 0 ▶ @{$data->[$j]} = map {$_ < 0 ? 0 : ($_ > $max ? $max : $_)} @{$data->[$j]} if ($bits != 32);
Branch: 3 branches
BranchTrueFalseTotal
if $bits != 32 0 0 0
$_ < 0 ? : 0 0 0
$_ > $max ? : 0 0 0
5081
5082 }
5083
5084 # patch undefined
5085 } else {
5086
5087 # if L*a*b* data
5088 0 ▶ if ($pi == 8) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pi == 8) { } 0 0 0
elsif ($pi == 5) { } 0 0 0
5089
5090 # if last patch
5091 0 ▶ if ($i == ($trows - 1) && $j == ($tcols - 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $trows - 1 and $j == $tcols - 1) { } 0 0 0
Condition0%0/3
$i == $trows - 1 and $j == $tcols - 1
!ll&&!rl&&r
000
MC/DC0%0/2
$i == $trows - 1 and $j == $tcols - 1
$i == $trows - 1 $j == $tcols - 1
Truth table0%0/3
A and B
A= $i == $trows - 1B= $j == $tcols - 1
ABresult
0X0
100
111
5092
5093 # set gray value
5094 0 $data->[$j] = [$max * 0.7, 0, 0];
5095
5096 } else {
5097
5098 # set white value
5099 0 $data->[$j] = [$max, 0, 0];
5100
5101 }
5102
5103 # if CMYK + spot data
5104 } elsif ($pi == 5) {
5105
5106 # if last patch
5107 0 ▶ if ($i == ($trows - 1) && $j == ($tcols - 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $trows - 1 and $j == $tcols - 1) { } 0 0 0
Condition0%0/3
$i == $trows - 1 and $j == $tcols - 1
!ll&&!rl&&r
000
MC/DC0%0/2
$i == $trows - 1 and $j == $tcols - 1
$i == $trows - 1 $j == $tcols - 1
Truth table0%0/3
A and B
A= $i == $trows - 1B= $j == $tcols - 1
ABresult
0X0
100
111
5108
5109 # set gray value
5110 0 $data->[$j] = [0, 0, 0, $max * 0.4, ($max) x ($samples - 4)];
5111
5112 } else {
5113
5114 # set white value
5115 0 $data->[$j] = [0, 0, 0, 0, ($max) x ($samples - 4)];
5116
5117 }
5118
5119 # RGB data
5120 } else {
5121
5122 # if last patch
5123 0 ▶ if ($i == ($trows - 1) && $j == ($tcols - 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $trows - 1 and $j == $tcols - 1) { } 0 0 0
Condition0%0/3
$i == $trows - 1 and $j == $tcols - 1
!ll&&!rl&&r
000
MC/DC0%0/2
$i == $trows - 1 and $j == $tcols - 1
$i == $trows - 1 $j == $tcols - 1
Truth table0%0/3
A and B
A= $i == $trows - 1B= $j == $tcols - 1
ABresult
0X0
100
111
5124
5125 # set gray value
5126 0 $data->[$j] = [($max * 0.7) x $samples];
5127
5128 } else {
5129
5130 # set white value
5131 0 $data->[$j] = [($max) x $samples];
5132
5133 }
5134
5135 }
5136
5137 }
5138
5139 }
5140
5141 # write TIFF strip
5142 0 _writeTIFFstrip($fh, $tags, $width, $gap, $left, $right, $i, $data, $fmt, $hash->{'dither'});
5143
5144 }
5145  
5146 # write TIFF IFD
5147 0 _writeTIFFdir($fh, $ifd, $short, $long, $tags);
5148  
5149 # close file
5150 0 close($fh);
5151  
5152 }
5153  
5154 # write chart to Adobe Swatch Exchange (.ase) file
5155 # column slice must be CMYK, RGB or L*a*b*
5156 # color type: 0 - global, 1 - spot, 2 - normal (default)
5157 # parameters: (path_to_file, row_slice, column_slice, [color_type])
5158 sub writeASE {
5159  
5160 # get parameters
5161 0 ▶ my ($self, $path, $rows, $cols, $type) = @_;
Subroutine writeASE: not called CC=33 SCAR=70.2
Pod documented
5162  
5163 # local variables
5164 0 my ($n, @fmt, $cs, $le, $sn, @files, $fh);
5165 0 my ($name, $slen, $blen);
5166 0 my ($cmyk, $rgb, $Lab, $val);
5167  
5168 # verify row_slice and column_slice are supplied
5169 0 ▶ (defined($rows) && defined($cols)) || croak('missing parameters');
Branch: 1 branch
BranchTrueFalseTotal
defined $rows and defined $cols or croak("missing parameters") 0 0 0
Condition0%0/3
defined $rows and defined $cols
!ll&&!rl&&r
000
MC/DC0%0/2
defined $rows and defined $cols
defined $rows defined $cols
Truth table0%0/3
A and B
A= defined $rowsB= defined $cols
ABresult
0X0
100
111
5170  
5171 # if row slice an empty array reference
5172 0 ▶ if (ref($rows) eq 'ARRAY' && @{$rows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 0 0 0
Condition0%0/3
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $rows eq "ARRAY" and @{$rows;} == 0
ref $rows eq "ARRAY" @{$rows;} == 0
Truth table0%0/3
A and B
A= ref $rows eq "ARRAY"B= @{$rows;} == 0
ABresult
0X0
100
111
5173
5174 # use all rows
5175 0 $rows = [1 .. $#{$self->[1]}];
5176
5177 } else {
5178
5179 # flatten row slice
5180 0 $rows = ICC::Shared::flatten($rows);
5181
5182 }
5183  
5184 # get number of rows
5185 0 $n = @{$rows};
5186  
5187 # filter row slice
5188 0 ▶ @{$rows} = grep {$_ == int($_) && $_ != 0 && defined($self->[1][$_])} @{$rows};
Branch: 1 branch
BranchTrueFalseTotal
$_ == int $_ and $_ != 0 and defined $self->[1][$_] 0 0 0
Condition0%0/3
$_ == int $_ and $_ != 0
!ll&&!rl&&r
000
MC/DC0%0/2
$_ == int $_ and $_ != 0
$_ == int $_ $_ != 0
Truth table0%0/3
A and B
A= $_ == int $_B= $_ != 0
ABresult
0X0
100
111
5189  
5190 # warn if invalid samples
5191 0 ▶ ($n == @{$rows}) || warn('row slice contains invalid samples');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$rows;} or warn "row slice contains invalid samples" 0 0 0
5192  
5193 # get format array
5194 0 @fmt = @{$self->[1][0]}[@{$cols}];
5195  
5196 # if column slice is CMYK
5197 0 ▶ if (4 == @fmt && 4 == grep {m/^(?:.*\|)?CMYK_[CMYK]$/} @fmt) {
Branch: 3 branches
BranchTrueFalseTotal
if (4 == @fmt and 4 == grep({/^(?:.*\|)?CMYK_[CMYK]$/;} @fmt)) { } 0 0 0
elsif (3 == @fmt and 3 == grep({/^(?:.*\|)?RGB_[RGB]$/;} @fmt)) { } 0 0 0
elsif (3 == @fmt and 3 == grep({/^(?:.*\|)?LAB_[LAB]$/;} @fmt)) { } 0 0 0
Condition0%0/3
4 == @fmt and 4 == grep({/^(?:.*\|)?CMYK_[CMYK]$/;} @fmt)
!ll&&!rl&&r
000
MC/DC0%0/2
4 == @fmt and 4 == grep({/^(?:.*\|)?CMYK_[CMYK]$/;} @fmt)
4 == @fmt 4 == grep({/^(?:.*\|)?CMYK_[CMYK]$/;} @fmt)
Truth table0%0/3
A and B
A= 4 == @fmtB= 4 == grep({/^(?:.*\|)?CMYK_[CMYK]$/;} @fmt)
ABresult
0X0
100
111
5198
5199 # set color space
5200 0 $cs = 'CMYK';
5201
5202 # if column slice is RGB
5203 0 ▶ } elsif (3 == @fmt && 3 == grep {m/^(?:.*\|)?RGB_[RGB]$/} @fmt) {
Condition0%0/3
3 == @fmt and 3 == grep({/^(?:.*\|)?RGB_[RGB]$/;} @fmt)
!ll&&!rl&&r
000
MC/DC0%0/2
3 == @fmt and 3 == grep({/^(?:.*\|)?RGB_[RGB]$/;} @fmt)
3 == @fmt 3 == grep({/^(?:.*\|)?RGB_[RGB]$/;} @fmt)
Truth table0%0/3
A and B
A= 3 == @fmtB= 3 == grep({/^(?:.*\|)?RGB_[RGB]$/;} @fmt)
ABresult
0X0
100
111
5204
5205 # set color space
5206 0 $cs = 'RGB ';
5207
5208 # if column slice is L*a*b*
5209 0 ▶ } elsif (3 == @fmt && 3 == grep {m/^(?:.*\|)?LAB_[LAB]$/} @fmt) {
Condition0%0/3
3 == @fmt and 3 == grep({/^(?:.*\|)?LAB_[LAB]$/;} @fmt)
!ll&&!rl&&r
000
MC/DC0%0/2
3 == @fmt and 3 == grep({/^(?:.*\|)?LAB_[LAB]$/;} @fmt)
3 == @fmt 3 == grep({/^(?:.*\|)?LAB_[LAB]$/;} @fmt)
Truth table0%0/3
A and B
A= 3 == @fmtB= 3 == grep({/^(?:.*\|)?LAB_[LAB]$/;} @fmt)
ABresult
0X0
100
111
5210
5211 # set color space
5212 0 $cs = 'LAB ';
5213
5214 } else {
5215
5216 # error
5217 0 croak('invalid column slice');
5218
5219 }
5220
5221 # if color type is undefined, set default (2 - normal)
5222 0 ▶ $type = 2 if (! defined($type));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type 0 0 0
5223
5224 # verify color type
5225 0 ▶ ($type == int($type) && $type >= 0 && $type <= 2) || croak('invalid ASE color type');
Branch: 1 branch
BranchTrueFalseTotal
$type == int $type and $type >= 0 and $type <= 2 or croak("invalid ASE color type") 0 0 0
Condition0%0/6
$type == int $type and $type >= 0 and $type <= 2
!ll&&!rl&&r
000
$type == int $type and $type >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$type == int $type and $type >= 0 and $type <= 2
$type == int $type $type >= 0 $type <= 2
Truth table0%0/4
A and B and C
A= $type == int $typeB= $type >= 0C= $type <= 2
ABCresult
0XX0
10X0
1100
1111
5226
5227 # get little-endian flag
5228 0 $le = ($Config{'byteorder'} =~ m/1234/);
5229
5230 # get sample name slice (could be undefined)
5231 0 $sn = $self->name;
5232
5233 # resolve file list from path
5234 0 ▶ (@files = File::Glob::bsd_glob($path)) || croak('invalid file path');
Branch: 1 branch
BranchTrueFalseTotal
@files = File::Glob::bsd_glob($path) or croak("invalid file path") 0 0 0
5235
5236 # verify file path is unique
5237 0 ▶ (@files == 1) || warn('file path not unique');
Branch: 1 branch
BranchTrueFalseTotal
@files == 1 or warn "file path not unique" 0 0 0
5238
5239 # open file
5240 0 open($fh, '>', $files[0]);
5241  
5242 # set binary mode
5243 0 binmode($fh);
5244  
5245 # print header (file signature, version, number of blocks)
5246 0 print $fh pack('A4nnN', 'ASEF', 1, 0, scalar(@{$rows}));
5247
5248 # for each sample
5249 0 for my $s (@{$rows}) {
5250
5251 # if color space is CMYK
5252 0 ▶ if ($cs eq 'CMYK') {
Branch: 3 branches
BranchTrueFalseTotal
if ($cs eq 'CMYK') { } 0 0 0
elsif ($cs eq 'RGB ') { } 0 0 0
elsif ($cs eq 'LAB ') { } 0 0 0
5253
5254 # get the CMYK values
5255 0 $cmyk = $self->slice([$s], $cols);
5256
5257 # if SAMPLE_NAME is defined
5258 0 ▶ if (defined($sn)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sn) { } 0 0 0
5259
5260 # get color name
5261 0 $name = $self->[1][$s][$sn->[0]];
5262
5263 # replace underscores with spaces
5264 0 $name =~ s/_/ /g;
5265
5266 } else {
5267
5268 # build color name from CMYK values
5269 0 $name = sprintf('C=%d M=%d Y=%d K=%d', @{$cmyk->[0]});
5270
5271 }
5272
5273 # compute string length
5274 0 $slen = length($name) + 1;
5275
5276 # compute block length
5277 0 $blen = 2 * $slen + 24;
5278
5279 # print block
5280 0 print $fh pack('nNn', 1, $blen, $slen);
5281 0 print $fh encode('UTF-16BE', $name . "\x00");
5282 0 print $fh pack('A4', 'CMYK');
5283
5284 # for each CMYK value
5285 0 for my $i (0 .. 3) {
5286
5287 # convert to floating point
5288 0 $val = pack('f', $cmyk->[0][$i]/100);
5289
5290 # reverse if little-endian system
5291 0 ▶ $val = reverse($val) if ($le);
Branch: 1 branch
BranchTrueFalseTotal
if $le 0 0 0
5292
5293 # print value
5294 0 print $fh $val;
5295
5296 }
5297
5298 # print color type
5299 0 print $fh pack('n', $type);
5300
5301 # if color space is RGB
5302 } elsif ($cs eq 'RGB ') {
5303
5304 # get the RGB values
5305 0 $rgb = $self->slice([$s], $cols);
5306
5307 # if SAMPLE_NAME is defined
5308 0 ▶ if (defined($sn)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sn) { } 0 0 0
5309
5310 # get color name
5311 0 $name = $self->[1][$s][$sn->[0]];
5312
5313 # replace underscores with spaces
5314 0 $name =~ s/_/ /g;
5315
5316 } else {
5317
5318 # build color name from RGB values
5319 0 $name = sprintf('R=%d G=%d B=%d', @{$rgb->[0]});
5320
5321 }
5322
5323 # compute string length
5324 0 $slen = length($name) + 1;
5325
5326 # compute block length
5327 0 $blen = 2 * $slen + 20;
5328
5329 # print block
5330 0 print $fh pack('nNn', 1, $blen, $slen);
5331 0 print $fh encode('UTF-16BE', $name . "\x00");
5332 0 print $fh pack('A4', 'RGB ');
5333
5334 # for each RGB value
5335 0 for my $i (0 .. 2) {
5336
5337 # convert to floating point
5338 0 $val = pack('f', $rgb->[0][$i]/255);
5339
5340 # reverse if little-endian system
5341 0 ▶ $val = reverse($val) if ($le);
Branch: 1 branch
BranchTrueFalseTotal
if $le 0 0 0
5342
5343 # print value
5344 0 print $fh $val;
5345
5346 }
5347
5348 # print color type
5349 0 print $fh pack('n', $type);
5350
5351 # if color space is L*a*b*
5352 } elsif ($cs eq 'LAB ') {
5353
5354 # get the L*a*b* values
5355 0 $Lab = $self->slice([$s], $cols);
5356
5357 # if SAMPLE_NAME is defined
5358 0 ▶ if (defined($sn)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sn) { } 0 0 0
5359
5360 # get color name
5361 0 $name = $self->[1][$s][$sn->[0]];
5362
5363 # replace underscores with spaces
5364 0 $name =~ s/_/ /g;
5365
5366 } else {
5367
5368 # build color name from L*a*b* values
5369 0 $name = sprintf('L=%d a=%d b=%d', @{$Lab->[0]});
5370
5371 }
5372
5373 # compute string length
5374 0 $slen = length($name) + 1;
5375
5376 # compute block length
5377 0 $blen = 2 * $slen + 20;
5378
5379 # print block
5380 0 print $fh pack('nNn', 1, $blen, $slen);
5381 0 print $fh encode('UTF-16BE', $name . "\x00");
5382 0 print $fh pack('A4', 'LAB ');
5383
5384 # modify L* value
5385 0 $Lab->[0][0] /= 100;
5386
5387 # for each L*a*b* value
5388 0 for my $i (0 .. 2) {
5389
5390 # convert to floating point
5391 0 $val = pack('f', $Lab->[0][$i]);
5392
5393 # reverse if little-endian system
5394 0 ▶ $val = reverse($val) if ($le);
Branch: 1 branch
BranchTrueFalseTotal
if $le 0 0 0
5395
5396 # print value
5397 0 print $fh $val;
5398
5399 }
5400
5401 # print color type
5402 0 print $fh pack('n', $type);
5403
5404 }
5405
5406 }
5407
5408 # close file
5409 0 close($fh);
5410
5411 }
5412  
5413 # print object contents to string
5414 # format is an array structure
5415 # parameter: ([format])
5416 # returns: (string)
5417 sub sdump {
5418  
5419 # get parameters
5420 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
5421  
5422 # local variables
5423 0 my ($s, $fmt);
5424  
5425 # resolve parameter to an array reference
5426 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
5427  
5428 # get format string
5429 0 ▶ $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $p->[0] && !ref($p->[0]) ? : 0 0 0
Condition0%0/3
defined $p->[0] and not ref $p->[0]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $p->[0] and not ref $p->[0]
defined $p->[0] not ref $p->[0]
Truth table0%0/3
A and not(B)
A= defined $p->[0]B= not ref $p->[0]
ABresult
0X0
100
111
5430  
5431 # set string to object ID
5432 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
5433  
5434 # return
5435 0 return($s);
5436  
5437 }
5438  
5439 # get column slice from DATA_FORMAT keys
5440 # format_keys is a list of keys with optional context
5441 # column_slice is reference to an array of column indices
5442 # note: returns 'undef' if any column is missing
5443 # parameters: (format_keys)
5444 # returns: (column_slice)
5445 sub _cols {
5446  
5447 # get object reference
5448 0 ▶ my $self = shift();
Subroutine _cols: not called CC=3 SCAR=24.8
5449  
5450 # local variables
5451 0 my (%fmt, @cols);
5452  
5453 # make lookup hash of DATA_FORMAT keys
5454 0 ▶ %fmt = map {defined($self->[1][0][$_]) ? ($self->[1][0][$_], $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[1][0][$_] ? : 0 0 0
5455  
5456 # lookup format keys in hash
5457 0 @cols = @fmt{@_};
5458  
5459 # return column slice or undef if any columns undefined
5460 0 ▶ return((grep {! defined()} @cols) ? undef : \@cols);
Branch: 1 branch
BranchTrueFalseTotal
grep({not defined $_;} @cols) ? : 0 0 0
5461  
5462 }
5463  
5464 # get spectral fields array
5465 # array contains column indices and wavelength
5466 # and is sorted by wavelength (low to high)
5467 # parameters: (object_reference, [context])
5468 # returns: (array_reference)
5469 sub _spectral {
5470  
5471 # get parameters
5472 45 ▶ my ($self, $context) = @_;
Subroutine _spectral: called CC=9 SCAR=22.0
5473  
5474 # local variables
5475 45 my (%fmt, @fields);
5476  
5477 # make lookup hash (context|wavelength -or- wavelength => column)
5478 45 ▶ %fmt = map {($self->[1][0][$_] =~ m/^(.*\|)?(?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)(\d{3})$/) ? (defined($1) ? "$1$2" : $2, $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 2 branches
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(.*\|)?(?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)(\d{3})$/ ? : 1440 239 1679
defined $1 ? : 972 468 1440
5479  
5480 # if context defined
5481 45 ▶ if (defined($context)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $context) { } 18 27 45
5482
5483 # make list of matching fields
5484 18 ▶ @fields = map {m/^$context\|(\d{3})$/ ? [$fmt{$_}, $1] : ()} keys(%fmt);
Branch: 1 branch
BranchTrueFalseTotal
/^$context\|(\d{3})$/ ? : 432 108 540
5485
5486 } else {
5487
5488 # make list of matching fields
5489 27 ▶ @fields = map {m/^(\d{3})$/ ? [$fmt{$_}, $1] : ()} keys(%fmt);
Branch: 1 branch
BranchTrueFalseTotal
/^(\d{3})$/ ? : 468 432 900
5490
5491 # if no matching fields
5492 27 ▶ if (@fields == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fields == 0) 14 13 27
5493
5494 # make lookup hash (wavelength => column)
5495 14 ▶ %fmt = map {($self->[1][0][$_] =~ m/^(?:.*\|)?(?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)(\d{3})$/) ? ($1, $_) : ()} (0 .. $#{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$_] =~ /^(?:.*\|)?(?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)(\d{3})$/ ? : 432 71 503
5496
5497 # make list of fields
5498 14 @fields = map {[$fmt{$_}, $_]} keys(%fmt);
5499
5500 }
5501
5502 }
5503  
5504 # return undef if no match
5505 45 ▶ return() if (@fields == 0);
Branch: 1 branch
BranchTrueFalseTotal
if @fields == 0 8 37 45
5506  
5507 # sort by wavelength
5508 37 @fields = sort {$a->[1] <=> $b->[1]} @fields;
5509  
5510 # return array reference
5511 37 return(\@fields);
5512  
5513 }
5514  
5515 # binary search
5516 # locates the interval containing or bounding the target value
5517 # returns an array of four index values, which indicate upper and lower transitions
5518 # parameters: (source_array, target_value, channel_index, low_index, high_index)
5519 # returns: (interval_index_array)
5520 sub _bin_search {
5521
5522 # get parameters
5523 0 ▶ my ($source, $target, $channel, $low, $high) = @_;
Subroutine _bin_search: not called CC=5 SCAR=34.0
5524
5525 # local variables
5526 0 my ($k, $interval);
5527
5528 # copy low and high indices
5529 0 $interval->[0] = $low;
5530 0 $interval->[1] = $high;
5531
5532 # while interval is open
5533 0 ▶ while ($interval->[1] - $interval->[0] > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval->[1] - $interval->[0] > 1) 0 0 0
5534
5535 # compute the midpoint
5536 0 $k = int(($interval->[1] + $interval->[0])/2);
5537
5538 # if midpoint value >= target value
5539 0 ▶ if ($source->[$k][$channel] >= $target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->[$k][$channel] >= $target) { } 0 0 0
5540
5541 # set higher index to midpoint
5542 0 $interval->[1] = $k;
5543
5544 } else {
5545
5546 # set lower index to midpoint
5547 0 $interval->[0] = $k;
5548
5549 }
5550
5551 }
5552
5553 # copy low and high indices
5554 0 $interval->[2] = $low;
5555 0 $interval->[3] = $high;
5556
5557 # while interval is open
5558 0 ▶ while ($interval->[3] - $interval->[2] > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval->[3] - $interval->[2] > 1) 0 0 0
5559
5560 # compute the midpoint
5561 0 $k = int(($interval->[3] + $interval->[2])/2);
5562
5563 # if midpoint value > target value
5564 0 ▶ if ($source->[$k][$channel] > $target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->[$k][$channel] > $target) { } 0 0 0
5565
5566 # set higher index to midpoint
5567 0 $interval->[3] = $k;
5568
5569 } else {
5570
5571 # set lower index to midpoint
5572 0 $interval->[2] = $k;
5573
5574 }
5575
5576 }
5577
5578 # return interval array
5579 0 return($interval);
5580
5581 }
5582  
5583 # linear search
5584 # locates the closest source sample based on Manhattan distance
5585 # parameters: (source_array, target_vector)
5586 # returns: (low_index, high_index)
5587 sub _lin_search {
5588
5589 # get parameters
5590 0 ▶ my ($source, $target) = @_;
Subroutine _lin_search: not called CC=7 SCAR=40.3
5591
5592 # local variables
5593 0 my ($d0, $d1, $d2, $low, $high);
5594
5595 # set initial difference
5596 0 $d0 = @{$target};
5597
5598 # for each source sample
5599 0 for my $i (0 .. $#{$source}) {
5600
5601 # clear differences
5602 0 $d1 = $d2 = 0;
5603
5604 # for each channel
5605 0 for my $j (0 .. $#{$target}) {
5606
5607 # add difference to target sample
5608 0 $d1 += abs($source->[$i][$j] - $target->[$j]);
5609
5610 # add difference to previous sample
5611 0 ▶ $d2 += abs($source->[$i][$j] - $source->[$i - 1][$j]) if ($i > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $i > 0 0 0 0
5612
5613 }
5614
5615 # if new difference less
5616 0 ▶ if ($d1 < $d0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d1 < $d0) 0 0 0
5617
5618 # save index
5619 0 $low = $high = $i;
5620
5621 # update difference
5622 0 $d0 = $d1;
5623
5624 }
5625
5626 # if duplicate sample
5627 0 ▶ if ($d0 == $d1 && $d2 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d0 == $d1 and $d2 == 0) 0 0 0
Condition0%0/3
$d0 == $d1 and $d2 == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$d0 == $d1 and $d2 == 0
$d0 == $d1 $d2 == 0
Truth table0%0/3
A and B
A= $d0 == $d1B= $d2 == 0
ABresult
0X0
100
111
5628
5629 # save index
5630 0 $high = $i;
5631
5632 }
5633
5634 }
5635
5636 # return
5637 0 return($low, $high);
5638
5639 }
5640  
5641 # add average sample
5642 # assumes device values (if any) are same for each sample
5643 # averages measurements values - spectral, XYZ, L*a*b*, or density
5644 # L*a*b* values are converted to xyz for averaging, then back to L*a*b*
5645 # density values are converted to reflectance for averaging, then back to density
5646 # parameters: (object_reference, row_slice, linear_slice, L*a*b*_slice, density_slice, id_slice, name_slice, hash)
5647 # returns: (average_sample_index)
5648 sub _add_avg {
5649  
5650 # get parameters
5651 0 ▶ my ($self, $rows, $c1, $c2, $c3, $id, $name, $hash) = @_;
Subroutine _add_avg: not called CC=14 SCAR=53.5
5652  
5653 # local variables
5654 0 my ($n, $next, @xyz, $sid, $sn);
5655  
5656 # get number of samples
5657 0 $n = @{$rows};
5658  
5659 # get index of next data row
5660 0 $next = $#{$self->[1]} + 1;
5661  
5662 # copy first sample
5663 0 $self->[1][$next] = [@{$self->[1][shift(@{$rows})]}];
5664  
5665 # for each group of L*a*b* columns
5666 0 ▶ for (my $j = 0; $j < @{$c2}; $j += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$c2;}) 0 0 0
5667
5668 # convert to L*a*b* values to xyz
5669 0 @{$self->[1][$next]}[@{$c2}[$j .. $j + 2]] = ICC::Shared::_Lab2xyz(@{$self->[1][$next]}[@{$c2}[$j .. $j + 2]]);
5670
5671 }
5672
5673 # for each density column
5674 0 for my $j (@{$c3}) {
5675
5676 # convert to density to reflectance
5677 0 $self->[1][$next][$j] = POSIX::pow(10, -$self->[1][$next][$j]);
5678
5679 }
5680  
5681 # for remaining samples
5682 0 for my $i (@{$rows}) {
5683
5684 # for each linear column
5685 0 for my $j (@{$c1}) {
5686
5687 # add value
5688 0 $self->[1][$next][$j] += $self->[1][$i][$j];
5689
5690 }
5691
5692 # for each group of L*a*b* columns
5693 0 ▶ for (my $j = 0; $j < @{$c2}; $j += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$c2;}) 0 0 0
5694
5695 # get xyz values
5696 0 @xyz = ICC::Shared::_Lab2xyz(@{$self->[1][$i]}[@{$c2}[$j .. $j + 2]]);
5697
5698 # add to self
5699 0 $self->[1][$next][$c2->[$j]] += $xyz[0];
5700 0 $self->[1][$next][$c2->[$j + 1]] += $xyz[1];
5701 0 $self->[1][$next][$c2->[$j + 2]] += $xyz[2];
5702
5703 }
5704
5705 # for each density column
5706 0 for my $j (@{$c3}) {
5707
5708 # add temp reflectance
5709 0 $self->[1][$next][$j] += POSIX::pow(10, -$self->[1][$i][$j]);
5710
5711 }
5712
5713 }
5714  
5715 # for each measurement column
5716 0 for my $j (@{$c1}, @{$c2}, @{$c3}) {
5717
5718 # divide by number of samples
5719 0 $self->[1][$next][$j] /= $n;
5720
5721 }
5722  
5723 # for each group of L*a*b* columns
5724 0 ▶ for (my $j = 0; $j < @{$c2}; $j += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$c2;}) 0 0 0
5725
5726 # convert to xyz values to L*a*b*
5727 0 @{$self->[1][$next]}[@{$c2}[$j .. $j + 2]] = ICC::Shared::_xyz2Lab(@{$self->[1][$next]}[@{$c2}[$j .. $j + 2]]);
5728
5729 }
5730  
5731 # for each density column
5732 0 for my $j (@{$c3}) {
5733
5734 # convert to reflectance to density
5735 0 $self->[1][$next][$j] = -POSIX::log10($self->[1][$next][$j]);
5736
5737 }
5738  
5739 # get SAMPLE_ID value from hash
5740 0 $sid = $hash->{'id'};
5741  
5742 # for each SAMPLE_ID column
5743 0 for my $i (@{$id}) {
5744
5745 # if SAMPLE_ID defined
5746 0 ▶ if (defined($sid)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sid) { } 0 0 0
5747
5748 # set to hash value
5749 0 $self->[1][$next][$i] = $sid;
5750
5751 } else {
5752
5753 # set to row index
5754 0 $self->[1][$next][$i] = $next;
5755
5756 }
5757
5758 }
5759  
5760 # get SAMPLE_NAME value from hash
5761 0 $sn = $hash->{'name'};
5762  
5763 # for each SAMPLE_NAME column
5764 0 for my $i (@{$name}) {
5765
5766 # if SAMPLE_NAME defined
5767 0 ▶ if (defined($sn)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sn) { } 0 0 0
5768
5769 # set to hash value
5770 0 $self->[1][$next][$i] = $sn;
5771
5772 } else {
5773
5774 # append '_AVG' to existing value
5775 0 $self->[1][$next][$i] .= '_AVG';
5776
5777 }
5778
5779 }
5780  
5781 # return row
5782 0 return($next);
5783  
5784 }
5785  
5786 # get averaging groups
5787 # returns column slices for each averaging method
5788 # parameters: (object_reference, hash)
5789 # returns: (linear_slice, L*a*b*_slice, density_slice)
5790 sub _avg_groups {
5791  
5792 # get parameters
5793 1 ▶ my ($self, $hash) = @_;
Subroutine _avg_groups: called CC=12 SCAR=29.0
5794  
5795 # local variables
5796 1 my (@c1, @c2, @c3, @cs);
5797  
5798 # for each format field
5799 1 for my $i (0 .. $#{$self->[1][0]}) {
5800
5801 # add column if XYZ or spectral field
5802 12 ▶ push(@c1, $i) if ($self->[1][0][$i] =~ m/^(?:.*\|)?(?:XYZ_[XYZ]|(?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)\d{3})$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /^(?:.*\|)?(?:XYZ_[XYZ]|(?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)\d{3})$/ 3 9 12
5803
5804 # add column if L*a*b* field
5805 12 ▶ push(@c2, $i) if ($self->[1][0][$i] =~ m/^(?:.*\|)?LAB_[LAB]$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /^(?:.*\|)?LAB_[LAB]$/ 3 9 12
5806
5807 # add column if density field
5808 12 ▶ push(@c3, $i) if ($self->[1][0][$i] =~ m/^(?:.*\|)?D_(?:RED|GREEN|BLUE|VIS)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->[1][0][$i] =~ /^(?:.*\|)?D_(?:RED|GREEN|BLUE|VIS)$/ 0 12 12
5809
5810 }
5811
5812 # linear averaging method (L*a*b* values are converted to xyz, density values are converted to reflectance)
5813 1 ▶ if (! defined($hash->{'method'}) || $hash->{'method'} eq 'LINEAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $hash->{'method'} or $hash->{'method'} eq 'LINEAR') { } 1 0 1
elsif (defined $hash->{'method'} and $hash->{'method'} eq 'SIMPLE') { } 0 0 0
Condition33%1/3
not defined $hash->{"method"} or $hash->{"method"} eq "LINEAR"
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $hash->{"method"} or $hash->{"method"} eq "LINEAR"
not defined $hash->{"method"} $hash->{"method"} eq "LINEAR"
Truth table33%1/3
not(A) or B
A= not defined $hash->{"method"}B= $hash->{"method"} eq "LINEAR"
ABresult
1X1
011
000
5814
5815 # verify number of L*a*b* fields
5816 1 ▶ (@c2 % 3 == 0) || croak('wrong number of L*a*b* fields');
Branch: 1 branch
BranchTrueFalseTotal
@c2 % 3 == 0 or croak("wrong number of L*a*b* fields") 0 1 1
5817
5818 # for each group of L*a*b* columns
5819 1 ▶ for (my $j = 0; $j < @c2; $j += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @c2) 1 1 2
5820
5821 # sort by field name
5822 1 @cs = sort {$self->[1][0][$a] cmp $self->[1][0][$b]} @c2[$j .. $j + 2];
5823
5824 # verify field consistency
5825 1 ▶ (join('', map {substr($_, -1, 1)} @{$self->[1][0]}[@cs]) eq 'ABL') || croak('L*a*b* field inconsistency');
Branch: 1 branch
BranchTrueFalseTotal
join("", map({substr $_, -1, 1;} @{$$self[1][0];}[@cs])) eq "ABL" or croak("L*a*b* field inconsistency") 0 1 1
5826
5827 # save columns in LAB order
5828 1 @c2[$j .. $j + 2] = @cs[2, 0, 1];
5829
5830 }
5831
5832 # if simple averaging method
5833 ▶ } elsif (defined($hash->{'method'}) && $hash->{'method'} eq 'SIMPLE') {
Condition0%0/3
defined $hash->{"method"} and $hash->{"method"} eq "SIMPLE"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash->{"method"} and $hash->{"method"} eq "SIMPLE"
defined $hash->{"method"} $hash->{"method"} eq "SIMPLE"
Truth table0%0/3
A and B
A= defined $hash->{"method"}B= $hash->{"method"} eq "SIMPLE"
ABresult
0X0
100
111
5834
5835 # copy L*a*b* and density columns to XYZ or spectral array
5836 0 push(@c1, @c2, @c3);
5837
5838 # clear L*a*b* and density arrays
5839 0 @c2 = ();
5840 0 @c3 = ();
5841
5842 } else {
5843
5844 # error
5845 0 croak('unsupported averaging method');
5846
5847 }
5848  
5849 # return slices
5850 1 return(\@c1, \@c2, \@c3);
5851  
5852 }
5853  
5854 # add OBA effect to XYZ array
5855 # parameters: (chart_object, M1_slice, M2_slice, XYZ_array, oba_factor, hash)
5856 sub _add_oba {
5857  
5858 # get parameters
5859 0 ▶ my ($self, $spec1, $spec2, $xyz, $oba, $hash) = @_;
Subroutine _add_oba: not called CC=6 SCAR=37.4
5860  
5861 # local variables
5862 0 my ($color, $illum, @m1, @m2, $spectral, $xyzoba);
5863  
5864 # save illuminant
5865 0 $illum = $hash->{'illuminant'};
5866  
5867 # if illuminant an array reference
5868 0 ▶ if (defined($hash->{'illuminant'}) && ref($hash->{'illuminant'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'illuminant'} and ref $hash->{'illuminant'} eq 'ARRAY') { } 0 0 0
Condition0%0/3
defined $hash->{"illuminant"} and ref $hash->{"illuminant"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash->{"illuminant"} and ref $hash->{"illuminant"} eq "ARRAY"
defined $hash->{"illuminant"} ref $hash->{"illuminant"} eq "ARRAY"
Truth table0%0/3
A and B
A= defined $hash->{"illuminant"}B= ref $hash->{"illuminant"} eq "ARRAY"
ABresult
0X0
100
111
5869
5870 # set illuminant to CIE D50
5871 0 $hash->{'illuminant'} = ['CIE', 'D50'];
5872
5873 } else {
5874
5875 # set illuminant to ASTM D50
5876 0 $hash->{'illuminant'} = 'D50';
5877
5878 }
5879  
5880 # make 'Color.pm' object (D50 illuminant)
5881 0 $color = ICC::Support::Color->new($hash);
5882  
5883 # restore illuminant
5884 0 $hash->{'illuminant'} = $illum;
5885  
5886 # for each sample
5887 0 for my $i (1 .. $#{$self->[1]}) {
5888
5889 # get M1 spectral values
5890 0 @m1 = @{$self->[1][$i]}[@{$spec1}];
5891
5892 # get M2 spectral values
5893 0 @m2 = @{$self->[1][$i]}[@{$spec2}];
5894
5895 # compute (M1 - M2) spectral values
5896 0 $spectral->[$i - 1] = [map {$m1[$_] - $m2[$_]} (0 .. $#m1)];
5897
5898 }
5899  
5900 # transform (M1 - M2) spectral to D50 XYZ (hash may contain 'encoding' key)
5901 0 $xyzoba = ICC::Support::Color::_trans2($color, $spectral, $hash);
5902  
5903 # for each sample
5904 0 for my $i (0 .. $#{$xyz}) {
5905
5906 # for each XYZ
5907 0 for my $j (0 .. 2) {
5908
5909 # add scaled OBA effect
5910 0 $xyz->[$i][$j] += $xyzoba->[$i][$j] * $oba;
5911
5912 }
5913
5914 }
5915
5916 }
5917  
5918 # get/set data
5919 # common routine called by get/set methods
5920 # row_slice and column_slice may be either a scalar or array reference
5921 # an empty array reference indicates all samples or fields
5922 # replacement_data is reference to a 2-D array of replacement values
5923 # array dimensions must match size of row_slice and column_slice
5924 # data_slice is Math::Matrix object, defined by row_slice and column_slice
5925 # get_code_ref and set_code_ref transform the data when getting and setting
5926 # parameters: (object_ref, object_index, row_slice, column_slice, replacement_data, get_code_ref, set_code_ref)
5927 # if column_slice undefined, returns: ()
5928 # if row_slice undefined, returns: (column_slice)
5929 # if replacement_data undefined, returns: (data_slice)
5930 # otherwise, sets replacement data and returns: (column_slice)
5931 sub _getset {
5932  
5933 # get parameters
5934 397 ▶ my ($self, $ix, $rows, $cols, $data, $get, $set) = @_;
Subroutine _getset: called CC=25 SCAR=33.8
5935  
5936 # return empty if no column slice
5937 397 ▶ defined($cols) || return();
Branch: 1 branch
BranchTrueFalseTotal
defined $cols or return () 180 217 397
5938  
5939 # if column slice an empty array reference
5940 217 ▶ if (ref($cols) eq 'ARRAY' && @{$cols} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cols eq 'ARRAY' and @{$cols;} == 0) { } 2 215 217
Condition100%3/3
ref $cols eq "ARRAY" and @{$cols;} == 0
!ll&&!rl&&r
102052
MC/DC100%2/2
ref $cols eq "ARRAY" and @{$cols;} == 0
ref $cols eq "ARRAY" @{$cols;} == 0
Truth table100%3/3
A and B
A= ref $cols eq "ARRAY"B= @{$cols;} == 0
ABresult
0X0
100
111
5941
5942 # use all columns
5943 2 $cols = [0 .. $#{$self->[$ix][0]}];
5944
5945 } else {
5946
5947 # flatten column slice
5948 215 $cols = ICC::Shared::flatten($cols);
5949
5950 # verify column slice contents
5951 215 ▶ (@{$cols} == grep {! ref() && $_ == int($_) && $_ >= 0} @{$cols}) || croak('invalid column slice');
Branch: 2 branches
BranchTrueFalseTotal
@{$cols;} == grep({not ref $_ and $_ == int $_ and $_ >= 0;} @{$cols;}) or croak("invalid column slice") 0 215 215
not ref $_ and $_ == int $_ and $_ >= 0 2017 0 2017
Condition33%1/3
not ref $_ and $_ == int $_
!ll&&!rl&&r
002017
MC/DC0%0/2
not ref $_ and $_ == int $_
not ref $_ $_ == int $_
Truth table33%1/3
not(A) and B
A= not ref $_B= $_ == int $_
ABresult
0X0
100
111
5952
5953 }
5954  
5955 # return columns slice if no row slice
5956 217 ▶ defined($rows) || return($cols);
Branch: 1 branch
BranchTrueFalseTotal
defined $rows or return $cols 121 96 217
5957  
5958 # if row slice an empty array reference
5959 96 ▶ if (ref($rows) eq 'ARRAY' && @{$rows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rows eq 'ARRAY' and @{$rows;} == 0) { } 35 61 96
Condition66%2/3
ref $rows eq "ARRAY" and @{$rows;} == 0
!ll&&!rl&&r
06135
MC/DC50%1/2
ref $rows eq "ARRAY" and @{$rows;} == 0
ref $rows eq "ARRAY" @{$rows;} == 0
Truth table66%2/3
A and B
A= ref $rows eq "ARRAY"B= @{$rows;} == 0
ABresult
0X0
100
111
5960
5961 # use all rows
5962 35 $rows = [1 .. $#{$self->[$ix]}];
5963
5964 } else {
5965
5966 # flatten row slice
5967 61 $rows = ICC::Shared::flatten($rows);
5968
5969 # verify row slice contents
5970 61 ▶ (@{$rows} == grep {! ref() && $_ == int($_) && $_ >= 0} @{$rows}) || croak('invalid row slice');
Branch: 2 branches
BranchTrueFalseTotal
@{$rows;} == grep({not ref $_ and $_ == int $_ and $_ >= 0;} @{$rows;}) or croak("invalid row slice") 0 61 61
not ref $_ and $_ == int $_ and $_ >= 0 201 0 201
Condition33%1/3
not ref $_ and $_ == int $_
!ll&&!rl&&r
00201
MC/DC0%0/2
not ref $_ and $_ == int $_
not ref $_ $_ == int $_
Truth table33%1/3
not(A) and B
A= not ref $_B= $_ == int $_
ABresult
0X0
100
111
5971
5972 }
5973  
5974 # no replacement data (get)
5975 96 ▶ if (! defined($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $data) { } 71 25 96
5976
5977 # verify 'get' code ref, or use identity function
5978 71 ▶ $get = (defined($get) && ref($get) eq 'CODE') ? $get : sub {@_};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
defined $get && ref $get eq 'CODE' ? : 21 50 71
Condition66%2/3
defined $get and ref $get eq "CODE"
!ll&&!rl&&r
50021
MC/DC50%1/2
defined $get and ref $get eq "CODE"
defined $get ref $get eq "CODE"
Truth table66%2/3
A and B
A= defined $getB= ref $get eq "CODE"
ABresult
0X0
100
111
5979
5980 # for each row
5981 71 for my $i (0 .. $#{$rows}) {
5982
5983 # get transformed data row
5984 476 @{$data->[$i]} = &$get(@{$self->[$ix][$rows->[$i]]}[@{$cols}]);
5985
5986 }
5987
5988 # return data slice as a Math::Matrix object
5989 71 return(bless($data, 'Math::Matrix'));
5990
5991 # with replacement data (set)
5992 } else {
5993
5994 # verify replacement data is 2-D array or Math::Matrix object
5995 25 ▶ ((ref($data) eq 'ARRAY' || UNIVERSAL::isa($data, 'Math::Matrix')) && ref($data->[0]) eq 'ARRAY') || croak('replacement data not a 2-D array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $data eq "ARRAY" || UNIVERSAL::isa($data, "Math::Matrix") and ref $data->[0] eq "ARRAY" or croak("replacement data not a 2-D array reference") 0 25 25
Condition33%2/6
ref $data eq "ARRAY" || UNIVERSAL::isa($data, "Math::Matrix") and ref $data->[0] eq "ARRAY"
!ll&&!rl&&r
0025
ref $data eq "ARRAY" or UNIVERSAL::isa($data, "Math::Matrix")
l!l&&r!l&&!r
2500
MC/DC0%0/3
ref $data eq "ARRAY" || UNIVERSAL::isa($data, "Math::Matrix") and ref $data->[0] eq "ARRAY"
ref $data eq "ARRAY" UNIVERSAL::isa($data, "Math::Matrix") ref $data->[0] eq "ARRAY"
Truth table20%1/5
A or B and C
A= ref $data eq "ARRAY"B= UNIVERSAL::isa($data, "Math::Matrix")C= ref $data->[0] eq "ARRAY"
ABCresult
00X0
1X00
0100
1X11
0111
5996
5997 # verify replacement data size
5998 25 ▶ ($#{$data} == $#{$rows} && $#{$data->[0]} == $#{$cols}) || croak('replacement data is wrong sized');
Branch: 1 branch
BranchTrueFalseTotal
$#{$data;} == $#{$rows;} and $#{$$data[0];} == $#{$cols;} or croak("replacement data is wrong sized") 0 25 25
Condition33%1/3
$#{$data;} == $#{$rows;} and $#{$$data[0];} == $#{$cols;}
!ll&&!rl&&r
0025
MC/DC0%0/2
$#{$data;} == $#{$rows;} and $#{$$data[0];} == $#{$cols;}
$#{$data;} == $#{$rows;} $#{$$data[0];} == $#{$cols;}
Truth table33%1/3
A and B
A= $#{$data;} == $#{$rows;}B= $#{$$data[0];} == $#{$cols;}
ABresult
0X0
100
111
5999
6000 # verify 'set' code ref, or use identity function
6001 25 ▶ $set = (defined($set) && ref($set) eq 'CODE') ? $set : sub {@_};
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
defined $set && ref $set eq 'CODE' ? : 9 16 25
Condition66%2/3
defined $set and ref $set eq "CODE"
!ll&&!rl&&r
1609
MC/DC50%1/2
defined $set and ref $set eq "CODE"
defined $set ref $set eq "CODE"
Truth table66%2/3
A and B
A= defined $setB= ref $set eq "CODE"
ABresult
0X0
100
111
6002
6003 # for each row
6004 25 for my $i (0 .. $#{$rows}) {
6005
6006 # set transformed data row
6007 75 @{$self->[$ix][$rows->[$i]]}[@{$cols}] = &$set(@{$data->[$i]});
6008
6009 }
6010
6011 # return column slice
6012 25 return($cols);
6013
6014 }
6015
6016 }
6017  
6018 # get accumulated sample values
6019 # sample dimensions are in pixels
6020 # used by _readChartTIFF to extract samples from a data stripe
6021 # parameters: (reference_to_data, sample_offset, sample_width, number_channels)
6022 # returns: (accumulated_sample_values)
6023 sub _getSample {
6024
6025 # get parameters
6026 0 ▶ my ($data, $so, $sx, $c) = @_;
Subroutine _getSample: not called CC=4 SCAR=30.0
6027
6028 # initialize sample values
6029 0 my @sv = (0) x $c;
6030
6031 # for each row
6032 0 for my $i (0 .. $#{$data}) {
6033
6034 # for each pixel
6035 0 for my $j (0 .. $sx - 1) {
6036
6037 # for each channel
6038 0 for my $k (0 .. $c - 1) {
6039
6040 # accumulate sample value
6041 0 $sv[$k] += $data->[$i][($so + $j) * $c + $k];
6042
6043 }
6044
6045 }
6046
6047 }
6048
6049 # return sample values
6050 0 return(@sv);
6051
6052 }
6053  
6054 # get row length
6055 # parameters: (object_reference, hash)
6056 # returns: (row_length)
6057 sub _getRowLength {
6058  
6059 # get parameters
6060 0 ▶ my ($self, $hash) = @_;
Subroutine _getRowLength: not called CC=22 SCAR=62.3
6061  
6062 # local variables
6063 0 my ($rows, $n, $square);
6064  
6065 # if 'rows' hash key is defined
6066 0 ▶ if (defined($hash->{'rows'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"rows"}) 0 0 0
6067
6068 # get row length value
6069 0 $rows = $hash->{'rows'};
6070
6071 # if valid row length
6072 0 ▶ if (Scalar::Util::looks_like_number($rows) && $rows > 0 && $rows == int($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows) { } 0 0 0
Condition0%0/6
&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($rows) and $rows > 0
!ll&&!rl&&r
000
MC/DC0%0/3
&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows
&Scalar::Util::looks_like_number($rows) $rows > 0 $rows == int $rows
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($rows)B= $rows > 0C= $rows == int $rows
ABCresult
0XX0
10X0
1100
1111
6073
6074 # return
6075 0 return($rows);
6076
6077 } else {
6078
6079 # warn
6080 0 warn('invalid \'rows\' parameter');
6081
6082 }
6083
6084 }
6085
6086 # if LGOROWLENGTH keyword
6087 0 ▶ if ($rows = keyword($self, 'LGOROWLENGTH')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rows = keyword($self, "LGOROWLENGTH")) 0 0 0
6088
6089 # if valid row length
6090 0 ▶ if (Scalar::Util::looks_like_number($rows) && $rows > 0 && $rows == int($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows) { } 0 0 0
Condition0%0/6
&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($rows) and $rows > 0
!ll&&!rl&&r
000
MC/DC0%0/3
&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows
&Scalar::Util::looks_like_number($rows) $rows > 0 $rows == int $rows
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($rows)B= $rows > 0C= $rows == int $rows
ABCresult
0XX0
10X0
1100
1111
6091
6092 # return
6093 0 return($rows);
6094
6095 } else {
6096
6097 # warn
6098 0 warn('invalid \'LGOROWLENGTH\' value');
6099
6100 }
6101
6102 }
6103
6104 # if NUMBER_OF_STRIPS keyword
6105 0 ▶ if ($rows = keyword($self, 'NUMBER_OF_STRIPS')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rows = keyword($self, "NUMBER_OF_STRIPS")) 0 0 0
6106
6107 # if valid row length
6108 0 ▶ if (Scalar::Util::looks_like_number($rows) && $rows > 0 && $rows == int($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows) { } 0 0 0
Condition0%0/6
&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($rows) and $rows > 0
!ll&&!rl&&r
000
MC/DC0%0/3
&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows
&Scalar::Util::looks_like_number($rows) $rows > 0 $rows == int $rows
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($rows)B= $rows > 0C= $rows == int $rows
ABCresult
0XX0
10X0
1100
1111
6109
6110 # return
6111 0 return($rows);
6112
6113 } else {
6114
6115 # warn
6116 0 warn('invalid \'NUMBER_OF_STRIPS\' value');
6117
6118 }
6119
6120 }
6121
6122 # if 'NumberPatchRows' key is defined
6123 0 ▶ if (defined($self->[0]{'xrp:CustomAttributes'}{'NumberPatchRows'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{"xrp:CustomAttributes"}{"NumberPatchRows"}) 0 0 0
6124
6125 # get row length value
6126 0 $rows = $self->[0]{'xrp:CustomAttributes'}{'NumberPatchRows'};
6127
6128 # if valid row length
6129 0 ▶ if (Scalar::Util::looks_like_number($rows) && $rows > 0 && $rows == int($rows)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows) { } 0 0 0
Condition0%0/6
&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($rows) and $rows > 0
!ll&&!rl&&r
000
MC/DC0%0/3
&Scalar::Util::looks_like_number($rows) and $rows > 0 and $rows == int $rows
&Scalar::Util::looks_like_number($rows) $rows > 0 $rows == int $rows
Truth table0%0/4
A and B and C
A= &Scalar::Util::looks_like_number($rows)B= $rows > 0C= $rows == int $rows
ABCresult
0XX0
10X0
1100
1111
6130
6131 # return
6132 0 return($rows);
6133
6134 } else {
6135
6136 # warn
6137 0 warn('invalid \'NumberPatchRows\' attribute');
6138
6139 }
6140
6141 }
6142  
6143 # get number of samples
6144 0 $n = $#{$self->[1]};
6145  
6146 # return if 0
6147 0 ▶ return(0) if ($n == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 0 0 0
6148  
6149 # return if 1 or 2
6150 0 ▶ return(1) if ($n < 3);
Branch: 1 branch
BranchTrueFalseTotal
if $n < 3 0 0 0
6151  
6152 # compute size of square chart
6153 0 $square = POSIX::ceil(sqrt($n));
6154  
6155 # return if chart is square
6156 0 ▶ return($square) if ($n == $square**2);
Branch: 1 branch
BranchTrueFalseTotal
if $n == $square ** 2 0 0 0
6157  
6158 # set row length one less than square chart
6159 0 $rows = $square - 1;
6160  
6161 # while modulus is non-zero, decrement row length
6162 0 ▶ while ($n % $rows) {$rows--}
Branch: 1 branch
BranchTrueFalseTotal
if ($n % $rows) 0 0 0
6163  
6164 # return row length, choosing full rectangle if possible
6165 0 ▶ return($rows > $square/2 ? $rows : $square);
Branch: 1 branch
BranchTrueFalseTotal
$rows > $square / 2 ? : 0 0 0
6166  
6167 }
6168  
6169 # get illuminant white point
6170 # returns XYZ vector from colorimetry array
6171 # returns D50 if CAT or undefined
6172 # parameter: (object_reference, column_slice, [hash])
6173 # returns: (XYZ_vector)
6174 sub _illumWP {
6175  
6176 # get parameters
6177 0 ▶ my ($self, $cols, $hash) = @_;
Subroutine _illumWP: not called CC=4 SCAR=30.0
6178  
6179 # if XYZ values are valid
6180 0 ▶ if (3 == grep {defined() && ! ref() && $_ > 0} @{$self->[2][2]}[@{$cols}]) {
Branch: 2 branches
BranchTrueFalseTotal
if (3 == grep({defined $_ and not ref $_ and $_ > 0;} @{$$self[2][2];}[@{$cols;}])) { } 0 0 0
defined $_ and not ref $_ and $_ > 0 0 0 0
Condition0%0/3
defined $_ and not ref $_
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_ and not ref $_
defined $_ not ref $_
Truth table0%0/3
A and not(B)
A= defined $_B= not ref $_
ABresult
0X0
100
111
6181
6182 # return XYZ vector
6183 0 return([@{$self->[2][2]}[@{$cols}]]);
6184
6185 } else {
6186
6187 # return D50 vector
6188 0 return(ICC::Shared::D50);
6189
6190 }
6191  
6192 }
6193  
6194 # compute media white point
6195 # multiple samples are averaged
6196 # result also stored in colorimetry array
6197 # parameter: (object_reference, column_slice, [hash])
6198 # returns: (XYZ_vector)
6199 sub _mediaWP {
6200  
6201 # get parameters
6202 0 ▶ my ($self, $cols, $hash) = @_;
Subroutine _mediaWP: not called CC=10 SCAR=47.0
6203  
6204 # local variables
6205 0 my ($WPxyz, $dev, $mwv, $n, @XYZ, @XYZs);
6206  
6207 # if column slice is L*a*b*
6208 0 ▶ if ((3 == grep {$self->[1][0][$_] =~ m/LAB_[LAB]$/} @{$cols})) {
Branch: 2 branches
BranchTrueFalseTotal
if (3 == grep({$self->[1][0][$_] =~ /LAB_[LAB]$/;} @{$cols;})) { } 0 0 0
elsif (3 != grep({$self->[1][0][$_] =~ /XYZ_[XYZ]$/;} @{$cols;})) { } 0 0 0
6209
6210 # get illuminant white point
6211 0 ▶ $WPxyz = defined($self->[2][2][$cols->[0]]) ? [@{$self->[2][2]}[@{$cols}]] : ICC::Shared::D50;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[2][2][$cols->[0]] ? : 0 0 0
6212
6213 # if column slice is not XYZ
6214 0 } elsif ((3 != grep {$self->[1][0][$_] =~ m/XYZ_[XYZ]$/} @{$cols})) {
6215
6216 # warning
6217 0 warn('column slice not XYZ or L*a*b* data');
6218
6219 # return empty
6220 0 return();
6221
6222 }
6223  
6224 # if no device data (using 'device' context)
6225 0 ▶ if (! ($dev = device($self, {'context' => $hash->{'device'}}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dev = device($self, {"context", $hash->{"device"}})) 0 0 0
6226
6227 # warning
6228 0 warn('no device data');
6229
6230 # return empty
6231 0 return();
6232
6233 }
6234  
6235 # set media white device value (255 if RGB, 0 otherwise)
6236 0 ▶ $mwv = ($self->[1][0][$dev->[0]] =~ m/RGB_R$/) ? 255 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$dev->[0]] =~ /RGB_R$/ ? : 0 0 0
6237  
6238 # for each sample
6239 0 for my $i (1 .. $#{$self->[1]}) {
6240
6241 # if all device channels are white
6242 0 ▶ if (@{$dev} == grep {$_ == $mwv} @{$self->[1][$i]}[@{$dev}]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$dev;} == grep({$_ == $mwv;} @{$$self[1][$i];}[@{$dev;}])) 0 0 0
6243
6244 # if L*a*b* data
6245 0 ▶ if ($WPxyz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WPxyz) { } 0 0 0
6246
6247 # convert L*a*b* values to XYZ
6248 0 @XYZs = ICC::Shared::_Lab2XYZ(@{$self->[1][$i]}[@{$cols}], $WPxyz);
6249
6250 # accumulate XYZ values
6251 0 $XYZ[0] += $XYZs[0];
6252 0 $XYZ[1] += $XYZs[1];
6253 0 $XYZ[2] += $XYZs[2];
6254
6255 # if XYZ data
6256 } else {
6257
6258 # accumulate XYZ values
6259 0 $XYZ[0] += $self->[1][$i][$cols->[0]];
6260 0 $XYZ[1] += $self->[1][$i][$cols->[1]];
6261 0 $XYZ[2] += $self->[1][$i][$cols->[2]];
6262
6263 }
6264
6265 # increment count
6266 0 $n++;
6267
6268 }
6269
6270 }
6271  
6272 # if media white sample(s)
6273 0 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) { } 0 0 0
6274
6275 # store average XYZ values in colorimetry array, and return XYZ vector
6276 0 return([@{$self->[2][3]}[@{$cols}] = map {$_/$n} @XYZ]);
6277
6278 } else {
6279
6280 # warning
6281 0 warn('no media white sample found');
6282
6283 # return empty
6284 0 return();
6285
6286 }
6287
6288 }
6289  
6290 # compute media black point
6291 # multiple samples are averaged
6292 # result also stored in colorimetry array
6293 # parameter: (object_reference, column_slice, [hash])
6294 # returns: (XYZ_vector)
6295 sub _mediaBP {
6296  
6297 # get parameters
6298 0 ▶ my ($self, $cols, $hash) = @_;
Subroutine _mediaBP: not called CC=10 SCAR=47.0
6299  
6300 # local variables
6301 0 my ($WPxyz, $dev, $mbv, $n, @XYZ, @XYZs);
6302  
6303 # if column slice is L*a*b*
6304 0 ▶ if ((3 == grep {$self->[1][0][$_] =~ m/LAB_[LAB]$/} @{$cols})) {
Branch: 2 branches
BranchTrueFalseTotal
if (3 == grep({$self->[1][0][$_] =~ /LAB_[LAB]$/;} @{$cols;})) { } 0 0 0
elsif (3 != grep({$self->[1][0][$_] =~ /XYZ_[XYZ]$/;} @{$cols;})) { } 0 0 0
6305
6306 # get illuminant white point
6307 0 ▶ $WPxyz = defined($self->[2][2][$cols->[0]]) ? [@{$self->[2][2]}[@{$cols}]] : ICC::Shared::D50;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[2][2][$cols->[0]] ? : 0 0 0
6308
6309 # if column slice is not XYZ
6310 0 } elsif ((3 != grep {$self->[1][0][$_] =~ m/XYZ_[XYZ]$/} @{$cols})) {
6311
6312 # warning
6313 0 warn('column slice not XYZ or L*a*b* data');
6314
6315 # return empty
6316 0 return();
6317
6318 }
6319  
6320 # if no device data (using 'device' context)
6321 0 ▶ if (! ($dev = device($self, {'context' => $hash->{'device'}}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dev = device($self, {"context", $hash->{"device"}})) 0 0 0
6322
6323 # warning
6324 0 warn('no device data');
6325
6326 # return empty
6327 0 return();
6328
6329 }
6330  
6331 # set media black device value (0 if RGB, 100 otherwise)
6332 0 ▶ $mbv = ($self->[1][0][$dev->[0]] =~ m/RGB_R$/) ? 1 : 100;
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0][$dev->[0]] =~ /RGB_R$/ ? : 0 0 0
6333  
6334 # for each sample
6335 0 for my $i (1 .. $#{$self->[1]}) {
6336
6337 # if all device channels are black
6338 0 ▶ if (@{$dev} == grep {$_ == $mbv} @{$self->[1][$i]}[@{$dev}]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$dev;} == grep({$_ == $mbv;} @{$$self[1][$i];}[@{$dev;}])) 0 0 0
6339
6340 # increment count
6341 0 $n++;
6342
6343 # if L*a*b* data
6344 0 ▶ if ($WPxyz) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WPxyz) { } 0 0 0
6345
6346 # convert L*a*b* values to XYZ
6347 0 @XYZs = ICC::Shared::_Lab2XYZ(@{$self->[1][$i]}[@{$cols}], $WPxyz);
6348
6349 # accumulate XYZ values
6350 0 $XYZ[0] += $XYZs[0];
6351 0 $XYZ[1] += $XYZs[1];
6352 0 $XYZ[2] += $XYZs[2];
6353
6354 # if XYZ data
6355 } else {
6356
6357 # accumulate XYZ values
6358 0 $XYZ[0] += $self->[1][$i][$cols->[0]];
6359 0 $XYZ[1] += $self->[1][$i][$cols->[1]];
6360 0 $XYZ[2] += $self->[1][$i][$cols->[2]];
6361
6362 }
6363
6364 }
6365
6366 }
6367  
6368 # if media black sample(s)
6369 0 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) { } 0 0 0
6370
6371 # store average XYZ values in colorimetry array, and return XYZ vector
6372 0 return([@{$self->[2][4]}[@{$cols}] = map {$_/$n} @XYZ]);
6373
6374 } else {
6375
6376 # warning
6377 0 warn('no media black sample found');
6378
6379 # return empty
6380 0 return();
6381
6382 }
6383
6384 }
6385  
6386 # make SAMPLE_ID hash
6387 # if no SAMPLE_ID field, hash is initialized
6388 # parameter: (object_reference)
6389 sub _makeSampleID {
6390  
6391 # get object reference
6392 23 ▶ my $self = shift();
Subroutine _makeSampleID: called CC=3 SCAR=11.0
6393  
6394 # if SAMPLE_ID column(s) exist
6395 23 ▶ if (my @id = grep {$self->[1][0][$_] =~ m/^(?:.*\|)?(?:SAMPLE_ID|SampleID)$/} (0 .. $#{$self->[1][0]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@id) = grep({$self->[1][0][$_] =~ /^(?:.*\|)?(?:SAMPLE_ID|SampleID)$/;} 0 .. $#{$$self[1][0];})) { } 15 8 23
6396
6397 # make the SAMPLE_ID hash, omitting undefined ID values
6398 15 ▶ $self->[4] = {map {defined($self->[1][$_][$id[0]]) ? ($self->[1][$_][$id[0]], $_) : ()} (1 .. $#{$self->[1]})};
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[1][$_][$id[0]] ? : 166 0 166
6399
6400 } else {
6401
6402 # initialize the hash
6403 8 $self->[4] = {};
6404
6405 }
6406  
6407 }
6408  
6409 # add colorimetry metadata
6410 # called when creating a new object
6411 # parameter: (object_reference)
6412 sub _addColorMeta {
6413  
6414 # get object reference
6415 22 ▶ my $self = shift();
Subroutine _addColorMeta: called CC=14 SCAR=29.5
6416  
6417 # local variables
6418 22 my (@cols, $hash, $illum, $spec, $nm, $str, $color, $WPxyz, @values);
6419  
6420 # if object contains colorimetric data
6421 22 ▶ if (@cols = grep {$self->[1][0][$_] =~ m/^(?:(.*)\|)?(?:LAB_[LAB]|XYZ_[XYZ]|STDEV_[LABXYZ]|MEAN_DE|STDEV_DE|CHI_SQD_PAR)$/} (0 .. $#{$self->[1][0]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cols = grep({$self->[1][0][$_] =~ /^(?:(.*)\|)?(?:LAB_[LAB]|XYZ_[XYZ]|STDEV_[LABXYZ]|MEAN_DE|STDEV_DE|CHI_SQD_PAR)$/;} 0 .. $#{$$self[1][0];})) 9 13 22
6422
6423 # set default hash values
6424 9 $hash = {'illuminant' => 'D50', 'observer' => '2'};
6425
6426 # if CxF3 'TristimulusSpec' node
6427 9 ▶ if (defined($self->[0]{'CxF3_dom'}) && 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->[0]{'CxF3_dom'} and 0) { } 0 9 9
elsif (@values = keyword($self, 'WEIGHTING_FUNCTION')) { } 7 2 9
Condition100%2/2
defined $self->[0]{"CxF3_dom"} and 0
!ll
72
MC/DC100%1/1
defined $self->[0]{"CxF3_dom"} and 0
defined $self->[0]{"CxF3_dom"}
Truth table100%2/2
A
A= defined $self->[0]{"CxF3_dom"}
Aresult
00
11
6428
6429 ##### to be implemented #####
6430
6431 # if 'WEIGHTING_FUNCTION' keyword(s)
6432 } elsif (@values = keyword($self, 'WEIGHTING_FUNCTION')) {
6433
6434 # join values into string
6435 7 $str = join(';', @values);
6436
6437 # match illuminant and save in hash
6438 7 ▶ $hash->{'illuminant'} = $1 if ($str =~ m/ILLUMINANT\s*,\s*(\w+)"/);
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /ILLUMINANT\s*,\s*(\w+)"/ 0 7 7
6439
6440 # match observer and save in hash
6441 7 ▶ $hash->{'observer'} = $1 if ($str =~ m/OBSERVER\s*,\s*(\d+).*"/);
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /OBSERVER\s*,\s*(\d+).*"/ 0 7 7
6442
6443 }
6444
6445 # if non-standard illuminant
6446 9 ▶ if ($hash->{'illuminant'} ne 'D50' || $hash->{'observer'} ne '2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hash->{'illuminant'} ne 'D50' or $hash->{'observer'} ne '2') { } 0 9 9
Condition33%1/3
$hash->{"illuminant"} ne "D50" or $hash->{"observer"} ne 2
l!l&&r!l&&!r
009
MC/DC0%0/2
$hash->{"illuminant"} ne "D50" or $hash->{"observer"} ne 2
$hash->{"illuminant"} ne "D50" $hash->{"observer"} ne 2
Truth table33%1/3
A or B
A= $hash->{"illuminant"} ne "D50"B= $hash->{"observer"} ne 2
ABresult
1X1
011
000
6447
6448 # make an empty 'Color.pm' object
6449 0 $color = ICC::Support::Color->new();
6450
6451 # if illuminant is an ARRAY reference
6452 0 ▶ if (ref($hash->{'illuminant'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{'illuminant'} eq 'ARRAY') { } 0 0 0
6453
6454 # initialize object for CIE method
6455 0 ICC::Support::Color::_cie($color, $hash);
6456
6457 } else {
6458
6459 # initialize object for ASTM method
6460 0 ICC::Support::Color::_astm($color, $hash);
6461
6462 }
6463
6464 # use computed white point
6465 0 $WPxyz = $color->iwtpt();
6466
6467 } else {
6468
6469 # use D50
6470 9 $WPxyz = ICC::Shared::D50;
6471
6472 }
6473
6474 # for each colorimetric field
6475 9 for my $i (@cols) {
6476
6477 # if field name ends in L or X
6478 48 ▶ if ($self->[1][0][$i] =~ m/[LX]$/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->[1][0][$i] =~ /[LX]$/) { } 16 32 48
elsif ($self->[1][0][$i] =~ /[AY]$/) { } 16 16 32
elsif ($self->[1][0][$i] =~ /[BZ]$/) { } 16 0 16
6479
6480 # save WP X-value
6481 16 $self->[2][2][$i] = $WPxyz->[0];
6482
6483 # if field name ends in A or Y
6484 } elsif ($self->[1][0][$i] =~ m/[AY]$/) {
6485
6486 # save WP Y-value
6487 16 $self->[2][2][$i] = $WPxyz->[1];
6488
6489 # if field name ends in B or Z
6490 } elsif ($self->[1][0][$i] =~ m/[BZ]$/) {
6491
6492 # save WP Z-value
6493 16 $self->[2][2][$i] = $WPxyz->[2];
6494
6495 }
6496
6497 }
6498
6499 }
6500
6501 }
6502  
6503 # read chart from list of data files
6504 # averages color measurement data (spectral, XYZ, L*a*b* or density)
6505 # files must have identical structure (rows and cols)
6506 # parameters: (object_reference, ref_to_file_list, hash)
6507 # returns: (number_of_files_averaged)
6508 sub _readChartAvg {
6509  
6510 # get parameters
6511 1 ▶ my ($self, $list, $hash) = @_;
Subroutine _readChartAvg: called CC=49 SCAR=56.4
6512  
6513 # local variables
6514 1 my ($n, $result, $c1, $c2, $c3, $keys, $temp, @xyz);
6515 1 my ($charts, $fstat, @ctx1, @ctx2, $add_hash);
6516  
6517 # initialize file count
6518 1 $n = 0;
6519  
6520 # if hash is defined
6521 1 ▶ if (defined($hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash) 1 0 1
6522
6523 # for each hash key
6524 1 for (keys(%{$hash})) {
6525
6526 # if XYZ based stat requested
6527 0 ▶ if (m/^STDEV_XYZ$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^STDEV_XYZ$/) { } 0 0 0
elsif (/^(MEAN_DE|STDEV_LAB|CHI_SQD_PAR)$/) { } 0 0 0
6528
6529 # if value is a scalar
6530 0 ▶ if (! ref($hash->{$_})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $hash->{$_}) { } 0 0 0
elsif (ref $hash->{$_} eq 'ARRAY') { } 0 0 0
6531
6532 # save XYZ context
6533 0 push(@ctx1, $hash->{$_});
6534
6535 } elsif (ref($hash->{$_}) eq 'ARRAY') {
6536
6537 # save XYZ contexts
6538 0 push(@ctx1, @{$hash->{$_}});
6539
6540 }
6541
6542 # increment flag
6543 0 $fstat++;
6544
6545 # if L*a*b* based stat requested
6546 } elsif (m/^(MEAN_DE|STDEV_LAB|CHI_SQD_PAR)$/) {
6547
6548 # if value is a scalar
6549 0 ▶ if (! ref($hash->{$_})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $hash->{$_}) { } 0 0 0
elsif (ref $hash->{$_} eq 'ARRAY') { } 0 0 0
6550
6551 # save L*a*b* context
6552 0 push(@ctx2, $hash->{$_});
6553
6554 } elsif (ref($hash->{$_}) eq 'ARRAY') {
6555
6556 # save L*a*b* contexts
6557 0 push(@ctx2, @{$hash->{$_}});
6558
6559 }
6560
6561 # increment flag
6562 0 $fstat++;
6563
6564 }
6565
6566 }
6567
6568 }
6569  
6570 # for each file
6571 1 for my $file (@{$list}) {
6572
6573 # if first file
6574 4 ▶ if ($n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0) { } 1 3 4
6575
6576 # if file read successfully
6577 1 ▶ if (! ($result = _readChart($self, $file, $hash))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result = _readChart($self, $file, $hash)) { } 1 0 1
6578
6579 # add colorimetric metadata
6580 1 _addColorMeta($self);
6581
6582 # make format key string
6583 1 ▶ $keys = join(':', map {defined() ? $_ : '-'} @{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 12 0 12
6584
6585 # for each XYZ context
6586 1 for my $ctx (@ctx1) {
6587
6588 # copy the hash
6589 0 $add_hash = Storable::dclone($hash);
6590
6591 # set the context (undef for no context)
6592 0 ▶ $add_hash->{'context'} = defined($ctx) && length($ctx) ? $ctx : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ctx && length $ctx ? : 0 0 0
Condition0%0/3
defined $ctx and length $ctx
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctx and length $ctx
defined $ctx length $ctx
Truth table0%0/3
A and B
A= defined $ctxB= length $ctx
ABresult
0X0
100
111
6593
6594 # delete the 'added' context
6595 0 delete($add_hash->{'added'});
6596
6597 # add the XYZ values
6598 0 add_xyz($self, $add_hash);
6599
6600 }
6601
6602 # for each L*a*b* context
6603 1 for my $ctx (@ctx2) {
6604
6605 # copy the hash
6606 0 $add_hash = Storable::dclone($hash);
6607
6608 # set the context (undef for no context)
6609 0 ▶ $add_hash->{'context'} = defined($ctx) && length($ctx) ? $ctx : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ctx && length $ctx ? : 0 0 0
Condition0%0/3
defined $ctx and length $ctx
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctx and length $ctx
defined $ctx length $ctx
Truth table0%0/3
A and B
A= defined $ctxB= length $ctx
ABresult
0X0
100
111
6610
6611 # delete the 'added' context
6612 0 delete($add_hash->{'added'});
6613
6614 # add the L*a*b* values
6615 0 add_lab($self, $add_hash);
6616
6617 }
6618
6619 # save copy of chart data, if needed for stats
6620 1 ▶ $charts->[0] = Storable::dclone($self->[1]) if ($fstat);
Branch: 1 branch
BranchTrueFalseTotal
if $fstat 0 1 1
6621
6622 # get averaging groups
6623 1 ($c1, $c2, $c3) = _avg_groups($self, $hash);
6624
6625 # if there are L*a*b* or density groups
6626 1 ▶ if (@{$c2} || @{$c3}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$c2;} or @{$c3;}) 1 0 1
Condition33%1/3
@{$c2;} or @{$c3;}
l!l&&r!l&&!r
100
MC/DC0%0/2
@{$c2;} or @{$c3;}
@{$c2;} @{$c3;}
Truth table33%1/3
A or B
A= @{$c2;}B= @{$c3;}
ABresult
1X1
011
000
6627
6628 # for each sample
6629 1 for my $i (1 .. $#{$self->[1]}) {
6630
6631 # for each group of L*a*b* columns
6632 10 ▶ for (my $j = 0; $j < @{$c2}; $j += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$c2;}) 10 10 20
6633
6634 # convert to L*a*b* values to xyz
6635 10 @{$self->[1][$i]}[@{$c2}[$j .. $j + 2]] = ICC::Shared::_Lab2xyz(@{$self->[1][$i]}[@{$c2}[$j .. $j + 2]]);
6636
6637 }
6638
6639 # for each density column
6640 10 for my $j (@{$c3}) {
6641
6642 # convert to density to reflectance
6643 0 $self->[1][$i][$j] = POSIX::pow(10, -$self->[1][$i][$j]);
6644
6645 }
6646
6647 }
6648
6649 }
6650
6651 # increment file count
6652 1 $n++;
6653
6654 } else {
6655
6656 # print warning
6657 0 warn("chart $file $result, ignored\n");
6658
6659 }
6660
6661 } else {
6662
6663 # make temporary Chart object
6664 3 $temp = ICC::Support::Chart->new();
6665
6666 # if file read successfully
6667 3 ▶ if (! ($result = _readChart($temp, $file, $hash))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result = _readChart($temp, $file, $hash)) { } 3 0 3
6668
6669 # if charts have same structure (rows and cols)
6670 3 ▶ if ($#{$self->[1]} == $#{$temp->[1]} && $keys eq join(':', map {defined() ? $_ : '-'} @{$temp->[1][0]})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($#{$$self[1];} == $#{$$temp[1];} and $keys eq join(':', map({defined $_ ? $_ : '-';} @{$$temp[1][0];}))) { } 3 0 3
defined $_ ? : 36 0 36
Condition33%1/3
$#{$$self[1];} == $#{$$temp[1];} and $keys eq join(":", map({defined $_ ? $_ : "-";} @{$$temp[1][0];}))
!ll&&!rl&&r
003
MC/DC0%0/2
$#{$$self[1];} == $#{$$temp[1];} and $keys eq join(":", map({defined $_ ? $_ : "-";} @{$$temp[1][0];}))
$#{$$self[1];} == $#{$$temp[1];} $keys eq join(":", map({defined $_ ? $_ : "-";} @{$$temp[1][0];}))
Truth table33%1/3
A and B
A= $#{$$self[1];} == $#{$$temp[1];}B= $keys eq join(":", map({defined $_ ? $_ : "-";} @{$$temp[1][0];}))
ABresult
0X0
100
111
6671
6672 # for each XYZ context
6673 3 for my $ctx (@ctx1) {
6674
6675 # copy the hash
6676 0 $add_hash = Storable::dclone($hash);
6677
6678 # set the context (undef for no context)
6679 0 ▶ $add_hash->{'context'} = defined($ctx) && length($ctx) ? $ctx : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ctx && length $ctx ? : 0 0 0
Condition0%0/3
defined $ctx and length $ctx
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctx and length $ctx
defined $ctx length $ctx
Truth table0%0/3
A and B
A= defined $ctxB= length $ctx
ABresult
0X0
100
111
6680
6681 # delete the 'added' context
6682 0 delete($add_hash->{'added'});
6683
6684 # add the XYZ values
6685 0 add_xyz($temp, $add_hash);
6686
6687 }
6688
6689 # for each L*a*b* context
6690 3 for my $ctx (@ctx2) {
6691
6692 # copy the hash
6693 0 $add_hash = Storable::dclone($hash);
6694
6695 # set the context (undef for no context)
6696 0 ▶ $add_hash->{'context'} = defined($ctx) && length($ctx) ? $ctx : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $ctx && length $ctx ? : 0 0 0
Condition0%0/3
defined $ctx and length $ctx
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ctx and length $ctx
defined $ctx length $ctx
Truth table0%0/3
A and B
A= defined $ctxB= length $ctx
ABresult
0X0
100
111
6697
6698 # delete the 'added' context
6699 0 delete($add_hash->{'added'});
6700
6701 # add the L*a*b* values
6702 0 add_lab($temp, $add_hash);
6703
6704 }
6705
6706 # save copy of chart data, if needed for stats
6707 3 ▶ $charts->[$n] = $temp->[1] if ($fstat);
Branch: 1 branch
BranchTrueFalseTotal
if $fstat 0 3 3
6708
6709 # for each sample
6710 3 for my $i (1 .. $#{$self->[1]}) {
6711
6712 # for each linear column
6713 30 for my $j (@{$c1}) {
6714
6715 # add temp value
6716 90 $self->[1][$i][$j] += $temp->[1][$i][$j];
6717
6718 }
6719
6720 # for each group of L*a*b* columns
6721 30 ▶ for (my $j = 0; $j < @{$c2}; $j += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$c2;}) 30 30 60
6722
6723 # get temp xyz values
6724 30 @xyz = ICC::Shared::_Lab2xyz(@{$temp->[1][$i]}[@{$c2}[$j .. $j + 2]]);
6725
6726 # add to self
6727 30 $self->[1][$i][$c2->[$j]] += $xyz[0];
6728 30 $self->[1][$i][$c2->[$j + 1]] += $xyz[1];
6729 30 $self->[1][$i][$c2->[$j + 2]] += $xyz[2];
6730
6731 }
6732
6733 # for each density column
6734 30 for my $j (@{$c3}) {
6735
6736 # add temp reflectance
6737 0 $self->[1][$i][$j] += POSIX::pow(10, -$temp->[1][$i][$j]);
6738
6739 }
6740
6741 }
6742
6743 # increment file count
6744 3 $n++;
6745
6746 } else {
6747
6748 # print warning
6749 0 warn("chart $file has different structure, ignored\n");
6750
6751 }
6752
6753 } else {
6754
6755 # print warning
6756 0 warn("chart $file $result, ignored\n");
6757
6758 }
6759
6760 }
6761
6762 }
6763  
6764 # if any files were read
6765 1 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) 1 0 1
6766
6767 # if there are measurement values
6768 1 ▶ if (@{$c1} || @{$c2} || @{$c3}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$c1;} or @{$c2;} or @{$c3;}) 0 0 0
Condition33%2/6
@{$c1;} or @{$c2;} or @{$c3;}
l!l&&r!l&&!r
100
@{$c1;} or @{$c2;}
l!l&&r!l&&!r
100
MC/DC0%0/3
@{$c1;} or @{$c2;} or @{$c3;}
@{$c1;} @{$c2;} @{$c3;}
Truth table25%1/4
A or B or C
A= @{$c1;}B= @{$c2;}C= @{$c3;}
ABCresult
1XX1
01X1
0011
0000
6769
6770 # for each sample
6771 1 for my $i (1 .. $#{$self->[1]}) {
6772
6773 # for each measurement column
6774 10 for my $j (@{$c1}, @{$c2}, @{$c3}) {
6775
6776 # divide by n
6777 60 $self->[1][$i][$j] /= $n;
6778
6779 }
6780
6781 # for each group of L*a*b* columns
6782 10 ▶ for (my $j = 0; $j < @{$c2}; $j += 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @{$c2;}) 10 10 20
6783
6784 # convert to xyz values to L*a*b*
6785 10 @{$self->[1][$i]}[@{$c2}[$j .. $j + 2]] = ICC::Shared::_xyz2Lab(@{$self->[1][$i]}[@{$c2}[$j .. $j + 2]]);
6786
6787 }
6788
6789 # for each density column
6790 10 for my $j (@{$c3}) {
6791
6792 # convert reflectance to density
6793 0 $self->[1][$i][$j] = -POSIX::log10($self->[1][$i][$j]);
6794
6795 }
6796
6797 }
6798
6799 }
6800
6801 # add ISO statistics, if requested
6802 1 ▶ _addStats($self, $charts, $hash) if ($fstat);
Branch: 1 branch
BranchTrueFalseTotal
if $fstat 0 1 1
6803
6804 # print message
6805 1 print "$n files read in directory $self->[0]{'file_path'}\n\n";
6806
6807 # save number of files read
6808 1 $self->[0]{'files_read'} = $n;
6809
6810 }
6811  
6812 # return
6813 1 return($n);
6814  
6815 }
6816  
6817 # add ISO statistics
6818 # the object_reference contains the mean values
6819 # the individual charts are in the array_of_chart_objects
6820 # parameters: (object_reference, array_of_chart_objects, hash)
6821 sub _addStats {
6822  
6823 # get parameters
6824 0 ▶ my ($self, $charts, $hash) = @_;
Subroutine _addStats: not called CC=31 SCAR=69.0
6825  
6826 # local variables
6827 0 my (@ctx, $cols, $scols);
6828  
6829 # for each hash key
6830 0 for (keys(%{$hash})) {
6831
6832 # if value is a scalar
6833 0 ▶ if (! ref($hash->{$_})) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $hash->{$_}) { } 0 0 0
elsif (ref $hash->{$_} eq 'ARRAY') { } 0 0 0
6834
6835 # save context value
6836 0 @ctx = ($hash->{$_});
6837
6838 } elsif (ref($hash->{$_}) eq 'ARRAY') {
6839
6840 # save context values
6841 0 @ctx = @{$hash->{$_}};
6842
6843 }
6844
6845 # if 'STDEV_XYZ'
6846 0 ▶ if (m/^STDEV_XYZ$/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/^STDEV_XYZ$/) { } 0 0 0
elsif (/^(STDEV_LAB|CHI_SQD_PAR)$/) { } 0 0 0
elsif (/^MEAN_DE$/) { } 0 0 0
6847
6848 # for each context
6849 0 for my $context (@ctx) {
6850
6851 # resolve context value
6852 0 ▶ $context = defined($context) && length($context) ? $context : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $context && length $context ? : 0 0 0
Condition0%0/3
defined $context and length $context
!ll&&!rl&&r
000
MC/DC0%0/2
defined $context and length $context
defined $context length $context
Truth table0%0/3
A and B
A= defined $contextB= length $context
ABresult
0X0
100
111
6853
6854 # if no STDEV_XYZ columns with context
6855 0 ▶ if (! test($self, 'STDEVXYZ', $context)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (test($self, "STDEVXYZ", $context)) 0 0 0
6856
6857 # get XYZ columns
6858 0 ▶ $cols = cols($self, map {defined($context) ? "$context|$_" : $_} qw(XYZ_X XYZ_Y XYZ_Z));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
6859
6860 # add STDEV_XYZ columns
6861 0 ▶ $scols = add_fmt($self, map {defined($context) ? "$context|$_" : $_} qw(STDEV_X STDEV_Y STDEV_Z));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
6862
6863 # for each XYZ
6864 0 for my $i (0 .. 2) {
6865
6866 # add STDEV_XYZ values
6867 0 _addStdDevCol($self, $charts, $cols->[$i], $scols->[$i]);
6868
6869 }
6870
6871 }
6872
6873 # set origin
6874 0 @{$self->[2][0]}[@{$scols}] = ($cols) x 3;
6875
6876 # save illuminant white point
6877 0 @{$self->[2][2]}[@{$scols}] = @{$self->[2][2]}[@{$cols}];
6878
6879 }
6880
6881 # if 'STDEV_LAB' or 'CHI_SQD_PAR'
6882 } elsif (m/^(STDEV_LAB|CHI_SQD_PAR)$/) {
6883
6884 # for each context
6885 0 for my $context (@ctx) {
6886
6887 # resolve context value
6888 0 ▶ $context = defined($context) && length($context) ? $context : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $context && length $context ? : 0 0 0
Condition0%0/3
defined $context and length $context
!ll&&!rl&&r
000
MC/DC0%0/2
defined $context and length $context
defined $context length $context
Truth table0%0/3
A and B
A= defined $contextB= length $context
ABresult
0X0
100
111
6889
6890 # if no STDEV_LAB columns with context
6891 0 ▶ if (! test($self, 'STDEVLAB', $context)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (test($self, "STDEVLAB", $context)) 0 0 0
6892
6893 # get L*a*b* columns
6894 0 ▶ $cols = cols($self, map {defined($context) ? "$context|$_" : $_} qw(LAB_L LAB_A LAB_B));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
6895
6896 # add STDEV_LAB columns
6897 0 ▶ $scols = add_fmt($self, map {defined($context) ? "$context|$_" : $_} qw(STDEV_L STDEV_A STDEV_B));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
6898
6899 # for each L*a*b*
6900 0 for my $i (0 .. 2) {
6901
6902 # add STDEV_LAB values
6903 0 _addStdDevCol($self, $charts, $cols->[$i], $scols->[$i]);
6904
6905 }
6906
6907 # set origin
6908 0 @{$self->[2][0]}[@{$scols}] = ($cols) x 3;
6909
6910 # save illuminant white point
6911 0 @{$self->[2][2]}[@{$scols}] = @{$self->[2][2]}[@{$cols}];
6912
6913 }
6914
6915 # if 'CHI_SQD_PAR'
6916 0 ▶ if ($1 eq 'CHI_SQD_PAR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "CHI_SQD_PAR") 0 0 0
6917
6918 # get STDEV_LAB columns
6919 0 ▶ $cols = cols($self, map {defined($context) ? "$context|$_" : $_} qw(STDEV_L STDEV_A STDEV_B));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
6920
6921 # add CHI_SQD_PAR column
6922 0 ▶ $scols = add_fmt($self, map {defined($context) ? "$context|$_" : $_} qw(CHI_SQD_PAR));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
6923
6924 # for each sample
6925 0 for my $i (1 .. $#{$self->[1]}) {
6926
6927 # set CHI_SQD_PAR value (average of L*a*b* standard deviations)
6928 0 $self->[1][$i][$scols->[0]] = List::Util::sum(@{$self->[1][$i]}[@{$cols}])/3;
6929
6930 }
6931
6932 # set origin
6933 0 $self->[2][0][$scols->[0]] = $cols;
6934
6935 }
6936
6937 }
6938
6939 # if 'MEAN_DE'
6940 } elsif (m/^MEAN_DE$/) {
6941
6942 # for each context
6943 0 for my $context (@ctx) {
6944
6945 # resolve context value
6946 0 ▶ $context = defined($context) && length($context) ? $context : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $context && length $context ? : 0 0 0
Condition0%0/3
defined $context and length $context
!ll&&!rl&&r
000
MC/DC0%0/2
defined $context and length $context
defined $context length $context
Truth table0%0/3
A and B
A= defined $contextB= length $context
ABresult
0X0
100
111
6947
6948 # if no MEAN_DE columns with context
6949 0 ▶ if (! test($self, 'MEAN_DE', $context)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (test($self, "MEAN_DE", $context)) 0 0 0
6950
6951 # get L*a*b* columns
6952 0 ▶ $cols = cols($self, map {defined($context) ? "$context|$_" : $_} qw(LAB_L LAB_A LAB_B));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
6953
6954 # add MEAN_DE column
6955 0 ▶ $scols = add_fmt($self, map {defined($context) ? "$context|$_" : $_} qw(MEAN_DE));
Branch: 1 branch
BranchTrueFalseTotal
defined $context ? : 0 0 0
6956
6957 # add MEAN_DE values
6958 0 _addMeanDECol($self, $charts, $cols, $scols->[0]);
6959
6960 # set origin
6961 0 $self->[2][0][$scols->[0]] = $cols;
6962
6963 }
6964
6965 }
6966
6967 }
6968
6969 }
6970
6971 }
6972  
6973 # add standard deviation column
6974 # the object_reference contains the mean values
6975 # the individual charts are in the array_of_chart_objects
6976 # parameters: (object_reference, array_of_chart_objects, mean_column, std_dev_column)
6977 sub _addStdDevCol {
6978  
6979 # get parameters
6980 0 ▶ my ($self, $charts, $m, $s) = @_;
Subroutine _addStdDevCol: not called CC=4 SCAR=30.0
6981  
6982 # local variables
6983 0 my ($n);
6984  
6985 # get number of charts
6986 0 $n = @{$charts};
6987  
6988 # for each sample
6989 0 for my $i (1 .. $#{$self->[1]}) {
6990
6991 # initialize value
6992 0 $self->[1][$i][$s] = 0;
6993
6994 # if number of charts > 0
6995 0 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) { } 0 0 0
6996
6997 # for each chart
6998 0 for my $j (0 .. $#{$charts}) {
6999
7000 # add squared difference
7001 0 $self->[1][$i][$s] += ($charts->[$j][$i][$m] - $self->[1][$i][$m])**2;
7002
7003 }
7004
7005 # complete calculation
7006 0 $self->[1][$i][$s] = sqrt($self->[1][$i][$s]/$n);
7007
7008 } else {
7009
7010 # error
7011 0 croak('can\'t compute standard deviation with zero samples');
7012
7013 }
7014
7015 }
7016
7017 }
7018  
7019 # add mean dEab column
7020 # the object_reference contains the mean values
7021 # the individual charts are in the array_of_chart_objects
7022 # parameters: (object_reference, array_of_chart_objects, mean_L*a*b*_columns, mean_dE_column)
7023 sub _addMeanDECol {
7024  
7025 # get parameters
7026 0 ▶ my ($self, $charts, $m, $s) = @_;
Subroutine _addMeanDECol: not called CC=5 SCAR=34.0
7027  
7028 # local variables
7029 0 my ($n, $dE);
7030  
7031 # get number of charts
7032 0 $n = @{$charts};
7033  
7034 # for each sample
7035 0 for my $i (1 .. $#{$self->[1]}) {
7036
7037 # initialize value
7038 0 $self->[1][$i][$s] = 0;
7039
7040 # if number of charts > 0
7041 0 ▶ if ($n) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n) { } 0 0 0
7042
7043 # for each chart
7044 0 for my $j (0 .. $#{$charts}) {
7045
7046 # initialize dE
7047 0 $dE = 0;
7048
7049 # for each L*a*b*
7050 0 for my $k (0 .. 2) {
7051
7052 # add squared difference
7053 0 $dE += ($self->[1][$i][$m->[$k]] - $charts->[$j][$i][$m->[$k]])**2;
7054
7055 }
7056
7057 # add dE for this chart
7058 0 $self->[1][$i][$s] += sqrt($dE);
7059
7060 }
7061
7062 # complete calculation
7063 0 $self->[1][$i][$s] /= $n;
7064
7065 } else {
7066
7067 # error
7068 0 croak('can\'t compute mean dE with zero samples');
7069
7070 }
7071
7072 }
7073
7074 }
7075  
7076 # read chart from list of data files
7077 # files must have identical structure (cols)
7078 # reads first chart, then appends other charts
7079 # parameters: (object_reference, ref_to_file_list, hash)
7080 # returns: (number_of_files_appended)
7081 sub _readChartAppend {
7082  
7083 # get parameters
7084 1 ▶ my ($self, $list, $hash) = @_;
Subroutine _readChartAppend: called CC=9 SCAR=22.9
7085  
7086 # local variables
7087 1 my ($n, $result, $keys, $temp);
7088  
7089 # initialize file counter
7090 1 $n = 0;
7091  
7092 # for each file
7093 1 for my $file (@{$list}) {
7094
7095 # if first file
7096 4 ▶ if ($n == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n == 0) { } 1 3 4
7097
7098 # if file read successfully
7099 1 ▶ if (! ($result = _readChart($self, $file, $hash))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result = _readChart($self, $file, $hash)) { } 1 0 1
7100
7101 # add colorimetric metadata
7102 1 _addColorMeta($self);
7103
7104 # make format key string
7105 1 ▶ $keys = join(':', map {defined() ? $_ : '-'} @{$self->[1][0]});
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 12 0 12
7106
7107 # increment counter
7108 1 $n++;
7109
7110 } else {
7111
7112 # print warning
7113 0 warn("chart $file $result, ignored\n");
7114
7115 }
7116
7117 } else {
7118
7119 # make temporary Chart object
7120 3 $temp = ICC::Support::Chart->new();
7121
7122 # if file read successfully
7123 3 ▶ if (! ($result = _readChart($temp, $file, $hash))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $result = _readChart($temp, $file, $hash)) { } 3 0 3
7124
7125 # if charts have same structure (cols)
7126 3 ▶ if ($keys eq join(':', map {defined() ? $_ : '-'} @{$temp->[1][0]})) {
Branch: 2 branches
BranchTrueFalseTotal
if ($keys eq join(':', map({defined $_ ? $_ : '-';} @{$$temp[1][0];}))) { } 3 0 3
defined $_ ? : 36 0 36
7127
7128 # append temp samples
7129 3 push(@{$self->[1]}, @{$temp->[1]}[1 .. $#{$temp->[1]}]);
7130
7131 # increment counter
7132 3 $n++;
7133
7134 } else {
7135
7136 # print warning
7137 0 warn("chart $file has different structure, ignored\n");
7138
7139 }
7140
7141 } else {
7142
7143 # print warning
7144 0 warn("chart $file $result, ignored\n");
7145
7146 }
7147
7148 }
7149
7150 }
7151  
7152 # print message if any files were read
7153 1 ▶ print "$n files read in directory $self->[0]{'file_path'}\n\n" if ($n);
Branch: 1 branch
BranchTrueFalseTotal
if $n 1 0 1
7154  
7155 # return
7156 1 return($n);
7157  
7158 }
7159  
7160 # read chart
7161 # parameters: (object_reference, path_to_file, hash)
7162 # returns: (result)
7163 sub _readChart {
7164  
7165 # get parameters
7166 27 ▶ my ($self, $path, $hash) = @_;
Subroutine _readChart: called CC=11 SCAR=28.6
7167  
7168 # local variables
7169 27 my ($fh, $buf, $result);
7170  
7171 # open the file (read-only)
7172 27 ▶ open($fh, '<', $path) || return("$! when opening $path");
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $path or return "$! when opening $path" 0 27 27
7173  
7174 # set binary mode
7175 27 binmode($fh);
7176  
7177 # read start of file
7178 27 read($fh, $buf, 1024);
7179  
7180 # reset file pointer
7181 27 seek($fh, 0, 0);
7182  
7183 # if an ASE file
7184 27 ▶ if ($buf =~ m/^ASEF/) {
Branch: 5 branches
BranchTrueFalseTotal
if ($buf =~ /^ASEF/) { } 0 27 27
elsif ($buf =~ /^(II\*\x00|MM\x00\*)/) { } 0 27 27
elsif (substr($buf, 36, 4) eq 'acsp') { } 0 27 27
elsif ($buf =~ /<\?xml/) { } 8 19 27
elsif (substr($buf, 0, 4) eq "\000 \000\000" or substr($buf, 0, 4) eq "\0002\000\000") { } 0 19 19
7185
7186 # save file type
7187 0 $self->[0]{'file_type'} = 'ASEF';
7188
7189 # read ASE file
7190 0 $result = _readChartASE($self, $fh, $hash);
7191
7192 # if a TIFF file
7193 } elsif ($buf =~ m/^(II\*\x00|MM\x00\*)/) {
7194
7195 # save file type
7196 0 $self->[0]{'file_type'} = 'TIFF';
7197
7198 # read TIFF file
7199 0 $result = _readChartTIFF($self, $fh, $hash);
7200
7201 # if an ICC profile
7202 } elsif (substr($buf, 36, 4) eq 'acsp') {
7203
7204 # save file type
7205 0 $self->[0]{'file_type'} = 'prof';
7206
7207 # read ICC file
7208 0 $result = _readChartICC($self, $fh, $hash);
7209
7210 # if an XML file
7211 } elsif ($buf =~ m/<\?xml/) {
7212
7213 # save file type
7214 8 $self->[0]{'file_type'} = 'CXFX';
7215
7216 # read CxF3 file
7217 8 $result = _readChartCxF3($self, $fh, $hash);
7218
7219 # if an SS3 file
7220 ▶ } elsif (substr($buf, 0, 4) eq "\x00\x20\x00\x00" || substr($buf, 0, 4) eq "\x00\x32\x00\x00") {
Condition33%1/3
substr($buf, 0, 4) eq "\0 \0\0" or substr($buf, 0, 4) eq "\0002\0\0"
l!l&&r!l&&!r
0019
MC/DC0%0/2
substr($buf, 0, 4) eq "\0 \0\0" or substr($buf, 0, 4) eq "\0002\0\0"
substr($buf, 0, 4) eq "\0 \0\0" substr($buf, 0, 4) eq "\0002\0\0"
Truth table33%1/3
A or B
A= substr($buf, 0, 4) eq "\0 \0\0"B= substr($buf, 0, 4) eq "\0002\0\0"
ABresult
1X1
011
000
7221
7222 # save file type
7223 0 $self->[0]{'file_type'} = 'SS3';
7224
7225 # read SS3 file
7226 0 $result = _readChartSS3($self, $fh, $hash);
7227
7228 } else {
7229
7230 # check for CR-LF (DOS/Windows)
7231 19 ▶ if ($buf =~ m/\015\012/) {
Branch: 3 branches
BranchTrueFalseTotal
if ($buf =~ /\015\012/) { } 1 18 19
elsif ($buf =~ /\012/) { } 17 1 18
elsif ($buf =~ /\015/) { } 1 0 1
7232
7233 # set record separator
7234 1 $self->[0]{'read_rs'} = "\015\012";
7235
7236 # check for LF (Unix/OSX)
7237 } elsif ($buf =~ m/\012/) {
7238
7239 # set record separator
7240 17 $self->[0]{'read_rs'} = "\012";
7241
7242 # check for CR (Mac)
7243 } elsif ($buf =~ m/\015/) {
7244
7245 # set record separator
7246 1 $self->[0]{'read_rs'} = "\015";
7247
7248 # not a text file
7249 } else {
7250
7251 # close the file
7252 0 close($fh);
7253
7254 # return
7255 0 return('unknown file type');
7256
7257 }
7258
7259 # save file type
7260 19 $self->[0]{'file_type'} = 'TEXT';
7261
7262 # read ASCII file
7263 19 $result = _readChartASCII($self, $fh, $hash);
7264
7265 }
7266  
7267 # close the file
7268 27 close($fh);
7269  
7270 # return
7271 27 return($result);
7272  
7273 }
7274  
7275 # read chart from ISO 28178 ASCII data file
7276 # parameters: (object_reference, file_handle, hash)
7277 # returns: (result)
7278 sub _readChartASCII {
7279  
7280 # get parameters
7281 19 ▶ my ($self, $fh, $hash) = @_;
Subroutine _readChartASCII: called CC=33 SCAR=41.5
7282  
7283 # local variables
7284 19 my ($state, $iflag, $eflag, $index);
7285 19 my (@fields, $illum, $append);
7286  
7287 # localize input record separator
7288 19 local $/ = $self->[0]{'read_rs'};
7289  
7290 # localize loop variable
7291 19 local $_;
7292  
7293 # initialize variables
7294 19 $self->[1] = [[]];
7295 19 $illum = [[]];
7296 19 $index = 1;
7297 19 $state = 0;
7298 19 $iflag = 0;
7299  
7300 # read the file, line by line
7301 19 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 497 19 516
7302
7303 # add appended text, as is
7304 497 ▶ $append .= $_ if ($state == 4);
Branch: 1 branch
BranchTrueFalseTotal
if $state == 4 0 497 497
7305
7306 # remove leading spaces/tabs and trailing whitespace
7307 497 s/^[ \t]*(.*?)[\s,]*$/$1/;
7308
7309 # if normal comment line (all comments are removed)
7310 497 ▶ if (s/#[\s]*(.*)// && $state == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/#[\s]*(.*)// and $state == 0) 32 465 497
Condition66%2/3
s/#[\s]*(.*)// and $state == 0
!ll&&!rl&&r
465032
MC/DC50%1/2
s/#[\s]*(.*)// and $state == 0
s/#[\s]*(.*)// $state == 0
Truth table66%2/3
A and B
A= s/#[\s]*(.*)//B= $state == 0
ABresult
0X0
100
111
7311
7312 # if remaining line blank
7313 32 ▶ if (length() == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $_ == 0) { } 26 6 32
7314
7315 # add comment to header array
7316 26 push(@{$self->[3]}, ['#', $1]);
7317
7318 } else {
7319
7320 # restore comment to header line
7321 # preserves time in ProfileMaker 'CREATED' lines
7322 6 $_ .= "# $1";
7323
7324 }
7325
7326 }
7327
7328 # skip blank lines
7329 497 ▶ next if (length() == 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $_ == 0 26 471 497
7330
7331 # begin data format
7332 471 ▶ if (m/^BEGIN_DATA_FORMAT$/) {
Branch: 6 branches
BranchTrueFalseTotal
if (/^BEGIN_DATA_FORMAT$/) { } 19 452 471
elsif (/^END_DATA_FORMAT$/) { } 19 433 452
elsif (/^BEGIN_DATA$/) { } 19 414 433
elsif (/^END_DATA$/) { } 19 395 414
elsif (/^BEGIN_DATA_EMISSION$/) { } 0 395 395
elsif (/^END_DATA_EMISSION$/) { } 0 395 395
7333
7334 # set state
7335 19 $state = 1;
7336
7337 # end data format
7338 } elsif (m/^END_DATA_FORMAT$/) {
7339
7340 # set state
7341 19 $state = 2;
7342
7343 # begin data
7344 } elsif (m/^BEGIN_DATA$/) {
7345
7346 # set state
7347 19 $state = 3;
7348
7349 # end data
7350 } elsif (m/^END_DATA$/) {
7351
7352 # set state
7353 19 $state = 4;
7354
7355 # begin ProfileMaker illuminant section
7356 } elsif (m/^BEGIN_DATA_EMISSION$/) {
7357
7358 # set illuminant flag
7359 0 $iflag = 1;
7360
7361 # reset index
7362 0 $index = 1;
7363
7364 # end ProfileMaker illuminant section
7365 } elsif (m/^END_DATA_EMISSION$/) {
7366
7367 # clear illuminant flag
7368 0 $iflag = 0;
7369
7370 # reset appended data
7371 0 $append = '';
7372
7373 # anything else
7374 } else {
7375
7376 # format
7377 395 ▶ if ($iflag == 0 && $state == 1) {
Branch: 5 branches
BranchTrueFalseTotal
if ($iflag == 0 and $state == 1) { } 19 376 395
elsif ($iflag == 0 and $state == 3) { } 190 186 376
elsif ($iflag == 1 and $state == 1) { } 0 186 186
elsif ($iflag == 1 and $state == 3) { } 0 186 186
elsif ($iflag == 0 and $state == 0 || $state == 2) { } 186 0 186
Condition66%2/3
$iflag == 0 and $state == 1
!ll&&!rl&&r
037619
MC/DC50%1/2
$iflag == 0 and $state == 1
$iflag == 0 $state == 1
Truth table66%2/3
A and B
A= $iflag == 0B= $state == 1
ABresult
0X0
100
111
7378
7379 # change 'SampleID' to 'SAMPLE_ID'
7380 # non-standard notation used by ProfileMaker
7381 19 s/SampleID/SAMPLE_ID/;
7382
7383 # parse and save format keys
7384 19 push(@{$self->[1][0]}, split(/[\s,]+/));
7385
7386 # data
7387 ▶ } elsif ($iflag == 0 && $state == 3) {
Condition66%2/3
$iflag == 0 and $state == 3
!ll&&!rl&&r
0186190
MC/DC50%1/2
$iflag == 0 and $state == 3
$iflag == 0 $state == 3
Truth table66%2/3
A and B
A= $iflag == 0B= $state == 3
ABresult
0X0
100
111
7388
7389 # if Euro flag not defined
7390 190 ▶ if (! defined($eflag)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $eflag) 19 171 190
7391
7392 # split data
7393 19 @fields = split(/[\s,]+/);
7394
7395 # set flag for Euro decimal notation (e.g. 6,3 becomes 6.3)
7396 19 ▶ $eflag = m/,/ && @fields > (@{$self->[1][0]} || 0);
Condition20%1/5
/,/ && @fields > (@{$self->[1][0];} || 0)
!ll&&!rl&&r
1900
@{$self->[1][0];} || 0
l!l
00
MC/DC0%0/2
/,/ && @fields > (@{$self->[1][0];} || 0)
/,/ @fields > (@{$self->[1][0];} || 0)
MC/DC0%0/1
@{$self->[1][0];} || 0
@{$self->[1][0];}
Truth table33%1/3
A && B
A= /,/B= @fields > (@{$self->[1][0];} || 0)
ABresult
0X0
100
111
Truth table0%0/2
A
A= @{$self->[1][0];}
Aresult
11
00
7397
7398 }
7399
7400 # fix Euro decimal notation (e.g. 6,3 becomes 6.3)
7401 190 ▶ s/(\d),(\d)/$1.$2/g if ($eflag);
Branch: 1 branch
BranchTrueFalseTotal
if $eflag 0 190 190
7402
7403 # parse and save data
7404 190 $self->[1][$index++] = [split(/[\s,]+/)];
7405
7406 # illuminant format
7407 # may be different from data format
7408 ▶ } elsif ($iflag == 1 && $state == 1) {
Condition33%1/3
$iflag == 1 and $state == 1
!ll&&!rl&&r
18600
MC/DC0%0/2
$iflag == 1 and $state == 1
$iflag == 1 $state == 1
Truth table33%1/3
A and B
A= $iflag == 1B= $state == 1
ABresult
0X0
100
111
7409
7410 # change 'SampleID' to 'SAMPLE_ID'
7411 # non-standard notation used by ProfileMaker
7412 0 s/SampleID/SAMPLE_ID/;
7413
7414 # parse and save illuminant format keys
7415 0 push(@{$illum->[0]}, split(/[\s,]+/));
7416
7417 # illuminant data
7418 ▶ } elsif ($iflag == 1 && $state == 3) {
Condition33%1/3
$iflag == 1 and $state == 3
!ll&&!rl&&r
18600
MC/DC0%0/2
$iflag == 1 and $state == 3
$iflag == 1 $state == 3
Truth table33%1/3
A and B
A= $iflag == 1B= $state == 3
ABresult
0X0
100
111
7419
7420 # fix Euro decimal notation (e.g. 6,3 becomes 6.3)
7421 0 ▶ s/(\d),(\d)/$1.$2/g if ($eflag);
Branch: 1 branch
BranchTrueFalseTotal
if $eflag 0 0 0
7422
7423 # parse and save illuminant data
7424 0 $illum->[$index++] = [split(/[\s,]+/)];
7425
7426 # header lines
7427 ▶ } elsif ($iflag == 0 && ($state == 0 || $state == 2)) {
Condition50%3/6
$iflag == 0 and $state == 0 || $state == 2
!ll&&!rl&&r
00186
$state == 0 or $state == 2
l!l&&r!l&&!r
167190
MC/DC0%0/3
$iflag == 0 and $state == 0 || $state == 2
$iflag == 0 $state == 0 $state == 2
Truth table50%2/4
A and B or C
A= $iflag == 0B= $state == 0C= $state == 2
ABCresult
0XX0
1000
11X1
1011
7428
7429 # match keyword/value
7430 186 m/^([^\s,]*)[\s,]*(.*?)$/;
7431
7432 # add to header array
7433 186 ▶ push(@{$self->[3]}, [$1, $2]) if (length($1));
Branch: 1 branch
BranchTrueFalseTotal
if length $1 186 0 186
7434
7435 }
7436
7437 }
7438
7439 }
7440  
7441 # save illuminant data, if any
7442 19 ▶ $self->[0]{'illuminant'} = $illum if defined($illum->[1]);
Branch: 1 branch
BranchTrueFalseTotal
if defined $illum->[1] 0 19 19
7443  
7444 # save appended data, if any
7445 19 ▶ $self->[0]{'append'} = $append if (defined($append));
Branch: 1 branch
BranchTrueFalseTotal
if defined $append 0 19 19
7446  
7447 # apply rotation/flip (special keywords)
7448 19 _rotateChartASCII($self);
7449  
7450 # return success flag
7451 19 ▶ return($state == 4 ? () : "ASCII read failed with state $state");
Branch: 1 branch
BranchTrueFalseTotal
$state == 4 ? : 19 0 19
7452  
7453 }
7454  
7455 # apply rotation/flip to ASCII chart data
7456 # if LGOROWLENGTH and (DPLGROTATE or DPLGFLIP) keywords are present
7457 # parameter: (object_reference)
7458 sub _rotateChartASCII {
7459  
7460 # get object reference
7461 19 ▶ my $self = shift();
Subroutine _rotateChartASCII: called CC=4 SCAR=20.9
7462  
7463 # local variables
7464 19 my ($rot, $flip, $mat, $rows);
7465  
7466 # get the rotation and flip values
7467 19 $rot = keyword($self, 'DPLGROTATE');
7468 19 $flip = keyword($self, 'DPLGFLIP');
7469  
7470 # if LGOROWLENGTH and (DPLGROTATE or DPLGFLIP) keywords
7471 19 ▶ if (keyword($self, 'LGOROWLENGTH') && ($rot || $flip)) {
Branch: 1 branch
BranchTrueFalseTotal
if (keyword($self, "LGOROWLENGTH") and $rot || $flip) 0 19 19
Condition33%2/6
keyword($self, "LGOROWLENGTH") and $rot || $flip
!ll&&!rl&&r
0190
$rot or $flip
l!l&&r!l&&!r
0019
MC/DC0%0/3
keyword($self, "LGOROWLENGTH") and $rot || $flip
keyword($self, "LGOROWLENGTH") $rot $flip
Truth table25%1/4
A and B or C
A= keyword($self, "LGOROWLENGTH")B= $rotC= $flip
ABCresult
0XX0
1000
11X1
1011
7472
7473 # get selection matrix
7474 0 $mat = select_matrix($self)->rotate($rot)->flip($flip);
7475
7476 # flatten matrix
7477 0 $rows = ICC::Shared::flatten($mat);
7478
7479 # prepend DATA_FORMAT row index (0)
7480 0 unshift(@{$rows}, 0);
7481
7482 # rearrange chart data
7483 0 $self->[1] = [@{$self->[1]}[@{$rows}]];
7484
7485 # update LGOROWLENGTH
7486 0 keyword($self, 'LGOROWLENGTH', scalar(@{$mat->[0]}));
7487
7488 }
7489
7490 }
7491  
7492 # read chart from Adobe Swatch Exchange (.ase) file
7493 # optional hash key: 'colorspace'
7494 # 'colorspace' values: 'CMYK', 'LAB ', 'RGB ' or 'Gray'
7495 # 'Gray' swatches are mapped to CMYK values
7496 # parameters: (object_reference, file_handle, hash)
7497 # returns: (result)
7498 sub _readChartASE {
7499  
7500 # get parameters
7501 0 ▶ my ($self, $fh, $hash) = @_;
Subroutine _readChartASE: not called CC=28 SCAR=67.0
7502  
7503 # local variables
7504 0 my ($cs, $le, $buf, @header, $sn);
7505 0 my ($mark, $type, $blen, $slen);
7506 0 my ($name, $space, $cmyk, $rgb, $Lab, $dev);
7507  
7508 # set colorspace selector
7509 0 ▶ $cs = $hash->{'colorspace'} if defined($hash->{'colorspace'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash->{"colorspace"} 0 0 0
7510  
7511 # get little-endian flag
7512 0 $le = ($Config{'byteorder'} =~ m/1234/);
7513  
7514 # read header (file signature, version, number of blocks)
7515 0 read($fh, $buf, 12);
7516  
7517 # unpack buffer
7518 0 @header = unpack('A4nnN', $buf);
7519  
7520 # verify file signature
7521 0 ▶ ($header[0] eq 'ASEF') || return('not a valid ASE file');
Branch: 1 branch
BranchTrueFalseTotal
$header[0] eq "ASEF" or return "not a valid ASE file" 0 0 0
7522  
7523 # add SAMPLE_NAME field
7524 0 $sn = add_fmt($self, 'SAMPLE_NAME');
7525  
7526 # set file pointer
7527 0 $mark = 12;
7528  
7529 # for each block
7530 0 for my $s (1 .. $header[3]) {
7531
7532 # read block type, block length, and string length
7533 0 read($fh, $buf, 8);
7534
7535 # unpack buffer
7536 0 ($type, $blen, $slen) = unpack('nNn', $buf);
7537
7538 # if color entry type
7539 0 ▶ if ($type == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 1) 0 0 0
7540
7541 # read color name
7542 0 read($fh, $buf, 2 * $slen);
7543
7544 # decode color name
7545 0 $name = decode('UTF-16BE', $buf);
7546
7547 # trim trailing '0'
7548 0 $name =~ s/\x00$//;
7549
7550 # change spaces to underscores
7551 0 $name =~ s/\s/_/g;
7552
7553 # read color space
7554 0 read($fh, $space, 4);
7555
7556 # if colorspace is CMYK
7557 0 ▶ if (($space eq 'CMYK' && (! defined($cs)) || $cs eq 'CMYK')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($space eq 'CMYK' and not defined $cs or $cs eq 'CMYK') { } 0 0 0
elsif ($space eq 'RGB ' and not defined $cs or $cs eq 'RGB ') { } 0 0 0
elsif ($space eq 'LAB ' and not defined $cs or $cs eq 'LAB ') { } 0 0 0
elsif ($space eq 'Gray' and not defined $cs or $cs eq 'Gray') { } 0 0 0
Condition0%0/6
$space eq "CMYK" and not defined $cs or $cs eq "CMYK"
l!l&&r!l&&!r
000
$space eq "CMYK" and not defined $cs
!ll&&!rl&&r
000
MC/DC0%0/3
$space eq "CMYK" and not defined $cs or $cs eq "CMYK"
$space eq "CMYK" not defined $cs $cs eq "CMYK"
Truth table0%0/5
A and not(B) or C
A= $space eq "CMYK"B= not defined $csC= $cs eq "CMYK"
ABCresult
11X1
0X11
1011
0X00
1000
7558
7559 # store color as SAMPLE_NAME
7560 0 $self->[1][$s][$sn->[0]] = $name;
7561
7562 # init device array
7563 0 $dev = [];
7564
7565 # for each CMYK value
7566 0 for my $i (0 .. 3) {
7567
7568 # read 32-bit floating point value
7569 0 read($fh, $buf, 4);
7570
7571 # reverse bytes if long-endian system
7572 0 ▶ $buf = reverse($buf) if ($le);
Branch: 1 branch
BranchTrueFalseTotal
if $le 0 0 0
7573
7574 # unpack buffer
7575 0 $dev->[$i] = unpack('f', $buf);
7576
7577 }
7578
7579 # if CMYK slice undefined
7580 0 ▶ if (! defined($cmyk)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cmyk) 0 0 0
7581
7582 # add CMYK slice
7583 0 $cmyk = add_fmt($self, qw(CMYK_C CMYK_M CMYK_Y CMYK_K));
7584
7585 }
7586
7587 # store CMYK values
7588 0 @{$self->[1][$s]}[@{$cmyk}] = map {100 * $_} @{$dev};
7589
7590 # if colorspace is RGB
7591 ▶ } elsif (($space eq 'RGB ' && (! defined($cs)) || $cs eq 'RGB ')) {
Condition0%0/6
$space eq "RGB " and not defined $cs or $cs eq "RGB "
l!l&&r!l&&!r
000
$space eq "RGB " and not defined $cs
!ll&&!rl&&r
000
MC/DC0%0/3
$space eq "RGB " and not defined $cs or $cs eq "RGB "
$space eq "RGB " not defined $cs $cs eq "RGB "
Truth table0%0/5
A and not(B) or C
A= $space eq "RGB "B= not defined $csC= $cs eq "RGB "
ABCresult
11X1
0X11
1011
0X00
1000
7592
7593 # store color as SAMPLE_NAME
7594 0 $self->[1][$s][$sn->[0]] = $name;
7595
7596 # init device array
7597 0 $dev = [];
7598
7599 # for each RGB value
7600 0 for my $i (0 .. 2) {
7601
7602 # read 32-bit floating point value
7603 0 read($fh, $buf, 4);
7604
7605 # reverse bytes if long-endian system
7606 0 ▶ $buf = reverse($buf) if ($le);
Branch: 1 branch
BranchTrueFalseTotal
if $le 0 0 0
7607
7608 # unpack buffer
7609 0 $dev->[$i] = unpack('f', $buf);
7610
7611 }
7612
7613 # if RGB slice undefined
7614 0 ▶ if (! defined($rgb)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rgb) 0 0 0
7615
7616 # add RGB slice
7617 0 $rgb = add_fmt($self, qw(RGB_R RGB_G RGB_B));
7618
7619 }
7620
7621 # store RGB values
7622 0 @{$self->[1][$s]}[@{$rgb}] = map {255 * $_} @{$dev};
7623
7624 # if colorspace is L*a*b*
7625 ▶ } elsif (($space eq 'LAB ' && (! defined($cs)) || $cs eq 'LAB ')) {
Condition0%0/6
$space eq "LAB " and not defined $cs or $cs eq "LAB "
l!l&&r!l&&!r
000
$space eq "LAB " and not defined $cs
!ll&&!rl&&r
000
MC/DC0%0/3
$space eq "LAB " and not defined $cs or $cs eq "LAB "
$space eq "LAB " not defined $cs $cs eq "LAB "
Truth table0%0/5
A and not(B) or C
A= $space eq "LAB "B= not defined $csC= $cs eq "LAB "
ABCresult
11X1
0X11
1011
0X00
1000
7626
7627 # store color as SAMPLE_NAME
7628 0 $self->[1][$s][$sn->[0]] = $name;
7629
7630 # init device array
7631 0 $dev = [];
7632
7633 # for each L*a*b* value
7634 0 for my $i (0 .. 2) {
7635
7636 # read 32-bit floating point value
7637 0 read($fh, $buf, 4);
7638
7639 # reverse bytes if long-endian system
7640 0 ▶ $buf = reverse($buf) if ($le);
Branch: 1 branch
BranchTrueFalseTotal
if $le 0 0 0
7641
7642 # unpack buffer
7643 0 $dev->[$i] = unpack('f', $buf);
7644
7645 }
7646
7647 # if L*a*b* slice undefined
7648 0 ▶ if (! defined($Lab)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Lab) 0 0 0
7649
7650 # add L*a*b* fields
7651 0 $Lab = add_fmt($self, qw(LAB_L LAB_A LAB_B));
7652
7653 }
7654
7655 # store L*a*b* values
7656 0 @{$self->[1][$s]}[@{$Lab}] = (100 * $dev->[0], $dev->[1], $dev->[2]);
7657
7658 # if colorspace is Grayscale
7659 ▶ } elsif (($space eq 'Gray' && (! defined($cs)) || $cs eq 'Gray')) {
Condition0%0/6
$space eq "Gray" and not defined $cs or $cs eq "Gray"
l!l&&r!l&&!r
000
$space eq "Gray" and not defined $cs
!ll&&!rl&&r
000
MC/DC0%0/3
$space eq "Gray" and not defined $cs or $cs eq "Gray"
$space eq "Gray" not defined $cs $cs eq "Gray"
Truth table0%0/5
A and not(B) or C
A= $space eq "Gray"B= not defined $csC= $cs eq "Gray"
ABCresult
11X1
0X11
1011
0X00
1000
7660
7661 # store color as SAMPLE_NAME
7662 0 $self->[1][$s][$sn->[0]] = $name;
7663
7664 # read 32-bit floating point value
7665 0 read($fh, $buf, 4);
7666
7667 # reverse bytes if long-endian system
7668 0 ▶ $buf = reverse($buf) if ($le);
Branch: 1 branch
BranchTrueFalseTotal
if $le 0 0 0
7669
7670 # unpack buffer
7671 0 $dev = [unpack('f', $buf)];
7672
7673 # if CMYK slice is undefined
7674 0 ▶ if (! defined($cmyk)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $cmyk) 0 0 0
7675
7676 # add CMYK slice
7677 0 $cmyk = add_fmt($self, qw(CMYK_C CMYK_M CMYK_Y CMYK_K));
7678
7679 }
7680
7681 # store CMYK values
7682 0 @{$self->[1][$s]}[@{$cmyk}] = (0, 0, 0, 100 * (1 - $dev->[0]));
7683
7684 }
7685
7686 }
7687
7688 # set file pointer to next block
7689 0 $mark += $blen + 6;
7690
7691 # seek next block
7692 0 seek($fh, $mark, 0);
7693
7694 }
7695  
7696 # return
7697 0 return();
7698  
7699 }
7700  
7701 # read chart from ICC profile
7702 # some profiles have tags containing chart data
7703 # parameters: (object_reference, file_handle, hash)
7704 # returns: (result)
7705 sub _readChartICC {
7706  
7707 # get parameters
7708 0 ▶ my ($self, $fh, $hash) = @_;
Subroutine _readChartICC: not called CC=21 SCAR=61.4
7709  
7710 # local variables
7711 0 my (@header, @tagtab, %offset, %tags, $type, $class);
7712 0 my ($temp, $data, $text, $result);
7713  
7714 # load ICC::Profile modules, if not already included
7715 0 require ICC::Profile;
7716  
7717 # read the profile header
7718 0 ▶ ICC::Profile::_readICCheader($fh, \@header) || return('failed reading ICC profile header');
Branch: 1 branch
BranchTrueFalseTotal
ICC::Profile::_readICCheader($fh, \@header) or return "failed reading ICC profile header" 0 0 0
7719  
7720 # read the profile tag table
7721 0 ▶ ICC::Profile::_readICCtagtable($fh, \@tagtab) || return('failed reading ICC profile tag table');
Branch: 1 branch
BranchTrueFalseTotal
ICC::Profile::_readICCtagtable($fh, \@tagtab) or return "failed reading ICC profile tag table" 0 0 0
7722  
7723 # for each tag
7724 0 for my $tag (@tagtab) {
7725
7726 # if tag contains measurement data
7727 0 ▶ if ($tag->[0] =~ m/^(?:CxF |DevD|CIED|DEVD|targ)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag->[0] =~ /^(?:CxF |DevD|CIED|DEVD|targ)$/) 0 0 0
7728
7729 # if a duplicate tag
7730 0 ▶ if (exists($offset{$tag->[1]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $offset{$tag->[1]}) { } 0 0 0
7731
7732 # use original tag
7733 0 $tags{$tag->[0]} = $offset{$tag->[1]};
7734
7735 } else {
7736
7737 # seek to start of tag
7738 0 seek($fh, $tag->[1], 0);
7739
7740 # read tag type signature
7741 0 read($fh, $type, 4);
7742
7743 # convert non-word characters to underscores
7744 0 $type =~ s|\W|_|g;
7745
7746 # form class specifier
7747 0 $class = 'ICC::Profile::' . $type;
7748
7749 # if 'class->new_fh' method exists
7750 0 ▶ if ($class->can('new_fh')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('new_fh')) { } 0 0 0
7751
7752 # create specific tag object
7753 0 $tags{$tag->[0]} = $class->new_fh($self, $fh, $tag);
7754
7755 } else {
7756
7757 # create generic tag object
7758 0 $tags{$tag->[0]} = ICC::Profile::Generic->new_fh($self, $fh, $tag);
7759
7760 }
7761
7762 # save tag in hash
7763 0 $offset{$tag->[1]} = $tags{$tag->[0]};
7764
7765 }
7766
7767 }
7768
7769 }
7770
7771 # if creator is i1Profiler and 'CxF ' tag exists
7772 0 ▶ if ($header[23] eq 'XRCM' && exists($tags{'CxF '})) {
Branch: 4 branches
BranchTrueFalseTotal
if ($header[23] eq 'XRCM' and exists $tags{'CxF '}) { } 0 0 0
elsif ($header[23] eq 'LOGO' and exists $tags{'DevD'} and exists $tags{'CIED'}) { } 0 0 0
elsif ($header[23] eq 'MONS' || $header[1] eq 'mnco' and exists $tags{'DEVD'}) { } 0 0 0
elsif (exists $tags{'targ'}) { } 0 0 0
Condition0%0/3
$header[23] eq "XRCM" and exists $tags{"CxF "}
!ll&&!rl&&r
000
MC/DC0%0/2
$header[23] eq "XRCM" and exists $tags{"CxF "}
$header[23] eq "XRCM" exists $tags{"CxF "}
Truth table0%0/3
A and B
A= $header[23] eq "XRCM"B= exists $tags{"CxF "}
ABresult
0X0
100
111
7773
7774 # close file handle
7775 0 close($fh);
7776
7777 # open file handle to CxF3 string
7778 0 open($fh, '<', \$tags{'CxF '}->text());
7779
7780 # make chart from CxF3 string
7781 0 return(_readChartCxF3($self, $fh, $hash));
7782
7783 # if creator is ProfileMaker and 'DevD' / 'CIED' tags exist
7784 ▶ } elsif ($header[23] eq 'LOGO' && exists($tags{'DevD'}) && exists($tags{'CIED'})) {
Condition0%0/6
$header[23] eq "LOGO" and exists $tags{"DevD"} and exists $tags{"CIED"}
!ll&&!rl&&r
000
$header[23] eq "LOGO" and exists $tags{"DevD"}
!ll&&!rl&&r
000
MC/DC0%0/3
$header[23] eq "LOGO" and exists $tags{"DevD"} and exists $tags{"CIED"}
$header[23] eq "LOGO" exists $tags{"DevD"} exists $tags{"CIED"}
Truth table0%0/4
A and B and C
A= $header[23] eq "LOGO"B= exists $tags{"DevD"}C= exists $tags{"CIED"}
ABCresult
0XX0
10X0
1100
1111
7785
7786 # close file handle
7787 0 close($fh);
7788
7789 # open file handle to 'DevD' text string
7790 0 open($fh, '<', \$tags{'DevD'}->text());
7791
7792 # read chart from text
7793 0 ▶ ($result = _readChartASCII($self, $fh, $hash)) && return("failed reading ICC profile DEVD tag, $result");
Branch: 1 branch
BranchTrueFalseTotal
$result = _readChartASCII($self, $fh, $hash) and return "failed reading ICC profile DEVD tag, $result" 0 0 0
7794
7795 # close file handle
7796 0 close($fh);
7797
7798 # make temporary chart object
7799 0 $temp = ICC::Support::Chart->new();
7800
7801 # open file handle to 'CIED' text string
7802 0 open($fh, '<', \$tags{'CIED'}->text());
7803
7804 # read chart from text
7805 0 ▶ ($result = _readChartASCII($temp, $fh, $hash)) && return("failed reading ICC profile CIED tag, $result");
Branch: 1 branch
BranchTrueFalseTotal
$result = _readChartASCII($temp, $fh, $hash) and return "failed reading ICC profile CIED tag, $result" 0 0 0
7806
7807 # get data slice (all rows, spectral, XYZ and L*a*b* columns)
7808 0 $data = slice($temp, [0 .. $#{$temp->[1]}], [grep {$temp->[1][0][$_] =~ m/^(nm\d{3}|XYZ_(X|Y|Z)|LAB_(L|A|B))$/} (0 .. $#{$temp->[1][0]})]);
7809
7810 # append to chart
7811 0 add_cols($self, $data);
7812
7813 # for each keyword
7814 0 for my $key (@{$temp->[3]}) {
7815
7816 # if keyword not in main chart
7817 0 ▶ if (0 == grep {$key->[0] eq $_->[0]} @{$self->[3]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 == grep({$key->[0] eq $_->[0];} @{$$self[3];})) 0 0 0
7818
7819 # append keyword/value
7820 0 push(@{$self->[3]}, $key);
7821
7822 }
7823
7824 }
7825
7826 # return
7827 0 return();
7828
7829 # if creator is Monaco and 'DEVD' tag exists (some old profiles are identified by preferred CMM)
7830 ▶ } elsif (($header[23] eq 'MONS' || $header[1] eq 'mnco') && exists($tags{'DEVD'})) {
Condition0%0/6
$header[23] eq "MONS" || $header[1] eq "mnco" and exists $tags{"DEVD"}
!ll&&!rl&&r
000
$header[23] eq "MONS" or $header[1] eq "mnco"
l!l&&r!l&&!r
000
MC/DC0%0/3
$header[23] eq "MONS" || $header[1] eq "mnco" and exists $tags{"DEVD"}
$header[23] eq "MONS" $header[1] eq "mnco" exists $tags{"DEVD"}
Truth table0%0/5
A or B and C
A= $header[23] eq "MONS"B= $header[1] eq "mnco"C= exists $tags{"DEVD"}
ABCresult
00X0
1X00
0100
1X11
0111
7831
7832 # read chart from Monaco 'DEVD' tag
7833 0 return(_readMonacoDEVD($self, $tags{'DEVD'}->data(), \@header));
7834
7835 # if 'targ' tag exists
7836 } elsif (exists($tags{'targ'})) {
7837
7838 # get 'targ' tag text string
7839 0 $text = $tags{'targ'}->text();
7840
7841 # if reference to ICC Characterization Data Registry
7842 0 ▶ if ($text =~ m/^ICCHDAT (.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^ICCHDAT (.*)$/) { } 0 0 0
7843
7844 # return
7845 0 return("profile derived from $1 characterization data, available at www.color.org");
7846
7847 } else {
7848
7849 # close file handle
7850 0 close($fh);
7851
7852 # open file handle to text string
7853 0 open($fh, '<', \$text);
7854
7855 # read chart from text
7856 0 return(_readChartASCII($self, $fh, $hash));
7857
7858 }
7859
7860 }
7861  
7862 # return
7863 0 return('failed reading ICC profile characterization data');
7864  
7865 }
7866  
7867 # read chart from Monaco 'DEVD' tag
7868 # parameters: (object_reference, tag_data, profile_header)
7869 # returns: (result)
7870 sub _readMonacoDEVD {
7871  
7872 # get parameters
7873 0 ▶ my ($self, $data, $header) = @_;
Subroutine _readMonacoDEVD: not called CC=44 SCAR=75.9
7874  
7875 # local variables
7876 0 my ($big, %cshash, $cs, $nc, $fix, $ix, $tag, $tac, $limit, $mult, $dev, $lab);
7877 0 my ($ns, $sec, @devfix, @nd, $nt, @devstep, @dev, @cmy, @sum, @temp, $m, @dat);
7878  
7879 # get big-endian flag (true if our system is big-endian)
7880 0 $big = ($Config{'byteorder'} =~ m/4321/);
7881  
7882 # colorspace hash (colorspace => number_channels)
7883 0 %cshash = ('RGB ' => 3, 'CMYK' => 4, '5CLR' => 5, '6CLR' => 6, '7CLR' => 7, '8CLR' => 8);
7884  
7885 # initialize fixed value array
7886 0 @devfix = ();
7887  
7888 # get colorspace from profile header
7889 0 $cs = $header->[4];
7890  
7891 # lookup number of channels
7892 0 $nc = $cshash{$cs};
7893  
7894 # set number of fixed channels
7895 0 $fix = $nc - 3;
7896  
7897 # set index to start of first tag
7898 0 $ix = 28;
7899  
7900 # set tag value
7901 0 $tag = pack('N', 0x002D);
7902  
7903 # find TAC tag
7904 0 ▶ do {$ix = index($data, $tag, $ix)} while ($ix >= 0 && $ix % 4 && $ix++);
Branch: 1 branch
BranchTrueFalseTotal
$ix >= 0 and $ix % 4 and $ix++ and do { do { $ix = index($data, $tag, $ix) } } 0 0 0
Condition0%0/6
$ix >= 0 and $ix % 4 and $ix++
!ll&&!rl&&r
000
$ix >= 0 and $ix % 4
!ll&&!rl&&r
000
MC/DC0%0/3
$ix >= 0 and $ix % 4 and $ix++
$ix >= 0 $ix % 4 $ix++
Truth table0%0/4
A and B and C
A= $ix >= 0B= $ix % 4C= $ix++
ABCresult
0XX0
10X0
1100
1111
7905  
7906 # verify tag found
7907 0 ▶ ($ix >= 0) || return('failed reading TAC from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
$ix >= 0 or return "failed reading TAC from Monaco DEVD tag" 0 0 0
7908  
7909 # get TAC value
7910 0 ▶ $tac = 100 * unpack('d', $big ? substr($data, $ix + 4, 8) : reverse(substr($data, $ix + 4, 8)));
Branch: 1 branch
BranchTrueFalseTotal
$big ? : 0 0 0
7911  
7912 # if RGB colorspace
7913 0 ▶ if ($cs eq 'RGB ') {
Branch: 2 branches
BranchTrueFalseTotal
if ($cs eq 'RGB ') { } 0 0 0
elsif ($cs eq 'CMYK') { } 0 0 0
7914
7915 # add device fields
7916 0 $dev = add_fmt($self, qw(RGB_R RGB_G RGB_B));
7917
7918 # set device multiplier
7919 0 $mult = 255;
7920
7921 # if CMYK colorspace
7922 } elsif ($cs eq 'CMYK') {
7923
7924 # add device fields
7925 0 $dev = add_fmt($self, qw(CMYK_C CMYK_M CMYK_Y CMYK_K));
7926
7927 # set device multiplier
7928 0 $mult = 100;
7929
7930 } else {
7931
7932 # add device fields
7933 0 $dev = add_fmt($self, map {"$cs\_$_"} (1 .. $nc));
7934
7935 # set device multiplier
7936 0 $mult = 100;
7937
7938 }
7939  
7940 # add L*a*b* fields
7941 0 $lab = add_fmt($self, qw(LAB_L LAB_A LAB_B));
7942  
7943 # advance index
7944 0 $ix += 12;
7945  
7946 # set tag value
7947 0 $tag = pack('N', 0x0027);
7948  
7949 # find data group tag
7950 0 ▶ do {$ix = index($data, $tag, $ix)} while ($ix >= 0 && $ix % 4 && $ix++);
Branch: 1 branch
BranchTrueFalseTotal
$ix >= 0 and $ix % 4 and $ix++ and do { do { $ix = index($data, $tag, $ix) } } 0 0 0
Condition0%0/6
$ix >= 0 and $ix % 4 and $ix++
!ll&&!rl&&r
000
$ix >= 0 and $ix % 4
!ll&&!rl&&r
000
MC/DC0%0/3
$ix >= 0 and $ix % 4 and $ix++
$ix >= 0 $ix % 4 $ix++
Truth table0%0/4
A and B and C
A= $ix >= 0B= $ix % 4C= $ix++
ABCresult
0XX0
10X0
1100
1111
7951  
7952 # verify tag found
7953 0 ▶ ($ix >= 0) || return('failed reading data group from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
$ix >= 0 or return "failed reading data group from Monaco DEVD tag" 0 0 0
7954  
7955 # get number data sections in group
7956 0 $ns = unpack('N', substr($data, $ix + 4, 4));
7957  
7958 # advance index
7959 0 $ix += 8;
7960  
7961 # for data each section
7962 0 for my $s (0 .. $ns - 1) {
7963
7964 # verify tag 0x0028
7965 0 ▶ (substr($data, $ix, 4) eq pack('N', 0x0028)) || return(0);
Branch: 1 branch
BranchTrueFalseTotal
substr($data, $ix, 4) eq "\0\0\0(" or return 0 0 0 0
7966
7967 # get section index
7968 0 $sec = unpack('N', substr($data, $ix + 4, 4));
7969
7970 # verify section index is correct
7971 0 ▶ ($sec == $s) || return('failed reading section index from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
$sec == $s or return "failed reading section index from Monaco DEVD tag" 0 0 0
7972
7973 # advance index
7974 0 $ix += 8;
7975
7976 # verify tag 0x002A (fixed device values)
7977 0 ▶ (substr($data, $ix, 4) eq pack('N', 0x002A)) || return('failed reading fixed device values from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
substr($data, $ix, 4) eq "\0\0\0*" or return "failed reading fixed device values from Monaco DEVD tag" 0 0 0
7978
7979 # if fixed device values (none for RGB)
7980 0 ▶ if ($fix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fix) 0 0 0
7981
7982 # get fixed device values (black plus any extra colors, e.g. orange or green)
7983 0 ▶ @devfix = unpack("d$fix", $big ? substr($data, $ix + 4, 8 * $fix) : reverse(substr($data, $ix + 4, 8 * $fix)));
Branch: 1 branch
BranchTrueFalseTotal
$big ? : 0 0 0
7984
7985 # reverse array if little-endian
7986 0 ▶ @devfix = reverse(@devfix) if (! $big);
Branch: 1 branch
BranchTrueFalseTotal
unless $big 0 0 0
7987
7988 # apply multiplier
7989 0 @devfix = map {$_ * $mult} @devfix;
7990
7991 }
7992
7993 # advance index
7994 0 $ix += 8 * $fix + 4;
7995
7996 # verify tag 0x002B (step counts by color)
7997 0 ▶ (substr($data, $ix, 4) eq pack('N', 0x002B)) || return('failed reading step counts from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
substr($data, $ix, 4) eq "\0\0\0+" or return "failed reading step counts from Monaco DEVD tag" 0 0 0
7998
7999 # get device step counts
8000 0 @nd = unpack('N3', substr($data, $ix + 4, 12));
8001
8002 # get total number of steps
8003 0 $nt = $nd[0] + $nd[1] + $nd[2];
8004
8005 # advance index
8006 0 $ix += 16;
8007
8008 # verify tag 0x002C (step values by color)
8009 0 ▶ (substr($data, $ix, 4) eq pack('N', 0x002C)) || return('failed reading step values from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
substr($data, $ix, 4) eq "\0\0\0," or return "failed reading step values from Monaco DEVD tag" 0 0 0
8010
8011 # get step values
8012 0 ▶ @devstep = unpack("d$nt", $big ? substr($data, $ix + 4, 8 * $nt) : reverse(substr($data, $ix + 4, 8 * $nt)));
Branch: 1 branch
BranchTrueFalseTotal
$big ? : 0 0 0
8013
8014 # reverse array if little-endian
8015 0 ▶ @devstep = reverse(@devstep) if (! $big);
Branch: 1 branch
BranchTrueFalseTotal
unless $big 0 0 0
8016
8017 # apply multiplier
8018 0 @devstep = map {$_ * $mult} @devstep;
8019
8020 # advance index
8021 0 $ix += 8 * $nt + 4;
8022
8023 # initialize arrays
8024 0 @dev = ();
8025 0 @sum = ();
8026 0 @temp = ();
8027
8028 # if RGB colorspace
8029 0 ▶ if ($cs eq 'RGB ') {
Branch: 1 branch
BranchTrueFalseTotal
if ($cs eq 'RGB ') { } 0 0 0
8030
8031 # for each blue step
8032 0 for my $i (0 .. $nd[2] - 1) {
8033
8034 # for each green step
8035 0 for my $j (0 .. $nd[1] - 1) {
8036
8037 # for each red step
8038 0 for my $k (0 .. $nd[0] - 1) {
8039
8040 # save RGB values
8041 0 push(@dev, $devstep[$k], $devstep[$j + $nd[0]], $devstep[$i + $nd[0] + $nd[1]]);
8042
8043 }
8044
8045 }
8046
8047 }
8048
8049 # if CMYK or NCLR colorspace
8050 } else {
8051
8052 # for each yellow step
8053 0 for my $i (0 .. $nd[2] - 1) {
8054
8055 # for each cyan step
8056 0 for my $j (0 .. $nd[0] - 1) {
8057
8058 # for each magenta step
8059 0 for my $k (0 .. $nd[1] - 1) {
8060
8061 # get CMY values
8062 0 @cmy = ($devstep[$j], $devstep[$k + $nd[0]], $devstep[$i + $nd[0] + $nd[1]]);
8063
8064 # save CMY values
8065 0 push(@temp, [@cmy]);
8066
8067 # save total ink value
8068 0 push(@sum, List::Util::sum(@cmy, @devfix));
8069
8070 }
8071
8072 }
8073
8074 }
8075
8076 # initialize actual ink limit
8077 0 $limit = $nc * 100;
8078
8079 # find actual ink limit (smallest value greater than TAC)
8080 0 ▶ for (@sum) {$limit = $_ if ($_ > $tac && $_ < $limit)};
Branch: 1 branch
BranchTrueFalseTotal
if $_ > $tac and $_ < $limit 0 0 0
Condition0%0/3
$_ > $tac and $_ < $limit
!ll&&!rl&&r
000
MC/DC0%0/2
$_ > $tac and $_ < $limit
$_ > $tac $_ < $limit
Truth table0%0/3
A and B
A= $_ > $tacB= $_ < $limit
ABresult
0X0
100
111
8081
8082 # for each sample
8083 0 for my $i (0 .. $#sum) {
8084
8085 # get cmy values
8086 0 @cmy = @{$temp[$i]};
8087
8088 # if sample within ink limit, or a corner point
8089 0 ▶ if ($sum[$i] <= $limit || ((0 < grep {$_ == 0} @cmy) && (0 < grep {$_ == 100} @cmy))) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sum[$i] <= $limit or 0 < grep({$_ == 0;} @cmy) and 0 < grep({$_ == 100;} @cmy)) 0 0 0
Condition0%0/6
$sum[$i] <= $limit or 0 < grep({$_ == 0;} @cmy) and 0 < grep({$_ == 100;} @cmy)
l!l&&r!l&&!r
000
0 < grep({$_ == 0;} @cmy) and 0 < grep({$_ == 100;} @cmy)
!ll&&!rl&&r
000
MC/DC0%0/3
$sum[$i] <= $limit or 0 < grep({$_ == 0;} @cmy) and 0 < grep({$_ == 100;} @cmy)
$sum[$i] <= $limit 0 < grep({$_ == 0;} @cmy) 0 < grep({$_ == 100;} @cmy)
Truth table0%0/4
A or B and C
A= $sum[$i] <= $limitB= 0 < grep({$_ == 0;} @cmy)C= 0 < grep({$_ == 100;} @cmy)
ABCresult
1XX1
0111
00X0
0100
8090
8091 # copy cmy values
8092 0 push(@dev, @cmy);
8093
8094 }
8095
8096 }
8097
8098 }
8099
8100 # verify tag 0x0032 (L*a*b* sample data)
8101 0 ▶ (substr($data, $ix, 4) eq pack('N', 0x0032)) || return('failed reading L*a*b* data from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
substr($data, $ix, 4) eq "\0\0\0002" or return "failed reading L*a*b* data from Monaco DEVD tag" 0 0 0
8102
8103 # get number of values
8104 0 $m = unpack('N', substr($data, $ix + 4, 4)) * 3;
8105
8106 # get L*a*b* color data
8107 0 ▶ @dat = unpack("d$m", $big ? substr($data, $ix + 8, 8 * $m) : reverse(substr($data, $ix + 8, 8 * $m)));
Branch: 1 branch
BranchTrueFalseTotal
$big ? : 0 0 0
8108
8109 # reverse array if little-endian
8110 0 ▶ @dat = reverse(@dat) if (! $big);
Branch: 1 branch
BranchTrueFalseTotal
unless $big 0 0 0
8111
8112 # advance index
8113 0 $ix += 8 * $m + 8;
8114
8115 # verify @dev and @dat are same size
8116 0 ▶ (scalar(@dev) == scalar(@dat)) || return('failed comparing data counts of Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
scalar @dev == scalar @dat or return "failed comparing data counts of Monaco DEVD tag" 0 0 0
8117
8118 # for each sample (3 values per sample)
8119 0 for my $i (0 .. ($m/3 - 1)) {
8120
8121 # add sample data to object
8122 0 push (@{$self->[1]}, [@dev[($i * 3) .. ($i * 3 + 2)], @devfix, @dat[($i * 3) .. ($i * 3 + 2)]]);
8123
8124 }
8125
8126 # verify tag 0x0029 (end of section)
8127 0 ▶ (substr($data, $ix, 4) eq pack('N', 0x0029)) || return('failed reading section end from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
substr($data, $ix, 4) eq "\0\0\0)" or return "failed reading section end from Monaco DEVD tag" 0 0 0
8128
8129 # advance index
8130 0 $ix += 4;
8131
8132 }
8133  
8134 # verify tag 0x0030 (end of data)
8135 0 ▶ (substr($data, $ix, 4) eq pack('N', 0x0030)) || return('failed reading data end from Monaco DEVD tag');
Branch: 1 branch
BranchTrueFalseTotal
substr($data, $ix, 4) eq "\0\0\0000" or return "failed reading data end from Monaco DEVD tag" 0 0 0
8136  
8137 # add 'CREATED' keyword/value from header date/time
8138 0 push(@{$self->[3]}, ['CREATED', sprintf('%.4d-%.2d-%.2dT%.2d:%.2d:%.2dZ', @{$header}[6 .. 11])]);
8139  
8140 # return
8141 0 return();
8142  
8143 }
8144  
8145 # read chart from SpectraShop (.ss3) file
8146 # parameters: (object_reference, file_handle, hash)
8147 sub _readChartSS3 {
8148  
8149 # get parameters
8150 0 ▶ my ($self, $fh, $hash) = @_;
Subroutine _readChartSS3: not called CC=20 SCAR=60.4
8151  
8152 # local variables
8153 0 my (%fmt, $buf, @data, $notes);
8154 0 my ($meta, $measure, %tally, @keys, $value, $nm);
8155  
8156 # metadata format array (v32)
8157 0 $fmt{'32'} = [
8158 [qw(Identifier_1 SAMPLE_NAME P)],
8159 [qw(Identifier_2 SAMPLE_ID2 P)],
8160 [qw(Identifier_3 SAMPLE_ID3 P)],
8161 [qw(Material MATERIAL P)],
8162 [qw(Manufacturer MANUFACTURER P)],
8163 [qw(Model MODEL P)],
8164 [qw(Serial_Number SERIAL_NUMBER P)],
8165 [qw(Production_Date PROD_DATE P)],
8166 [qw(Surface SURFACE P)],
8167 [qw(Originator ORIGINATOR P)],
8168 [qw(Creation_Date CREATED P)],
8169 [qw(Comments NOTE P)],
8170 [qw(Instrument INSTRUMENTATION P)],
8171 [qw(Spectrum_Type SPECTRUM_TYPE n), [qw(Emissive-light Emissive-monitor Observer Reflective Transmissive)]],
8172 [qw(Filter MEASUREMENT_FILTER P)],
8173 [qw(Geometry MEASUREMENT_GEOMETRY P)],
8174 [qw(Aperture MEASUREMENT_APERTURE P)],
8175 [qw(Data_Reference DATA_REFERENCE P)],
8176 [qw(Illuminant MEASUREMENT_SOURCE P)],
8177 [qw(Backing SAMPLE_BACKING P)],
8178 [qw(Measurements NSAMPLES n)],
8179 [qw(Notes ACQUIRE_NOTE P)],
8180 ];
8181  
8182 # metadata format array (v50)
8183 0 $fmt{'50'} = [
8184 [qw(Identifier_1 SAMPLE_NAME P)],
8185 [qw(Identifier_2 SAMPLE_ID2 P)],
8186 [qw(Identifier_3 SAMPLE_ID3 P)],
8187 [qw(Material MATERIAL P)],
8188 [qw(Manufacturer MANUFACTURER P)],
8189 [qw(Model MODEL P)],
8190 [qw(Serial_Number SERIAL_NUMBER P)],
8191 [qw(Production_Date PROD_DATE P)],
8192 [qw(Surface SURFACE P)],
8193 [qw(Originator ORIGINATOR P)],
8194 [qw(Creation_Date CREATED P)],
8195 [qw(Comments NOTE P)],
8196 [qw(Instrument INSTRUMENTATION P)],
8197 [qw(Serial_Number INSTRUMENT_SERIAL_NUMBER P)],
8198 [qw(Spectrum_Type SPECTRUM_TYPE n), [qw(Emissive-light Emissive-monitor Observer Reflective Transmissive)]],
8199 [qw(Filter MEASUREMENT_FILTER P)],
8200 [qw(Geometry MEASUREMENT_GEOMETRY P)],
8201 [qw(Aperture MEASUREMENT_APERTURE P)],
8202 [qw(Data_Reference DATA_REFERENCE P)],
8203 [qw(Illuminant MEASUREMENT_SOURCE P)],
8204 [qw(Backing SAMPLE_BACKING P)],
8205 [qw(Measurements NSAMPLES n)],
8206 [qw(Notes ACQUIRE_NOTE P)],
8207 ];
8208  
8209 # read version, samples, Collection Notes length
8210 0 read($fh, $buf, 7);
8211  
8212 # unpack
8213 0 @data = unpack('nx2nC', $buf);
8214  
8215 # read Collection Notes string
8216 0 read($fh, $notes, $data[2]);
8217  
8218 # for each sample
8219 0 for my $i (0 .. ($data[1] - 1)) {
8220
8221 # for each metadata field
8222 0 for my $j (0 .. $#{$fmt{$data[0]}}) {
8223
8224 # if a Pascal string
8225 0 ▶ if ($fmt{$data[0]}[$j][2] eq 'P') {
Branch: 2 branches
BranchTrueFalseTotal
if ($fmt{$data[0]}[$j][2] eq 'P') { } 0 0 0
elsif ($fmt{$data[0]}[$j][2] eq 'n') { } 0 0 0
8226
8227 # read string length
8228 0 read($fh, $buf, 1);
8229
8230 # read string
8231 0 read($fh, $meta->[$i][$j], unpack('C', $buf));
8232
8233 # if an unsigned short integer
8234 } elsif ($fmt{$data[0]}[$j][2] eq 'n') {
8235
8236 # read short integer
8237 0 read($fh, $buf, 2);
8238
8239 # unpack
8240 0 $meta->[$i][$j] = unpack('n', $buf);
8241
8242 }
8243
8244 }
8245
8246 # read wavelength parameters (start, end, increment, count)
8247 0 read($fh, $buf, 8);
8248
8249 # unpack (unsigned short integer)
8250 0 $measure->[$i][0] = [unpack('n4', $buf)];
8251
8252 # for each wavelength
8253 0 for my $j (1 .. $measure->[$i][0][3]) {
8254
8255 # read measurements (avg, low, high, std_dev)
8256 0 read($fh, $buf, 16);
8257
8258 # unpack (32-bit float, big endian)
8259 0 $measure->[$i][$j] = [unpack('(f4)>', $buf)];
8260
8261 }
8262
8263 }
8264  
8265 # add Collection Notes to header line array, if not null string
8266 0 ▶ push(@{$self->[3]}, ['FILE_DESCRIPTOR', "\"$notes\""]) if (length($notes));
Branch: 1 branch
BranchTrueFalseTotal
if length $notes 0 0 0
8267  
8268 # for each metadata field
8269 0 for my $j (0 .. $#{$meta->[0]}) {
8270
8271 # init hash
8272 0 %tally = ();
8273
8274 # for each sample
8275 0 for my $i (0 .. $#{$meta}) {
8276
8277 # increment hash value
8278 0 $tally{$meta->[$i][$j]}++;
8279
8280 }
8281
8282 # get hash keys
8283 0 @keys = keys(%tally);
8284
8285 # if one hash key
8286 0 ▶ if (@keys == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys == 1) { } 0 0 0
8287
8288 # if not the null string
8289 0 ▶ if (length($keys[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $keys[0]) 0 0 0
8290
8291 # if value is string
8292 0 ▶ if ($fmt{$data[0]}[$j][2] eq 'P') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt{$data[0]}[$j][2] eq 'P') { } 0 0 0
8293
8294 # wrap in quotes
8295 0 $value = "\"$keys[0]\"";
8296
8297 } else {
8298
8299 # if value is an enumeration
8300 0 ▶ if (defined($fmt{$data[0]}[$j][3])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fmt{$data[0]}[$j][3]) { } 0 0 0
8301
8302 # look up enumerated value and wrap in quotes
8303 0 $value = "\"$fmt{$data[0]}[$j][3][$keys[0]]\"";
8304
8305 } else {
8306
8307 # use value as-is
8308 0 $value = $keys[0];
8309
8310 }
8311
8312 }
8313
8314 # add KEYWORD/VALUE to header line array
8315 0 push(@{$self->[3]}, [$fmt{$data[0]}[$j][1], $value]);
8316
8317 }
8318
8319 } else {
8320
8321 # add keyword to DATA_FORMAT array
8322 0 push(@{$self->[1][0]}, $fmt{$data[0]}[$j][1]);
8323
8324 # for each sample
8325 0 for my $i (0 .. $#{$meta}) {
8326
8327 # if value is an enumeration
8328 0 ▶ if (defined($fmt{$data[0]}[$j][3])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fmt{$data[0]}[$j][3]) { } 0 0 0
8329
8330 # look up enumerated value
8331 0 $value = $fmt{$data[0]}[$j][3][$meta->[$i][$j]];
8332
8333 } else {
8334
8335 # use value as-is
8336 0 $value = $meta->[$i][$j];
8337
8338 }
8339
8340 # add value to DATA array
8341 0 push(@{$self->[1][$i + 1]}, $meta->[$i][$j]);
8342
8343 }
8344
8345 }
8346
8347 }
8348  
8349 # for each wavelength parameter (start, end, increment, count)
8350 0 for my $j (0 .. 3) {
8351
8352 # init hash
8353 0 %tally = ();
8354
8355 # for each sample
8356 0 for my $i (0 .. $#{$measure}) {
8357
8358 # increment hash value
8359 0 $tally{$measure->[$i][0][$j]}++;
8360
8361 }
8362
8363 # get hash keys
8364 0 @keys = keys(%tally);
8365
8366 # verify all samples have same wavelength parameter value
8367 0 ▶ (@keys == 1) || return('samples have varied spectral range');
Branch: 1 branch
BranchTrueFalseTotal
@keys == 1 or return "samples have varied spectral range" 0 0 0
8368
8369 }
8370  
8371 # for each wavelength
8372 0 for my $j (0 .. ($#{$measure->[0]} - 1)) {
8373
8374 # compute wavelength from start and increment values
8375 0 $nm = $measure->[0][0][0] + $j * $measure->[0][0][2];
8376
8377 # add keyword to DATA_FORMAT array
8378 0 push(@{$self->[1][0]}, "nm$nm");
8379
8380 # for each sample
8381 0 for my $i (0 .. $#{$measure}) {
8382
8383 # add average measurement to DATA array
8384 0 push(@{$self->[1][$i + 1]}, $measure->[$i][$j + 1][0]);
8385
8386 }
8387
8388 }
8389  
8390 # return
8391 0 return();
8392  
8393 }
8394  
8395 # read data from TIFF file
8396 # RGB, CMYK, and CIE L*a*b* color spaces supported
8397 # 8-bit, 16-bit or 32-bit, Intel or Motorola byte order supported
8398 # alpha and spot channels in RGB and CMYK files supported
8399 # optional hash keys: 'rows', 'columns', 'crop', 'ratio', 'aperture', 'udf', 'format'
8400 # default 'rows' and 'columns' are taken from image size, default 'ratio' is 0.5
8401 # 'crop' is an array containing the left, right, upper and lower crop values in pixels
8402 # 'ratio' is a value between 0 and 1, sample is a single pixel when 'ratio' is 0
8403 # 'aperture' is in millimeters, and take precedence over 'ratio'
8404 # 'udf' is a code reference to a pixel processing function
8405 # 'format' is an array reference containing the format fields
8406 # parameters: (object_reference, file_handle, hash)
8407 # returns: (result)
8408 sub _readChartTIFF {
8409  
8410 # get parameters
8411 0 ▶ my ($self, $fh, $hash) = @_;
Subroutine _readChartTIFF: not called CC=91 SCAR=90.3
8412  
8413 # local variables
8414 0 my ($buf, $short, $long, $fp, @header, $tags);
8415 0 my ($cols, $rows, $bits, $pi, $samples);
8416 0 my ($context, $fmt, $upf, $udf, $dev, $div, $dab);
8417 0 my ($trows, $tcols, $crop, $roff, $coff);
8418 0 my ($res, $size, $frac, $ratio, $rxo, $cxo, $pixels, $width);
8419 0 my ($lower, $upper, $left, $right, $band, $pval, @data, @pix);
8420  
8421 # read the header
8422 0 read($fh, $buf, 8);
8423  
8424 # if big-endian (Motorola)
8425 0 ▶ if (substr($buf, 0, 2) eq 'MM') {
Branch: 2 branches
BranchTrueFalseTotal
if (substr($buf, 0, 2) eq 'MM') { } 0 0 0
elsif (substr($buf, 0, 2) eq 'II') { } 0 0 0
8426
8427 # set 'unpack' formats
8428 0 $short = 'n';
8429 0 $long = 'N';
8430 0 $fp = 'f>'; # might not be IEEE FP on some platforms
8431
8432 # if little-endian (Intel)
8433 } elsif (substr($buf, 0, 2) eq 'II'){
8434
8435 # set 'unpack' formats
8436 0 $short = 'v';
8437 0 $long = 'V';
8438 0 $fp = 'f<'; # might not be IEEE FP on some platforms
8439
8440 } else {
8441
8442 # error
8443 0 return('TIFF byte order incorrect');
8444
8445 }
8446  
8447 # unpack the header
8448 0 @header = unpack("A2 $short $long", $buf);
8449  
8450 # verify file signature
8451 0 ▶ ($header[1] == 42) || return('TIFF file signature incorrect');
Branch: 1 branch
BranchTrueFalseTotal
$header[1] == 42 or return "TIFF file signature incorrect" 0 0 0
8452  
8453 # read TIFF image file directory (IFD)
8454 0 $tags = _readTIFFdir($fh, $header[2], $short, $long);
8455  
8456 # verify compression (1 = uncompressed)
8457 0 ▶ ($tags->{'259'}[0] == 1) || return('TIFF compression unsupported');
Branch: 1 branch
BranchTrueFalseTotal
$tags->{259}[0] == 1 or return "TIFF compression unsupported" 0 0 0
8458  
8459 # verify orientation (1 = normal)
8460 0 ▶ (! exists($tags->{'274'}) || $tags->{'274'}[0] == 1) || warn('TIFF orientation rotated and/or flipped');
Branch: 1 branch
BranchTrueFalseTotal
not exists $tags->{274} or $tags->{274}[0] == 1 or warn "TIFF orientation rotated and/or flipped" 0 0 0
Condition0%0/3
not exists $tags->{274} or $tags->{274}[0] == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $tags->{274} or $tags->{274}[0] == 1
not exists $tags->{274} $tags->{274}[0] == 1
Truth table0%0/3
not(A) or B
A= not exists $tags->{274}B= $tags->{274}[0] == 1
ABresult
1X1
011
000
8461  
8462 # verify planar configuration (1 = chunky)
8463 0 ▶ (! exists($tags->{'284'}) || $tags->{'284'}[0] == 1) || return('TIFF planar configuration unsupported');
Branch: 1 branch
BranchTrueFalseTotal
not exists $tags->{284} or $tags->{284}[0] == 1 or return "TIFF planar configuration unsupported" 0 0 0
Condition0%0/3
not exists $tags->{284} or $tags->{284}[0] == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $tags->{284} or $tags->{284}[0] == 1
not exists $tags->{284} $tags->{284}[0] == 1
Truth table0%0/3
not(A) or B
A= not exists $tags->{284}B= $tags->{284}[0] == 1
ABresult
1X1
011
000
8464  
8465 # verify not tiled
8466 0 ▶ (! exists($tags->{'322'})) || return('TIFF tiled layout unsupported');
Branch: 1 branch
BranchTrueFalseTotal
exists $tags->{322} and return "TIFF tiled layout unsupported" 0 0 0
8467  
8468 # get TIFF columns (width)
8469 0 $cols = $tags->{'256'}[0];
8470  
8471 # get TIFF rows (length)
8472 0 $rows = $tags->{'257'}[0];
8473  
8474 # get TIFF bits per sample
8475 0 $bits = $tags->{'258'}[0];
8476  
8477 # verify bits per sample
8478 0 ▶ ($bits == 8 || $bits == 16 || $bits == 32) || return('TIFF bits per sample unsupported');
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 or $bits == 16 or $bits == 32 or return "TIFF bits per sample unsupported" 0 0 0
Condition0%0/6
$bits == 8 or $bits == 16 or $bits == 32
l!l&&r!l&&!r
000
$bits == 8 or $bits == 16
l!l&&r!l&&!r
000
MC/DC0%0/3
$bits == 8 or $bits == 16 or $bits == 32
$bits == 8 $bits == 16 $bits == 32
Truth table0%0/4
A or B or C
A= $bits == 8B= $bits == 16C= $bits == 32
ABCresult
1XX1
01X1
0011
0000
8479  
8480 # get the photometric interpretation
8481 0 $pi = $tags->{'262'}[0];
8482  
8483 # if 32-bits per sample
8484 0 ▶ if ($bits == 32) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bits == 32) 0 0 0
8485
8486 # verify 32-bit IEEE FP format, RGB image
8487 0 ▶ ($tags->{'339'}[0] == 3 && $pi == 2) || return('TIFF format unsupported');
Branch: 1 branch
BranchTrueFalseTotal
$tags->{339}[0] == 3 and $pi == 2 or return "TIFF format unsupported" 0 0 0
Condition0%0/3
$tags->{339}[0] == 3 and $pi == 2
!ll&&!rl&&r
000
MC/DC0%0/2
$tags->{339}[0] == 3 and $pi == 2
$tags->{339}[0] == 3 $pi == 2
Truth table0%0/3
A and B
A= $tags->{339}[0] == 3B= $pi == 2
ABresult
0X0
100
111
8488
8489 }
8490  
8491 # get TIFF samples per pixel
8492 0 $samples = $tags->{'277'}[0];
8493  
8494 # verify bits per sample array
8495 0 ▶ ($samples == grep {$_ == $bits} @{$tags->{'258'}}) || return('TIFF image structure unsupported');
Branch: 1 branch
BranchTrueFalseTotal
$samples == grep({$_ == $bits;} @{$$tags{258};}) or return "TIFF image structure unsupported" 0 0 0
8496  
8497 # get context (if any)
8498 0 $context = $hash->{'context'};
8499  
8500 # get user defined function (if any)
8501 0 $udf = $hash->{'udf'};
8502  
8503 # verify UDF is a code reference
8504 0 ▶ (ref($udf) eq 'CODE') || return('UDF not a code reference') if (defined($udf));
Branch: 1 branch
BranchTrueFalseTotal
if defined $udf 0 0 0
Condition0%0/5
defined $udf && (ref $udf eq 'CODE' || (return 'UDF not a code reference'))
!ll&&!rl&&r
000
ref $udf eq "CODE" or return "UDF not a code reference"
l!l
00
MC/DC0%0/2
defined $udf && (ref $udf eq 'CODE' || (return 'UDF not a code reference'))
defined $udf ref $udf eq "CODE"
Truth table0%0/3
A && B
A= defined $udfB= ref $udf eq "CODE"
ABresult
0X0
100
111
8505  
8506 # set device value divisor
8507 0 ▶ $dev = ($bits == 8) ? 255 : 65535;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
8508  
8509 # add fields for udf (if any)
8510 0 ▶ $fmt = add_fmt($self, map {defined($context) ? "$context|$_" : $_} @{$hash->{'format'}}) if defined($hash->{'format'});
Branch: 2 branches
BranchTrueFalseTotal
if defined $hash->{"format"} 0 0 0
defined $context ? : 0 0 0
8511  
8512 # if RGB file
8513 0 ▶ if ($pi == 2 && $samples < 13) {
Branch: 4 branches
BranchTrueFalseTotal
if ($pi == 2 and $samples < 13) { } 0 0 0
elsif ($pi == 5 and $samples == 4) { } 0 0 0
elsif ($pi == 5 and $samples > 4 and $samples < 16) { } 0 0 0
elsif ($pi == 8 and $samples == 3) { } 0 0 0
Condition0%0/3
$pi == 2 and $samples < 13
!ll&&!rl&&r
000
MC/DC0%0/2
$pi == 2 and $samples < 13
$pi == 2 $samples < 13
Truth table0%0/3
A and B
A= $pi == 2B= $samples < 13
ABresult
0X0
100
111
8514
8515 # add RGB and ALPHA fields, if not already defined
8516 0 ▶ $fmt = add_fmt($self, map {defined($context) ? "$context|$_" : $_} (qw(RGB_R RGB_G RGB_B), map {"RGB_A$_"} (1 .. $samples - 3))) if (! defined($fmt));
Branch: 2 branches
BranchTrueFalseTotal
unless defined $fmt 0 0 0
defined $context ? : 0 0 0
8517
8518 # set unpack format (8, 16 or 32 bits)
8519 0 ▶ $upf = ($bits == 8) ? 'C*' : ($bits == 16) ? "$short*" : "$fp*";
Branch: 2 branches
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
$bits == 16 ? : 0 0 0
8520
8521 # set divisor (8, 16 or 32 bits)
8522 0 ▶ $div = ($bits == 8) ? 1 : ($bits == 16) ? 257 : 1/255;
Branch: 2 branches
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
$bits == 16 ? : 0 0 0
8523
8524 # if CMYK file
8525 ▶ } elsif ($pi == 5 && $samples == 4) {
Condition0%0/3
$pi == 5 and $samples == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$pi == 5 and $samples == 4
$pi == 5 $samples == 4
Truth table0%0/3
A and B
A= $pi == 5B= $samples == 4
ABresult
0X0
100
111
8526
8527 # add CMYK fields, if not already defined
8528 0 ▶ $fmt = add_fmt($self, map {defined($context) ? "$context|$_" : $_} qw(CMYK_C CMYK_M CMYK_Y CMYK_K)) if (! defined($fmt));
Branch: 2 branches
BranchTrueFalseTotal
unless defined $fmt 0 0 0
defined $context ? : 0 0 0
8529
8530 # set unpack format (8 or 16 bits)
8531 0 ▶ $upf = ($bits == 8) ? 'C*' : "$short*";
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
8532
8533 # set divisor (8 or 16 bits)
8534 0 ▶ $div = ($bits == 8) ? 2.55 : 655.35;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
8535
8536 # if nCLR file
8537 ▶ } elsif ($pi == 5 && $samples > 4 && $samples < 16) {
Condition0%0/6
$pi == 5 and $samples > 4 and $samples < 16
!ll&&!rl&&r
000
$pi == 5 and $samples > 4
!ll&&!rl&&r
000
MC/DC0%0/3
$pi == 5 and $samples > 4 and $samples < 16
$pi == 5 $samples > 4 $samples < 16
Truth table0%0/4
A and B and C
A= $pi == 5B= $samples > 4C= $samples < 16
ABCresult
0XX0
10X0
1100
1111
8538
8539 # add nCLR fields, if not already defined
8540 0 ▶ $fmt = add_fmt($self, map {defined($context) ? "$context|$_" : $_} map {sprintf('%xCLR_%x', $samples, $_)} (1 .. $samples)) if (! defined($fmt));
Branch: 2 branches
BranchTrueFalseTotal
unless defined $fmt 0 0 0
defined $context ? : 0 0 0
8541
8542 # set unpack format (8 or 16 bits)
8543 0 ▶ $upf = ($bits == 8) ? 'C*' : "$short*";
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
8544
8545 # set divisor (8 or 16 bits)
8546 0 ▶ $div = ($bits == 8) ? 2.55 : 655.35;
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
8547
8548 # if CIE L*a*b* file
8549 ▶ } elsif ($pi == 8 && $samples == 3) {
Condition0%0/3
$pi == 8 and $samples == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$pi == 8 and $samples == 3
$pi == 8 $samples == 3
Truth table0%0/3
A and B
A= $pi == 8B= $samples == 3
ABresult
0X0
100
111
8550
8551 # add L*a*b* fields, if not already defined
8552 0 ▶ $fmt = add_fmt($self, map {defined($context) ? "$context|$_" : $_} qw(LAB_L LAB_A LAB_B)) if (! defined($fmt));
Branch: 2 branches
BranchTrueFalseTotal
unless defined $fmt 0 0 0
defined $context ? : 0 0 0
8553
8554 # set unpack format (8 or 16 bits)
8555 0 ▶ $upf = ($bits == 8) ? '(Ccc)*' : "$short*";
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
8556
8557 # set divisors (8 or 16 bits)
8558 0 ▶ $div = ($bits == 8) ? 2.55 : 655.35; # L*
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
8559 0 ▶ $dab = ($bits == 8) ? 1 : 256; # a* and b*
Branch: 1 branch
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
8560
8561 } else {
8562
8563 # return error
8564 0 return('TIFF color space unsupported');
8565
8566 }
8567  
8568 # get target rows (could be undefined)
8569 0 $trows = $hash->{'rows'};
8570  
8571 # get target columns (could be undefined)
8572 0 $tcols = $hash->{'columns'};
8573  
8574 # if 'crop' parameter is defined
8575 0 ▶ if (defined($hash->{'crop'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'crop'}) { } 0 0 0
8576
8577 # get crop parameter
8578 0 $crop = $hash->{'crop'};
8579
8580 # verify array reference
8581 0 ▶ (ref($crop) eq 'ARRAY') || return('TIFF crop parameter not an array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $crop eq "ARRAY" or return "TIFF crop parameter not an array reference" 0 0 0
8582
8583 # verify array contains four non-negative integers
8584 0 ▶ (4 == @{$crop} && 4 == grep {$_ == int($_) && $_ >= 0} @{$crop}) || return('TIFF crop parameter(s) invalid');
Branch: 2 branches
BranchTrueFalseTotal
4 == @{$crop;} and 4 == grep({$_ == int $_ and $_ >= 0;} @{$crop;}) or return "TIFF crop parameter(s) invalid" 0 0 0
$_ == int $_ and $_ >= 0 0 0 0
Condition0%0/3
4 == @{$crop;} and 4 == grep({$_ == int $_ and $_ >= 0;} @{$crop;})
!ll&&!rl&&r
000
MC/DC0%0/2
4 == @{$crop;} and 4 == grep({$_ == int $_ and $_ >= 0;} @{$crop;})
4 == @{$crop;} 4 == grep({$_ == int $_ and $_ >= 0;} @{$crop;})
Truth table0%0/3
A and B
A= 4 == @{$crop;}B= 4 == grep({$_ == int $_ and $_ >= 0;} @{$crop;})
ABresult
0X0
100
111
8585
8586 # adjust rows and columns
8587 0 $rows -= $crop->[2] + $crop->[3];
8588 0 $cols -= $crop->[0] + $crop->[1];
8589
8590 # verify cropped size
8591 0 ▶ ($rows > 0 && $cols > 0) || return('TIFF crop size too small');
Branch: 1 branch
BranchTrueFalseTotal
$rows > 0 and $cols > 0 or return "TIFF crop size too small" 0 0 0
Condition0%0/3
$rows > 0 and $cols > 0
!ll&&!rl&&r
000
MC/DC0%0/2
$rows > 0 and $cols > 0
$rows > 0 $cols > 0
Truth table0%0/3
A and B
A= $rows > 0B= $cols > 0
ABresult
0X0
100
111
8592
8593 # set offset values
8594 0 $roff = $crop->[2];
8595 0 $coff = $crop->[0];
8596
8597 } else {
8598
8599 # set offset values
8600 0 $roff = 0;
8601 0 $coff = 0;
8602
8603 }
8604  
8605 # if aperture is defined in hash
8606 0 ▶ if (defined($hash->{'aperture'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'aperture'}) { } 0 0 0
8607
8608 # compute image resolution
8609 0 $res = $tags->{'283'}[0]/$tags->{'283'}[1];
8610
8611 # convert to lines/mm if resolution unit is inch
8612 0 ▶ $res /= 25.4 if ($tags->{'296'}[0] == 2);
Branch: 1 branch
BranchTrueFalseTotal
if $tags->{296}[0] == 2 0 0 0
8613
8614 # convert to lines/mm if resolution unit is cm
8615 0 ▶ $res /= 10 if ($tags->{'296'}[0] == 3);
Branch: 1 branch
BranchTrueFalseTotal
if $tags->{296}[0] == 3 0 0 0
8616
8617 # if target rows or target columns are defined
8618 0 ▶ if (defined($trows) || defined($tcols)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $trows or defined $tcols) { } 0 0 0
Condition0%0/3
defined $trows or defined $tcols
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $trows or defined $tcols
defined $trows defined $tcols
Truth table0%0/3
A or B
A= defined $trowsB= defined $tcols
ABresult
1X1
011
000
8619
8620 # use image rows if target rows undefined
8621 0 ▶ $trows = $rows if (! defined($trows));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trows 0 0 0
8622
8623 # use image columns if target columns undefined
8624 0 ▶ $tcols = $cols if (! defined($tcols));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tcols 0 0 0
8625
8626 # compute aperture size (diameter in pixels)
8627 0 ($frac, $size) = POSIX::modf(sqrt(ICC::Shared::PI/4) * $res * $hash->{'aperture'});
8628
8629 # if fractional part < 0.25
8630 0 ▶ if ($frac < 0.25) {
Branch: 2 branches
BranchTrueFalseTotal
if ($frac < 0.25) { } 0 0 0
elsif ($frac < 0.75) { } 0 0 0
8631
8632 # set row and column index offsets
8633 0 $rxo = $cxo = $size - 1;
8634
8635 # if fractional part < 0.75
8636 } elsif ($frac < 0.75) {
8637
8638 # set row index offset
8639 0 $rxo = $size - 1;
8640
8641 # set column index offset
8642 0 $cxo = $size;
8643
8644 } else {
8645
8646 # set row and column index offsets
8647 0 $rxo = $cxo = $size;
8648
8649 }
8650
8651 # verify aperture is within sample area
8652 0 ▶ ($rxo <= $rows/$trows && $cxo <= $cols/$tcols) || croak('TIFF aperture exceeds sample area')
Branch: 1 branch
BranchTrueFalseTotal
$rxo <= $rows / $trows and $cxo <= $cols / $tcols or croak("TIFF aperture exceeds sample area") 0 0 0
Condition0%0/3
$rxo <= $rows / $trows and $cxo <= $cols / $tcols
!ll&&!rl&&r
000
MC/DC0%0/2
$rxo <= $rows / $trows and $cxo <= $cols / $tcols
$rxo <= $rows / $trows $cxo <= $cols / $tcols
Truth table0%0/3
A and B
A= $rxo <= $rows / $trowsB= $cxo <= $cols / $tcols
ABresult
0X0
100
111
8653
8654 } else {
8655
8656 # compute aperture area (in pixels)
8657 0 $size = ICC::Shared::PI * ($res * $hash->{'aperture'}/2)**2;
8658
8659 # compute the target rows
8660 0 $trows = int(sqrt($size * $rows/$cols) + 0.5);
8661
8662 # compute the target columns
8663 0 $tcols = int($size/$trows + 0.5);
8664
8665 # set row and column indices (single pixel sample)
8666 0 $rxo = $cxo = 0;
8667
8668 }
8669
8670 } else {
8671
8672 # use image rows if target rows undefined
8673 0 ▶ $trows = $rows if (! defined($trows));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $trows 0 0 0
8674
8675 # use image columns if target columns undefined
8676 0 ▶ $tcols = $cols if (! defined($tcols));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tcols 0 0 0
8677
8678 # get mask ratio (default 0.5)
8679 0 ▶ $ratio = defined($hash->{'ratio'}) ? $hash->{'ratio'} : 0.5;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'ratio'} ? : 0 0 0
8680
8681 # verify mask ratio
8682 0 ▶ ($ratio >= 0 && $ratio <= 1) || croak('TIFF mask ratio < 0 or > 1');
Branch: 1 branch
BranchTrueFalseTotal
$ratio >= 0 and $ratio <= 1 or croak("TIFF mask ratio < 0 or > 1") 0 0 0
Condition0%0/3
$ratio >= 0 and $ratio <= 1
!ll&&!rl&&r
000
MC/DC0%0/2
$ratio >= 0 and $ratio <= 1
$ratio >= 0 $ratio <= 1
Truth table0%0/3
A and B
A= $ratio >= 0B= $ratio <= 1
ABresult
0X0
100
111
8683
8684 # compute row index offset
8685 0 $rxo = int($ratio * $rows/$trows - 0.5);
8686
8687 # compute column index offset
8688 0 $cxo = int($ratio * $cols/$tcols - 0.5);
8689
8690 }
8691  
8692 # warn if large target size
8693 0 ▶ ($trows * $tcols <= 10000) || warn('TIFF target size > 10000 samples');
Branch: 1 branch
BranchTrueFalseTotal
$trows * $tcols <= 10000 or warn "TIFF target size > 10000 samples" 0 0 0
8694  
8695 # compute number of pixels
8696 0 $pixels = ($rxo + 1) * ($cxo + 1);
8697  
8698 # compute row width (bytes)
8699 0 $width = $tags->{'256'}[0] * List::Util::sum(@{$tags->{'258'}})/8;
8700  
8701 # for each target row
8702 0 for my $i (0 .. $trows - 1) {
8703
8704 # compute sample lower row
8705 0 $lower = int(($i + 0.5) * $rows/$trows - $rxo/2) + $roff;
8706
8707 # compute sample upper row
8708 0 $upper = $lower + $rxo;
8709
8710 # get sample band data
8711 0 $band = _readTIFFband($fh, $tags, $lower, $upper, $width, $upf);
8712
8713 # for each target column
8714 0 for my $j (0 .. $tcols - 1) {
8715
8716 # compute sample left column
8717 0 $left = int(($j + 0.5) * $cols/$tcols - $cxo/2) + $coff;
8718
8719 # compute sample right column
8720 0 $right = $left + $cxo;
8721
8722 # initialize data
8723 0 @data = ();
8724
8725 # for each row (band)
8726 0 for my $m (0 .. $#{$band}) {
8727
8728 # for each column
8729 0 for my $n ($left .. $right) {
8730
8731 # get pixel value (all samples)
8732 0 @pix = @{$band->[$m]}[$n * $samples .. ($n + 1) * $samples - 1];
8733
8734 # if 16-bit L*a*b*
8735 0 ▶ if ($pi == 8 && $bits == 16) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pi == 8 and $bits == 16) 0 0 0
Condition0%0/3
$pi == 8 and $bits == 16
!ll&&!rl&&r
000
MC/DC0%0/2
$pi == 8 and $bits == 16
$pi == 8 $bits == 16
Truth table0%0/3
A and B
A= $pi == 8B= $bits == 16
ABresult
0X0
100
111
8736
8737 # adjust a* and b* if pixel value negative (signed 16-bit)
8738 0 ▶ $pix[1] += -65536 if ($pix[1] > 32767);
Branch: 1 branch
BranchTrueFalseTotal
if $pix[1] > 32767 0 0 0
8739 0 ▶ $pix[2] += -65536 if ($pix[2] > 32767);
Branch: 1 branch
BranchTrueFalseTotal
if $pix[2] > 32767 0 0 0
8740
8741 }
8742
8743 # if user defined function provided
8744 0 ▶ if (defined($udf)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $udf) 0 0 0
8745
8746 # if L*a*b* file
8747 0 ▶ if ($pi == 8) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pi == 8) { } 0 0 0
8748
8749 # convert values
8750 0 $pix[0] /= $div;
8751 0 $pix[1] /= $dab;
8752 0 $pix[2] /= $dab;
8753
8754 } else {
8755
8756 # convert to device values
8757 0 @pix = map {$_/$dev} @pix;
8758
8759 # if a CMYK file
8760 0 ▶ if ($pi == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pi == 5) 0 0 0
8761
8762 # for alpha/spot colors (if any)
8763 0 for my $s (4 .. $samples - 1) {
8764
8765 # invert device value
8766 0 $pix[$s] = 1 - $pix[$s];
8767
8768 }
8769
8770 }
8771
8772 }
8773
8774 # call user defined function
8775 0 @pix = &$udf(@pix);
8776
8777 }
8778
8779 # for each channel (may be different from TIFF samples)
8780 0 for my $s (0 .. $#pix) {
8781
8782 # accumulate pixel values
8783 0 $data[$s] += $pix[$s]
8784
8785 }
8786
8787 }
8788
8789 }
8790
8791 # if user defined function provided
8792 0 ▶ if (defined($udf)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $udf) { } 0 0 0
elsif ($pi == 8) { } 0 0 0
8793
8794 # save data in object
8795 0 @{$self->[1][$j * $trows + $i + 1]}[@{$fmt}] = map {$_/$pixels} @data;
8796
8797 # if L*a*b* file
8798 } elsif ($pi == 8) {
8799
8800 # save data in object
8801 0 $self->[1][$j * $trows + $i + 1][$fmt->[0]] = $data[0]/($pixels * $div);
8802 0 $self->[1][$j * $trows + $i + 1][$fmt->[1]] = $data[1]/($pixels * $dab);
8803 0 $self->[1][$j * $trows + $i + 1][$fmt->[2]] = $data[2]/($pixels * $dab);
8804
8805 # all others
8806 } else {
8807
8808 # normalize data values
8809 0 @data = map {$_/($pixels * $div)} @data;
8810
8811 # if a CMYK file
8812 0 ▶ if ($pi == 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pi == 5) 0 0 0
8813
8814 # for alpha/spot colors (if any)
8815 0 for my $s (4 .. $samples - 1) {
8816
8817 # invert %-dot value
8818 0 $data[$s] = 100 - $data[$s];
8819
8820 }
8821
8822 }
8823
8824 # save data in object
8825 0 @{$self->[1][$j * $trows + $i + 1]}[@{$fmt}] = @data;
8826
8827 }
8828
8829 }
8830
8831 }
8832  
8833 # save the tag hash in object header
8834 0 $self->[0]{'TIFF_tag'} = $tags;
8835  
8836 # add LGOROWLENGTH keyword
8837 0 keyword($self, 'LGOROWLENGTH', $trows);
8838  
8839 # return
8840 0 return();
8841  
8842 }
8843  
8844 # read TIFF image file directory (IFD)
8845 # parameters: (file_handle, offset, short_format, long_format)
8846 # returns: (IFD_hash)
8847 sub _readTIFFdir {
8848  
8849 # get parameters
8850 0 ▶ my ($fh, $start, $short, $long) = @_;
Subroutine _readTIFFdir: not called CC=15 SCAR=54.8
8851  
8852 # local variables
8853 0 my (@ts, $buf, $id, $type, $count, $size, $mark, $offset, $num, $denom, $tags);
8854  
8855 # field type size (in bytes)
8856 0 @ts = (0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4);
8857  
8858 # seek start of IFD
8859 0 seek($fh, $start, 0);
8860  
8861 # read number entries
8862 0 read($fh, $buf, 2);
8863  
8864 # read the directory
8865 0 for (1 .. unpack($short, $buf)) {
8866
8867 # read first part of IFD entry
8868 0 read($fh, $buf, 8);
8869
8870 # unpack first three fields (ID, type, count)
8871 0 ($id, $type, $count) = unpack("$short$short$long", $buf);
8872
8873 # read last part of IFD entry
8874 0 read($fh, $buf, 4);
8875
8876 # determine value/offset size (size * count) + (1 if ASCII string)
8877 0 ▶ $size = $ts[$type] * $count + (($type == 2) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$type == 2 ? : 0 0 0
8878
8879 # if an offset
8880 0 ▶ if ($size > 4) {
Branch: 5 branches
BranchTrueFalseTotal
if ($size > 4) { } 0 0 0
elsif ($type == 1 or $type == 7) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
8881
8882 # mark file location
8883 0 $mark = tell($fh);
8884
8885 # unpack offset
8886 0 $offset = unpack($long, $buf);
8887
8888 # seek values
8889 0 seek($fh, $offset, 0);
8890
8891 # if binary string
8892 0 ▶ if ($type == 1 || $type == 7) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type == 1 or $type == 7) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
elsif ($type == 5) { } 0 0 0
Condition0%0/3
$type == 1 or $type == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == 1 or $type == 7
$type == 1 $type == 7
Truth table0%0/3
A or B
A= $type == 1B= $type == 7
ABresult
1X1
011
000
8893
8894 # read binary string
8895 0 read($fh, $buf, $count);
8896
8897 # unpack value
8898 0 $tags->{$id} = [unpack("a$count", $buf)];
8899
8900 # if ASCII string
8901 } elsif ($type == 2) {
8902
8903 # read ASCII string
8904 0 read($fh, $buf, $count);
8905
8906 # unpack null-terminated ASCII string
8907 0 $tags->{$id} = [unpack("Z$count", $buf)];
8908
8909 # if short values
8910 } elsif ($type == 3) {
8911
8912 # read values
8913 0 read($fh, $buf, 2 * $count);
8914
8915 # unpack values
8916 0 $tags->{$id} = [unpack("$short$count", $buf)];
8917
8918 # if long values
8919 } elsif ($type == 4) {
8920
8921 # read values
8922 0 read($fh, $buf, 4 * $count);
8923
8924 # unpack values
8925 0 $tags->{$id} = [unpack("$long$count", $buf)];
8926
8927 # if rational values
8928 } elsif ($type == 5) {
8929
8930 # double count (one rational value is two long values)
8931 0 $count *= 2;
8932
8933 # read values
8934 0 read($fh, $buf, 4 * $count);
8935
8936 # unpack values
8937 0 $tags->{$id} = [unpack("$long$count", $buf)];
8938
8939 }
8940
8941 # reset file pointer
8942 0 seek($fh, $mark, 0);
8943
8944 # if binary string
8945 ▶ } elsif ($type == 1 || $type == 7) {
Condition0%0/3
$type == 1 or $type == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == 1 or $type == 7
$type == 1 $type == 7
Truth table0%0/3
A or B
A= $type == 1B= $type == 7
ABresult
1X1
011
000
8946
8947 # unpack binary string
8948 0 $tags->{$id} = [unpack("a$count", $buf)];
8949
8950 # if ASCII string
8951 } elsif ($type == 2) {
8952
8953 # unpack null-terminated ASCII string
8954 0 $tags->{$id} = [unpack("Z$count", $buf)];
8955
8956 # if short value(s)
8957 } elsif ($type == 3) {
8958
8959 # unpack value(s)
8960 0 $tags->{$id} = [unpack("$short$count", $buf)];
8961
8962 # if long value
8963 } elsif ($type == 4) {
8964
8965 # unpack value
8966 0 $tags->{$id} = [unpack($long, $buf)];
8967
8968 } else {
8969
8970 # save packed value
8971 0 $tags->{$id} = [$buf];
8972
8973 }
8974
8975 }
8976  
8977 # return
8978 0 return($tags);
8979  
8980 }
8981  
8982 # read TIFF image band
8983 # row zero is top of image
8984 # parameters: (file_handle, IFD_hash, lower_row, upper_row, row_width, unpack_format)
8985 # returns: (2D_array)
8986 sub _readTIFFband {
8987  
8988 # get parameters
8989 0 ▶ my ($fh, $tags, $lower, $upper, $width, $upf) = @_;
Subroutine _readTIFFband: not called CC=2 SCAR=17.9
8990  
8991 # local variables
8992 0 my ($offset, $rows, $buf, $band);
8993  
8994 # get strip offset array
8995 0 $offset = $tags->{'273'};
8996  
8997 # get rows per strip
8998 0 $rows = $tags->{'278'}[0];
8999  
9000 # for each row
9001 0 for my $i ($lower .. $upper) {
9002
9003 # set file pointer
9004 0 seek($fh, $offset->[int($i/$rows)] + ($i % $rows) * $width, 0);
9005
9006 # read row data
9007 0 read($fh, $buf, $width);
9008
9009 # unpack data
9010 0 $band->[$i - $lower] = [unpack($upf, $buf)];
9011
9012 }
9013  
9014 # return
9015 0 return($band);
9016  
9017 }
9018  
9019 # write TIFF image file directory (IFD)
9020 # parameters: (file_handle, offset, short_format, long_format, IFD_hash)
9021 sub _writeTIFFdir {
9022  
9023 # get parameters
9024 0 ▶ my ($fh, $ifd, $short, $long, $tags) = @_;
Subroutine _writeTIFFdir: not called CC=25 SCAR=64.8
9025  
9026 # local variables
9027 0 my (@ts, @sid, $mark, $type, $count, $size, $fmt);
9028  
9029 # field type size (in bytes)
9030 0 @ts = (0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 4);
9031  
9032 # make list of tag ids, sorted numerically
9033 0 @sid = sort {$a <=> $b} keys(%{$tags});
9034  
9035 # seek start of IFD
9036 0 seek($fh, $ifd, 0);
9037  
9038 # write number of tags
9039 0 print $fh pack($short, scalar(@sid));
9040  
9041 # set data pointer
9042 0 $mark = $ifd + 12 * @sid + 6;
9043  
9044 # for each tag
9045 0 for my $id (@sid) {
9046
9047 # get data type
9048 0 $type = $tags->{$id}[0];
9049
9050 # if a binary string
9051 0 ▶ if ($type == 1 || $type == 7) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type == 1 or $type == 7) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 5) { } 0 0 0
Condition0%0/3
$type == 1 or $type == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == 1 or $type == 7
$type == 1 $type == 7
Truth table0%0/3
A or B
A= $type == 1B= $type == 7
ABresult
1X1
011
000
9052
9053 # set count to string length
9054 0 $count = length($tags->{$id}[1]);
9055
9056 # if an ASCII string
9057 } elsif ($type == 2) {
9058
9059 # set count to string length + 1
9060 0 $count = length($tags->{$id}[1]) + 1;
9061
9062 # if a rational value
9063 } elsif ($type == 5) {
9064
9065 # set count to number of values/2
9066 0 $count = $#{$tags->{$id}}/2;
9067
9068 } else {
9069
9070 # set count to number of values
9071 0 $count = $#{$tags->{$id}};
9072
9073 }
9074
9075 # if size of value/offset > 4
9076 0 ▶ if (($size = $count * $ts[$type]) > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (($size = $count * $ts[$type]) > 4) { } 0 0 0
9077
9078 # write directory entry with offset
9079 0 print $fh pack("$short$short$long$long", $id, $type, $count, $mark);
9080
9081 # increment data pointer
9082 0 $mark += $size;
9083
9084 # make a word boundary
9085 0 $mark += $mark % 2;
9086
9087 } else {
9088
9089 # if a binary string
9090 0 ▶ if ($type == 1 || $type == 7) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type == 1 or $type == 7) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
Condition0%0/3
$type == 1 or $type == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == 1 or $type == 7
$type == 1 $type == 7
Truth table0%0/3
A or B
A= $type == 1B= $type == 7
ABresult
1X1
011
000
9091
9092 # set pack format
9093 0 $fmt = 'a4';
9094
9095 # if an ASCII string
9096 } elsif ($type == 2) {
9097
9098 # set pack format
9099 0 $fmt = 'Z4';
9100
9101 # if a short value
9102 } elsif ($type == 3) {
9103
9104 # set pack format (one or two values)
9105 0 ▶ $fmt = $count == 1 ? $short . 'x2' : $short . '2';
Branch: 1 branch
BranchTrueFalseTotal
$count == 1 ? : 0 0 0
9106
9107 # if a long value
9108 } elsif ($type == 4) {
9109
9110 # set pack format
9111 0 $fmt = $long;
9112
9113 } else {
9114
9115 # error
9116 0 croak('unsupported TIFF data type, stopped');
9117
9118 }
9119
9120 # write directory entry (12 bytes) with value(s)
9121 0 print $fh pack("$short$short$long$fmt", $id, $type, $count, @{$tags->{$id}}[1 .. $#{$tags->{$id}}]);
9122
9123 }
9124
9125 }
9126  
9127 # set data pointer
9128 0 $mark = $ifd + 12 * @sid + 6;
9129  
9130 # for each tag
9131 0 for my $id (@sid) {
9132
9133 # get data type
9134 0 $type = $tags->{$id}[0];
9135
9136 # if a binary string
9137 0 ▶ if ($type == 1 || $type == 7) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type == 1 or $type == 7) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 5) { } 0 0 0
Condition0%0/3
$type == 1 or $type == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == 1 or $type == 7
$type == 1 $type == 7
Truth table0%0/3
A or B
A= $type == 1B= $type == 7
ABresult
1X1
011
000
9138
9139 # set count to string length
9140 0 $count = length($tags->{$id}[1]);
9141
9142 # if an ASCII string
9143 } elsif ($type == 2) {
9144
9145 # set count to string length + 1
9146 0 $count = length($tags->{$id}[1]) + 1;
9147
9148 # if a rational value
9149 } elsif ($type == 5) {
9150
9151 # set count to number of values/2
9152 0 $count = $#{$tags->{$id}}/2;
9153
9154 } else {
9155
9156 # set count to number of values
9157 0 $count = $#{$tags->{$id}};
9158
9159 }
9160
9161 # if size of value/offset > 4
9162 0 ▶ if (($size = $count * $ts[$type]) > 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (($size = $count * $ts[$type]) > 4) 0 0 0
9163
9164 # if a binary string
9165 0 ▶ if ($type == 1 || $type == 7) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type == 1 or $type == 7) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
elsif ($type == 5) { } 0 0 0
Condition0%0/3
$type == 1 or $type == 7
l!l&&r!l&&!r
000
MC/DC0%0/2
$type == 1 or $type == 7
$type == 1 $type == 7
Truth table0%0/3
A or B
A= $type == 1B= $type == 7
ABresult
1X1
011
000
9166
9167 # set pack format
9168 0 $fmt = "a$count";
9169
9170 # if an ASCII string
9171 } elsif ($type == 2) {
9172
9173 # set pack format
9174 0 $fmt = "Z$count";
9175
9176 # if a short value
9177 } elsif ($type == 3) {
9178
9179 # set pack format
9180 0 $fmt = "$short$count";
9181
9182 # if a long value
9183 } elsif ($type == 4) {
9184
9185 # set pack format
9186 0 $fmt = "$long$count";
9187
9188 # if a rational value
9189 } elsif ($type == 5) {
9190
9191 # set pack format
9192 0 $fmt = "$long$#{$tags->{$id}}";
9193
9194 } else {
9195
9196 # error
9197 0 croak('unsupported TIFF data type, stopped');
9198 }
9199
9200 # set file pointer
9201 0 seek($fh, $mark, 0);
9202
9203 # write the data value(s)
9204 0 print $fh pack($fmt, @{$tags->{$id}}[1 .. $#{$tags->{$id}}]);
9205
9206 # increment data pointer
9207 0 $mark += $size;
9208
9209 # make a word boundary
9210 0 $mark += $mark % 2;
9211
9212 }
9213
9214 }
9215
9216 }
9217  
9218 # write TIFF data strip
9219 # parameters: (file_handle, IFD_hash, patch_width, gap_width, left_edge_width, right_edge_width, strip_index, strip_data_array, pack_format, dither_value)
9220 sub _writeTIFFstrip {
9221  
9222 # get parameters
9223 0 ▶ my ($fh, $tags, $width, $gap, $left, $right, $sx, $data, $fmt, $dither) = @_;
Subroutine _writeTIFFstrip: not called CC=31 SCAR=69.0
9224  
9225 # local variables
9226 0 my ($pi, $samples, $bits, $max, $diff, $edge, $w, @spot, $rms, $gdata, @row, $strip);
9227  
9228 # get photometric interpretation
9229 0 $pi = $tags->{'262'}[1];
9230  
9231 # get number of samples (channels)
9232 0 $samples = $tags->{'277'}[1];
9233  
9234 # get bits per sample
9235 0 $bits = $tags->{'258'}[1];
9236  
9237 # max binary value (8, 16 or 32 bits)
9238 0 ▶ $max = ($bits == 8) ? 255 : ($bits == 16) ? 65535 : 1;
Branch: 2 branches
BranchTrueFalseTotal
$bits == 8 ? : 0 0 0
$bits == 16 ? : 0 0 0
9239  
9240 # make list of spot channel indices
9241 0 @spot = (4 .. $tags->{'277'}[1] - 1);
9242  
9243 # for each patch
9244 0 for my $i (0 .. $#{$data}) {
9245
9246 # if RGB data
9247 0 ▶ if ($pi == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pi == 2) { } 0 0 0
elsif ($pi == 5) { } 0 0 0
9248
9249 # compute white and black differences
9250 0 $diff->[$i][0] = sqrt(($max - $data->[$i][0])**2 + ($max - $data->[$i][1])**2 + ($max - $data->[$i][2])**2);
9251 0 $diff->[$i][1] = sqrt($data->[$i][0]**2 + $data->[$i][1]**2 + $data->[$i][2]**2);
9252
9253 # if CMYK data
9254 } elsif ($pi == 5) {
9255
9256 # compute rms value of CMY + spot channels (CMY weighted and spot channels inverted)
9257 0 $rms = sqrt(List::Util::sum(1.5 * $data->[$i][0]**2, $data->[$i][1]**2, 0.5 * $data->[$i][2]**2, (map {($max - $data->[$i][$_])**2} @spot))/(3 + @spot));
9258
9259 # compute white and black differences (black * color)
9260 0 $diff->[$i][0] = $max - ($max - $data->[$i][3]) * ($max - $rms)/$max;
9261 0 $diff->[$i][1] = ($max - $data->[$i][3]) * ($max - $rms)/$max;
9262
9263 # L*a*b* data
9264 } else {
9265
9266 # compute white and black differences (approx dEab)
9267 0 $diff->[$i][0] = sqrt(($max - $data->[$i][0])**2 + 6.55 * $data->[$i][1]**2 + 6.55 * $data->[$i][2]**2);
9268 0 $diff->[$i][1] = sqrt($data->[$i][0]**2 + 6.55 * $data->[$i][1]**2 + 6.55 * $data->[$i][2]**2);
9269
9270 }
9271
9272 # skip first patch
9273 0 ▶ if ($i > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
9274
9275 # if RGB data
9276 0 ▶ if ($pi == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($pi == 2) { } 0 0 0
elsif ($pi == 5) { } 0 0 0
9277
9278 # if max white difference > max black difference
9279 0 ▶ if (($diff->[$i - 1][0] > $diff->[$i][0] ? $diff->[$i - 1][0] : $diff->[$i][0]) > ($diff->[$i - 1][1] > $diff->[$i][1] ? $diff->[$i - 1][1] : $diff->[$i][1])) {
Branch: 3 branches
BranchTrueFalseTotal
if (($$diff[$i - 1][0] > $diff->[$i][0] ? $$diff[$i - 1][0] : $diff->[$i][0]) > ($$diff[$i - 1][1] > $diff->[$i][1] ? $$diff[$i - 1][1] : $diff->[$i][1])) { } 0 0 0
$$diff[$i - 1][0] > $diff->[$i][0] ? : 0 0 0
$$diff[$i - 1][1] > $diff->[$i][1] ? : 0 0 0
9280
9281 # gap is white
9282 0 $gdata->[$i - 1] = [($max) x 3];
9283
9284 } else {
9285
9286 # gap is black
9287 0 $gdata->[$i - 1] = [0, 0, 0];
9288
9289 }
9290
9291 # if CMYK data
9292 } elsif ($pi == 5) {
9293
9294 # if max white difference > max black difference
9295 0 ▶ if (($diff->[$i - 1][0] > $diff->[$i][0] ? $diff->[$i - 1][0] : $diff->[$i][0]) > ($diff->[$i - 1][1] > $diff->[$i][1] ? $diff->[$i - 1][1] : $diff->[$i][1])) {
Branch: 3 branches
BranchTrueFalseTotal
if (($$diff[$i - 1][0] > $diff->[$i][0] ? $$diff[$i - 1][0] : $diff->[$i][0]) > ($$diff[$i - 1][1] > $diff->[$i][1] ? $$diff[$i - 1][1] : $diff->[$i][1])) { } 0 0 0
$$diff[$i - 1][0] > $diff->[$i][0] ? : 0 0 0
$$diff[$i - 1][1] > $diff->[$i][1] ? : 0 0 0
9296
9297 # gap is white
9298 0 $gdata->[$i - 1] = [0, 0, 0, 0, ($max) x ($samples - 4)];
9299
9300 } else {
9301
9302 # gap is black
9303 0 $gdata->[$i - 1] = [0, 0, 0, ($max) x ($samples - 3)];
9304
9305 }
9306
9307 # L*a*b* data
9308 } else {
9309
9310 # if max white difference > max black difference
9311 0 ▶ if (($diff->[$i - 1][0] > $diff->[$i][0] ? $diff->[$i - 1][0] : $diff->[$i][0]) > ($diff->[$i - 1][1] > $diff->[$i][1] ? $diff->[$i - 1][1] : $diff->[$i][1])) {
Branch: 3 branches
BranchTrueFalseTotal
if (($$diff[$i - 1][0] > $diff->[$i][0] ? $$diff[$i - 1][0] : $diff->[$i][0]) > ($$diff[$i - 1][1] > $diff->[$i][1] ? $$diff[$i - 1][1] : $diff->[$i][1])) { } 0 0 0
$$diff[$i - 1][0] > $diff->[$i][0] ? : 0 0 0
$$diff[$i - 1][1] > $diff->[$i][1] ? : 0 0 0
9312
9313 # gap is white
9314 0 $gdata->[$i - 1] = [$max, 0, 0];
9315
9316 } else {
9317
9318 # gap is black
9319 0 $gdata->[$i - 1] = [0, 0, 0];
9320
9321 }
9322
9323 }
9324
9325 }
9326
9327 }
9328  
9329 # compute edge pixel values (black)
9330 0 ▶ $edge = ($pi == 5) ? [0, 0, 0, ($max) x ($samples - 3)] : [0, 0, 0];
Branch: 1 branch
BranchTrueFalseTotal
$pi == 5 ? : 0 0 0
9331  
9332 # for each patch
9333 0 for my $i (0 .. $#{$data}) {
9334
9335 # if first patch
9336 0 ▶ if ($i == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
elsif ($i == $#{$data;}) { } 0 0 0
9337
9338 # add left edge data
9339 0 push(@row, (@{$edge}) x $left->[0]);
9340
9341 # set patch width
9342 0 $w = $width - $left->[1];
9343
9344 # if last patch
9345 0 } elsif ($i == $#{$data}) {
9346
9347 # set patch width
9348 0 $w = $width - $right->[1];
9349
9350 # others
9351 } else {
9352
9353 # set patch width
9354 0 $w = $width;
9355
9356 }
9357
9358 # if dither enabled or 32-bits
9359 0 ▶ if (defined($dither) || $bits == 32) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dither or $bits == 32) { } 0 0 0
Condition0%0/3
defined $dither or $bits == 32
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $dither or $bits == 32
defined $dither $bits == 32
Truth table0%0/3
A or B
A= defined $ditherB= $bits == 32
ABresult
1X1
011
000
9360
9361 # add patch data
9362 0 push(@row, (@{$data->[$i]}) x $w);
9363
9364 } else {
9365
9366 # add patch data, adding/subtracting 0.5 to round to the nearest integer (by 'pack', below)
9367 0 ▶ push(@row, (map {$_ < 0 ? $_ - 0.5 : $_ + 0.5} @{$data->[$i]}) x $w);
Branch: 1 branch
BranchTrueFalseTotal
$_ < 0 ? : 0 0 0
9368
9369 }
9370
9371 # if last patch
9372 0 ▶ if ($i == $#{$data}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#{$data;}) { } 0 0 0
9373
9374 # add right edge data
9375 0 push(@row, (@{$edge}) x $right->[0]);
9376
9377 } else {
9378
9379 # add gap data
9380 0 push(@row, (@{$gdata->[$i]}) x $gap);
9381
9382 }
9383
9384 }
9385  
9386 # set file pointer to strip offset
9387 0 seek($fh, $tags->{'273'}[$sx + 1], 0);
9388
9389 # if dither enabled and 8-bit
9390 0 ▶ if (defined($dither) && $bits == 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dither and $bits == 8) { } 0 0 0
Condition0%0/3
defined $dither and $bits == 8
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dither and $bits == 8
defined $dither $bits == 8
Truth table0%0/3
A and B
A= defined $ditherB= $bits == 8
ABresult
0X0
100
111
9391
9392 # for each strip row
9393 0 for my $i (0 .. $tags->{'278'}[1] - 1) {
9394
9395 # write packed data with dithering
9396 0 ▶ print $fh pack($fmt, map {$_ < 0 ? $_ - rand() : $_ + rand()} @row);
Branch: 1 branch
BranchTrueFalseTotal
$_ < 0 ? : 0 0 0
9397
9398 }
9399
9400 } else {
9401
9402 # for each strip row
9403 0 for my $i (0 .. $tags->{'278'}[1] - 1) {
9404
9405 # write packed data
9406 0 print $fh pack($fmt, @row);
9407
9408 }
9409
9410 }
9411
9412 }
9413  
9414 # read chart from CxF3 data file
9415 # parameters: (object_reference, file_handle, hash)
9416 # returns: (result)
9417 sub _readChartCxF3 {
9418  
9419 # get parameters
9420 8 ▶ my ($self, $fh, $hash) = @_;
Subroutine _readChartCxF3: called CC=17 SCAR=28.7
9421  
9422 # local variables
9423 8 my ($dom, $root, $ns, $uri, %keys, @info, @obj, $ops_hash, $ops);
9424 8 my ($ix, $type, $name, $value, $node, @data, $xrp, @attr);
9425  
9426 # parse CxF3 document
9427 8 ▶ eval{$dom = XML::LibXML->load_xml('IO' => $fh)} || return('failed parsing CxF3 document');
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $dom = "XML::LibXML"->load_xml("IO", $fh) } } or return "failed parsing CxF3 document" 0 8 8
9428  
9429 # validate the CxF3 document
9430 8 ▶ _validateCxF3($dom) if (defined($hash->{'validate'}) && $hash->{'validate'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash->{"validate"} and $hash->{"validate"} 0 8 8
Condition33%1/3
defined $hash->{"validate"} and $hash->{"validate"}
!ll&&!rl&&r
800
MC/DC0%0/2
defined $hash->{"validate"} and $hash->{"validate"}
defined $hash->{"validate"} $hash->{"validate"}
Truth table33%1/3
A and B
A= defined $hash->{"validate"}B= $hash->{"validate"}
ABresult
0X0
100
111
9431  
9432 # get root element
9433 8 $root = $dom->documentElement();
9434  
9435 # get the namespace prefix and URI
9436 8 $ns = $root->prefix();
9437 8 $uri = $root->namespaceURI();
9438  
9439 # verify CxF3 document or return
9440 8 ▶ ($uri eq 'http://colorexchangeformat.com/CxF3-core') || return('CxF3 document has wrong URI');
Branch: 1 branch
BranchTrueFalseTotal
$uri eq "http://colorexchangeformat.com/CxF3-core" or return "CxF3 document has wrong URI" 0 8 8
9441  
9442 # get cc:Object elements
9443 8 @obj = $root->findnodes("$ns:Resources/$ns:ObjectCollection/$ns:Object");
9444  
9445 # get cc:FileInformation elements (optional)
9446 8 @info = $root->findnodes("$ns:FileInformation/*");
9447  
9448 # save root element
9449 # this method only reads data from cc:Object nodes
9450 # all other CxF3 info is kept in the dom object
9451 # and accessed as needed by other methods
9452 8 $self->[0]{'CxF3_dom'} = $root;
9453  
9454 # save record separator in header
9455 # note: XML files might not have record separators
9456 # so we use Perl's input record separator instead
9457 8 $self->[0]{'read_rs'} = $/;
9458  
9459 # make CxF3 => ASCII mapping table (from ISO 17972-1, Annex A)
9460 8 %keys = ('Creator' => 'ORIGINATOR', 'Description' => 'FILE_DESCRIPTOR', 'CreationDate' => 'CREATED', 'Comment' => 'CXF3_COMMENT');
9461  
9462 # for each cc:FileInformation element
9463 8 for my $s (@info) {
9464
9465 # if cc:Tag node
9466 40 ▶ if ($s->nodeName() eq "$ns:Tag") {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->nodeName eq "${ns}:Tag") { } 16 24 40
9467
9468 # get name attribute
9469 16 $name = $s->getAttribute('Name');
9470
9471 # get value attribute
9472 16 $value = $s->getAttribute('Value');
9473
9474 } else {
9475
9476 # get node name
9477 24 $name = $s->nodeName();
9478
9479 # remove namespace prefix
9480 24 $name =~ s/^\w+://;
9481
9482 # lookup name in hash
9483 24 ▶ $name = defined($keys{$name}) ? $keys{$name} : $name;
Branch: 1 branch
BranchTrueFalseTotal
defined $keys{$name} ? : 24 0 24
9484
9485 # get node value
9486 24 $value = $s->textContent();
9487
9488 }
9489
9490 # add name/value to header array
9491 40 push(@{$self->[3]}, [$name, "\"$value\"", 'FileInformation']);
9492
9493 }
9494  
9495 # make the operations hash and add format fields
9496 8 $ops_hash = _makeCxF3readops($self, $root, $ns, \@obj, $hash);
9497  
9498 # initialize sample index
9499 8 $ix = 0;
9500  
9501 # for each cc:Object element
9502 8 for my $s (@obj) {
9503
9504 # get the ObjectType attribute
9505 160 $type = $s->getAttribute('ObjectType');
9506
9507 # get the Name attribute
9508 160 $name = $s->getAttribute('Name');
9509
9510 # if ObjectType is 'Target' or '...Measurement'
9511 160 ▶ if ($type =~ m/^Target$|Measurement$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^Target$|Measurement$/) { } 160 0 160
9512
9513 # match numeric part of Name attribute
9514 160 $name =~ m/(\d+)$/;
9515
9516 # set row index
9517 160 $ix = $1;
9518
9519 } else {
9520
9521 # increment row index
9522 0 $ix++;
9523
9524 }
9525
9526 # get operation list for this ObjectType
9527 160 $ops = $ops_hash->{$type};
9528
9529 # for each operation
9530 160 for my $i (0 .. $#{$ops}) {
9531
9532 # get main Xpath node
9533 160 ($node) = $s->findnodes($ops->[$i][1]);
9534
9535 # if subpaths
9536 160 ▶ if (@{$ops->[$i][2]}) {
Branch: 3 branches
BranchTrueFalseTotal
if (@{$ops->[$i][2];}) { } 100 60 160
elsif (@{$ops->[$i][3];} == 1) { } 0 60 60
elsif (@{$ops->[$i][3];} > 1) { } 60 0 60
9537
9538 # if data class is NCLR
9539 100 ▶ if ($ops->[$i][0] eq 'NCLR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ops->[$i][0] eq 'NCLR') { } 20 80 100
9540
9541 # get the CMYK values
9542 20 @data = map {$node->findvalue($_)} @{$ops->[$i][2]};
9543
9544 # for each SpotColor
9545 20 for my $spotcolor ($node->findnodes("$ns:SpotColor")) {
9546
9547 # push SpotColor value
9548 40 push(@data, $spotcolor->findvalue("$ns:Percentage"));
9549
9550 }
9551
9552 # set chart data (CMYK + SPOT values)
9553 20 @{$self->[1][$ix]}[@{$ops->[$i][3]}] = @data;
9554
9555 } else {
9556
9557 # set chart data using subpaths
9558 80 @{$self->[1][$ix]}[@{$ops->[$i][3]}] = map {$node->findvalue($_)} @{$ops->[$i][2]};
9559
9560 }
9561
9562 # if no subpaths and one field
9563 60 } elsif (@{$ops->[$i][3]} == 1) {
9564
9565 # set chart data to text content
9566 0 $self->[1][$ix][$ops->[$i][3][0]] = $node->textContent();
9567
9568 # if no subpaths and multiple fields (e.g. spectral data)
9569 60 } elsif (@{$ops->[$i][3]} > 1) {
9570
9571 # set chart data splitting text content
9572 60 @{$self->[1][$ix]}[@{$ops->[$i][3]}] = split(/ /, $node->textContent());
9573
9574 }
9575
9576 }
9577
9578 }
9579  
9580 # read CxF3 ColorSpecification nodes
9581 8 _readCxF3colorspec($self, $root, $ns);
9582  
9583 # make XPathContext object for X-Rite Prism namespace
9584 8 $xrp = XML::LibXML::XPathContext->new($root);
9585 8 $xrp->registerNs('xrp', 'http://www.xrite.com/products/prism');
9586  
9587 # get the xrp:CustomAttributes node
9588 8 ▶ if (($node) = $xrp->findnodes("$ns:CustomResources/xrp:Prism/xrp:CustomAttributes")) {
Branch: 1 branch
BranchTrueFalseTotal
if (($node) = $xrp->findnodes("${ns}:CustomResources/xrp:Prism/xrp:CustomAttributes")) 8 0 8
9589
9590 # get the attribute list
9591 8 @attr = $node->attributes();
9592
9593 # add xrp:CustomAttributes hash
9594 8 $self->[0]{'xrp:CustomAttributes'} = {map {$_->nodeName, $_->getValue()} @attr};
9595
9596 }
9597  
9598 # return
9599 8 return();
9600  
9601 }
9602  
9603 # make CxF3 read operations hash
9604 # adds the format fields to object
9605 # parameters: (object_reference, CxF3_root, CxF3_prefix, CxF3_object_array_reference, hash)
9606 # returns: (hash_ref)
9607 sub _makeCxF3readops {
9608  
9609 # get parameters
9610 8 ▶ my ($self, $root, $ns, $obj, $hash) = @_;
Subroutine _makeCxF3readops: called CC=33 SCAR=53.0
9611  
9612 # local variables
9613 8 my (@attr, @tags, %keys, $table, $k, $m, $n, $t, $type, $entry, $ops_hash);
9614 8 my (@format, @nodes, $node, @data, $name, $colorspec, $start, $inc);
9615  
9616 # if cc:Object filter parameter provided
9617 8 ▶ if (defined($hash->{'cc:Object'}) && ref($hash->{'cc:Object'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"cc:Object"} and ref $hash->{"cc:Object"} eq "ARRAY") 0 8 8
Condition33%1/3
defined $hash->{"cc:Object"} and ref $hash->{"cc:Object"} eq "ARRAY"
!ll&&!rl&&r
800
MC/DC0%0/2
defined $hash->{"cc:Object"} and ref $hash->{"cc:Object"} eq "ARRAY"
defined $hash->{"cc:Object"} ref $hash->{"cc:Object"} eq "ARRAY"
Truth table33%1/3
A and B
A= defined $hash->{"cc:Object"}B= ref $hash->{"cc:Object"} eq "ARRAY"
ABresult
0X0
100
111
9618
9619 # for each entry
9620 0 for (@{$hash->{'cc:Object'}}) {
9621
9622 # match type/attribute
9623 0 m/^([^\s\/]*?)\/?([^\s\/]*)$/;
9624
9625 # save matched values
9626 0 $entry = [$1, $2];
9627
9628 # if a valid attribute (see CxF3_Core.xsd)
9629 0 ▶ if ($2 =~ m/^(?:|ObjectType|Name|Id|GUID|\*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($2 =~ /^(?:|ObjectType|Name|Id|GUID|\*)$/) { } 0 0 0
9630
9631 # push on array
9632 0 push(@attr, $entry);
9633
9634 } else {
9635
9636 # print warning
9637 0 warn('invalid cc:Object attribute');
9638
9639 }
9640
9641 }
9642
9643 }
9644  
9645 # if cc:Tag filter parameter provided
9646 8 ▶ if (defined($hash->{'cc:Tag'}) && ref($hash->{'cc:Tag'}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"cc:Tag"} and ref $hash->{"cc:Tag"} eq "ARRAY") 0 8 8
Condition33%1/3
defined $hash->{"cc:Tag"} and ref $hash->{"cc:Tag"} eq "ARRAY"
!ll&&!rl&&r
800
MC/DC0%0/2
defined $hash->{"cc:Tag"} and ref $hash->{"cc:Tag"} eq "ARRAY"
defined $hash->{"cc:Tag"} ref $hash->{"cc:Tag"} eq "ARRAY"
Truth table33%1/3
A and B
A= defined $hash->{"cc:Tag"}B= ref $hash->{"cc:Tag"} eq "ARRAY"
ABresult
0X0
100
111
9647
9648 # for each entry
9649 0 for (@{$hash->{'cc:Tag'}}) {
9650
9651 # match type/key
9652 0 m/^([^\s\/]*?)\/?([^\s\/]*)$/;
9653
9654 # push on array
9655 0 push(@tags, [$1, $2]);
9656
9657 }
9658
9659 }
9660  
9661 # make hash for sort order of certain keys
9662 8 %keys = ('SampleID' => -2, 'SampleName' => -1, 'Id' => -2, 'Name' => -1);
9663  
9664 # table [data_class, CxF3_main_path, [CxF3_sub_paths], [CGATS/ASCII field names]]
9665 # some mappings have no sub-paths, which is indicated by an empty sub_path array
9666 # the 'NCLR', 'SPECTRAL' and 'DENSITY' data classes are special cases
9667 8 $table = [
9668 ['RGB', "$ns:DeviceColorValues/$ns:ColorRGB", ["$ns:R", "$ns:G", "$ns:B"], [qw(RGB_R RGB_G RGB_B)]],
9669 ['CMYK', "$ns:DeviceColorValues/$ns:ColorCMYK", ["$ns:Cyan", "$ns:Magenta", "$ns:Yellow", "$ns:Black"], [qw(CMYK_C CMYK_M CMYK_Y CMYK_K)]],
9670 ['NCLR', "$ns:DeviceColorValues/$ns:ColorCMYKPlusN", ["$ns:Cyan", "$ns:Magenta", "$ns:Yellow", "$ns:Black"], [qw(nCLR)]],
9671 ['SPECTRAL', "$ns:ColorValues/$ns:ReflectanceSpectrum", [], [qw(nm)]],
9672 ['DENSITY', "$ns:ColorValues/$ns:ColorDensity/$ns:Density", [], [qw(D_RED D_GREEN D_BLUE D_VIS)]],
9673 ['XYZ', "$ns:ColorValues/$ns:ColorCIEXYZ", ["$ns:X", "$ns:Y", "$ns:Z"], [qw(XYZ_X XYZ_Y XYZ_Z)]],
9674 ['XYY', "$ns:ColorValues/$ns:ColorCIExyY", ["$ns:x", "$ns:y", "$ns:Y"], [qw(XYY_X XYY_Y XYY_YCAP)]],
9675 ['LAB', "$ns:ColorValues/$ns:ColorCIELab", ["$ns:L", "$ns:A", "$ns:B"], [qw(LAB_L LAB_A LAB_B)]],
9676 ['LCH', "$ns:ColorValues/$ns:ColorCIELCh", ["$ns:L", "$ns:C", "$ns:H"], [qw(LAB_L LAB_C LAB_H)]],
9677 ['DE', "$ns:ColorDifferenceValues/$ns:DeltaCIELab/$ns:dE", [], [qw(LAB_DE)]],
9678 ['DE94', "$ns:ColorDifferenceValues/$ns:DeltaCIELab/$ns:dE94", [], [qw(LAB_DE94)]],
9679 ['DECMC', "$ns:ColorDifferenceValues/$ns:DeltaCIELab/$ns:dEcmc", [], [qw(LAB_CMC)]],
9680 ['DE2000', "$ns:ColorDifferenceValues/$ns:DeltaCIELab/$ns:dE2000", [], [qw(LAB_2000)]],
9681 ];
9682  
9683 # set next table index
9684 8 $m = $#{$table} + 1;
9685  
9686 # for each CxF3 'Object'
9687 8 for my $s (@{$obj}) {
9688
9689 # get the 'ObjectType' attribute
9690 160 $type = $s->getAttribute('ObjectType');
9691
9692 # if 'ObjectType' not in hash
9693 160 ▶ if (! defined($ops_hash->{$type})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ops_hash->{$type}) 16 144 160
9694
9695 # add 'ObjectType' to hash
9696 16 $ops_hash->{$type} = [];
9697
9698 # if 'Object' attributes are mapped
9699 16 ▶ if (@attr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@attr) { } 0 16 16
9700
9701 # for each 'Object' attribute (GUID is optional)
9702 0 for my $t (qw(ObjectType Name Id GUID)) {
9703
9704 # if attribute exists and is mapped
9705 0 ▶ if ($s->exists("\@$t") && grep {($_->[0] eq $type || $_->[0] =~ m/^\*?$/) && ($_->[1] eq $t || $_->[1] =~ m/^\*?$/)} @attr) {
Branch: 2 branches
BranchTrueFalseTotal
if ($s->exists("\@$t") and grep {$_->[0] eq $type || $_->[0] =~ /^\*?$/ and $_->[1] eq $t || $_->[1] =~ /^\*?$/;} @attr) 0 0 0
$_->[0] eq $type || $_->[0] =~ /^\*?$/ and $_->[1] eq $t || $_->[1] =~ /^\*?$/ 0 0 0
Condition0%0/12
$s->exists("\@$t") and grep {$_->[0] eq $type || $_->[0] =~ /^\*?$/ and $_->[1] eq $t || $_->[1] =~ /^\*?$/;} @attr
!ll&&!rl&&r
000
($_->[0] eq $type || $_->[0] =~ /^\*?$/) && ($_->[1] eq $t || $_->[1] =~ /^\*?$/)
!ll&&!rl&&r
000
$_->[0] eq $type or $_->[0] =~ /^\*?$/
l!l&&r!l&&!r
000
$_->[1] eq $t or $_->[1] =~ /^\*?$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$s->exists("\@$t") and grep {$_->[0] eq $type || $_->[0] =~ /^\*?$/ and $_->[1] eq $t || $_->[1] =~ /^\*?$/;} @attr
$s->exists("\@$t") grep {$_->[0] eq $type || $_->[0] =~ /^\*?$/ and $_->[1] eq $t || $_->[1] =~ /^\*?$/;} @attr
MC/DC0%0/4
($_->[0] eq $type || $_->[0] =~ /^\*?$/) && ($_->[1] eq $t || $_->[1] =~ /^\*?$/)
$_->[0] eq $type $_->[0] =~ /^\*?$/ $_->[1] eq $t $_->[1] =~ /^\*?$/
Truth table0%0/3
A and B
A= $s->exists("\@$t")B= grep {$_->[0] eq $type || $_->[0] =~ /^\*?$/ and $_->[1] eq $t || $_->[1] =~ /^\*?$/;} @attr
ABresult
0X0
100
111
Truth table0%0/7
A or B && C or D
A= $_->[0] eq $typeB= $_->[0] =~ /^\*?$/C= $_->[1] eq $tD= $_->[1] =~ /^\*?$/
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
9706
9707 # get sort order
9708 0 ▶ $k = defined($keys{$t}) ? $keys{$t} : $m++;
Branch: 1 branch
BranchTrueFalseTotal
defined $keys{$t} ? : 0 0 0
9709
9710 # push table entry on hash array (note: attribute XPaths begin with @)
9711 0 push(@{$ops_hash->{$type}}, $entry = ["ATTR:$t", "\@$t", [], [$t], $type, $k]);
9712
9713 # push table entry on format array
9714 0 push(@format, $entry);
9715
9716 }
9717
9718 }
9719
9720 } else {
9721
9722 # if ObjectType not 'Target' or '...Measurement'
9723 16 ▶ if ($type !~ m/^Target$|Measurement$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($type =~ /^Target$|Measurement$/) 0 16 16
9724
9725 # push table entry on hash array (note: attribute XPaths begin with @)
9726 0 push(@{$ops_hash->{$type}}, $entry = ['NAME', '@Name', [], ['SAMPLE_NAME'], $type, -1]);
9727
9728 # push table entry on format array
9729 0 push(@format, $entry);
9730
9731 }
9732
9733 }
9734
9735 # for each table entry
9736 16 for my $i (0 .. $#{$table}) {
9737
9738 # get table entry
9739 208 $t = $table->[$i];
9740
9741 # if main XPath exists
9742 208 ▶ if ($s->exists($t->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->exists($t->[1])) 16 192 208
9743
9744 # get ColorSpecification attribute (if any)
9745 16 $colorspec = $s->findvalue("$t->[1]/\@ColorSpecification");
9746
9747 # push table entry on hash array
9748 16 push(@{$ops_hash->{$type}}, $entry = [@{$t}, $type, $i, $colorspec]);
9749
9750 # push table entry on format array
9751 16 push(@format, $entry);
9752
9753 # if an 'NCLR' entry
9754 16 ▶ if ($entry->[0] eq 'NCLR') {
Branch: 2 branches
BranchTrueFalseTotal
if ($entry->[0] eq 'NCLR') { } 2 14 16
elsif ($entry->[0] eq 'SPECTRAL') { } 6 8 14
9755
9756 # get cc:SpotColor nodes
9757 2 @nodes = $s->findnodes(".//$ns:SpotColor");
9758
9759 # get number of colors
9760 2 $n = @nodes + 4;
9761
9762 # add format fields
9763 2 $entry->[3] = [map {sprintf('%xCLR_%x', $n, $_)} (1 .. $n)];
9764
9765 # if a 'SPECTRAL' entry
9766 } elsif ($entry->[0] eq 'SPECTRAL') {
9767
9768 # get the ReflectanceSpectrum data
9769 6 @data = split(/ /, $s->findvalue($t->[1]));
9770
9771 # get the ColorSpecification node (linked by the ColorSpecification attribute)
9772 6 ($node) = $root->findnodes("$ns:Resources/$ns:ColorSpecificationCollection/$ns:ColorSpecification[\@Id='$colorspec']");
9773
9774 # get the StartWL attribute
9775 6 $start = $node->findvalue("$ns:MeasurementSpec/$ns:WavelengthRange/\@StartWL");
9776
9777 # get the Increment attribute
9778 6 $inc = $node->findvalue("$ns:MeasurementSpec/$ns:WavelengthRange/\@Increment");
9779
9780 # add format fields
9781 6 $entry->[3] = [map {'nm' . ($start + $_ * $inc)} (0 .. $#data)];
9782
9783 }
9784
9785 }
9786
9787 }
9788
9789 # if Tags are mapped
9790 16 ▶ if (@tags) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tags) 0 16 16
9791
9792 # for each Tag
9793 0 for my $t ($s->findnodes("$ns:TagCollection/$ns:Tag")) {
9794
9795 # get Tag Name attribute
9796 0 $name = $t->getAttribute('Name');
9797
9798 # if this Tag is mapped
9799 0 ▶ if (grep {($_->[0] eq $type || $_->[0] =~ m/^\*?$/) && ($_->[1] eq $name || $_->[1] =~ m/^\*?$/)} @tags) {
Branch: 2 branches
BranchTrueFalseTotal
if (grep {$_->[0] eq $type || $_->[0] =~ /^\*?$/ and $_->[1] eq $name || $_->[1] =~ /^\*?$/;} @tags) 0 0 0
$_->[0] eq $type || $_->[0] =~ /^\*?$/ and $_->[1] eq $name || $_->[1] =~ /^\*?$/ 0 0 0
Condition0%0/9
($_->[0] eq $type || $_->[0] =~ /^\*?$/) && ($_->[1] eq $name || $_->[1] =~ /^\*?$/)
!ll&&!rl&&r
000
$_->[0] eq $type or $_->[0] =~ /^\*?$/
l!l&&r!l&&!r
000
$_->[1] eq $name or $_->[1] =~ /^\*?$/
l!l&&r!l&&!r
000
MC/DC0%0/4
($_->[0] eq $type || $_->[0] =~ /^\*?$/) && ($_->[1] eq $name || $_->[1] =~ /^\*?$/)
$_->[0] eq $type $_->[0] =~ /^\*?$/ $_->[1] eq $name $_->[1] =~ /^\*?$/
Truth table0%0/7
A or B && C or D
A= $_->[0] eq $typeB= $_->[0] =~ /^\*?$/C= $_->[1] eq $nameD= $_->[1] =~ /^\*?$/
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
9800
9801 # get sort order
9802 0 ▶ $k = defined($keys{$name}) ? $keys{$name} : $m++;
Branch: 1 branch
BranchTrueFalseTotal
defined $keys{$name} ? : 0 0 0
9803
9804 # push table entry on hash array (note: attribute XPaths begin with @)
9805 0 push(@{$ops_hash->{$type}}, $entry = ["TAG:$name", "$ns:TagCollection/$ns:Tag[\@Name = '$name']/\@Value", [], [$name], $type, $k]);
9806
9807 # push table entry on format array
9808 0 push(@format, $entry);
9809
9810 }
9811
9812 }
9813
9814 }
9815
9816 }
9817
9818 }
9819  
9820 # sort format array by table index
9821 8 @format = sort {$a->[5] <=> $b->[5]} @format;
9822
9823 # for each format entry
9824 8 for my $fmt (@format) {
9825
9826 # add format fields to data array and replace keys with column indices
9827 16 $fmt->[3] = add_fmt($self, map {"$fmt->[4]|$_"} @{$fmt->[3]});
9828
9829 # if entry has ColorSpecification
9830 16 ▶ if (defined($fmt->[6])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fmt->[6]) 16 0 16
9831
9832 # add ColorSpecification attribute to colorimetry array
9833 16 for (@{$fmt->[3]}) {$self->[2][5][$_] = $fmt->[6]}
9834
9835 }
9836
9837 }
9838  
9839 # return
9840 8 return($ops_hash);
9841  
9842 }
9843  
9844 # read CxF3 ColorSpecification nodes
9845 # parameters: (object_reference, CxF3_root, CxF3_prefix)
9846 sub _readCxF3colorspec {
9847  
9848 # get parameters
9849 8 ▶ my ($self, $root, $ns) = @_;
Subroutine _readCxF3colorspec: called CC=8 SCAR=20.8
9850  
9851 # local variables
9852 8 my (@keys, @cspec, $id, $node, $child, $value);
9853  
9854 # make CxF3 => ASCII mapping table (from ISO 17972-1, Annex A)
9855 8 @keys = (
9856 ["$ns:MeasurementSpec/$ns:GeometryChoice" => 'MEASUREMENT_GEOMETRY'],
9857 ["$ns:MeasurementSpec/$ns:Device/$ns:DeviceFilter" => 'FILTER'],
9858 ["$ns:MeasurementSpec/$ns:Device/$ns:DeviceIllumination" => 'MEASUREMENT_SOURCE'],
9859 ["$ns:MeasurementSpec/$ns:CalibrationStandard" => 'DEVCALSTD'],
9860 );
9861  
9862 # find the ColorSpecification nodes
9863 8 @cspec = $root->findnodes("$ns:Resources/$ns:ColorSpecificationCollection/$ns:ColorSpecification");
9864  
9865 # for each ColorSpecification node
9866 8 for my $s (@cspec) {
9867
9868 # get the Id attribute and skip if 'Unknown'
9869 16 ▶ next if (($id = $s->getAttribute('Id')) eq 'Unknown');
Branch: 1 branch
BranchTrueFalseTotal
if ($id = $s->getAttribute("Id")) eq "Unknown" 8 8 16
9870
9871 # for each entry in mapping table
9872 8 for my $i (0 .. $#keys) {
9873
9874 # if XPath is found
9875 32 ▶ if (($node) = $s->findnodes($keys[$i][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (($node) = $s->findnodes($keys[$i][0])) 24 8 32
9876
9877 # get the first non-blank child node
9878 24 ▶ if (($child) = $node->nonBlankChildNodes()) {
Branch: 1 branch
BranchTrueFalseTotal
if (($child) = $node->nonBlankChildNodes) 24 0 24
9879
9880 # if child is an element node
9881 24 ▶ if ($child->nodeType() == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($child->nodeType == 1) { } 8 16 24
elsif ($child->nodeType == 3) { } 16 0 16
9882
9883 # serialize node
9884 8 $value = $node->toString(1);
9885
9886 # remove tabs and endlines
9887 8 $value =~ s/[\t\n]+//g;
9888
9889 # remove namespace prefix
9890 8 $value =~ s/([<\/])$ns:/$1/g;
9891
9892 # if child is a text node
9893 } elsif ($child->nodeType() == 3) {
9894
9895 # get the value
9896 16 $value = $node->textContent();
9897
9898 }
9899
9900 # save in header line array
9901 24 push(@{$self->[3]}, [$keys[$i][1], "\"$value\"", $id]);
9902
9903 }
9904
9905 }
9906
9907 }
9908
9909 }
9910
9911 }
9912  
9913 # make CxF3 FileInformation nodes
9914 # optional hash parameter contains 'cc:FileInformation' filter array
9915 # parameters: (object_reference, CxF3_root, CxF3_prefix, CxF3_namespace_URI, hash)
9916 # returns: (datetime)
9917 sub _makeCxF3fileinfo {
9918  
9919 # get parameters
9920 0 ▶ my ($self, $root, $ns, $nsURI, $hash) = @_;
Subroutine _makeCxF3fileinfo: not called CC=14 SCAR=53.5
9921  
9922 # local variables
9923 0 my (@filter, $t, $datetime, $info, %keys);
9924 0 my ($keyword, $value, $source, $node, $child);
9925  
9926 # get filter array (if any)
9927 0 ▶ @filter = @{ICC::Shared::flatten($hash->{'cc:FileInformation'})} if (defined($hash->{'cc:FileInformation'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash->{"cc:FileInformation"} 0 0 0
9928  
9929 # make Time::Piece object
9930 0 $t = localtime();
9931  
9932 # get the 'FileInformation' node
9933 0 ($info) = $root->findnodes("$ns:FileInformation");
9934  
9935 # make ASCII => CxF3 mapping table (from ISO 17972-1, Annex A)
9936 0 %keys = ('ORIGINATOR' => "$ns:Creator", 'FILE_DESCRIPTOR' => "$ns:Description", 'CXF3_COMMENT' => "$ns:Comment");
9937  
9938 # for each file header line
9939 0 for (@{$self->[3]}) {
9940
9941 # get keyword, value and source
9942 0 ($keyword, $value, $source) = @{$_};
9943
9944 # strip quotes from value
9945 0 $value =~ s/^\"(.*)\"$/$1/;
9946
9947 # if keyword is 'CREATED'
9948 0 ▶ if ($keyword eq 'CREATED') {
Branch: 2 branches
BranchTrueFalseTotal
if ($keyword eq 'CREATED') { } 0 0 0
elsif (defined $source and $source eq 'FileInformation' or grep {$_ eq $keyword;} @filter) { } 0 0 0
9949
9950 # make Time::Piece object from 'CREATED' value
9951 0 $t = _makeTimePiece($value);
9952
9953 # if source is 'FileInformation' or keyword is in filter array
9954 0 ▶ } elsif ((defined($source) && $source eq 'FileInformation') || grep {$_ eq $keyword} @filter) {
Condition0%0/6
defined $source and $source eq "FileInformation" or grep {$_ eq $keyword;} @filter
l!l&&r!l&&!r
000
defined $source and $source eq "FileInformation"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $source and $source eq "FileInformation" or grep {$_ eq $keyword;} @filter
defined $source $source eq "FileInformation" grep {$_ eq $keyword;} @filter
Truth table0%0/5
A and B or C
A= defined $sourceB= $source eq "FileInformation"C= grep {$_ eq $keyword;} @filter
ABCresult
11X1
0X11
1011
0X00
1000
9955
9956 # if keyword in mapping table
9957 0 ▶ if (exists($keys{$keyword})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $keys{$keyword}) { } 0 0 0
9958
9959 # if XPath exists in FileInformation element
9960 0 ▶ if (($node) = $info->findnodes($keys{$keyword})) {
Branch: 1 branch
BranchTrueFalseTotal
if (($node) = $info->findnodes($keys{$keyword})) 0 0 0
9961
9962 # if text content exists
9963 0 ▶ if ((($child) = $node->nonBlankChildNodes) && $child->nodeType == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (($child) = $node->nonBlankChildNodes and $child->nodeType == 3) 0 0 0
Condition0%0/3
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
!ll&&!rl&&r
000
MC/DC0%0/2
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
($child) = $node->nonBlankChildNodes $child->nodeType == 3
Truth table0%0/3
A and B
A= ($child) = $node->nonBlankChildNodesB= $child->nodeType == 3
ABresult
0X0
100
111
9964
9965 # update text content
9966 0 $child->setData($value);
9967
9968 }
9969
9970 }
9971
9972 # must be a 'Tag' element
9973 } else {
9974
9975 # if XPath exists in FileInformation element
9976 0 ▶ if (($node) = $info->findnodes("$ns:Tag[\@Name='$keyword']")) {
Branch: 1 branch
BranchTrueFalseTotal
if (($node) = $info->findnodes("${ns}:Tag[\@Name='${keyword}']")) { } 0 0 0
9977
9978 # update the Value attribute
9979 0 $node->setAttribute('Value', $value);
9980
9981 } else {
9982
9983 # add new Tag element
9984 0 $node = $info->appendChild(XML::LibXML::Element->new('Tag'));
9985 0 $node->setAttribute('Name', $keyword);
9986 0 $node->setAttribute('Value', $value);
9987 0 $node->setNamespace($nsURI, $ns);
9988
9989 }
9990
9991 }
9992
9993 }
9994
9995 }
9996  
9997 # make ISO 8601 datetime string from Time::Piece object
9998 0 $datetime = $t->strftime('%Y-%m-%dT%T%z');
9999 0 substr($datetime, -2, 0, ':');
10000  
10001 # get the 'CreationDate' node
10002 0 ($node) = $info->findnodes("$ns:CreationDate");
10003  
10004 # if text content exists
10005 0 ▶ if ((($child) = $node->nonBlankChildNodes) && $child->nodeType == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (($child) = $node->nonBlankChildNodes and $child->nodeType == 3) 0 0 0
Condition0%0/3
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
!ll&&!rl&&r
000
MC/DC0%0/2
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
($child) = $node->nonBlankChildNodes $child->nodeType == 3
Truth table0%0/3
A and B
A= ($child) = $node->nonBlankChildNodesB= $child->nodeType == 3
ABresult
0X0
100
111
10006
10007 # update text content
10008 0 $child->setData($datetime);
10009
10010 }
10011  
10012 # return datetime
10013 0 return($datetime);
10014  
10015 }
10016  
10017 # make CxF3 write operations array
10018 # parameters: (object_reference, CxF3_root, CxF3_prefix, column_slice)
10019 # returns: (array_ref)
10020 sub _makeCxF3writeops {
10021  
10022 # get parameters
10023 0 ▶ my ($self, $root, $ns, $cols) = @_;
Subroutine _makeCxF3writeops: not called CC=40 SCAR=74.0
10024  
10025 # local variables
10026 0 my ($n, %keys, $table, $class, $prefix, $key, $ops, $groups, $sort);
10027  
10028 # if column slice defined
10029 0 ▶ if (defined($cols)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cols) { } 0 0 0
10030
10031 # if column slice an empty array reference
10032 0 ▶ if (ref($cols) eq 'ARRAY' && @{$cols} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cols eq 'ARRAY' and @{$cols;} == 0) { } 0 0 0
Condition0%0/3
ref $cols eq "ARRAY" and @{$cols;} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
ref $cols eq "ARRAY" and @{$cols;} == 0
ref $cols eq "ARRAY" @{$cols;} == 0
Truth table0%0/3
A and B
A= ref $cols eq "ARRAY"B= @{$cols;} == 0
ABresult
0X0
100
111
10033
10034 # use all columns
10035 0 $cols = [0 .. $#{$self->[1][0]}];
10036
10037 } else {
10038
10039 # flatten column slice
10040 0 $cols = ICC::Shared::flatten($cols);
10041
10042 }
10043
10044 } else {
10045
10046 # use all columns
10047 0 $cols = [0 .. $#{$self->[1][0]}];
10048
10049 }
10050  
10051 # get number of fields
10052 0 $n = @{$cols};
10053  
10054 # remove undefined keys
10055 0 @{$cols} = grep {defined($self->[1][0][$_])} @{$cols};
10056  
10057 # warn if undefined keys
10058 0 ▶ ($n == @{$cols}) || warn('undefined keys in column slice');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$cols;} or warn "undefined keys in column slice" 0 0 0
10059  
10060 # get number of fields
10061 0 $n = @{$cols};
10062  
10063 # remove duplicate keys
10064 0 @{$cols} = grep {! $keys{$self->[1][0][$_]}++} @{$cols};
10065  
10066 # warn if duplicate keys
10067 0 ▶ ($n == @{$cols}) || warn('duplicate keys in column slice');
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$cols;} or warn "duplicate keys in column slice" 0 0 0
10068  
10069 # table structure: [data_class, CxF3_main_path, [CxF3_sub_paths], regex, sort_order]
10070 # some mappings have no sub-paths, which is indicated by an empty sub_path array
10071 # sort_order array contains the last character(s) of the format keys, and is optional
10072 # the 'NCLR', 'SPECTRAL' and 'DENSITY' data classes are special cases
10073 0 $table = [
10074 ['RGB', "$ns:DeviceColorValues/$ns:ColorRGB", ["$ns:R", "$ns:G", "$ns:B"], qr/^(?:(.*)\|)?RGB_[RGB]$/, [qw(R G B)]],
10075 ['CMYK', "$ns:DeviceColorValues/$ns:ColorCMYK", ["$ns:Cyan", "$ns:Magenta", "$ns:Yellow", "$ns:Black"], qr/^(?:(.*)\|)?CMYK_[CMYK]$/, [qw(C M Y K)]],
10076 ['NCLR', "$ns:DeviceColorValues/$ns:ColorCMYKPlusN", ["$ns:Cyan", "$ns:Magenta", "$ns:Yellow", "$ns:Black"], qr/^(?:(.*)\|)?[2-9A-F]CLR_[1-9A-F]$/],
10077 ['SPECTRAL', "$ns:ColorValues/$ns:ReflectanceSpectrum", [], qr/^(?:(.*)\|)?(?:nm|SPECTRAL_NM_|SPECTRAL_NM|SPECTRAL_|NM_|R_)\d{3}$/],
10078 ['DENSITY', "$ns:ColorValues/$ns:ColorDensity/$ns:Density", [], qr/^(?:(.*)\|)?D_(?:RED|GREEN|BLUE|VIS)$/, [qw(RED GREEN BLUE VIS)]],
10079 ['XYZ', "$ns:ColorValues/$ns:ColorCIEXYZ", ["$ns:X", "$ns:Y", "$ns:Z"], qr/^(?:(.*)\|)?XYZ_[XYZ]$/, [qw(X Y Z)]],
10080 ['XYY', "$ns:ColorValues/$ns:ColorCIExyY", ["$ns:x", "$ns:y", "$ns:Y"], qr/^(?:(.*)\|)?XYY_(?:X|Y|CAPY)$/, [qw(_X _Y _CAPY)]],
10081 ['LAB', "$ns:ColorValues/$ns:ColorCIELab", ["$ns:L", "$ns:A", "$ns:B"], qr/^(?:(.*)\|)?LAB_[LAB]$/, [qw(L A B)]],
10082 ['LCH', "$ns:ColorValues/$ns:ColorCIELCh", ["$ns:L", "$ns:C", "$ns:H"], qr/^(?:(.*)\|)?LAB_[LCH]$/, [qw(L C H)]],
10083 ['DE', "$ns:ColorDifferenceValues/$ns:DeltaCIELab/$ns:dE", [], qr/^(?:(.*)\|)?LAB_DE$/],
10084 ['DE94', "$ns:ColorDifferenceValues/$ns:DeltaCIELab/$ns:dE94", [], qr/^(?:(.*)\|)?LAB_DE94$/],
10085 ['DECMC', "$ns:ColorDifferenceValues/$ns:DeltaCIELab/$ns:dEcmc", [], qr/^(?:(.*)\|)?LAB_CMC$/],
10086 ['DE2000', "$ns:ColorDifferenceValues/$ns:DeltaCIELab/$ns:dE2000", [], qr/^(?:(.*)\|)?LAB_2000$/],
10087 ];
10088  
10089 # following section builds operations array from column slice
10090 #
10091 # sort keys alphabetically
10092 0 @{$cols} = sort {$self->[1][0][$a] cmp $self->[1][0][$b]} @{$cols};
10093  
10094 # for each field
10095 0 for my $i (@{$cols}) {
10096
10097 # if key matches current class and prefix (prefix could be undefined)
10098 0 ▶ if (defined($class) && $self->[1][0][$i] =~ /$table->[$class][3]/ && (defined($prefix) ? $prefix : "\n") eq (defined($1) ? $1 : "\n")) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $class and $self->[1][0][$i] =~ /$table->[$class][3]/ and (defined $prefix ? $prefix : "\n") eq (defined $1 ? $1 : "\n")) { } 0 0 0
defined $prefix ? : 0 0 0
defined $1 ? : 0 0 0
Condition0%0/6
defined $class and $self->[1][0][$i] =~ /$table->[$class][3]/ and (defined $prefix ? $prefix : "\n") eq (defined $1 ? $1 : "\n")
!ll&&!rl&&r
000
defined $class and $self->[1][0][$i] =~ /$table->[$class][3]/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $class and $self->[1][0][$i] =~ /$table->[$class][3]/ and (defined $prefix ? $prefix : "\n") eq (defined $1 ? $1 : "\n")
defined $class $self->[1][0][$i] =~ /$table->[$class][3]/ (defined $prefix ? $prefix : "\n") eq (defined $1 ? $1 : "\n")
Truth table0%0/4
A and B and C
A= defined $classB= $self->[1][0][$i] =~ /$table->[$class][3]/C= (defined $prefix ? $prefix : "\n") eq (defined $1 ? $1 : "\n")
ABCresult
0XX0
10X0
1100
1111
10099
10100 # add index to current operation
10101 0 push(@{$ops->[-1][4]}, $i);
10102
10103 } else {
10104
10105 # for each data class
10106 0 for my $j (0 .. $#{$table}) {
10107
10108 # if key matches class
10109 0 ▶ if ($self->[1][0][$i] =~ /$table->[$j][3]/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->[1][0][$i] =~ /$table->[$j][3]/) { } 0 0 0
elsif ($j == $#{$table;}) { } 0 0 0
10110
10111 # save current prefix
10112 0 $prefix = $1;
10113
10114 # save current class
10115 0 $class = $j;
10116
10117 # add new operation
10118 0 push(@{$ops}, [$table->[$j][0], $prefix, $table->[$j][1], $table->[$j][2], [$i], {}, $j]);
10119
10120 # quit loop
10121 0 last;
10122
10123 # if no match found in table
10124 0 } elsif ($j == $#{$table}) {
10125
10126 # match prefix/key
10127 0 $self->[1][0][$i] =~ m/^(?:(.*)\|)?(.*)/;
10128
10129 # save matched values
10130 0 $prefix = $1;
10131 0 $key = $2;
10132
10133 # set current class
10134 0 $class = undef;
10135
10136 # if prefix defined, and not Target or ...Measurement, and key is SAMPLE_NAME
10137 0 ▶ if (defined($prefix) && $prefix !~ m/^Target$|Measurement$/ && $key =~ m/^SAMPLE_NAME$|^SampleName$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prefix and not $prefix =~ /^Target$|Measurement$/ and $key =~ /^SAMPLE_NAME$|^SampleName$/) { } 0 0 0
Condition0%0/6
defined $prefix and not $prefix =~ /^Target$|Measurement$/ and $key =~ /^SAMPLE_NAME$|^SampleName$/
!ll&&!rl&&r
000
defined $prefix and not $prefix =~ /^Target$|Measurement$/
!ll&&!rl&&r
000
MC/DC0%0/3
defined $prefix and not $prefix =~ /^Target$|Measurement$/ and $key =~ /^SAMPLE_NAME$|^SampleName$/
defined $prefix not $prefix =~ /^Target$|Measurement$/ $key =~ /^SAMPLE_NAME$|^SampleName$/
Truth table0%0/4
A and not(B) and C
A= defined $prefixB= not $prefix =~ /^Target$|Measurement$/C= $key =~ /^SAMPLE_NAME$|^SampleName$/
ABCresult
0XX0
10X0
1100
1111
10138
10139 # add special operation to set 'Object' 'Name' attribute to SAMPLE_NAME
10140 0 push(@{$ops}, ['TAG', $prefix, '', [], [], {'Name' => [$i]}, -1]);
10141
10142 } else {
10143
10144 # add Tag operation
10145 0 push(@{$ops}, ['TAG', $prefix, "$ns:TagCollection/$ns:Tag", [], [], {'Name' => $key, 'Value' => [$i]}, 100]);
10146
10147 }
10148
10149 }
10150
10151 }
10152
10153 }
10154
10155 }
10156  
10157 # following section sorts and verifies column slices, sets default prefixes and checks for multiple elements
10158 #
10159 # init loop variable
10160 0 %keys = ();
10161
10162 # for each array entry
10163 0 for my $t (@{$ops}) {
10164
10165 # if sort order is defined
10166 0 ▶ if (defined($table->[$t->[6]][4])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$table[$t->[6]][4]) 0 0 0
10167
10168 # arrange column indices in sort order
10169 0 @{$t->[4]} = map {my $end = $_; grep {$self->[1][0][$_] =~ m/$end$/} @{$t->[4]}} @{$table->[$t->[6]][4]};
10170
10171 }
10172
10173 # if class is SPECTRAL
10174 0 ▶ if ($t->[0] eq 'SPECTRAL') {
Branch: 3 branches
BranchTrueFalseTotal
if ($t->[0] eq 'SPECTRAL') { } 0 0 0
elsif ($t->[0] eq 'DENSITY') { } 0 0 0
elsif ($t->[0] eq 'NCLR') { } 0 0 0
10175
10176 # verify spectral slice
10177 0 ▶ (@{$t->[4]} == @{_spectral($self, $t->[1])}) || warn("invalid column slice - SPECTRAL class");
Branch: 1 branch
BranchTrueFalseTotal
@{$t->[4];} == @{_spectral($self, $t->[1]);} or warn "invalid column slice - SPECTRAL class" 0 0 0
10178
10179 # if class is DENSITY
10180 } elsif ($t->[0] eq 'DENSITY') {
10181
10182 # to be done
10183
10184 # if class is NCLR
10185 } elsif ($t->[0] eq 'NCLR') {
10186
10187 # match first key to get number of channels
10188 0 $self->[1][0][$t->[4][0]] =~ m/([2-9A-F])CLR_[1-9A-F]$/;
10189
10190 # verify nCLR slice
10191 0 ▶ (@{$t->[4]} == CORE::hex($1)) || warn("invalid column slice - NCLR class");
Branch: 1 branch
BranchTrueFalseTotal
@{$t->[4];} == CORE::hex $1 or warn "invalid column slice - NCLR class" 0 0 0
10192
10193 # all others
10194 } else {
10195
10196 # verify subpaths match column slice
10197 0 ▶ (@{$t->[4]} == @{$t->[3]} || (@{$t->[4]} == 1 && @{$t->[3]} == 0)) || warn("invalid column slice - $t->[0] class");
Branch: 1 branch
BranchTrueFalseTotal
@{$t->[4];} == @{$t->[3];} or @{$t->[4];} == 1 and @{$t->[3];} == 0 or warn "invalid column slice - $t->[0] class" 0 0 0
Condition0%0/6
@{$t->[4];} == @{$t->[3];} or @{$t->[4];} == 1 and @{$t->[3];} == 0
l!l&&r!l&&!r
000
@{$t->[4];} == 1 and @{$t->[3];} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
@{$t->[4];} == @{$t->[3];} or @{$t->[4];} == 1 and @{$t->[3];} == 0
@{$t->[4];} == @{$t->[3];} @{$t->[4];} == 1 @{$t->[3];} == 0
Truth table0%0/4
A or B and C
A= @{$t->[4];} == @{$t->[3];}B= @{$t->[4];} == 1C= @{$t->[3];} == 0
ABCresult
1XX1
0111
00X0
0100
10198
10199 }
10200
10201 # if prefix undefined
10202 0 ▶ if (! defined($t->[1])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t->[1]) 0 0 0
10203
10204 # if XPath contains 'ColorValues' or 'ColorDifferenceValues'
10205 0 ▶ if ($t->[2] =~ m/^$ns:(?:ColorValues|ColorDifferenceValues)\//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->[2] =~ m[^$ns:(?:ColorValues|ColorDifferenceValues)/]) { } 0 0 0
elsif ($t->[2] =~ m[^$ns:DeviceColorValues/]) { } 0 0 0
10206
10207 # set prefix to M0_Measurement
10208 0 $t->[1] = 'M0_Measurement';
10209
10210 # if XPath contains 'DeviceColorValues'
10211 } elsif ($t->[2] =~ m/^$ns:DeviceColorValues\//) {
10212
10213 # set prefix to Target
10214 0 $t->[1] = 'Target';
10215
10216 # all others
10217 } else {
10218
10219 # set prefix to '~~'
10220 0 $t->[1] = '~~';
10221
10222 }
10223
10224 }
10225
10226 # for 'ColorValues' or 'DeviceColorValues'
10227 0 ▶ if ($t->[2] =~ m/^$ns:(ColorValues|DeviceColorValues)\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->[2] =~ m[^$ns:(ColorValues|DeviceColorValues)/]) 0 0 0
10228
10229 # warn on multiple elements (not allowed by i1Profiler)
10230 0 ▶ print "warning: multiple $1 elements in CxF3 $t->[1] object\n" if ($keys{"$1/$t->[1]"}++ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $keys{"$1/$t->[1]"}++ == 1 0 0 0
10231
10232 }
10233
10234 }
10235  
10236 # following section groups operations by prefix
10237 #
10238 # sort by prefix, then by table index
10239 0 ▶ @{$ops} = sort {($a->[1] cmp $b->[1]) or ($a->[6] <=> $b->[6])} @{$ops};
Branch: 1 branch
BranchTrueFalseTotal
$ICC::Support::Chart::a->[1] cmp $ICC::Support::Chart::b->[1] or $ICC::Support::Chart::a->[6] <=> $ICC::Support::Chart::b->[6] 0 0 0
10240  
10241 # init loop variable
10242 0 $prefix = undef;
10243  
10244 # for each operation
10245 0 for my $t (@{$ops}) {
10246
10247 # if same prefix as last operation
10248 0 ▶ if (defined($prefix) && $prefix eq $t->[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $prefix and $prefix eq $t->[1]) { } 0 0 0
elsif ($t->[0] eq 'TAG' and $t->[1] eq '~~') { } 0 0 0
Condition0%0/3
defined $prefix and $prefix eq $t->[1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $prefix and $prefix eq $t->[1]
defined $prefix $prefix eq $t->[1]
Truth table0%0/3
A and B
A= defined $prefixB= $prefix eq $t->[1]
ABresult
0X0
100
111
10249
10250 # add operation to last group
10251 0 push(@{$groups->[-1]}, $t);
10252
10253 # if class is TAG and prefix is '~~'
10254 ▶ } elsif ($t->[0] eq 'TAG' && $t->[1] eq '~~') {
Condition0%0/3
$t->[0] eq "TAG" and $t->[1] eq "~~"
!ll&&!rl&&r
000
MC/DC0%0/2
$t->[0] eq "TAG" and $t->[1] eq "~~"
$t->[0] eq "TAG" $t->[1] eq "~~"
Truth table0%0/3
A and B
A= $t->[0] eq "TAG"B= $t->[1] eq "~~"
ABresult
0X0
100
111
10255
10256 # for each group
10257 0 for my $g (@{$groups}) {
10258
10259 # add operation
10260 0 push(@{$g}, $t);
10261
10262 }
10263
10264 # set prefix
10265 0 $prefix = undef;
10266
10267 # others
10268 } else {
10269
10270 # add new group
10271 0 push(@{$groups}, [$t]);
10272
10273 # set prefix
10274 0 $prefix = $t->[1];
10275
10276 }
10277
10278 }
10279  
10280 # return
10281 0 return($groups);
10282  
10283 }
10284  
10285 # make CxF3 ColorSpecification nodes
10286 # parameters: (object_reference, CxF3_root, CxF3_prefix, CxF3_namespace_URI, operations_array)
10287 sub _makeCxF3colorspec {
10288  
10289 # get parameters
10290 0 ▶ my ($self, $root, $ns, $nsURI, $ops) = @_;
Subroutine _makeCxF3colorspec: not called CC=34 SCAR=70.8
10291  
10292 # local variables
10293 0 my (@illum, @filter, $cscol, $template, $unknown);
10294 0 my (%table, %cspec, %hash, $keyword, $value, $source);
10295 0 my ($Id, $cs, @nodes, $node, $child, @wav);
10296 0 my ($parser, $frag, $std, $xpath);
10297  
10298 # illumination types
10299 0 @illum = qw(M0_Incandescent M1_Daylight M2_UVExcluded M3_Polarized);
10300  
10301 # filter types
10302 0 @filter = qw(Filter_None Filter_None Filter_UVExcluded Filter_None);
10303  
10304 # get the 'ColorSpecificationCollection' node
10305 0 ($cscol) = $root->findnodes("$ns:Resources/$ns:ColorSpecificationCollection");
10306  
10307 # get the 'ColorSpecification' node with Id = 'template'
10308 0 ($template) = $cscol->findnodes("$ns:ColorSpecification[\@Id='template']");
10309  
10310 # get the 'ColorSpecification' node with Id = 'Unknown'
10311 0 ($unknown) = $cscol->findnodes("$ns:ColorSpecification[\@Id='Unknown']");
10312  
10313 # make ASCII => CxF3 mapping table (from ISO 17972-1, Annex A)
10314 0 %table = (
10315 'MANUFACTURER' => "$ns:MeasurementSpec/$ns:Device/$ns:Manufacturer",
10316 'MODEL' => "$ns:MeasurementSpec/$ns:Device/$ns:Model",
10317 'SERIAL_NUMBER' => "$ns:MeasurementSpec/$ns:Device/$ns:SerialNumber",
10318 'MEASUREMENT_GEOMETRY' => "$ns:MeasurementSpec/$ns:GeometryChoice",
10319 'MEASUREMENT_SOURCE' => "$ns:MeasurementSpec/$ns:Device/$ns:DeviceIllumination",
10320 'FILTER' => "$ns:MeasurementSpec/$ns:Device/$ns:DeviceFilter",
10321 'POLARIZATION' => "$ns:MeasurementSpec/$ns:Device/$ns:DevicePolarization",
10322 'SAMPLE_BACKING' => "$ns:MeasurementSpec/$ns:Backing",
10323 'DEVCALSTD' => "$ns:MeasurementSpec/$ns:CalibrationStandard",
10324 );
10325  
10326 # for each group
10327 0 for my $group (@{$ops}) {
10328
10329 # for each operation
10330 0 for my $t (@{$group}) {
10331
10332 # if ColorValues (only ColorValues reference a ColorSpecification)
10333 0 ▶ if ($t->[2] =~ m/^$ns:ColorValues\//) {
Branch: 2 branches
BranchTrueFalseTotal
if ($t->[2] =~ m[^$ns:ColorValues/]) { } 0 0 0
elsif ($t->[2] =~ m[^$ns:DeviceColorValues/]) { } 0 0 0
10334
10335 # set Id to saved value, if defined, or add '_spec' to prefix
10336 # the ColorSpecification Id is saved in the Colorimetry array when reading a CxF3 file
10337 0 ▶ $Id = defined($self->[2][5][$t->[4][0]]) ? $self->[2][5][$t->[4][0]] : "$t->[1]\_spec";
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[2][5][$t->[4][0]] ? : 0 0 0
10338
10339 # set attribute hash
10340 0 $t->[5]{'ColorSpecification'} = $Id;
10341
10342 # if 'ColorSpecification' undefined
10343 0 ▶ if (! $cspec{$Id}++) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cspec{$Id}++) 0 0 0
10344
10345 # initialize keyword hash
10346 0 %hash = ();
10347
10348 # add cloned 'ColorSpecification' element to 'ColorSpecificationCollection'
10349 0 $cs = $cscol->appendChild($template->cloneNode(1));
10350
10351 # set the Id
10352 0 $cs->setAttribute('Id', $Id);
10353
10354 # if spectral data
10355 # there are three types of spectral data, reflective, transmissive and emissive
10356 # spectral data has a WavelengthRange node which contains the starting wavelength and increment
10357 0 ▶ if ($t->[2] =~ m/(Reflectance|Transmittance|Emissive)Spectrum$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->[2] =~ /(Reflectance|Transmittance|Emissive)Spectrum$/) { } 0 0 0
10358
10359 # get the 'MeasurementType' node
10360 0 ($node) = $cs->findnodes("$ns:MeasurementSpec/$ns:MeasurementType");
10361
10362 # if text content exists
10363 0 ▶ if ((($child) = $node->nonBlankChildNodes) && $child->nodeType == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (($child) = $node->nonBlankChildNodes and $child->nodeType == 3) 0 0 0
Condition0%0/3
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
!ll&&!rl&&r
000
MC/DC0%0/2
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
($child) = $node->nonBlankChildNodes $child->nodeType == 3
Truth table0%0/3
A and B
A= ($child) = $node->nonBlankChildNodesB= $child->nodeType == 3
ABresult
0X0
100
111
10364
10365 # update text content
10366 0 $child->setData("Spectrum_$1");
10367
10368 }
10369
10370 # for first two data columns
10371 0 for ($t->[4][0], $t->[4][1]) {
10372
10373 # match wavelength in format key
10374 0 $self->[1][0][$_] =~ m/(\d{3})$/;
10375
10376 # push to array
10377 0 push(@wav, $1);
10378
10379 }
10380
10381 # find the 'WavelengthRange' node
10382 0 ($node) = $cs->findnodes("$ns:MeasurementSpec/$ns:WavelengthRange");
10383
10384 # set the 'StartWL' attribute
10385 0 $node->setAttribute('StartWL', $wav[0]);
10386
10387 # set the 'Increment' attribute
10388 0 $node->setAttribute('Increment', $wav[1] - $wav[0]);
10389
10390 # set operation 'StartWL' attribute
10391 0 $t->[5]{'StartWL'} = $wav[0];
10392
10393 } else {
10394
10395 # find the 'WavelengthRange' node
10396 0 ($node) = $cs->findnodes("$ns:MeasurementSpec/$ns:WavelengthRange");
10397
10398 # unbind the node (used only with spectral data)
10399 0 $node->unbindNode();
10400
10401 }
10402
10403 # for each file header entry
10404 0 for (@{$self->[3]}) {
10405
10406 # get keyword, value and source
10407 0 ($keyword, $value, $source) = @{$_};
10408
10409 # strip quotes from value
10410 0 $value =~ s/^\"(.*)\"$/$1/;
10411
10412 # if source is ColorSpecification Id
10413 0 ▶ if (defined($source) && $source eq $Id) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source and $source eq $Id) 0 0 0
Condition0%0/3
defined $source and $source eq $Id
!ll&&!rl&&r
000
MC/DC0%0/2
defined $source and $source eq $Id
defined $source $source eq $Id
Truth table0%0/3
A and B
A= defined $sourceB= $source eq $Id
ABresult
0X0
100
111
10414
10415 # add keyword to hash
10416 0 $hash{$keyword}++;
10417
10418 # if keyword in table
10419 0 ▶ if (exists($table{$keyword})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $table{$keyword}) 0 0 0
10420
10421 # if XPath does not exist in ColorSpecification element
10422 0 ▶ if (! (($node) = $cs->findnodes($table{$keyword}))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($node) = $cs->findnodes($table{$keyword})) 0 0 0
10423
10424 # set node
10425 0 $node = $cs;
10426
10427 # initialize XPath
10428 0 $xpath = undef;
10429
10430 # for each segment
10431 0 for (split(/\//, $table{$keyword})) {
10432
10433 # add segment to XPath
10434 0 ▶ $xpath = defined($xpath) ? "$xpath/$_" : $_;
Branch: 1 branch
BranchTrueFalseTotal
defined $xpath ? : 0 0 0
10435
10436 # if XPath does not exist in ColorSpecification element
10437 0 ▶ if (! (($node) = $cs->findnodes($xpath))) {
Branch: 1 branch
BranchTrueFalseTotal
unless (($node) = $cs->findnodes($xpath)) 0 0 0
10438
10439 # add element for XPath segment
10440 0 $node = $node->appendChild(XML::LibXML::Element->new($_));
10441 0 $node->setNamespace($nsURI, $ns);
10442
10443 }
10444
10445 }
10446
10447 }
10448
10449 # get the first non-blank child node
10450 0 ($child) = $node->nonBlankChildNodes();
10451
10452 # make a parser object
10453 0 $parser = XML::LibXML->new();
10454
10455 # if value is an XML balanced chunk
10456 0 ▶ if ($value =~ m/</ && eval{$frag = $parser->parse_balanced_chunk($value)}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($value =~ /</ and eval { do { $frag = $parser->parse_balanced_chunk($value) } }) { } 0 0 0
elsif (not defined $child) { } 0 0 0
elsif ($child->nodeType == 3) { } 0 0 0
Condition0%0/3
$value =~ /</ and eval { do { $frag = $parser->parse_balanced_chunk($value) } }
!ll&&!rl&&r
000
MC/DC0%0/2
$value =~ /</ and eval { do { $frag = $parser->parse_balanced_chunk($value) } }
$value =~ /</ eval { do { $frag = $parser->parse_balanced_chunk($value) } }
Truth table0%0/3
A and B
A= $value =~ /</B= eval { do { $frag = $parser->parse_balanced_chunk($value) } }
ABresult
0X0
100
111
10457
10458 # get all element nodes
10459 0 @nodes = $frag->findnodes('//*');
10460
10461 # replace existing node
10462 0 $node->replaceNode($frag);
10463
10464 # set namespace of each element
10465 0 for (@nodes) {$_->setNamespace($nsURI, $ns)};
10466
10467 # if no child node
10468 } elsif (! defined($child)) {
10469
10470 # set text content to value
10471 0 $node->appendText($value);
10472
10473 # if child node is text type
10474 } elsif ($child->nodeType == 3) {
10475
10476 # modify existing text content
10477 0 $child->setData($value);
10478
10479 }
10480
10481 }
10482
10483 }
10484
10485 }
10486
10487 # match illumination standard in prefix (M0, M1, M2, M3)
10488 0 ▶ $std = ($t->[1] =~ m/^M([0-3])/) ? $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$t->[1] =~ /^M([0-3])/ ? : 0 0 0
10489
10490 # if 'MEASUREMENT_SOURCE' not a keyword
10491 0 ▶ if (! exists($hash{'MEASUREMENT_SOURCE'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hash{"MEASUREMENT_SOURCE"}) 0 0 0
10492
10493 # find the 'DeviceIllumination' node
10494 0 ($node) = $cs->findnodes("$ns:MeasurementSpec/$ns:Device/$ns:DeviceIllumination");
10495
10496 # if text content exists
10497 0 ▶ if ((($child) = $node->nonBlankChildNodes) && $child->nodeType == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (($child) = $node->nonBlankChildNodes and $child->nodeType == 3) 0 0 0
Condition0%0/3
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
!ll&&!rl&&r
000
MC/DC0%0/2
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
($child) = $node->nonBlankChildNodes $child->nodeType == 3
Truth table0%0/3
A and B
A= ($child) = $node->nonBlankChildNodesB= $child->nodeType == 3
ABresult
0X0
100
111
10498
10499 # update text content
10500 0 $child->setData($illum[$std]);
10501
10502 }
10503
10504 }
10505
10506 # if 'FILTER' not a keyword
10507 0 ▶ if (! exists($hash{'FILTER'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hash{"FILTER"}) 0 0 0
10508
10509 # find the 'DeviceFilter' node
10510 0 ($node) = $cs->findnodes("$ns:MeasurementSpec/$ns:Device/$ns:DeviceFilter");
10511
10512 # if text content exists
10513 0 ▶ if ((($child) = $node->nonBlankChildNodes) && $child->nodeType == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (($child) = $node->nonBlankChildNodes and $child->nodeType == 3) 0 0 0
Condition0%0/3
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
!ll&&!rl&&r
000
MC/DC0%0/2
($child) = $node->nonBlankChildNodes and $child->nodeType == 3
($child) = $node->nonBlankChildNodes $child->nodeType == 3
Truth table0%0/3
A and B
A= ($child) = $node->nonBlankChildNodesB= $child->nodeType == 3
ABresult
0X0
100
111
10514
10515 # update text content
10516 0 $child->setData($filter[$std]);
10517
10518 }
10519
10520 }
10521
10522 # if 'POLARIZATION' not a keyword and M3 standard
10523 0 ▶ if (! exists($hash{'POLARIZATION'}) && $std == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $hash{"POLARIZATION"} and $std == 3) 0 0 0
Condition0%0/3
not exists $hash{"POLARIZATION"} and $std == 3
!ll&&!rl&&r
000
MC/DC0%0/2
not exists $hash{"POLARIZATION"} and $std == 3
not exists $hash{"POLARIZATION"} $std == 3
Truth table0%0/3
not(A) and B
A= not exists $hash{"POLARIZATION"}B= $std == 3
ABresult
0X0
100
111
10524
10525 # get the 'Device' node
10526 0 ($node) = $cs->findnodes("$ns:MeasurementSpec/$ns:Device");
10527
10528 # add 'Polarization' node
10529 0 $node = $node->appendChild(XML::LibXML::Element->new("$ns:Polarization"));
10530 0 $node->appendText(XML::LibXML::Boolean->True);
10531 0 $node->setNamespace($nsURI, $ns);
10532
10533 }
10534
10535 }
10536
10537 # if 'DeviceColorValues'
10538 } elsif ($t->[2] =~ m/^$ns:DeviceColorValues\//) {
10539
10540 # set attributes hash
10541 0 $t->[5]{'ColorSpecification'} = 'Unknown';
10542
10543 # increment 'ColorSpecification' hash
10544 0 $cspec{'Unknown'}++;
10545
10546 }
10547
10548 }
10549
10550 }
10551  
10552 # unbind 'template' node
10553 0 $template->unbindNode();
10554  
10555 # unbind 'Unknown' node, if not referenced
10556 0 ▶ $unknown->unbindNode() if (! $cspec{'Unknown'});
Branch: 1 branch
BranchTrueFalseTotal
if not $cspec{"Unknown"} 0 0 0
10557  
10558 }
10559  
10560 # validate CxF3 document
10561 # prints warning and error info
10562 # parameters: (document_reference)
10563 sub _validateCxF3 {
10564  
10565 # get document reference
10566 0 ▶ my $doc = shift();
Subroutine _validateCxF3: not called CC=2 SCAR=17.9
10567  
10568 # load CxF3 schema
10569 0 state $xmlschema = XML::LibXML::Schema->new('location' => ICC::Shared::getICCPath('Templates/CxF3_Core.xsd'));
10570  
10571 # validate the document
10572 0 ▶ if (! defined(eval {$xmlschema->validate($doc)})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined eval { do { $xmlschema->validate($doc) } }) 0 0 0
10573
10574 # print warning on failure
10575 0 print "warning: invalid CxF3 document\n$@\n";
10576
10577 }
10578
10579 }
10580  
10581 # make patch set
10582 # supported hash keys: 'colorspace', 'template', 'sort', 'limit'
10583 # parameters: (object_reference, hash)
10584 # returns: (result)
10585 sub _makePatchSet {
10586  
10587 # get parameters
10588 0 ▶ my ($self, $hash) = @_;
Subroutine _makePatchSet: not called CC=44 SCAR=75.9
10589  
10590 # local variables
10591 0 my ($cs, $template, $sort, $tac, $n, $data, $eps);
10592 0 my (@fields, $loop, $limit, @inc, $init, $s, $code);
10593  
10594 # get the colorspace parameter
10595 0 ▶ (defined($cs = $hash->{'colorspace'})) || return('colorspace parameter missing');
Branch: 1 branch
BranchTrueFalseTotal
defined($cs = $hash->{"colorspace"}) or return "colorspace parameter missing" 0 0 0
10596  
10597 # get the template parameter
10598 0 ▶ (defined($template = $hash->{'template'})) || return('template parameter missing');
Branch: 1 branch
BranchTrueFalseTotal
defined($template = $hash->{"template"}) or return "template parameter missing" 0 0 0
10599  
10600 # get the sort parameter (optional)
10601 0 $sort = $hash->{'sort'};
10602  
10603 # get the ink limit parameter (optional)
10604 0 $tac = $hash->{'limit'};
10605  
10606 # get number of elements in first group
10607 0 $n = @{$template->[0]};
10608  
10609 # for each group
10610 0 for my $i (0 .. $#{$template}) {
10611
10612 # verify number of elements
10613 0 ▶ ($n == @{$template->[$i]}) || return("wrong number of elements in template group $i");
Branch: 1 branch
BranchTrueFalseTotal
$n == @{$template->[$i];} or return "wrong number of elements in template group $i" 0 0 0
10614
10615 # verify number of array references
10616 0 ▶ ($n == grep {ref() eq 'ARRAY'} @{$template->[$i]}) || return("non-array element(s) in template group $i");
Branch: 1 branch
BranchTrueFalseTotal
$n == grep({ref $_ eq "ARRAY";} @{$$template[$i];}) or return "non-array element(s) in template group $i" 0 0 0
10617
10618 # for each element
10619 0 for my $j (0 .. $#{$template->[$i]}) {
10620
10621 # verify element contains only numeric scalars
10622 0 ▶ (@{$template->[$i][$j]} > 0 && @{$template->[$i][$j]} == grep {! ref() && Scalar::Util::looks_like_number($_)} @{$template->[$i][$j]}) || return("non-numeric element in template group $i, $j");
Branch: 2 branches
BranchTrueFalseTotal
@{$template->[$i][$j];} > 0 and @{$template->[$i][$j];} == grep({not ref $_ and &Scalar::Util::looks_like_number($_);} @{$$template[$i][$j];}) or return "non-numeric element in template group $i, $j" 0 0 0
not ref $_ and &Scalar::Util::looks_like_number($_) 0 0 0
Condition0%0/3
@{$template->[$i][$j];} > 0 and @{$template->[$i][$j];} == grep({not ref $_ and &Scalar::Util::looks_like_number($_);} @{$$template[$i][$j];})
!ll&&!rl&&r
000
MC/DC0%0/2
@{$template->[$i][$j];} > 0 and @{$template->[$i][$j];} == grep({not ref $_ and &Scalar::Util::looks_like_number($_);} @{$$template[$i][$j];})
@{$template->[$i][$j];} > 0 @{$template->[$i][$j];} == grep({not ref $_ and &Scalar::Util::looks_like_number($_);} @{$$template[$i][$j];})
Truth table0%0/3
A and B
A= @{$template->[$i][$j];} > 0B= @{$template->[$i][$j];} == grep({not ref $_ and &Scalar::Util::looks_like_number($_);} @{$$template[$i][$j];})
ABresult
0X0
100
111
10623
10624 }
10625
10626 }
10627  
10628 # if RGB colorspace
10629 0 ▶ if ($cs eq 'RGB') {
Branch: 4 branches
BranchTrueFalseTotal
if ($cs eq 'RGB') { } 0 0 0
elsif ($cs eq 'CMYK') { } 0 0 0
elsif ($cs eq 'nCLR') { } 0 0 0
elsif ($cs eq 'Lab') { } 0 0 0
10630
10631 # verify number of channels
10632 0 ▶ ($n == 3) || return('wrong number of template elements for RGB colorspace');
Branch: 1 branch
BranchTrueFalseTotal
$n == 3 or return "wrong number of template elements for RGB colorspace" 0 0 0
10633
10634 # set fields
10635 0 @fields = qw(RGB_R RGB_G RGB_B);
10636
10637 # if CMYK colorspace
10638 } elsif ($cs eq 'CMYK') {
10639
10640 # verify number of channels
10641 0 ▶ ($n == 4) || return('wrong number of template elements for CMYK colorspace');
Branch: 1 branch
BranchTrueFalseTotal
$n == 4 or return "wrong number of template elements for CMYK colorspace" 0 0 0
10642
10643 # set fields
10644 0 @fields = qw(CMYK_C CMYK_M CMYK_Y CMYK_K);
10645
10646 # if nCLR colorspace
10647 } elsif ($cs eq 'nCLR') {
10648
10649 # verify number of channels
10650 0 ▶ ($n > 0 && $n < 16) || return('wrong number of template elements for nCLR colorspace');
Branch: 1 branch
BranchTrueFalseTotal
$n > 0 and $n < 16 or return "wrong number of template elements for nCLR colorspace" 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
10651
10652 # set fields
10653 0 @fields = map {$n . "CLR_$_"} (1 .. $n);
10654
10655 # if L*a*b* colorspace
10656 } elsif ($cs eq 'Lab') {
10657
10658 # verify number of channels
10659 0 ▶ ($n == 3) || return('wrong number of template elements for L*a*b* colorspace');
Branch: 1 branch
BranchTrueFalseTotal
$n == 3 or return "wrong number of template elements for L*a*b* colorspace" 0 0 0
10660
10661 # set fields
10662 0 @fields = qw(LAB_L LAB_A LAB_B);
10663
10664 } else {
10665
10666 # error
10667 0 return('invalid colorspace parameter');
10668
10669 }
10670  
10671 # make loop variable list
10672 0 $loop = join(', ', map {"\$i$_"} (0 .. $n - 1));
10673  
10674 # make initial code fragment
10675 0 $init = "\$data->[\$s++] = [$loop]";
10676  
10677 # initialize index
10678 0 $s = 0;
10679  
10680 # for each group
10681 0 for my $i (0 .. $#{$template}) {
10682
10683 # copy initial code fragment
10684 0 $code = $init;
10685
10686 # for each device channel (in reverse order)
10687 0 for my $j (reverse(0 .. $#{$template->[$i]})) {
10688
10689 # add loop code to fragment
10690 0 $code = "for my \$i$j (" . join(', ', @{$template->[$i][$j]}) . ") {$code}";
10691
10692 }
10693
10694 # evaluate code fragment
10695 0 eval($code);
10696
10697 }
10698  
10699 # if ink limit defined and color space is CMYK or nCLR
10700 0 ▶ if (defined($tac) && ($cs eq 'CMYK' || $cs eq 'nCLR')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tac and $cs eq "CMYK" || $cs eq "nCLR") 0 0 0
Condition0%0/6
defined $tac and $cs eq "CMYK" || $cs eq "nCLR"
!ll&&!rl&&r
000
$cs eq "CMYK" or $cs eq "nCLR"
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $tac and $cs eq "CMYK" || $cs eq "nCLR"
defined $tac $cs eq "CMYK" $cs eq "nCLR"
Truth table0%0/4
A and B or C
A= defined $tacB= $cs eq "CMYK"C= $cs eq "nCLR"
ABCresult
0XX0
1000
11X1
1011
10701
10702 # compute max comparison error
10703 0 $eps = 1E-12;
10704
10705 # verify ink limit is a number
10706 0 ▶ if (! ref($tac) && Scalar::Util::looks_like_number($tac)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $tac and &Scalar::Util::looks_like_number($tac)) { } 0 0 0
Condition0%0/3
not ref $tac and &Scalar::Util::looks_like_number($tac)
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $tac and &Scalar::Util::looks_like_number($tac)
not ref $tac &Scalar::Util::looks_like_number($tac)
Truth table0%0/3
not(A) and B
A= not ref $tacB= &Scalar::Util::looks_like_number($tac)
ABresult
0X0
100
111
10707
10708 # for each patch
10709 0 for (@{$data}) {
10710
10711 # add the total ink value
10712 0 push(@{$_}, List::Util::sum(@{$_}));
10713
10714 }
10715
10716 # make sort code fragment (sorts in ascending order by columns K ... total_ink_value)
10717 0 $code = '@{$data} = sort {' . join(' || ', map {"\$a->[$_] <=> \$b->[$_]"} (3 .. $n)) . '} @{$data}';
10718
10719 # sort data
10720 0 eval($code);
10721
10722 # for each patch
10723 0 for my $i (0 .. $#{$data}) {
10724
10725 # undefine limit if new group (different black or spot values)
10726 0 ▶ undef($limit) if (grep {$data->[$i][$_] != $data->[$i ? $i - 1 : 0][$_]} (3 .. $n - 1));
Branch: 2 branches
BranchTrueFalseTotal
if grep {$data->[$i][$_] != $$data[$i ? $i - 1 : 0][$_];} 3 .. $n - 1 0 0 0
$i ? : 0 0 0
10727
10728 # select patch if limit undefined or total ink <= limit or a CMY corner point
10729 0 ▶ push(@inc, [@{$data->[$i]}[0 .. $n - 1]]) if (! defined($limit) || ($data->[$i][-1] - $limit <= $eps) || ((grep {$data->[$i][$_] == 0} (0 .. 2)) && (grep {$data->[$i][$_] == 100} (0 .. 2))));
Branch: 1 branch
BranchTrueFalseTotal
if not defined $limit or $data->[$i][-1] - $limit <= $eps or grep {$data->[$i][$_] == 0;} 0..2 and grep {$data->[$i][$_] == 100;} 0..2 0 0 0
Condition0%0/9
not defined $limit or $data->[$i][-1] - $limit <= $eps or grep {$data->[$i][$_] == 0;} 0..2 and grep {$data->[$i][$_] == 100;} 0..2
l!l&&r!l&&!r
000
not defined $limit or $data->[$i][-1] - $limit <= $eps
l!l&&r!l&&!r
000
grep {$data->[$i][$_] == 0;} 0..2 and grep {$data->[$i][$_] == 100;} 0..2
!ll&&!rl&&r
000
MC/DC0%0/4
not defined $limit or $data->[$i][-1] - $limit <= $eps or grep {$data->[$i][$_] == 0;} 0..2 and grep {$data->[$i][$_] == 100;} 0..2
not defined $limit $data->[$i][-1] - $limit <= $eps grep {$data->[$i][$_] == 0;} 0..2 grep {$data->[$i][$_] == 100;} 0..2
Truth table0%0/5
not(A) or B or C and D
A= not defined $limitB= $data->[$i][-1] - $limit <= $epsC= grep {$data->[$i][$_] == 0;} 0..2D= grep {$data->[$i][$_] == 100;} 0..2
ABCDresult
1XXX1
01XX1
00111
000X0
00100
10730
10731 # set limit if undefined and total ink > TAC
10732 0 ▶ $limit = $data->[$i][-1] if (! defined($limit) && $data->[$i][-1] - $tac > $eps);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $limit and $data->[$i][-1] - $tac > $eps 0 0 0
Condition0%0/3
not defined $limit and $data->[$i][-1] - $tac > $eps
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $limit and $data->[$i][-1] - $tac > $eps
not defined $limit $data->[$i][-1] - $tac > $eps
Truth table0%0/3
not(A) and B
A= not defined $limitB= $data->[$i][-1] - $tac > $eps
ABresult
0X0
100
111
10733
10734 }
10735
10736 # set data to selected patches
10737 0 $data = \@inc;
10738
10739 } else {
10740
10741 # display warning
10742 0 carp("invalid ink limit parameter, ink limiting failed\n");
10743
10744 }
10745
10746 }
10747  
10748 # if sort parameter defined
10749 0 ▶ if (defined($sort)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sort) 0 0 0
10750
10751 # verify sort parameter is an array of integer scalars
10752 0 ▶ if (ref($sort) eq 'ARRAY' && @{$sort} == grep {! ref() && Scalar::Util::looks_like_number($_) && $_ == int($_) && abs($_) > 0 && abs($_) <= $n} @{$sort}) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $sort eq 'ARRAY' and @{$sort;} == grep({not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_ and abs $_ > 0 and abs $_ <= $n;} @{$sort;})) { } 0 0 0
not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_ and abs $_ > 0 and abs $_ <= $n 0 0 0
Condition0%0/12
ref $sort eq "ARRAY" and @{$sort;} == grep({not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_ and abs $_ > 0 and abs $_ <= $n;} @{$sort;})
!ll&&!rl&&r
000
not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_ and abs $_ > 0
!ll&&!rl&&r
000
not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_
!ll&&!rl&&r
000
not ref $_ and &Scalar::Util::looks_like_number($_)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $sort eq "ARRAY" and @{$sort;} == grep({not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_ and abs $_ > 0 and abs $_ <= $n;} @{$sort;})
ref $sort eq "ARRAY" @{$sort;} == grep({not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_ and abs $_ > 0 and abs $_ <= $n;} @{$sort;})
MC/DC0%0/4
not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_ and abs $_ > 0
not ref $_ &Scalar::Util::looks_like_number($_) $_ == int $_ abs $_ > 0
Truth table0%0/3
A and B
A= ref $sort eq "ARRAY"B= @{$sort;} == grep({not ref $_ and &Scalar::Util::looks_like_number($_) and $_ == int $_ and abs $_ > 0 and abs $_ <= $n;} @{$sort;})
ABresult
0X0
100
111
Truth table0%0/5
not(A) and B and C and D
A= not ref $_B= &Scalar::Util::looks_like_number($_)C= $_ == int $_D= abs $_ > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
10753
10754 # make sort code fragment
10755 0 ▶ $code = '@{$data} = sort {' . join(' || ', map {my $dir = m/-/; my $col = abs($_) - 1; $dir ? "\$b->[$col] <=> \$a->[$col]" : "\$a->[$col] <=> \$b->[$col]"} @{$sort}) . '} @{$data}';
Branch: 1 branch
BranchTrueFalseTotal
$dir ? : 0 0 0
10756
10757 # evaluate code fragment
10758 0 eval($code);
10759
10760 } else {
10761
10762 # display warning
10763 0 carp("invalid sort parameter, sorting failed\n");
10764
10765 }
10766
10767 }
10768  
10769 # add format fields
10770 0 unshift(@{$data}, [@fields]);
10771  
10772 # set object reference
10773 0 $self->[1] = $data;
10774  
10775 # return
10776 0 return();
10777  
10778 }
10779  
10780 # make Time::Piece object from text string
10781 # parses most common date/time notations
10782 # no object returned if parsing fails
10783 # parameter: (string -or- value)
10784 # returns: (object)
10785 sub _makeTimePiece {
10786  
10787 # get parameter
10788 0 ▶ my $str = shift();
Subroutine _makeTimePiece: not called CC=27 SCAR=66.3
10789  
10790 # local variables
10791 0 my ($parse, $fmt, $hr, $sec, $month);
10792  
10793 # if a numeric value (Unix time)
10794 0 ▶ if (Scalar::Util::looks_like_number($str)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Scalar::Util::looks_like_number($str)) { } 0 0 0
10795
10796 # return Time::Piece object from Unix time
10797 0 return(scalar(localtime($str)));
10798
10799 } else {
10800
10801 # if UTC offset matched (time string ends in '+/-hh:mm', '+/-hhmm', or '+/-hh')
10802 0 ▶ if ($str =~ s/(T[\d:]+)([+-]\d{2}):?(\d{2})?/$1/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ s/(T[\d:]+)([+-]\d{2}):?(\d{2})?/$1/) { } 0 0 0
elsif ($str =~ s/(T[\d:]+)Z/$1/) { } 0 0 0
10803
10804 # set UTC offset to matched value
10805 0 ▶ $parse = $2 . (defined($3) ? $3 : '00');
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 0 0 0
10806
10807 # set UTC format
10808 0 $fmt = '%z';
10809
10810 # if Zulu time (time string ends in 'Z')
10811 } elsif ($str =~ s/(T[\d:]+)Z/$1/) {
10812
10813 # set UTC offset to 0
10814 0 $parse = '+0000';
10815
10816 # set UTC format
10817 0 $fmt = '%z';
10818
10819 } else {
10820
10821 # initialize strings
10822 0 $parse = $fmt = '';
10823
10824 }
10825
10826 # if time matched (time string 'hh:mm' or 'hh:mm:ss', 'AM' or 'PM' optional)
10827 0 ▶ if ($str =~ s/(\d{1,2})(:\d{1,2})(:\d{1,2})?\s*(AM|PM)?//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ s/(\d{1,2})(:\d{1,2})(:\d{1,2})?\s*(AM|PM)?//) 0 0 0
10828
10829 # if 12 AM
10830 0 ▶ if (defined($4) && $4 eq 'AM' && $1 == 12) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $4 and $4 eq 'AM' and $1 == 12) { } 0 0 0
elsif (defined $4 and $4 eq 'PM' and $1 > 0 and $1 < 12) { } 0 0 0
Condition0%0/6
defined $4 and $4 eq "AM" and $1 == 12
!ll&&!rl&&r
000
defined $4 and $4 eq "AM"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $4 and $4 eq "AM" and $1 == 12
defined $4 $4 eq "AM" $1 == 12
Truth table0%0/4
A and B and C
A= defined $4B= $4 eq "AM"C= $1 == 12
ABCresult
0XX0
10X0
1100
1111
10831
10832 # set hour
10833 0 $hr = 0;
10834
10835 # if 1 PM - 11 PM
10836 ▶ } elsif (defined($4) && $4 eq 'PM' && $1 > 0 && $1 < 12) {
Condition0%0/9
defined $4 and $4 eq "PM" and $1 > 0 and $1 < 12
!ll&&!rl&&r
000
defined $4 and $4 eq "PM" and $1 > 0
!ll&&!rl&&r
000
defined $4 and $4 eq "PM"
!ll&&!rl&&r
000
MC/DC0%0/4
defined $4 and $4 eq "PM" and $1 > 0 and $1 < 12
defined $4 $4 eq "PM" $1 > 0 $1 < 12
Truth table0%0/5
A and B and C and D
A= defined $4B= $4 eq "PM"C= $1 > 0D= $1 < 12
ABCDresult
0XXX0
10XX0
110X0
11100
11111
10837
10838 # set hour
10839 0 $hr = $1 + 12;
10840
10841 } else {
10842
10843 # set hour
10844 0 $hr = $1;
10845
10846 }
10847
10848 # set seconds
10849 0 ▶ $sec = defined($3) ? $3 : ':00';
Branch: 1 branch
BranchTrueFalseTotal
defined $3 ? : 0 0 0
10850
10851 # add time string
10852 0 $parse = "T$hr$2$sec$parse";
10853
10854 # add time format
10855 0 $fmt = "T%T$fmt";
10856
10857 }
10858
10859 # if three number date matched
10860 0 ▶ if ($str =~ m/(\d{1,4})[\/-](\d{1,2})[\/-](\d{1,4})/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ m[(\d{1,4})[/-](\d{1,2})[/-](\d{1,4})]) { } 0 0 0
elsif (uc($str) =~ /(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)/) { } 0 0 0
10861
10862 # if first value > 99
10863 0 ▶ if ($1 > 99) {
Branch: 2 branches
BranchTrueFalseTotal
if ($1 > 99) { } 0 0 0
elsif ($3 > 99) { } 0 0 0
10864
10865 # add date string
10866 0 $parse = "$1-$2-$3$parse";
10867
10868 # if last value > 99
10869 } elsif ($3 > 99) {
10870
10871 # add date string
10872 0 $parse = "$3-$1-$2$parse";
10873
10874 # last value is two digit year
10875 } else {
10876
10877 # add date string
10878 0 ▶ $parse = ($3 > 68 ? 1900 + $3 : 2000 + $3) . "-$1-$2$parse";
Branch: 1 branch
BranchTrueFalseTotal
$3 > 68 ? : 0 0 0
10879
10880 }
10881
10882 # add date format
10883 0 $fmt = "%Y-%m-%d$fmt";
10884
10885 # if text month matched
10886 } elsif (uc($str) =~ m/(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC)/) {
10887
10888 # save month
10889 0 $month = $1;
10890
10891 # if two numbers matched
10892 0 ▶ if ($str =~ m/(\d{1,4})[^\d]+(\d{1,4})/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($str =~ /(\d{1,4})[^\d]+(\d{1,4})/) { } 0 0 0
elsif ($str =~ /(\d{1,4})/) { } 0 0 0
10893
10894 # if first value > 99
10895 0 ▶ if ($1 > 99) {
Branch: 2 branches
BranchTrueFalseTotal
if ($1 > 99) { } 0 0 0
elsif ($2 > 99) { } 0 0 0
10896
10897 # add date string
10898 0 $parse = "$1-$month-$2$parse";
10899
10900 # if last value > 99
10901 } elsif ($2 > 99) {
10902
10903 # add date string
10904 0 $parse = "$2-$month-$1$parse";
10905
10906 # last value is two digit year
10907 } else {
10908
10909 # add date string
10910 0 ▶ $parse = ($2 > 68 ? 1900 + $2 : 2000 + $2) . "/$month/$1$parse";
Branch: 1 branch
BranchTrueFalseTotal
$2 > 68 ? : 0 0 0
10911
10912 }
10913
10914 # if one number matched
10915 } elsif ($str =~ m/(\d{1,4})/) {
10916
10917 # if value > 99
10918 0 ▶ if ($1 > 99) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 > 99) { } 0 0 0
10919
10920 # add date string
10921 0 $parse = "$1-$month-1$parse";
10922
10923 } else {
10924
10925 # add date string
10926 0 ▶ $parse = ($1 > 68 ? 1900 + $1 : 2000 + $1) . "/$month/1$parse";
Branch: 1 branch
BranchTrueFalseTotal
$1 > 68 ? : 0 0 0
10927
10928 }
10929
10930 }
10931
10932 # add date format
10933 0 $fmt = "%Y-%b-%d$fmt";
10934
10935 }
10936
10937 # return Time::Piece object, if string parsed successfully
10938 0 ▶ return(Time::Piece->strptime($parse, $fmt)) if (length($parse));
Branch: 1 branch
BranchTrueFalseTotal
if length $parse 0 0 0
10939
10940 }
10941
10942 }
10943  
10944 # get file list
10945 # uses Perl 'bsd_glob' function
10946 # parameter: (path)
10947 # returns: (ref_to_file_list)
10948 sub _files {
10949  
10950 # get path
10951 21 ▶ my $path = shift();
Subroutine _files: called CC=3 SCAR=11.0
10952  
10953 # get list of files and/or directories
10954 21 my @files = grep {-e} File::Glob::bsd_glob($path);
10955  
10956 # if list is just one directory
10957 21 ▶ if (@files == 1 && -d $files[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@files == 1 and -d $files[0]) { } 2 19 21
Condition66%2/3
@files == 1 and -d $files[0]
!ll&&!rl&&r
0192
MC/DC50%1/2
@files == 1 and -d $files[0]
@files == 1 -d $files[0]
Truth table66%2/3
A and B
A= @files == 1B= -d $files[0]
ABresult
0X0
100
111
10958
10959 # get files in that directory
10960 2 @files = grep {-f} File::Glob::bsd_glob("$path/*");
10961
10962 } else {
10963
10964 # filter the files
10965 19 @files = grep {-f} @files;
10966
10967 }
10968  
10969 # return file list
10970 21 return(\@files);
10971  
10972 }
10973  
10974 # compute Mahalanobis distance
10975 # assumes parameters are valid
10976 # parameters: (vector1, vector2, inverse_covariance_matrix)
10977 # returns: (distance)
10978 sub _mahal {
10979  
10980 # get parameters
10981 0 ▶ my ($x, $y, $sinv) = @_;
Subroutine _mahal: not called CC=2 SCAR=17.9
10982  
10983 # local variables
10984 0 my ($d, $dT);
10985  
10986 # for each dimension
10987 0 for my $i (0 .. $#{$x}) {
10988
10989 # save difference
10990 0 $d->[0][$i] = $dT->[$i][0] = $x->[$i] - $y->[$i];
10991
10992 }
10993  
10994 # bless matrices
10995 0 bless($d, 'Math::Matrix');
10996 0 bless($dT, 'Math::Matrix');
10997  
10998 # return Mahalanobis distance
10999 0 return(sqrt(($d * $sinv * $dT)->[0][0]));
11000  
11001 }
11002  
11003 # get L*a*b* encoding code refs
11004 # parameter: (object_reference, hash)
11005 # returns: (get_code_ref, set_code_ref)
11006 sub _lab_encoding {
11007  
11008 # get object reference
11009 29 ▶ my ($self, $hash) = @_;
Subroutine _lab_encoding: called CC=8 SCAR=40.9
11010  
11011 # local variable
11012 29 my ($encode);
11013  
11014 # get encoding parameter from hash
11015 29 $encode = $hash->{'encoding'};
11016  
11017 # if encoding parameter undefined
11018 29 ▶ if (! defined($encode)) {
Branch: 7 branches
BranchTrueFalseTotal
if (not defined $encode) { } 29 0 29
elsif ($encode == 0) { } 0 0 0
elsif ($encode == 1) { } 0 0 0
elsif ($encode == 2) { } 0 0 0
elsif ($encode == 3) { } 0 0 0
elsif ($encode == 4) { } 0 0 0
elsif ($encode == 5) { } 0 0 0
11019
11020 # return code refs (identity)
11021 29 ▶ return(sub {@_}, sub {@_});
Subroutine __ANON__: called CC=1 SCAR=0.0
11022
11023 # if encoding is 8/16-bit ICC CIELAB
11024 } elsif ($encode == 0) {
11025
11026 # return code refs
11027 0 ▶ return(sub {defined($_[0]) ? $_[0] / 100 : $_[0], defined($_[1]) ? ($_[1] + 128)/255 : $_[1], defined($_[2]) ? ($_[2] + 128)/255 : $_[2]},
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11028 0 ▶ sub {defined($_[0]) ? $_[0] * 100 : $_[0], defined($_[1]) ? $_[1] * 255 - 128 : $_[1], defined($_[2]) ? $_[2] * 255 - 128 : $_[2]});
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11029
11030 # if encoding is 16-bit ICC legacy L*a*b*
11031 } elsif ($encode == 1) {
11032
11033 # return code refs
11034 0 ▶ return(sub {defined($_[0]) ? $_[0] * 256/25700 : $_[0], defined($_[1]) ? ($_[1] + 128) * 256/65535 : $_[1], defined($_[2]) ? ($_[2] + 128) * 256/65535 : $_[2]},
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11035 0 ▶ sub {defined($_[0]) ? $_[0] * 25700/256 : $_[0], defined($_[1]) ? $_[1] * 65535/256 - 128 : $_[1], defined($_[2]) ? $_[2] * 65535/256 - 128 : $_[2]});
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11036
11037 # if encoding is 16-bit EFI/Monaco L*a*b*
11038 } elsif ($encode == 2) {
11039
11040 # return code refs
11041 0 ▶ return(sub {defined($_[0]) ? $_[0]/100 : $_[0], defined($_[1]) ? ($_[1] + 128) * 256/65535 : $_[1], defined($_[2]) ? ($_[2] + 128) * 256/65535 : $_[2]},
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11042 0 ▶ sub {defined($_[0]) ? $_[0] * 100 : $_[0], defined($_[1]) ? $_[1] * 65535/256 - 128 : $_[1], defined($_[2]) ? $_[2] * 65535/256 - 128 : $_[2]});
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11043
11044 # if encoding is L*a*b*
11045 } elsif ($encode == 3) {
11046
11047 # return code refs (identity)
11048 0 ▶ return(sub {@_}, sub {@_});
Subroutine __ANON__: not called CC=1 SCAR=6.9
11049
11050 # if encoding is LxLyLz
11051 } elsif ($encode == 4) {
11052
11053 # return code refs
11054 0 ▶ return(sub {if (defined($_[0]) && defined($_[1]) && defined($_[2])) {$_[0] + 116 * $_[1]/500, $_[0], $_[0] - 116 * $_[2]/200} else {@_}},
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and defined $_[1] and defined $_[2]) { } 0 0 0
Condition0%0/6
defined $_[0] and defined $_[1] and defined $_[2]
!ll&&!rl&&r
000
defined $_[0] and defined $_[1]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] and defined $_[1] and defined $_[2]
defined $_[0] defined $_[1] defined $_[2]
Truth table0%0/4
A and B and C
A= defined $_[0]B= defined $_[1]C= defined $_[2]
ABCresult
0XX0
10X0
1100
1111
11055 0 ▶ sub {if (defined($_[0]) && defined($_[1]) && defined($_[2])) {$_[1], 500 * ($_[0] - $_[1])/116, 200 * ($_[1] - $_[2])/116} else {@_}});
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and defined $_[1] and defined $_[2]) { } 0 0 0
Condition0%0/6
defined $_[0] and defined $_[1] and defined $_[2]
!ll&&!rl&&r
000
defined $_[0] and defined $_[1]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] and defined $_[1] and defined $_[2]
defined $_[0] defined $_[1] defined $_[2]
Truth table0%0/4
A and B and C
A= defined $_[0]B= defined $_[1]C= defined $_[2]
ABCresult
0XX0
10X0
1100
1111
11056
11057 # if encoding is unit LxLyLz
11058 } elsif ($encode == 5) {
11059
11060 # return code refs
11061 0 ▶ return(sub {if (defined($_[0]) && defined($_[1]) && defined($_[2])) {map {$_/100} ($_[0] + 116 * $_[1]/500, $_[0], $_[0] - 116 * $_[2]/200)} else {@_}},
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and defined $_[1] and defined $_[2]) { } 0 0 0
Condition0%0/6
defined $_[0] and defined $_[1] and defined $_[2]
!ll&&!rl&&r
000
defined $_[0] and defined $_[1]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] and defined $_[1] and defined $_[2]
defined $_[0] defined $_[1] defined $_[2]
Truth table0%0/4
A and B and C
A= defined $_[0]B= defined $_[1]C= defined $_[2]
ABCresult
0XX0
10X0
1100
1111
11062 0 ▶ sub {if (defined($_[0]) && defined($_[1]) && defined($_[2])) {map {$_ * 100} ($_[1], 500 * ($_[0] - $_[1])/116, 200 * ($_[1] - $_[2])/116)} else {@_}});
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_[0] and defined $_[1] and defined $_[2]) { } 0 0 0
Condition0%0/6
defined $_[0] and defined $_[1] and defined $_[2]
!ll&&!rl&&r
000
defined $_[0] and defined $_[1]
!ll&&!rl&&r
000
MC/DC0%0/3
defined $_[0] and defined $_[1] and defined $_[2]
defined $_[0] defined $_[1] defined $_[2]
Truth table0%0/4
A and B and C
A= defined $_[0]B= defined $_[1]C= defined $_[2]
ABCresult
0XX0
10X0
1100
1111
11063
11064 } else {
11065
11066 # error
11067 0 croak('invalid L*a*b* encoding');
11068
11069 }
11070  
11071 }
11072  
11073 # get XYZ encoding code refs
11074 # assumes there are XYZ columns
11075 # parameter: (object_reference, column_slice, [hash])
11076 # returns: (get_code_ref, set_code_ref)
11077 sub _xyz_encoding {
11078  
11079 # get object reference
11080 23 ▶ my ($self, $cols, $hash) = @_;
Subroutine _xyz_encoding: called CC=12 SCAR=48.2
11081  
11082 # local variable
11083 23 my ($encode, $wtpt);
11084  
11085 # get encoding parameter from hash
11086 23 $encode = $hash->{'encoding'};
11087  
11088 # if encoding parameter undefined
11089 23 ▶ if (! defined($encode)) {
Branch: 7 branches
BranchTrueFalseTotal
if (not defined $encode) { } 23 0 23
elsif ($encode eq 'L*' or $encode == 4) { } 0 0 0
elsif ($encode == 7) { } 0 0 0
elsif ($encode == 8) { } 0 0 0
elsif ($encode == 9) { } 0 0 0
elsif ($encode == 10) { } 0 0 0
elsif ($encode == 11) { } 0 0 0
11090
11091 # return code refs (identity)
11092 23 ▶ return(sub {@_}, sub {@_});
Subroutine __ANON__: called CC=1 SCAR=0.0
11093
11094 # if encoding is L*
11095 ▶ } elsif ($encode eq 'L*' || $encode == 4) {
Condition0%0/3
$encode eq "L*" or $encode == 4
l!l&&r!l&&!r
000
MC/DC0%0/2
$encode eq "L*" or $encode == 4
$encode eq "L*" $encode == 4
Truth table0%0/3
A or B
A= $encode eq "L*"B= $encode == 4
ABresult
1X1
011
000
11096
11097 # get illuminant white point
11098 0 ▶ ($wtpt = _illumWP($self, $cols, $hash)) || croak('illuminant white point required for LxLyLz encoding');
Branch: 1 branch
BranchTrueFalseTotal
$wtpt = _illumWP($self, $cols, $hash) or croak("illuminant white point required for LxLyLz encoding") 0 0 0
11099
11100 # return code refs
11101 0 ▶ return(sub {defined($_[0]) ? ICC::Shared::x2L($_[0] / $wtpt->[0]) : $_[0], defined($_[1]) ? ICC::Shared::x2L($_[1] / $wtpt->[1]) : $_[1], defined($_[2]) ? ICC::Shared::x2L($_[2] / $wtpt->[2]) : $_[2]},
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11102 0 ▶ sub {defined($_[0]) ? ICC::Shared::L2x($_[0]) * $wtpt->[0] : $_[0], defined($_[1]) ? ICC::Shared::L2x($_[1]) * $wtpt->[1] : $_[1], defined($_[2]) ? ICC::Shared::L2x($_[2]) * $wtpt->[2] : $_[2]});
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11103
11104 # if encoding is 16-bit ICC XYZ
11105 } elsif ($encode == 7) {
11106
11107 # return code refs
11108 0 ▶ return(sub {map {defined() ? $_ / 199.9969482421875 : $_} @_}, sub {map {defined() ? $_ * 199.9969482421875 : $_} @_});
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
defined $_ ? : 0 0 0
defined $_ ? : 0 0 0
11109
11110 # if encoding is 32-bit ICC XYZNumber
11111 } elsif ($encode == 8) {
11112
11113 # return code refs
11114 0 ▶ return(sub {map {defined() ? $_ / 100 : $_} @_}, sub {map {defined() ? $_ * 100 : $_} @_});
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 2 branches
BranchTrueFalseTotal
defined $_ ? : 0 0 0
defined $_ ? : 0 0 0
11115
11116 # if encoding is xyz
11117 } elsif ($encode == 9) {
11118
11119 # get illuminant white point
11120 0 ▶ ($wtpt = _illumWP($self, $cols, $hash)) || croak('illuminant white point required for xyz encoding');
Branch: 1 branch
BranchTrueFalseTotal
$wtpt = _illumWP($self, $cols, $hash) or croak("illuminant white point required for xyz encoding") 0 0 0
11121
11122 # return code refs
11123 0 ▶ return(sub {defined($_[0]) ? $_[0] / $wtpt->[0] : $_[0], defined($_[1]) ? $_[1] / $wtpt->[1] : $_[1], defined($_[2]) ? $_[2] / $wtpt->[2] : $_[2]},
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11124 0 ▶ sub {defined($_[0]) ? $_[0] * $wtpt->[0] : $_[0], defined($_[1]) ? $_[1] * $wtpt->[1] : $_[1], defined($_[2]) ? $_[2] * $wtpt->[2] : $_[2]});
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11125
11126 # if encoding is XYZ
11127 } elsif ($encode == 10) {
11128
11129 # return code refs (identity)
11130 0 ▶ return(sub {@_}, sub {@_});
Subroutine __ANON__: not called CC=1 SCAR=6.9
11131
11132 # if encoding is media relative xyz
11133 } elsif ($encode == 11) {
11134
11135 # get media white point
11136 0 ▶ ($wtpt = _mediaWP($self, $cols, $hash)) || croak('media white point required for media relative xyz encoding');
Branch: 1 branch
BranchTrueFalseTotal
$wtpt = _mediaWP($self, $cols, $hash) or croak("media white point required for media relative xyz encoding") 0 0 0
11137
11138 # return code refs
11139 0 ▶ return(sub {defined($_[0]) ? $_[0] / $wtpt->[0] : $_[0], defined($_[1]) ? $_[1] / $wtpt->[1] : $_[1], defined($_[2]) ? $_[2] / $wtpt->[2] : $_[2]},
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11140 0 ▶ sub {defined($_[0]) ? $_[0] * $wtpt->[0] : $_[0], defined($_[1]) ? $_[1] * $wtpt->[1] : $_[1], defined($_[2]) ? $_[2] * $wtpt->[2] : $_[2]});
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 3 branches
BranchTrueFalseTotal
defined $_[0] ? : 0 0 0
defined $_[1] ? : 0 0 0
defined $_[2] ? : 0 0 0
11141
11142 } else {
11143
11144 # error
11145 0 croak('invalid XYZ encoding');
11146
11147 }
11148  
11149 }
11150  
11151 # get density encoding code refs
11152 # parameter: (object_reference, hash)
11153 # returns: (get_code_ref, set_code_ref)
11154 sub _density_encoding {
11155  
11156 # get object reference
11157 17 ▶ my ($self, $hash) = @_;
Subroutine _density_encoding: called CC=6 SCAR=35.0
11158  
11159 # get encoding parameter from hash
11160 17 my $encode = $hash->{'encoding'};
11161  
11162 # if encoding parameter undefined or density
11163 17 ▶ if (! defined($encode) || $encode eq 'density') {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $encode or $encode eq 'density') { } 17 0 17
elsif ($encode eq 'linear') { } 0 0 0
elsif ($encode eq 'unit') { } 0 0 0
elsif ($encode eq 'L*') { } 0 0 0
Condition33%1/3
not defined $encode or $encode eq "density"
l!l&&r!l&&!r
1700
MC/DC0%0/2
not defined $encode or $encode eq "density"
not defined $encode $encode eq "density"
Truth table33%1/3
not(A) or B
A= not defined $encodeB= $encode eq "density"
ABresult
1X1
011
000
11164
11165 # return code refs (identity)
11166 17 ▶ return(sub {@_}, sub {@_});
Subroutine __ANON__: not called CC=1 SCAR=2.6
11167
11168 # if encoding is linear (RGBV)
11169 } elsif ($encode eq 'linear') {
11170
11171 # return code refs
11172 0 ▶ return(sub {map {defined() ? 100 * POSIX::pow(10, -$_) : $_} @_}, sub {map {if (defined()) {if ($_ > 0) {-POSIX::log10($_/100)} else {warn("log of $_"); 99}} else {$_}} @_});
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 3 branches
BranchTrueFalseTotal
defined $_ ? : 0 0 0
if (defined $_) { } 0 0 0
if ($_ > 0) { } 0 0 0
11173
11174 # if encoding is unit
11175 } elsif ($encode eq 'unit') {
11176
11177 # return code refs
11178 0 ▶ return(sub {map {defined() ? POSIX::pow(10, -$_) : $_} @_}, sub {map {if (defined()) {if ($_ > 0) {-POSIX::log10($_)} else {warn("log of $_"); 99}} else {$_}} @_});
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 3 branches
BranchTrueFalseTotal
defined $_ ? : 0 0 0
if (defined $_) { } 0 0 0
if ($_ > 0) { } 0 0 0
11179
11180 # if encoding is L*
11181 } elsif ($encode eq 'L*') {
11182
11183 # return code refs
11184 0 ▶ return(sub {map {defined() ? ICC::Shared::x2L(POSIX::pow(10, -$_)) : $_} @_}, sub {map {if (defined()) {if ($_ > 0) {-POSIX::log10(ICC::Shared::L2x($_))} else {warn("log of $_"); 99}} else {$_}} @_});
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 3 branches
BranchTrueFalseTotal
defined $_ ? : 0 0 0
if (defined $_) { } 0 0 0
if ($_ > 0) { } 0 0 0
11185
11186 } else {
11187
11188 # error
11189 0 croak('invalid density encoding');
11190
11191 }
11192  
11193 }
11194  
11195 # get rgbv encoding code refs
11196 # parameter: (object_reference, hash)
11197 # returns: (get_code_ref, set_code_ref)
11198 sub _rgbv_encoding {
11199  
11200 # get object reference
11201 0 ▶ my ($self, $hash) = @_;
Subroutine _rgbv_encoding: not called CC=7 SCAR=40.3
11202  
11203 # get encoding parameter from hash
11204 0 my $encode = $hash->{'encoding'};
11205  
11206 # if encoding parameter undefined or linear
11207 0 ▶ if (! defined($encode) || $encode eq 'linear'|| $encode eq 'RGBV') {
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $encode or $encode eq 'linear' or $encode eq 'RGBV') { } 0 0 0
elsif ($encode eq 'unit') { } 0 0 0
elsif ($encode eq 'density') { } 0 0 0
elsif ($encode eq 'L*') { } 0 0 0
Condition0%0/6
not defined $encode or $encode eq "linear" or $encode eq "RGBV"
l!l&&r!l&&!r
000
not defined $encode or $encode eq "linear"
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $encode or $encode eq "linear" or $encode eq "RGBV"
not defined $encode $encode eq "linear" $encode eq "RGBV"
Truth table0%0/4
not(A) or B or C
A= not defined $encodeB= $encode eq "linear"C= $encode eq "RGBV"
ABCresult
1XX1
01X1
0011
0000
11208
11209 # return code refs (identity)
11210 0 ▶ return(sub {@_}, sub {@_});
Subroutine __ANON__: not called CC=1 SCAR=6.9
11211
11212 # if encoding is unit
11213 } elsif ($encode eq 'unit') {
11214
11215 # return code refs
11216 0 ▶ return(sub {map {$_/100} @_}, sub {map {$_ * 100} @_});
Subroutine __ANON__: not called CC=1 SCAR=6.9
11217
11218 # if encoding is density
11219 } elsif ($encode eq 'density') {
11220
11221 # return code refs
11222 0 ▶ return(sub {map {if (defined()) {if ($_ > 0) {-POSIX::log10($_/100)} else {warn("log of $_"); 99}} else {$_}} @_}, sub {map {defined() ? 100 * POSIX::pow(10, -$_) : $_} @_});
Subroutine __ANON__: not called CC=3 SCAR=24.8
Branch: 3 branches
BranchTrueFalseTotal
if (defined $_) { } 0 0 0
if ($_ > 0) { } 0 0 0
defined $_ ? : 0 0 0
11223
11224 # if encoding is L*
11225 } elsif ($encode eq 'L*') {
11226
11227 # return code refs
11228 0 ▶ return(sub {map {ICC::Shared::x2L($_/100)} @_}, sub {map {ICC::Shared::L2x($_) * 100} @_});
Subroutine __ANON__: not called CC=1 SCAR=6.9
11229
11230 } else {
11231
11232 # error
11233 0 croak('invalid rgbv encoding');
11234
11235 }
11236  
11237 }
11238  
11239 #--------- additional Math::Matrix methods ---------
11240  
11241 package Math::Matrix;
11242  
11243 # rotate matrix
11244 # rotation: 0 = None, 1 = 90° CW, 2 = 180°, 3 = 90° CCW
11245 # note: rotation describes appearance in MeasureTool
11246 # parameter: (rotation)
11247 # returns: (rotated_matrix)
11248 sub rotate {
11249  
11250 # get parameters
11251 0 ▶ my ($self, $rot) = @_;
Subroutine rotate: not called CC=14 SCAR=53.5
Pod undocumented
11252  
11253 # local variables
11254 0 my ($rows, $cols, $replace);
11255  
11256 # return if rotation undefined
11257 0 ▶ return($self) if (! defined($rot));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rot 0 0 0
11258  
11259 # resolve rotation parameter
11260 0 $rot = int($rot) % 4;
11261  
11262 # get upper row index
11263 0 $rows = $#{$self};
11264  
11265 # get upper column index
11266 0 $cols = $#{$self->[0]};
11267  
11268 # if rotation = 0 (none)
11269 0 ▶ if ($rot == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($rot == 0) { } 0 0 0
elsif ($rot == 1) { } 0 0 0
elsif ($rot == 2) { } 0 0 0
elsif ($rot == 3) { } 0 0 0
11270
11271 # for each row
11272 0 for my $i (0 .. $rows) {
11273
11274 # for each column
11275 0 for my $j (0 .. $cols) {
11276
11277 # copy matrix element
11278 0 $replace->[$i][$j] = $self->[$i][$j];
11279
11280 }
11281
11282 }
11283
11284 # if rotation = 1 (90° CW)
11285 } elsif ($rot == 1) {
11286
11287 # for each row
11288 0 for my $i (0 .. $rows) {
11289
11290 # for each column
11291 0 for my $j (0 .. $cols) {
11292
11293 # copy matrix element
11294 0 $replace->[$j][$i] = $self->[$i][$cols - $j];
11295
11296 }
11297
11298 }
11299
11300 # if rotation = 2 (180°)
11301 } elsif ($rot == 2) {
11302
11303 # for each row
11304 0 for my $i (0 .. $rows) {
11305
11306 # for each column
11307 0 for my $j (0 .. $cols) {
11308
11309 # copy matrix element
11310 0 $replace->[$i][$j] = $self->[$rows - $i][$cols - $j];
11311
11312 }
11313
11314 }
11315
11316 # if rotation = 3 (90° CCW)
11317 } elsif ($rot == 3) {
11318
11319 # for each row
11320 0 for my $i (0 .. $rows) {
11321
11322 # for each column
11323 0 for my $j (0 .. $cols) {
11324
11325 # copy matrix element
11326 0 $replace->[$j][$i] = $self->[$rows - $i][$j];
11327
11328 }
11329
11330 }
11331
11332 }
11333  
11334 # return new object
11335 0 return(bless($replace, 'Math::Matrix'));
11336  
11337 }
11338  
11339 # flip matrix
11340 # flip: 0 = transpose, 1 = horizontal, 2 = cross transpose, 3 = vertical
11341 # note: flip describes appearance in MeasureTool
11342 # parameter: (flip)
11343 # returns: (flipped_matrix)
11344 sub flip {
11345  
11346 # get parameters
11347 0 ▶ my ($self, $flip) = @_;
Subroutine flip: not called CC=14 SCAR=53.5
Pod documented
11348  
11349 # local variables
11350 0 my ($rows, $cols, $replace);
11351  
11352 # return if flip undefined
11353 0 ▶ return($self) if (! defined($flip));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $flip 0 0 0
11354  
11355 # resolve flip parameter
11356 0 $flip = int($flip) % 4;
11357  
11358 # get upper row index
11359 0 $rows = $#{$self};
11360  
11361 # get upper column index
11362 0 $cols = $#{$self->[0]};
11363  
11364 # if flip = 0 (transpose)
11365 0 ▶ if ($flip == 0) {
Branch: 4 branches
BranchTrueFalseTotal
if ($flip == 0) { } 0 0 0
elsif ($flip == 1) { } 0 0 0
elsif ($flip == 2) { } 0 0 0
elsif ($flip == 3) { } 0 0 0
11366
11367 # for each row
11368 0 for my $i (0 .. $rows) {
11369
11370 # for each column
11371 0 for my $j (0 .. $cols) {
11372
11373 # copy matrix element
11374 0 $replace->[$j][$i] = $self->[$i][$j];
11375
11376 }
11377
11378 }
11379
11380 # if flip = 1 (horizontal)
11381 } elsif ($flip == 1) {
11382
11383 # for each row
11384 0 for my $i (0 .. $rows) {
11385
11386 # for each column
11387 0 for my $j (0 .. $cols) {
11388
11389 # copy matrix element
11390 0 $replace->[$i][$j] = $self->[$rows - $i][$j];
11391
11392 }
11393
11394 }
11395
11396 # if flip = 2 (cross transpose)
11397 } elsif ($flip == 2) {
11398
11399 # for each row
11400 0 for my $i (0 .. $rows) {
11401
11402 # for each column
11403 0 for my $j (0 .. $cols) {
11404
11405 # copy matrix element
11406 0 $replace->[$j][$i] = $self->[$rows - $i][$cols - $j];
11407
11408 }
11409
11410 }
11411
11412 # if flip = 3 (vertical)
11413 } elsif ($flip == 3) {
11414
11415 # for each row
11416 0 for my $i (0 .. $rows) {
11417
11418 # for each column
11419 0 for my $j (0 .. $cols) {
11420
11421 # copy matrix element
11422 0 $replace->[$i][$j] = $self->[$i][$cols - $j];
11423
11424 }
11425
11426 }
11427
11428 }
11429  
11430 # return new object
11431 0 return(bless($replace, 'Math::Matrix'));
11432  
11433 }
11434  
11435 # randomize matrix
11436 # returns: (randomized_matrix)
11437 sub randomize {
11438  
11439 # get object reference
11440 0 ▶ my $self = shift();
Subroutine randomize: not called CC=3 SCAR=24.8
Pod undocumented
11441  
11442 # local variables
11443 0 my (@ix, $rows, $cols, $replace);
11444  
11445 # flatten and randomize matrix
11446 0 @ix = List::Util::shuffle(@{ICC::Shared::flatten($self)});
11447  
11448 # get upper row index
11449 0 $rows = $#{$self};
11450  
11451 # get upper column index
11452 0 $cols = $#{$self->[0]};
11453  
11454 # for each row
11455 0 for my $i (0 .. $rows) {
11456
11457 # for each column
11458 0 for my $j (0 .. $cols) {
11459
11460 # set element
11461 0 $replace->[$i][$j] = $ix[$i * ($cols + 1) + $j];
11462
11463 }
11464
11465 }
11466  
11467 # return new object
11468 0 return(bless($replace, 'Math::Matrix'));
11469  
11470 }
11471  
11472 2 1;
11473  
↑ Summary blib/lib/ICC/Support/Chart.pm »