blib/lib/ICC/Profile/XYZ_.pm

filter: Statementstmt 65.2% 47 / 72 Branchbran 16.6% 4 / 24 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 71.4% 10 / 14 Podpod 14.2% 1 / 7 totaltotal 49.6% 63 / 127 CC 18 SCAR 24.9
CC
18
Cov
51%
sdump
30.0
_newICCXYZ_
30.0
XYZ
12.0
CRAP 12.1
« blib/lib/ICC/Profile/data.pm ↑ Summary blib/lib/ICC/Profile/desc.pm »
1 package ICC::Profile::XYZ_;
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.12;
7  
8 # revised 2018-08-07
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 # note that the XYZ tag contains an array of XYZ values, not a single XYZ value
19 # there is typically just one XYZ value in that array, which is accessed by the 'XYZ' method
20  
21 # create new XYZ_ tag object
22 # parameters: ()
23 # parameters: (ref_to_XYZ_array)
24 # parameters: (ref_to_array_of_XYZ_arrays)
25 # returns: (ref_to_object)
26 sub new {
27  
28 # get object class
29 1 ▶ my $class = shift();
Subroutine new: called CC=3 SCAR=12.3
Pod undocumented
30  
31 # create empty XYZ_ object
32 1 my $self = [
33 {}, # object header
34 [], # array of XYZ arrays
35 ];
36  
37 # if single parameter is an array reference
38 1 ▶ if (@_ == 1 && ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq "ARRAY") 0 1 1
Condition33%1/3
@_ == 1 and ref $_[0] eq "ARRAY"
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "ARRAY"
@_ == 1 ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "ARRAY"
ABresult
0X0
100
111
39
40 # set object attributes
41 0 _newICCXYZ_($self, @_);
42
43 }
44  
45 # bless object
46 1 bless($self, $class);
47  
48 # return object reference
49 1 return($self);
50  
51 }
52  
53 # create XYZ_ tag object from ICC profile
54 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
55 # returns: (ref_to_object)
56 sub new_fh {
57  
58 # get object class
59 1 ▶ my $class = shift();
Subroutine new_fh: called CC=2 SCAR=7.0
Pod undocumented
60  
61 # create empty XYZ_ object
62 1 my $self = [
63 {}, # object header
64 [], # array of XYZ arrays
65 ];
66  
67 # verify 3 parameters
68 1 ▶ (@_ == 3) or croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 1 1
69  
70 # read XYZ_ data from profile
71 1 _readICCXYZ_($self, @_);
72  
73 # bless object
74 1 bless($self, $class);
75  
76 # return object reference
77 1 return($self);
78  
79 }
80  
81 # writes XYZ_ tag object to ICC profile
82 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
83 sub write_fh {
84  
85 # verify 4 parameters
86 1 ▶ (@_ == 4) or croak('wrong number of parameters');
Subroutine write_fh: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("wrong number of parameters") 0 1 1
87  
88 # write XYZ_ data to profile
89 1 goto &_writeICCXYZ_;
90  
91 }
92  
93 # get tag size (for writing to profile)
94 # returns: (tag_size)
95 sub size {
96  
97 # get parameters
98 3 ▶ my ($self) = @_;
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
99  
100 # return size
101 3 return(8 + @{$self->[1]} * 12);
102  
103 }
104  
105 # get reference to array of XYZ arrays
106 # returns: (ref_to_array_of_XYZ arrays)
107 sub array {
108  
109 # get parameters
110 0 ▶ my $self = shift();
Subroutine array: not called CC=1 SCAR=6.9
Pod undocumented
111  
112 # return reference to array of XYZ arrays
113 0 return($self->[1]);
114  
115 }
116  
117 # get/set first XYZ array
118 # parameters: ([ref_to_XYZ_array])
119 # returns: (ref_to_XYZ_array)
120 sub XYZ {
121  
122 # get object reference
123 0 ▶ my $self = shift();
Subroutine XYZ: not called CC=3 SCAR=24.8
Pod undocumented
124  
125 # if parameter supplied
126 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
127
128 # verify array reference
129 0 ▶ (ref($_[0]) eq 'ARRAY') or croak('parameter must be array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "ARRAY" or croak("parameter must be array reference") 0 0 0
130
131 # save array reference
132 0 $self->[1][0] = shift();
133
134 }
135  
136 # return array reference
137 0 return($self->[1][0]);
138  
139 }
140  
141 # print object contents to string
142 # format is an array structure
143 # parameter: ([format])
144 # returns: (string)
145 sub sdump {
146  
147 # get parameters
148 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
149  
150 # local variables
151 0 my ($s, $fmt);
152  
153 # resolve parameter to an array reference
154 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
155  
156 # get format string
157 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
158  
159 # set string to object ID
160 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
161  
162 # return
163 0 return($s);
164  
165 }
166  
167 # make new XYZ_ tag from array
168 # array may be a single XYZ triplet, or an array of XYZ triplets
169 # parameters: (ref_to_object, ref_to_array)
170 sub _newICCXYZ_ {
171  
172 # get parameters
173 0 ▶ my ($self, $array) = @_;
Subroutine _newICCXYZ_: not called CC=5 SCAR=34.0
174  
175 # if first array element is an array
176 0 ▶ if (ref($array->[0]) eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $array->[0] eq 'ARRAY') { } 0 0 0
elsif (not ref $array->[0]) { } 0 0 0
177
178 # for each array element
179 0 for my $i (0 .. $#{$array}) {
180
181 # if first array element is not a reference
182 0 ▶ if (! ref($array->[$i][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $array->[$i][0]) { } 0 0 0
183
184 # save XYZ triplet
185 0 $self->[1][$i] = [@{$array->[$i]}];
186
187 } else {
188
189 # error
190 0 croak('invalid parameters for XYZ tag');
191
192 }
193
194 }
195
196 # if first array element is not a reference
197 } elsif (! ref($array->[0])) {
198
199 # save XYZ triplet
200 0 $self->[1] = [[@{$array}]];
201
202 } else {
203
204 # error
205 0 croak('invalid parameters for XYZ tag');
206
207 }
208
209 }
210  
211 # read XYZ_ tag from ICC profile
212 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
213 sub _readICCXYZ_ {
214  
215 # get parameters
216 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCXYZ_: called CC=2 SCAR=6.9
217  
218 # local variables
219 1 my ($buf);
220  
221 # save tag signature
222 1 $self->[0]{'signature'} = $tag->[0];
223  
224 # seek start of tag data
225 1 seek($fh, $tag->[1] + 8, 0);
226  
227 # for each XYZ triplet
228 1 for my $i (0 .. ($tag->[2] - 20)/12) {
229
230 # read XYZ values
231 1 read($fh, $buf, 12);
232
233 # unpack XYZ values
234 1 $self->[1][$i] = [ICC::Shared::s15f162v(unpack('N3', $buf))];
235
236 }
237
238 }
239  
240 # write XYZ_ tag to ICC profile
241 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
242 sub _writeICCXYZ_ {
243  
244 # get parameters
245 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCXYZ_: called CC=3 SCAR=11.0
246  
247 # verify tag data
248 1 ▶ (@{$self->[1]} > 0) or carp('writing \'XYZ_\' tag without values');
Branch: 1 branch
BranchTrueFalseTotal
@{$self->[1];} > 0 or carp("writing 'XYZ_' tag without values") 0 1 1
249  
250 # seek start of tag
251 1 seek($fh, $tag->[1], 0);
252  
253 # write tag signature
254 1 print $fh pack('a4 x4', 'XYZ ');
255  
256 # for each XYZ triplet
257 1 for my $XYZ (@{$self->[1]}) {
258
259 # write XYZ values
260 1 print $fh pack('N3', map {$_ + 0.5} ICC::Shared::v2s15f16(@{$XYZ}));
261
262 }
263
264 }
265  
266 2 1;
« blib/lib/ICC/Profile/data.pm ↑ Summary blib/lib/ICC/Profile/desc.pm »