| 1 | package ICC::Profile::ZXML; | ||||||||||||||||||||||||||||
| 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.22; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # revised 2016-05-17 | ||||||||||||||||||||||||||||
| 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 | # support modules | ||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use Compress::Raw::Zlib; # interface to zlib | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # create empty ZXML object | ||||||||||||||||||||||||||||
| 30 | 1 | my $self = [ | |||||||||||||||||||||||||||
| 31 | {}, # object header | ||||||||||||||||||||||||||||
| 32 | '' # zip compressed string | ||||||||||||||||||||||||||||
| 33 | ]; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # if parameter supplied | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # save it | ||||||||||||||||||||||||||||
| 39 | 0 | $self->[1] = shift(); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # bless object | ||||||||||||||||||||||||||||
| 44 | 1 | bless($self, $class); | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # return object reference | ||||||||||||||||||||||||||||
| 47 | 1 | 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 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new_fh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 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 | ▶ | (@_ == 3) || croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | # get tag reference | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
write_fh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | # verify 3 parameters | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | (@_ == 3) || croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | # write ZXML data to profile | ||||||||||||||||||||||||||||
| 90 | 0 | _writeICCZXML($self, @_); | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # get tag size (for writing to profile) | ||||||||||||||||||||||||||||
| 95 | # note: deflates the CxF file and saves result | ||||||||||||||||||||||||||||
| 96 | # returns: (tag_size) | ||||||||||||||||||||||||||||
| 97 | sub size { | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | # get parameters | ||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
size: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # return size | ||||||||||||||||||||||||||||
| 103 | 0 | return(12 + length($self->[1])); | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # get/set zipped data string | ||||||||||||||||||||||||||||
| 108 | # parameters: ([data]) | ||||||||||||||||||||||||||||
| 109 | # returns: (data) | ||||||||||||||||||||||||||||
| 110 | sub data { | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # get object reference | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
data: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | # if parameter supplied | ||||||||||||||||||||||||||||
| 116 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | # save it | ||||||||||||||||||||||||||||
| 119 | 0 | $self->[1] = shift(); | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | # return text string | ||||||||||||||||||||||||||||
| 124 | 0 | return($self->[1]); | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | # get/set CxF text string | ||||||||||||||||||||||||||||
| 129 | # inflates/deflates zipped data string | ||||||||||||||||||||||||||||
| 130 | # parameters: ([text_string]) | ||||||||||||||||||||||||||||
| 131 | # returns: (text_string) | ||||||||||||||||||||||||||||
| 132 | sub text { | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | # get object reference | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
text: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | # local variables | ||||||||||||||||||||||||||||
| 138 | 0 | my ($cxf, $d, $i, $status); | |||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | # if parameter supplied | ||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | # get parameter | ||||||||||||||||||||||||||||
| 144 | 0 | $cxf = shift(); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # make deflation object | ||||||||||||||||||||||||||||
| 147 | 0 | ($d, $status) = Compress::Raw::Zlib::Deflate->new('-AppendOutput' => 1); | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | # check status | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | ($status == Z_OK) || croak("zlib error $status creating deflation object"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | # deflate the text string (adding 4 nulls) | ||||||||||||||||||||||||||||
| 153 | 0 | $status = $d->deflate(pack('a* x4', $cxf), $self->[1]); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # check status | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | ($status == Z_OK) || croak("zlib error $status deflating text string"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # finish decompression | ||||||||||||||||||||||||||||
| 159 | 0 | $status = $d->flush($self->[1]); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | } else { | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # make inflation object | ||||||||||||||||||||||||||||
| 164 | 0 | ($i, $status) = Compress::Raw::Zlib::Inflate->new(); | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # check status | ||||||||||||||||||||||||||||
| 167 | 0 | ▶ | ($status == Z_OK) || croak("zlib error $status creating inflation object"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # inflate entire zip string | ||||||||||||||||||||||||||||
| 170 | 0 | $status = $i->inflate($self->[1], $cxf); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # check status | ||||||||||||||||||||||||||||
| 173 | 0 | ▶ | ($status == Z_STREAM_END) || croak("zlib error $status inflating text string"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # trim nulls from end of string | ||||||||||||||||||||||||||||
| 176 | 0 | $cxf = unpack('Z*', $cxf); | |||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # return text string | ||||||||||||||||||||||||||||
| 181 | 0 | return($cxf); | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | # print object contents to string | ||||||||||||||||||||||||||||
| 186 | # format is an array structure | ||||||||||||||||||||||||||||
| 187 | # parameter: ([format]) | ||||||||||||||||||||||||||||
| 188 | # returns: (string) | ||||||||||||||||||||||||||||
| 189 | sub sdump { | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | # get parameters | ||||||||||||||||||||||||||||
| 192 | 0 | ▶ | my ($self, $p) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sdump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # local variables | ||||||||||||||||||||||||||||
| 195 | 0 | my ($s, $fmt); | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # resolve parameter to an array reference | ||||||||||||||||||||||||||||
| 198 | 0 | ▶ | $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | # get format string | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $p->[0] and not ref $p->[0]
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]
| |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | # set string to object ID | ||||||||||||||||||||||||||||
| 204 | 0 | $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | # return | ||||||||||||||||||||||||||||
| 207 | 0 | return($s); | |||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # read ZXML tag from ICC profile | ||||||||||||||||||||||||||||
| 212 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 213 | sub _readICCZXML { | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | # get parameters | ||||||||||||||||||||||||||||
| 216 | 0 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_readICCZXML: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | # local variables | ||||||||||||||||||||||||||||
| 219 | 0 | my ($buf, $a, $b); | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | # save tag signature | ||||||||||||||||||||||||||||
| 222 | 0 | $self->[0]{'signature'} = $tag->[0]; | |||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | # seek start of tag | ||||||||||||||||||||||||||||
| 225 | 0 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | # read tag | ||||||||||||||||||||||||||||
| 228 | 0 | read($fh, $buf, $tag->[2]); | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # unpack zip string | ||||||||||||||||||||||||||||
| 231 | 0 | ($a, $b, $self->[1]) = unpack('x4 N2 a*', $buf); | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | # save prefix values | ||||||||||||||||||||||||||||
| 234 | 0 | $self->[0]{'prefix'} = [$a, $b]; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | # write ZXML tag to ICC profile | ||||||||||||||||||||||||||||
| 239 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 240 | sub _writeICCZXML { | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | # get parameters | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_writeICCZXML: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | # seek start of tag | ||||||||||||||||||||||||||||
| 246 | 0 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | # write tag | ||||||||||||||||||||||||||||
| 249 | 0 | print $fh pack('a4 N2 a*', 'ZXML', @{$self->[0]{'prefix'}}, $self->[1]); | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 2 | 1; | |||||||||||||||||||||||||||