blib/lib/ICC/Profile/view.pm

filter: Statementstmt 19.7% 14 / 71 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 28.5% 4 / 14 Podpod 14.2% 1 / 7 totaltotal 13.7% 19 / 138 CC 18 SCAR 27.5
CC
18
Cov
13%
type
30.0
sdump
30.0
_newICCview
20.0
CRAP 15.7
« blib/lib/ICC/Support/nPINT.pm ↑ Summary blib/lib/ICC/Support/geo2.pm »
1 package ICC::Profile::view;
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 # create new view tag object
19 # parameters: ()
20 # parameters: (ref_to_attribute_hash)
21 # returns: (ref_to_object)
22 sub new {
23  
24 # get object class
25 0 ▶ my $class = shift();
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
26
27 # create empty view object
28 0 my $self = [
29 {}, # object header
30 [], # illuminant XYZ array
31 [], # surround XYZ array
32 0 # illuminant type
33 ];
34  
35 # if single parameter is a hash reference
36 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
37  
38 # set object attributes
39 0 _newICCview($self, @_);
40  
41 }
42  
43 # bless object
44 0 bless($self, $class);
45  
46 # return object reference
47 0 return($self);
48  
49 }
50  
51 # create view tag object from ICC profile
52 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
53 # returns: (ref_to_object)
54 sub new_fh {
55  
56 # get object class
57 0 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
58  
59 # create empty view object
60 0 my $self = [
61 {}, # object header
62 [], # illuminant XYZ array
63 [], # surround XYZ array
64 0 # illuminant type
65 ];
66  
67 # verify 3 parameters
68 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
69  
70 # read view data from profile
71 0 _readICCview($self, @_);
72  
73 # bless object
74 0 bless($self, $class);
75  
76 # return object reference
77 0 return($self);
78  
79 }
80  
81 # writes view 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 0 ▶ my $self = shift();
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
87  
88 # verify 3 parameters
89 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
90  
91 # write view data to profile
92 0 _writeICCview($self, @_);
93  
94 }
95  
96 # get tag size (for writing to profile)
97 # returns: (tag_size)
98 sub size {
99
100 # get parameters
101 0 ▶ my ($self) = @_;
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
102
103 # return size
104 0 return(36);
105
106 }
107  
108 # get XYZ values
109 # index: illuminant = 0, surround = 1
110 # returns: (ref_to_XYZ_array)
111 sub XYZ {
112  
113 # get parameters
114 0 ▶ my $self = shift();
Subroutine XYZ: not called CC=3 SCAR=24.8
Pod undocumented
115
116 # get index
117 0 my $i = shift();
118
119 # verify index
120 0 ▶ ($i == 0 || $i == 1) || croak('invalid view index');
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 or $i == 1 or croak("invalid view index") 0 0 0
Condition0%0/3
$i == 0 or $i == 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$i == 0 or $i == 1
$i == 0 $i == 1
Truth table0%0/3
A or B
A= $i == 0B= $i == 1
ABresult
1X1
011
000
121  
122 # return XYZ values
123 0 return($self->[$i + 1]);
124  
125 }
126  
127 # get/set illuminant type
128 # 0 = unknown, 1 = D50, 2 = D65, 3 = D93, 4 = F2, 5 = D55, 6 = A, 7 = Equi_Power, 8 = F8
129 # parameters: ([type_value])
130 # returns: (type_value)
131 sub type {
132  
133 # get object reference
134 0 ▶ my $self = shift();
Subroutine type: not called CC=5 SCAR=34.0
Pod undocumented
135
136 # if parameter supplied
137 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
138
139 # get type value
140 0 my $type = shift();
141
142 # verify type value
143 0 ▶ ($type == int($type) && $type >= 0 && $type <= 8) || croak('invalid illuminant type');
Branch: 1 branch
BranchTrueFalseTotal
$type == int $type and $type >= 0 and $type <= 8 or croak("invalid illuminant type") 0 0 0
Condition0%0/6
$type == int $type and $type >= 0 and $type <= 8
!ll&&!rl&&r
000
$type == int $type and $type >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$type == int $type and $type >= 0 and $type <= 8
$type == int $type $type >= 0 $type <= 8
Truth table0%0/4
A and B and C
A= $type == int $typeB= $type >= 0C= $type <= 8
ABCresult
0XX0
10X0
1100
1111
144
145 # save it
146 0 $self->[3] = $type;
147
148 }
149
150 # return illuminant type
151 0 return($self->[3]);
152  
153 }
154  
155 # print object contents to string
156 # format is an array structure
157 # parameter: ([format])
158 # returns: (string)
159 sub sdump {
160  
161 # get parameters
162 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
163  
164 # local variables
165 0 my ($s, $fmt);
166  
167 # resolve parameter to an array reference
168 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
169  
170 # get format string
171 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
172  
173 # set string to object ID
174 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
175  
176 # return
177 0 return($s);
178  
179 }
180  
181 # make new view tag from attribute hash
182 # hash may contain pointers to header, illuminant XYZ array, surround XYZ array, illuminant type
183 # keys are: ('header', 'illuminant', 'surround', 'type')
184 # tag elements not specified in the hash are left empty
185 # parameters: (ref_to_object, ref_to_attribute_hash)
186 sub _newICCview {
187
188 # get parameters
189 0 ▶ my ($self, $hash) = @_;
Subroutine _newICCview: not called CC=4 SCAR=30.0
190
191 # local variables
192 0 my (%list);
193
194 # set attribute list (key => [reference_type, array_index])
195 0 %list = ('header' => ['HASH', 0], 'illuminant' => ['ARRAY', 1], 'surround' => ['ARRAY', 2], 'type' => ['', 3]);
196
197 # for each attribute
198 0 for my $attr (keys(%list)) {
199
200 # if attribute specified
201 0 ▶ if (exists($hash->{$attr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash->{$attr}) 0 0 0
202
203 # if correct reference type
204 0 ▶ if (ref($hash->{$attr}) eq $list{$attr}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{$attr} eq $list{$attr}[0]) { } 0 0 0
205
206 # set tag element
207 0 $self->[$list{$attr}[1]] = $hash->{$attr};
208
209 } else {
210
211 # error
212 0 croak('wrong reference type');
213
214 }
215
216 }
217
218 }
219
220 }
221  
222 # read view tag from ICC profile
223 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
224 sub _readICCview {
225
226 # get parameters
227 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCview: not called CC=1 SCAR=6.9
228
229 # local variables
230 0 my ($buf, $i);
231
232 # save tag signature
233 0 $self->[0]{'signature'} = $tag->[0];
234
235 # seek start of tag data
236 0 seek($fh, $tag->[1] + 8, 0);
237
238 # read illuminant XYZ values
239 0 read($fh, $buf, 12);
240
241 # unpack and save values
242 0 $self->[1] = [ICC::Shared::s15f162v(unpack('N3', $buf))];
243
244 # read surround XYZ values
245 0 read($fh, $buf, 12);
246
247 # unpack and save values
248 0 $self->[2] = [ICC::Shared::s15f162v(unpack('N3', $buf))];
249
250 # read illuminant type
251 0 read($fh, $buf, 4);
252
253 # unpack and save value
254 0 $self->[3] = unpack('N', $buf);
255
256 }
257  
258 # write view tag to ICC profile
259 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
260 sub _writeICCview {
261  
262 # get parameters
263 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCview: not called CC=1 SCAR=6.9
264  
265 # local variables
266 0 my ($buf, $XYZ);
267  
268 # seek start of tag
269 0 seek($fh, $tag->[1], 0);
270  
271 # write tag
272 0 print $fh pack('a4 x4 N3 N3 N', 'view', ICC::Shared::v2s15f16(@{$self->[1]}), ICC::Shared::v2s15f16(@{$self->[2]}), $self->[3]);
273  
274 }
275  
276 2 1;
« blib/lib/ICC/Support/nPINT.pm ↑ Summary blib/lib/ICC/Support/geo2.pm »