line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package ICC::Profile::ZXML; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
86964
|
use strict; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
110
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.22; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# revised 2018-08-07 |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright © 2004-2019 by William B. Birkett |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# add development directory |
13
|
2
|
|
|
2
|
|
427
|
use lib 'lib'; |
|
2
|
|
|
|
|
561
|
|
|
2
|
|
|
|
|
10
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# inherit from Shared |
16
|
2
|
|
|
2
|
|
609
|
use parent qw(ICC::Shared); |
|
2
|
|
|
|
|
524
|
|
|
2
|
|
|
|
|
8
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# support modules |
19
|
2
|
|
|
2
|
|
1325
|
use Compress::Raw::Zlib; # interface to zlib |
|
2
|
|
|
|
|
8793
|
|
|
2
|
|
|
|
|
1604
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# create new ZXML tag object |
22
|
|
|
|
|
|
|
# parameters: ([text_string]) |
23
|
|
|
|
|
|
|
# returns: (ref_to_object) |
24
|
|
|
|
|
|
|
sub new { |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# get object class |
27
|
1
|
|
|
1
|
0
|
1010
|
my $class = shift(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# create empty ZXML object |
30
|
1
|
|
|
|
|
4
|
my $self = [ |
31
|
|
|
|
|
|
|
{}, # object header |
32
|
|
|
|
|
|
|
'' # zip compressed string |
33
|
|
|
|
|
|
|
]; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# if parameter supplied |
36
|
1
|
50
|
|
|
|
4
|
if (@_) { |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# save it |
39
|
0
|
|
|
|
|
0
|
$self->[1] = shift(); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# bless object |
44
|
1
|
|
|
|
|
3
|
bless($self, $class); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# return object reference |
47
|
1
|
|
|
|
|
2
|
return($self); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# create ZXML 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 ZXML object |
60
|
0
|
|
|
|
|
|
my $self = [ |
61
|
|
|
|
|
|
|
{}, # object header |
62
|
|
|
|
|
|
|
'' # zip compressed string |
63
|
|
|
|
|
|
|
]; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# verify 3 parameters |
66
|
0
|
0
|
|
|
|
|
(@_ == 3) or croak('wrong number of parameters'); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# read ZXML data from profile |
69
|
0
|
|
|
|
|
|
_readICCZXML($self, @_); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# bless object |
72
|
0
|
|
|
|
|
|
bless($self, $class); |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
# return object reference |
75
|
0
|
|
|
|
|
|
return($self); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# writes ZXML tag object to ICC profile |
80
|
|
|
|
|
|
|
# parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) |
81
|
|
|
|
|
|
|
sub write_fh { |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# verify 4 parameters |
84
|
0
|
0
|
|
0
|
0
|
|
(@_ == 4) or croak('wrong number of parameters'); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# write ZXML data to profile |
87
|
0
|
|
|
|
|
|
goto &_writeICCZXML; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# get tag size (for writing to profile) |
92
|
|
|
|
|
|
|
# note: deflates the CxF file and saves result |
93
|
|
|
|
|
|
|
# returns: (tag_size) |
94
|
|
|
|
|
|
|
sub size { |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# get parameters |
97
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# return size |
100
|
0
|
|
|
|
|
|
return(12 + length($self->[1])); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
# get/set zipped data string |
105
|
|
|
|
|
|
|
# parameters: ([data]) |
106
|
|
|
|
|
|
|
# returns: (data) |
107
|
|
|
|
|
|
|
sub data { |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# get object reference |
110
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# if parameter supplied |
113
|
0
|
0
|
|
|
|
|
if (@_) { |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# save it |
116
|
0
|
|
|
|
|
|
$self->[1] = shift(); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# return text string |
121
|
0
|
|
|
|
|
|
return($self->[1]); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# get/set CxF text string |
126
|
|
|
|
|
|
|
# inflates/deflates zipped data string |
127
|
|
|
|
|
|
|
# parameters: ([text_string]) |
128
|
|
|
|
|
|
|
# returns: (text_string) |
129
|
|
|
|
|
|
|
sub text { |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# get object reference |
132
|
0
|
|
|
0
|
0
|
|
my $self = shift(); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# local variables |
135
|
0
|
|
|
|
|
|
my ($cxf, $d, $i, $status); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# if parameter supplied |
138
|
0
|
0
|
|
|
|
|
if (@_) { |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# get parameter |
141
|
0
|
|
|
|
|
|
$cxf = shift(); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# make deflation object |
144
|
0
|
|
|
|
|
|
($d, $status) = Compress::Raw::Zlib::Deflate->new('-AppendOutput' => 1); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# check status |
147
|
0
|
0
|
|
|
|
|
($status == Z_OK) or croak("zlib error $status creating deflation object"); |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# deflate the text string (adding 4 nulls) |
150
|
0
|
|
|
|
|
|
$status = $d->deflate(pack('a* x4', $cxf), $self->[1]); |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# check status |
153
|
0
|
0
|
|
|
|
|
($status == Z_OK) or croak("zlib error $status deflating text string"); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# finish decompression |
156
|
0
|
|
|
|
|
|
$status = $d->flush($self->[1]); |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
} else { |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
# make inflation object |
161
|
0
|
|
|
|
|
|
($i, $status) = Compress::Raw::Zlib::Inflate->new(); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# check status |
164
|
0
|
0
|
|
|
|
|
($status == Z_OK) or croak("zlib error $status creating inflation object"); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# inflate entire zip string |
167
|
0
|
|
|
|
|
|
$status = $i->inflate($self->[1], $cxf); |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# check status |
170
|
0
|
0
|
|
|
|
|
($status == Z_STREAM_END) or croak("zlib error $status inflating text string"); |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# trim nulls from end of string |
173
|
0
|
|
|
|
|
|
$cxf = unpack('Z*', $cxf); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# return text string |
178
|
0
|
|
|
|
|
|
return($cxf); |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# print object contents to string |
183
|
|
|
|
|
|
|
# format is an array structure |
184
|
|
|
|
|
|
|
# parameter: ([format]) |
185
|
|
|
|
|
|
|
# returns: (string) |
186
|
|
|
|
|
|
|
sub sdump { |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
# get parameters |
189
|
0
|
|
|
0
|
1
|
|
my ($self, $p) = @_; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# local variables |
192
|
0
|
|
|
|
|
|
my ($s, $fmt); |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# resolve parameter to an array reference |
195
|
0
|
0
|
|
|
|
|
$p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; |
|
|
0
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
# get format string |
198
|
0
|
0
|
0
|
|
|
|
$fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef'; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# set string to object ID |
201
|
0
|
|
|
|
|
|
$s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
# return |
204
|
0
|
|
|
|
|
|
return($s); |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
# read ZXML tag from ICC profile |
209
|
|
|
|
|
|
|
# parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) |
210
|
|
|
|
|
|
|
sub _readICCZXML { |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# get parameters |
213
|
0
|
|
|
0
|
|
|
my ($self, $parent, $fh, $tag) = @_; |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
# local variables |
216
|
0
|
|
|
|
|
|
my ($buf, $a, $b); |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# save tag signature |
219
|
0
|
|
|
|
|
|
$self->[0]{'signature'} = $tag->[0]; |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
# seek start of tag |
222
|
0
|
|
|
|
|
|
seek($fh, $tag->[1], 0); |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# read tag |
225
|
0
|
|
|
|
|
|
read($fh, $buf, $tag->[2]); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# unpack zip string |
228
|
0
|
|
|
|
|
|
($a, $b, $self->[1]) = unpack('x4 N2 a*', $buf); |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# save prefix values |
231
|
0
|
|
|
|
|
|
$self->[0]{'prefix'} = [$a, $b]; |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
# write ZXML tag to ICC profile |
236
|
|
|
|
|
|
|
# parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) |
237
|
|
|
|
|
|
|
sub _writeICCZXML { |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
# get parameters |
240
|
0
|
|
|
0
|
|
|
my ($self, $parent, $fh, $tag) = @_; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
# seek start of tag |
243
|
0
|
|
|
|
|
|
seek($fh, $tag->[1], 0); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# write tag |
246
|
0
|
|
|
|
|
|
print $fh pack('a4 N2 a*', 'ZXML', @{$self->[0]{'prefix'}}, $self->[1]); |
|
0
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
1; |