| 1 | package ICC::Profile::curf; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | 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 | 1 | ▶ | use lib 'lib'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | # inherit from Shared | ||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use parent qw(ICC::Shared); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | # create new curf tag object | ||||||||||||||||||||||||||||||||
| 19 | # hash may contain pointers to segments or breakpoints | ||||||||||||||||||||||||||||||||
| 20 | # segments are an array of 'parf' or 'samf' objects | ||||||||||||||||||||||||||||||||
| 21 | # hash keys are: ('segment', 'breakpoint') | ||||||||||||||||||||||||||||||||
| 22 | # parameters: ([ref_to_attribute_hash]) | ||||||||||||||||||||||||||||||||
| 23 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||||||
| 24 | sub new { | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | # get object class | ||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | # create empty curf object | ||||||||||||||||||||||||||||||||
| 30 | 0 | my $self = [ | |||||||||||||||||||||||||||||||
| 31 | {}, # object header | ||||||||||||||||||||||||||||||||
| 32 | [], # segment object array | ||||||||||||||||||||||||||||||||
| 33 | [] # breakpoint array | ||||||||||||||||||||||||||||||||
| 34 | ]; | ||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | # if there are parameters | ||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | # if one parameter, a hash reference | ||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (@_ == 1 && ref($_[0]) eq 'HASH') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | # make new curf object from attribute hash | ||||||||||||||||||||||||||||||||
| 43 | 0 | _new_from_hash($self, shift()); | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | # error | ||||||||||||||||||||||||||||||||
| 48 | 0 | croak('\'curf\' parameter must be a hash reference'); | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||
| 54 | # bless object | ||||||||||||||||||||||||||||||||
| 55 | 0 | bless($self, $class); | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | # return object reference | ||||||||||||||||||||||||||||||||
| 58 | 0 | return($self); | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||
| 62 | # create curf tag object from ICC profile | ||||||||||||||||||||||||||||||||
| 63 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||||||
| 64 | # returns: (ref_to_object) | ||||||||||||||||||||||||||||||||
| 65 | sub new_fh { | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | # get object class | ||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $class = shift(); | ||||||||||||||||||||||||||||||
|
Subroutine
new_fh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | # create empty curf object | ||||||||||||||||||||||||||||||||
| 71 | 0 | my $self = [ | |||||||||||||||||||||||||||||||
| 72 | {}, # object header | ||||||||||||||||||||||||||||||||
| 73 | [], # segment object array | ||||||||||||||||||||||||||||||||
| 74 | [] # breakpoint array | ||||||||||||||||||||||||||||||||
| 75 | ]; | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | # verify 3 parameters | ||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | (@_ == 3) || croak('wrong number of parameters'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||
| 80 | # read curf data from profile | ||||||||||||||||||||||||||||||||
| 81 | 0 | _readICCcurf($self, @_); | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | # bless object | ||||||||||||||||||||||||||||||||
| 84 | 0 | bless($self, $class); | |||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | # return object reference | ||||||||||||||||||||||||||||||||
| 87 | 0 | return($self); | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | # writes curf tag object to ICC profile | ||||||||||||||||||||||||||||||||
| 92 | # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||||||
| 93 | sub write_fh { | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | # get tag reference | ||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||
|
Subroutine
write_fh: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | # verify 3 parameters | ||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | (@_ == 3) || croak('wrong number of parameters'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | # write curf data to profile | ||||||||||||||||||||||||||||||||
| 102 | 0 | _writeICCcurf($self, @_); | |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | # get tag size (for writing to profile) | ||||||||||||||||||||||||||||||||
| 107 | # returns: (tag_size) | ||||||||||||||||||||||||||||||||
| 108 | sub size { | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | # get parameters | ||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
size: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | # set size of header and breakpoints | ||||||||||||||||||||||||||||||||
| 114 | 0 | my $size = 12 + 4 * @{$self->[2]}; | |||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | # for each curve segment | ||||||||||||||||||||||||||||||||
| 117 | 0 | for my $seg (@{$self->[1]}) { | |||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | # add size | ||||||||||||||||||||||||||||||||
| 120 | 0 | $size += $seg->size(); | |||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | # return size | ||||||||||||||||||||||||||||||||
| 125 | 0 | return($size); | |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | # compute curve derivative function | ||||||||||||||||||||||||||||||||
| 130 | # parameters: (input_value) | ||||||||||||||||||||||||||||||||
| 131 | # returns: (output_value) | ||||||||||||||||||||||||||||||||
| 132 | sub derivative { | ||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | # get parameters | ||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my ($self, $in) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
derivative: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | # local variables | ||||||||||||||||||||||||||||||||
| 138 | 0 | my ($ix); | |||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | # return transformed value, if just one segment | ||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | return($self->[1][0]->derivative($in)) if ($#{$self->[1]} == 0); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||
| 143 | # initialize index | ||||||||||||||||||||||||||||||||
| 144 | 0 | $ix = 0; | |||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||
| 146 | # for each breakpoint | ||||||||||||||||||||||||||||||||
| 147 | 0 | for my $bp (@{$self->[2]}) { | |||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||
| 149 | # last if breakpoint >= input value | ||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | last if ($bp >= $in); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | # increment index | ||||||||||||||||||||||||||||||||
| 153 | 0 | $ix++; | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||
| 157 | # if segment is a 'parf' object | ||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if (UNIVERSAL::isa($self->[1][$ix], 'ICC::Profile::parf')) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | # return transformed value | ||||||||||||||||||||||||||||||||
| 161 | 0 | return($self->[1][$ix]->derivative($in)); | |||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||
| 163 | # if segment is a 'samf' object | ||||||||||||||||||||||||||||||||
| 164 | } elsif (UNIVERSAL::isa($self->[1][$ix], 'ICC::Profile::samf')) { | ||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||
| 166 | # return transformed value | ||||||||||||||||||||||||||||||||
| 167 | 0 | return($self->[1][$ix]->derivative($in, $self->[2][$ix - 1], $self->[2][$ix], $self->[1][$ix - 1])); | |||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||
| 169 | } else { | ||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||
| 171 | # error | ||||||||||||||||||||||||||||||||
| 172 | 0 | croak('unsupported object class for \'curf\' segment'); | |||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | # compute curve function | ||||||||||||||||||||||||||||||||
| 179 | # parameters: (input_value) | ||||||||||||||||||||||||||||||||
| 180 | # returns: (output_value) | ||||||||||||||||||||||||||||||||
| 181 | sub transform { | ||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||
| 183 | # get parameters | ||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my ($self, $in) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
transform: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||
| 186 | # local variables | ||||||||||||||||||||||||||||||||
| 187 | 0 | my ($ix); | |||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||
| 189 | # return transformed value, if just one segment | ||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | return($self->[1][0]->transform($in)) if ($#{$self->[1]} == 0); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||
| 192 | # initialize index | ||||||||||||||||||||||||||||||||
| 193 | 0 | $ix = 0; | |||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||
| 195 | # for each breakpoint | ||||||||||||||||||||||||||||||||
| 196 | 0 | for my $bp (@{$self->[2]}) { | |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||
| 198 | # last if breakpoint >= input value | ||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | last if ($bp >= $in); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | # increment index | ||||||||||||||||||||||||||||||||
| 202 | 0 | $ix++; | |||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||
| 206 | # if segment is a 'parf' object | ||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if (UNIVERSAL::isa($self->[1][$ix], 'ICC::Profile::parf')) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | # return transformed value | ||||||||||||||||||||||||||||||||
| 210 | 0 | return($self->[1][$ix]->transform($in)); | |||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | # if segment is a 'samf' object | ||||||||||||||||||||||||||||||||
| 213 | } elsif (UNIVERSAL::isa($self->[1][$ix], 'ICC::Profile::samf')) { | ||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||
| 215 | # return transformed value | ||||||||||||||||||||||||||||||||
| 216 | 0 | return($self->[1][$ix]->transform($in, $self->[2][$ix - 1], $self->[2][$ix], $self->[1][$ix - 1])); | |||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||
| 218 | } else { | ||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||
| 220 | # error | ||||||||||||||||||||||||||||||||
| 221 | 0 | croak('unsupported object class for \'curf\' segment'); | |||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||
| 227 | # get/set segment array reference | ||||||||||||||||||||||||||||||||
| 228 | # parameters: ([ref_to_array]) | ||||||||||||||||||||||||||||||||
| 229 | # returns: (ref_to_array) | ||||||||||||||||||||||||||||||||
| 230 | sub segment { | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | # get object reference | ||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||
|
Subroutine
segment: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | # if parameter | ||||||||||||||||||||||||||||||||
| 236 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | # verify array reference | ||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | (ref($_[0]) eq 'ARRAY') || croak('not an array reference'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | # set array reference | ||||||||||||||||||||||||||||||||
| 242 | 0 | $self->[1] = [@{shift()}]; | |||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | # return array reference | ||||||||||||||||||||||||||||||||
| 247 | 0 | return($self->[1]); | |||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||
| 251 | # get/set breakpoint array reference | ||||||||||||||||||||||||||||||||
| 252 | # parameters: ([ref_to_array]) | ||||||||||||||||||||||||||||||||
| 253 | # returns: (ref_to_array) | ||||||||||||||||||||||||||||||||
| 254 | sub breakpoint { | ||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||
| 256 | # get object reference | ||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | my $self = shift(); | ||||||||||||||||||||||||||||||
|
Subroutine
breakpoint: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||
| 259 | # if parameter | ||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | # verify array reference | ||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | (ref($_[0]) eq 'ARRAY') || croak('not an array reference'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | # set array reference | ||||||||||||||||||||||||||||||||
| 266 | 0 | $self->[2] = [@{shift()}]; | |||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||
| 270 | # return array reference | ||||||||||||||||||||||||||||||||
| 271 | 0 | return($self->[2]); | |||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||
| 275 | # print object contents to string | ||||||||||||||||||||||||||||||||
| 276 | # format is an array structure | ||||||||||||||||||||||||||||||||
| 277 | # parameter: ([format]) | ||||||||||||||||||||||||||||||||
| 278 | # returns: (string) | ||||||||||||||||||||||||||||||||
| 279 | sub sdump { | ||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | # get parameters | ||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | my ($self, $p) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
sdump: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | # local variables | ||||||||||||||||||||||||||||||||
| 285 | 0 | my ($s, $fmt); | |||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | # resolve parameter to an array reference | ||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : []; | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||
| 290 | # get format string | ||||||||||||||||||||||||||||||||
| 291 | 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]
| |||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||
| 293 | # set string to object ID | ||||||||||||||||||||||||||||||||
| 294 | 0 | $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self); | |||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||
| 296 | # return | ||||||||||||||||||||||||||||||||
| 297 | 0 | return($s); | |||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||
| 301 | # make new curf object from attribute hash | ||||||||||||||||||||||||||||||||
| 302 | # hash may contain pointers to segments, or breakpoints | ||||||||||||||||||||||||||||||||
| 303 | # hash keys are: ('segment', 'breakpoint') | ||||||||||||||||||||||||||||||||
| 304 | # object elements not specified in the hash are unchanged | ||||||||||||||||||||||||||||||||
| 305 | # parameters: (ref_to_object, ref_to_attribute_hash) | ||||||||||||||||||||||||||||||||
| 306 | sub _new_from_hash { | ||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||
| 308 | # get parameters | ||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | my ($self, $hash) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_new_from_hash: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | # for each attribute | ||||||||||||||||||||||||||||||||
| 312 | 0 | for my $attr (keys(%{$hash})) { | |||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | # if 'segment' | ||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if ($attr eq 'segment') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||
| 317 | # if reference to an array of 'parf' or 'samf' objects | ||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | if (ref($hash->{$attr}) eq 'ARRAY' && @{$hash->{$attr}} == grep {UNIVERSAL::isa($_, 'ICC::Profile::parf') || UNIVERSAL::isa($_, 'ICC::Profile::samf')} @{$hash->{$attr}}) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({UNIVERSAL::isa($_, "ICC::Profile::parf") or UNIVERSAL::isa($_, "ICC::Profile::samf");} @{$$hash{$attr};})
MC/DC0%0/2
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({UNIVERSAL::isa($_, "ICC::Profile::parf") or UNIVERSAL::isa($_, "ICC::Profile::samf");} @{$$hash{$attr};})
ref $hash->{$attr} eq "ARRAY"
@{$hash->{$attr};} == grep({UNIVERSAL::isa($_, "ICC::Profile::parf") or UNIVERSAL::isa($_, "ICC::Profile::samf");} @{$$hash{$attr};})
Truth table0%0/3
A and B
A= ref $hash->{$attr} eq "ARRAY"B= @{$hash->{$attr};} == grep({UNIVERSAL::isa($_, "ICC::Profile::parf") or UNIVERSAL::isa($_, "ICC::Profile::samf");} @{$$hash{$attr};})
| |||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | # set object element | ||||||||||||||||||||||||||||||||
| 321 | 0 | $self->[1] = [@{$hash->{$attr}}]; | |||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||
| 323 | } else { | ||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||
| 325 | # wrong data type | ||||||||||||||||||||||||||||||||
| 326 | 0 | croak('\'curf\' segment attribute must be a reference to an array of \'parf\' or \'samf\' objects'); | |||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | # if 'breakpoint' | ||||||||||||||||||||||||||||||||
| 331 | } elsif ($attr eq 'breakpoint') { | ||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | # if reference to an array of scalars | ||||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if (ref($hash->{$attr}) eq 'ARRAY' && @{$hash->{$attr}} == grep {! ref()} @{$hash->{$attr}}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
MC/DC0%0/2
ref $hash->{$attr} eq "ARRAY" and @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
ref $hash->{$attr} eq "ARRAY"
@{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
Truth table0%0/3
A and B
A= ref $hash->{$attr} eq "ARRAY"B= @{$hash->{$attr};} == grep({not ref $_;} @{$$hash{$attr};})
| |||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||
| 336 | # set object element | ||||||||||||||||||||||||||||||||
| 337 | 0 | $self->[2] = [@{$hash->{$attr}}]; | |||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||
| 339 | } else { | ||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||
| 341 | # wrong data type | ||||||||||||||||||||||||||||||||
| 342 | 0 | croak('\'curf\' breakpoint attribute must be a reference to an array of scalars'); | |||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | # read curf tag from ICC profile | ||||||||||||||||||||||||||||||||
| 353 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||||||
| 354 | sub _readICCcurf { | ||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||
| 356 | # get parameters | ||||||||||||||||||||||||||||||||
| 357 | 0 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_readICCcurf: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||
| 359 | # local variables | ||||||||||||||||||||||||||||||||
| 360 | 0 | my ($buf, $segs, $mark, $class); | |||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||
| 362 | # save tag signature | ||||||||||||||||||||||||||||||||
| 363 | 0 | $self->[0]{'signature'} = $tag->[0]; | |||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||
| 365 | # seek start of tag | ||||||||||||||||||||||||||||||||
| 366 | 0 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||
| 368 | # read tag header | ||||||||||||||||||||||||||||||||
| 369 | 0 | read($fh, $buf, 12); | |||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||
| 371 | # unpack number of segments | ||||||||||||||||||||||||||||||||
| 372 | 0 | $segs = unpack('x8 n x2', $buf); | |||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||
| 374 | # if one segment | ||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | if ($segs == 1) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||
| 377 | # mark file offset | ||||||||||||||||||||||||||||||||
| 378 | 0 | $mark = tell($fh); | |||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | # read segment type signature | ||||||||||||||||||||||||||||||||
| 381 | 0 | read($fh, $buf, 4); | |||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||
| 383 | # if type is 'parf' | ||||||||||||||||||||||||||||||||
| 384 | 0 | ▶ | if ($buf eq 'parf') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||
| 386 | # create object | ||||||||||||||||||||||||||||||||
| 387 | 0 | $self->[1][0] = ICC::Profile::parf->new_fh($self, $fh, ['curf', $mark]); | |||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | } else { | ||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||
| 391 | # error | ||||||||||||||||||||||||||||||||
| 392 | 0 | croak('wrong segment type in \'curf\' tag'); | |||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||
| 396 | # if more than one segment | ||||||||||||||||||||||||||||||||
| 397 | } elsif ($segs > 1) { | ||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||
| 399 | # read breakpoint values | ||||||||||||||||||||||||||||||||
| 400 | 0 | read($fh, $buf, 4 * ($segs - 1)); | |||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||
| 402 | # unpack breakpoint values | ||||||||||||||||||||||||||||||||
| 403 | 0 | $self->[2] = [unpack('f>*', $buf)]; | |||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||
| 405 | # for each segment | ||||||||||||||||||||||||||||||||
| 406 | 0 | for my $i (0 .. $segs - 1) { | |||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | # mark file offset | ||||||||||||||||||||||||||||||||
| 409 | 0 | $mark = tell($fh); | |||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||
| 411 | # read segment type signature | ||||||||||||||||||||||||||||||||
| 412 | 0 | read($fh, $buf, 4); | |||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||
| 414 | # if type is 'parf' or 'samf' | ||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if ($buf eq 'parf' || $buf eq 'samf') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$buf eq "parf" or $buf eq "samf"
MC/DC0%0/2
$buf eq "parf" or $buf eq "samf"
$buf eq "parf"
$buf eq "samf"
Truth table0%0/3
A or B
A= $buf eq "parf"B= $buf eq "samf"
| |||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||
| 417 | # form class specifier | ||||||||||||||||||||||||||||||||
| 418 | 0 | $class = "ICC::Profile::$buf"; | |||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||
| 420 | # create specific tag object | ||||||||||||||||||||||||||||||||
| 421 | 0 | $self->[1][$i] = $class->new_fh($self, $fh, ['curf', $mark]); | |||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | } else { | ||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||
| 425 | # error | ||||||||||||||||||||||||||||||||
| 426 | 0 | croak('unsupported segment type in \'curf\' tag'); | |||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||
| 432 | } else { | ||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||
| 434 | # error | ||||||||||||||||||||||||||||||||
| 435 | 0 | croak('\'curf\' tag has no segments'); | |||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | } | ||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | # write curf tag to ICC profile | ||||||||||||||||||||||||||||||||
| 442 | # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry) | ||||||||||||||||||||||||||||||||
| 443 | sub _writeICCcurf { | ||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||
| 445 | # get parameters | ||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | my ($self, $parent, $fh, $tag) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
_writeICCcurf: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||
| 448 | # verify segments | ||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | (@{$self->[1]} > 0) || carp('\'curf\' object must contain at least one segment'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||
| 451 | # verify breakpoints | ||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | (@{$self->[1]} == @{$self->[2]} + 1) || carp('\'curf\' object must contain a breakpoint between each segment'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||
| 454 | # seek start of tag | ||||||||||||||||||||||||||||||||
| 455 | 0 | seek($fh, $tag->[1], 0); | |||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||
| 457 | # write tag type signature and segment count | ||||||||||||||||||||||||||||||||
| 458 | 0 | print $fh pack('a4 x4 n x2', 'curf', scalar(@{$self->[1]})); | |||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||
| 460 | # write breakpoints | ||||||||||||||||||||||||||||||||
| 461 | 0 | print $fh pack('f>*', @{$self->[2]}); | |||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||
| 463 | # for each segment | ||||||||||||||||||||||||||||||||
| 464 | 0 | for my $seg (@{$self->[1]}) { | |||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||
| 466 | # write segment data | ||||||||||||||||||||||||||||||||
| 467 | 0 | $seg->write_fh($self, $fh, ['curf', tell($fh)]); | |||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||
| 473 | 1 | 1; | |||||||||||||||||||||||||||||||