blib/lib/ICC/Profile/clro.pm

filter: Statementstmt 91.5% 65 / 71 Branchbran 44.4% 8 / 18 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.3% 12 / 13 Podpod 16.6% 1 / 6 totaltotal 76.1% 86 / 113 CC 11 SCAR 20.7
CC
11
Cov
79%
sdump
30.0
sequence
3.0
write_fh
2.0
CRAP 7.9
« blib/lib/ICC/Profile/text.pm ↑ Summary Build »
1 package ICC::Profile::clro;
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 clro tag object
19 # parameters: ([ref_to_seq_array])
20 # returns: (ref_to_object)
21 sub new {
22  
23 # get object class
24 2 ▶ my $class = shift();
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
25
26 # create empty clro object
27 2 my $self = [
28 {}, # object header
29 [] # colorant sequence array
30 ];
31  
32 # if parameter supplied
33 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
34
35 # make new clro tag from colorant sequence array
36 1 _newICCclro($self, @_);
37
38 }
39  
40 # bless object
41 2 bless($self, $class);
42
43 # return object reference
44 2 return($self);
45  
46 }
47  
48 # create clro 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 1 ▶ my $class = shift();
Subroutine new_fh: called CC=2 SCAR=7.0
Pod undocumented
55  
56 # create empty clro object
57 1 my $self = [
58 {}, # object header
59 [] # colorant sequence array
60 ];
61  
62 # verify 3 parameters
63 1 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 1 1
64  
65 # read clro data from profile
66 1 _readICCclro($self, @_);
67  
68 # bless object
69 1 bless($self, $class);
70  
71 # return object reference
72 1 return($self);
73  
74 }
75  
76 # writes clro 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 1 ▶ my $self = shift();
Subroutine write_fh: called CC=2 SCAR=7.1
Pod undocumented
82  
83 # verify 3 parameters
84 1 ▶ (@_ == 3) || croak('wrong number of parameters');
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 or croak("wrong number of parameters") 0 1 1
85  
86 # write clro data to profile
87 1 _writeICCclro($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]});
100  
101 }
102  
103 # get/set colorant sequence
104 # parameters: ([ref_to_seq_array])
105 # returns: (ref_to_seq_array)
106 sub sequence {
107  
108 # get object reference
109 2 ▶ my $self = shift();
Subroutine sequence: called CC=3 SCAR=11.0
Pod undocumented
110
111 # if parameter supplied
112 2 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 1 2
113
114 # get ref to sequence array
115 1 my $seq = shift();
116
117 # initialize counter
118 1 my $i = 0;
119  
120 # verify sequence array
121 1 ▶ (@{$seq} == grep {$_ == $i++} sort {$a <=> $b} @{$seq}) || croak('bad sequence array');
Branch: 1 branch
BranchTrueFalseTotal
@{$seq;} == grep({$_ == $i++;} (sort {$a <=> $b;} @{$seq;})) or croak("bad sequence array") 0 1 1
122  
123 # save array
124 1 $self->[1] = $seq;
125
126 }
127
128 # return text string
129 2 return($self->[1]);
130  
131 }
132  
133 # print object contents to string
134 # format is an array structure
135 # parameter: ([format])
136 # returns: (string)
137 sub sdump {
138  
139 # get parameters
140 0 ▶ my ($self, $p) = @_;
Subroutine sdump: not called CC=5 SCAR=34.0
Pod documented
141  
142 # local variables
143 0 my ($s, $fmt);
144  
145 # resolve parameter to an array reference
146 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
147  
148 # get format string
149 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
150  
151 # set string to object ID
152 0 $s = sprintf("'%s' object, (0x%x)\n", ref($self), $self);
153  
154 # return
155 0 return($s);
156  
157 }
158  
159 # make new clro tag from colorant sequence array
160 # parameters: (ref_to_object, ref_to_seq_array)
161 sub _newICCclro {
162  
163 # get parameters
164 1 ▶ my ($self, $seq) = @_;
Subroutine _newICCclro: called CC=2 SCAR=6.9
165  
166 # initialize counter
167 1 my $i = 0;
168  
169 # verify sequence array
170 1 ▶ (@{$seq} == grep {$_ == $i++} sort {$a <=> $b} @{$seq}) || croak('bad sequence array');
Branch: 1 branch
BranchTrueFalseTotal
@{$seq;} == grep({$_ == $i++;} (sort {$a <=> $b;} @{$seq;})) or croak("bad sequence array") 0 1 1
171  
172 # copy array
173 1 $self->[1] = [@{$seq}];
174  
175 }
176  
177 # read clro tag from ICC profile
178 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
179 sub _readICCclro {
180  
181 # get parameters
182 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _readICCclro: called CC=1 SCAR=0.0
183  
184 # local variables
185 1 my ($buf, $cnt);
186  
187 # save tag signature
188 1 $self->[0]{'signature'} = $tag->[0];
189  
190 # seek start of tag
191 1 seek($fh, $tag->[1], 0);
192
193 # read tag type signature and colorant count
194 1 read($fh, $buf, 12);
195  
196 # unpack colorant count
197 1 $cnt = unpack('x8 N', $buf);
198  
199 # read colorant array
200 1 read($fh, $buf, $cnt);
201  
202 # unpack colorant array
203 1 $self->[1] = [unpack('C*', $buf)];
204  
205 }
206  
207 # write clro tag to ICC profile
208 # parameters: (ref_to_object, ref_to_parent_object, file_handle, ref_to_tag_table_entry)
209 sub _writeICCclro {
210  
211 # get parameters
212 1 ▶ my ($self, $parent, $fh, $tag) = @_;
Subroutine _writeICCclro: called CC=1 SCAR=0.0
213  
214 # seek start of tag
215 1 seek($fh, $tag->[1], 0);
216  
217 # write tag
218 1 print $fh pack('a4 x4 N C*', 'clro', scalar(@{$self->[1]}), @{$self->[1]});
219  
220 }
221  
222 2 1;
« blib/lib/ICC/Profile/text.pm ↑ Summary Build »