lib/ICC/Profile/mpet.pm

filter: Statementstmt 7.7% 22 / 284 Branchbran 0.7% 1 / 126 Conditioncond 0.0% 0 / 43 MC/DCmcdc 0.0% 0 / 28 Subroutinesub 20.6% 6 / 29 Podpod 6.6% 1 / 15 totaltotal 5.7% 30 / 525 CC 98 SCAR 44.1
CC
98
Cov
5%
inverse
272.0
transform
156.0
sdump
132.0
CRAP 82.3
« lib/ICC/Support/nMIX.pm ↑ Summary lib/ICC/Profile/parf.pm »
1 package ICC::Profile::mpet;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 0.51;
7  
8 # revised 2016-05-17
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 2 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 2 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # use POSIX math
19 2 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # create new mpet object
22 # array contains processing element objects
23 # objects must have '_transform' and 'jacobian' methods
24 # parameters: ([array_ref])
25 # returns: (ref_to_object)
26 sub new {
27  
28 # get object class
29 1 ▶ my $class = shift();
Subroutine new: called CC=4 SCAR=20.1
Pod undocumented
30  
31 # create empty mpet object
32 1 my $self = [
33 {}, # object header
34 [], # processing elements
35 0x00 # transform mask
36 ];
37  
38 # if there are parameters
39 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
40
41 # if one parameter, an array reference
42 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY') { } 0 0 0
Condition0%0/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
43
44 # make new mpet tag
45 0 _new_from_array($self, @_);
46
47 } else {
48
49 # error
50 0 croak('parameter must be an array reference');
51
52 }
53
54 }
55  
56 # bless object
57 1 bless($self, $class);
58  
59 # return object reference
60 1 return($self);
61  
62 }
63  
64 # get/set reference to header hash
65 # parameters: ([ref_to_new_hash])
66 # returns: (ref_to_hash)
67 sub header {
68  
69 # get object reference
70 0 ▶ my $self = shift();
Subroutine header: not called CC=4 SCAR=30.0
Pod undocumented
71  
72 # if there are parameters
73 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
74
75 # if one parameter, a hash reference
76 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
77
78 # set header to new hash
79 0 $self->[0] = shift();
80
81 } else {
82
83 # error
84 0 croak('parameter must be a hash reference');
85
86 }
87
88 }
89  
90 # return reference
91 0 return($self->[0]);
92  
93 }
94  
95 # get/set processing element array reference
96 # parameters: ([ref_to_array])
97 # returns: (ref_to_array)
98 sub array {
99  
100 # get object reference
101 0 ▶ my $self = shift();
Subroutine array: not called CC=6 SCAR=37.4
Pod undocumented
102  
103 # if parameter
104 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
105
106 # verify array reference
107 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
108
109 # for each processing element
110 0 for my $i (0 .. $#{$_[0]}) {
111
112 # verify object has processing methods
113 0 ▶ ($_[0][$i]->can('_transform') && $_[0][$i]->can('jacobian')) || croak('processing element lacks \'transform\' or \'jacobian\' method');
Branch: 1 branch
BranchTrueFalseTotal
$_[0][$i]->can("_transform") and $_[0][$i]->can("jacobian") or croak("processing element lacks 'transform' or 'jacobian' method") 0 0 0
Condition0%0/3
$_[0][$i]->can("_transform") and $_[0][$i]->can("jacobian")
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0][$i]->can("_transform") and $_[0][$i]->can("jacobian")
$_[0][$i]->can("_transform") $_[0][$i]->can("jacobian")
Truth table0%0/3
A and B
A= $_[0][$i]->can("_transform")B= $_[0][$i]->can("jacobian")
ABresult
0X0
100
111
114
115 # add processing element
116 0 $self->[1][$i] = $_[0][$i];
117
118 }
119
120 }
121  
122 # return array reference
123 0 return($self->[1]);
124  
125 }
126  
127 # get/set transform mask
128 # bits ... 3-2-1-0 correpsond to ... PE3-PE2-PE1-PE0
129 # parameters: ([new_mask_value])
130 # returns: (mask_value)
131 sub mask {
132  
133 # get object reference
134 0 ▶ my $self = shift();
Subroutine mask: not called CC=3 SCAR=24.8
Pod undocumented
135  
136 # if there are parameters
137 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
138
139 # if one parameter
140 0 ▶ if (@_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1) { } 0 0 0
141
142 # set object transform mask value
143 0 $self->[2] = shift();
144
145 } else {
146
147 # error
148 0 croak('more than one parameter');
149
150 }
151
152 }
153  
154 # return transform mask value
155 0 return($self->[2]);
156  
157 }
158  
159 # create mpet tag object from ICC profile
160 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
161 # returns: (ref_to_object)
162 sub new_fh {
163  
164 # get object class
165 0 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
166  
167 # create empty mpet object
168 0 my $self = [
169 {}, # object header
170 [], # processing elements
171 0x00 # transform mask
172 ];
173  
174 # verify 3 parameters
175 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
176  
177 # read mpet data from profile
178 0 _readICCmpet($self, @_);
179  
180 # bless object
181 0 bless($self, $class);
182  
183 # return object reference
184 0 return($self);
185  
186 }
187  
188 # writes mpet tag object to ICC profile
189 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
190 sub write_fh {
191  
192 # get tag reference
193 0 ▶ my $self = shift();
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
194  
195 # verify 3 parameters
196 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
197  
198 # write mpet data to profile
199 0 _writeICCmpet($self, @_);
200  
201 }
202  
203 # get tag size (for writing to profile)
204 # returns: (tag_size)
205 sub size {
206  
207 # get parameters
208 0 ▶ my ($self) = @_;
Subroutine size: not called CC=2 SCAR=17.9
Pod undocumented
209  
210 # local variables
211 0 my ($size);
212  
213 # set header size
214 0 $size = 16 + 8 * @{$self->[1]};
215  
216 # for each processing element
217 0 for my $pel (@{$self->[1]}) {
218
219 # add size
220 0 $size += $pel->size();
221
222 # adjust to 4-byte boundary
223 0 $size += -$size % 4;
224
225 }
226  
227 # return size
228 0 return($size);
229  
230 }
231  
232 # get number of input channels
233 # returns: (number)
234 sub cin {
235  
236 # get object reference
237 0 ▶ my $self = shift();
Subroutine cin: not called CC=1 SCAR=6.9
Pod undocumented
238  
239 # return
240 0 return($self->[1][0]->cin());
241  
242 }
243  
244 # get number of output channels
245 # returns: (number)
246 sub cout {
247  
248 # get object reference
249 0 ▶ my $self = shift();
Subroutine cout: not called CC=1 SCAR=6.9
Pod undocumented
250  
251 # return
252 0 return($self->[1][-1]->cout());
253  
254 }
255  
256 # transform data
257 # transform mask enables/disables individual tag elements
258 # clipping mask enables/disables individual tag output clipping
259 # supported input types:
260 # parameters: (list, [hash])
261 # parameters: (vector, [hash])
262 # parameters: (matrix, [hash])
263 # parameters: (Math::Matrix_object, [hash])
264 # parameters: (structure, [hash])
265 # returns: (same_type_as_input)
266 sub transform {
267  
268 # set hash value (0 or 1)
269 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
270  
271 # if input a 'Math::Matrix' object
272 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
273
274 # call matrix transform
275 0 &_trans2;
276
277 # if input an array reference
278 ▶ } 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
279
280 # if array contains numbers (vector)
281 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
282
283 # call vector transform
284 0 &_trans1;
285
286 # if array contains vectors (2-D array)
287 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
288
289 # call matrix transform
290 0 &_trans2;
291
292 } else {
293
294 # call structure transform
295 0 &_trans3;
296
297 }
298
299 # if input a list (of numbers)
300 0 } elsif (@_ == $h + 1 + grep {Scalar::Util::looks_like_number($_)} @_) {
301
302 # call list transform
303 0 &_trans0;
304
305 } else {
306
307 # error
308 0 croak('invalid transform input');
309
310 }
311  
312 }
313  
314 # inverse transform
315 # note: number of undefined output values must equal number of defined input values
316 # note: the input and output vectors contain the final solution on return
317 # hash key 'init' specifies initial value vector
318 # hash key 'ubox' enables unit box extrapolation
319 # parameters: (input_vector, output_vector, [hash])
320 # returns: (RMS_error_value)
321 sub inverse {
322  
323 # get parameters
324 0 ▶ my ($self, $in, $out, $hash) = @_;
Subroutine inverse: not called CC=16 SCAR=56.1
Pod undocumented
325  
326 # local variables
327 0 my ($i, $j, @si, @so, $init);
328 0 my ($int, $jac, $mat, $delta);
329 0 my ($max, $elim, $dlim, $accum, $error);
330  
331 # initialize indices
332 0 $i = $j = -1;
333  
334 # build slice arrays while validating input and output arrays
335 0 ▶ ((grep {$i++; defined() && push(@si, $i)} @{$in}) == (grep {$j++; ! defined() && push(@so, $j)} @{$out})) || croak('wrong number of undefined values');
Branch: 3 branches
BranchTrueFalseTotal
grep({++$i; defined $_ and push @si, $i;} @{$in;}) == grep({++$j; not defined $_ and push @so, $j;} @{$out;}) or croak("wrong number of undefined values") 0 0 0
defined $_ and push @si, $i 0 0 0
not defined $_ and push @so, $j 0 0 0
336  
337 # get init array
338 0 $init = $hash->{'init'};
339  
340 # for each undefined output value
341 0 for my $i (@so) {
342
343 # set to supplied initial value or 0.5
344 0 ▶ $out->[$i] = defined($init->[$i]) ? $init->[$i] : 0.5;
Branch: 1 branch
BranchTrueFalseTotal
defined $init->[$i] ? : 0 0 0
345
346 }
347  
348 # set maximum loop count
349 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
350  
351 # loop error limit
352 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
353  
354 # set delta limit ('mpet' tags use floating point PCS, so L*a*b* values need greater limit)
355 0 ▶ $dlim = $hash->{'inv_dlim'} || ($self->[0]{'input_cs'} eq 'Lab ') ? 50.0 : 0.5;
Branch: 1 branch
BranchTrueFalseTotal
$hash->{'inv_dlim'} || $self->[0]{'input_cs'} eq 'Lab ' ? : 0 0 0
Condition0%0/3
$hash->{"inv_dlim"} or $self->[0]{"input_cs"} eq "Lab "
l!l&&r!l&&!r
000
MC/DC0%0/2
$hash->{"inv_dlim"} or $self->[0]{"input_cs"} eq "Lab "
$hash->{"inv_dlim"} $self->[0]{"input_cs"} eq "Lab "
Truth table0%0/3
A or B
A= $hash->{"inv_dlim"}B= $self->[0]{"input_cs"} eq "Lab "
ABresult
1X1
011
000
356  
357 # create empty solution matrix
358 0 $mat = Math::Matrix->new([]);
359  
360 # compute initial transform values
361 0 ($jac, $int) = jacobian($self, $out, $hash);
362  
363 # solution loop
364 0 for (1 .. $max) {
365
366 # for each input
367 0 for my $i (0 .. $#si) {
368
369 # for each output
370 0 for my $j (0 .. $#so) {
371
372 # copy Jacobian value to solution matrix
373 0 $mat->[$i][$j] = $jac->[$si[$i]][$so[$j]];
374
375 }
376
377 # save residual value to solution matrix
378 0 $mat->[$i][$#si + 1] = $in->[$si[$i]] - $int->[$si[$i]];
379
380 }
381
382 # solve for delta values
383 0 $delta = $mat->solve;
384
385 # for each output value
386 0 for my $i (0 .. $#so) {
387
388 # add delta (limited using hyperbolic tangent)
389 0 $out->[$so[$i]] += POSIX::tanh($delta->[$i][0]/$dlim) * $dlim;
390
391 }
392
393 # compute updated transform values
394 0 ($jac, $int) = jacobian($self, $out, $hash);
395
396 # initialize error accumulator
397 0 $accum = 0;
398
399 # for each input
400 0 for my $i (0 .. $#si) {
401
402 # accumulate delta squared
403 0 $accum += ($in->[$si[$i]] - $int->[$si[$i]])**2;
404
405 }
406
407 # compute RMS error
408 0 $error = sqrt($accum/@si);
409
410 # if error less than limit
411 0 ▶ last if ($error < $elim);
Branch: 1 branch
BranchTrueFalseTotal
if $error < $elim 0 0 0
412
413 }
414  
415 # update input vector with final values
416 0 @{$in} = @{$int};
417  
418 # return
419 0 return($error);
420  
421 }
422  
423 # compute Jacobian matrix
424 # transform mask enables/disables individual tag elements
425 # parameters: (input_vector, [hash])
426 # returns: (Jacobian_matrix, [output_vector])
427 sub jacobian {
428  
429 # get parameters
430 0 ▶ my ($self, $data, $hash) = @_;
Subroutine jacobian: not called CC=7 SCAR=40.3
Pod undocumented
431  
432 # local variables
433 0 my ($jac, $jaci);
434  
435 # for each processing element
436 0 for my $i (0 .. $#{$self->[1]}) {
437
438 # if processing element defined, and transform mask bit set
439 0 ▶ if (defined($self->[1][$i]) && $self->[2] & 0x01 << $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1][$i] and $self->[2] & 1 << $i) 0 0 0
Condition0%0/3
defined $self->[1][$i] and $self->[2] & 1 << $i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[1][$i] and $self->[2] & 1 << $i
defined $self->[1][$i] $self->[2] & 1 << $i
Truth table0%0/3
A and B
A= defined $self->[1][$i]B= $self->[2] & 1 << $i
ABresult
0X0
100
111
440
441 # compute Jacobian matrix and transform data
442 0 ($jaci, $data) = $self->[1][$i]->jacobian($data, $hash);
443
444 # multiply Jacobian matrices
445 0 ▶ $jac = defined($jac) ? $jaci * $jac : $jaci;
Branch: 1 branch
BranchTrueFalseTotal
defined $jac ? : 0 0 0
446
447 }
448
449 }
450  
451 # if Jacobian matrix is undefined, use identity matrix
452 0 ▶ $jac = Math::Matrix->diagonal((1) x @{$data}) if (! defined($jac));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $jac 0 0 0
453  
454 # if output values wanted
455 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
456
457 # return Jacobian and output values
458 0 return($jac, $data);
459
460 } else {
461
462 # return Jacobian only
463 0 return($jac);
464
465 }
466
467 }
468  
469 # get/set PCS encoding
470 # for use with ICC::Support::PCS objects
471 # parameters: ([PCS_encoding])
472 # returns: (PCS_encoding)
473 sub pcs {
474  
475 # get parameters
476 0 ▶ my ($self, $pcs) = @_;
Subroutine pcs: not called CC=4 SCAR=30.0
Pod undocumented
477  
478 # if PCS parameter is supplied
479 0 ▶ if (defined($pcs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pcs) { } 0 0 0
480
481 # if a valid PCS encoding
482 0 ▶ if (grep {$pcs == $_} (3, 8)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$pcs == $_;} 3, 8) { } 0 0 0
483
484 # copy to tag header hash
485 0 $self->[0]{'pcs_encoding'} = $pcs;
486
487 # return PCS encoding
488 0 return($pcs);
489
490 } else {
491
492 # error
493 0 croak('invalid PCS encoding');
494
495 }
496
497 } else {
498
499 # if PCS is defined in tag header
500 0 ▶ if (defined($self->[0]{'pcs_encoding'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{'pcs_encoding'}) { } 0 0 0
501
502 # return PCS encoding
503 0 return($self->[0]{'pcs_encoding'});
504
505 } else {
506
507 # error
508 0 croak('can\'t determine PCS encoding');
509
510 }
511
512 }
513
514 }
515  
516 # get/set white point
517 # parameters: ([white_point])
518 # returns: (white_point)
519 sub wtpt {
520  
521 # get parameters
522 0 ▶ my ($self, $wtpt) = @_;
Subroutine wtpt: not called CC=5 SCAR=34.0
Pod undocumented
523  
524 # if white point parameter is supplied
525 0 ▶ if (defined($wtpt)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wtpt) { } 0 0 0
526
527 # if an array of three scalars
528 0 ▶ if (@{$wtpt} == 3 && 3 == grep {! ref()} @{$wtpt}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$wtpt;} == 3 and 3 == grep({not ref $_;} @{$wtpt;})) { } 0 0 0
Condition0%0/3
@{$wtpt;} == 3 and 3 == grep({not ref $_;} @{$wtpt;})
!ll&&!rl&&r
000
MC/DC0%0/2
@{$wtpt;} == 3 and 3 == grep({not ref $_;} @{$wtpt;})
@{$wtpt;} == 3 3 == grep({not ref $_;} @{$wtpt;})
Truth table0%0/3
A and B
A= @{$wtpt;} == 3B= 3 == grep({not ref $_;} @{$wtpt;})
ABresult
0X0
100
111
529
530 # copy to tag header hash
531 0 $self->[0]{'wtpt'} = $wtpt;
532
533 # return white point
534 0 return($wtpt);
535
536 } else {
537
538 # error
539 0 croak('invalid white point');
540
541 }
542
543 } else {
544
545 # if white point is defined in tag header
546 0 ▶ if (defined($self->[0]{'wtpt'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[0]{'wtpt'}) { } 0 0 0
547
548 # return return white point
549 0 return($self->[0]{'wtpt'});
550
551 } else {
552
553 # error
554 0 croak('can\'t determine white point');
555
556 }
557
558 }
559
560 }
561  
562 # print object contents to string
563 # format is an array structure
564 # parameter: ([format])
565 # returns: (string)
566 sub sdump {
567  
568 # get parameters
569 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=11 SCAR=48.8
Pod documented
570  
571 # local variables
572 0 my ($element, $fmt, $s, $pt, $st);
573  
574 # resolve parameter to an array reference
575 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
576  
577 # get format string
578 0 ▶ $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 's';
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
579  
580 # set string to object ID
581 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
582  
583 # if format contains 'o'
584 0 ▶ if ($fmt =~ m/s/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fmt =~ /s/) 0 0 0
585
586 # get default parameter
587 0 $pt = $p->[-1];
588
589 # for each processing element
590 0 for my $i (0 .. $#{$self->[1]}) {
591
592 # get element reference
593 0 $element = $self->[1][$i];
594
595 # if processing element is undefined
596 0 ▶ if (! defined($element)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $element) { } 0 0 0
elsif (not builtin::blessed($element)) { } 0 0 0
elsif ($element->can('sdump')) { } 0 0 0
597
598 # append message
599 0 $s .= "\tprocessing element is undefined\n";
600
601 # if processing element is not a blessed object
602 } elsif (! Scalar::Util::blessed($element)) {
603
604 # append message
605 0 $s .= "\tprocessing element is not a blessed object\n";
606
607 # if processing element has an 'sdump' method
608 } elsif ($element->can('sdump')) {
609
610 # get 'sdump' string
611 0 ▶ $st = $element->sdump(defined($p->[$i + 1]) ? $p->[$i + 1] : $pt);
Branch: 1 branch
BranchTrueFalseTotal
defined $$p[$i + 1] ? : 0 0 0
612
613 # prepend tabs to each line
614 0 $st =~ s/^/\t/mg;
615
616 # append 'sdump' string
617 0 $s .= $st;
618
619 # processing element is object without an 'sdump' method
620 } else {
621
622 # append object info
623 0 $s .= sprintf("\t'%s' object, (0x%x)\n", ref($element), $element);
624
625 }
626
627 }
628
629 }
630  
631 # return
632 0 return($s);
633  
634 }
635  
636 # transform list
637 # parameters: (object_reference, list, [hash])
638 # returns: (list)
639 sub _trans0 {
640  
641 # local variables
642 0 ▶ my ($self, $hash, $data);
Subroutine _trans0: not called CC=2 SCAR=17.9
643  
644 # get object reference
645 0 $self = shift();
646  
647 # get optional hash
648 0 ▶ $hash = pop() if (ref($_[-1]) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 0 0 0
649  
650 # process data
651 0 $data = _trans1($self, [@_], $hash);
652  
653 # return list
654 0 return(@{$data});
655  
656 }
657  
658 # transform vector
659 # parameters: (object_reference, vector, [hash])
660 # returns: (vector)
661 sub _trans1 {
662  
663 # get parameters
664 0 ▶ my ($self, $data, $hash) = @_;
Subroutine _trans1: not called CC=4 SCAR=30.0
665  
666 # for each processing element
667 0 for my $i (0 .. $#{$self->[1]}) {
668
669 # if processing element defined, and transform mask bit set
670 0 ▶ if (defined($self->[1][$i]) && $self->[2] & 0x01 << $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1][$i] and $self->[2] & 1 << $i) 0 0 0
Condition0%0/3
defined $self->[1][$i] and $self->[2] & 1 << $i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[1][$i] and $self->[2] & 1 << $i
defined $self->[1][$i] $self->[2] & 1 << $i
Truth table0%0/3
A and B
A= defined $self->[1][$i]B= $self->[2] & 1 << $i
ABresult
0X0
100
111
671
672 # transform data
673 0 $data = $self->[1][$i]->_trans1($data, $hash);
674
675 }
676
677 }
678
679 # return
680 0 return($data);
681
682 }
683  
684 # transform matrix (2-D array -or- Math::Matrix object)
685 # parameters: (object_reference, matrix, [hash])
686 # returns: (matrix)
687 sub _trans2 {
688  
689 # get parameters
690 0 ▶ my ($self, $data, $hash) = @_;
Subroutine _trans2: not called CC=4 SCAR=30.0
691  
692 # for each processing element
693 0 for my $i (0 .. $#{$self->[1]}) {
694
695 # if processing element defined, and transform mask bit set
696 0 ▶ if (defined($self->[1][$i]) && $self->[2] & 0x01 << $i) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->[1][$i] and $self->[2] & 1 << $i) 0 0 0
Condition0%0/3
defined $self->[1][$i] and $self->[2] & 1 << $i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->[1][$i] and $self->[2] & 1 << $i
defined $self->[1][$i] $self->[2] & 1 << $i
Truth table0%0/3
A and B
A= defined $self->[1][$i]B= $self->[2] & 1 << $i
ABresult
0X0
100
111
697
698 # transform data
699 0 $data = $self->[1][$i]->_trans2($data, $hash);
700
701 }
702
703 }
704  
705 # return
706 0 return($data);
707  
708 }
709  
710 # transform structure
711 # parameters: (object_reference, structure, [hash])
712 # returns: (structure)
713 sub _trans3 {
714  
715 # get parameters
716 0 ▶ my ($self, $in, $hash) = @_;
Subroutine _trans3: not called CC=1 SCAR=6.9
717  
718 # transform the array structure
719 0 _crawl($self, $in, my $out = [], $hash);
720  
721 # return
722 0 return($out);
723  
724 }
725  
726 # recursive transform
727 # array structure is traversed until scalar arrays are found and transformed
728 # parameters: (ref_to_object, input_array_reference, output_array_reference, hash)
729 sub _crawl {
730  
731 # get parameters
732 0 ▶ my ($self, $in, $out, $hash) = @_;
Subroutine _crawl: not called CC=4 SCAR=30.0
733  
734 # if input is a vector (reference to a scalar array)
735 0 ▶ if (@{$in} == grep {! ref()} @{$in}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$in;} == grep({not ref $_;} @{$in;})) { } 0 0 0
736
737 # transform input vector and copy to output
738 0 @{$out} = @{_trans1($self, $in, $hash)};
739
740 } else {
741
742 # for each input element
743 0 for my $i (0 .. $#{$in}) {
744
745 # if an array reference
746 0 ▶ if (ref($in->[$i]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $in->[$i] eq 'ARRAY') { } 0 0 0
747
748 # transform next level
749 0 _crawl($self, $in->[$i], $out->[$i] = [], $hash);
750
751 } else {
752
753 # error
754 0 croak('invalid transform input');
755
756 }
757
758 }
759
760 }
761
762 }
763  
764 # check object structure
765 # parameter: (ref_to_object)
766 # returns: (number_input_channels, number_output_channels)
767 sub _check {
768  
769 # get object reference
770 0 ▶ my $self = shift();
Subroutine _check: not called CC=7 SCAR=40.3
771  
772 # local variables
773 0 my ($ci, $co);
774  
775 # for each processing element
776 0 for my $i (0 .. $#{$self->[1]}) {
777
778 # if element has 'cin' method
779 0 ▶ if ($self->[1][$i]->can('cin')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1][$i]->can("cin")) 0 0 0
780
781 # if number of input channels is undefined
782 0 ▶ if (! defined($ci)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ci) 0 0 0
783
784 # set number of input channels
785 0 $ci = $self->[1][$i]->cin();
786
787 }
788
789 # if number of output channels is defined
790 0 ▶ if (defined($co)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $co) 0 0 0
791
792 # verify input channels of this element match output channels of previous element
793 0 ▶ ($self->[1][$i]->cin() == $co) || croak('\'mpet\' processing element has wrong number of channels');
Branch: 1 branch
BranchTrueFalseTotal
$self->[1][$i]->cin == $co or croak("'mpet' processing element has wrong number of channels") 0 0 0
794
795 }
796
797 }
798
799 # if element has 'cout' method
800 0 ▶ if ($self->[1][$i]->can('cout')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1][$i]->can("cout")) 0 0 0
801
802 # set number of output channels
803 0 $co = $self->[1][$i]->cout();
804
805 }
806
807 }
808  
809 # return
810 0 return($ci, $co);
811  
812 }
813  
814 # make new mpet tag from array
815 # array contains processing element objects
816 # objects must have '_trans1', '_trans2', and 'jacobian' methods
817 # parameters: (ref_to_object, ref_to_array)
818 sub _new_from_array {
819  
820 # get parameters
821 0 ▶ my ($self, $array) = @_;
Subroutine _new_from_array: not called CC=5 SCAR=34.0
822  
823 # for each processing element
824 0 for my $i (0 .. $#{$array}) {
825
826 # verify object has required processing methods
827 0 ▶ ($array->[$i]->can('_trans1')) || croak('processing element lacks \'_trans1\'method');
Branch: 1 branch
BranchTrueFalseTotal
$array->[$i]->can("_trans1") or croak("processing element lacks '_trans1'method") 0 0 0
828 0 ▶ ($array->[$i]->can('_trans2')) || croak('processing element lacks \'_trans2\'method');
Branch: 1 branch
BranchTrueFalseTotal
$array->[$i]->can("_trans2") or croak("processing element lacks '_trans2'method") 0 0 0
829 0 ▶ ($array->[$i]->can('jacobian')) || croak('processing element lacks\'jacobian\' method');
Branch: 1 branch
BranchTrueFalseTotal
$array->[$i]->can("jacobian") or croak("processing element lacks'jacobian' method") 0 0 0
830
831 # add processing element
832 0 $self->[1][$i] = $array->[$i];
833
834 }
835  
836 # check object structure
837 0 _check($self);
838  
839 }
840  
841 # read mpet tag from ICC profile
842 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
843 sub _readICCmpet {
844  
845 # get parameters
846 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCmpet: not called CC=8 SCAR=42.8
847  
848 # local variables
849 0 my ($buf, @mft, $table, $tag2, $type, $class, %hash);
850  
851 # set tag signature
852 0 $self->[0]{'signature'} = $tag->[0];
853  
854 # if 'D2Bx' tag
855 0 ▶ if ($tag->[0] =~ m|^D2B[0-2]$|) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag->[0] =~ /^D2B[0-2]$/) { } 0 0 0
elsif ($tag->[0] =~ /^B2D[0-2]$/) { } 0 0 0
856
857 # set input colorspace
858 0 $self->[0]{'input_cs'} = $parent->[1][4];
859
860 # set output colorspace
861 0 $self->[0]{'output_cs'} = $parent->[1][5];
862
863 # if 'B2Dx' tag
864 } elsif ($tag->[0] =~ m|^B2D[0-2]$|) {
865
866 # set input colorspace
867 0 $self->[0]{'input_cs'} = $parent->[1][5];
868
869 # set output colorspace
870 0 $self->[0]{'output_cs'} = $parent->[1][4];
871
872 }
873  
874 # seek start of tag
875 0 seek($fh, $tag->[1], 0);
876  
877 # read tag header
878 0 read($fh, $buf, 16);
879  
880 # unpack header
881 0 @mft = unpack('a4 x4 n2 N', $buf);
882  
883 # verify tag signature
884 0 ▶ ($mft[0] eq 'mpet') or croak('wrong tag type');
Branch: 1 branch
BranchTrueFalseTotal
$mft[0] eq "mpet" or croak("wrong tag type") 0 0 0
885  
886 # for each processing element
887 0 for my $i (0 .. $mft[3] - 1) {
888
889 # read positionNumber
890 0 read($fh, $buf, 8);
891
892 # unpack to processing element tag table
893 0 $table->[$i] = ['mpet', unpack('N2', $buf)];
894
895 }
896  
897 # clear transform mask
898 0 $self->[2] = 0;
899  
900 # for each processing element
901 0 for my $i (0 .. $mft[3] - 1) {
902
903 # get tag table entry
904 0 $tag2 = $table->[$i];
905
906 # make offset absolute
907 0 $tag2->[1] += $tag->[1];
908
909 # if a duplicate tag
910 0 ▶ if (exists($hash{$tag2->[1]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash{$tag2->[1]}) { } 0 0 0
911
912 # use original tag
913 0 $self->[1][$i] = $hash{$tag2->[1]};
914
915 } else {
916
917 # seek to start of tag
918 0 seek($fh, $tag2->[1], 0);
919
920 # read tag type signature
921 0 read($fh, $type, 4);
922
923 # convert non-word characters to underscores
924 0 $type =~ s|\W|_|g;
925
926 # form class specifier
927 0 $class = "ICC::Profile::$type";
928
929 # if 'class->new_fh' method exists
930 0 ▶ if ($class->can('new_fh')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can('new_fh')) { } 0 0 0
931
932 # create specific tag object
933 0 $self->[1][$i] = $class->new_fh($self, $fh, $tag2);
934
935 } else {
936
937 # create generic tag object
938 0 $self->[1][$i] = ICC::Profile::Generic->new_fh($self, $fh, $tag2);
939
940 # print warning
941 0 print "processing element $type opened as generic\n";
942
943 }
944
945 # save tag in hash
946 0 $hash{$tag2->[1]} = $self->[1][$i];
947
948 }
949
950 # set mask bit
951 0 $self->[2] |= 0x01 << $i;
952
953 }
954  
955 }
956  
957 # write mpet tag to ICC profile
958 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
959 sub _writeICCmpet {
960  
961 # get parameters
962 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCmpet: not called CC=6 SCAR=37.4
963  
964 # local variables
965 0 my ($ci, $co, $n, $offset, $size, @pept, %hash);
966  
967 # check object structure
968 0 ($ci, $co) = _check($self);
969  
970 # set number of processing elements
971 0 $n = @{$self->[1]};
972  
973 # seek start of tag
974 0 seek($fh, $tag->[1], 0);
975  
976 # write 'mpet' header
977 0 print $fh pack('a4 x4 n2 N', 'mpet', $ci, $co, $n);
978  
979 # set tag offset
980 0 $offset = 16 + 8 * $n;
981  
982 # for each processing element
983 0 for my $i (0 .. $#{$self->[1]}) {
984
985 # verify processing element allowed in 'mpet' tag
986 0 ▶ (ref($self->[1][$i]) =~ m/^ICC::Profile::(cvst|matf|clut|Generic)$/) || croak('processing element not allowed in \'mpet\' tag');
Branch: 1 branch
BranchTrueFalseTotal
ref($self->[1][$i]) =~ /^ICC::Profile::(cvst|matf|clut|Generic)$/ or croak("processing element not allowed in 'mpet' tag") 0 0 0
987
988 # if tag not in hash
989 0 ▶ if (! exists($hash{$self->[1][$i]})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $hash{$self->[1][$i]}) { } 0 0 0
990
991 # get size
992 0 $size = $self->[1][$i]->size();
993
994 # set table entry and add to hash
995 0 $pept[$i] = $hash{$self->[1][$i]} = [$offset, $size];
996
997 # update offset
998 0 $offset += $size;
999
1000 # adjust to 4-byte boundary
1001 0 $offset += -$offset % 4;
1002
1003 } else {
1004
1005 # set table entry
1006 0 $pept[$i] = $hash{$self->[1][$i]};
1007
1008 }
1009
1010 # write processing element position entry
1011 0 print $fh pack('N2', @{$pept[$i]});
1012
1013 }
1014  
1015 # initialize hash
1016 0 %hash = ();
1017  
1018 # for each processing element
1019 0 for my $i (0 .. $#{$self->[1]}) {
1020
1021 # if tag not in hash
1022 0 ▶ if (! exists($hash{$self->[1][$i]})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $hash{$self->[1][$i]}) 0 0 0
1023
1024 # make offset absolute
1025 0 $pept[$i][0] += $tag->[1];
1026
1027 # write tag
1028 0 $self->[1][$i]->write_fh($self, $fh, ['mpet', $pept[$i][0], $pept[$i][1]]);
1029
1030 # add key to hash
1031 0 $hash{$self->[1][$i]}++;
1032
1033 }
1034
1035 }
1036
1037 }
1038  
1039 2 1;
« lib/ICC/Support/nMIX.pm ↑ Summary lib/ICC/Profile/parf.pm »