lib/ICC/Support/Color.pm

filter: Statementstmt 4.2% 25 / 595 Branchbran 0.6% 2 / 324 Conditioncond 0.3% 1 / 299 MC/DCmcdc 0.0% 0 / 160 Subroutinesub 17.9% 7 / 39 Podpod 100% 9 / 9 totaltotal 3.0% 44 / 1426 CC 290 SCAR 61.1
CC
290
Cov
2%
_cie
1482.0
jacobian
1332.0
observer
306.0
CRAP 450.1
« lib/ICC/Support/spline.pm ↑ Summary blib/lib/ICC/Profile.pm »
1 package ICC::Support::Color;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 0.22;
7  
8 # revised 2017-09-08
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 File::Glob;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # enable static variables
22 2 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # spectral range hash
25 2 our $srh = {'31' => [400, 700, 10], '36' => [380, 730, 10], '38' => [360, 730, 10], '43' => [360, 780, 10], '81' => [380, 780, 5]};
26  
27 # create new Color object
28 # hash keys are: 'illuminant', 'observer', 'increment', 'method', 'imethod', 'bandpass', 'ibandpass', 'status', 'range'
29 # the method used is determined by the hash keys.
30 # for ASTM method,
31 # 'illuminant' value is a scalar, 'A', 'C', 'D50', 'D55', 'D65', 'D75', 'F2', 'F7', or 'F11', default is 'D50'
32 # 'observer' value is a scalar, '2' or '10', default is '2'
33 # 'increment' value is a scalar, '10' or '20', default is '10'
34 # 'bandpass' value is a scalar, 'astm', 'triangle', 'trapezoid' or 'six', default is no bandpass correction
35 # for CIE method,
36 # 'illuminant' value is an array reference, [], ['source', 'id'] or ['nm', 'spd']
37 # an empty array indicates no illuminant, for emissive measurements
38 # 'source' values are 'CIE', 'Philips', or a measurement file path
39 # 'id' values depend on the 'source'
40 # 'CIE' illuminants are 'A', 'C', 'D50', 'D55', 'D65', 'D75', 'FL1' to 'FL12', 'FL3.1' to 'FL3.15', 'HP1' to 'HP5', and 'E'
41 # 'Philips' illuminants are '60_A/W', 'C100S54', 'C100S54C', 'F32T8/TL830', 'F32T8/TL835', 'F32T8/TL841', 'F32T8/TL850', 'F32T8/TL865/PLUS', 'F34/CW/RS/EW', 'F34T12WW/RS/EW', 'F40/C50', 'F40/C75', 'F40/CWX', 'F40/DX', 'F40/DXTP', 'F40/N', 'F34T12/LW/RS/EW', 'H38HT-100', 'H38JA-100/DX', 'MHC100/U/MP/3K', 'MHC100/U/MP/4K', and 'SDW-T_100W/LV'
42 # for a measurement file path, the 'id' is the sample number
43 # 'nm' and 'spd' are vectors, wavelength range and spectral power distribution
44 # 'observer' value is a scalar, '2', '10', '2P' or '10P', default '2'
45 # 'increment' value is a scalar, '1' or '5', default '1'
46 # 'method' value is a scalar, 'linear', 'cspline' or 'lagrange', default is 'cspline'
47 # 'bandpass' value is a scalar, 'astm', 'triangle' or 'trapezoid', default is no bandpass correction
48 # 'imethod' value is a scalar, 'linear', 'cspline' or 'lagrange', default is 'linear' or 'cspline', based on smoothness of the illuminant SPD
49 # 'ibandpass' value is a scalar, 'astm', 'triangle' or 'trapezoid', default is no bandpass correction
50 # for ISO 5-3 method (density),
51 # 'status' value is a scalar, 'A', 'M', 'T', 'E', or 'I', default 'T'
52 # 'increment' value is a scalar, '10' or '20', default '10'
53 # 'range' value is: [start_nm, end_nm, increment], which is added to the spectral range hash ($srh)
54 # parameters: ([ref_to_attribute_hash])
55 # returns: (object_reference)
56 sub new {
57  
58 # get object class
59 1 ▶ my $class = shift();
Subroutine new: called CC=4 SCAR=17.2
Pod documented
60  
61 # create empty Color object
62 1 my $self = [
63 {}, # object header
64 [], # illuminant (CIE)
65 [], # color-matching functions (CIE)
66 [], # color-weight functions (ASTM and ISO 5-3)
67 [], # color-weight functions (adjusted to input range and cached)
68 [] # white-point
69 ];
70  
71 # if one parameter, a hash reference
72 1 ▶ if (@_ == 1 && ref($_[0]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 1 1
elsif (@_) { } 0 1 1
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
73
74 # set object contents from hash
75 0 _new_from_hash($self, $_[0]);
76
77 } elsif (@_) {
78
79 # error
80 0 croak('invalid parameter(s)');
81
82 }
83  
84 # return blessed object
85 1 return(bless($self, $class));
86  
87 }
88  
89 # get/set reference to header hash
90 # header contains keys used by 'new'
91 # parameters: ([ref_to_new_hash])
92 # returns: (ref_to_hash)
93 sub header {
94  
95 # get object reference
96 0 ▶ my $self = shift();
Subroutine header: not called CC=4 SCAR=30.0
Pod documented
97  
98 # if there are parameters
99 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
100
101 # if one parameter, a hash reference
102 0 ▶ if (@_ == 1 && ref($_[0]) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
103
104 # set header to copy of hash
105 0 $self->[0] = Storable::dclone(shift());
106
107 } else {
108
109 # error
110 0 croak('parameter must be a hash reference');
111
112 }
113
114 }
115  
116 # return reference
117 0 return($self->[0]);
118  
119 }
120  
121 # get/set reference to illuminant structure
122 # structure: [[start_nm, end_nm, increment], spd_vector]
123 # note: set updates the color-weight functions
124 # parameters: ([ref_to_new_structure])
125 # returns: (ref_to_structure)
126 sub illuminant {
127  
128 # get object reference
129 0 ▶ my $self = shift();
Subroutine illuminant: not called CC=15 SCAR=54.8
Pod documented
130  
131 # local variables
132 0 my ($array, $sx);
133  
134 # if there are parameters
135 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
136
137 # if one parameter, an array reference
138 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
139
140 # get array reference
141 0 $array = shift();
142
143 # initialize data array
144 0 $self->[1] = [];
145
146 # if array is not empty
147 0 ▶ if (@{$array}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$array;}) 0 0 0
148
149 # verify array size
150 0 ▶ (@{$array} == 2) or croak('invalid illuminant array');
Branch: 1 branch
BranchTrueFalseTotal
@{$array;} == 2 or croak("invalid illuminant array") 0 0 0
151
152 # verify wavelength range
153 0 ▶ (ref($array->[0]) eq 'ARRAY' && 3 == @{$array->[0]} && (3 == grep {Scalar::Util::looks_like_number($_)} @{$array->[0]}) && $array->[0][2]) or croak('invalid illuminant wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2] or croak("invalid illuminant wavelength range") 0 0 0
Condition0%0/9
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2]
!ll&&!rl&&r
000
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];})
!ll&&!rl&&r
000
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];}
!ll&&!rl&&r
000
MC/DC0%0/4
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2]
ref $array->[0] eq "ARRAY" 3 == @{$array->[0];} 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) $array->[0][2]
Truth table0%0/5
A and B and C and D
A= ref $array->[0] eq "ARRAY"B= 3 == @{$array->[0];}C= 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];})D= $array->[0][2]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
154
155 # compute upper index of spd array
156 0 ▶ (($sx = ICC::Shared::round(($array->[0][1] - $array->[0][0])/$array->[0][2])) > 0) or croak('inconsistent illuminant wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
($sx = ICC::Shared::round(($array->[0][1] - $array->[0][0]) / $array->[0][2])) > 0 or croak("inconsistent illuminant wavelength range") 0 0 0
157
158 # verify spd array
159 0 ▶ (ref($array->[1]) eq 'ARRAY' && $#{$array->[1]} == $sx && @{$array->[1]} == grep {Scalar::Util::looks_like_number($_)} @{$array->[1]}) or croak('invalid illuminant spd array');
Branch: 1 branch
BranchTrueFalseTotal
ref $array->[1] eq "ARRAY" and $#{$$array[1];} == $sx and @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];}) or croak("invalid illuminant spd array") 0 0 0
Condition0%0/6
ref $array->[1] eq "ARRAY" and $#{$$array[1];} == $sx and @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];})
!ll&&!rl&&r
000
ref $array->[1] eq "ARRAY" and $#{$$array[1];} == $sx
!ll&&!rl&&r
000
MC/DC0%0/3
ref $array->[1] eq "ARRAY" and $#{$$array[1];} == $sx and @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];})
ref $array->[1] eq "ARRAY" $#{$$array[1];} == $sx @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];})
Truth table0%0/4
A and B and C
A= ref $array->[1] eq "ARRAY"B= $#{$$array[1];} == $sxC= @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];})
ABCresult
0XX0
10X0
1100
1111
160
161 # copy array contents
162 0 $self->[1] = Storable::dclone($array);
163
164 # if observer array defined
165 0 ▶ if (defined($self->[2][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[2][0]) 0 0 0
166
167 # update color-weight functions
168 0 _make_cwf($self);
169
170 }
171
172 }
173
174 } else {
175
176 # error
177 0 croak('parameter must be an array reference');
178
179 }
180
181 }
182  
183 # return reference
184 0 return($self->[1]);
185  
186 }
187  
188 # get/set reference to observer structure
189 # structure: [[start_nm, end_nm, increment], cmf_matrix]
190 # note: set updates the color-weight functions
191 # parameters: ([ref_to_new_structure])
192 # returns: (ref_to_structure)
193 sub observer {
194  
195 # get object reference
196 0 ▶ my $self = shift();
Subroutine observer: not called CC=17 SCAR=57.2
Pod documented
197  
198 # local variables
199 0 my ($array, $sx);
200  
201 # if there are parameters
202 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
203
204 # if one parameter, an array reference
205 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
206
207 # get array reference
208 0 $array = shift();
209
210 # initialize data array
211 0 $self->[2] = [];
212
213 # if array is not empty
214 0 ▶ if (@{$array}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$array;}) 0 0 0
215
216 # verify array size
217 0 ▶ (@{$array} == 2) or croak('invalid observer array');
Branch: 1 branch
BranchTrueFalseTotal
@{$array;} == 2 or croak("invalid observer array") 0 0 0
218
219 # verify wavelength range
220 0 ▶ (ref($array->[0]) eq 'ARRAY' && 3 == @{$array->[0]} && (3 == grep {Scalar::Util::looks_like_number($_)} @{$array->[0]}) && $array->[0][2]) or croak('invalid observer wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2] or croak("invalid observer wavelength range") 0 0 0
Condition0%0/9
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2]
!ll&&!rl&&r
000
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];})
!ll&&!rl&&r
000
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];}
!ll&&!rl&&r
000
MC/DC0%0/4
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2]
ref $array->[0] eq "ARRAY" 3 == @{$array->[0];} 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) $array->[0][2]
Truth table0%0/5
A and B and C and D
A= ref $array->[0] eq "ARRAY"B= 3 == @{$array->[0];}C= 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];})D= $array->[0][2]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
221
222 # compute upper index of observer matrix
223 0 ▶ (($sx = ICC::Shared::round(($array->[0][1] - $array->[0][0])/$array->[0][2])) > 0) or croak('inconsistent observer wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
($sx = ICC::Shared::round(($array->[0][1] - $array->[0][0]) / $array->[0][2])) > 0 or croak("inconsistent observer wavelength range") 0 0 0
224
225 # verify observer matrix
226 0 ▶ ((ref($array->[1]) eq 'ARRAY' || UNIVERSAL::isa($array->[1], 'Math::Matrix')) && ref($array->[1][0]) eq 'ARRAY' && $#{$array->[1][0]} == $sx && @{$array->[1][0]} == grep {Scalar::Util::looks_like_number($_)} @{$array->[1][0]}) or croak('invalid observer cmf matrix');
Branch: 1 branch
BranchTrueFalseTotal
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY" and $#{$$array[1][0];} == $sx and @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];}) or croak("invalid observer cmf matrix") 0 0 0
Condition0%0/12
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY" and $#{$$array[1][0];} == $sx and @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];})
!ll&&!rl&&r
000
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY" and $#{$$array[1][0];} == $sx
!ll&&!rl&&r
000
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY"
!ll&&!rl&&r
000
ref $array->[1] eq "ARRAY" or UNIVERSAL::isa($array->[1], "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/5
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY" and $#{$$array[1][0];} == $sx and @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];})
ref $array->[1] eq "ARRAY" UNIVERSAL::isa($array->[1], "Math::Matrix") ref $array->[1][0] eq "ARRAY" $#{$$array[1][0];} == $sx @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];})
Truth table0%0/9
A or B and C and D and E
A= ref $array->[1] eq "ARRAY"B= UNIVERSAL::isa($array->[1], "Math::Matrix")C= ref $array->[1][0] eq "ARRAY"D= $#{$$array[1][0];} == $sxE= @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];})
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
227
228 # copy array contents
229 0 $self->[2] = Storable::dclone($array);
230
231 # if illuminant array defined
232 0 ▶ if (defined($self->[1][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1][0]) 0 0 0
233
234 # update color-weight functions
235 0 _make_cwf($self);
236
237 }
238
239 }
240
241 } else {
242
243 # error
244 0 croak('parameter must be an array reference');
245
246 }
247
248 }
249  
250 # return reference
251 0 return($self->[2]);
252  
253 }
254  
255 # get/set reference to color-weight function structure
256 # structure: [[start_nm, end_nm, increment], cwf_matrix]
257 # parameters: ([ref_to_new_structure])
258 # returns: (ref_to_structure)
259 sub cwf {
260  
261 # get object reference
262 0 ▶ my $self = shift();
Subroutine cwf: not called CC=17 SCAR=57.2
Pod documented
263  
264 # local variables
265 0 my ($array, $sx);
266  
267 # if there are parameters
268 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
269
270 # if one parameter, an array reference
271 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
272
273 # get array reference
274 0 $array = shift();
275
276 # initialize data array
277 0 $self->[3] = [];
278
279 # if array is not empty
280 0 ▶ if (@{$array}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$array;}) 0 0 0
281
282 # verify array size
283 0 ▶ (@{$array} == 2) or croak('invalid cwf array');
Branch: 1 branch
BranchTrueFalseTotal
@{$array;} == 2 or croak("invalid cwf array") 0 0 0
284
285 # verify wavelength range
286 0 ▶ (ref($array->[0]) eq 'ARRAY' && 3 == @{$array->[0]} && (3 == grep {Scalar::Util::looks_like_number($_)} @{$array->[0]}) && $array->[0][2]) or croak('invalid cwf wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2] or croak("invalid cwf wavelength range") 0 0 0
Condition0%0/9
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2]
!ll&&!rl&&r
000
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];})
!ll&&!rl&&r
000
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];}
!ll&&!rl&&r
000
MC/DC0%0/4
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2]
ref $array->[0] eq "ARRAY" 3 == @{$array->[0];} 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) $array->[0][2]
Truth table0%0/5
A and B and C and D
A= ref $array->[0] eq "ARRAY"B= 3 == @{$array->[0];}C= 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];})D= $array->[0][2]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
287
288 # compute upper index of cwf matrix
289 0 ▶ (($sx = ICC::Shared::round(($array->[0][1] - $array->[0][0])/$array->[0][2])) > 0) or croak('inconsistent cwf wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
($sx = ICC::Shared::round(($array->[0][1] - $array->[0][0]) / $array->[0][2])) > 0 or croak("inconsistent cwf wavelength range") 0 0 0
290
291 # verify cwf matrix
292 0 ▶ ((ref($array->[1]) eq 'ARRAY' || UNIVERSAL::isa($array->[1], 'Math::Matrix')) && ref($array->[1][0]) eq 'ARRAY' && $#{$array->[1][0]} == $sx && @{$array->[1][0]} == grep {Scalar::Util::looks_like_number($_)} @{$array->[1][0]}) or croak('invalid cwf weight matrix');
Branch: 1 branch
BranchTrueFalseTotal
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY" and $#{$$array[1][0];} == $sx and @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];}) or croak("invalid cwf weight matrix") 0 0 0
Condition0%0/12
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY" and $#{$$array[1][0];} == $sx and @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];})
!ll&&!rl&&r
000
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY" and $#{$$array[1][0];} == $sx
!ll&&!rl&&r
000
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY"
!ll&&!rl&&r
000
ref $array->[1] eq "ARRAY" or UNIVERSAL::isa($array->[1], "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/5
ref $array->[1] eq "ARRAY" || UNIVERSAL::isa($array->[1], "Math::Matrix") and ref $array->[1][0] eq "ARRAY" and $#{$$array[1][0];} == $sx and @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];})
ref $array->[1] eq "ARRAY" UNIVERSAL::isa($array->[1], "Math::Matrix") ref $array->[1][0] eq "ARRAY" $#{$$array[1][0];} == $sx @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];})
Truth table0%0/9
A or B and C and D and E
A= ref $array->[1] eq "ARRAY"B= UNIVERSAL::isa($array->[1], "Math::Matrix")C= ref $array->[1][0] eq "ARRAY"D= $#{$$array[1][0];} == $sxE= @{$array->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1][0];})
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
293
294 # copy array contents
295 0 $self->[3] = Storable::dclone($array);
296
297 # for each weight function (XYZ -or- RGBV)
298 0 for my $i (0 .. $#{$array->[1]}) {
299
300 # update white point array
301 0 $self->[5][$i] = List::Util::sum(@{$array->[1][$i]});
302
303 }
304
305 }
306
307 } else {
308
309 # error
310 0 croak('parameter must be an array reference');
311
312 }
313
314 }
315  
316 # return reference
317 0 return($self->[3]);
318  
319 }
320  
321 # get illuminant white point
322 # encoding specified by 'encoding' hash key
323 # 'encoding' values are 'XYZ', 'xyz', 'ICC_XYZ', 'ICC_XYZNumber', and 'density'
324 # parameters: ([hash])
325 # returns: (XYZ_vector)
326 sub iwtpt {
327  
328 # get parameters
329 0 ▶ my ($self, $hash) = @_;
Subroutine iwtpt: not called CC=2 SCAR=17.9
Pod documented
330  
331 # local variable
332 0 my ($code);
333  
334 # return white point with optional encoding
335 0 ▶ return(defined($code = _encoding($self, $hash)) ? [&$code(@{$self->[5]})] : $self->[5]);
Branch: 1 branch
BranchTrueFalseTotal
defined($code = _encoding($self, $hash)) ? : 0 0 0
336  
337 }
338  
339 # transform data
340 # hash keys are: 'range', and 'encoding'
341 # 'range' value is: [start_nm, end_nm, increment]
342 # 'encoding' values are 'XYZ', 'xyz', 'ICC_XYZ', 'ICC_XYZNumber', 'RGBV', 'rgbv' and 'density'
343 # supported input types:
344 # parameters: (list, [hash])
345 # parameters: (vector, [hash])
346 # parameters: (matrix, [hash])
347 # parameters: (Math::Matrix_object, [hash])
348 # parameters: (structure, [hash])
349 # returns: (same_type_as_input)
350 sub transform {
351  
352 # set hash value (0 or 1)
353 0 ▶ my $h = ref($_[-1]) eq 'HASH' ? 1 : 0;
Subroutine transform: not called CC=14 SCAR=53.5
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 0 0 0
354  
355 # verify color weight array
356 0 ▶ (defined($_[0]->[3][0]) && defined($_[0]->[3][1])) or croak('color weight array undefined');
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0][3][0] and defined $_[0][3][1] or croak("color weight array undefined") 0 0 0
Condition0%0/3
defined $_[0][3][0] and defined $_[0][3][1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $_[0][3][0] and defined $_[0][3][1]
defined $_[0][3][0] defined $_[0][3][1]
Truth table0%0/3
A and B
A= defined $_[0][3][0]B= defined $_[0][3][1]
ABresult
0X0
100
111
357  
358 # if input a 'Math::Matrix' object
359 0 ▶ if (@_ == $h + 2 && UNIVERSAL::isa($_[1], 'Math::Matrix')) {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == $h + 2 and UNIVERSAL::isa($_[1], 'Math::Matrix')) { } 0 0 0
elsif (@_ == $h + 2 and ref $_[1] eq 'ARRAY') { } 0 0 0
elsif (@_ == $h + 1 + grep({&Scalar::Util::looks_like_number($_);} @_)) { } 0 0 0
Condition0%0/3
@_ == $h + 2 and UNIVERSAL::isa($_[1], "Math::Matrix")
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == $h + 2 and UNIVERSAL::isa($_[1], "Math::Matrix")
@_ == $h + 2 UNIVERSAL::isa($_[1], "Math::Matrix")
Truth table0%0/3
A and B
A= @_ == $h + 2B= UNIVERSAL::isa($_[1], "Math::Matrix")
ABresult
0X0
100
111
360
361 # call matrix transform
362 0 &_trans2;
363
364 # if input an array reference
365 ▶ } elsif (@_ == $h + 2 && ref($_[1]) eq 'ARRAY') {
Condition0%0/3
@_ == $h + 2 and ref $_[1] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == $h + 2 and ref $_[1] eq "ARRAY"
@_ == $h + 2 ref $_[1] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == $h + 2B= ref $_[1] eq "ARRAY"
ABresult
0X0
100
111
366
367 # if array contains numbers (vector)
368 0 ▶ if (! ref($_[1][0]) && @{$_[1]} == grep {Scalar::Util::looks_like_number($_)} @{$_[1]}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})) { } 0 0 0
elsif (ref $_[1][0] eq 'ARRAY' and @{$_[1];} == grep({ref $_ eq 'ARRAY' and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})) { } 0 0 0
Condition0%0/3
not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
!ll&&!rl&&r
000
MC/DC0%0/2
not ref $_[1][0] and @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
not ref $_[1][0] @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
Truth table0%0/3
not(A) and B
A= not ref $_[1][0]B= @{$_[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$_[1];})
ABresult
0X0
100
111
369
370 # call vector transform
371 0 &_trans1;
372
373 # if array contains vectors (2-D array)
374 0 ▶ } elsif (ref($_[1][0]) eq 'ARRAY' && @{$_[1]} == grep {ref($_) eq 'ARRAY' && Scalar::Util::looks_like_number($_->[0])} @{$_[1]}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]) 0 0 0
Condition0%0/3
ref $_[1][0] eq "ARRAY" and @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_[1][0] eq "ARRAY" and @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
ref $_[1][0] eq "ARRAY" @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
Truth table0%0/3
A and B
A= ref $_[1][0] eq "ARRAY"B= @{$_[1];} == grep({ref $_ eq "ARRAY" and &Scalar::Util::looks_like_number($_->[0]);} @{$_[1];})
ABresult
0X0
100
111
375
376 # call matrix transform
377 0 &_trans2;
378
379 } else {
380
381 # call structure transform
382 0 &_trans3;
383
384 }
385
386 # if input a list (of numbers)
387 0 } elsif (@_ == $h + 1 + grep {Scalar::Util::looks_like_number($_)} @_) {
388
389 # call list transform
390 0 &_trans0;
391
392 } else {
393
394 # error
395 0 croak('invalid transform input');
396
397 }
398  
399 }
400  
401 # compute Jacobian matrix
402 # hash keys are: 'range', and 'encoding'
403 # 'range' value is: [start_nm, end_nm, increment]
404 # 'encoding' values are 'XYZ', 'xyz', 'ICC_XYZ', 'ICC_XYZNumber', 'RGBV', 'rgbv' and 'density'
405 # parameters: (input_vector, [hash])
406 # returns: (Jacobian_matrix, [output_vector])
407 sub jacobian {
408  
409 # get parameters
410 0 ▶ my ($self, $in, $hash) = @_;
Subroutine jacobian: not called CC=36 SCAR=71.9
Pod documented
411  
412 # local variables
413 0 my ($range, $encoding, $jac, $out, $sf);
414  
415 # check if ICC::Support::Lapack module is loaded
416 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
417  
418 # get input spectral range
419 0 ▶ ($range = $hash->{'range'} || $srh->{@{$in}}) or croak('spectral range must be specified');
Branch: 1 branch
BranchTrueFalseTotal
$range = $hash->{"range"} || $$ICC::Support::Color::srh{@{$in;}} or croak("spectral range must be specified") 0 0 0
Condition0%0/3
$hash->{'range'} || $$ICC::Support::Color::srh{@{$in;}}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hash->{'range'} || $$ICC::Support::Color::srh{@{$in;}}
$hash->{'range'} $$ICC::Support::Color::srh{@{$in;}}
Truth table0%0/3
A || B
A= $hash->{'range'}B= $$ICC::Support::Color::srh{@{$in;}}
ABresult
1X1
011
000
420  
421 # if data increment == cwf increment
422 0 ▶ if ($range->[2] == $self->[3][0][2]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($range->[2] == $self->[3][0][2]) { } 0 0 0
elsif ($range->[2] > $self->[3][0][2]) { } 0 0 0
423
424 # use adjusted cwf
425 0 $jac = Storable::dclone(_adjust_cwf($self, $range));
426
427 # if data increment > cwf increment
428 } elsif ($range->[2] > $self->[3][0][2]) {
429
430 # use reduced cwf
431 0 $jac = Storable::dclone(_reduce_cwf($self, $range));
432
433 } else {
434
435 # error
436 0 croak('data increment < cwf increment');
437
438 }
439  
440 # if hash contain 'encoding' other than 'XYZ' or 'RGBV'
441 0 ▶ if (defined($encoding = $hash->{'encoding'}) && $encoding ne 'XYZ' && $encoding ne 'RGBV') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($encoding = $hash->{"encoding"}) and $encoding ne "XYZ" and $encoding ne "RGBV") 0 0 0
Condition0%0/6
defined($encoding = $hash->{"encoding"}) and $encoding ne "XYZ" and $encoding ne "RGBV"
!ll&&!rl&&r
000
defined($encoding = $hash->{"encoding"}) and $encoding ne "XYZ"
!ll&&!rl&&r
000
MC/DC0%0/3
defined($encoding = $hash->{"encoding"}) and $encoding ne "XYZ" and $encoding ne "RGBV"
defined($encoding = $hash->{"encoding"}) $encoding ne "XYZ" $encoding ne "RGBV"
Truth table0%0/4
A and B and C
A= defined($encoding = $hash->{"encoding"})B= $encoding ne "XYZ"C= $encoding ne "RGBV"
ABCresult
0XX0
10X0
1100
1111
442
443 # if encoding is 'ICC_XYZ'
444 0 ▶ if ($encoding eq 'ICC_XYZ' && @{$jac} == 3) {
Branch: 5 branches
BranchTrueFalseTotal
if ($encoding eq 'ICC_XYZ' and @{$jac;} == 3) { } 0 0 0
elsif ($encoding eq 'ICC_XYZNumber' and @{$jac;} == 3) { } 0 0 0
elsif ($encoding eq 'xyz' and @{$jac;} == 3) { } 0 0 0
elsif ($encoding eq 'unit' and @{$jac;} == 4) { } 0 0 0
elsif ($encoding eq 'density' and @{$jac;} == 4) { } 0 0 0
Condition0%0/3
$encoding eq "ICC_XYZ" and @{$jac;} == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "ICC_XYZ" and @{$jac;} == 3
$encoding eq "ICC_XYZ" @{$jac;} == 3
Truth table0%0/3
A and B
A= $encoding eq "ICC_XYZ"B= @{$jac;} == 3
ABresult
0X0
100
111
445
446 # for each XYZ
447 0 for my $i (0 .. 2) {
448
449 # for each spectral value
450 0 for my $j (0 .. $#{$jac->[0]}) {
451
452 # adjust value
453 0 $jac->[$i][$j] *= 327.68/65535;
454
455 }
456
457 }
458
459 # if encoding is 'ICC_XYZNumber'
460 0 ▶ } elsif ($encoding eq 'ICC_XYZNumber' && @{$jac} == 3) {
Condition0%0/3
$encoding eq "ICC_XYZNumber" and @{$jac;} == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "ICC_XYZNumber" and @{$jac;} == 3
$encoding eq "ICC_XYZNumber" @{$jac;} == 3
Truth table0%0/3
A and B
A= $encoding eq "ICC_XYZNumber"B= @{$jac;} == 3
ABresult
0X0
100
111
461
462 # for each XYZ
463 0 for my $i (0 .. 2) {
464
465 # for each spectral value
466 0 for my $j (0 .. $#{$jac->[0]}) {
467
468 # adjust value
469 0 $jac->[$i][$j] /= 100;
470
471 }
472
473 }
474
475 # if encoding is 'xyz'
476 0 ▶ } elsif ($encoding eq 'xyz' && @{$jac} == 3) {
Condition0%0/3
$encoding eq "xyz" and @{$jac;} == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "xyz" and @{$jac;} == 3
$encoding eq "xyz" @{$jac;} == 3
Truth table0%0/3
A and B
A= $encoding eq "xyz"B= @{$jac;} == 3
ABresult
0X0
100
111
477
478 # verify white point
479 0 ▶ ($self->[5][0] && $self->[5][1] && $self->[5][2]) or croak('invalid illuminant white point');
Branch: 1 branch
BranchTrueFalseTotal
$self->[5][0] and $self->[5][1] and $self->[5][2] or croak("invalid illuminant white point") 0 0 0
Condition0%0/6
$self->[5][0] and $self->[5][1] and $self->[5][2]
!ll&&!rl&&r
000
$self->[5][0] and $self->[5][1]
!ll&&!rl&&r
000
MC/DC0%0/3
$self->[5][0] and $self->[5][1] and $self->[5][2]
$self->[5][0] $self->[5][1] $self->[5][2]
Truth table0%0/4
A and B and C
A= $self->[5][0]B= $self->[5][1]C= $self->[5][2]
ABCresult
0XX0
10X0
1100
1111
480
481 # for each XYZ
482 0 for my $i (0 .. 2) {
483
484 # for each spectral value
485 0 for my $j (0 .. $#{$jac->[0]}) {
486
487 # adjust value
488 0 $jac->[$i][$j] /= $self->[5][$i];
489
490 }
491
492 }
493
494 # if encoding is 'unit'
495 0 ▶ } elsif ($encoding eq 'unit' && @{$jac} == 4) {
Condition0%0/3
$encoding eq "unit" and @{$jac;} == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "unit" and @{$jac;} == 4
$encoding eq "unit" @{$jac;} == 4
Truth table0%0/3
A and B
A= $encoding eq "unit"B= @{$jac;} == 4
ABresult
0X0
100
111
496
497 # for each RGBV
498 0 for my $i (0 .. 3) {
499
500 # for each spectral value
501 0 for my $j (0 .. $#{$jac->[0]}) {
502
503 # adjust value
504 0 $jac->[$i][$j] /= 100;
505
506 }
507
508 }
509
510 # if encoding is 'density'
511 0 ▶ } elsif ($encoding eq 'density' && @{$jac} == 4) {
Condition0%0/3
$encoding eq "density" and @{$jac;} == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "density" and @{$jac;} == 4
$encoding eq "density" @{$jac;} == 4
Truth table0%0/3
A and B
A= $encoding eq "density"B= @{$jac;} == 4
ABresult
0X0
100
111
512
513 # delete encoding
514 0 delete($hash->{'encoding'});
515
516 # get the output values (RGBV)
517 0 $out = _trans1($self, $in, $hash);
518
519 # verify output
520 0 ▶ ($out->[0] && $out->[1] && $out->[2] && $out->[3]) or croak('invalid density value');
Branch: 1 branch
BranchTrueFalseTotal
$out->[0] and $out->[1] and $out->[2] and $out->[3] or croak("invalid density value") 0 0 0
Condition0%0/9
$out->[0] and $out->[1] and $out->[2] and $out->[3]
!ll&&!rl&&r
000
$out->[0] and $out->[1] and $out->[2]
!ll&&!rl&&r
000
$out->[0] and $out->[1]
!ll&&!rl&&r
000
MC/DC0%0/4
$out->[0] and $out->[1] and $out->[2] and $out->[3]
$out->[0] $out->[1] $out->[2] $out->[3]
Truth table0%0/5
A and B and C and D
A= $out->[0]B= $out->[1]C= $out->[2]D= $out->[3]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
521
522 # for each RGBV
523 0 for my $i (0 .. 3) {
524
525 # compute scale factor
526 0 $sf = - $out->[$i] * ICC::Shared::ln10;
527
528 # for each spectral value
529 0 for my $j (0 .. $#{$jac->[0]}) {
530
531 # adjust value
532 0 $jac->[$i][$j] /= $sf;
533
534 }
535
536 }
537
538 # restore encoding
539 0 $hash->{'encoding'} = 'density';
540
541 } else {
542
543 # error
544 0 croak('unsupported XYZ/RGBV encoding');
545 }
546
547 }
548  
549 # if output vector wanted
550 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
551
552 # return Jacobian and output vector
553 0 return($jac, _trans1($self, $in, $hash));
554
555 } else {
556
557 # return Jacobian only
558 0 return($jac);
559
560 }
561
562 }
563  
564 # print object contents to string !!! needs work !!!
565 # format is an array structure
566 # parameter: ([format])
567 # returns: (string)
568 sub sdump {
569  
570 # get parameters
571 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
572  
573 # local variables
574 0 my ($s, $fmt);
575  
576 # resolve parameter to an array reference
577 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
578  
579 # get format string
580 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
581  
582 # set string to object ID
583 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
584  
585 # return
586 0 return($s);
587  
588 }
589  
590 # transform list
591 # parameters: (object_reference, list, [hash])
592 # returns: (list)
593 sub _trans0 {
594  
595 # local variables
596 0 ▶ my ($self, $hash);
Subroutine _trans0: not called CC=2 SCAR=17.9
597  
598 # get object reference
599 0 $self = shift();
600  
601 # get optional hash
602 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
603  
604 # return
605 0 return(@{_trans1($self, \@_, $hash)});
606  
607 }
608  
609 # transform vector
610 # parameters: (object_reference, vector, [hash])
611 # returns: (vector)
612 sub _trans1 {
613  
614 # get parameters
615 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans1: not called CC=8 SCAR=42.8
616  
617 # local variables
618 0 my ($range, $cwf, $out, $code);
619  
620 # check if ICC::Support::Lapack module is loaded
621 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
622  
623 # get input spectral range
624 0 ▶ ($range = $hash->{'range'} || $srh->{@{$in}}) or croak('spectral range must be specified');
Branch: 1 branch
BranchTrueFalseTotal
$range = $hash->{"range"} || $$ICC::Support::Color::srh{@{$in;}} or croak("spectral range must be specified") 0 0 0
Condition0%0/3
$hash->{'range'} || $$ICC::Support::Color::srh{@{$in;}}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hash->{'range'} || $$ICC::Support::Color::srh{@{$in;}}
$hash->{'range'} $$ICC::Support::Color::srh{@{$in;}}
Truth table0%0/3
A || B
A= $hash->{'range'}B= $$ICC::Support::Color::srh{@{$in;}}
ABresult
1X1
011
000
625  
626 # if data increment == cwf increment
627 0 ▶ if ($range->[2] == $self->[3][0][2]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($range->[2] == $self->[3][0][2]) { } 0 0 0
elsif ($range->[2] > $self->[3][0][2]) { } 0 0 0
628
629 # adjust cwf to match data range
630 0 $cwf = _adjust_cwf($self, $range);
631
632 # if data increment > cwf increment
633 } elsif ($range->[2] > $self->[3][0][2]) {
634
635 # adjust cwf to match data range
636 0 $cwf = _reduce_cwf($self, $range);
637
638 } else {
639
640 # error
641 0 croak('data increment < cwf increment');
642
643 }
644
645 # if ICC::Support::Lapack module is loaded
646 0 ▶ if ($lapack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lapack) { } 0 0 0
647
648 # compute output matrix using BLAS dgemv function
649 0 $out = ICC::Support::Lapack::matf_vec_trans($in, $cwf);
650
651 } else {
652
653 # for each XYZ or RGBV
654 0 for my $i (0 .. $#{$cwf}) {
655
656 # compute dot product
657 0 $out->[$i] = ICC::Shared::dotProduct($in, $cwf->[$i]);
658
659 }
660
661 }
662  
663 # return with optional encoding
664 0 ▶ return(defined($code = _encoding($self, $hash)) ? [&$code(@{$out})] : $out);
Branch: 1 branch
BranchTrueFalseTotal
defined($code = _encoding($self, $hash)) ? : 0 0 0
665  
666 }
667  
668 # transform matrix (2-D array -or- Math::Matrix object)
669 # parameters: (object_reference, matrix, [hash])
670 # returns: (matrix)
671 sub _trans2 {
672  
673 # get parameters
674 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans2: not called CC=11 SCAR=48.8
675  
676 # local variables
677 0 my ($range, $cwf, $out, $code);
678  
679 # check if ICC::Support::Lapack module is loaded
680 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
681  
682 # get input spectral range
683 0 ▶ ($range = $hash->{'range'} || $srh->{@{$in->[0]}}) or croak('spectral range must be specified');
Branch: 1 branch
BranchTrueFalseTotal
$range = $hash->{"range"} || $$ICC::Support::Color::srh{@{$in->[0];}} or croak("spectral range must be specified") 0 0 0
Condition0%0/3
$hash->{'range'} || $$ICC::Support::Color::srh{@{$in->[0];}}
l!l&&r!l&&!r
000
MC/DC0%0/2
$hash->{'range'} || $$ICC::Support::Color::srh{@{$in->[0];}}
$hash->{'range'} $$ICC::Support::Color::srh{@{$in->[0];}}
Truth table0%0/3
A || B
A= $hash->{'range'}B= $$ICC::Support::Color::srh{@{$in->[0];}}
ABresult
1X1
011
000
684  
685 # if data increment == cwf increment
686 0 ▶ if ($range->[2] == $self->[3][0][2]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($range->[2] == $self->[3][0][2]) { } 0 0 0
elsif ($range->[2] > $self->[3][0][2]) { } 0 0 0
687
688 # adjust cwf to match data range
689 0 $cwf = _adjust_cwf($self, $range);
690
691 # if data increment > cwf increment
692 } elsif ($range->[2] > $self->[3][0][2]) {
693
694 # adjust cwf to match data range
695 0 $cwf = _reduce_cwf($self, $range);
696  
697 } else {
698
699 # error
700 0 croak('data increment < cwf increment');
701
702 }
703  
704 # if ICC::Support::Lapack module is loaded
705 0 ▶ if ($lapack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lapack) { } 0 0 0
706
707 # compute output matrix using BLAS dgemm function
708 0 $out = ICC::Support::Lapack::matf_mat_trans($in, $cwf);
709
710 } else {
711
712 # for each sample
713 0 for my $i (0 .. $#{$in}) {
714
715 # for each XYZ or RGBV
716 0 for my $j (0 .. $#{$cwf}) {
717
718 # compute dot product
719 0 $out->[$i][$j] = ICC::Shared::dotProduct($in->[$i], $cwf->[$j]);
720
721 }
722
723 }
724
725 }
726  
727 # if encoding enabled
728 0 ▶ if ($code = _encoding($self, $hash)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code = _encoding($self, $hash)) 0 0 0
729
730 # for each sample
731 0 for my $i (0 .. $#{$out}) {
732
733 # apply encoding
734 0 @{$out->[$i]} = &$code(@{$out->[$i]});
735
736 }
737
738 }
739  
740 # return output (Math::Matrix object or 2-D array)
741 0 ▶ return(UNIVERSAL::isa($in, 'Math::Matrix') ? bless($out, 'Math::Matrix') : $out);
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($in, 'Math::Matrix') ? : 0 0 0
742  
743 }
744  
745 # transform structure
746 # parameters: (object_reference, structure, [hash])
747 # returns: (structure)
748 sub _trans3 {
749  
750 # get parameters
751 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans3: not called CC=1 SCAR=6.9
752  
753 # transform the array structure
754 0 _crawl($self, \&_trans1, $in, my $out = [], $hash);
755  
756 # return output structure
757 0 return($out);
758  
759 }
760  
761 # recursive transform
762 # array structure is traversed until all vectors are found and transformed
763 # parameters: (object_reference, subroutine_reference, input_array_reference, output_array_reference, hash)
764 sub _crawl {
765  
766 # get parameters
767 0 ▶ my ($self, $sub, $in, $out, $hash) = @_;
Subroutine _crawl: not called CC=4 SCAR=30.0
768  
769 # if input is a vector (reference to a numeric array)
770 0 ▶ if (@{$in} == grep {Scalar::Util::looks_like_number($_)} @{$in}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$in;} == grep({&Scalar::Util::looks_like_number($_);} @{$in;})) { } 0 0 0
771
772 # transform input vector and copy to output
773 0 @{$out} = @{$sub->($self, $in, $hash)};
774
775 } else {
776
777 # for each input element
778 0 for my $i (0 .. $#{$in}) {
779
780 # if an array reference
781 0 ▶ if (ref($in->[$i]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in->[$i] eq 'ARRAY') { } 0 0 0
782
783 # transform next level
784 0 _crawl($self, $sub, $in->[$i], $out->[$i] = [], $hash);
785
786 } else {
787
788 # error
789 0 croak('invalid input structure');
790
791 }
792
793 }
794
795 }
796
797 }
798  
799 # reduce cwf matrix to match data range
800 # the reduced cwf and data range is cached
801 # parameters: (object_reference, data_range)
802 # returns: (reduced_cwf)
803 sub _reduce_cwf {
804  
805 # get parameters
806 0 ▶ my ($self, $range_data) = @_;
Subroutine _reduce_cwf: not called CC=13 SCAR=52.0
807  
808 # local variables
809 0 my ($method, $bandpass, $range_cwf, $cwf, $mat);
810  
811 # if cached CWF matches data range
812 0 ▶ if (defined($self->[4][0]) && $self->[4][0][0] == $range_data->[0] && $self->[4][0][1] == $range_data->[1] && $self->[4][0][2] == $range_data->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[4][0] and $self->[4][0][0] == $range_data->[0] and $self->[4][0][1] == $range_data->[1] and $self->[4][0][2] == $range_data->[2]) 0 0 0
Condition0%0/9
defined $self->[4][0] and $self->[4][0][0] == $range_data->[0] and $self->[4][0][1] == $range_data->[1] and $self->[4][0][2] == $range_data->[2]
!ll&&!rl&&r
000
defined $self->[4][0] and $self->[4][0][0] == $range_data->[0] and $self->[4][0][1] == $range_data->[1]
!ll&&!rl&&r
000
defined $self->[4][0] and $self->[4][0][0] == $range_data->[0]
!ll&&!rl&&r
000
MC/DC0%0/4
defined $self->[4][0] and $self->[4][0][0] == $range_data->[0] and $self->[4][0][1] == $range_data->[1] and $self->[4][0][2] == $range_data->[2]
defined $self->[4][0] $self->[4][0][0] == $range_data->[0] $self->[4][0][1] == $range_data->[1] $self->[4][0][2] == $range_data->[2]
Truth table0%0/5
A and B and C and D
A= defined $self->[4][0]B= $self->[4][0][0] == $range_data->[0]C= $self->[4][0][1] == $range_data->[1]D= $self->[4][0][2] == $range_data->[2]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
813
814 # return cached CWF
815 0 return($self->[4][1]);
816
817 }
818  
819 # check if ICC::Support::Lapack module is loaded
820 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
821  
822 # get interpolation method
823 0 ▶ $method = $self->[0]{'method'} // 'cspline';
Condition0%0/2
$self->[0]{"method"} // "cspline"
l!l
00
MC/DC0%0/1
$self->[0]{"method"} // "cspline"
$self->[0]{"method"}
Truth table0%0/2
A
A= $self->[0]{"method"}
Aresult
11
00
824  
825 # get bandpass correction
826 0 ▶ $bandpass = $self->[0]{'bandpass'} // 0;
Condition0%0/2
$self->[0]{"bandpass"} // 0
l!l
00
MC/DC0%0/1
$self->[0]{"bandpass"} // 0
$self->[0]{"bandpass"}
Truth table0%0/2
A
A= $self->[0]{"bandpass"}
Aresult
11
00
827  
828 # get cwf range
829 0 $range_cwf = $self->[3][0];
830  
831 # if method is linear
832 0 ▶ if ($method eq 'linear') {
Branch: 3 branches
BranchTrueFalseTotal
if ($method eq 'linear') { } 0 0 0
elsif ($method eq 'cspline') { } 0 0 0
elsif ($method eq 'lagrange') { } 0 0 0
833
834 # compute linear interpolation matrix
835 0 $mat = ICC::Shared::linear_matrix($range_data, $range_cwf, 'copy');
836
837 # if method is cubic spline
838 } elsif ($method eq 'cspline') {
839
840 # compute cubic spline interpolation matrix
841 0 $mat = ICC::Shared::cspline_matrix($range_data, $range_cwf, 'copy');
842
843 # if method is Lagrange
844 } elsif ($method eq 'lagrange') {
845
846 # compute Lagrange interpolation matrix
847 0 $mat = ICC::Shared::lagrange_matrix($range_data, $range_cwf, 'copy');
848
849 } else {
850
851 # error
852 0 croak('invalid interpolation method');
853
854 }
855
856 # if ICC::Support::Lapack module is loaded
857 0 ▶ if ($lapack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lapack) { } 0 0 0
858
859 # compute cwf using BLAS dgemm function
860 0 $cwf = ICC::Support::Lapack::mat_xplus($self->[3][1], $mat);
861
862 # if bandpass correction is enabled
863 0 ▶ if ($bandpass) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bandpass) 0 0 0
864
865 # apply correction matrix
866 0 $cwf = ICC::Support::Lapack::mat_xplus($cwf, _bandpass($range_data, $method, $bandpass));
867
868 }
869
870 } else {
871
872 # compute cwf using Math::Matrix module
873 0 $cwf = bless(Storable::dclone($self->[3][1]), 'Math::Matrix') * $mat;
874
875 # if bandpass correction is enabled
876 0 ▶ if ($bandpass) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bandpass) 0 0 0
877
878 # apply correction matrix
879 0 $cwf = $cwf * _bandpass($range_data, $method, $bandpass);
880
881 }
882
883 }
884  
885 # cache reduced CWF
886 0 $self->[4][0] = $range_data;
887 0 $self->[4][1] = $cwf;
888  
889 # return
890 0 return($cwf);
891  
892 }
893  
894 # make bandpass correction matrix
895 # per ASTM E 2729 or deconvolution
896 # parameters: (data_range, interpolation_method, bandpass_method)
897 # returns: (matrix)
898 sub _bandpass {
899  
900 # get parameters
901 0 ▶ my ($range_data, $method, $bandpass) = @_;
Subroutine _bandpass: not called CC=10 SCAR=47.0
902  
903 # local variables
904 0 my ($ix, $jx, $range_mat, $mati, $matc, $bpf, $info, $matrix);
905  
906 # compute bandpass matrix upper index
907 0 $ix = ($range_data->[1] - $range_data->[0])/$range_data->[2];
908
909 # set bandpass function upper index
910 0 $jx = 20;
911  
912 # if bandpass value if 'astm'
913 0 ▶ if ($bandpass eq 'astm') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bandpass eq 'astm') { } 0 0 0
914
915 # return ASTM E 2729 bandpass rectification matrix
916 0 return(_bandpass_astm($ix));
917
918 } else {
919
920 # compute interpolation matrix range
921 0 $range_mat = [$range_data->[0] - $range_data->[2], $range_data->[1] + $range_data->[2], $range_data->[2]/10];
922
923 # if method is linear
924 0 ▶ if ($method eq 'linear') {
Branch: 3 branches
BranchTrueFalseTotal
if ($method eq 'linear') { } 0 0 0
elsif ($method eq 'cspline') { } 0 0 0
elsif ($method eq 'lagrange') { } 0 0 0
925
926 # compute linear interpolation matrix
927 0 $mati = ICC::Shared::linear_matrix($range_data, $range_mat, 'linear');
928
929 # if method is cubic spline
930 } elsif ($method eq 'cspline') {
931
932 # compute cubic spline interpolation matrix
933 0 $mati = ICC::Shared::cspline_matrix($range_data, $range_mat, 'linear');
934
935 # if method is Lagrange
936 } elsif ($method eq 'lagrange') {
937
938 # compute Lagrange interpolation matrix
939 0 $mati = ICC::Shared::lagrange_matrix($range_data, $range_mat, 'linear');
940
941 } else {
942
943 # error
944 0 croak('invalid interpolation method');
945
946 }
947
948 # if bandpass value if 'triangle'
949 0 ▶ if ($bandpass eq 'triangle') {
Branch: 3 branches
BranchTrueFalseTotal
if ($bandpass eq 'triangle') { } 0 0 0
elsif ($bandpass eq 'trapezoid') { } 0 0 0
elsif (ref $bandpass eq 'ARRAY' and $#{$bandpass;} == $jx) { } 0 0 0
950
951 # compute bandpass function array
952 0 $bpf = _bandpass_fn(1, $jx);
953
954 # if bandpass value if 'trapezoid' (combination of three triangular sub-bands)
955 } elsif ($bandpass eq 'trapezoid') {
956
957 # compute bandpass function array
958 0 $bpf = _bandpass_fn(1/3, $jx);
959
960 # if bandpass value is an array reference
961 0 ▶ } elsif (ref($bandpass) eq 'ARRAY' && $#{$bandpass} == $jx) {
Condition0%0/3
ref $bandpass eq "ARRAY" and $#{$bandpass;} == $jx
!ll&&!rl&&r
000
MC/DC0%0/2
ref $bandpass eq "ARRAY" and $#{$bandpass;} == $jx
ref $bandpass eq "ARRAY" $#{$bandpass;} == $jx
Truth table0%0/3
A and B
A= ref $bandpass eq "ARRAY"B= $#{$bandpass;} == $jx
ABresult
0X0
100
111
962
963 # set value
964 0 $bpf = $bandpass;
965
966 } else {
967
968 # error
969 0 croak('invalid bandpass correction');
970
971 }
972
973 # compute convolution matrix
974 0 $matc = _conv_matrix($bpf, $ix);
975
976 # check if ICC::Support::Lapack module is loaded
977 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
978
979 # if Lapack module loaded
980 0 ▶ if ($lapack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lapack) { } 0 0 0
981
982 # multiply matrices and invert using Lapack module
983 0 ($info, $matrix) = ICC::Support::Lapack::inv(ICC::Support::Lapack::mat_xplus($matc, $mati));
984
985 # return deconvolution matrix
986 0 return(bless($matrix, 'Math::Matrix'));
987
988 } else {
989
990 # return deconvolution matrix
991 0 return(($matc * $mati)->invert());
992
993 }
994
995 }
996
997 }
998  
999 # make ASTM E 2729 bandpass rectification matrix
1000 # parameter: (upper_index)
1001 # returns: (matrix)
1002 sub _bandpass_astm {
1003  
1004 # get upper index
1005 0 ▶ my $ix = shift();
Subroutine _bandpass_astm: not called CC=16 SCAR=56.1
1006  
1007 # local variables
1008 0 my ($matrix, @zeros);
1009  
1010 # make array of zeros
1011 0 @zeros = (0) x ($ix + 1);
1012  
1013 # for each matrix row
1014 0 for my $i (0 .. $ix) {
1015
1016 # set the row to zeros
1017 0 $matrix->[$i] = [@zeros];
1018
1019 # for each matrix column
1020 0 for my $j (0 .. $ix) {
1021
1022 # if main diagonal
1023 0 ▶ if ($i == $j) {
Branch: 3 branches
BranchTrueFalseTotal
if ($i == $j) { } 0 0 0
elsif (abs $i - $j == 1 and $i > 0 and $i < $ix) { } 0 0 0
elsif (abs $i - $j == 2 and $i > 0 and $i < $ix) { } 0 0 0
1024
1025 0 ▶ if ($i == 0 || $i == $ix) {
Branch: 2 branches
BranchTrueFalseTotal
if ($i == 0 or $i == $ix) { } 0 0 0
elsif ($i == 1 or $i == $ix - 1) { } 0 0 0
Condition0%0/3
$i == 0 or $i == $ix
l!l&&r!l&&!r
000
MC/DC0%0/2
$i == 0 or $i == $ix
$i == 0 $i == $ix
Truth table0%0/3
A or B
A= $i == 0B= $i == $ix
ABresult
1X1
011
000
1026
1027 0 $matrix->[$i][$j] = 1;
1028
1029 ▶ } elsif ($i == 1 || $i == $ix - 1) {
Condition0%0/3
$i == 1 or $i == $ix - 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$i == 1 or $i == $ix - 1
$i == 1 $i == $ix - 1
Truth table0%0/3
A or B
A= $i == 1B= $i == $ix - 1
ABresult
1X1
011
000
1030
1031 0 $matrix->[$i][$j] = 1.21;
1032
1033 } else {
1034
1035 0 $matrix->[$i][$j] = 1.22;
1036
1037 }
1038
1039 # if +/- 1 diagonal, and not the first or last rows
1040 ▶ } elsif (abs($i - $j) == 1 && $i > 0 && $i < $ix) {
Condition0%0/6
abs $i - $j == 1 and $i > 0 and $i < $ix
!ll&&!rl&&r
000
abs $i - $j == 1 and $i > 0
!ll&&!rl&&r
000
MC/DC0%0/3
abs $i - $j == 1 and $i > 0 and $i < $ix
abs $i - $j == 1 $i > 0 $i < $ix
Truth table0%0/4
A and B and C
A= abs $i - $j == 1B= $i > 0C= $i < $ix
ABCresult
0XX0
10X0
1100
1111
1041
1042 0 ▶ if ($j == 0 || $j == $ix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j == 0 or $j == $ix) { } 0 0 0
Condition0%0/3
$j == 0 or $j == $ix
l!l&&r!l&&!r
000
MC/DC0%0/2
$j == 0 or $j == $ix
$j == 0 $j == $ix
Truth table0%0/3
A or B
A= $j == 0B= $j == $ix
ABresult
1X1
011
000
1043
1044 0 $matrix->[$i][$j] = -0.10;
1045
1046 } else {
1047
1048 0 $matrix->[$i][$j] = -0.12;
1049
1050 }
1051
1052 # if +/- 2 diagonal, and not the first or last rows
1053 ▶ } elsif (abs($i - $j) == 2 && $i > 0 && $i < $ix) {
Condition0%0/6
abs $i - $j == 2 and $i > 0 and $i < $ix
!ll&&!rl&&r
000
abs $i - $j == 2 and $i > 0
!ll&&!rl&&r
000
MC/DC0%0/3
abs $i - $j == 2 and $i > 0 and $i < $ix
abs $i - $j == 2 $i > 0 $i < $ix
Truth table0%0/4
A and B and C
A= abs $i - $j == 2B= $i > 0C= $i < $ix
ABCresult
0XX0
10X0
1100
1111
1054
1055 0 $matrix->[$i][$j] = 0.01;
1056
1057 }
1058
1059 }
1060
1061 }
1062  
1063 # return Math::Matrix object
1064 0 return(bless($matrix, 'Math::Matrix'));
1065  
1066 }
1067  
1068 # make simple bandpass function
1069 # shape ranges from 0 to 1 (rectangular to triangular)
1070 # upper index must be divisible by 4
1071 # parameters: (shape, upper_index)
1072 # returns: (bandpass_array)
1073 sub _bandpass_fn {
1074  
1075 # get parameters
1076 0 ▶ my ($shape, $ix) = @_;
Subroutine _bandpass_fn: not called CC=9 SCAR=45.0
1077  
1078 # local variables
1079 0 my ($m, $v, @array, $sum);
1080  
1081 # verify shape
1082 0 ▶ ($shape >= 0 && $shape <= 1) or croak('invalid shape parameter');
Branch: 1 branch
BranchTrueFalseTotal
$shape >= 0 and $shape <= 1 or croak("invalid shape parameter") 0 0 0
Condition0%0/3
$shape >= 0 and $shape <= 1
!ll&&!rl&&r
000
MC/DC0%0/2
$shape >= 0 and $shape <= 1
$shape >= 0 $shape <= 1
Truth table0%0/3
A and B
A= $shape >= 0B= $shape <= 1
ABresult
0X0
100
111
1083  
1084 # verify upper index
1085 0 ▶ ($ix == int($ix) && ! ($ix % 4)) or croak('invalid upper index');
Branch: 1 branch
BranchTrueFalseTotal
$ix == int $ix and not $ix % 4 or croak("invalid upper index") 0 0 0
Condition0%0/3
$ix == int $ix and not $ix % 4
!ll&&!rl&&r
000
MC/DC0%0/2
$ix == int $ix and not $ix % 4
$ix == int $ix not $ix % 4
Truth table0%0/3
A and not(B)
A= $ix == int $ixB= not $ix % 4
ABresult
0X0
100
111
1086  
1087 # if shape not rectangular
1088 0 ▶ if ($shape) {
Branch: 1 branch
BranchTrueFalseTotal
if ($shape) { } 0 0 0
1089
1090 # compute slope
1091 0 $m = 2/($shape * $ix);
1092
1093 } else {
1094
1095 # set slope to big number
1096 0 $m = 1E100;
1097
1098 }
1099  
1100 # for each array element
1101 0 for my $i (0 .. $ix/2) {
1102
1103 # compute value
1104 0 $v = ($i - $ix/4) * $m + 0.5;
1105
1106 # set array elements to limited value
1107 0 ▶ $array[$i] = $array[$ix - $i] = $v < 0 ? 0 : $v > 1 ? 1 : $v;
Branch: 2 branches
BranchTrueFalseTotal
$v < 0 ? : 0 0 0
$v > 1 ? : 0 0 0
1108
1109 }
1110  
1111 # compute array sum
1112 0 $sum = List::Util::sum(@array);
1113  
1114 # return normalized array
1115 0 return([map {$_/$sum} @array]);
1116  
1117 }
1118  
1119 # make convolution matrix
1120 # parameters: (bandpass_function_vector, row_upper_index)
1121 # returns: (convolution_matrix)
1122 sub _conv_matrix {
1123  
1124 # get parameters
1125 0 ▶ my ($bpf, $ix) = @_;
Subroutine _conv_matrix: not called CC=6 SCAR=37.4
1126  
1127 # local variables
1128 0 my ($n, $p, @zeros, $mat);
1129  
1130 # verify bandpass function
1131 0 ▶ (@{$bpf} % 2) or croak('bandpass function must have odd number of elements');
Branch: 1 branch
BranchTrueFalseTotal
@{$bpf;} % 2 or croak("bandpass function must have odd number of elements") 0 0 0
1132  
1133 # verify row upper index
1134 0 ▶ ($ix == int($ix) && $ix >= 0) or croak('row upper index must be an integer >= 0');
Branch: 1 branch
BranchTrueFalseTotal
$ix == int $ix and $ix >= 0 or croak("row upper index must be an integer >= 0") 0 0 0
Condition0%0/3
$ix == int $ix and $ix >= 0
!ll&&!rl&&r
000
MC/DC0%0/2
$ix == int $ix and $ix >= 0
$ix == int $ix $ix >= 0
Truth table0%0/3
A and B
A= $ix == int $ixB= $ix >= 0
ABresult
0X0
100
111
1135  
1136 # compute upper column index
1137 0 $n = $#{$bpf} * ($ix + 2)/2;
1138  
1139 # compute bandpass increment
1140 0 $p = $#{$bpf}/2;
1141  
1142 # make array of zeros
1143 0 @zeros = (0) x ($n + 1);
1144  
1145 # for each row
1146 0 for my $i (0 .. $ix) {
1147
1148 # add row of zeros
1149 0 $mat->[$i] = [@zeros];
1150
1151 # for each bandpass value
1152 0 for my $j (0 .. $#{$bpf}) {
1153
1154 # copy bandpass value
1155 0 $mat->[$i][$i * $p + $j] = $bpf->[$j];
1156
1157 }
1158
1159 }
1160  
1161 # return
1162 0 return(bless($mat, 'Math::Matrix'));
1163  
1164 }
1165  
1166 # adjust cwf matrix to match data range
1167 # the adjusted cwf and data range is cached
1168 # parameters: (object_reference, data_range)
1169 # returns: (adjusted_cwf)
1170 sub _adjust_cwf {
1171  
1172 # get parameters
1173 0 ▶ my ($self, $range_data) = @_;
Subroutine _adjust_cwf: not called CC=10 SCAR=47.0
1174  
1175 # local variables
1176 0 my ($bandpass, $off, $cwf);
1177  
1178 # if cached CWF matches data range
1179 0 ▶ if (defined($self->[4][0]) && $self->[4][0][0] == $range_data->[0] && $self->[4][0][1] == $range_data->[1] && $self->[4][0][2] == $range_data->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[4][0] and $self->[4][0][0] == $range_data->[0] and $self->[4][0][1] == $range_data->[1] and $self->[4][0][2] == $range_data->[2]) 0 0 0
Condition0%0/9
defined $self->[4][0] and $self->[4][0][0] == $range_data->[0] and $self->[4][0][1] == $range_data->[1] and $self->[4][0][2] == $range_data->[2]
!ll&&!rl&&r
000
defined $self->[4][0] and $self->[4][0][0] == $range_data->[0] and $self->[4][0][1] == $range_data->[1]
!ll&&!rl&&r
000
defined $self->[4][0] and $self->[4][0][0] == $range_data->[0]
!ll&&!rl&&r
000
MC/DC0%0/4
defined $self->[4][0] and $self->[4][0][0] == $range_data->[0] and $self->[4][0][1] == $range_data->[1] and $self->[4][0][2] == $range_data->[2]
defined $self->[4][0] $self->[4][0][0] == $range_data->[0] $self->[4][0][1] == $range_data->[1] $self->[4][0][2] == $range_data->[2]
Truth table0%0/5
A and B and C and D
A= defined $self->[4][0]B= $self->[4][0][0] == $range_data->[0]C= $self->[4][0][1] == $range_data->[1]D= $self->[4][0][2] == $range_data->[2]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1180
1181 # return cached CWF
1182 0 return($self->[4][1]);
1183
1184 }
1185  
1186 # check if ICC::Support::Lapack module is loaded
1187 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
1188  
1189 # get bandpass correction
1190 0 ▶ $bandpass = $self->[0]{'bandpass'} // 0;
Condition0%0/2
$self->[0]{"bandpass"} // 0
l!l
00
MC/DC0%0/1
$self->[0]{"bandpass"} // 0
$self->[0]{"bandpass"}
Truth table0%0/2
A
A= $self->[0]{"bandpass"}
Aresult
11
00
1191  
1192 # compute range offset
1193 0 $off = abs(($range_data->[0] - $self->[3][0][0])/$range_data->[2]);
1194  
1195 # verify offset is an integer
1196 0 ▶ (abs($off - ICC::Shared::round($off)) < 1E-12) or croak('range offset not an integer');
Branch: 1 branch
BranchTrueFalseTotal
abs $off - ICC::Shared::round($off) < "1e-12" or croak("range offset not an integer") 0 0 0
1197  
1198 # adjust CWF matrix
1199 0 $cwf = _adjust_matrix($self->[3][1], $self->[3][0], $range_data);
1200  
1201 # if bandpass correction enabled, and not table 6
1202 0 ▶ if ($bandpass && $bandpass ne 'six') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bandpass and $bandpass ne "six") 0 0 0
Condition0%0/3
$bandpass and $bandpass ne "six"
!ll&&!rl&&r
000
MC/DC0%0/2
$bandpass and $bandpass ne "six"
$bandpass $bandpass ne "six"
Truth table0%0/3
A and B
A= $bandpassB= $bandpass ne "six"
ABresult
0X0
100
111
1203
1204 # if ICC::Support::Lapack module is loaded
1205 0 ▶ if ($lapack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lapack) { } 0 0 0
1206
1207 # apply correction matrix
1208 0 $cwf = ICC::Support::Lapack::mat_xplus($cwf, _bandpass($range_data, 'lagrange', $bandpass));
1209
1210 } else {
1211
1212 # apply correction matrix
1213 0 $cwf = bless($cwf, 'Math::Matrix') * _bandpass($range_data, 'lagrange', $bandpass);
1214
1215 }
1216
1217 }
1218  
1219 # cache adjusted CWF
1220 0 $self->[4][0] = $range_data;
1221 0 $self->[4][1] = $cwf;
1222  
1223 # return
1224 0 return($cwf);
1225  
1226 }
1227  
1228 # adjust matrix to match data range
1229 # parameters: (matrix, matrix_range, data_range)
1230 # returns: (adjusted_matrix)
1231 sub _adjust_matrix {
1232  
1233 # get parameters
1234 0 ▶ my ($matrix, $range_matrix, $range_data) = @_;
Subroutine _adjust_matrix: not called CC=6 SCAR=37.4
1235  
1236 # local variables
1237 0 my ($adj, $j);
1238  
1239 # clone matrix
1240 0 $adj = Storable::dclone($matrix);
1241  
1242 # for each function
1243 0 for my $i (0 .. $#{$adj}) {
1244
1245 # if cwf start < data start
1246 0 ▶ if ($range_matrix->[0] < $range_data->[0]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($range_matrix->[0] < $range_data->[0]) { } 0 0 0
elsif ($range_matrix->[0] > $range_data->[0]) { } 0 0 0
1247
1248 # compute number of elements to combine
1249 0 $j = int(($range_data->[0] - $range_matrix->[0])/$range_data->[2] + 1.5);
1250
1251 # combine elements
1252 0 splice(@{$adj->[$i]}, 0, $j, List::Util::sum(@{$adj->[$i]}[0 .. ($j - 1)]));
1253
1254 # if cwf start > data start
1255 } elsif ($range_matrix->[0] > $range_data->[0]) {
1256
1257 # compute number of zeros to add
1258 0 $j = int(($range_matrix->[0] - $range_data->[0])/$range_data->[2] + 0.5);
1259
1260 # add zeros
1261 0 unshift(@{$adj->[$i]}, (0) x $j);
1262
1263 }
1264
1265 # if cwf end > data end
1266 0 ▶ if ($range_matrix->[1] > $range_data->[1]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($range_matrix->[1] > $range_data->[1]) { } 0 0 0
elsif ($range_matrix->[1] < $range_data->[1]) { } 0 0 0
1267
1268 # compute number of elements to combine
1269 0 $j = int(($range_matrix->[1] - $range_data->[1])/$range_data->[2] + 1.5);
1270
1271 # combine elements
1272 0 splice(@{$adj->[$i]}, -$j, $j, List::Util::sum(@{$adj->[$i]}[-$j .. -1]));
1273
1274 # if cwf end < data end
1275 } elsif ($range_matrix->[1] < $range_data->[1]) {
1276
1277 # compute number of zeros to add
1278 0 $j = int(($range_data->[1] - $range_matrix->[1])/$range_data->[2] + 0.5);
1279
1280 # add zeros
1281 0 push(@{$adj->[$i]}, (0) x $j);
1282
1283 }
1284
1285 }
1286  
1287 # return
1288 0 return($adj);
1289  
1290 }
1291  
1292 # compute CIE color-weight functions
1293 # parameters: (object_reference)
1294 # results are saved in the object
1295 # cwf cache is cleared
1296 sub _make_cwf {
1297  
1298 # get parameters
1299 0 ▶ my $self = shift();
Subroutine _make_cwf: not called CC=17 SCAR=57.2
1300  
1301 # local variables
1302 0 my ($range, $obs, $inc, $smooth, $method, $bandpass, $matc, $illum, $spd, $ks, @k, @Wx, @Wy, @Wz);
1303  
1304 # if cwf_range key defined
1305 0 ▶ if (defined($self->[0]{'cwf_range'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->[0]{'cwf_range'}) { } 0 0 0
elsif ($self->[2][0][2] != ($inc = $self->[0]{'increment'} // 1)) { } 0 0 0
1306
1307 # use supplied range
1308 0 $range = $self->[0]{'cwf_range'};
1309
1310 # interpolate observer functions, with linear extrapolation
1311 0 $obs = ICC::Support::Lapack::matf_mat_trans($self->[2][1], ICC::Shared::cspline_matrix($self->[2][0], $range, 'linear'));
1312
1313 # if observer requires interpolation
1314 ▶ } elsif ($self->[2][0][2] != ($inc = $self->[0]{'increment'} // 1)) {
Condition0%0/2
$self->[0]{"increment"} // 1
l!l
00
MC/DC0%0/1
$self->[0]{"increment"} // 1
$self->[0]{"increment"}
Truth table0%0/2
A
A= $self->[0]{"increment"}
Aresult
11
00
1315
1316 # use observer range, changing increment
1317 0 $range = [$self->[2][0][0], $self->[2][0][1], $inc];
1318
1319 # interpolate observer functions
1320 0 $obs = ICC::Support::Lapack::matf_mat_trans($self->[2][1], ICC::Shared::cspline_matrix($self->[2][0], $range));
1321
1322 } else {
1323
1324 # use observer range
1325 0 $range = $self->[2][0];
1326
1327 # get observer functions
1328 0 $obs = $self->[2][1];
1329
1330 }
1331  
1332 # if observer requires exponentiation
1333 0 ▶ if ($self->[0]{'observer_exp'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[0]{"observer_exp"}) 0 0 0
1334
1335 # for each spectral value
1336 0 for my $i (0 .. $#{$obs->[0]}) {
1337
1338 # exponentiate
1339 0 $obs->[0][$i] = exp($obs->[0][$i]);
1340 0 $obs->[1][$i] = exp($obs->[1][$i]);
1341 0 $obs->[2][$i] = exp($obs->[2][$i]);
1342
1343 }
1344
1345 }
1346  
1347 # if illuminant is defined
1348 0 ▶ if (defined($self->[1][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1][0]) { } 0 0 0
1349
1350 # compute illuminant smoothness
1351 0 $smooth = _smoothness($self->[1][1]);
1352
1353 # get illuminant interpolation method
1354 0 ▶ $method = $self->[0]{'imethod'} // ($smooth == 0 || $smooth > 0.001) ? 'linear' : 'cspline';
Branch: 1 branch
BranchTrueFalseTotal
$self->[0]{'imethod'} // ($smooth == 0 || $smooth > 0.001) ? : 0 0 0
Condition0%0/6
$self->[0]{"imethod"} // ($smooth == 0 || $smooth > "0.001")
l!l&&r!l&&!r
000
$smooth == 0 or $smooth > "0.001"
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->[0]{"imethod"} // ($smooth == 0 || $smooth > "0.001")
$self->[0]{"imethod"} $smooth == 0 $smooth > "0.001"
Truth table0%0/4
A // B or C
A= $self->[0]{"imethod"}B= $smooth == 0C= $smooth > "0.001"
ABCresult
1XX1
01X1
0011
0000
1355
1356 # if illuminant bandpass correction enabled
1357 0 ▶ if (defined($bandpass = $self->[0]{'ibandpass'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($bandpass = $self->[0]{'ibandpass'})) { } 0 0 0
1358
1359 # compute bandpass correction matrix
1360 0 $matc = _bandpass($self->[1][0], $method, $bandpass);
1361
1362 # apply bandpass correction matrix
1363 0 $illum = [map {ICC::Shared::dotProduct($self->[1][1], $_)} @{$matc}];
1364
1365 } else {
1366
1367 # use illuminant as is
1368 0 $illum = $self->[1][1];
1369
1370 }
1371
1372 # if method is linear
1373 0 ▶ if ($method eq 'linear') {
Branch: 3 branches
BranchTrueFalseTotal
if ($method eq 'linear') { } 0 0 0
elsif ($method eq 'cspline') { } 0 0 0
elsif ($method eq 'lagrange') { } 0 0 0
1374
1375 # interpolate illuminant data
1376 0 $spd = ICC::Shared::linear($illum, $self->[1][0], $range, 'copy');
1377
1378 # if method is cubic spline
1379 } elsif ($method eq 'cspline') {
1380
1381 # interpolate illuminant data
1382 0 $spd = ICC::Shared::cspline($illum, $self->[1][0], $range, 'copy');
1383
1384 # if method is Lagrange -or- ASTM E 2022
1385 } elsif ($method eq 'lagrange') {
1386
1387 # interpolate illuminant data
1388 0 $spd = ICC::Shared::lagrange($illum, $self->[1][0], $range, 'copy');
1389
1390 } else {
1391
1392 # error
1393 0 croak('invalid illuminant interpolation method');
1394
1395 }
1396
1397 # get or compute summation constant
1398 0 ▶ $ks = $self->[0]{'cwf_ks'} // 100/ICC::Shared::dotProduct($spd, $obs->[1]);
Condition0%0/3
$self->[0]{"cwf_ks"} // 100 / ICC::Shared::dotProduct($spd, $obs->[1])
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->[0]{"cwf_ks"} // 100 / ICC::Shared::dotProduct($spd, $obs->[1])
$self->[0]{"cwf_ks"} 100 / ICC::Shared::dotProduct($spd, $obs->[1])
Truth table0%0/3
A // B
A= $self->[0]{"cwf_ks"}B= 100 / ICC::Shared::dotProduct($spd, $obs->[1])
ABresult
1X1
011
000
1399
1400 # for each spectral value
1401 0 for my $i (0 .. $#{$obs->[0]}) {
1402
1403 # compute spectral products (k * illuminant * observer)
1404 0 $Wx[$i] = $ks * $spd->[$i] * $obs->[0][$i];
1405 0 $Wy[$i] = $ks * $spd->[$i] * $obs->[1][$i];
1406 0 $Wz[$i] = $ks * $spd->[$i] * $obs->[2][$i];
1407
1408 }
1409
1410 } else {
1411
1412 # compute summation constants (slightly different for X, Y, Z)
1413 0 $k[0] = 100/List::Util::sum(@{$obs->[0]});
1414 0 $k[1] = 100/List::Util::sum(@{$obs->[1]});
1415 0 $k[2] = 100/List::Util::sum(@{$obs->[2]});
1416
1417 # for each spectral value
1418 0 for my $i (0 .. $#{$obs->[0]}) {
1419
1420 # compute spectral products (k * observer)
1421 0 $Wx[$i] = $k[0] * $obs->[0][$i];
1422 0 $Wy[$i] = $k[1] * $obs->[1][$i];
1423 0 $Wz[$i] = $k[2] * $obs->[2][$i];
1424
1425 }
1426
1427 }
1428  
1429 # set wavelength range (start, end, and increment)
1430 0 $self->[3][0] = [@{$range}];
1431  
1432 # set color-weight functions
1433 0 $self->[3][1][0] = [@Wx];
1434 0 $self->[3][1][1] = [@Wy];
1435 0 $self->[3][1][2] = [@Wz];
1436  
1437 # set illuminant white point (XYZ)
1438 0 $self->[5][0] = List::Util::sum(@Wx);
1439 0 $self->[5][1] = List::Util::sum(@Wy);
1440 0 $self->[5][2] = List::Util::sum(@Wz);
1441  
1442 # clear adjusted CWF cache
1443 0 $self->[4] = [];
1444  
1445 }
1446  
1447 # read CIE illuminant and color-matching functions
1448 # compute color-weight functions (k * illuminant * observer) and white point
1449 # illuminant, observer and increment specified in hash
1450 # parameters: (object_reference, hash)
1451 # results are saved in the object
1452 sub _cie {
1453  
1454 # get parameters
1455 0 ▶ my ($self, $hash) = @_;
Subroutine _cie: not called CC=38 SCAR=73.0
1456  
1457 # local variables
1458 0 my ($array, @files, $illum, $s, $w, $sx);
1459 0 my ($inc, $obs, $cmf, $key);
1460  
1461 # get copy of illuminant array
1462 0 $array = Storable::dclone($hash->{'illuminant'});
1463  
1464 # if empty array (emissive)
1465 0 ▶ if (! @{$array}) {
Branch: 4 branches
BranchTrueFalseTotal
if (not @{$array;}) { } 0 0 0
elsif (@files = grep({-f $_;} File::Glob::bsd_glob($array->[0]))) { } 0 0 0
elsif (@files = grep({-f $_;} File::Glob::bsd_glob(ICC::Shared::getICCPath("Data/$array->[0]_illums_*.yml")))) { } 0 0 0
elsif (@{$array;} == grep({ref $_ eq 'ARRAY';} @{$array;})) { } 0 0 0
1466
1467 # clear illuminant
1468 0 $self->[1] = [];
1469
1470 # if a measured illuminant (file path)
1471 0 } elsif (@files = grep {-f} File::Glob::bsd_glob($array->[0])) {
1472
1473 # make new chart object
1474 0 $illum = ICC::Support::Chart->new($files[0]);
1475
1476 # get sample from hash (default is 1)
1477 0 ▶ $s = defined($array->[1]) ? $array->[1] : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $array->[1] ? : 0 0 0
1478
1479 # verify sample
1480 0 ▶ (Scalar::Util::looks_like_number($s) && $s == int($s) && $s > 0 && $s <= $illum->size()) or croak('invalid sample number');
Branch: 1 branch
BranchTrueFalseTotal
&Scalar::Util::looks_like_number($s) and $s == int $s and $s > 0 and $s <= $illum->size or croak("invalid sample number") 0 0 0
Condition0%0/9
&Scalar::Util::looks_like_number($s) and $s == int $s and $s > 0 and $s <= $illum->size
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($s) and $s == int $s and $s > 0
!ll&&!rl&&r
000
&Scalar::Util::looks_like_number($s) and $s == int $s
!ll&&!rl&&r
000
MC/DC0%0/4
&Scalar::Util::looks_like_number($s) and $s == int $s and $s > 0 and $s <= $illum->size
&Scalar::Util::looks_like_number($s) $s == int $s $s > 0 $s <= $illum->size
Truth table0%0/5
A and B and C and D
A= &Scalar::Util::looks_like_number($s)B= $s == int $sC= $s > 0D= $s <= $illum->size
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1481
1482 # set wavelength range
1483 0 $self->[1][0] = $illum->nm();
1484
1485 # set spectral values
1486 0 ▶ ($self->[1][1] = $illum->spectral([$s])->[0]) or croak('illuminant chart has no spectral data');
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][1] = $illum->spectral([$s])->[0] or croak("illuminant chart has no spectral data") 0 0 0
1487
1488 # if a standard illuminant (YAML file in data folder)
1489 0 } elsif (@files = grep {-f} File::Glob::bsd_glob(ICC::Shared::getICCPath("Data/$array->[0]_illums_*.yml"))) {
1490
1491 # load standard illuminants (YAML format)
1492 0 $illum = YAML::Tiny->read($files[0])->[0];
1493
1494 # get wavelength vector
1495 0 $w = $illum->{'nm'};
1496
1497 # set wavelength range
1498 0 $self->[1][0] = [$w->[0], $w->[-1], $w->[1] - $w->[0]];
1499
1500 # set spectral values
1501 0 ▶ ($self->[1][1] = $illum->{$array->[1]}) or croak('standard illuminant not found');
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][1] = $$illum{$array->[1]} or croak("standard illuminant not found") 0 0 0
1502
1503 # if illuminant is two array references (wavelength range and spd vectors)
1504 0 } elsif (@{$array} == grep {ref() eq 'ARRAY'} @{$array}) {
1505
1506 # verify wavelength range
1507 0 ▶ (ref($array->[0]) eq 'ARRAY' && 3 == @{$array->[0]} && (3 == grep {Scalar::Util::looks_like_number($_)} @{$array->[0]}) && $array->[0][2]) or croak('invalid illuminant wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2] or croak("invalid illuminant wavelength range") 0 0 0
Condition0%0/9
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2]
!ll&&!rl&&r
000
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];})
!ll&&!rl&&r
000
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];}
!ll&&!rl&&r
000
MC/DC0%0/4
ref $array->[0] eq "ARRAY" and 3 == @{$array->[0];} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) and $array->[0][2]
ref $array->[0] eq "ARRAY" 3 == @{$array->[0];} 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];}) $array->[0][2]
Truth table0%0/5
A and B and C and D
A= ref $array->[0] eq "ARRAY"B= 3 == @{$array->[0];}C= 3 == grep({&Scalar::Util::looks_like_number($_);} @{$$array[0];})D= $array->[0][2]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1508
1509 # compute upper index of spd array
1510 0 ▶ (($sx = ICC::Shared::round(($array->[0][1] - $array->[0][0])/$array->[0][2])) > 0) or croak('inconsistent illuminant wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
($sx = ICC::Shared::round(($array->[0][1] - $array->[0][0]) / $array->[0][2])) > 0 or croak("inconsistent illuminant wavelength range") 0 0 0
1511
1512 # verify spd array
1513 0 ▶ (ref($array->[1]) eq 'ARRAY' && $#{$array->[1]} == $sx && @{$array->[1]} == grep {Scalar::Util::looks_like_number($_)} @{$array->[1]}) or croak('invalid illuminant spd array');
Branch: 1 branch
BranchTrueFalseTotal
ref $array->[1] eq "ARRAY" and $#{$$array[1];} == $sx and @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];}) or croak("invalid illuminant spd array") 0 0 0
Condition0%0/6
ref $array->[1] eq "ARRAY" and $#{$$array[1];} == $sx and @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];})
!ll&&!rl&&r
000
ref $array->[1] eq "ARRAY" and $#{$$array[1];} == $sx
!ll&&!rl&&r
000
MC/DC0%0/3
ref $array->[1] eq "ARRAY" and $#{$$array[1];} == $sx and @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];})
ref $array->[1] eq "ARRAY" $#{$$array[1];} == $sx @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];})
Truth table0%0/4
A and B and C
A= ref $array->[1] eq "ARRAY"B= $#{$$array[1];} == $sxC= @{$array->[1];} == grep({&Scalar::Util::looks_like_number($_);} @{$$array[1];})
ABCresult
0XX0
10X0
1100
1111
1514
1515 # copy array contents
1516 0 $self->[1] = Storable::dclone($array);
1517
1518 } else {
1519
1520 # error
1521 0 croak("invalid illuminant [@{$array}]");
1522
1523 }
1524  
1525 # get increment from hash (default is 1)
1526 0 ▶ $inc = defined($hash->{'increment'}) ? $hash->{'increment'} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'increment'} ? : 0 0 0
1527  
1528 # if increment is 1 nm
1529 0 ▶ if ($inc == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($inc == 1) { } 0 0 0
elsif ($inc == 5) { } 0 0 0
1530
1531 # set wavelength range
1532 0 $self->[2][0] = [360, 830, 1];
1533
1534 # load CIE color matching functions (YAML format)
1535 0 $cmf = YAML::Tiny->read(ICC::Shared::getICCPath('Data/CIE_cmfs_360-830_x_1.yml'))->[0];
1536
1537 # if increment is 5 nm
1538 } elsif ($inc == 5) {
1539
1540 # set wavelength range
1541 0 $self->[2][0] = [380, 780, 5];
1542
1543 # load CIE color matching functions (YAML format)
1544 0 $cmf = YAML::Tiny->read(ICC::Shared::getICCPath('Data/CIE_cmfs_380-780_x_5.yml'))->[0];
1545
1546 } else {
1547
1548 # error
1549 0 croak('invalid spectral increment');
1550
1551 }
1552  
1553 # get observer from hash (default is 2)
1554 0 ▶ $obs = defined($hash->{'observer'}) ? $hash->{'observer'} : 2;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'observer'} ? : 0 0 0
1555  
1556 # if observer is an array reference
1557 0 ▶ if (ref($obs) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $obs eq 'ARRAY') { } 0 0 0
1558
1559 # verify array size
1560 0 ▶ (@{$obs} == 2) or croak('invalid observer array');
Branch: 1 branch
BranchTrueFalseTotal
@{$obs;} == 2 or croak("invalid observer array") 0 0 0
1561
1562 # verify range
1563 0 (ref($obs->[0]) eq 'ARRAY' && (@{$obs->[0]} == grep {Scalar::Util::looks_like_number($_)} @{$obs->[0]}) &&
1564 0 ▶ @{$obs->[0]} == 3 && $obs->[0][2] && ! (($obs->[0][1] - $obs->[0][0]) % $obs->[0][2])) or croak('invalid observer wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
ref $obs->[0] eq "ARRAY" and @{$obs->[0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[0];}) and @{$obs->[0];} == 3 and $obs->[0][2] and not +($obs->[0][1] - $obs->[0][0]) % $obs->[0][2] or croak("invalid observer wavelength range") 0 0 0
Condition0%0/12
ref $obs->[0] eq "ARRAY" and @{$obs->[0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[0];}) and @{$obs->[0];} == 3 and $obs->[0][2] and not +($obs->[0][1] - $obs->[0][0]) % $obs->[0][2]
!ll&&!rl&&r
000
ref $obs->[0] eq "ARRAY" and @{$obs->[0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[0];}) and @{$obs->[0];} == 3 and $obs->[0][2]
!ll&&!rl&&r
000
ref $obs->[0] eq "ARRAY" and @{$obs->[0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[0];}) and @{$obs->[0];} == 3
!ll&&!rl&&r
000
ref $obs->[0] eq "ARRAY" and @{$obs->[0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[0];})
!ll&&!rl&&r
000
MC/DC0%0/5
ref $obs->[0] eq "ARRAY" and @{$obs->[0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[0];}) and @{$obs->[0];} == 3 and $obs->[0][2] and not +($obs->[0][1] - $obs->[0][0]) % $obs->[0][2]
ref $obs->[0] eq "ARRAY" @{$obs->[0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[0];}) @{$obs->[0];} == 3 $obs->[0][2] not +($obs->[0][1] - $obs->[0][0]) % $obs->[0][2]
Truth table0%0/6
A and B and C and D and not(E)
A= ref $obs->[0] eq "ARRAY"B= @{$obs->[0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[0];})C= @{$obs->[0];} == 3D= $obs->[0][2]E= not +($obs->[0][1] - $obs->[0][0]) % $obs->[0][2]
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
1565
1566 # compute upper index of observer matrix
1567 0 ▶ (($sx = ICC::Shared::round(($obs->[0][1] - $obs->[0][0])/$obs->[0][2])) > 0) or croak('inconsistent observer wavelength range');
Branch: 1 branch
BranchTrueFalseTotal
($sx = ICC::Shared::round(($obs->[0][1] - $obs->[0][0]) / $obs->[0][2])) > 0 or croak("inconsistent observer wavelength range") 0 0 0
1568
1569 # verify observer matrix
1570 ((ref($obs->[1]) eq 'ARRAY' || UNIVERSAL::isa($obs->[1], 'Math::Matrix')) && ref($obs->[1][0]) eq 'ARRAY' &&
1571 0 ▶ $#{$obs->[1][0]} == $sx && @{$obs->[1][0]} == grep {Scalar::Util::looks_like_number($_)} @{$obs->[1][0]}) or croak('invalid observer cmf matrix');
Branch: 1 branch
BranchTrueFalseTotal
ref $obs->[1] eq "ARRAY" || UNIVERSAL::isa($obs->[1], "Math::Matrix") and ref $obs->[1][0] eq "ARRAY" and $#{$$obs[1][0];} == $sx and @{$obs->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[1][0];}) or croak("invalid observer cmf matrix") 0 0 0
Condition0%0/12
ref $obs->[1] eq "ARRAY" || UNIVERSAL::isa($obs->[1], "Math::Matrix") and ref $obs->[1][0] eq "ARRAY" and $#{$$obs[1][0];} == $sx and @{$obs->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[1][0];})
!ll&&!rl&&r
000
ref $obs->[1] eq "ARRAY" || UNIVERSAL::isa($obs->[1], "Math::Matrix") and ref $obs->[1][0] eq "ARRAY" and $#{$$obs[1][0];} == $sx
!ll&&!rl&&r
000
ref $obs->[1] eq "ARRAY" || UNIVERSAL::isa($obs->[1], "Math::Matrix") and ref $obs->[1][0] eq "ARRAY"
!ll&&!rl&&r
000
ref $obs->[1] eq "ARRAY" or UNIVERSAL::isa($obs->[1], "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/5
ref $obs->[1] eq "ARRAY" || UNIVERSAL::isa($obs->[1], "Math::Matrix") and ref $obs->[1][0] eq "ARRAY" and $#{$$obs[1][0];} == $sx and @{$obs->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[1][0];})
ref $obs->[1] eq "ARRAY" UNIVERSAL::isa($obs->[1], "Math::Matrix") ref $obs->[1][0] eq "ARRAY" $#{$$obs[1][0];} == $sx @{$obs->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[1][0];})
Truth table0%0/9
A or B and C and D and E
A= ref $obs->[1] eq "ARRAY"B= UNIVERSAL::isa($obs->[1], "Math::Matrix")C= ref $obs->[1][0] eq "ARRAY"D= $#{$$obs[1][0];} == $sxE= @{$obs->[1][0];} == grep({&Scalar::Util::looks_like_number($_);} @{$$obs[1][0];})
ABCDEresult
00XXX0
1X0XX0
010XX0
1X10X0
0110X0
1X1100
011100
1X1111
011111
1572
1573 # copy array contents
1574 0 $self->[2] = Storable::dclone($obs);
1575
1576 } else {
1577
1578 # get observer key
1579 0 ▶ ($key = {'2' => 'CIE1931', '10' => 'CIE1964', '2P' => 'CIE2012D2', '10P' => 'CIE2012D10'}->{$obs}) or croak('invalid observer key');
Branch: 1 branch
BranchTrueFalseTotal
$key = {2, "CIE1931", 10, "CIE1964", "2P", "CIE2012D2", "10P", "CIE2012D10"}->{$obs} or croak("invalid observer key") 0 0 0
1580
1581 # set CIE color-matching functions
1582 0 $self->[2][1][0] = $cmf->{$key . 'x'};
1583 0 $self->[2][1][1] = $cmf->{$key . 'y'};
1584 0 $self->[2][1][2] = $cmf->{$key . 'z'};
1585
1586 }
1587  
1588 # compute color-weight functions
1589 0 _make_cwf($self);
1590  
1591 # set object type
1592 0 $self->[0]{'type'} = 'CIE';
1593  
1594 }
1595  
1596 # read ASTM color weight functions and white point
1597 # illuminant, observer, increment and bandpass specified in hash
1598 # parameters: (object_reference, hash)
1599 # results are saved in the object
1600 sub _astm {
1601  
1602 # get parameters
1603 0 ▶ my ($self, $hash) = @_;
Subroutine _astm: not called CC=12 SCAR=50.5
1604  
1605 # local variables
1606 0 my ($table, $id, @bpc, @inc, @obs, @illum, @m, $nm);
1607  
1608 # initialize id
1609 0 $id = 1;
1610  
1611 # if increment key in hash
1612 0 ▶ if (defined($hash->{'increment'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"increment"}) 0 0 0
1613
1614 # enumerate ASTM increments
1615 0 @inc = qw(10 20);
1616
1617 # match observer value
1618 0 ▶ (@m = grep {$hash->{'increment'} eq $inc[$_]} (0 .. $#inc)) || warn('invalid increment value - using 10 nm');
Branch: 1 branch
BranchTrueFalseTotal
@m = grep({$hash->{"increment"} eq $inc[$_];} 0 .. $#inc) or warn "invalid increment value - using 10 nm" 0 0 0
1619
1620 # adjust id for increment
1621 0 ▶ $id += @m ? $m[0] : 0;
Branch: 1 branch
BranchTrueFalseTotal
@m ? : 0 0 0
1622
1623 }
1624  
1625 # if observer key in hash
1626 0 ▶ if (defined($hash->{'observer'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"observer"}) 0 0 0
1627
1628 # enumerate ASTM observers
1629 0 @obs = qw(2 10);
1630
1631 # match observer value
1632 0 ▶ (@m = grep {$hash->{'observer'} eq $obs[$_]} (0 .. $#obs)) || warn('invalid observer value - using 1931 2º');
Branch: 1 branch
BranchTrueFalseTotal
@m = grep({$hash->{"observer"} eq $obs[$_];} 0 .. $#obs) or warn "invalid observer value - using 1931 2\302\272" 0 0 0
1633
1634 # adjust id for observer
1635 0 ▶ $id += @m ? 2 * $m[0] : 0;
Branch: 1 branch
BranchTrueFalseTotal
@m ? : 0 0 0
1636
1637 }
1638  
1639 # if illuminant key in hash
1640 0 ▶ if (defined($hash->{'illuminant'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{'illuminant'}) { } 0 0 0
1641
1642 # enumerate ASTM illuminants
1643 0 @illum = qw(A C D50 D55 D65 D75 F2 F7 F11);
1644
1645 # match illuminant value
1646 0 ▶ (@m = grep {$hash->{'illuminant'} eq $illum[$_]} (0 .. $#illum)) || warn('invalid illuminant value - using D50');
Branch: 1 branch
BranchTrueFalseTotal
@m = grep({$hash->{"illuminant"} eq $illum[$_];} 0 .. $#illum) or warn "invalid illuminant value - using D50" 0 0 0
1647
1648 # adjust id for illuminant
1649 0 ▶ $id += @m ? 4 * $m[0] : 8;
Branch: 1 branch
BranchTrueFalseTotal
@m ? : 0 0 0
1650
1651 } else {
1652
1653 # adjust id for D50 illuminant
1654 0 $id += 8;
1655
1656 }
1657  
1658 # set table: 5 (no bpc) -or- 6 (with bpc)
1659 # note: table 6 is deprecated in ASTM E 2729
1660 0 ▶ $table = (defined($hash->{'bandpass'}) && $hash->{'bandpass'} eq 'six') ? 6 : 5;
Branch: 1 branch
BranchTrueFalseTotal
defined $hash->{'bandpass'} && $hash->{'bandpass'} eq 'six' ? : 0 0 0
Condition0%0/3
defined $hash->{"bandpass"} and $hash->{"bandpass"} eq "six"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash->{"bandpass"} and $hash->{"bandpass"} eq "six"
defined $hash->{"bandpass"} $hash->{"bandpass"} eq "six"
Truth table0%0/3
A and B
A= defined $hash->{"bandpass"}B= $hash->{"bandpass"} eq "six"
ABresult
0X0
100
111
1661  
1662 # combine table and id
1663 0 $table .= '.' . $id;
1664  
1665 # load ASTM weight functions (YAML format)
1666 0 state $ASTM = YAML::Tiny->read(ICC::Shared::getICCPath('Data/ASTM_E308_data.yml'))->[0];
1667  
1668 # get wavelength vector
1669 0 $nm = $ASTM->{$table . 'nm'};
1670  
1671 # set wavelength start, end, and increment
1672 0 $self->[3][0] = [$nm->[0], $nm->[-1], $nm->[1] - $nm->[0]];
1673  
1674 # set color-weight functions
1675 0 $self->[3][1][0] = $ASTM->{$table . 'x'};
1676 0 $self->[3][1][1] = $ASTM->{$table . 'y'};
1677 0 $self->[3][1][2] = $ASTM->{$table . 'z'};
1678  
1679 # set illuminant white point
1680 0 $self->[5] = $ASTM->{$table . 'wp'};
1681  
1682 # set object type
1683 0 $self->[0]{'type'} = 'ASTM';
1684  
1685 }
1686  
1687 # read ISO 5-3 density weight functions
1688 # status and increment specified in hash
1689 # parameters: (object_reference, hash)
1690 # results are saved in the object
1691 sub _iso {
1692  
1693 # get parameters
1694 0 ▶ my ($self, $hash) = @_;
Subroutine _iso: not called CC=7 SCAR=40.3
1695  
1696 # local variables
1697 0 my ($status, $inc, @m, $nm);
1698  
1699 # initialize table selectors
1700 0 $status = 'T';
1701 0 $inc = '10';
1702  
1703 # if status key in hash
1704 0 ▶ if (defined($hash->{'status'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"status"}) 0 0 0
1705
1706 # match status value
1707 0 ▶ (@m = grep {$hash->{'status'} eq $_} qw(A M T E I)) || warn('invalid status value - using T');
Branch: 1 branch
BranchTrueFalseTotal
@m = grep({$hash->{"status"} eq $_;} "A", "M", "T", "E", "I") or warn "invalid status value - using T" 0 0 0
1708
1709 # set status
1710 0 ▶ $status = @m ? $m[0] : 'T';
Branch: 1 branch
BranchTrueFalseTotal
@m ? : 0 0 0
1711
1712 }
1713  
1714 # if increment key in hash
1715 0 ▶ if (defined($hash->{'increment'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $hash->{"increment"}) 0 0 0
1716
1717 # match observer value
1718 0 ▶ (@m = grep {$hash->{'increment'} eq $_} qw(10 20)) || warn('invalid increment value - using 10 nm');
Branch: 1 branch
BranchTrueFalseTotal
@m = grep({$hash->{"increment"} eq $_;} 10, 20) or warn "invalid increment value - using 10 nm" 0 0 0
1719
1720 # set increment
1721 0 ▶ $inc = @m ? $m[0] : '10';
Branch: 1 branch
BranchTrueFalseTotal
@m ? : 0 0 0
1722
1723 }
1724  
1725 # load ISO 5-3 weight functions (YAML format)
1726 0 state $ISO = YAML::Tiny->read(ICC::Shared::getICCPath('Data/ISO_5-3_data.yml'))->[0];
1727  
1728 # get wavelength vector
1729 0 $nm = $ISO->{$inc . 'nm'};
1730  
1731 # set wavelength start, end, and increment
1732 0 $self->[3][0] = [$nm->[0], $nm->[-1], $nm->[1] - $nm->[0]];
1733  
1734 # set density weight functions
1735 0 $self->[3][1][0] = $ISO->{$inc . $status . 'r'};
1736 0 $self->[3][1][1] = $ISO->{$inc . $status . 'g'};
1737 0 $self->[3][1][2] = $ISO->{$inc . $status . 'b'};
1738 0 $self->[3][1][3] = $ISO->{$inc . 'vis'};
1739  
1740 # set density weight function sums
1741 0 $self->[5][0] = List::Util::sum(@{$self->[3][1][0]});
1742 0 $self->[5][1] = List::Util::sum(@{$self->[3][1][1]});
1743 0 $self->[5][2] = List::Util::sum(@{$self->[3][1][2]});
1744 0 $self->[5][3] = List::Util::sum(@{$self->[3][1][3]});
1745  
1746 # set object type
1747 0 $self->[0]{'type'} = 'ISO';
1748  
1749 }
1750  
1751 # compute vector smoothness
1752 # (returns 0 if vector is linear)
1753 # parameter: (vector)
1754 # returns: (linearity)
1755 sub _smoothness {
1756  
1757 # get parameter
1758 0 ▶ my $v = shift();
Subroutine _smoothness: not called CC=4 SCAR=30.0
1759  
1760 # local variables
1761 0 my ($d, $s);
1762  
1763 # return if < 3 vector elements
1764 0 ▶ return(0) if (@{$v} < 3);
Branch: 1 branch
BranchTrueFalseTotal
if @{$v;} < 3 0 0 0
1765  
1766 # for each triplet
1767 0 for my $i (0 .. $#{$v} - 2) {
1768
1769 # add linear deviation
1770 0 $d += (2 * $v->[$i + 1] - $v->[$i] - $v->[$i + 2])**2;
1771
1772 # add outer magnitudes
1773 0 $s += abs($v->[$i]) + abs($v->[$i + 2]);
1774
1775 }
1776  
1777 # return relative rms value
1778 0 ▶ return($s ? sqrt($d)/$s : 0);
Branch: 1 branch
BranchTrueFalseTotal
$s ? : 0 0 0
1779  
1780 }
1781  
1782 # get encoding CODE reference
1783 # parameter(object_reference, hash)
1784 # returns: (CODE_reference)
1785 sub _encoding {
1786  
1787 # get parameters
1788 0 ▶ my ($self, $hash) = @_;
Subroutine _encoding: not called CC=16 SCAR=56.1
1789  
1790 # local variables
1791 0 my ($encoding, $size);
1792  
1793 # if hash contain 'encoding' value, but not 'XYZ', 'RGBV' or 'linear'
1794 0 ▶ if (defined($encoding = $hash->{'encoding'}) && $encoding !~ m/^(XYZ|RGBV|linear)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($encoding = $hash->{'encoding'}) and not $encoding =~ /^(XYZ|RGBV|linear)$/) { } 0 0 0
Condition0%0/3
defined($encoding = $hash->{"encoding"}) and not $encoding =~ /^(XYZ|RGBV|linear)$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined($encoding = $hash->{"encoding"}) and not $encoding =~ /^(XYZ|RGBV|linear)$/
defined($encoding = $hash->{"encoding"}) not $encoding =~ /^(XYZ|RGBV|linear)$/
Truth table0%0/3
A and not(B)
A= defined($encoding = $hash->{"encoding"})B= not $encoding =~ /^(XYZ|RGBV|linear)$/
ABresult
0X0
100
111
1795
1796 # get output size
1797 0 $size = @{$self->[3][1]};
1798
1799 # if encoding is 'ICC_XYZ'
1800 0 ▶ if ($encoding eq 'ICC_XYZ' && $size == 3) {
Branch: 5 branches
BranchTrueFalseTotal
if ($encoding eq 'ICC_XYZ' and $size == 3) { } 0 0 0
elsif ($encoding eq 'ICC_XYZNumber' and $size == 3) { } 0 0 0
elsif ($encoding eq 'xyz' and $size == 3) { } 0 0 0
elsif ($encoding eq 'unit' and $size == 4) { } 0 0 0
elsif ($encoding eq 'density' and $size == 4) { } 0 0 0
Condition0%0/3
$encoding eq "ICC_XYZ" and $size == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "ICC_XYZ" and $size == 3
$encoding eq "ICC_XYZ" $size == 3
Truth table0%0/3
A and B
A= $encoding eq "ICC_XYZ"B= $size == 3
ABresult
0X0
100
111
1801
1802 # return code reference
1803 0 ▶ return(sub {map {$_ * 327.68/65535} @_});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1804
1805 # if encoding is 'ICC_XYZNumber'
1806 ▶ } elsif ($encoding eq 'ICC_XYZNumber' && $size == 3) {
Condition0%0/3
$encoding eq "ICC_XYZNumber" and $size == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "ICC_XYZNumber" and $size == 3
$encoding eq "ICC_XYZNumber" $size == 3
Truth table0%0/3
A and B
A= $encoding eq "ICC_XYZNumber"B= $size == 3
ABresult
0X0
100
111
1807
1808 # return code reference
1809 0 ▶ return(sub {map {$_/100} @_});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1810
1811 # if encoding is 'xyz'
1812 ▶ } elsif ($encoding eq 'xyz' && $size == 3) {
Condition0%0/3
$encoding eq "xyz" and $size == 3
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "xyz" and $size == 3
$encoding eq "xyz" $size == 3
Truth table0%0/3
A and B
A= $encoding eq "xyz"B= $size == 3
ABresult
0X0
100
111
1813
1814 # verify white point
1815 0 ▶ ($self->[5][0] && $self->[5][1] && $self->[5][2]) or croak('invalid illuminant white point');
Branch: 1 branch
BranchTrueFalseTotal
$self->[5][0] and $self->[5][1] and $self->[5][2] or croak("invalid illuminant white point") 0 0 0
Condition0%0/6
$self->[5][0] and $self->[5][1] and $self->[5][2]
!ll&&!rl&&r
000
$self->[5][0] and $self->[5][1]
!ll&&!rl&&r
000
MC/DC0%0/3
$self->[5][0] and $self->[5][1] and $self->[5][2]
$self->[5][0] $self->[5][1] $self->[5][2]
Truth table0%0/4
A and B and C
A= $self->[5][0]B= $self->[5][1]C= $self->[5][2]
ABCresult
0XX0
10X0
1100
1111
1816
1817 # return code reference
1818 0 ▶ return(sub {$_[0]/$self->[5][0], $_[1]/$self->[5][1], $_[2]/$self->[5][2]});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1819
1820 # if encoding is 'unit'
1821 ▶ } elsif ($encoding eq 'unit' && $size == 4) {
Condition0%0/3
$encoding eq "unit" and $size == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "unit" and $size == 4
$encoding eq "unit" $size == 4
Truth table0%0/3
A and B
A= $encoding eq "unit"B= $size == 4
ABresult
0X0
100
111
1822
1823 # return code reference
1824 0 ▶ return(sub {map {$_/100} @_});
Subroutine __ANON__: not called CC=1 SCAR=6.9
1825
1826 # if encoding is 'density'
1827 ▶ } elsif ($encoding eq 'density' && $size == 4) {
Condition0%0/3
$encoding eq "density" and $size == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$encoding eq "density" and $size == 4
$encoding eq "density" $size == 4
Truth table0%0/3
A and B
A= $encoding eq "density"B= $size == 4
ABresult
0X0
100
111
1828
1829 # return code reference
1830 0 ▶ return(sub {map {$_ > 0 ? -POSIX::log10($_/100) : 99} @_});
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_ > 0 ? : 0 0 0
1831
1832 } else {
1833
1834 # error
1835 0 croak('unsupported XYZ/RGBV encoding');
1836
1837 }
1838
1839 } else {
1840
1841 # return empty
1842 0 return();
1843
1844 }
1845
1846 }
1847  
1848 # set object contents from parameter hash
1849 # parameters: (object_reference, ref_to_parameter_hash)
1850 sub _new_from_hash {
1851  
1852 # get parameters
1853 0 ▶ my ($self, $hash) = @_;
Subroutine _new_from_hash: not called CC=12 SCAR=50.5
1854  
1855 # local variables
1856 0 my ($range, $ox);
1857  
1858 # save colorimetry hash in object header
1859 0 $self->[0] = Storable::dclone($hash);
1860  
1861 # if 'range' is defined
1862 0 ▶ if (defined($range = $hash->{'range'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($range = $hash->{"range"})) 0 0 0
1863
1864 # verify wavelength range structure
1865 0 ▶ (ref($range) eq 'ARRAY' && 3 == @{$range} && (3 == grep {Scalar::Util::looks_like_number($_)} @{$range})) or croak('invalid wavelength range structure');
Branch: 1 branch
BranchTrueFalseTotal
ref $range eq "ARRAY" and 3 == @{$range;} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$range;}) or croak("invalid wavelength range structure") 0 0 0
Condition0%0/6
ref $range eq "ARRAY" and 3 == @{$range;} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$range;})
!ll&&!rl&&r
000
ref $range eq "ARRAY" and 3 == @{$range;}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $range eq "ARRAY" and 3 == @{$range;} and 3 == grep({&Scalar::Util::looks_like_number($_);} @{$range;})
ref $range eq "ARRAY" 3 == @{$range;} 3 == grep({&Scalar::Util::looks_like_number($_);} @{$range;})
Truth table0%0/4
A and B and C
A= ref $range eq "ARRAY"B= 3 == @{$range;}C= 3 == grep({&Scalar::Util::looks_like_number($_);} @{$range;})
ABCresult
0XX0
10X0
1100
1111
1866
1867 # compute upper index
1868 0 $ox = ICC::Shared::round(($range->[1] - $range->[0])/$range->[2]);
1869
1870 # verify wavelength range values
1871 0 ▶ ($ox > 0 && abs($ox * $range->[2] - $range->[1] + $range->[0]) < 1E-12 && $range->[2] > 0) or croak('invalid wavelength range values');
Branch: 1 branch
BranchTrueFalseTotal
$ox > 0 and abs $ox * $range->[2] - $range->[1] + $range->[0] < "1e-12" and $range->[2] > 0 or croak("invalid wavelength range values") 0 0 0
Condition0%0/6
$ox > 0 and abs $ox * $range->[2] - $range->[1] + $range->[0] < "1e-12" and $range->[2] > 0
!ll&&!rl&&r
000
$ox > 0 and abs $ox * $range->[2] - $range->[1] + $range->[0] < "1e-12"
!ll&&!rl&&r
000
MC/DC0%0/3
$ox > 0 and abs $ox * $range->[2] - $range->[1] + $range->[0] < "1e-12" and $range->[2] > 0
$ox > 0 abs $ox * $range->[2] - $range->[1] + $range->[0] < "1e-12" $range->[2] > 0
Truth table0%0/4
A and B and C
A= $ox > 0B= abs $ox * $range->[2] - $range->[1] + $range->[0] < "1e-12"C= $range->[2] > 0
ABCresult
0XX0
10X0
1100
1111
1872
1873 # add range to hash
1874 0 $srh->{$ox + 1} = $range;
1875
1876 }
1877  
1878 # if 'status' is defined, a scalar
1879 0 ▶ if (defined($hash->{'status'}) && ! ref($hash->{'status'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $hash->{'status'} and not ref $hash->{'status'}) { } 0 0 0
elsif (defined $hash->{'illuminant'} and ref $hash->{'illuminant'} eq 'ARRAY') { } 0 0 0
Condition0%0/3
defined $hash->{"status"} and not ref $hash->{"status"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $hash->{"status"} and not ref $hash->{"status"}
defined $hash->{"status"} not ref $hash->{"status"}
Truth table0%0/3
A and not(B)
A= defined $hash->{"status"}B= not ref $hash->{"status"}
ABresult
0X0
100
111
1880
1881 # read ISO 5-3 color-weight functions (density)
1882 0 _iso($self, $hash);
1883
1884 # if 'illuminant' is defined, an ARRAY ref
1885 ▶ } elsif (defined($hash->{'illuminant'}) && ref($hash->{'illuminant'}) eq 'ARRAY') {
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
1886
1887 # read CIE illuminant and color-matching functions, compute color-weight functions
1888 0 _cie($self, $hash);
1889
1890 } else {
1891
1892 # read ASTM color-weight functions
1893 0 _astm($self, $hash);
1894
1895 }
1896
1897 }
1898  
1899 2 1;
1900  
« lib/ICC/Support/spline.pm ↑ Summary blib/lib/ICC/Profile.pm »