blib/lib/ICC/Profile/XYZ_.pm

filter: Statementstmt 65.7% 48 / 73 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 50.0% 64 / 128 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 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 # 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) || 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 # get tag reference
86 1 ▶ my $self = shift();
Subroutine write_fh: called CC=2 SCAR=7.1
Pod undocumented
87  
88 # verify 3 parameters
89 1 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 1 1
90  
91 # write XYZ_ data to profile
92 1 _writeICCXYZ_($self, @_);
93  
94 }
95  
96 # get tag size (for writing to profile)
97 # returns: (tag_size)
98 sub size {
99  
100 # get parameters
101 3 ▶ my ($self) = @_;
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
102  
103 # return size
104 3 return(8 + @{$self->[1]} * 12);
105  
106 }
107  
108 # get reference to array of XYZ arrays
109 # returns: (ref_to_array_of_XYZ arrays)
110 sub array {
111  
112 # get parameters
113 0 ▶ my $self = shift();
Subroutine array: not called CC=1 SCAR=6.9
Pod undocumented
114  
115 # return reference to array of XYZ arrays
116 0 return($self->[1]);
117  
118 }
119  
120 # get/set first XYZ array
121 # parameters: ([ref_to_XYZ_array])
122 # returns: (ref_to_XYZ_array)
123 sub XYZ {
124  
125 # get object reference
126 0 ▶ my $self = shift();
Subroutine XYZ: not called CC=3 SCAR=24.8
Pod undocumented
127  
128 # if parameter supplied
129 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
130
131 # verify array reference
132 0 ▶ (ref($_[0]) eq 'ARRAY') || croak('parameter must be array reference');
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq "ARRAY" or croak("parameter must be array reference") 0 0 0
133
134 # save array reference
135 0 $self->[1][0] = shift();
136
137 }
138  
139 # return array reference
140 0 return($self->[1][0]);
141  
142 }
143  
144 # print object contents to string
145 # format is an array structure
146 # parameter: ([format])
147 # returns: (string)
148 sub sdump {
149  
150 # get parameters
151 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
152  
153 # local variables
154 0 my ($s, $fmt);
155  
156 # resolve parameter to an array reference
157 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
158  
159 # get format string
160 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
161  
162 # set string to object ID
163 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
164  
165 # return
166 0 return($s);
167  
168 }
169  
170 # make new XYZ_ tag from array
171 # array may be a single XYZ triplet, or an array of XYZ triplets
172 # parameters: (ref_to_object, ref_to_array)
173 sub _newICCXYZ_ {
174  
175 # get parameters
176 0 ▶ my ($self, $array) = @_;
Subroutine _newICCXYZ_: not called CC=5 SCAR=34.0
177  
178 # if first array element is an array
179 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
180
181 # for each array element
182 0 for my $i (0 .. $#{$array}) {
183
184 # if first array element is not a reference
185 0 ▶ if (! ref($array->[$i][0])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $array->[$i][0]) { } 0 0 0
186
187 # save XYZ triplet
188 0 $self->[1][$i] = [@{$array->[$i]}];
189
190 } else {
191
192 # error
193 0 croak('invalid parameters for XYZ tag');
194
195 }
196
197 }
198
199 # if first array element is not a reference
200 } elsif (! ref($array->[0])) {
201
202 # save XYZ triplet
203 0 $self->[1] = [[@{$array}]];
204
205 } else {
206
207 # error
208 0 croak('invalid parameters for XYZ tag');
209
210 }
211
212 }
213  
214 # read XYZ_ tag from ICC profile
215 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
216 sub _readICCXYZ_ {
217  
218 # get parameters
219 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCXYZ_: called CC=2 SCAR=6.9
220  
221 # local variables
222 1 my ($buf);
223  
224 # save tag signature
225 1 $self->[0]{'signature'} = $tag->[0];
226  
227 # seek start of tag data
228 1 seek($fh, $tag->[1] + 8, 0);
229  
230 # for each XYZ triplet
231 1 for my $i (0 .. ($tag->[2] - 20)/12) {
232
233 # read XYZ values
234 1 read($fh, $buf, 12);
235
236 # unpack XYZ values
237 1 $self->[1][$i] = [ICC::Shared::s15f162v(unpack('N3', $buf))];
238
239 }
240
241 }
242  
243 # write XYZ_ tag to ICC profile
244 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
245 sub _writeICCXYZ_ {
246  
247 # get parameters
248 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCXYZ_: called CC=3 SCAR=11.0
249  
250 # verify tag data
251 1 ▶ (@{$self->[1]} > 0) || carp('writing \'XYZ_\' tag without values');
Branch: 1 branch
BranchTrueFalseTotal
@{$self->[1];} > 0 or carp("writing 'XYZ_' tag without values") 0 1 1
252  
253 # seek start of tag
254 1 seek($fh, $tag->[1], 0);
255  
256 # write tag signature
257 1 print $fh pack('a4 x4', 'XYZ ');
258  
259 # for each XYZ triplet
260 1 for my $XYZ (@{$self->[1]}) {
261
262 # write XYZ values
263 1 print $fh pack('N3', map {$_ + 0.5} ICC::Shared::v2s15f16(@{$XYZ}));
264
265 }
266
267 }
268  
269 2 1;
« blib/lib/ICC/Profile/data.pm ↑ Summary blib/lib/ICC/Profile/desc.pm »