blib/lib/ICC/Profile/clrt.pm

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