| 1 | package ICC::Profile::data; | ||||||||||||||||||||||||||||
| 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.12; | |||||||||||||||||||||||||||
| 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 | # create new data tag object | ||||||||||||||||||||||||||||
| 19 | # parameters: ([data_flag, data_string]) | ||||||||||||||||||||||||||||
| 20 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||
| 21 | sub new { | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # get object class | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # create empty data object | ||||||||||||||||||||||||||||
| 27 | 0 | my $self = [ | |||||||||||||||||||||||||||
| 28 | {}, # object header | ||||||||||||||||||||||||||||
| 29 | 1, # data flag | ||||||||||||||||||||||||||||
| 30 | '' # data string | ||||||||||||||||||||||||||||
| 31 | ]; | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | # if parameter supplied | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # save data flag | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $self->[1] = (shift() == 0) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # save data string | ||||||||||||||||||||||||||||
| 40 | 0 | $self->[2] = shift(); | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # bless object | ||||||||||||||||||||||||||||
| 45 | 0 | bless($self, $class); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # return object reference | ||||||||||||||||||||||||||||
| 48 | 0 | return($self); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # create data tag object from ICC profile | ||||||||||||||||||||||||||||
| 53 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 54 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||
| 55 | sub new_fh { | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # get object class | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||
|
Subroutine
new_fh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # create empty data object | ||||||||||||||||||||||||||||
| 61 | 0 | my $self = [ | |||||||||||||||||||||||||||
| 62 | {}, # object header | ||||||||||||||||||||||||||||
| 63 | 1, # data flag | ||||||||||||||||||||||||||||
| 64 | '' # data string | ||||||||||||||||||||||||||||
| 65 | ]; | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # verify 3 parameters | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | (@_ == 3) || croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # read data from profile | ||||||||||||||||||||||||||||
| 71 | 0 | _readICCdata($self, @_); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | # bless object | ||||||||||||||||||||||||||||
| 74 | 0 | bless($self, $class); | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | # return object reference | ||||||||||||||||||||||||||||
| 77 | 0 | return($self); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | # writes data tag object to ICC profile | ||||||||||||||||||||||||||||
| 82 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 83 | sub write_fh { | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | # get tag reference | ||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
write_fh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | # verify 3 parameters | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | (@_ == 3) || croak('wrong number of parameters'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # write data to profile | ||||||||||||||||||||||||||||
| 92 | 0 | _writeICCdata($self, @_); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | # get tag size (for writing to profile) | ||||||||||||||||||||||||||||
| 97 | # returns: (tag_size) | ||||||||||||||||||||||||||||
| 98 | sub size { | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # get parameters | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
size: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | # return size | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | return(12 + length($self->[2]) + ($self->[1] == 0 ? 1 : 0)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | # get/set data string | ||||||||||||||||||||||||||||
| 109 | # parameters: ([data_flag, data_string]) | ||||||||||||||||||||||||||||
| 110 | # returns: (data_string) | ||||||||||||||||||||||||||||
| 111 | sub data { | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | # get object reference | ||||||||||||||||||||||||||||
| 114 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||
|
Subroutine
data: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # if parameters supplied | ||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | # save data flag | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | $self->[1] = shift() == 0 ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # save data string | ||||||||||||||||||||||||||||
| 123 | 0 | $self->[2] = shift(); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # return data string | ||||||||||||||||||||||||||||
| 128 | 0 | return($self->[2]); | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | # print object contents to string | ||||||||||||||||||||||||||||
| 133 | # format is an array structure | ||||||||||||||||||||||||||||
| 134 | # parameter: ([format]) | ||||||||||||||||||||||||||||
| 135 | # returns: (string) | ||||||||||||||||||||||||||||
| 136 | sub sdump { | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | # get parameters | ||||||||||||||||||||||||||||
| 139 | 0 | ▶ | my ($self, $p) = @_; | ||||||||||||||||||||||||||
|
Subroutine
sdump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # local variables | ||||||||||||||||||||||||||||
| 142 | 0 | my ($s, $fmt); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | # resolve parameter to an array reference | ||||||||||||||||||||||||||||
| 145 | 0 | ▶ | $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # get format string | ||||||||||||||||||||||||||||
| 148 | 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]
| |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | # set string to object ID | ||||||||||||||||||||||||||||
| 151 | 0 | $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # return | ||||||||||||||||||||||||||||
| 154 | 0 | return($s); | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # read data tag from ICC profile | ||||||||||||||||||||||||||||
| 159 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 160 | sub _readICCdata { | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # get parameters | ||||||||||||||||||||||||||||
| 163 | 0 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_readICCdata: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | # local variables | ||||||||||||||||||||||||||||
| 166 | 0 | my ($buf); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | # save tag signature | ||||||||||||||||||||||||||||
| 169 | 0 | $self->[0]{'signature'} = $tag->[0]; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | # seek start of tag | ||||||||||||||||||||||||||||
| 172 | 0 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # read type and data flag | ||||||||||||||||||||||||||||
| 175 | 0 | read($fh, $buf, 12); | |||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | # unpack data flag | ||||||||||||||||||||||||||||
| 178 | 0 | $self->[1] = unpack('x8 N', $buf); | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # read remaining data | ||||||||||||||||||||||||||||
| 181 | 0 | read($fh, $buf, $tag->[2] - 12); | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | # if ASCII data | ||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if ($self->[1] == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # unpack ASCII data (zero terminated) | ||||||||||||||||||||||||||||
| 187 | 0 | $self->[2] = unpack('Z*', $buf); | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | # if binary data | ||||||||||||||||||||||||||||
| 190 | } elsif ($self->[1] == 1) { | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | # unpack binary data | ||||||||||||||||||||||||||||
| 193 | 0 | $self->[2] = unpack('a*', $buf); | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | } else { | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # print message | ||||||||||||||||||||||||||||
| 198 | 0 | carp('unknown data type'); | |||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | # write data tag to ICC profile | ||||||||||||||||||||||||||||
| 205 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||
| 206 | sub _writeICCdata { | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # get parameters | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_writeICCdata: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # seek start of tag | ||||||||||||||||||||||||||||
| 212 | 0 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | # if ASCII data | ||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($self->[1] == 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | # write tag | ||||||||||||||||||||||||||||
| 218 | 0 | print $fh pack('a4 x4 N Z*', 'data', $self->[1], $self->[2]); | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # if binary data | ||||||||||||||||||||||||||||
| 221 | } elsif ($self->[1] == 1) { | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | # write tag | ||||||||||||||||||||||||||||
| 224 | 0 | print $fh pack('a4 x4 N a*', 'data', $self->[1], $self->[2]); | |||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | } else { | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | # print message | ||||||||||||||||||||||||||||
| 229 | 0 | carp('unknown data type'); | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 2 | 1; | |||||||||||||||||||||||||||