blib/lib/ICC/Profile/view.pm

filter: Statementstmt 20.0% 14 / 70 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.8% 19 / 137 CC 18 SCAR 27.5
CC
18
Cov
13%
type
30.0
sdump
30.0
_newICCview
20.0
CRAP 15.7
« blib/lib/ICC/Profile/ZXML.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 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 # 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) or 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 # verify 4 parameters
86 0 ▶ (@_ == 4) or croak('wrong number of parameters');
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
@_ == 4 or croak("wrong number of parameters") 0 0 0
87  
88 # write view data to profile
89 0 goto &_writeICCview;
90  
91 }
92  
93 # get tag size (for writing to profile)
94 # returns: (tag_size)
95 sub size {
96
97 # get parameters
98 0 ▶ my ($self) = @_;
Subroutine size: not called CC=1 SCAR=6.9
Pod undocumented
99
100 # return size
101 0 return(36);
102
103 }
104  
105 # get XYZ values
106 # index: illuminant = 0, surround = 1
107 # returns: (ref_to_XYZ_array)
108 sub XYZ {
109  
110 # get parameters
111 0 ▶ my $self = shift();
Subroutine XYZ: not called CC=3 SCAR=24.8
Pod undocumented
112
113 # get index
114 0 my $i = shift();
115
116 # verify index
117 0 ▶ ($i == 0 || $i == 1) or 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
118  
119 # return XYZ values
120 0 return($self->[$i + 1]);
121  
122 }
123  
124 # get/set illuminant type
125 # 0 = unknown, 1 = D50, 2 = D65, 3 = D93, 4 = F2, 5 = D55, 6 = A, 7 = Equi_Power, 8 = F8
126 # parameters: ([type_value])
127 # returns: (type_value)
128 sub type {
129  
130 # get object reference
131 0 ▶ my $self = shift();
Subroutine type: not called CC=5 SCAR=34.0
Pod undocumented
132
133 # if parameter supplied
134 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
135
136 # get type value
137 0 my $type = shift();
138
139 # verify type value
140 0 ▶ ($type == int($type) && $type >= 0 && $type <= 8) or 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
141
142 # save it
143 0 $self->[3] = $type;
144
145 }
146
147 # return illuminant type
148 0 return($self->[3]);
149  
150 }
151  
152 # print object contents to string
153 # format is an array structure
154 # parameter: ([format])
155 # returns: (string)
156 sub sdump {
157  
158 # get parameters
159 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
160  
161 # local variables
162 0 my ($s, $fmt);
163  
164 # resolve parameter to an array reference
165 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
166  
167 # get format string
168 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
169  
170 # set string to object ID
171 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
172  
173 # return
174 0 return($s);
175  
176 }
177  
178 # make new view tag from attribute hash
179 # hash may contain pointers to header, illuminant XYZ array, surround XYZ array, illuminant type
180 # keys are: ('header', 'illuminant', 'surround', 'type')
181 # tag elements not specified in the hash are left empty
182 # parameters: (ref_to_object, ref_to_attribute_hash)
183 sub _newICCview {
184
185 # get parameters
186 0 ▶ my ($self, $hash) = @_;
Subroutine _newICCview: not called CC=4 SCAR=30.0
187
188 # local variables
189 0 my (%list);
190
191 # set attribute list (key => [reference_type, array_index])
192 0 %list = ('header' => ['HASH', 0], 'illuminant' => ['ARRAY', 1], 'surround' => ['ARRAY', 2], 'type' => ['', 3]);
193
194 # for each attribute
195 0 for my $attr (keys(%list)) {
196
197 # if attribute specified
198 0 ▶ if (exists($hash->{$attr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hash->{$attr}) 0 0 0
199
200 # if correct reference type
201 0 ▶ if (ref($hash->{$attr}) eq $list{$attr}[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $hash->{$attr} eq $list{$attr}[0]) { } 0 0 0
202
203 # set tag element
204 0 $self->[$list{$attr}[1]] = $hash->{$attr};
205
206 } else {
207
208 # error
209 0 croak('wrong reference type');
210
211 }
212
213 }
214
215 }
216
217 }
218  
219 # read view tag from ICC profile
220 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
221 sub _readICCview {
222
223 # get parameters
224 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCview: not called CC=1 SCAR=6.9
225
226 # local variables
227 0 my ($buf, $i);
228
229 # save tag signature
230 0 $self->[0]{'signature'} = $tag->[0];
231
232 # seek start of tag data
233 0 seek($fh, $tag->[1] + 8, 0);
234
235 # read illuminant XYZ values
236 0 read($fh, $buf, 12);
237
238 # unpack and save values
239 0 $self->[1] = [ICC::Shared::s15f162v(unpack('N3', $buf))];
240
241 # read surround XYZ values
242 0 read($fh, $buf, 12);
243
244 # unpack and save values
245 0 $self->[2] = [ICC::Shared::s15f162v(unpack('N3', $buf))];
246
247 # read illuminant type
248 0 read($fh, $buf, 4);
249
250 # unpack and save value
251 0 $self->[3] = unpack('N', $buf);
252
253 }
254  
255 # write view tag to ICC profile
256 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
257 sub _writeICCview {
258  
259 # get parameters
260 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCview: not called CC=1 SCAR=6.9
261  
262 # local variables
263 0 my ($buf, $XYZ);
264  
265 # seek start of tag
266 0 seek($fh, $tag->[1], 0);
267  
268 # write tag
269 0 print $fh pack('a4 x4 N3 N3 N', 'view', ICC::Shared::v2s15f16(@{$self->[1]}), ICC::Shared::v2s15f16(@{$self->[2]}), $self->[3]);
270  
271 }
272  
273 2 1;
« blib/lib/ICC/Profile/ZXML.pm ↑ Summary blib/lib/ICC/Support/geo2.pm »