blib/lib/ICC/Profile/sf32.pm

filter: Statementstmt 43.8% 43 / 98 Branchbran 15.6% 5 / 32 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 76.9% 10 / 13 Podpod 14.2% 1 / 7 totaltotal 28.9% 59 / 204 CC 32 SCAR 44.8
CC
32
Cov
29%
matrix
210.0
new
73.0
sdump
30.0
CRAP 88.0
« lib/ICC/Support/nPINT.pm ↑ Summary lib/ICC/Support/geo2.pm »
1 package ICC::Profile::sf32;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = 0.22;
7  
8 # revised 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 # create new sf32 tag object
19 # input may be 1-D array, 2-D array, or Math::Matrix object
20 # parameters: ([ref_to_input])
21 # returns: (ref_to_object)
22 sub new {
23  
24 # get object class
25 1 ▶ my $class = shift();
Subroutine new: called CC=10 SCAR=42.9
Pod undocumented
26
27 # create empty sf32 object
28 1 my $self = [
29 {}, # object header
30 [] # s15f16 array
31 ];
32
33 # if parameter supplied
34 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
35
36 # if one parameter, a reference to a 1-D array
37 0 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY' && @{$_[0]} == grep {! ref()} @{$_[0]}) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY' and @{$_[0];} == grep({not ref $_;} @{$_[0];})) { } 0 0 0
elsif (@_ == 1 and ref $_[0] eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix') and @{$_[0];} == grep({ref $_ eq 'ARRAY';} @{$_[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
38
39 # copy array
40 0 $self->[1] = [@{shift()}];
41
42 # if one parameter, a reference to a 2-D array or Math::Matrix object
43 0 ▶ } elsif (@_ == 1 && (ref($_[0]) eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix')) && @{$_[0]} == grep {ref() eq 'ARRAY'} @{$_[0]}) {
Condition0%0/9
@_ == 1 and ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix") and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
!ll&&!rl&&r
000
@_ == 1 and ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix")
!ll&&!rl&&r
000
ref $_[0] eq "ARRAY" or UNIVERSAL::isa($_[0], "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/4
@_ == 1 and ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix") and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
@_ == 1 ref $_[0] eq "ARRAY" UNIVERSAL::isa($_[0], "Math::Matrix") @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
Truth table0%0/6
A and B or C and D
A= @_ == 1B= ref $_[0] eq "ARRAY"C= UNIVERSAL::isa($_[0], "Math::Matrix")D= @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
44
45 # initialize array
46 0 $self->[1] = [];
47
48 # for each row
49 0 for (@{$_[0]}) {
50
51 # push row values
52 0 push(@{$self->[1]}, @{$_});
53
54 }
55
56 } else {
57
58 # error
59 0 croak('parameter must an array reference (1-D or 2-D)');
60
61 }
62
63 }
64  
65 # bless object
66 1 bless($self, $class);
67
68 # return object reference
69 1 return($self);
70  
71 }
72  
73 # create sf32 tag object from ICC profile
74 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
75 # returns: (ref_to_object)
76 sub new_fh {
77  
78 # get object class
79 1 ▶ my $class = shift();
Subroutine new_fh: called CC=2 SCAR=7.0
Pod undocumented
80  
81 # create empty sf32 object
82 1 my $self = [
83 {}, # object header
84 [] # s15f16 array
85 ];
86  
87 # verify 3 parameters
88 1 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 1 1
89  
90 # read sf32 data from profile
91 1 _readICCsf32($self, @_);
92  
93 # bless object
94 1 bless($self, $class);
95  
96 # return object reference
97 1 return($self);
98  
99 }
100  
101 # writes sf32 tag object to ICC profile
102 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
103 sub write_fh {
104  
105 # get tag reference
106 1 ▶ my $self = shift();
Subroutine write_fh: called CC=2 SCAR=7.1
Pod undocumented
107  
108 # verify 3 parameters
109 1 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 1 1
110  
111 # write sf32 data to profile
112 1 _writeICCsf32($self, @_);
113  
114 }
115  
116 # get tag size (for writing to profile)
117 # returns: (tag_size)
118 sub size {
119
120 # get parameters
121 3 ▶ my ($self) = @_;
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
122
123 # return size
124 3 return(8 + @{$self->[1]} * 4);
125
126 }
127  
128 # get/set array reference
129 # parameters: ([ref_to_array])
130 # returns: (ref_to_array)
131 sub array {
132  
133 # get object reference
134 0 ▶ my $self = shift();
Subroutine array: not called CC=3 SCAR=24.8
Pod undocumented
135
136 # if parameter
137 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
138
139 # verify array reference
140 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
141
142 # set array reference
143 0 $self->[1] = shift();
144
145 }
146
147 # return array reference
148 0 return($self->[1]);
149  
150 }
151  
152 # get/set matrix
153 # access array in matrix format
154 # get parameters: (matrix_columns)
155 # set parameters: (matrix_object)
156 # set parameters: (ref_to_2D_array)
157 # returns: (matrix_object)
158 sub matrix {
159  
160 # get object reference
161 0 ▶ my $self = shift();
Subroutine matrix: not called CC=14 SCAR=53.5
Pod undocumented
162
163 # local variables
164 0 my ($size, $rows, $cols, $matrix);
165
166 # if parameter
167 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
168
169 # if one parameter, a scalar
170 0 ▶ if (@_ == 1 && ! ref($_[0])) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) { } 0 0 0
elsif (@_ == 1 and ref $_[0] eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix') and @{$_[0];} == grep({ref $_ eq 'ARRAY';} @{$_[0];})) { } 0 0 0
Condition0%0/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table0%0/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
171
172 # get array size
173 0 $size = @{$self->[1]};
174
175 # get columns
176 0 $cols = shift();
177
178 # verify matrix dimensions
179 0 ▶ ($size && $cols && ($size % $cols == 0)) || croak('invalid matrix dimensions');
Branch: 1 branch
BranchTrueFalseTotal
$size and $cols and $size % $cols == 0 or croak("invalid matrix dimensions") 0 0 0
Condition0%0/6
$size and $cols and $size % $cols == 0
!ll&&!rl&&r
000
$size and $cols
!ll&&!rl&&r
000
MC/DC0%0/3
$size and $cols and $size % $cols == 0
$size $cols $size % $cols == 0
Truth table0%0/4
A and B and C
A= $sizeB= $colsC= $size % $cols == 0
ABCresult
0XX0
10X0
1100
1111
180
181 # make new empty matrix object
182 0 $matrix = Math::Matrix->new([]);
183
184 # compute rows
185 0 $rows = $size/$cols;
186
187 # for each row
188 0 for my $i (0 .. $rows - 1) {
189
190 # set matrix row
191 0 $matrix->[$i] = [@{$self->[1]}[$i * $cols .. ($i + 1) * $cols - 1]];
192
193 }
194
195 # return matrix
196 0 return($matrix);
197
198 # if one parameter, a reference to a 2-D array or Math::Matrix object
199 0 ▶ } elsif (@_ == 1 && (ref($_[0]) eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix')) && @{$_[0]} == grep {ref() eq 'ARRAY'} @{$_[0]}) {
Condition0%0/9
@_ == 1 and ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix") and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
!ll&&!rl&&r
000
@_ == 1 and ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix")
!ll&&!rl&&r
000
ref $_[0] eq "ARRAY" or UNIVERSAL::isa($_[0], "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/4
@_ == 1 and ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix") and @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
@_ == 1 ref $_[0] eq "ARRAY" UNIVERSAL::isa($_[0], "Math::Matrix") @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
Truth table0%0/6
A and B or C and D
A= @_ == 1B= ref $_[0] eq "ARRAY"C= UNIVERSAL::isa($_[0], "Math::Matrix")D= @{$_[0];} == grep({ref $_ eq "ARRAY";} @{$_[0];})
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
200
201 # initialize array
202 0 $self->[1] = [];
203
204 # for each row
205 0 for (@{$_[0]}) {
206
207 # push row values
208 0 push(@{$self->[1]}, @{$_});
209
210 }
211
212 # if an array
213 0 ▶ if (ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
214
215 # return Math::Matrix object
216 0 return (Math::Matrix->new(@{$_[0]}));
217
218 } else {
219
220 # return copy of parameter (Math::Matrix object)
221 0 return(Storable::dclone($_[0]));
222
223 }
224
225 } else {
226
227 # error
228 0 croak('parameter must be column width or a 2-D array reference');
229
230 }
231
232 }
233
234 }
235  
236 # print object contents to string
237 # format is an array structure
238 # parameter: ([format])
239 # returns: (string)
240 sub sdump {
241  
242 # get parameters
243 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
244  
245 # local variables
246 0 my ($s, $fmt);
247  
248 # resolve parameter to an array reference
249 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
250  
251 # get format string
252 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
253  
254 # set string to object ID
255 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
256  
257 # return
258 0 return($s);
259  
260 }
261  
262 # read sf32 tag from ICC profile
263 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
264 sub _readICCsf32 {
265
266 # get parameters
267 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCsf32: called CC=2 SCAR=6.9
268
269 # local variables
270 1 my ($buf);
271
272 # save tag signature
273 1 $self->[0]{'signature'} = $tag->[0];
274
275 # seek start of tag
276 1 seek($fh, $tag->[1], 0);
277
278 # read entire tag
279 1 read($fh, $buf, $tag->[2]);
280
281 # unpack array and convert values
282 1 ▶ $self->[1] = [map {($_ & 0x80000000) ? $_/65536 - 65536 : $_/65536} unpack('x8 N*', $buf)];
Branch: 1 branch
BranchTrueFalseTotal
$_ & 2147483648 ? : 3 6 9
283
284 }
285  
286 # write sf32 tag to ICC profile
287 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
288 sub _writeICCsf32 {
289  
290 # get parameters
291 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCsf32: called CC=1 SCAR=0.0
292  
293 # seek start of tag
294 1 seek($fh, $tag->[1], 0);
295  
296 # write tag
297 1 print $fh pack('a4 x4 N*', 'sf32', map {$_ * 65536} @{$self->[1]});
298  
299 }
300  
301 2 1;
« lib/ICC/Support/nPINT.pm ↑ Summary lib/ICC/Support/geo2.pm »