blib/lib/ICC/Profile/clut.pm

filter: Statementstmt 12.6% 73 / 576 Branchbran 5.4% 13 / 238 Conditioncond 0.0% 0 / 110 MC/DCmcdc 0.0% 0 / 67 Subroutinesub 32.5% 13 / 40 Podpod 6.2% 1 / 16 totaltotal 9.5% 100 / 1047 CC 207 SCAR 54.3
CC
207
Cov
9%
build
930.0
_trans2
342.0
_new_from_hash
342.0
CRAP 228.9
« blib/lib/ICC/Support/rbf.pm ↑ Summary lib/ICC/Support/bern.pm »
1 package ICC::Profile::clut;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = 0.21;
7  
8 # revised 2016-05-17
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 7 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 7 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # use POSIX math
19 7 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # enable static variables
22 7 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 # create new clut object
25 # hash may contain pointers to clut, grid size array or user-defined functions
26 # hash keys are: ('array', 'clut_bytes', 'gsa', 'udf')
27 # parameters: ([ref_to_attribute_hash])
28 # returns: (ref_to_object)
29 sub new {
30  
31 # get object class
32 5 ▶ my $class = shift();
Subroutine new: called CC=4 SCAR=20.1
Pod undocumented
33  
34 # create empty clut object
35 5 my $self = [
36 {}, # object header
37 [], # clut
38 [], # grid size array
39 [], # user-defined functions
40 undef, # clut cache (for Lapack)
41 undef, # corner point cache
42 ];
43  
44 # if there are parameters
45 5 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 5 5
46
47 # if one parameter, a hash reference
48 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
49
50 # make new clut object from attribute hash
51 0 _new_from_hash($self, @_);
52
53 } else {
54
55 # error
56 0 croak('parameter must be a hash reference');
57
58 }
59
60 }
61  
62 # bless object
63 5 bless($self, $class);
64  
65 # return object reference
66 5 return($self);
67  
68 }
69  
70 # get/set reference to header hash
71 # parameters: ([ref_to_new_hash])
72 # returns: (ref_to_hash)
73 sub header {
74
75 # get object reference
76 0 ▶ my $self = shift();
Subroutine header: not called CC=4 SCAR=30.0
Pod undocumented
77
78 # if there are parameters
79 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
80
81 # if one parameter, a hash reference
82 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
83
84 # set header to new hash
85 0 $self->[0] = {%{shift()}};
86
87 } else {
88
89 # error
90 0 croak('parameter must be a hash reference');
91
92 }
93
94 }
95
96 # return reference
97 0 return($self->[0]);
98
99 }
100  
101 # get/set reference to clut array
102 # parameters: ([ref_to_new_array])
103 # returns: (ref_to_array)
104 sub array {
105  
106 # get object reference
107 0 ▶ my $self = shift();
Subroutine array: not called CC=9 SCAR=45.0
Pod undocumented
108  
109 # if there are parameters
110 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
111
112 # if one parameter, a 2-D array reference
113 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY' && @{$_[0]} == grep {ref() eq 'ARRAY'} @{$_[0]}) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY' and @{$_[0];} == grep({ref $_ eq 'ARRAY';} @{$_[0];})) { } 0 0 0
elsif (@_ == 1 and UNIVERSAL::isa($_[0], 'Math::Matrix')) { } 0 0 0
Condition0%0/6
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
!ll&&!rl&&r
000
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
@_ == 1 ref $_[0] eq "ARRAY" @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
Truth table0%0/4
A and B and C
A= @_ == 1B= ref $_[0] eq "ARRAY"C= @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
ABCresult
0XX0
10X0
1100
1111
114
115 # set clut to clone of array
116 0 $self->[1] = Storable::dclone($_[0]);
117
118 # update caches
119 0 ▶ $self->[4] = ICC::Support::Lapack::cache_2D($self->[1]) if (defined($INC{'ICC/Support/Lapack.pm'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $INC{"ICC/Support/Lapack.pm"} 0 0 0
120 0 undef($self->[5]);
121
122 # if one parameter, a Math::Matrix object
123 ▶ } elsif (@_ == 1 && UNIVERSAL::isa($_[0], 'Math::Matrix')) {
Condition0%0/3
@_ == 1 and UNIVERSAL::isa($_[0], "Math::Matrix")
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and UNIVERSAL::isa($_[0], "Math::Matrix")
@_ == 1 UNIVERSAL::isa($_[0], "Math::Matrix")
Truth table0%0/3
A and B
A= @_ == 1B= UNIVERSAL::isa($_[0], "Math::Matrix")
ABresult
0X0
100
111
124
125 # set clut to object
126 0 $self->[1] = $_[0];
127
128 # update caches
129 0 ▶ $self->[4] = ICC::Support::Lapack::cache_2D($self->[1]) if (defined($INC{'ICC/Support/Lapack.pm'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $INC{"ICC/Support/Lapack.pm"} 0 0 0
130 0 undef($self->[5]);
131
132 } else {
133
134 # error
135 0 croak('clut array must be a 2-D array reference or Math::Matrix object');
136
137 }
138
139 }
140  
141 # return reference
142 0 return($self->[1]);
143  
144 }
145  
146 # get/set reference to grid size array
147 # parameters: ([ref_to_new_array])
148 # returns: (ref_to_array)
149 sub gsa {
150  
151 # get object reference
152 38 ▶ my $self = shift();
Subroutine gsa: called CC=5 SCAR=28.8
Pod undocumented
153  
154 # if there are parameters
155 38 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 38 38
156
157 # if one parameter, an array reference
158 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY' && @{$_[0]} == grep {! ref()} @{$_[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY' and @{$_[0];} == grep({not ref $_;} @{$_[0];})) { } 0 0 0
Condition0%0/6
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({not ref $_;} @{$_[0];})
!ll&&!rl&&r
000
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({not ref $_;} @{$_[0];})
@_ == 1 ref $_[0] eq "ARRAY" @{$_[0];} == grep({not ref $_;} @{$_[0];})
Truth table0%0/4
A and B and C
A= @_ == 1B= ref $_[0] eq "ARRAY"C= @{$_[0];} == grep({not ref $_;} @{$_[0];})
ABCresult
0XX0
10X0
1100
1111
159
160 # set gsa to copy of array
161 0 $self->[2] = [@{shift()}];
162
163 } else {
164
165 # error
166 0 croak('clut gsa must be an array reference');
167
168 }
169
170 }
171  
172 # return reference
173 38 return($self->[2]);
174  
175 }
176  
177 # get/set reference to user-defined functions array
178 # parameters: ([ref_to_new_array])
179 # returns: (ref_to_array)
180 sub udf {
181
182 # get object reference
183 0 ▶ my $self = shift();
Subroutine udf: not called CC=5 SCAR=34.0
Pod undocumented
184
185 # if there are parameters
186 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
187
188 # if one parameter, an array reference
189 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY' && @{$_[0]} == grep {ref() eq 'CODE'} @{$_[0]}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY' and @{$_[0];} == grep({ref $_ eq 'CODE';} @{$_[0];})) { } 0 0 0
Condition0%0/6
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({ref $_ eq "CODE";} @{$_[0];})
!ll&&!rl&&r
000
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
@_ == 1 and ref $_[0] eq "ARRAY" and @{$_[0];} == grep({ref $_ eq "CODE";} @{$_[0];})
@_ == 1 ref $_[0] eq "ARRAY" @{$_[0];} == grep({ref $_ eq "CODE";} @{$_[0];})
Truth table0%0/4
A and B and C
A= @_ == 1B= ref $_[0] eq "ARRAY"C= @{$_[0];} == grep({ref $_ eq "CODE";} @{$_[0];})
ABCresult
0XX0
10X0
1100
1111
190
191 # set udf to copy of array
192 0 $self->[3] = [@{shift()}];
193
194 } else {
195
196 # error
197 0 croak('parameter must be an array reference');
198
199 }
200
201 }
202
203 # return reference
204 0 return($self->[3]);
205
206 }
207  
208 # get/set reference to clut array element
209 # array element is an array of output values
210 # parameters: (index_array, [ref_to_new_array])
211 # returns: (ref_to_array)
212 sub clut {
213  
214 # get object reference
215 0 ▶ my $self = shift();
Subroutine clut: not called CC=10 SCAR=47.0
Pod undocumented
216  
217 # local variables
218 0 my ($lx, $ref, $gsa);
219  
220 # get reference to new array (if present)
221 0 ▶ $ref = pop() if (ref($_[-1]) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "ARRAY" 0 0 0
222  
223 # get grid size array
224 0 $gsa = $self->[2];
225  
226 # validate indices
227 0 ▶ (@_ == @{$gsa}) || croak('wrong number of clut indices');
Branch: 1 branch
BranchTrueFalseTotal
@_ == @{$gsa;} or croak("wrong number of clut indices") 0 0 0
228 0 ▶ (@_ == grep {! ref() && $_ == int($_)} @_) || croak('clut index not an integer');
Branch: 2 branches
BranchTrueFalseTotal
@_ == grep({not ref $_ and $_ == int $_;} @_) or croak("clut index not an integer") 0 0 0
not ref $_ and $_ == int $_ 0 0 0
229 0 ▶ (@_ == grep {$_[$_] >= 0 && $_[$_] < $gsa->[$_]} 0 .. $#_) || croak('clut index out of range');
Branch: 2 branches
BranchTrueFalseTotal
@_ == grep({$_[$_] >= 0 and $_[$_] < $gsa->[$_];} 0 .. $#_) or croak("clut index out of range") 0 0 0
$_[$_] >= 0 and $_[$_] < $gsa->[$_] 0 0 0
230  
231 # initialize clut pointer
232 0 $lx = $_[0];
233  
234 # for each remaining index
235 0 for my $i (1 .. $#_) {
236
237 # multiply by grid size
238 0 $lx *= $gsa->[$i];
239
240 # add index
241 0 $lx += $_[$i];
242
243 }
244  
245 # if replacement data provided
246 0 ▶ if (defined($ref)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref) 0 0 0
247
248 # update CLUT
249 0 $self->[1][$lx] = [@{$ref}];
250
251 # update caches
252 0 ▶ $self->[4] = ICC::Support::Lapack::cache_2D($self->[1]) if (defined($INC{'ICC/Support/Lapack.pm'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $INC{"ICC/Support/Lapack.pm"} 0 0 0
253 0 undef($self->[5]);
254
255 }
256  
257 # return array reference
258 0 return($self->[1][$lx]);
259  
260 }
261  
262 # create clut object from ICC profile
263 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
264 # returns: (ref_to_object)
265 sub new_fh {
266  
267 # get object class
268 0 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
269  
270 # create empty clut object
271 0 my $self = [
272 {}, # object header
273 [], # clut
274 [], # grid size array
275 [] # user-defined functions
276 ];
277  
278 # verify 3 parameters
279 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
280  
281 # read clut data from profile
282 0 _readICCclut($self, @_);
283  
284 # bless object
285 0 bless($self, $class);
286  
287 # return object reference
288 0 return($self);
289  
290 }
291  
292 # writes clut object to ICC profile
293 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
294 sub write_fh {
295  
296 # get object reference
297 0 ▶ my $self = shift();
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
298  
299 # verify 3 parameters
300 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
301  
302 # write clut data to profile
303 0 _writeICCclut($self, @_);
304  
305 }
306  
307 # get tag size (for writing to profile)
308 # returns: (clut_size)
309 sub size {
310  
311 # get parameter
312 0 ▶ my $self = shift();
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
313  
314 # return size
315 0 return(_clut_size($self, 4) + 28);
316  
317 }
318  
319 # get number of input channels
320 # returns: (number)
321 sub cin {
322  
323 # get object reference
324 4 ▶ my $self = shift();
Subroutine cin: called CC=1 SCAR=0.0
Pod undocumented
325  
326 # return
327 4 return(scalar(@{$self->[2]}));
328  
329 }
330  
331 # get number of output channels
332 # returns: (number)
333 sub cout {
334  
335 # get object reference
336 4 ▶ my $self = shift();
Subroutine cout: called CC=1 SCAR=0.0
Pod undocumented
337  
338 # return
339 4 return(scalar(@{$self->[1][0]}));
340  
341 }
342  
343 # build clut array from user-defined transform function
344 # parameters may be set with an optional hash
345 # keys are: ('clut_bytes', 'gsa', 'udf', 'slice')
346 # parameters: ([ref_to_attribute_hash])
347 # returns: (ref_to_object)
348 sub build {
349  
350 # get parameters
351 0 ▶ my ($self, $hash) = @_;
Subroutine build: not called CC=30 SCAR=68.4
Pod undocumented
352  
353 # local variables
354 0 my ($gsa, $ci, $co, @out);
355 0 my ($size, @slice);
356  
357 # for each attribute
358 0 for my $attr (keys(%{$hash})) {
359
360 # if 'clut_bytes'
361 0 ▶ if ($attr eq 'clut_bytes') {
Branch: 4 branches
BranchTrueFalseTotal
if ($attr eq 'clut_bytes') { } 0 0 0
elsif ($attr eq 'gsa') { } 0 0 0
elsif ($attr eq 'udf') { } 0 0 0
elsif ($attr eq 'slice') { } 0 0 0
362
363 # if a scalar, 1 or 2
364 0 ▶ if (! ref($hash->{$attr}) && ($hash->{$attr} == 1 || $hash->{$attr} == 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $hash->{$attr} and $hash->{$attr} == 1 || $hash->{$attr} == 2) { } 0 0 0
Condition0%0/6
not ref $hash->{$attr} and $hash->{$attr} == 1 || $hash->{$attr} == 2
!ll&&!rl&&r
000
$hash->{$attr} == 1 or $hash->{$attr} == 2
l!l&&r!l&&!r
000
MC/DC0%0/3
not ref $hash->{$attr} and $hash->{$attr} == 1 || $hash->{$attr} == 2
not ref $hash->{$attr} $hash->{$attr} == 1 $hash->{$attr} == 2
Truth table0%0/4
not(A) and B or C
A= not ref $hash->{$attr}B= $hash->{$attr} == 1C= $hash->{$attr} == 2
ABCresult
0XX0
1000
11X1
1011
365
366 # add to header hash
367 0 $self->[0]{'clut_bytes'} = $hash->{$attr};
368
369 } else {
370
371 # wrong data type
372 0 croak('clut \'clut_bytes\' attribute must be a scalar, 1 or 2');
373
374 }
375
376 # if 'gsa'
377 } elsif ($attr eq 'gsa') {
378
379 # if reference to an array of scalars
380 0 ▶ if (ref($hash->{$attr}) eq 'ARRAY' && @{$hash->{$attr}} == grep {! ref()} @{$hash->{$attr}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{$attr} eq 'ARRAY' and @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})) { } 0 0 0
Condition0%0/3
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
ref $hash->{$attr} eq "ARRAY" @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
Truth table0%0/3
A and B
A= ref $hash->{$attr} eq "ARRAY"B= @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
ABresult
0X0
100
111
381
382 # set object element
383 0 $self->[2] = [@{$hash->{$attr}}];
384
385 } else {
386
387 # wrong data type
388 0 croak('clut \'gsa\' attribute must be an array reference');
389
390 }
391
392 # if 'udf'
393 } elsif ($attr eq 'udf') {
394
395 # if reference to an array of CODE references
396 0 ▶ if (ref($hash->{$attr}) eq 'ARRAY' && @{$hash->{$attr}} == grep {ref() eq 'CODE'} @{$hash->{$attr}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{$attr} eq 'ARRAY' and @{$hash->{$attr};} == grep({ref $_ eq 'CODE';} @{$$hash{$attr};})) { } 0 0 0
Condition0%0/3
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({ref $_ eq "CODE";} @{$$hash{$attr};})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({ref $_ eq "CODE";} @{$$hash{$attr};})
ref $hash->{$attr} eq "ARRAY" @{$hash->{$attr};} == grep({ref $_ eq "CODE";} @{$$hash{$attr};})
Truth table0%0/3
A and B
A= ref $hash->{$attr} eq "ARRAY"B= @{$hash->{$attr};} == grep({ref $_ eq "CODE";} @{$$hash{$attr};})
ABresult
0X0
100
111
397
398 # set object element
399 0 $self->[3] = [@{$hash->{$attr}}];
400
401 } else {
402
403 # wrong data type
404 0 croak('clut \'udf\' attribute must be an array reference');
405
406 }
407
408 # if 'slice'
409 } elsif ($attr eq 'slice') {
410
411 # if reference to an array of scalars
412 0 ▶ if (ref($hash->{$attr}) eq 'ARRAY' && @{$hash->{$attr}} == grep {! ref()} @{$hash->{$attr}}) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $hash->{$attr} eq 'ARRAY' and @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})) { } 0 0 0
elsif ($hash->{$attr} eq 'log') { } 0 0 0
Condition0%0/3
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
ref $hash->{$attr} eq "ARRAY" @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
Truth table0%0/3
A and B
A= ref $hash->{$attr} eq "ARRAY"B= @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
ABresult
0X0
100
111
413
414 # set slice array
415 0 @slice = @{$hash->{$attr}};
416
417 # if 'log'
418 } elsif ($hash->{$attr} eq 'log') {
419
420 # if 'log' hash is defined
421 0 ▶ if (defined($self->[0]{'log'}) && ref($self->[0]{'log'}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{"log"} and ref $self->[0]{"log"} eq "HASH") 0 0 0
Condition0%0/3
defined $self->[0]{"log"} and ref $self->[0]{"log"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[0]{"log"} and ref $self->[0]{"log"} eq "HASH"
defined $self->[0]{"log"} ref $self->[0]{"log"} eq "HASH"
Truth table0%0/3
A and B
A= defined $self->[0]{"log"}B= ref $self->[0]{"log"} eq "HASH"
ABresult
0X0
100
111
422
423 # set slice to hash keys
424 0 @slice = keys(%{$self->[0]{'log'}});
425
426 }
427
428 } else {
429
430 # wrong data type
431 0 croak('clut \'slice\' attribute must be an array reference or \'log\'');
432
433 }
434
435 } else {
436
437 # invalid attribute
438 0 croak('invalid clut attribute');
439
440 }
441
442 }
443  
444 # get grid size array
445 0 $gsa = $self->[2];
446  
447 # get number of input channels
448 0 $self->[0]{'input_channels'} = $ci = @{$gsa};
449  
450 # validate user-defined function
451 0 ▶ (ref($self->[3][0]) eq 'CODE') || croak('invalid user-defined function');
Branch: 1 branch
BranchTrueFalseTotal
ref $self->[3][0] eq "CODE" or croak("invalid user-defined function") 0 0 0
452  
453 # test user-defined function
454 0 @out = &{$self->[3][0]}((0) x $ci);
455  
456 # determine number of output channels
457 0 $self->[0]{'output_channels'} = $co = @out;
458  
459 # validate parameters
460 0 ▶ (@{$gsa} == grep {! ref() && $_ == int($_)} @{$gsa}) || croak('grid size not an integer');
Branch: 2 branches
BranchTrueFalseTotal
@{$gsa;} == grep({not ref $_ and $_ == int $_;} @{$gsa;}) or croak("grid size not an integer") 0 0 0
not ref $_ and $_ == int $_ 0 0 0
461 0 ▶ (0 == grep {$_ < 2} @{$gsa}) || croak('grid size less than 2');
Branch: 1 branch
BranchTrueFalseTotal
0 == grep({$_ < 2;} @{$gsa;}) or croak("grid size less than 2") 0 0 0
462 0 ▶ ($ci > 0 && $ci < 16) || croak('invalid number of input channels');
Branch: 1 branch
BranchTrueFalseTotal
$ci > 0 and $ci < 16 or croak("invalid number of input channels") 0 0 0
Condition0%0/3
$ci > 0 and $ci < 16
!ll&&!rl&&r
000
MC/DC0%0/2
$ci > 0 and $ci < 16
$ci > 0 $ci < 16
Truth table0%0/3
A and B
A= $ci > 0B= $ci < 16
ABresult
0X0
100
111
463 0 ▶ ($co > 0 && $co < 16) || croak('invalid number of output channels');
Branch: 1 branch
BranchTrueFalseTotal
$co > 0 and $co < 16 or croak("invalid number of output channels") 0 0 0
Condition0%0/3
$co > 0 and $co < 16
!ll&&!rl&&r
000
MC/DC0%0/2
$co > 0 and $co < 16
$co > 0 $co < 16
Truth table0%0/3
A and B
A= $co > 0B= $co < 16
ABresult
0X0
100
111
464  
465 # initialize clut entries
466 0 $size = 1;
467  
468 # for each input channel
469 0 for (@{$gsa}) {
470
471 # multiply by grid size
472 0 $size *= $_;
473
474 }
475  
476 # set slice to entire clut, if empty
477 0 ▶ @slice = (0 .. $size - 1) if (! @slice);
Branch: 1 branch
BranchTrueFalseTotal
unless @slice 0 0 0
478  
479 # for each clut entry
480 0 for my $i (@slice) {
481
482 # compute transform value
483 0 $self->[1][$i] = [&{$self->[3][0]}(_lin2ix($gsa, $i))];
484
485 }
486
487 # update caches
488 0 ▶ $self->[4] = ICC::Support::Lapack::cache_2D($self->[1]) if (defined($INC{'ICC/Support/Lapack.pm'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $INC{"ICC/Support/Lapack.pm"} 0 0 0
489 0 undef($self->[5]);
490  
491 # return object reference
492 0 return($self);
493  
494 }
495  
496 # transform data
497 # input range is (0 - 1)
498 # hash key 'ubox' enables unit box extrapolation
499 # supported input types:
500 # parameters: (list, [hash])
501 # parameters: (vector, [hash])
502 # parameters: (matrix, [hash])
503 # parameters: (Math::Matrix_object, [hash])
504 # parameters: (structure, [hash])
505 # returns: (same_type_as_input)
506 sub transform {
507  
508 # set hash value (0 or 1)
509 0 ▶ my $h = ref($_[-1]) eq 'HASH' ? 1 : 0;
Subroutine transform: not called CC=12 SCAR=50.5
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
ref $_[-1] eq 'HASH' ? : 0 0 0
510  
511 # if input a 'Math::Matrix' object
512 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
513
514 # call matrix transform
515 0 &_trans2;
516
517 # if input an array reference
518 ▶ } 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
519
520 # if array contains numbers (vector)
521 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
522
523 # call vector transform
524 0 &_trans1;
525
526 # if array contains vectors (2-D array)
527 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
528
529 # call matrix transform
530 0 &_trans2;
531
532 } else {
533
534 # call structure transform
535 0 &_trans3;
536
537 }
538
539 # if input a list (of numbers)
540 0 } elsif (@_ == $h + 1 + grep {Scalar::Util::looks_like_number($_)} @_) {
541
542 # call list transform
543 0 &_trans0;
544
545 } else {
546
547 # error
548 0 croak('invalid transform input');
549
550 }
551  
552 }
553  
554 # inverse transform
555 # note: number of undefined output values must equal number of defined input values
556 # note: the input and output vectors contain the final solution on return
557 # hash key 'init' specifies initial value vector
558 # hash key 'ubox' enables unit box extrapolation
559 # parameters: (input_vector, output_vector, [hash])
560 # returns: (RMS_error_value)
561 sub inverse {
562  
563 # get parameters
564 0 ▶ my ($self, $in, $out, $hash) = @_;
Subroutine inverse: not called CC=15 SCAR=54.8
Pod undocumented
565  
566 # local variables
567 0 my ($i, $j, @si, @so, $init);
568 0 my ($int, $jac, $mat, $delta);
569 0 my ($max, $elim, $dlim, $accum, $error);
570  
571 # initialize indices
572 0 $i = $j = -1;
573  
574 # build slice arrays while validating input and output arrays
575 0 ▶ ((grep {$i++; defined() && push(@si, $i)} @{$in}) == (grep {$j++; ! defined() && push(@so, $j)} @{$out})) || croak('wrong number of undefined values');
Branch: 3 branches
BranchTrueFalseTotal
grep({++$i; defined $_ and push @si, $i;} @{$in;}) == grep({++$j; not defined $_ and push @so, $j;} @{$out;}) or croak("wrong number of undefined values") 0 0 0
defined $_ and push @si, $i 0 0 0
not defined $_ and push @so, $j 0 0 0
576  
577 # get init array
578 0 $init = $hash->{'init'};
579  
580 # for each undefined output value
581 0 for my $i (@so) {
582
583 # set to supplied initial value or 0.5
584 0 ▶ $out->[$i] = defined($init->[$i]) ? $init->[$i] : 0.5;
Branch: 1 branch
BranchTrueFalseTotal
defined $init->[$i] ? : 0 0 0
585
586 }
587  
588 # set maximum loop count
589 0 ▶ $max = $hash->{'inv_max'} || 10;
Condition0%0/2
$hash->{'inv_max'} || 10
l!l
00
MC/DC0%0/1
$hash->{'inv_max'} || 10
$hash->{'inv_max'}
Truth table0%0/2
A
A= $hash->{'inv_max'}
Aresult
11
00
590  
591 # loop error limit
592 0 ▶ $elim = $hash->{'inv_elim'} || 1E-6;
Condition0%0/2
$hash->{'inv_elim'} || 1e-06
l!l
00
MC/DC0%0/1
$hash->{'inv_elim'} || 1e-06
$hash->{'inv_elim'}
Truth table0%0/2
A
A= $hash->{'inv_elim'}
Aresult
11
00
593  
594 # set delta limit
595 0 ▶ $dlim = $hash->{'inv_dlim'} || 0.5;
Condition0%0/2
$hash->{'inv_dlim'} || 0.5
l!l
00
MC/DC0%0/1
$hash->{'inv_dlim'} || 0.5
$hash->{'inv_dlim'}
Truth table0%0/2
A
A= $hash->{'inv_dlim'}
Aresult
11
00
596  
597 # create empty solution matrix
598 0 $mat = Math::Matrix->new([]);
599  
600 # compute initial transform values
601 0 ($jac, $int) = jacobian($self, $out, $hash);
602  
603 # solution loop
604 0 for (1 .. $max) {
605
606 # for each input
607 0 for my $i (0 .. $#si) {
608
609 # for each output
610 0 for my $j (0 .. $#so) {
611
612 # copy Jacobian value to solution matrix
613 0 $mat->[$i][$j] = $jac->[$si[$i]][$so[$j]];
614
615 }
616
617 # save residual value to solution matrix
618 0 $mat->[$i][$#si + 1] = $in->[$si[$i]] - $int->[$si[$i]];
619
620 }
621
622 # solve for delta values
623 0 $delta = $mat->solve;
624
625 # for each output value
626 0 for my $i (0 .. $#so) {
627
628 # add delta (limited using hyperbolic tangent)
629 0 $out->[$so[$i]] += POSIX::tanh($delta->[$i][0]/$dlim) * $dlim;
630
631 }
632
633 # compute updated transform values
634 0 ($jac, $int) = jacobian($self, $out, $hash);
635
636 # initialize error accumulator
637 0 $accum = 0;
638
639 # for each input
640 0 for my $i (0 .. $#si) {
641
642 # accumulate delta squared
643 0 $accum += ($in->[$si[$i]] - $int->[$si[$i]])**2;
644
645 }
646
647 # compute RMS error
648 0 $error = sqrt($accum/@si);
649
650 # if error less than limit
651 0 ▶ last if ($error < $elim);
Branch: 1 branch
BranchTrueFalseTotal
if $error < $elim 0 0 0
652
653 }
654  
655 # update input vector with final values
656 0 @{$in} = @{$int};
657  
658 # return
659 0 return($error);
660  
661 }
662  
663 # compute Jacobian matrix
664 # nominal input range is (0 - 1)
665 # hash key 'ubox' enables unit box extrapolation
666 # clipped outputs are extrapolated using Jacobian
667 # parameters: (input_vector, [hash])
668 # returns: (Jacobian_matrix, [output_vector])
669 sub jacobian {
670  
671 # get parameters
672 0 ▶ my ($self, $in, $hash) = @_;
Subroutine jacobian: not called CC=16 SCAR=56.1
Pod undocumented
673  
674 # local variables
675 0 my ($ext, $out, $jac, $rel, $cp, $jac_bc, $sf);
676  
677 # check if ICC::Support::Lapack module is loaded
678 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
679  
680 # if user-defined transform and user-defined Jacobian functions
681 0 ▶ if (defined($self->[3][0]) && defined($self->[3][1])) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->[3][0] and defined $self->[3][1]) { } 0 0 0
elsif (defined $self->[3][0] ^ defined $self->[3][1]) { } 0 0 0
Condition0%0/3
defined $self->[3][0] and defined $self->[3][1]
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[3][0] and defined $self->[3][1]
defined $self->[3][0] defined $self->[3][1]
Truth table0%0/3
A and B
A= defined $self->[3][0]B= defined $self->[3][1]
ABresult
0X0
100
111
682
683 # if output values wanted
684 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
685
686 # return Jacobian and output values
687 0 return(&{$self->[3][1]}(@{$in}), [&{$self->[3][0]}(@{$in})]);
688
689 } else {
690
691 # return Jacobian only
692 0 return(&{$self->[3][1]}(@{$in}));
693
694 }
695
696 # if user-defined transform xor user-defined Jacobian functions
697 } elsif (defined($self->[3][0]) ^ defined($self->[3][1])) {
698
699 # die with message
700 0 croak('transform and Jacobian must both be user-defined functions, or not');
701
702 }
703  
704 # if unit box extrapolation
705 0 ▶ if ($hash->{'ubox'} && grep {$_ < 0.0 || $_ > 1.0} @{$in}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$in;}) 0 0 0
$_ < 0 or $_ > 1 0 0 0
Condition0%0/3
$hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$in;}
!ll&&!rl&&r
000
MC/DC0%0/2
$hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$in;}
$hash->{"ubox"} grep {$_ < 0 or $_ > 1;} @{$in;}
Truth table0%0/3
A and B
A= $hash->{"ubox"}B= grep {$_ < 0 or $_ > 1;} @{$in;}
ABresult
0X0
100
111
706
707 # compute intersection with unit box
708 0 ($ext, $in) = _intersect($in);
709
710 }
711  
712 # if ICC::Support::Lapack module is loaded
713 0 ▶ if ($lapack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lapack) { } 0 0 0
714
715 # if extrapolating
716 0 ▶ if (defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ext) { } 0 0 0
717
718 # compute Jacobian matrix using Lapack module
719 0 $jac = ICC::Support::Lapack::clut_jacobian_ext($self->[2], $in, $self->[4]);
720
721 } else {
722
723 # compute Jacobian matrix using Lapack module
724 0 $jac = ICC::Support::Lapack::clut_jacobian($self->[2], $in, $self->[4]);
725
726 }
727
728 # bless Jacobian as Math::Matrix object
729 0 bless($jac, 'Math::Matrix');
730
731 } else {
732
733 # if extrapolating
734 0 ▶ if (defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ext) { } 0 0 0
735
736 # compute outer corner points
737 0 $cp = _locate_ext($self);
738
739 # compute the barycentric jacobian
740 0 $jac_bc = _barycentric_jacobian($in);
741
742 # compute Jacobian matrix
743 0 $jac = bless($cp, 'Math::Matrix') * $jac_bc;
744
745 } else {
746
747 # compute relative input vector and corner points
748 0 ($rel, $cp) = _locate($self, $in);
749
750 # compute the barycentric jacobian
751 0 $jac_bc = _barycentric_jacobian($rel);
752
753 # compute Jacobian matrix
754 0 $jac = bless($cp, 'Math::Matrix') * $jac_bc;
755
756 # for each input channel
757 0 for my $i (0 .. $#{$jac->[0]}) {
758
759 # compute scale factor for grid size
760 0 $sf = $self->[2][$i] - 1;
761
762 # for each output channel
763 0 for my $j (0 .. $#{$jac}) {
764
765 # scale matrix element
766 0 $jac->[$j][$i] *= $sf;
767
768 }
769
770 }
771
772 }
773
774 }
775  
776 # if output values wanted
777 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
778
779 # compute output values
780 0 $out = _trans1($self, $in);
781
782 # if extrapolating
783 0 ▶ if (defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ext) 0 0 0
784
785 # for each output
786 0 for my $i (0 .. $#{$self->[1][0]}) {
787
788 # add delta value
789 0 $out->[$i] += ICC::Shared::dotProduct($jac->[$i], $ext);
790
791 }
792
793 }
794
795 # return Jacobian and output vector
796 0 return($jac, $out);
797
798 } else {
799
800 # return Jacobian only
801 0 return($jac);
802
803 }
804
805 }
806  
807 # print object contents to string
808 # format is an array structure
809 # parameter: ([format])
810 # returns: (string)
811 sub sdump {
812  
813 # get parameters
814 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
815  
816 # local variables
817 0 my ($s, $fmt);
818  
819 # resolve parameter to an array reference
820 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
821  
822 # get format string
823 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
824  
825 # set string to object ID
826 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
827  
828 # return
829 0 return($s);
830  
831 }
832  
833 # transform list
834 # parameters: (object_reference, list, [hash])
835 # returns: (list)
836 sub _trans0 {
837  
838 # local variables
839 0 ▶ my ($self, $hash, @out);
Subroutine _trans0: not called CC=2 SCAR=17.9
840  
841 # get object reference
842 0 $self = shift();
843  
844 # get optional hash
845 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
846  
847 # compute output using '_trans1'
848 0 @out = @{_trans1($self, \@_, $hash)};
849  
850 # return
851 0 return(@out);
852  
853 }
854  
855 # transform vector
856 # parameters: (object_reference, vector, [hash])
857 # returns: (vector)
858 sub _trans1 {
859  
860 # get parameters
861 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans1: not called CC=11 SCAR=48.8
862  
863 # local variables
864 0 my ($ext, $out, $rel, $cp, $coef, $jac_bc, $jac);
865  
866 # check if ICC::Support::Lapack module is loaded
867 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
868  
869 # if user-defined transform function
870 0 ▶ if (defined($self->[3][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[3][0]) 0 0 0
871
872 # call it and return
873 0 return([&{$self->[3][0]}(@{$in})]);
874
875 }
876  
877 # if unit box extrapolation
878 0 ▶ if ($hash->{'ubox'} && grep {$_ < 0.0 || $_ > 1.0} @{$in}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$in;}) 0 0 0
$_ < 0 or $_ > 1 0 0 0
Condition0%0/3
$hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$in;}
!ll&&!rl&&r
000
MC/DC0%0/2
$hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$in;}
$hash->{"ubox"} grep {$_ < 0 or $_ > 1;} @{$in;}
Truth table0%0/3
A and B
A= $hash->{"ubox"}B= grep {$_ < 0 or $_ > 1;} @{$in;}
ABresult
0X0
100
111
879
880 # compute intersection with unit box
881 0 ($ext, $in) = _intersect($in);
882
883 }
884
885 # if ICC::Support::Lapack module is loaded
886 0 ▶ if ($lapack) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lapack) { } 0 0 0
887
888 # compute output using Lapack module
889 0 $out = ICC::Support::Lapack::clut_vec_trans($self->[2], $in, $self->[4]);
890
891 # if extrapolating
892 0 ▶ if (defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ext) 0 0 0
893
894 # compute Jacobian matrix using Lapack module
895 0 $jac = ICC::Support::Lapack::clut_jacobian_ext($self->[2], $in, $self->[4]);
896
897 # for each output
898 0 for my $i (0 .. $#{$self->[1][0]}) {
899
900 # add delta value
901 0 $out->[$i] += ICC::Shared::dotProduct($jac->[$i], $ext);
902
903 }
904
905 }
906
907
908 } else {
909
910 # compute relative input vector and corner points
911 0 ($rel, $cp) = _locate($self, $in);
912
913 # compute barycentric coefficients
914 0 $coef = _barycentric($rel);
915
916 # for each output value
917 0 for my $i (0 .. $#{$self->[1][0]}) {
918
919 # compute output value
920 0 $out->[$i] = ICC::Shared::dotProduct($cp->[$i], $coef);
921
922 }
923
924 # if extrapolating
925 0 ▶ if (defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ext) 0 0 0
926
927 # compute outer corner points
928 0 $cp = _locate_ext($self);
929
930 # compute the barycentric Jacobian
931 0 $jac_bc = _barycentric_jacobian($in);
932
933 # compute Jacobian matrix
934 0 $jac = bless($cp, 'Math::Matrix') * $jac_bc;
935
936 # for each output
937 0 for my $i (0 .. $#{$self->[1][0]}) {
938
939 # add delta value
940 0 $out->[$i] += ICC::Shared::dotProduct($jac->[$i], $ext);
941
942 }
943
944 }
945
946 }
947  
948 # return
949 0 return($out);
950  
951 }
952  
953 # transform matrix (2-D array -or- Math::Matrix object)
954 # parameters: (object_reference, matrix, [hash])
955 # returns: (matrix)
956 sub _trans2 {
957  
958 # get parameters
959 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans2: not called CC=18 SCAR=58.3
960  
961 # local variables
962 0 my ($out, $ext, $ink, $rel, $cp, $coef, $jac_bc, $jac);
963  
964 # check if ICC::Support::Lapack module is loaded
965 0 state $lapack = defined($INC{'ICC/Support/Lapack.pm'});
966  
967 # if user-defined transform function
968 0 ▶ if (defined($self->[3][0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->[3][0]) { } 0 0 0
elsif ($lapack) { } 0 0 0
969
970 # for each input vector
971 0 for my $i (0 .. $#{$in}) {
972
973 # call udf to compute transformed value
974 0 $out->[$i] = [&{$self->[3][0]}(@{$in->[$i]})];
975
976 }
977
978 # if ICC::Support::Lapack module is loaded
979 } elsif ($lapack) {
980
981 # for each input vector
982 0 for my $i (0 .. $#{$in}) {
983
984 # if unit box extrapolation
985 0 ▶ if ($hash->{'ubox'} && grep {$_ < 0.0 || $_ > 1.0} @{$in->[$i]}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hash->{'ubox'} and grep {$_ < 0.0 or $_ > 1.0;} @{$$in[$i];}) { } 0 0 0
$_ < 0 or $_ > 1 0 0 0
Condition0%0/3
$hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$$in[$i];}
!ll&&!rl&&r
000
MC/DC0%0/2
$hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$$in[$i];}
$hash->{"ubox"} grep {$_ < 0 or $_ > 1;} @{$$in[$i];}
Truth table0%0/3
A and B
A= $hash->{"ubox"}B= grep {$_ < 0 or $_ > 1;} @{$$in[$i];}
ABresult
0X0
100
111
986
987 # compute intersection with unit box
988 0 ($ext, $ink) = _intersect($in->[$i]);
989
990 } else {
991
992 # no extrapolation, copy input
993 0 ($ext, $ink) = (undef, $in->[$i]);
994
995 }
996
997 # compute output using Lapack module
998 0 $out->[$i] = ICC::Support::Lapack::clut_vec_trans($self->[2], $ink, $self->[4]);
999
1000 # if extrapolating
1001 0 ▶ if (defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ext) 0 0 0
1002
1003 # compute Jacobian matrix using Lapack module
1004 0 $jac = ICC::Support::Lapack::clut_jacobian_ext($self->[2], $ink, $self->[4]);
1005
1006 # for each output value
1007 0 for my $j (0 .. $#{$self->[1][0]}) {
1008
1009 # add delta value
1010 0 $out->[$i][$j] += ICC::Shared::dotProduct($jac->[$j], $ext);
1011
1012 }
1013
1014 }
1015
1016 }
1017
1018 } else {
1019
1020 # for each input vector
1021 0 for my $i (0 .. $#{$in}) {
1022
1023 # if unit box extrapolation
1024 0 ▶ if ($hash->{'ubox'} && grep {$_ < 0.0 || $_ > 1.0} @{$in->[$i]}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($hash->{'ubox'} and grep {$_ < 0.0 or $_ > 1.0;} @{$$in[$i];}) { } 0 0 0
$_ < 0 or $_ > 1 0 0 0
Condition0%0/3
$hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$$in[$i];}
!ll&&!rl&&r
000
MC/DC0%0/2
$hash->{"ubox"} and grep {$_ < 0 or $_ > 1;} @{$$in[$i];}
$hash->{"ubox"} grep {$_ < 0 or $_ > 1;} @{$$in[$i];}
Truth table0%0/3
A and B
A= $hash->{"ubox"}B= grep {$_ < 0 or $_ > 1;} @{$$in[$i];}
ABresult
0X0
100
111
1025
1026 # compute intersection with unit box
1027 0 ($ext, $ink) = _intersect($in->[$i]);
1028
1029 } else {
1030
1031 # no extrapolation, copy input
1032 0 ($ext, $ink) = (undef, $in->[$i]);
1033
1034 }
1035
1036 # compute relative input vector and corner points
1037 0 ($rel, $cp) = _locate($self, $ink);
1038
1039 # compute barycentric coefficients
1040 0 $coef = _barycentric($rel);
1041
1042 # for each output value
1043 0 for my $j (0 .. $#{$self->[1][0]}) {
1044
1045 # compute output value
1046 0 $out->[$i][$j] = ICC::Shared::dotProduct($cp->[$j], $coef);
1047
1048 }
1049
1050 # if extrapolating
1051 0 ▶ if (defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ext) 0 0 0
1052
1053 # compute outer corner points
1054 0 $cp = _locate_ext($self);
1055
1056 # compute the barycentric Jacobian
1057 0 $jac_bc = _barycentric_jacobian($ink);
1058
1059 # compute Jacobian matrix
1060 0 $jac = bless($cp, 'Math::Matrix') * $jac_bc;
1061
1062 # for each output value
1063 0 for my $j (0 .. $#{$self->[1][0]}) {
1064
1065 # add delta value
1066 0 $out->[$i][$j] += ICC::Shared::dotProduct($jac->[$j], $ext);
1067
1068 }
1069
1070 }
1071
1072 }
1073
1074 }
1075  
1076 # return
1077 0 ▶ return(UNIVERSAL::isa($in, 'Math::Matrix') ? bless($out, 'Math::Matrix') : $out);
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($in, 'Math::Matrix') ? : 0 0 0
1078  
1079 }
1080  
1081 # transform structure
1082 # parameters: (object_reference, structure, [hash])
1083 # returns: (structure)
1084 sub _trans3 {
1085  
1086 # get parameters
1087 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans3: not called CC=1 SCAR=6.9
1088  
1089 # transform the array structure
1090 0 _crawl($self, $in, my $out = [], $hash);
1091  
1092 # return
1093 0 return($out);
1094  
1095 }
1096  
1097 # recursive transform
1098 # array structure is traversed until scalar arrays are found and transformed
1099 # parameters: (ref_to_object, input_array_reference, output_array_reference, hash)
1100 sub _crawl {
1101  
1102 # get parameters
1103 0 ▶ my ($self, $in, $out, $hash) = @_;
Subroutine _crawl: not called CC=4 SCAR=30.0
1104  
1105 # if input is a vector (reference to a scalar array)
1106 0 ▶ if (@{$in} == grep {! ref()} @{$in}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$in;} == grep({not ref $_;} @{$in;})) { } 0 0 0
1107
1108 # transform input vector and copy to output
1109 0 @{$out} = @{_trans1($self, $in, $hash)};
1110
1111 } else {
1112
1113 # for each input element
1114 0 for my $i (0 .. $#{$in}) {
1115
1116 # if an array reference
1117 0 ▶ if (ref($in->[$i]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in->[$i] eq 'ARRAY') { } 0 0 0
1118
1119 # transform next level
1120 0 _crawl($self, $in->[$i], $out->[$i] = [], $hash);
1121
1122 } else {
1123
1124 # error
1125 0 croak('invalid transform input');
1126
1127 }
1128
1129 }
1130
1131 }
1132
1133 }
1134  
1135 # compute relative input vector and corner points
1136 # parameter: (object_ref, input_vector)
1137 # returns: (relative_input_vector, corner_point_array)
1138 sub _locate {
1139  
1140 # get parameter
1141 0 ▶ my ($self, $in) = @_;
Subroutine _locate: not called CC=9 SCAR=45.0
1142  
1143 # local variables
1144 0 my (@rel, @ox, $ux, $key, @ix, $gp, $cp);
1145  
1146 # for each input value
1147 0 for my $i (0 .. $#{$in}) {
1148
1149 # split clut span into fractional and integer parts
1150 0 ($rel[$i], $ox[$i]) = POSIX::modf($in->[$i] * ($self->[2][$i] - 1));
1151
1152 # compute upper grid index
1153 0 $ux = $self->[2][$i] - 2;
1154
1155 # if grid index < 0
1156 0 ▶ if ($ox[$i] < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ox[$i] < 0) { } 0 0 0
elsif ($ox[$i] > $ux) { } 0 0 0
1157
1158 # adjust
1159 0 $rel[$i] += $ox[$i];
1160 0 $ox[$i] = 0;
1161
1162 # if grid index > upper index
1163 } elsif ($ox[$i] > $ux) {
1164
1165 #adjust
1166 0 $rel[$i] += $ox[$i] - $ux;
1167 0 $ox[$i] = $ux;
1168
1169 }
1170
1171 }
1172  
1173 # compute hash key
1174 0 $key = join(':', @ox);
1175
1176 # if corner points are not cached
1177 0 ▶ if (! ($cp = $self->[5]{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cp = $self->[5]{$key}) 0 0 0
1178
1179 # for each corner point
1180 0 for my $i (0 .. 2**@{$in} - 1) {
1181
1182 # copy origin
1183 0 @ix = @ox;
1184
1185 # for each input
1186 0 for my $j (0 .. $#{$in}) {
1187
1188 # increment index if bit set
1189 0 ▶ $ix[$j]++ if ($i >> $j & 1);
Branch: 1 branch
BranchTrueFalseTotal
if $i >> $j & 1 0 0 0
1190
1191 }
1192
1193 # get clut grid point array
1194 0 $gp = $self->[1][_ix2lin($self->[2], @ix)];
1195
1196 # for each output
1197 0 for my $j (0 .. $#{$gp}) {
1198
1199 # copy array value
1200 0 $cp->[$j][$i] = $gp->[$j];
1201
1202 }
1203
1204 }
1205
1206 # save in cache
1207 0 $self->[5]{$key} = $cp;
1208
1209 }
1210  
1211 # return
1212 0 return(\@rel, $cp);
1213  
1214 }
1215  
1216 # compute outer corner points
1217 # parameter: (object_ref)
1218 # returns: (corner_point_array)
1219 sub _locate_ext {
1220  
1221 # get parameter
1222 0 ▶ my ($self) = @_;
Subroutine _locate_ext: not called CC=6 SCAR=37.4
1223  
1224 # local variables
1225 0 my ($cp, @ix, $gp);
1226  
1227 # if ext corner points are not cached
1228 0 ▶ if (! ($cp = $self->[5]{'ext'})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cp = $self->[5]{"ext"}) 0 0 0
1229
1230 # for each corner point
1231 0 for my $i (0 .. 2**@{$self->[2]} - 1) {
1232
1233 # for each input
1234 0 for my $j (0 .. $#{$self->[2]}) {
1235
1236 # increment index if bit set
1237 0 ▶ $ix[$j] = ($i >> $j & 1) ? $self->[2][$j] - 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i >> $j & 1 ? : 0 0 0
1238
1239 }
1240
1241 # get clut grid point array
1242 0 $gp = $self->[1][_ix2lin($self->[2], @ix)];
1243
1244 # for each output
1245 0 for my $j (0 .. $#{$gp}) {
1246
1247 # copy array value
1248 0 $cp->[$j][$i] = $gp->[$j];
1249
1250 }
1251
1252 }
1253
1254 # save in cache
1255 0 $self->[5]{'ext'} = $cp;
1256
1257 }
1258  
1259 # return
1260 0 return($cp);
1261  
1262 }
1263  
1264 # compute barycentric coefficients
1265 # parameter: (input_vector)
1266 # returns: (coefficient_array)
1267 sub _barycentric {
1268  
1269 # get parameter
1270 0 ▶ my $in = shift();
Subroutine _barycentric: not called CC=4 SCAR=30.0
1271  
1272 # local variables
1273 0 my ($inc, $coef);
1274  
1275 # compute complement values
1276 0 $inc = [map {1 - $_} @{$in}];
1277  
1278 # initialize coefficient array
1279 0 $coef = [(1.0) x 2**@{$in}];
1280  
1281 # for each coefficient
1282 0 for my $i (0 .. $#{$coef}) {
1283
1284 # for each device value
1285 0 for my $j (0 .. $#{$in}) {
1286
1287 # if $j-th bit set
1288 0 ▶ if ($i >> $j & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >> $j & 1) { } 0 0 0
1289
1290 # multiply by device value
1291 0 $coef->[$i] *= $in->[$j];
1292
1293 } else {
1294
1295 # multiply by (1 - device value)
1296 0 $coef->[$i] *= $inc->[$j];
1297
1298 }
1299
1300 }
1301
1302 }
1303  
1304 # return
1305 0 return($coef);
1306  
1307 }
1308  
1309 # compute barycentric Jacobian matrix
1310 # parameter: (input_vector)
1311 # returns: (Jacobian_matrix)
1312 sub _barycentric_jacobian {
1313  
1314 # get parameter
1315 0 ▶ my $in = shift();
Subroutine _barycentric_jacobian: not called CC=7 SCAR=40.3
1316  
1317 # local variables
1318 0 my ($inc, $rows, $jac);
1319  
1320 # compute complement values
1321 0 $inc = [map {1 - $_} @{$in}];
1322  
1323 # compute matrix rows
1324 0 $rows = 2**@{$in};
1325  
1326 # for each matrix row
1327 0 for my $i (0 .. $rows - 1) {
1328
1329 # initialize row
1330 0 $jac->[$i] = [(1.0) x @{$in}];
1331
1332 # for each matrix column
1333 0 for my $j (0 .. $#{$in}) {
1334
1335 # for each device value
1336 0 for my $k (0 .. $#{$in}) {
1337
1338 # if $k-th bit set
1339 0 ▶ if ($i >> $k & 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >> $k & 1) { } 0 0 0
1340
1341 # multiply by device value -or- 1 (skip)
1342 0 ▶ $jac->[$i][$j] *= $in->[$k] if ($j != $k);
Branch: 1 branch
BranchTrueFalseTotal
if $j != $k 0 0 0
1343
1344 } else {
1345
1346 # multiply by (1 - device value) -or- -1
1347 0 ▶ $jac->[$i][$j] *= ($j != $k) ? $inc->[$k] : -1;
Branch: 1 branch
BranchTrueFalseTotal
$j != $k ? : 0 0 0
1348
1349 }
1350
1351 }
1352
1353 }
1354
1355 }
1356  
1357 # return
1358 0 return(bless($jac, 'Math::Matrix'));
1359  
1360 }
1361  
1362 # find unit box intersection
1363 # with line from input to box-center
1364 # parameters: (input_vector)
1365 # returns: (extrapolation_vector, intersection_vector)
1366 sub _intersect {
1367  
1368 # get input values
1369 0 ▶ my ($in) = shift();
Subroutine _intersect: not called CC=3 SCAR=24.8
1370  
1371 # local variables
1372 0 my (@cin, $dmax, $ubox, $ext);
1373  
1374 # compute input to box-center difference
1375 0 @cin = map {$_ - 0.5} @{$in};
1376  
1377 # initialize
1378 0 $dmax = 0;
1379  
1380 # for each difference
1381 0 for (@cin) {
1382
1383 # if larger absolute value
1384 0 ▶ if (abs($_) > $dmax) {
Branch: 1 branch
BranchTrueFalseTotal
if (abs $_ > $dmax) 0 0 0
1385
1386 # new max difference
1387 0 $dmax = abs($_);
1388
1389 }
1390
1391 }
1392  
1393 # multiply max difference by 2
1394 0 $dmax *= 2;
1395  
1396 # compute intersection vector (on surface of unit box)
1397 0 $ubox = [map {$_/$dmax + 0.5} @cin];
1398  
1399 # compute extrapolation vector (as Math::Matrix object)
1400 0 $ext = [map {$in->[$_] - $ubox->[$_]} (0 .. $#{$in})];
1401  
1402 # return
1403 0 return($ext, $ubox);
1404  
1405 }
1406  
1407 # compute clut linear index from index array
1408 # parameters: (ref_to_grid_size_array, index_array)
1409 # returns: (linear_index)
1410 sub _ix2lin {
1411  
1412 # get parameters
1413 0 ▶ my ($gsa, @ix) = @_;
Subroutine _ix2lin: not called CC=2 SCAR=17.9
1414  
1415 # initialize linear_index
1416 0 my $lx = $ix[0];
1417  
1418 # for each remaining array value
1419 0 for my $i (1 .. $#ix) {
1420
1421 # multiply by grid size
1422 0 $lx *= $gsa->[$i];
1423
1424 # add index value
1425 0 $lx += $ix[$i];
1426
1427 }
1428  
1429 # return linear index
1430 0 return($lx);
1431  
1432 }
1433  
1434 # compute clut index array from linear index
1435 # parameters: (ref_to_grid_size_array, linear_index)
1436 # returns: (index_array)
1437 sub _lin2ix {
1438  
1439 # get parameters
1440 0 ▶ my ($gsa, $lx) = @_;
Subroutine _lin2ix: not called CC=2 SCAR=17.9
1441  
1442 # local variables
1443 0 my ($mod, @ix);
1444  
1445 # for each input channel
1446 0 for my $gs (reverse(@{$gsa})) {
1447
1448 # compute modulus
1449 0 $mod = $lx % $gs;
1450
1451 # adjust linear index
1452 0 $lx = ($lx - $mod)/$gs;
1453
1454 # save input value
1455 0 unshift(@ix, $mod/($gs - 1));
1456
1457 }
1458  
1459 # return index array
1460 0 return(@ix);
1461  
1462 }
1463  
1464 # get clut size
1465 # parameter: (clut_bytes)
1466 # returns: (clut_size)
1467 sub _clut_size {
1468  
1469 # get parameter
1470 14 ▶ my ($self, $bytes) = @_;
Subroutine _clut_size: called CC=2 SCAR=6.9
1471  
1472 # get size of clut entry
1473 14 my $size = $bytes * @{$self->[1][0]};
1474  
1475 # for each grid size value
1476 14 for (@{$self->[2]}) {
1477
1478 # multiply by grid size
1479 45 $size *= $_;
1480
1481 }
1482  
1483 # return size
1484 14 return($size);
1485  
1486 }
1487  
1488 # make new clut object from attribute hash
1489 # hash may contain pointers to clut, clut size, grid size array, and user-defined functions
1490 # hash keys are: ('array', 'clut_bytes', 'gsa', 'udf')
1491 # object elements not specified in the hash are unchanged
1492 # parameters: (ref_to_object, ref_to_attribute_hash)
1493 sub _new_from_hash {
1494  
1495 # get parameters
1496 0 ▶ my ($self, $hash) = @_;
Subroutine _new_from_hash: not called CC=18 SCAR=58.3
1497  
1498 # for each attribute
1499 0 for my $attr (keys(%{$hash})) {
1500
1501 # if 'array'
1502 0 ▶ if ($attr eq 'array') {
Branch: 4 branches
BranchTrueFalseTotal
if ($attr eq 'array') { } 0 0 0
elsif ($attr eq 'clut_bytes') { } 0 0 0
elsif ($attr eq 'gsa') { } 0 0 0
elsif ($attr eq 'udf') { } 0 0 0
1503
1504 # if reference to a 2-D array
1505 0 ▶ if (ref($hash->{$attr}) eq 'ARRAY' && @{$hash->{$attr}} == grep {ref() eq 'ARRAY'} @{$hash->{$attr}}) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $hash->{$attr} eq 'ARRAY' and @{$hash->{$attr};} == grep({ref $_ eq 'ARRAY';} @{$$hash{$attr};})) { } 0 0 0
elsif (UNIVERSAL::isa($hash->{$attr}, 'Math::Matrix')) { } 0 0 0
Condition0%0/3
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({ref $_ eq "ARRAY";} @{$$hash{$attr};})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({ref $_ eq "ARRAY";} @{$$hash{$attr};})
ref $hash->{$attr} eq "ARRAY" @{$hash->{$attr};} == grep({ref $_ eq "ARRAY";} @{$$hash{$attr};})
Truth table0%0/3
A and B
A= ref $hash->{$attr} eq "ARRAY"B= @{$hash->{$attr};} == grep({ref $_ eq "ARRAY";} @{$$hash{$attr};})
ABresult
0X0
100
111
1506
1507 # set clut to clone of array
1508 0 $self->[1] = Storable::dclone($hash->{$attr});
1509
1510 # update caches
1511 0 ▶ $self->[4] = ICC::Support::Lapack::cache_2D($self->[1]) if (defined($INC{'ICC/Support/Lapack.pm'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $INC{"ICC/Support/Lapack.pm"} 0 0 0
1512 0 undef($self->[5]);
1513
1514 # if reference to a Math::Matrix object
1515 } elsif (UNIVERSAL::isa($hash->{$attr}, 'Math::Matrix')) {
1516
1517 # set clut to object
1518 0 $self->[1] = $hash->{$attr};
1519
1520 # update caches
1521 0 ▶ $self->[4] = ICC::Support::Lapack::cache_2D($self->[1]) if (defined($INC{'ICC/Support/Lapack.pm'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $INC{"ICC/Support/Lapack.pm"} 0 0 0
1522 0 undef($self->[5]);
1523
1524 } else {
1525
1526 # wrong data type
1527 0 croak('clut \'array\' attribute must be a 2-D array reference or Math::Matrix object');
1528
1529 }
1530
1531 # if 'clut_bytes'
1532 } elsif ($attr eq 'clut_bytes') {
1533
1534 # if a scalar, 1 or 2
1535 0 ▶ if (! ref($hash->{$attr}) && ($hash->{$attr} == 1 || $hash->{$attr} == 2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $hash->{$attr} and $hash->{$attr} == 1 || $hash->{$attr} == 2) { } 0 0 0
Condition0%0/6
not ref $hash->{$attr} and $hash->{$attr} == 1 || $hash->{$attr} == 2
!ll&&!rl&&r
000
$hash->{$attr} == 1 or $hash->{$attr} == 2
l!l&&r!l&&!r
000
MC/DC0%0/3
not ref $hash->{$attr} and $hash->{$attr} == 1 || $hash->{$attr} == 2
not ref $hash->{$attr} $hash->{$attr} == 1 $hash->{$attr} == 2
Truth table0%0/4
not(A) and B or C
A= not ref $hash->{$attr}B= $hash->{$attr} == 1C= $hash->{$attr} == 2
ABCresult
0XX0
1000
11X1
1011
1536
1537 # add to header hash
1538 0 $self->[0]{'clut_bytes'} = $hash->{$attr};
1539
1540 } else {
1541
1542 # wrong data type
1543 0 croak('clut \'clut_bytes\' attribute must be a scalar, 1 or 2');
1544
1545 }
1546
1547 # if 'gsa'
1548 } elsif ($attr eq 'gsa') {
1549
1550 # if reference to a 1-D array (vector)
1551 0 ▶ if (ref($hash->{$attr}) eq 'ARRAY' && @{$hash->{$attr}} == grep {Scalar::Util::looks_like_number($_)} @{$hash->{$attr}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{$attr} eq 'ARRAY' and @{$hash->{$attr};} == grep({&Scalar::Util::looks_like_number($_);} @{$$hash{$attr};})) { } 0 0 0
Condition0%0/3
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({&Scalar::Util::looks_like_number($_);} @{$$hash{$attr};})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({&Scalar::Util::looks_like_number($_);} @{$$hash{$attr};})
ref $hash->{$attr} eq "ARRAY" @{$hash->{$attr};} == grep({&Scalar::Util::looks_like_number($_);} @{$$hash{$attr};})
Truth table0%0/3
A and B
A= ref $hash->{$attr} eq "ARRAY"B= @{$hash->{$attr};} == grep({&Scalar::Util::looks_like_number($_);} @{$$hash{$attr};})
ABresult
0X0
100
111
1552
1553 # set object element
1554 0 $self->[2] = [@{$hash->{$attr}}];
1555
1556 } else {
1557
1558 # wrong data type
1559 0 croak('clut \'gsa\' attribute must be an array reference');
1560
1561 }
1562
1563 # if 'udf'
1564 } elsif ($attr eq 'udf') {
1565
1566 # if reference to an array of CODE references
1567 0 ▶ if (ref($hash->{$attr}) eq 'ARRAY' && @{$hash->{$attr}} == grep {ref() eq 'CODE'} @{$hash->{$attr}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{$attr} eq 'ARRAY' and @{$hash->{$attr};} == grep({ref $_ eq 'CODE';} @{$$hash{$attr};})) { } 0 0 0
Condition0%0/3
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({ref $_ eq "CODE";} @{$$hash{$attr};})
!ll&&!rl&&r
000
MC/DC0%0/2
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({ref $_ eq "CODE";} @{$$hash{$attr};})
ref $hash->{$attr} eq "ARRAY" @{$hash->{$attr};} == grep({ref $_ eq "CODE";} @{$$hash{$attr};})
Truth table0%0/3
A and B
A= ref $hash->{$attr} eq "ARRAY"B= @{$hash->{$attr};} == grep({ref $_ eq "CODE";} @{$$hash{$attr};})
ABresult
0X0
100
111
1568
1569 # set object element
1570 0 $self->[3] = [@{$hash->{$attr}}];
1571
1572 } else {
1573
1574 # wrong data type
1575 0 croak('clut \'udf\' attribute must be an array reference');
1576
1577 }
1578
1579 } else {
1580
1581 # invalid attribute
1582 0 croak('invalid clut attribute');
1583
1584 }
1585
1586 }
1587
1588 }
1589  
1590 # read clut data
1591 # note: assumes file handle is positioned at start of clut data
1592 # header information must be read separately by the calling function
1593 # precision is number of bytes per clut element, 1 (8-bit), 2 (16-bit) or 4 (floating point)
1594 # parameters: (ref_to_object, file_handle, output_channels, ref_to_grid_size_array, precision)
1595 sub _read_clut {
1596  
1597 # get parameters
1598 4 ▶ my ($self, $fh, $co, $gsa, $bytes) = @_;
Subroutine _read_clut: called CC=9 SCAR=23.7
1599  
1600 # local variables
1601 4 my ($rbs, $size, $buf);
1602  
1603 # set read block size
1604 4 $rbs = $bytes * $co;
1605  
1606 # initialize clut entries
1607 4 $size = 1;
1608  
1609 # for each input channel
1610 4 for (@{$gsa}) {
1611
1612 # multiply by grid size
1613 13 $size *= $_;
1614
1615 }
1616
1617 # if 8-bit table
1618 4 ▶ if ($bytes == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bytes == 1) { } 1 3 4
elsif ($bytes == 2) { } 3 0 3
elsif ($bytes == 4) { } 0 0 0
1619
1620 # for each clut entry
1621 1 for my $i (0 .. $size - 1) {
1622
1623 # read into buffer
1624 35937 read($fh, $buf, $rbs);
1625
1626 # unpack buffer and save
1627 35937 $self->[1][$i] = [map {$_/255} unpack('C*', $buf)];
1628
1629 }
1630
1631 # if 16-bit table
1632 } elsif ($bytes == 2) {
1633
1634 # for each clut entry
1635 3 for my $i (0 .. $size - 1) {
1636
1637 # read into buffer
1638 93347 read($fh, $buf, $rbs);
1639
1640 # unpack buffer and save
1641 93347 $self->[1][$i] = [map {$_/65535} unpack('n*', $buf)];
1642
1643 }
1644
1645 # if floating point table
1646 } elsif ($bytes == 4) {
1647
1648 # for each clut entry
1649 0 for my $i (0 .. $size - 1) {
1650
1651 # read into buffer
1652 0 read($fh, $buf, $rbs);
1653
1654 # unpack buffer and save
1655 0 $self->[1][$i] = [unpack('f>*', $buf)];
1656
1657 }
1658
1659 } else {
1660
1661 # error
1662 0 croak('unsupported data size, must be 1, 2 or 4 bytes');
1663
1664 }
1665  
1666 # cache clut for Lapack functions, if defined
1667 4 ▶ $self->[4] = ICC::Support::Lapack::cache_2D($self->[1]) if (defined($INC{'ICC/Support/Lapack.pm'}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $INC{"ICC/Support/Lapack.pm"} 0 4 4
1668  
1669 }
1670  
1671 # read clut tag from ICC profile
1672 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
1673 sub _readICCclut {
1674  
1675 # get parameters
1676 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCclut: not called CC=1 SCAR=6.9
1677  
1678 # local variables
1679 0 my ($buf, $ci, $co, $gsa);
1680  
1681 # save tag signature
1682 0 $self->[0]{'signature'} = $tag->[0];
1683  
1684 # seek start of tag
1685 0 seek($fh, $tag->[1], 0);
1686  
1687 # read tag header
1688 0 read($fh, $buf, 12);
1689  
1690 # unpack header
1691 0 ($ci, $co) = unpack('x8 n2', $buf);
1692  
1693 # set number of input channels
1694 0 $self->[0]{'input_channels'} = $ci;
1695  
1696 # set number of output channels
1697 0 $self->[0]{'output_channels'} = $co;
1698  
1699 # read grid size array
1700 0 read($fh, $buf, 16);
1701  
1702 # make grid size array
1703 0 $gsa = [grep {$_} unpack('C16', $buf)];
1704  
1705 # save grid size array
1706 0 $self->[2] = [@{$gsa}];
1707  
1708 # read clut
1709 0 _read_clut($self, $fh, $co, $gsa, 4);
1710  
1711 }
1712  
1713 # write clut data
1714 # note: assumes file handle is positioned at start of clut data
1715 # header information must be written separately by the calling function
1716 # precision is number of bytes per clut element, 1 (8-bit), 2 (16-bit) or 4 (floating point)
1717 # parameters: (ref_to_object, file_handle, ref_to_grid_size_array, precision)
1718 sub _write_clut {
1719  
1720 # get parameters
1721 4 ▶ my ($self, $fh, $gsa, $bytes) = @_;
Subroutine _write_clut: called CC=12 SCAR=28.5
1722  
1723 # local variables
1724 4 my ($size, $buf);
1725  
1726 # initialize clut size
1727 4 $size = 1;
1728  
1729 # for each input channel
1730 4 for (@{$gsa}) {
1731
1732 # multiply by grid size
1733 13 $size *= $_;
1734
1735 }
1736  
1737 # if 8-bit table
1738 4 ▶ if ($bytes == 1) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bytes == 1) { } 1 3 4
elsif ($bytes == 2) { } 3 0 3
elsif ($bytes == 4) { } 0 0 0
1739
1740 # for each clut entry
1741 1 for my $i (0 .. $size - 1) {
1742
1743 # write clut values, limiting and adding 0.5 to round
1744 35937 ▶ print $fh pack('C*', map {$_ < 0 ? 0 : ($_ > 1 ? 255 : $_ * 255 + 0.5)} @{$self->[1][$i]});
Branch: 2 branches
BranchTrueFalseTotal
$_ < 0 ? : 0 35937 35937
$_ > 1 ? : 0 35937 35937
1745
1746 }
1747
1748 # if 16-bit table
1749 } elsif ($bytes == 2) {
1750
1751 # for each clut entry
1752 3 for my $i (0 .. $size - 1) {
1753
1754 # write clut values, limiting and adding 0.5 to round
1755 93347 ▶ print $fh pack('n*', map {$_ < 0 ? 0 : ($_ > 1 ? 65535 : $_ * 65535 + 0.5)} @{$self->[1][$i]});
Branch: 2 branches
BranchTrueFalseTotal
$_ < 0 ? : 0 280041 280041
$_ > 1 ? : 0 280041 280041
1756
1757 }
1758
1759 # if floating point table
1760 } elsif ($bytes == 4) {
1761
1762 # for each clut entry
1763 0 for my $i (0 .. $size - 1) {
1764
1765 # write clut values
1766 0 print $fh pack('f>*', @{$self->[1][$i]});
1767
1768 }
1769
1770 } else {
1771
1772 # error
1773 0 croak('unsupported data size, must be 1, 2 or 4 bytes');
1774
1775 }
1776
1777 }
1778  
1779 # write clut tag to ICC profile
1780 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
1781 sub _writeICCclut {
1782  
1783 # get parameters
1784 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCclut: not called CC=7 SCAR=40.3
1785  
1786 # local variables
1787 0 my ($gsa, $ci, $co, @mat);
1788  
1789 # get grid size array
1790 0 $gsa = $self->[2];
1791  
1792 # get number of input channels
1793 0 $ci = @{$gsa};
1794  
1795 # get number of output channels
1796 0 $co = @{$self->[1][0]};
1797  
1798 # validate number input channels (1 to 15)
1799 0 ▶ ($ci > 0 && $ci < 16) || croak('unsupported number of input channels');
Branch: 1 branch
BranchTrueFalseTotal
$ci > 0 and $ci < 16 or croak("unsupported number of input channels") 0 0 0
Condition0%0/3
$ci > 0 and $ci < 16
!ll&&!rl&&r
000
MC/DC0%0/2
$ci > 0 and $ci < 16
$ci > 0 $ci < 16
Truth table0%0/3
A and B
A= $ci > 0B= $ci < 16
ABresult
0X0
100
111
1800  
1801 # validate number output channels (1 to 15)
1802 0 ▶ ($co > 0 && $co < 16) || croak('unsupported number of output channels');
Branch: 1 branch
BranchTrueFalseTotal
$co > 0 and $co < 16 or croak("unsupported number of output channels") 0 0 0
Condition0%0/3
$co > 0 and $co < 16
!ll&&!rl&&r
000
MC/DC0%0/2
$co > 0 and $co < 16
$co > 0 $co < 16
Truth table0%0/3
A and B
A= $co > 0B= $co < 16
ABresult
0X0
100
111
1803  
1804 # for each possible input channel
1805 0 for my $i (0 .. 15) {
1806
1807 # set grid size
1808 0 ▶ $mat[$i] = $gsa->[$i] || 0;
Condition0%0/2
$gsa->[$i] || 0
l!l
00
MC/DC0%0/1
$gsa->[$i] || 0
$gsa->[$i]
Truth table0%0/2
A
A= $gsa->[$i]
Aresult
11
00
1809
1810 }
1811  
1812 # seek start of tag
1813 0 seek($fh, $tag->[1], 0);
1814  
1815 # write 'clut' header
1816 0 print $fh pack('a4 x4 n2 C16', 'clut', $ci, $co, @mat);
1817  
1818 # write clut
1819 0 _write_clut($self, $fh, $gsa, 4);
1820  
1821 }
1822  
1823 7 1;
« blib/lib/ICC/Support/rbf.pm ↑ Summary lib/ICC/Support/bern.pm »