lib/ICC/Profile/samf.pm

filter: Statementstmt 17.3% 17 / 98 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 5 / 15 Podpod 12.5% 1 / 8 totaltotal 13.6% 23 / 168 CC 23 SCAR 30.5
CC
23
Cov
12%
derivative
42.0
transform
42.0
sdump
30.0
CRAP 21.1
« blib/lib/ICC/Support/akima.pm ↑ Summary blib/lib/ICC/Profile/samf.pm »
1 package ICC::Profile::samf;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = 0.11;
7  
8 # revised 2016-05-17
9 #
10 # Copyright © 2004-2018 by William B. Birkett
11  
12 # add development directory
13 1 ▶use lib 'lib';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # inherit from Shared
16 1 ▶use parent qw(ICC::Shared);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 # use POSIX math
19 1 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 # create new samf tag object
22 # parameters: ([ref_to_array])
23 # returns: (ref_to_object)
24 sub new {
25  
26 # get object class
27 0 ▶ my $class = shift();
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
28  
29 # create empty samf object
30 0 my $self = [
31 {}, # object header
32 [] # curve array
33 ];
34  
35 # if parameter supplied
36 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
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 # copy array
42 0 $self->[1] = [@{shift()}];
43
44 }
45  
46 # bless object
47 0 bless($self, $class);
48  
49 # return object reference
50 0 return($self);
51  
52 }
53  
54 # create samf tag object from ICC profile
55 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
56 # returns: (ref_to_object)
57 sub new_fh {
58  
59 # get object class
60 0 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
61  
62 # create empty samf object
63 0 my $self = [
64 {}, # object header
65 [] # curve array
66 ];
67  
68 # verify 3 parameters
69 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
70  
71 # read samf data from profile
72 0 _readICCsamf($self, @_);
73  
74 # bless object
75 0 bless($self, $class);
76  
77 # return object reference
78 0 return($self);
79  
80 }
81  
82 # writes samf tag object to ICC profile
83 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
84 sub write_fh {
85  
86 # get tag reference
87 0 ▶ my $self = shift();
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
88  
89 # verify 3 parameters
90 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
91  
92 # write samf data to profile
93 0 _writeICCsamf($self, @_);
94  
95 }
96  
97 # get tag size (for writing to profile)
98 # returns: (tag_size)
99 sub size {
100  
101 # get parameters
102 0 ▶ my ($self) = @_;
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
103  
104 # return size
105 0 return(12 + 4 * @{$self->[1]});
106  
107 }
108  
109 # compute curve derivative function
110 # parameters: (input_value, lower_breakpoint, upper_breakpoint, preceeding_segment_object)
111 # returns: (output_value)
112 sub derivative {
113  
114 # get parameters
115 0 ▶ my ($self, $in, $xbp0, $xbp1, $pseg) = @_;
Subroutine derivative: not called CC=6 SCAR=37.4
Pod undocumented
116  
117 # local variables
118 0 my ($xpos, $ix, $ir, $low);
119  
120 # compute x-position (0 - number of curve entries)
121 0 $xpos = ($#{$self->[1]} + 1) * ($in - $xbp0)/($xbp1 - $xbp0);
122  
123 # compute lower array index
124 0 $ix = POSIX::floor($xpos);
125  
126 # limit lower array index
127 0 ▶ $ix = $ix < 0 ? 0 : $ix > $#{$self->[1]} ? $#{$self->[1]} : $ix;
Branch: 2 branches
BranchTrueFalseTotal
$ix < 0 ? : 0 0 0
$ix > $#{$$self[1];} ? : 0 0 0
128  
129 # compute interpolation ratio
130 0 $ir = $xpos - $ix;
131  
132 # if lower breakpoint used
133 0 ▶ if ($ix == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix == 0) { } 0 0 0
134
135 # if preceeding segment a 'parf' object
136 0 ▶ if (UNIVERSAL::isa($pseg, 'ICC::Profile::parf')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($pseg, 'ICC::Profile::parf')) { } 0 0 0
elsif (UNIVERSAL::isa($pseg, 'ICC::Profile::samf')) { } 0 0 0
137
138 # compute lower curve entry value
139 0 $low = $pseg->transform($xbp0);
140
141 # if preceeding segment a 'samf' object
142 } elsif (UNIVERSAL::isa($pseg, 'ICC::Profile::samf')) {
143
144 # get lower curve entry value
145 0 $low = $pseg->[1][-1];
146
147 }
148
149 } else {
150
151 # get lower curve entry value
152 0 $low = $self->[1][$ix - 1];
153
154 }
155  
156 # return derivative value
157 0 return(($#{$self->[1]} + 1) * ($self->[1][$ix] - $low)/($xbp1 - $xbp0));
158  
159 }
160  
161 # compute curve function
162 # parameters: (input_value, lower_breakpoint, upper_breakpoint, preceeding_segment_object)
163 # returns: (output_value)
164 sub transform {
165  
166 # get parameters
167 0 ▶ my ($self, $in, $xbp0, $xbp1, $pseg) = @_;
Subroutine transform: not called CC=6 SCAR=37.4
Pod undocumented
168  
169 # local variables
170 0 my ($xpos, $ix, $ir, $low);
171  
172 # compute x-position (0 - number of curve entries)
173 0 $xpos = ($#{$self->[1]} + 1) * ($in - $xbp0)/($xbp1 - $xbp0);
174  
175 # compute lower array index
176 0 $ix = POSIX::floor($xpos);
177  
178 # limit lower array index
179 0 ▶ $ix = $ix < 0 ? 0 : $ix > $#{$self->[1]} ? $#{$self->[1]} : $ix;
Branch: 2 branches
BranchTrueFalseTotal
$ix < 0 ? : 0 0 0
$ix > $#{$$self[1];} ? : 0 0 0
180  
181 # compute interpolation ratio
182 0 $ir = $xpos - $ix;
183  
184 # if lower breakpoint used
185 0 ▶ if ($ix == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ix == 0) { } 0 0 0
186
187 # if preceeding segment a 'parf' object
188 0 ▶ if (UNIVERSAL::isa($pseg, 'ICC::Profile::parf')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($pseg, 'ICC::Profile::parf')) { } 0 0 0
elsif (UNIVERSAL::isa($pseg, 'ICC::Profile::samf')) { } 0 0 0
189
190 # compute lower curve entry value
191 0 $low = $pseg->transform($xbp0);
192
193 # if preceeding segment a 'samf' object
194 } elsif (UNIVERSAL::isa($pseg, 'ICC::Profile::samf')) {
195
196 # get lower curve entry value
197 0 $low = $pseg->[1][-1];
198
199 }
200
201 } else {
202
203 # get lower curve entry value
204 0 $low = $self->[1][$ix - 1];
205
206 }
207  
208 # return interpolated value
209 0 return($low + $ir * ($self->[1][$ix] - $low));
210  
211 }
212  
213 # get/set array reference
214 # parameters: ([ref_to_array])
215 # returns: (ref_to_array)
216 sub array {
217  
218 # get object reference
219 0 ▶ my $self = shift();
Subroutine array: not called CC=3 SCAR=24.8
Pod undocumented
220  
221 # if parameter
222 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
223
224 # verify array reference
225 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
226
227 # set array reference
228 0 $self->[1] = shift();
229
230 }
231  
232 # return array reference
233 0 return($self->[1]);
234  
235 }
236  
237 # print object contents to string
238 # format is an array structure
239 # parameter: ([format])
240 # returns: (string)
241 sub sdump {
242  
243 # get parameters
244 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
245  
246 # local variables
247 0 my ($s, $fmt);
248  
249 # resolve parameter to an array reference
250 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
251  
252 # get format string
253 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
254  
255 # set string to object ID
256 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
257  
258 # return
259 0 return($s);
260  
261 }
262  
263 # read samf tag from ICC profile
264 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
265 sub _readICCsamf {
266  
267 # get parameters
268 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCsamf: not called CC=2 SCAR=17.9
269  
270 # local variables
271 0 my ($buf, $cnt);
272  
273 # save tag signature
274 0 $self->[0]{'signature'} = $tag->[0];
275  
276 # seek start of tag
277 0 seek($fh, $tag->[1], 0);
278  
279 # read tag type signature and count
280 0 read($fh, $buf, 12);
281  
282 # unpack count
283 0 $cnt = unpack('x8 N', $buf);
284  
285 # if count > 0
286 0 ▶ if ($cnt > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cnt > 0) { } 0 0 0
287
288 # read array values
289 0 read($fh, $buf, $cnt * 4);
290
291 # unpack the values
292 0 $self->[1] = [unpack('f>*', $buf)];
293
294 } else {
295
296 # error
297 0 croak('\'samf\' tag has zero count');
298
299 }
300
301 }
302  
303 # write samf tag to ICC profile
304 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
305 sub _writeICCsamf {
306  
307 # get parameters
308 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCsamf: not called CC=2 SCAR=17.9
309  
310 # seek start of tag
311 0 seek($fh, $tag->[1], 0);
312  
313 # write tag type signature and count
314 0 print $fh pack('a4 x4 N', 'samf', scalar(@{$self->[1]}));
315  
316 # if count > 0
317 0 ▶ if (@{$self->[1]} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->[1];} > 0) { } 0 0 0
318
319 # write array
320 0 print $fh pack('f>*', @{$self->[1]});
321
322 } else {
323
324 # error
325 0 croak('\'samf\' object has zero count');
326
327 }
328
329 }
330  
331 1 1;
« blib/lib/ICC/Support/akima.pm ↑ Summary blib/lib/ICC/Profile/samf.pm »