blib/lib/ICC/Profile/ncl2.pm

filter: Statementstmt 11.4% 14 / 122 Branchbran 0.0% 0 / 38 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 30.7% 4 / 13 Podpod 16.6% 1 / 6 totaltotal 8.4% 19 / 224 CC 36 SCAR 42.5
CC
36
Cov
7%
_newICCncl2
182.0
array
56.0
_writeICCncl2
42.0
CRAP 70.0
« blib/lib/ICC/Profile/parf.pm ↑ Summary lib/ICC/Profile/mft2.pm »
1 package ICC::Profile::ncl2;
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 # create new ncl2 tag object
19 # parameters: ()
20 # parameters: (ref_to_color_table_array)
21 # parameters: (ref_to_A2B1_tag, [ref_to_array_of_colorant_names])
22 # returns: (ref_to_object)
23 sub new {
24  
25 # get object class
26 0 ▶ my $class = shift();
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
27  
28 # create empty ncl2 object
29 0 my $self = [
30 {}, # object header
31 [] # colorant array
32 ];
33  
34 # if parameter supplied
35 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
36
37 # if first parameter is an array or matrix
38 0 ▶ if (ref($_[0]) eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY' or UNIVERSAL::isa($_[0], 'Math::Matrix')) { } 0 0 0
Condition0%0/3
ref $_[0] eq "ARRAY" or UNIVERSAL::isa($_[0], "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq "ARRAY" or UNIVERSAL::isa($_[0], "Math::Matrix")
ref $_[0] eq "ARRAY" UNIVERSAL::isa($_[0], "Math::Matrix")
Truth table0%0/3
A or B
A= ref $_[0] eq "ARRAY"B= UNIVERSAL::isa($_[0], "Math::Matrix")
ABresult
1X1
011
000
39
40 # get array reference
41 0 my $array = shift();
42
43 # for each row
44 0 for my $i (0 .. $#{$array}) {
45
46 # copy to object
47 0 $self->[1][$i] = [@{$array->[$i]}];
48
49 }
50
51 } else {
52
53 # add color table from A2B1 tag
54 0 _newICCncl2($self, @_);
55
56 }
57
58 }
59  
60 # bless object
61 0 bless($self, $class);
62  
63 # return object reference
64 0 return($self);
65  
66 }
67  
68 # create ncl2 tag object from ICC profile
69 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
70 # returns: (ref_to_object)
71 sub new_fh {
72  
73 # get object class
74 0 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
75  
76 # create empty ncl2 object
77 0 my $self = [
78 {}, # object header
79 [] # colorant array
80 ];
81  
82 # verify 3 parameters
83 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
84  
85 # read ncl2 data from profile
86 0 _readICCncl2($self, @_);
87  
88 # bless object
89 0 bless($self, $class);
90  
91 # return object reference
92 0 return($self);
93  
94 }
95  
96 # writes ncl2 tag object to ICC profile
97 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
98 sub write_fh {
99  
100 # get tag reference
101 0 ▶ my $self = shift();
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
102  
103 # verify 3 parameters
104 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
105  
106 # write text data to profile
107 0 _writeICCncl2($self, @_);
108  
109 }
110  
111 # get tag size (for writing to profile)
112 # returns: (tag_size)
113 sub size {
114  
115 # get parameters
116 0 ▶ my ($self) = @_;
Subroutine size: not called CC=2 SCAR=17.9
Pod undocumented
117  
118 # return size
119 0 ▶ return(@{$self->[1]} ? 84 + @{$self->[1]} * (30 + @{$self->[1][0]} * 2) : 84);
Branch: 1 branch
BranchTrueFalseTotal
@{$self->[1];} ? : 0 0 0
120  
121 }
122  
123 # get/set named color array
124 # each row contains name, PCS values, and optional device values
125 # all value are 16-bit (0 - 65563)
126 # parameters: ([array_reference])
127 # returns: (array_reference)
128 sub array {
129  
130 # get object reference
131 0 ▶ my $self = shift();
Subroutine array: not called CC=7 SCAR=40.3
Pod undocumented
132  
133 # if parameters
134 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
135
136 # if one parameter, a single array reference or Math::Matrix object
137 0 ▶ if (@_ == 1 && (ref($_[0]) eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'ARRAY' || UNIVERSAL::isa($_[0], 'Math::Matrix')) { } 0 0 0
Condition0%0/6
@_ == 1 and ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix")
!ll&&!rl&&r
000
ref $_[0] eq "ARRAY" or UNIVERSAL::isa($_[0], "Math::Matrix")
l!l&&r!l&&!r
000
MC/DC0%0/3
@_ == 1 and ref $_[0] eq "ARRAY" || UNIVERSAL::isa($_[0], "Math::Matrix")
@_ == 1 ref $_[0] eq "ARRAY" UNIVERSAL::isa($_[0], "Math::Matrix")
Truth table0%0/4
A and B or C
A= @_ == 1B= ref $_[0] eq "ARRAY"C= UNIVERSAL::isa($_[0], "Math::Matrix")
ABCresult
0XX0
1000
11X1
1011
138
139 # get array reference
140 0 my $array = shift();
141
142 # initialize data array
143 0 $self->[1] = [];
144
145 # if array is not empty
146 0 ▶ if (@{$array}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$array;}) 0 0 0
147
148 # for each row
149 0 for my $i (0 .. $#{$array}) {
150
151 # copy to object
152 0 $self->[1][$i] = [@{$array->[$i]}];
153
154 }
155
156 }
157
158 } else {
159
160 # error
161 0 croak('parameter must be an array reference');
162
163 }
164
165 }
166  
167 # return color table reference
168 0 return($self->[1]);
169  
170 }
171  
172 # print object contents to string
173 # format is an array structure
174 # parameter: ([format])
175 # returns: (string)
176 sub sdump {
177  
178 # get parameters
179 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
180  
181 # local variables
182 0 my ($s, $fmt);
183  
184 # resolve parameter to an array reference
185 0 ▶ $p = defined($p) ? ref($p) eq 'ARRAY' ? $p : [$p] : [];
Branch: 2 branches
BranchTrueFalseTotal
defined $p ? : 0 0 0
ref $p eq 'ARRAY' ? : 0 0 0
186  
187 # get format string
188 0 ▶ $fmt = defined($p->[0]) && ! ref($p->[0]) ? $p->[0] : 'undef';
Branch: 1 branch
BranchTrueFalseTotal
defined $p->[0] && !ref($p->[0]) ? : 0 0 0
Condition0%0/3
defined $p->[0] and not ref $p->[0]
!ll&&!rl&&r
000
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]
ABresult
0X0
100
111
189  
190 # set string to object ID
191 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
192  
193 # return
194 0 return($s);
195  
196 }
197  
198 # new colorant tag from nCLR A2B1 tag
199 # parameters: (ref_to_object, ref_to_A2B1_tag, [ref_to_array_of_colorant_names])
200 sub _newICCncl2 {
201  
202 # get parameters
203 0 ▶ my ($self, $tag, $name) = @_;
Subroutine _newICCncl2: not called CC=13 SCAR=52.0
204  
205 # local variables
206 0 my ($type, $csi, $cso);
207 0 my ($cnt, @in, @out);
208  
209 # get tag type
210 0 $type = ref($tag);
211  
212 # get input colorspace
213 0 $csi = $tag->[0]{'input_cs'};
214  
215 # get output colorspace
216 0 $cso = $tag->[0]{'output_cs'};
217  
218 # if allowable tag type
219 0 ▶ if (($type eq 'ICC::Profile::mft1' || $type eq 'ICC::Profile::mft2' || $type eq 'ICC::Profile::mAB_') &&
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'ICC::Profile::mft1' || $type eq 'ICC::Profile::mft2' || $type eq 'ICC::Profile::mAB_' and $csi =~ /^([2-9A-F])CLR$/ and $cso eq 'Lab ' || $cso eq 'XYZ ') { } 0 0 0
Condition0%0/15
$type eq "ICC::Profile::mft1" || $type eq "ICC::Profile::mft2" || $type eq "ICC::Profile::mAB_" and $csi =~ /^([2-9A-F])CLR$/ and $cso eq "Lab " || $cso eq "XYZ "
!ll&&!rl&&r
000
$type eq "ICC::Profile::mft1" || $type eq "ICC::Profile::mft2" || $type eq "ICC::Profile::mAB_" and $csi =~ /^([2-9A-F])CLR$/
!ll&&!rl&&r
000
$type eq "ICC::Profile::mft1" or $type eq "ICC::Profile::mft2" or $type eq "ICC::Profile::mAB_"
l!l&&r!l&&!r
000
$type eq "ICC::Profile::mft1" or $type eq "ICC::Profile::mft2"
l!l&&r!l&&!r
000
$cso eq "Lab " or $cso eq "XYZ "
l!l&&r!l&&!r
000
MC/DC0%0/6
$type eq "ICC::Profile::mft1" || $type eq "ICC::Profile::mft2" || $type eq "ICC::Profile::mAB_" and $csi =~ /^([2-9A-F])CLR$/ and $cso eq "Lab " || $cso eq "XYZ "
$type eq "ICC::Profile::mft1" $type eq "ICC::Profile::mft2" $type eq "ICC::Profile::mAB_" $csi =~ /^([2-9A-F])CLR$/ $cso eq "Lab " $cso eq "XYZ "
Truth table0%0/13
A or B or C and D and E or F
A= $type eq "ICC::Profile::mft1"B= $type eq "ICC::Profile::mft2"C= $type eq "ICC::Profile::mAB_"D= $csi =~ /^([2-9A-F])CLR$/E= $cso eq "Lab "F= $cso eq "XYZ "
ABCDEFresult
000XXX0
1XX0XX0
01X0XX0
0010XX0
1XX1000
01X1000
0011000
1XX11X1
1XX1011
01X11X1
01X1011
00111X1
0011011
220 ($csi =~ m|^([2-9A-F])CLR$|) && ($cso eq 'Lab ' || $cso eq 'XYZ ')) {
221
222 # get count from match
223 0 $cnt = hex($1);
224
225 # set transform mask
226 0 $tag->[6] = 0x0f;
227
228 # for each colorant
229 0 for my $i (0 .. $cnt - 1) {
230
231 # for each input
232 0 for my $j (0 .. $cnt - 1) {
233
234 # set input
235 0 ▶ $in[$j] = $i == $j ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i == $j ? : 0 0 0
236
237 }
238
239 # if name array supplied
240 0 ▶ if (defined($name->[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name->[$i]) { } 0 0 0
241
242 # set the colorant name
243 0 $self->[1][$i][0] = $name->[$i];
244
245 } else {
246
247 # set the colorant name
248 0 $self->[1][$i][0] = sprintf('colorant_%x', $i + 1);
249
250 }
251
252 # if tag type is 'mft2' or colorspace is 'XYZ '
253 0 ▶ if ($type eq 'ICC::Profile::mft2' || $cso eq 'XYZ ') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'ICC::Profile::mft2' or $cso eq 'XYZ ') { } 0 0 0
Condition0%0/3
$type eq "ICC::Profile::mft2" or $cso eq "XYZ "
l!l&&r!l&&!r
000
MC/DC0%0/2
$type eq "ICC::Profile::mft2" or $cso eq "XYZ "
$type eq "ICC::Profile::mft2" $cso eq "XYZ "
Truth table0%0/3
A or B
A= $type eq "ICC::Profile::mft2"B= $cso eq "XYZ "
ABresult
1X1
011
000
254
255 # transform to PCS (legacy 16-bit Lab or XYZ)
256 0 @{$self->[1][$i]}[1 .. 3] = map {$_ * 65535} $tag->transform(@in);
257
258 } else {
259
260 # transform to PCS and convert to legacy 16-bit Lab
261 0 @{$self->[1][$i]}[1 .. 3] = map {$_ * 65280} $tag->transform(@in);
262
263 }
264
265 # push the device values (always 16-bit)
266 0 push(@{$self->[1][$i]}, map {$_ * 65535} @in);
267
268 }
269
270 # set pcs
271 0 $self->[0]{'pcs'} = $cso;
272
273 # set data color space
274 0 $self->[0]{'dcs'} = $csi;
275
276 # set flags
277 0 $self->[0]{'vsflag'} = 0;
278
279 # set prefix
280 0 $self->[0]{'prefix'} = '';
281
282 # set suffix
283 0 $self->[0]{'suffix'} = '';
284
285 } else {
286
287 # message
288 0 carp('wrong tag type');
289
290 }
291
292 }
293  
294 # read ncl2 tag from ICC profile
295 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
296 sub _readICCncl2 {
297  
298 # get parameters
299 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCncl2: not called CC=2 SCAR=17.9
300  
301 # local variables
302 0 my ($buf, $cnt, $dvc, $rsz, $fmt);
303  
304 # save tag signature
305 0 $self->[0]{'signature'} = $tag->[0];
306  
307 # save data color space
308 0 $self->[0]{'dcs'} = $parent->[1][4];
309  
310 # save profile connection space ('Lab ' or 'XYZ ')
311 0 $self->[0]{'pcs'} = $parent->[1][5];
312  
313 # seek start of tag
314 0 seek($fh, $tag->[1], 0);
315  
316 # read tag header
317 0 read($fh, $buf, 84);
318  
319 # unpack header
320 0 ($self->[0]{'vsflag'}, $cnt, $dvc, $self->[0]{'prefix'}, $self->[0]{'suffix'}) = unpack('x8 N3 Z32 Z32', $buf);
321  
322 # adjust device color count to include PCS
323 0 $dvc += 3;
324  
325 # set record size
326 0 $rsz = 32 + 2 * $dvc;
327  
328 # set unpack format
329 0 $fmt = "Z32n$dvc";
330  
331 # for each named color
332 0 for my $i (0 .. $cnt - 1) {
333
334 # read record
335 0 read($fh, $buf, $rsz);
336
337 # unpack color name, PCS and device values
338 0 $self->[1][$i] = [unpack($fmt, $buf)];
339
340 }
341
342 }
343  
344 # write ncl2 tag to ICC profile
345 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
346 sub _writeICCncl2 {
347  
348 # get parameters
349 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCncl2: not called CC=6 SCAR=37.4
350  
351 # local variables
352 0 my ($vsflag, $prefix, $suffix);
353 0 my ($cnt, $dvc, $fmt);
354  
355 # get vsflag, prefix and suffix using defaults if undefined
356 0 ▶ $vsflag = defined($self->[0]{'vsflag'}) ? $self->[0]{'vsflag'} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[0]{'vsflag'} ? : 0 0 0
357 0 ▶ $prefix = defined($self->[0]{'prefix'}) ? $self->[0]{'prefix'} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[0]{'prefix'} ? : 0 0 0
358 0 ▶ $suffix = defined($self->[0]{'suffix'}) ? $self->[0]{'suffix'} : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->[0]{'suffix'} ? : 0 0 0
359  
360 # get count from array size
361 0 $cnt = @{$self->[1]};
362  
363 # get device colors from array size
364 0 ▶ $dvc = @{$self->[1]} ? @{$self->[1][0]} - 4 : 0;
Branch: 1 branch
BranchTrueFalseTotal
@{$self->[1];} ? : 0 0 0
365  
366 # seek start of tag
367 0 seek($fh, $tag->[1], 0);
368  
369 # write header
370 0 print $fh pack('a4 x4 N3 Z32 Z32', 'ncl2', $vsflag, $cnt, $dvc, $prefix, $suffix);
371  
372 # make pack format
373 0 $fmt = 'Z32n' . ($dvc + 3);
374  
375 # for each named color
376 0 for my $rec (@{$self->[1]}) {
377
378 # write color name, pcs and device values
379 0 print $fh pack($fmt, @{$rec});
380
381 }
382
383 }
384  
385 2 1;
« blib/lib/ICC/Profile/parf.pm ↑ Summary lib/ICC/Profile/mft2.pm »