blib/lib/ICC/Profile/clrt.pm

filter: Statementstmt 32.9% 28 / 85 Branchbran 14.2% 4 / 28 Conditioncond 0.0% 0 / 24 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 53.8% 7 / 13 Podpod 16.6% 1 / 6 totaltotal 23.8% 40 / 168 CC 27 SCAR 47.6
CC
27
Cov
23%
_newICCclrt
272.0
sdump
30.0
new_fh
6.0
CRAP 117.1
« blib/lib/ICC/Profile/cvst.pm ↑ Summary blib/lib/ICC/Profile/para.pm »
1 package ICC::Profile::clrt;
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 clrt tag object
19 # parameters: ([ref_to_A2B1_tag, [ref_to_array_of_colorant_names]])
20 # returns: (ref_to_object)
21 sub new {
22  
23 # get object class
24 1 ▶ my $class = shift();
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
25
26 # create empty clrt object
27 1 my $self = [
28 {}, # object header
29 [] # colorant array
30 ];
31  
32 # if parameter supplied
33 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
34
35 # new colorant tag from xCLR A2B1 tag
36 0 _newICCclrt($self, @_);
37
38 }
39  
40 # bless object
41 1 bless($self, $class);
42
43 # return object reference
44 1 return($self);
45  
46 }
47  
48 # create clrt 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 ▶ my $class = shift();
Subroutine new_fh: not called CC=2 SCAR=17.9
Pod undocumented
55  
56 # create empty clrt object
57 0 my $self = [
58 {}, # object header
59 [] # colorant array
60 ];
61  
62 # verify 3 parameters
63 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
64  
65 # read clrt data from profile
66 0 _readICCclrt($self, @_);
67  
68 # bless object
69 0 bless($self, $class);
70  
71 # return object reference
72 0 return($self);
73  
74 }
75  
76 # writes clrt tag object to ICC profile
77 # parameters: (ref_to_parent_object, file_handle, ref_to_tag_table_entry)
78 sub write_fh {
79  
80 # get tag reference
81 0 ▶ my $self = shift();
Subroutine write_fh: not called CC=2 SCAR=17.9
Pod undocumented
82  
83 # verify 3 parameters
84 0 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 0 0
85  
86 # write text data to profile
87 0 _writeICCclrt($self, @_);
88  
89 }
90  
91 # get tag size (for writing to profile)
92 # returns: (tag_size)
93 sub size {
94
95 # get parameters
96 1 ▶ my ($self) = @_;
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
97
98 # return size
99 1 return(12 + @{$self->[1]} * 38);
100
101 }
102  
103 # get colorant table entry reference(s)
104 # parameters: (channel)
105 # returns: (ref_to_color_table_entry)
106 # parameters: (list_of_channels)
107 # returns: (list_of_refs_to_color_table_entries)
108 sub channel {
109  
110 # get object reference
111 2 ▶ my $self = shift();
Subroutine channel: called CC=3 SCAR=11.0
Pod undocumented
112
113 # if parameters
114 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 0 2
115
116 # if list is wanted
117 2 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 1 2
118
119 # return list of colorant table references
120 1 return(map {$self->[1][$_]} @_);
121
122 # single value wanted
123 } else {
124
125 # return single colorant table reference
126 1 return($self->[1][$_[0]]);
127
128 }
129
130 }
131
132 }
133  
134 # print object contents to string
135 # format is an array structure
136 # parameter: ([format])
137 # returns: (string)
138 sub sdump {
139  
140 # get parameters
141 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
142  
143 # local variables
144 0 my ($s, $fmt);
145  
146 # resolve parameter to an array reference
147 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
148  
149 # get format string
150 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
151  
152 # set string to object ID
153 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
154  
155 # return
156 0 return($s);
157  
158 }
159  
160 # new colorant tag from xCLR A2B1 tag
161 # parameters: (ref_to_object, ref_to_A2B1_tag, [ref_to_array_of_colorant_names])
162 sub _newICCclrt {
163
164 # get parameters
165 0 ▶ my ($self, $tag, $name) = @_;
Subroutine _newICCclrt: not called CC=16 SCAR=56.1
166
167 # local variables
168 0 my ($type, $csi, $cso);
169 0 my ($cnt, $max, @in, @out);
170
171 # get tag type
172 0 $type = ref($tag);
173
174 # get input colorspace
175 0 $csi = $tag->[0]{'input_cs'};
176
177 # get output colorspace
178 0 $cso = $tag->[0]{'output_cs'};
179
180 # if allowable tag type
181 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
182 ($csi =~ m|^([2-9A-F])CLR$|) && ($cso eq 'Lab ' || $cso eq 'XYZ ')) {
183
184 # get count from match
185 0 $cnt = hex($1);
186
187 # get maximum colorant value
188 0 ▶ $max = $type eq 'ICC::Profile::mft1' ? 255 : 65535;
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'ICC::Profile::mft1' ? : 0 0 0
189
190 # set transform mask
191 0 $tag->[6] = 0x0f;
192
193 # for each colorant
194 0 for my $i (0 .. $cnt - 1) {
195
196 # for each input
197 0 for my $j (0 .. $cnt - 1) {
198
199 # set input
200 0 ▶ $in[$j] = $i == $j ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i == $j ? : 0 0 0
201
202 }
203
204 # if name array supplied
205 0 ▶ if (defined($name->[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name->[$i]) { } 0 0 0
206
207 # set the colorant name
208 0 $self->[1][$i][0] = $name->[$i];
209
210 } else {
211
212 # set the colorant name
213 0 $self->[1][$i][0] = sprintf('colorant_%x', $i + 1);
214
215 }
216
217 # transform color value
218 0 @{$self->[1][$i]}[1 .. 3] = map {$_ * $max} $tag->transform(@in);
219
220 }
221
222 # set the PCS ('Lab ' or 'XYZ ')
223 0 $self->[0]{'pcs'} = $cso;
224
225 # set the output bit depth
226 0 ▶ $self->[0]{'output_bits'} = ($cso eq 'Lab ' && $type eq 'ICC::Profile::mft1') ? 8 : 16;
Branch: 1 branch
BranchTrueFalseTotal
$cso eq 'Lab ' && $type eq 'ICC::Profile::mft1' ? : 0 0 0
Condition0%0/3
$cso eq "Lab " and $type eq "ICC::Profile::mft1"
!ll&&!rl&&r
000
MC/DC0%0/2
$cso eq "Lab " and $type eq "ICC::Profile::mft1"
$cso eq "Lab " $type eq "ICC::Profile::mft1"
Truth table0%0/3
A and B
A= $cso eq "Lab "B= $type eq "ICC::Profile::mft1"
ABresult
0X0
100
111
227
228 # set the 16-bit Lab legacy flag
229 0 ▶ $self->[0]{'legacy'} = ($cso eq 'Lab ' && $type eq 'ICC::Profile::mft2') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cso eq 'Lab ' && $type eq 'ICC::Profile::mft2' ? : 0 0 0
Condition0%0/3
$cso eq "Lab " and $type eq "ICC::Profile::mft2"
!ll&&!rl&&r
000
MC/DC0%0/2
$cso eq "Lab " and $type eq "ICC::Profile::mft2"
$cso eq "Lab " $type eq "ICC::Profile::mft2"
Truth table0%0/3
A and B
A= $cso eq "Lab "B= $type eq "ICC::Profile::mft2"
ABresult
0X0
100
111
230
231 } else {
232
233 # message
234 0 carp('wrong tag type');
235
236 }
237
238 }
239  
240 # read clrt tag from ICC profile
241 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
242 sub _readICCclrt {
243  
244 # get parameters
245 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCclrt: not called CC=2 SCAR=17.9
246  
247 # local variables
248 0 my ($buf, $cnt);
249  
250 # save tag signature
251 0 $self->[0]{'signature'} = $tag->[0];
252  
253 # save profile connection space ('Lab ' or 'XYZ ')
254 0 $self->[0]{'pcs'} = $parent->[1][5];
255  
256 # seek start of tag
257 0 seek($fh, $tag->[1], 0);
258  
259 # read signature and color count
260 0 read($fh, $buf, 12);
261  
262 # unpack colorant count
263 0 $cnt = unpack('x8 N', $buf);
264  
265 # for each colorant
266 0 for my $i (0 .. $cnt - 1) {
267
268 # read colorant record
269 0 read($fh, $buf, 38);
270
271 # unpack colorant values
272 0 $self->[1][$i] = [unpack('Z32 n3', $buf)];
273
274 }
275
276 }
277  
278 # write clrt tag to ICC profile
279 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
280 sub _writeICCclrt {
281  
282 # get parameters
283 0 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCclrt: not called CC=2 SCAR=17.9
284  
285 # seek start of tag
286 0 seek($fh, $tag->[1], 0);
287  
288 # write type signature and colorant count
289 0 print $fh pack('a4 x4 N', 'clrt', scalar(@{$self->[1]}));
290  
291 # for each colorant record
292 0 for my $rec (@{$self->[1]}) {
293
294 # write colorant values
295 0 print $fh pack('Z32 n3', @{$rec});
296
297 }
298
299 }
300  
301 2 1;
« blib/lib/ICC/Profile/cvst.pm ↑ Summary blib/lib/ICC/Profile/para.pm »