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