line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ICC::Profile::view; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
97325
|
use strict; |
|
2
|
|
|
|
|
12
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
125
|
|
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
|
|
422
|
use lib 'lib'; |
|
2
|
|
|
|
|
614
|
|
|
2
|
|
|
|
|
10
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# inherit from Shared |
16
|
2
|
|
|
2
|
|
573
|
use parent qw(ICC::Shared); |
|
2
|
|
|
|
|
238
|
|
|
2
|
|
|
|
|
9
|
|
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
|
|
|
0
|
0
|
|
my $class = shift(); |
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
|
0
|
0
|
|
|
|
if (@_ == 1 && ref($_[0]) eq 'HASH') { |
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
|
|
|
0
|
0
|
|
my $class = shift(); |
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
|
0
|
|
|
|
|
(@_ == 3) or croak('wrong number of parameters'); |
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
|
0
|
|
0
|
0
|
|
(@_ == 4) or croak('wrong number of parameters'); |
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
|
|
|
0
|
0
|
|
my ($self) = @_; |
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
|
|
|
0
|
0
|
|
my $self = shift(); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# get index |
114
|
0
|
|
|
|
|
|
my $i = shift(); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# verify index |
117
|
0
|
0
|
0
|
|
|
|
($i == 0 || $i == 1) or croak('invalid view index'); |
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
|
|
|
0
|
0
|
|
my $self = shift(); |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# if parameter supplied |
134
|
0
|
0
|
|
|
|
|
if (@_) { |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# get type value |
137
|
0
|
|
|
|
|
|
my $type = shift(); |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# verify type value |
140
|
0
|
0
|
0
|
|
|
|
($type == int($type) && $type >= 0 && $type <= 8) or croak('invalid illuminant type'); |
|
|
|
0
|
|
|
|
|
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
|
|
|
0
|
1
|
|
my ($self, $p) = @_; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# local variables |
162
|
0
|
|
|
|
|
|
my ($s, $fmt); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# resolve parameter to an array reference |
165
|
0
|
0
|
|
|
|
|
$p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; |
|
|
0
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
# get format string |
168
|
0
|
0
|
0
|
|
|
|
$fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef'; |
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
|
|
|
0
|
|
|
my ($self, $hash) = @_; |
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
|
0
|
|
|
|
|
if (exists($hash->{$attr})) { |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# if correct reference type |
201
|
0
|
0
|
|
|
|
|
if (ref($hash->{$attr}) eq $list{$attr}[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
|
|
|
0
|
|
|
my ($self, $parent, $fh, $tag) = @_; |
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
|
|
|
0
|
|
|
my ($self, $parent, $fh, $tag) = @_; |
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]); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
1; |