blib/lib/ICC/Profile/clut.pm

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