blib/lib/ICC/Profile/para.pm

filter: Statementstmt 21.4% 49 / 229 Branchbran 4.3% 7 / 162 Conditioncond 6.0% 2 / 33 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 47.6% 10 / 21 Podpod 8.3% 1 / 12 totaltotal 14.5% 69 / 475 CC 92 SCAR 47.4
CC
92
Cov
14%
_parametric
240.0
transform
156.0
inverse
156.0
CRAP 114.3
« blib/lib/ICC/Profile/clrt.pm ↑ Summary blib/lib/ICC/Profile/vcgt.pm »
1 package ICC::Profile::para;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 our $VERSION = 0.41;
7  
8 # revised 2016-05-17
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 5 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 5 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # parameter count by function type
19 5 our @Np = (1, 3, 4, 5, 7);
20  
21 # create new 'para' tag object
22 # parameters: ([ref_to_array])
23 # returns: (ref_to_object)
24 sub new {
25  
26 # get object class
27 1 ▶ my $class = shift();
Subroutine new: called CC=6 SCAR=29.9
Pod undocumented
28
29 # create empty para object
30 1 my $self = [
31 {}, # object header
32 [] # parameter array
33 ];
34  
35 # if parameter supplied
36 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
37
38 # verify array reference
39 0 ▶ (ref($_[0]) eq 'ARRAY') || croak('not an array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "ARRAY" or croak("not an array reference") 0 0 0
40
41 # verify function type
42 0 ▶ ($_[0][0] == int($_[0][0]) && defined($Np[$_[0][0]])) || croak('invalid function type');
Branch: 1 branch
BranchTrueFalseTotal
$_[0][0] == int $_[0][0] and defined $ICC::Profile::para::Np[$_[0][0]] or croak("invalid function type") 0 0 0
Condition0%0/3
$_[0][0] == int $_[0][0] and defined $ICC::Profile::para::Np[$_[0][0]]
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0][0] == int $_[0][0] and defined $ICC::Profile::para::Np[$_[0][0]]
$_[0][0] == int $_[0][0] defined $ICC::Profile::para::Np[$_[0][0]]
Truth table0%0/3
A and B
A= $_[0][0] == int $_[0][0]B= defined $ICC::Profile::para::Np[$_[0][0]]
ABresult
0X0
100
111
43
44 # verify number of parameters
45 0 ▶ ($#{$_[0]} == $Np[$_[0][0]]) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
$#{$_[0];} == $ICC::Profile::para::Np[$_[0][0]] or croak("wrong number of parameters") 0 0 0
46
47 # copy array
48 0 $self->[1] = [@{shift()}];
49
50 }
51  
52 # bless object
53 1 bless($self, $class);
54
55 # return object reference
56 1 return($self);
57  
58 }
59  
60 # create inverse 'para' object
61 # returns: (ref_to_object)
62 sub inv {
63  
64 # get object
65 0 ▶ my $self = shift();
Subroutine inv: not called CC=11 SCAR=48.8
Pod undocumented
66  
67 # get parameter array
68 0 my @p = @{$self->[1]};
69  
70 # validate parameters
71 0 ▶ ($p[1]) || croak('invalid gamma value');
Branch: 1 branch
BranchTrueFalseTotal
$p[1] or croak("invalid gamma value") 0 0 0
72 0 ▶ ($p[2]) || croak('invalid a value') if ($p[0] > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $p[0] > 0 0 0 0
Condition0%0/6
$p[0] > 0 && ($p[2] || croak('invalid a value'))
!ll&&!rl&&r
000
$p[2] or croak("invalid a value")
l!l&&r!l&&!r
000
MC/DC0%0/3
$p[0] > 0 && ($p[2] || croak('invalid a value'))
$p[0] > 0 $p[2] croak("invalid a value")
Truth table0%0/4
A && B or C
A= $p[0] > 0B= $p[2]C= croak("invalid a value")
ABCresult
0XX0
1000
11X1
1011
73 0 ▶ ($p[4]) || croak('invalid c value') if ($p[0] > 2);
Branch: 1 branch
BranchTrueFalseTotal
if $p[0] > 2 0 0 0
Condition0%0/6
$p[0] > 2 && ($p[4] || croak('invalid c value'))
!ll&&!rl&&r
000
$p[4] or croak("invalid c value")
l!l&&r!l&&!r
000
MC/DC0%0/3
$p[0] > 2 && ($p[4] || croak('invalid c value'))
$p[0] > 2 $p[4] croak("invalid c value")
Truth table0%0/4
A && B or C
A= $p[0] > 2B= $p[4]C= croak("invalid c value")
ABCresult
0XX0
1000
11X1
1011
74  
75 # if type 0
76 0 ▶ if ($p[0] == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($p[0] == 0) { } 0 0 0
elsif ($p[0] == 1) { } 0 0 0
elsif ($p[0] == 2) { } 0 0 0
elsif ($p[0] == 3) { } 0 0 0
elsif ($p[0] == 4) { } 0 0 0
77
78 # return inverse curve [0, γ]
79 0 return(ICC::Profile::para->new([0, 1/$p[1]]));
80
81 # if type 1
82 } elsif ($p[0] == 1) {
83
84 # return inverse curve [2, γ, a, b, c]
85 0 return(ICC::Profile::para->new([2, 1/$p[1], 1/$p[2]**$p[1], 0, -$p[3]/$p[2]]));
86
87 # if type 2
88 } elsif ($p[0] == 2) {
89
90 # return inverse curve [2, γ, a, b, c]
91 0 return(ICC::Profile::para->new([2, 1/$p[1], 1/$p[2]**$p[1], -$p[4]/$p[2]**$p[1], -$p[3]/$p[2]]));
92
93 # if type 3
94 } elsif ($p[0] == 3) {
95
96 # return inverse curve [4, γ, a, b, c, d, e, f]
97 0 return(ICC::Profile::para->new([4, 1/$p[1], 1/$p[2]**$p[1], 0, 1/$p[4], $p[4] * $p[5], -$p[3]/$p[2], 0]));
98
99 # if type 4
100 } elsif ($p[0] == 4) {
101
102 # return inverse curve [4, γ, a, b, c, d, e, f]
103 0 return(ICC::Profile::para->new([4, 1/$p[1], 1/$p[2]**$p[1], -$p[6]/$p[2]**$p[1], 1/$p[4], $p[4] * $p[5] + $p[7], -$p[3]/$p[2], -$p[7]/$p[4]]));
104
105 } else {
106
107 # error
108 0 croak('invalid \'para\' object');
109
110 }
111
112 }
113  
114 # get/set array reference
115 # parameters: ([ref_to_array])
116 # returns: (ref_to_array)
117 sub array {
118  
119 # get object reference
120 0 ▶ my $self = shift();
Subroutine array: not called CC=7 SCAR=40.3
Pod undocumented
121
122 # local variables
123 0 my ($array, $type);
124
125 # if parameter
126 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
127
128 # get array reference
129 0 $array = shift();
130
131 # verify array reference
132 0 ▶ (ref($array) eq 'ARRAY') || croak('not an array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $array eq "ARRAY" or croak("not an array reference") 0 0 0
133
134 # get function type
135 0 $type = $array->[0];
136
137 # verify function type (integer, 0 - 4)
138 0 ▶ ($type == int($type) && $type >= 0 && $type <= 4) || croak('invalid function type');
Branch: 1 branch
BranchTrueFalseTotal
$type == int $type and $type >= 0 and $type <= 4 or croak("invalid function type") 0 0 0
Condition0%0/6
$type == int $type and $type >= 0 and $type <= 4
!ll&&!rl&&r
000
$type == int $type and $type >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$type == int $type and $type >= 0 and $type <= 4
$type == int $type $type >= 0 $type <= 4
Truth table0%0/4
A and B and C
A= $type == int $typeB= $type >= 0C= $type <= 4
ABCresult
0XX0
10X0
1100
1111
139
140 # verify number of parameters
141 0 ▶ ($#{$array} == $Np[$type]) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
$#{$array;} == $ICC::Profile::para::Np[$type] or croak("wrong number of parameters") 0 0 0
142
143 # set array reference
144 0 $self->[1] = $array;
145
146 }
147
148 # return array reference
149 0 return($self->[1]);
150  
151 }
152  
153 # compute curve function
154 # domain/range is (0 - 1)
155 # parameters: (input_value)
156 # returns: (output_value)
157 sub transform {
158  
159 # get parameters
160 0 ▶ my ($self, $in) = @_;
Subroutine transform: not called CC=12 SCAR=50.5
Pod undocumented
161  
162 # local variables
163 0 my ($a, $type);
164  
165 # get parameter array
166 0 $a = $self->[1];
167  
168 # get function type
169 0 $type = $a->[0];
170  
171 # function type 0
172 0 ▶ if ($type == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type == 0) { } 0 0 0
elsif ($type == 1) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
173
174 # if gamma = 1
175 0 ▶ if ($a->[1] == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->[1] == 1) { } 0 0 0
176
177 # return x
178 0 return($in);
179
180 } else {
181
182 # if input > 0
183 0 ▶ if ($in > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in > 0) { } 0 0 0
184
185 # return x**g
186 0 return($in ** $a->[1]);
187
188 } else {
189
190 # return 0
191 0 return(0);
192
193 }
194
195 }
196
197 # function type 1
198 } elsif ($type == 1) {
199
200 # if input ≥ -b/a
201 0 ▶ if ($in >= - $a->[3]/$a->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= -$a->[3] / $a->[2]) { } 0 0 0
202
203 # return (ax + b)**g
204 0 return(($a->[2] * $in + $a->[3]) ** $a->[1]);
205
206 } else {
207
208 # return 0
209 0 return(0);
210
211 }
212
213 # function type 2
214 } elsif ($type == 2) {
215
216 # if input ≥ -b/a
217 0 ▶ if ($in >= - $a->[3]/$a->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= -$a->[3] / $a->[2]) { } 0 0 0
218
219 # return (ax + b)**g + c
220 0 return(($a->[2] * $in + $a->[3]) ** $a->[1] + $a->[4]);
221
222 } else {
223
224 # return c
225 0 return($a->[4]);
226
227 }
228
229 # function type 3
230 } elsif ($type == 3) {
231
232 # if input ≥ d
233 0 ▶ if ($in >= $a->[5]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $a->[5]) { } 0 0 0
234
235 # return (ax + b)**g
236 0 return(($a->[2] * $in + $a->[3]) ** $a->[1]);
237
238 } else {
239
240 # return cx
241 0 return($a->[4] * $in);
242
243 }
244
245 # function type 4
246 } elsif ($type == 4) {
247
248 # if input ≥ d
249 0 ▶ if ($in >= $a->[5]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $a->[5]) { } 0 0 0
250
251 # return (ax + b)**g + e
252 0 return(($a->[2] * $in + $a->[3]) ** $a->[1] + $a->[6]);
253
254 } else {
255
256 # return (cx + f)
257 0 return($a->[4] * $in + $a->[7]);
258
259 }
260
261 } else {
262
263 # error
264 0 croak('invalid parametric function type');
265
266 }
267
268 }
269  
270 # compute curve inverse
271 # domain/range is (0 - 1)
272 # parameters: (input_value)
273 # returns: (output_value)
274 sub inverse {
275  
276 # get parameters
277 0 ▶ my ($self, $in) = @_;
Subroutine inverse: not called CC=12 SCAR=50.5
Pod undocumented
278  
279 # local variables
280 0 my ($a, $type);
281  
282 # get parameter array reference
283 0 $a = $self->[1];
284  
285 # get function type
286 0 $type = $a->[0];
287  
288 # function type 0
289 0 ▶ if ($type == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type == 0) { } 0 0 0
elsif ($type == 1) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
290
291 # if gamma = 1
292 0 ▶ if ($a->[1] == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->[1] == 1) { } 0 0 0
293
294 # return y
295 0 return($in);
296
297 } else {
298
299 # if input > 0
300 0 ▶ if ($in > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in > 0) { } 0 0 0
301
302 # return y**(1/g)
303 0 return($in ** (1/$a->[1]));
304
305 } else {
306
307 # return 0
308 0 return(0);
309
310 }
311
312 }
313
314 # function type 1
315 } elsif ($type == 1) {
316
317 # if input ≥ 0
318 0 ▶ if ($in >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= 0) { } 0 0 0
319
320 # return (y**(1/g) - b)/a
321 0 return(($in ** (1/$a->[1]) - $a->[3])/$a->[2]);
322
323 } else {
324
325 # return -b/a
326 0 return(- $a->[3]/$a->[2]);
327
328 }
329
330 # function type 2
331 } elsif ($type == 2) {
332
333 # if input ≥ c
334 0 ▶ if ($in >= $a->[4]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $a->[4]) { } 0 0 0
335
336 # return ((y - c)**(1/g) - b)/a
337 0 return((($in - $a->[4]) ** (1/$a->[1]) - $a->[3])/$a->[2]);
338
339 } else {
340
341 # return -b/a
342 0 return(- $a->[3]/$a->[2]);
343
344 }
345
346 # function type 3
347 } elsif ($type == 3) {
348
349 # if input ≥ cd
350 0 ▶ if ($in >= ($a->[4] * $a->[5])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $a->[4] * $a->[5]) { } 0 0 0
351
352 # return (y**(1/g) - b)/a
353 0 return(($in ** (1/$a->[1]) - $a->[3])/$a->[2]);
354
355 } else {
356
357 # return y/c
358 0 return($in/$a->[4]);
359
360 }
361
362 # function type 4
363 } elsif ($type == 4) {
364
365 # if input ≥ cd + f
366 0 ▶ if ($in >= ($a->[4] * $a->[5] + $a->[7])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $a->[4] * $a->[5] + $a->[7]) { } 0 0 0
367
368 # return ((y - e)**(1/g) - b)/a
369 0 return((($in - $a->[6]) ** (1/$a->[1]) - $a->[3])/$a->[2]);
370
371 } else {
372
373 # return (y - f)/c
374 0 return(($in - $a->[7])/$a->[4]);
375
376 }
377
378 } else {
379
380 # error
381 0 croak('invalid parametric function type');
382
383 }
384
385 }
386  
387 # compute curve derivative
388 # domain is (0 - 1)
389 # parameters: (input_value)
390 # returns: (derivative_value)
391 sub derivative {
392  
393 # get parameters
394 0 ▶ my ($self, $in) = @_;
Subroutine derivative: not called CC=12 SCAR=50.5
Pod undocumented
395  
396 # local variables
397 0 my ($a, $type);
398  
399 # get parameter array
400 0 $a = $self->[1];
401  
402 # get function type
403 0 $type = $a->[0];
404  
405 # function type 0
406 0 ▶ if ($type == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type == 0) { } 0 0 0
elsif ($type == 1) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
407
408 # if gamma = 1
409 0 ▶ if ($a->[1] == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a->[1] == 1) { } 0 0 0
410
411 # return 1
412 0 return(1);
413
414 } else {
415
416 # if input > 0
417 0 ▶ if ($in > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in > 0) { } 0 0 0
418
419 # return derivative
420 0 return($a->[1] * $in ** ($a->[1] - 1));
421
422 } else {
423
424 # return 0
425 0 return(0);
426
427 }
428
429 }
430
431 # function type 1
432 } elsif ($type == 1) {
433
434 # if input ≥ -b/a
435 0 ▶ if ($in >= - $a->[3]/$a->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= -$a->[3] / $a->[2]) { } 0 0 0
436
437 # return ga(ax + b)**(g - 1)
438 0 return($a->[1] * $a->[2] * ($a->[2] * $in + $a->[3]) ** ($a->[1] - 1));
439
440 } else {
441
442 # return 0
443 0 return(0);
444
445 }
446
447 # function type 2
448 } elsif ($type == 2) {
449
450 # if input ≥ -b/a
451 0 ▶ if ($in >= - $a->[3]/$a->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= -$a->[3] / $a->[2]) { } 0 0 0
452
453 # return ga(ax + b)**(g - 1)
454 0 return($a->[1] * $a->[2] * ($a->[2] * $in + $a->[3]) ** ($a->[1] - 1));
455
456 } else {
457
458 # return 0
459 0 return(0);
460
461 }
462
463 # function type 3
464 } elsif ($type == 3) {
465
466 # if input ≥ d
467 0 ▶ if ($in >= $a->[5]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $a->[5]) { } 0 0 0
468
469 # return ga(ax + b)**(g - 1)
470 0 return($a->[1] * $a->[2] * ($a->[2] * $in + $a->[3]) ** ($a->[1] - 1));
471
472 } else {
473
474 # return c
475 0 return($a->[4]);
476
477 }
478
479 # function type 4
480 } elsif ($type == 4) {
481
482 # if input ≥ d
483 0 ▶ if ($in >= $a->[5]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $a->[5]) { } 0 0 0
484
485 # return ga(ax + b)**(g - 1)
486 0 return($a->[1] * $a->[2] * ($a->[2] * $in + $a->[3]) ** ($a->[1] - 1));
487
488 } else {
489
490 # return c
491 0 return($a->[4]);
492
493 }
494
495 } else {
496
497 # error
498 0 croak('invalid parametric function type');
499
500 }
501
502 }
503  
504 # create para tag object from ICC profile
505 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
506 # returns: (ref_to_object)
507 sub new_fh {
508  
509 # get object class
510 16 ▶ my $class = shift();
Subroutine new_fh: called CC=2 SCAR=7.0
Pod undocumented
511  
512 # create empty para object
513 16 my $self = [
514 {}, # object header
515 [] # parameter array
516 ];
517  
518 # verify 3 parameters
519 16 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 16 16
520  
521 # read para data from profile
522 16 _readICCpara($self, @_);
523  
524 # bless object
525 16 bless($self, $class);
526  
527 # return object reference
528 16 return($self);
529  
530 }
531  
532 # writes para tag object to ICC profile
533 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
534 sub write_fh {
535  
536 # get tag reference
537 16 ▶ my $self = shift();
Subroutine write_fh: called CC=2 SCAR=7.1
Pod undocumented
538  
539 # verify 3 parameters
540 16 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 16 16
541  
542 # write para data to profile
543 16 _writeICCpara($self, @_);
544  
545 }
546  
547 # get tag size (for writing to profile)
548 # returns: (tag_size)
549 sub size {
550
551 # get parameters
552 60 ▶ my ($self) = @_;
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
553
554 # return size
555 60 return(12 + $Np[$self->[1][0]] * 4);
556
557 }
558  
559 # make table for 'curv' objects
560 # assumes curve domain/range is (0 - 1)
561 # parameters: (number_of_table_entries, [direction])
562 # returns: (ref_to_table_array)
563 sub table {
564  
565 # get parameters
566 0 ▶ my ($self, $n, $dir) = @_;
Subroutine table: not called CC=4 SCAR=30.0
Pod undocumented
567  
568 # local variables
569 0 my ($up, $table);
570  
571 # validate number of table entries
572 0 ▶ ($n == int($n) && $n >= 2) || carp('invalid number of table entries');
Branch: 1 branch
BranchTrueFalseTotal
$n == int $n and $n >= 2 or carp("invalid number of table entries") 0 0 0
Condition0%0/3
$n == int $n and $n >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$n == int $n and $n >= 2
$n == int $n $n >= 2
Truth table0%0/3
A and B
A= $n == int $nB= $n >= 2
ABresult
0X0
100
111
573  
574 # array upper index
575 0 $up = $n - 1;
576  
577 # for each table entry
578 0 for my $i (0 .. $up) {
579
580 # compute table value
581 0 $table->[$i] = _transform($self, $dir, $i/$up);
582
583 }
584  
585 # return table reference
586 0 return($table);
587  
588 }
589  
590 # make 'curv' object
591 # assumes curve domain/range is (0 - 1)
592 # parameters: (number_of_table_entries, [direction])
593 # returns: (ref_to_curv_object)
594 sub curv {
595  
596 # return 'curv' object reference
597 0 ▶ return(ICC::Profile::curv->new(table(@_)));
Subroutine curv: not called CC=1 SCAR=6.9
Pod undocumented
598  
599 }
600  
601 # print object contents to string
602 # format is an array structure
603 # parameter: ([format])
604 # returns: (string)
605 sub sdump {
606  
607 # get parameters
608 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=11 SCAR=48.8
Pod documented
609  
610 # local variables
611 0 my ($s, $fmt, $type);
612  
613 # resolve parameter to an array reference
614 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
615  
616 # get format string
617 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
618  
619 # set string to object ID
620 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
621  
622 # if object has parameters
623 0 ▶ if (defined($type = $self->[1][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($type = $self->[1][0])) { } 0 0 0
624
625 # if function type 0
626 0 ▶ if ($type == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type == 0) { } 0 0 0
elsif ($type == 1) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
627
628 # append parameter string
629 0 $s .= sprintf(" function type %d, gamma %.3f\n", @{$self->[1]});
630
631 # if function type 1
632 } elsif ($type == 1) {
633
634 # append parameter string
635 0 $s .= sprintf(" function type %d, gamma %.3f, a %.3f, b %.3f\n", @{$self->[1]});
636
637 # if function type 2
638 } elsif ($type == 2) {
639
640 # append parameter string
641 0 $s .= sprintf(" function type %d, gamma %.3f, a %.3f, b %.3f, c %.3f\n", @{$self->[1]});
642
643 # if function type 3
644 } elsif ($type == 3) {
645
646 # append parameter string
647 0 $s .= sprintf(" function type %d, gamma %.3f, a %.3f, b %.3f, c %.3f, d %.3f\n", @{$self->[1]});
648
649 # if function type 4
650 } elsif ($type == 4) {
651
652 # append parameter string
653 0 $s .= sprintf(" function type %d, gamma %.3f, a %.3f, b %.3f, c %.3f, d %.3f, e %.3f, f %.3f\n", @{$self->[1]});
654
655 } else {
656
657 # append error string
658 0 $s .= " invalid function type\n";
659
660 }
661
662 } else {
663
664 # append string
665 0 $s .= " <empty object>\n";
666
667 }
668  
669 # return
670 0 return($s);
671  
672 }
673  
674 # directional parametric partial derivatives
675 # nominal domain (0 - 1)
676 # direction: 0 - normal, 1 - inverse
677 # parameters: (object_reference, direction, input_value)
678 # returns: (partial_derivative_array)
679 sub _parametric {
680
681 # get parameters
682 0 ▶ my ($self, $dir, $in) = @_;
Subroutine _parametric: not called CC=15 SCAR=54.8
683
684 # local variables
685 0 my ($array, $type);
686 0 my ($axb, $dyda, $dydb);
687
688 # get parameter array reference
689 0 $array = $self->[1];
690
691 # get function type
692 0 $type = $array->[0];
693
694 # function type 0
695 0 ▶ if ($type == 0) {
Branch: 5 branches
BranchTrueFalseTotal
if ($type == 0) { } 0 0 0
elsif ($type == 1) { } 0 0 0
elsif ($type == 2) { } 0 0 0
elsif ($type == 3) { } 0 0 0
elsif ($type == 4) { } 0 0 0
696
697 # if inverse
698 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
699
700 # return ∂X/∂γ
701 0 return();
702
703 } else {
704
705 # return ∂Y/∂γ
706 0 return($in**$array->[1] * log($in));
707
708 }
709
710 # function type 1
711 } elsif ($type == 1) {
712
713 # if inverse
714 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
715
716 # return ∂X/∂γ, ∂X/∂a, ∂X/∂b
717 0 return();
718
719 } else {
720
721 # compute (aX + b) value
722 0 $axb = $array->[2] * $in + $array->[3];
723
724 # if X >= -b/a
725 0 ▶ if ($axb >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($axb >= 0) { } 0 0 0
726
727 # compute ∂Y/∂b
728 0 $dydb = $array->[1] * $axb**($array->[1] - 1);
729
730 # compute ∂Y/∂a
731 0 $dyda = $dydb * $in;
732
733 # return ∂Y/∂γ, ∂Y/∂a, ∂Y/∂b
734 0 return($axb**$array->[1] * log($axb), $dyda, $dydb);
735
736 } else {
737
738 # return ∂Y/∂γ, ∂Y/∂a, ∂Y/∂b
739 0 return(0, 0, 0);
740
741 }
742
743 }
744
745 # function type 2
746 } elsif ($type == 2) {
747
748 # if inverse
749 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
750
751 # return ∂X/∂γ, ∂X/∂a, ∂X/∂b, ∂X/∂c
752 0 return();
753
754 } else {
755
756 # compute (aX + b) value
757 0 $axb = $array->[2] * $in + $array->[3];
758
759 # if X >= -b/a
760 0 ▶ if ($axb >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($axb >= 0) { } 0 0 0
761
762 # compute ∂Y/∂b
763 0 $dydb = $array->[1] * $axb**($array->[1] - 1);
764
765 # compute ∂Y/∂a
766 0 $dyda = $dydb * $in;
767
768 # return ∂Y/∂γ, ∂Y/∂a, ∂Y/∂b, ∂Y/∂c
769 0 return($axb**$array->[1] * log($axb), $dyda, $dydb, 1);
770
771 } else {
772
773 # return ∂Y/∂γ, ∂Y/∂a, ∂Y/∂b, ∂Y/∂c
774 0 return(0, 0, 0, 1);
775
776 }
777
778 }
779
780 # function type 3
781 } elsif ($type == 3) {
782
783 # if inverse
784 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
785
786 # return ∂X/∂γ, ∂X/∂a, ∂X/∂b, ∂X/∂c
787 0 return();
788
789 } else {
790
791 # if X >= d
792 0 ▶ if ($in >= $array->[5]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $array->[5]) { } 0 0 0
793
794 # compute (aX + b) value
795 0 $axb = $array->[2] * $in + $array->[3];
796
797 # compute ∂Y/∂b
798 0 $dydb = $array->[1] * $axb**($array->[1] - 1);
799
800 # compute ∂Y/∂a
801 0 $dyda = $dydb * $in;
802
803 # return ∂Y/∂γ, ∂Y/∂a, ∂Y/∂b, ∂Y/∂c
804 0 return($axb**$array->[1] * log($axb), $dyda, $dydb, 0);
805
806 } else {
807
808 # return ∂Y/∂γ, ∂Y/∂a, ∂Y/∂b, ∂Y/∂c
809 0 return(0, 0, 0, $in);
810
811 }
812
813 }
814
815 # function type 4
816 } elsif ($type == 4) {
817
818 # if inverse
819 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
820
821 # return ∂X/∂γ, ∂X/∂a, ∂X/∂b, ∂X/∂c, ∂X/∂e, ∂X/∂f
822 0 return();
823
824 } else {
825
826 # if X >= d
827 0 ▶ if ($in >= $array->[5]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in >= $array->[5]) { } 0 0 0
828
829 # compute (aX + b) value
830 0 $axb = $array->[2] * $in + $array->[3];
831
832 # compute ∂Y/∂b
833 0 $dydb = $array->[1] * $axb**($array->[1] - 1);
834
835 # compute ∂Y/∂a
836 0 $dyda = $dydb * $in;
837
838 # return ∂Y/∂γ, ∂Y/∂a, ∂Y/∂b, ∂Y/∂c, ∂Y/∂e, ∂Y/∂f
839 0 return($axb**$array->[1] * log($axb), $dyda, $dydb, 0, 1, 0);
840
841 } else {
842
843 # return ∂Y/∂γ, ∂Y/∂a, ∂Y/∂b, ∂Y/∂c, ∂Y/∂e, ∂Y/∂f
844 0 return(0, 0, 0, $in, 0, 1);
845
846 }
847
848 }
849
850 } else {
851
852 # error
853 0 croak('invalid parametric function type');
854
855 }
856
857 }
858  
859 # directional derivative
860 # nominal domain (0 - 1)
861 # direction: 0 - normal, 1 - inverse
862 # parameters: (object_reference, direction, input_value)
863 # returns: (derivative_value)
864 sub _derivative {
865
866 # get parameters
867 0 ▶ my ($self, $dir, $in) = @_;
Subroutine _derivative: not called CC=3 SCAR=24.8
868
869 # if inverse transform
870 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
871
872 # compute derivative
873 0 my $d = derivative($self, $in);
874
875 # if non-zero
876 0 ▶ if ($d) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d) { } 0 0 0
877
878 # return inverse
879 0 return(1/$d);
880
881 } else {
882
883 # error
884 0 croak('infinite derivative');
885
886 }
887
888 } else {
889
890 # return derivative
891 0 return(derivative($self, $in));
892
893 }
894
895 }
896  
897 # directional transform
898 # nominal domain (0 - 1)
899 # direction: 0 - normal, 1 - inverse
900 # parameters: (object_reference, direction, input_value)
901 # returns: (output_value)
902 sub _transform {
903
904 # get parameters
905 0 ▶ my ($self, $dir, $in) = @_;
Subroutine _transform: not called CC=2 SCAR=17.9
906
907 # if inverse transform
908 0 ▶ if ($dir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dir) { } 0 0 0
909
910 # return inverse
911 0 return(inverse($self, $in));
912
913 } else {
914
915 # return transform
916 0 return(transform($self, $in));
917
918 }
919
920 }
921  
922 # read para tag from ICC profile
923 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
924 sub _readICCpara {
925  
926 # get parameters
927 16 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCpara: called CC=3 SCAR=11.0
928  
929 # local variables
930 16 my ($buf, $fun, $cnt);
931  
932 # save tag signature
933 16 $self->[0]{'signature'} = $tag->[0];
934  
935 # seek start of tag
936 16 seek($fh, $tag->[1], 0);
937  
938 # read tag type signature and function type
939 16 read($fh, $buf, 12);
940  
941 # unpack function type
942 16 $fun = unpack('x8 n x2', $buf);
943  
944 # get parameter count and verify
945 16 ▶ defined($cnt = $Np[$fun]) || croak('invalid function type when reading \'para\' tag');
Branch: 1 branch
BranchTrueFalseTotal
defined($cnt = $ICC::Profile::para::Np[$fun]) or croak("invalid function type when reading 'para' tag") 0 16 16
946  
947 # read parameter values
948 16 read($fh, $buf, $cnt * 4);
949  
950 # unpack the values
951 16 ▶ $self->[1] = [$fun, map {($_ & 0x80000000) ? $_/65536 - 65536 : $_/65536} unpack("N$cnt", $buf)];
Branch: 1 branch
BranchTrueFalseTotal
$_ & 2147483648 ? : 3 23 26
952  
953 }
954  
955 # write para tag to ICC profile
956 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
957 sub _writeICCpara {
958  
959 # get parameters
960 16 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCpara: called CC=4 SCAR=15.0
961  
962 # verify object structure
963 16 ▶ ($self->[1][0] == int($self->[1][0]) && defined($Np[$self->[1][0]]) && $Np[$self->[1][0]] == $#{$self->[1]}) || croak('invalid function data when writing \'para\' tag');
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][0] == int $self->[1][0] and defined $ICC::Profile::para::Np[$self->[1][0]] and $ICC::Profile::para::Np[$self->[1][0]] == $#{$$self[1];} or croak("invalid function data when writing 'para' tag") 0 16 16
Condition33%2/6
$self->[1][0] == int $self->[1][0] and defined $ICC::Profile::para::Np[$self->[1][0]] and $ICC::Profile::para::Np[$self->[1][0]] == $#{$$self[1];}
!ll&&!rl&&r
0016
$self->[1][0] == int $self->[1][0] and defined $ICC::Profile::para::Np[$self->[1][0]]
!ll&&!rl&&r
0016
MC/DC0%0/3
$self->[1][0] == int $self->[1][0] and defined $ICC::Profile::para::Np[$self->[1][0]] and $ICC::Profile::para::Np[$self->[1][0]] == $#{$$self[1];}
$self->[1][0] == int $self->[1][0] defined $ICC::Profile::para::Np[$self->[1][0]] $ICC::Profile::para::Np[$self->[1][0]] == $#{$$self[1];}
Truth table25%1/4
A and B and C
A= $self->[1][0] == int $self->[1][0]B= defined $ICC::Profile::para::Np[$self->[1][0]]C= $ICC::Profile::para::Np[$self->[1][0]] == $#{$$self[1];}
ABCresult
0XX0
10X0
1100
1111
964  
965 # seek start of tag
966 16 seek($fh, $tag->[1], 0);
967  
968 # write tag
969 16 print $fh pack('a4 x4 n x2 N*', 'para', $self->[1][0], map {$_ * 65536} @{$self->[1]}[1 .. $#{$self->[1]}]);
970  
971 }
972  
973 5 1;
« blib/lib/ICC/Profile/clrt.pm ↑ Summary blib/lib/ICC/Profile/vcgt.pm »