line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ICC::Profile::XYZ_; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
121256
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
52
|
|
4
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
121
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.12; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# revised 2018-08-07 |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright © 2004-2019 by William B. Birkett |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# add development directory |
13
|
2
|
|
|
2
|
|
465
|
use lib 'lib'; |
|
2
|
|
|
|
|
663
|
|
|
2
|
|
|
|
|
10
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# inherit from Shared |
16
|
2
|
|
|
2
|
|
238
|
use parent qw(ICC::Shared); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
12
|
|
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
|
|
|
1
|
0
|
1116
|
my $class = shift(); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# create empty XYZ_ object |
32
|
1
|
|
|
|
|
4
|
my $self = [ |
33
|
|
|
|
|
|
|
{}, # object header |
34
|
|
|
|
|
|
|
[], # array of XYZ arrays |
35
|
|
|
|
|
|
|
]; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# if single parameter is an array reference |
38
|
1
|
50
|
33
|
|
|
6
|
if (@_ == 1 && ref($_[0]) eq 'ARRAY') { |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# set object attributes |
41
|
0
|
|
|
|
|
0
|
_newICCXYZ_($self, @_); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# bless object |
46
|
1
|
|
|
|
|
3
|
bless($self, $class); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# return object reference |
49
|
1
|
|
|
|
|
3
|
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
|
|
|
1
|
0
|
760
|
my $class = shift(); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# create empty XYZ_ object |
62
|
1
|
|
|
|
|
3
|
my $self = [ |
63
|
|
|
|
|
|
|
{}, # object header |
64
|
|
|
|
|
|
|
[], # array of XYZ arrays |
65
|
|
|
|
|
|
|
]; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# verify 3 parameters |
68
|
1
|
50
|
|
|
|
5
|
(@_ == 3) or croak('wrong number of parameters'); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# read XYZ_ data from profile |
71
|
1
|
|
|
|
|
6
|
_readICCXYZ_($self, @_); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# bless object |
74
|
1
|
|
|
|
|
4
|
bless($self, $class); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# return object reference |
77
|
1
|
|
|
|
|
10
|
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
|
50
|
|
1
|
0
|
1196
|
(@_ == 4) or croak('wrong number of parameters'); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# write XYZ_ data to profile |
89
|
1
|
|
|
|
|
5
|
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
|
|
|
3
|
0
|
609
|
my ($self) = @_; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# return size |
101
|
3
|
|
|
|
|
5
|
return(8 + @{$self->[1]} * 12); |
|
3
|
|
|
|
|
28
|
|
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
|
|
|
0
|
0
|
0
|
my $self = shift(); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# return reference to array of XYZ arrays |
113
|
0
|
|
|
|
|
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
|
|
|
0
|
0
|
0
|
my $self = shift(); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# if parameter supplied |
126
|
0
|
0
|
|
|
|
0
|
if (@_) { |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# verify array reference |
129
|
0
|
0
|
|
|
|
0
|
(ref($_[0]) eq 'ARRAY') or croak('parameter must be array reference'); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# save array reference |
132
|
0
|
|
|
|
|
0
|
$self->[1][0] = shift(); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# return array reference |
137
|
0
|
|
|
|
|
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
|
|
|
0
|
1
|
0
|
my ($self, $p) = @_; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# local variables |
151
|
0
|
|
|
|
|
0
|
my ($s, $fmt); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# resolve parameter to an array reference |
154
|
0
|
0
|
|
|
|
0
|
$p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; |
|
|
0
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# get format string |
157
|
0
|
0
|
0
|
|
|
0
|
$fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef'; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
# set string to object ID |
160
|
0
|
|
|
|
|
0
|
$s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# return |
163
|
0
|
|
|
|
|
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
|
|
|
0
|
|
0
|
my ($self, $array) = @_; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# if first array element is an array |
176
|
0
|
0
|
|
|
|
0
|
if (ref($array->[0]) eq 'ARRAY') { |
|
|
0
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
# for each array element |
179
|
0
|
|
|
|
|
0
|
for my $i (0 .. $#{$array}) { |
|
0
|
|
|
|
|
0
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
# if first array element is not a reference |
182
|
0
|
0
|
|
|
|
0
|
if (! ref($array->[$i][0])) { |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# save XYZ triplet |
185
|
0
|
|
|
|
|
0
|
$self->[1][$i] = [@{$array->[$i]}]; |
|
0
|
|
|
|
|
0
|
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} else { |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# error |
190
|
0
|
|
|
|
|
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
|
|
|
|
|
0
|
$self->[1] = [[@{$array}]]; |
|
0
|
|
|
|
|
0
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
} else { |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# error |
205
|
0
|
|
|
|
|
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
|
|
|
1
|
|
3
|
my ($self, $parent, $fh, $tag) = @_; |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# local variables |
219
|
1
|
|
|
|
|
2
|
my ($buf); |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# save tag signature |
222
|
1
|
|
|
|
|
3
|
$self->[0]{'signature'} = $tag->[0]; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# seek start of tag data |
225
|
1
|
|
|
|
|
14
|
seek($fh, $tag->[1] + 8, 0); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# for each XYZ triplet |
228
|
1
|
|
|
|
|
5
|
for my $i (0 .. ($tag->[2] - 20)/12) { |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# read XYZ values |
231
|
1
|
|
|
|
|
9
|
read($fh, $buf, 12); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
# unpack XYZ values |
234
|
1
|
|
|
|
|
8
|
$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
|
|
|
1
|
|
3
|
my ($self, $parent, $fh, $tag) = @_; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
# verify tag data |
248
|
1
|
50
|
|
|
|
2
|
(@{$self->[1]} > 0) or carp('writing \'XYZ_\' tag without values'); |
|
1
|
|
|
|
|
4
|
|
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# seek start of tag |
251
|
1
|
|
|
|
|
8
|
seek($fh, $tag->[1], 0); |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# write tag signature |
254
|
1
|
|
|
|
|
18
|
print $fh pack('a4 x4', 'XYZ '); |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# for each XYZ triplet |
257
|
1
|
|
|
|
|
3
|
for my $XYZ (@{$self->[1]}) { |
|
1
|
|
|
|
|
4
|
|
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
# write XYZ values |
260
|
1
|
|
|
|
|
3
|
print $fh pack('N3', map {$_ + 0.5} ICC::Shared::v2s15f16(@{$XYZ})); |
|
3
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
6
|
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
1; |