DataMatrix/Engine.pm

filter: Statementstmt 74.1% 389 / 525 Branchbran 58.7% 168 / 286 Conditioncond 44.7% 68 / 152 MC/DCmcdc 17.4% 15 / 86 Subroutinesub 94.8% 37 / 39 Podpod 100% 31 / 31 totaltotal 63.2% 708 / 1119 CC 207 SCAR 40.6
CC
207
Cov
65%
SelectEncoding
129.8
DetectEncoding
108.0
EncodeASCII
107.8
CRAP 58.1
↑ Summary DataMatrix/CharDataFiller.pm »
1 package Barcode::DataMatrix::Engine;
2  
3 =head1 Barcode::DataMatrix::Engine
4  
5 The engine which generates the data matrix bitmap.
6  
7 =cut
8  
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Barcode::DataMatrix::Reed;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Barcode::DataMatrix::Constants ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Barcode::DataMatrix::CharDataFiller ();
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Data::Dumper;$Data::Dumper::Useqq = 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head2 DEBUG
18  
19 Turn on/off general debugging information.
20  
21 =cut
22  
23 2 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 our %DEBUG = (
26 ENC => 0,
27 EAUTO => 0,
28 CALC => 0,
29 TRACE => 0,
30 B256 => 0
31 );
32 2 our (@FORMATS,@C1);
33  
34 2 *FORMATS = \@Barcode::DataMatrix::Constants::FORMATS;
35 2 *C1 = \@Barcode::DataMatrix::Constants::C1;
36  
37 =head2 E_ASCII
38  
39 Represent the ASCII encoding type.
40  
41 =cut
42  
43 126 ▶sub E_ASCII { 0 }
Subroutine E_ASCII: called CC=1 SCAR=0.0
Pod documented
44  
45 =head2 E_C40
46  
47 Represent the C40 encoding type. (upper case alphanumeric)
48  
49 =cut
50  
51 380 ▶sub E_C40 { 1 }
Subroutine E_C40: called CC=1 SCAR=0.0
Pod documented
52  
53 =head2 E_TEXT
54  
55 Represent the TEXT encoding type. (lower case alphanumeric)
56  
57 =cut
58  
59 156 ▶sub E_TEXT { 2 }
Subroutine E_TEXT: called CC=1 SCAR=0.0
Pod documented
60  
61 =head2 E_BASE256
62  
63 Represent the BASE256 encoding type.
64  
65 =cut
66  
67 78 ▶sub E_BASE256 { 3 }
Subroutine E_BASE256: called CC=1 SCAR=0.0
Pod documented
68  
69 =head2 E_NONE
70  
71 Represent the when there is no encoding type.
72  
73 =cut
74  
75 8 ▶sub E_NONE { 4 }
Subroutine E_NONE: called CC=1 SCAR=0.0
Pod documented
76  
77 =head2 E_AUTO
78  
79 Represent the when the encoding type is automatically set.
80  
81 =cut
82  
83 28 ▶sub E_AUTO { 5 }
Subroutine E_AUTO: called CC=1 SCAR=0.0
Pod documented
84  
85 2 our $N = 255;
86  
87 =head2 Types
88  
89 Return a list of encoding types.
90  
91 =cut
92  
93 sub Types {
94 12 ▶ return qw( ASCII C40 TEXT BASE256 NONE AUTO );
Subroutine Types: called CC=1 SCAR=0.0
Pod documented
95 }
96  
97 =head2 stringToType (type_name)
98  
99 Return the integer representing the type from the type name.
100  
101 =cut
102  
103 sub stringToType {
104 54 ▶ my $m = 'E_'.shift;
Subroutine stringToType: called CC=1 SCAR=0.0
Pod documented
105 54 return eval { __PACKAGE__->$m(); };
106 }
107  
108 =head2 typeToString (type_integer)
109  
110 Return the type name from the integer representing the type.
111  
112 =cut
113  
114 sub typeToString {
115 12 ▶ my $i = shift;
Subroutine typeToString: called CC=4 SCAR=14.3
Pod documented
116 12 for (Types) {
117 42 ▶ return $_ if stringToType($_) == $i and defined $i;
Branch: 1 branch
BranchTrueFalseTotal
if stringToType($_) == $i and defined $i 12 30 42
Condition66%2/3
stringToType($_) == $i and defined $i
!ll&&!rl&&r
30012
MC/DC50%1/2
stringToType($_) == $i and defined $i
stringToType($_) == $i defined $i
Truth table66%2/3
A and B
A= stringToType($_) == $iB= defined $i
ABresult
0X0
100
111
118 }
119 0 return 'UNK';
120 }
121  
122 2 our @encName = map { typeToString $_ } 0..5;
123  
124 =head2 stringToFormat (format_string)
125  
126 Convert a "width x height" format string into an internal format specification.
127  
128 =cut
129  
130 sub stringToFormat {
131 12 ▶ my $sz = shift;
Subroutine stringToFormat: called CC=6 SCAR=32.9
Pod documented
132 12 ▶ return unless $sz;
Branch: 1 branch
BranchTrueFalseTotal
unless $sz 12 0 12
133 0 my ($w,$h) = map { +int } split /\s*x\s*/,$sz,2;
134 0 my $r;
135 0 for my $i (0..$#FORMATS) {
136 0 ▶ $r = $i,last if $FORMATS[$i][0] == $w and $FORMATS[$i][1] == $h;
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::FORMATS[$i][0] == $w and $Barcode::DataMatrix::Engine::FORMATS[$i][1] == $h 0 0 0
Condition0%0/3
$Barcode::DataMatrix::Engine::FORMATS[$i][0] == $w and $Barcode::DataMatrix::Engine::FORMATS[$i][1] == $h
!ll&&!rl&&r
000
MC/DC0%0/2
$Barcode::DataMatrix::Engine::FORMATS[$i][0] == $w and $Barcode::DataMatrix::Engine::FORMATS[$i][1] == $h
$Barcode::DataMatrix::Engine::FORMATS[$i][0] == $w $Barcode::DataMatrix::Engine::FORMATS[$i][1] == $h
Truth table0%0/3
A and B
A= $Barcode::DataMatrix::Engine::FORMATS[$i][0] == $wB= $Barcode::DataMatrix::Engine::FORMATS[$i][1] == $h
ABresult
0X0
100
111
137 }
138 0 ▶ die "Format not supported ($sz)\n" unless defined $r;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $r 0 0 0
139 0 return $r;
140 }
141  
142 =head2 setType (type_name)
143  
144 Set the encoding type from the given type name.
145  
146 =cut
147  
148 sub setType {
149 12 ▶ my $self = shift;
Subroutine setType: called CC=4 SCAR=14.2
Pod documented
150 12 my $type = shift;
151 12 my $t = stringToType($type);
152 12 ▶ warn "setType $type => $t\n" if $DEBUG{ENC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"ENC"} 0 12 12
153 12 ▶ $t = E_ASCII unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 12 12
154 12 $self->{encoding} = $self->{currentEncoding} = $t;
155 12 ▶ warn "Have type $t (".typeToString($t).")\n" if $DEBUG{ENC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"ENC"} 0 12 12
156 12 return;
157 }
158  
159 =head2 new
160  
161 Construct a C<Barcode::DataMatrix::Engine> object.
162  
163 =cut
164  
165 sub new {
166 12 ▶ my $self = bless{},shift;
Subroutine new: called CC=5 SCAR=16.4
Pod documented
167 12 $self->init();
168 12 ▶ warn "[CA] new(@_)\n" if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 12 12
169 12 $self->{orig} = $self->{code} = shift; # text
170 12 $self->setType(shift); # type of encoding
171 12 ▶ $self->{preferredFormat} = stringToFormat(shift) || -1; # type of format
Condition50%1/2
stringToFormat(shift()) || -1
l!l
012
MC/DC0%0/1
stringToFormat(shift()) || -1
stringToFormat(shift())
Truth table50%1/2
A
A= stringToFormat(shift())
Aresult
11
00
172 12 $self->{as} = [ ]; # additional streams
173 12 ▶ $self->ProcessTilde if (shift); # process tilde
Branch: 1 branch
BranchTrueFalseTotal
if shift() 0 12 12
174 12 ▶ return unless ( my $l = length($self->{code}) ); # no data to encode
Branch: 1 branch
BranchTrueFalseTotal
unless my $l = length $self->{"code"} 0 12 12
175 12 $self->{ac} = [ split //,$self->{code} ]; # create an char array
176 12 $self->{ai} = [ map { +ord } @{ $self->{ac} } ]; # create an int array
177 12 $self->CreateBitmap();
178 12 return $self;
179 }
180  
181 =head2 init
182  
183 Initialize some of the basic C<Barcode::DataMatrix::Engine> data.
184  
185 =cut
186  
187 sub init {
188 12 ▶ my $self = shift;
Subroutine init: called CC=2 SCAR=6.9
Pod documented
189 12 my %p = (
190 processTilde => 0,#0
191 encoding => E_ASCII,
192 preferredFormat => -1,
193 currentEncoding => E_ASCII,
194 C49rest => 0,
195 );
196 12 for (keys %p){
197 60 $self->{$_} = $p{$_};
198 }
199 }
200  
201 =head2 ProcessTilde
202  
203 Handle special or control characters, which are prefixed by a tilde C<~>
204 when encoding.
205  
206 =cut
207  
208 sub ProcessTilde {
209 0 ▶ my $self = shift;
Subroutine ProcessTilde: not called CC=8 SCAR=42.8
Pod documented
210 0 my $s = $self->{code};
211 0 my $as = $self->{as};
212 0 for ($s) {
213 0 s{~d(\d{3})}{ chr($1) }ge;
214 0 s{~d.{3}}{}g;
215 0 for my $i (0,1,4,5) {
216 0 s{^(.{$i})~1}{ $as->[$-[0]+$i]=''; $1."\350"}ge;
217 }
218 0 s{~1}{\035}g;
219 0 s{~2(.{3})}{ $as->[$-[0]] = $1; "\351".$2 }e;
220 0 s{^~3}{ $as->[0] = ''; "\352" }e;
221 0 s{^~5}{ $as->[0] = ''; "\354" }e;
222 0 s{^~6}{ $as->[0] = ''; "\355" }e;
223 0 s{~7(.{6})}{do{
224 0 my $d = int $1;
225 #warn "There is $d got from $1\n";
226 0 ▶ if ($d < 127) {
Branch: 2 branches
BranchTrueFalseTotal
if ($d < 127) { } 0 0 0
elsif ($d < 16383) { } 0 0 0
227 0 $d = chr($d+1);
228 }
229 elsif($d < 16383) {
230 0 $d =
231 chr( ( $d - 127 ) / 254 + 128 ).
232 chr( ( $d - 127 ) % 254 + 1 );
233 }
234 else{
235 0 $d =
236 chr( int( ( $d - 16383 ) / 64516 + 192 ) ).
237 chr( int( ( $d - 16383 ) / 254 ) % 254 + 1 ).
238 chr( int( ( $d - 16383 ) % 254 + 1 ) );
239 }
240 0 $as->[$-[0]] = $d;
241 0 ▶ warn "PT affect as[$-[0]] = ".join('+', map ord, split //, $d) if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 0 0
242 0 "\361"
243 }}ge;
244 0 ▶ s{~(.)}{$1 eq '~' ? '~' : $1}ge;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '~' ? : 0 0 0
245 0 ▶ warn "[C9] ProcessTilde($self->{code}) => ".Dumper($_) if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 0 0
246 0 return $self->{code} = $_;
247 }
248 }
249  
250 =head2 CalcReed (ai, err)
251  
252 Return the message as a Reed-Solomon encoded array.
253  
254 =cut
255  
256 sub CalcReed { # (int ai[], int i, int j) : void
257 16 ▶ my ($ai,$err) = @_;
Subroutine CalcReed: called CC=1 SCAR=0.0
Pod documented
258 16 my $rv = Barcode::DataMatrix::Reed::encode($ai,$err);
259 16 @$ai = @$rv;
260 16 return $ai;
261 }
262  
263 =head2 A253 (i, j)
264  
265 Return padding codewords via the 253-state algorithm.
266  
267 For more information see
268 L<http://grandzebu.net/informatique/codbar-en/datamatrix.htm>.
269  
270 The relevant text for this algorithm is reproduced here.
271  
272 If the symbol is not full, pad C<CW>s are required. After the last data
273 C<CW>, the 254 C<CW> indicates the end of the datas or the return to ASCII
274 method. First padding C<CW> is 129 and next padding C<CW>s are computed with
275 the 253-state algorithm.
276  
277 =head3 The 253-state algorithm
278  
279 Let C<P> be the number of data C<CW>s from the beginning of the data, C<R> a
280 pseudo random number and C<CW> the required pad C<CW>.
281  
282 R = ((149 * P) MOD 253) + 1
283 CW = (129 + R) MOD 254
284  
285 =cut
286  
287 sub A253 # C8 (int i, int j) : int
288 {
289 149 ▶ my ($i,$j) = @_;
Subroutine A253: called CC=2 SCAR=6.9
Pod documented
290 149 my $l = $i + (149 * $j) % 253 + 1;
291 149 ▶ return $l <= 254 ? $l : $l - 254;
Branch: 1 branch
BranchTrueFalseTotal
$l <= 254 ? : 75 74 149
292 }
293  
294 =head2 CreateBitmap
295  
296 Generate and return the bitmap representing the message.
297  
298 =cut
299  
300 sub CreateBitmap #CB (int ai[], String as[]) : int[][]
301 {
302 12 ▶ my $self = shift;
Subroutine CreateBitmap: called CC=34 SCAR=38.6
Pod documented
303 12 my ($ai,$as) = @$self{qw(ai as)};
304 12 ▶ warn "[CB] CreateBitmap(ai[" .join(',',@$ai).'], as[' . scalar(@$as) . "])\n" if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 12 12
305 12 my $ai1 = [];
306 12 my $i = 0;
307 12 ▶ $self->{currentEncoding} = $self->{encoding} if $self->{encoding} != E_AUTO;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"encoding"} != E_AUTO() 10 2 12
308 12 for ($self->{encoding}){
309 12 ▶ warn "[CB] Select method for $self->{encoding}, ".typeToString($self->{encoding})."\n" if $DEBUG{ENC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"ENC"} 0 12 12
310 12 ▶ $_ == E_AUTO && do { $i = $self->DetectEncoding($ai1); last;};
Branch: 1 branch
BranchTrueFalseTotal
$_ == E_AUTO() and do { $i = $self->DetectEncoding($ai1); last } 2 10 12
311 10 ▶ $_ == E_ASCII && do { $i = $self->EncodeASCII(scalar(@$ai), $ai, $ai1, $as); last;};
Branch: 1 branch
BranchTrueFalseTotal
$_ == E_ASCII() and do { $i = $self->EncodeASCII(scalar @$ai, $ai, $ai1, $as); last } 2 8 10
312 8 ▶ $_ == E_C40 && do { $i = $self->EncodeC40TEXT(scalar(@$ai), [0], $ai, $ai1, 0, 1, 0); last;};
Branch: 1 branch
BranchTrueFalseTotal
$_ == E_C40() and do { $i = $self->EncodeC40TEXT(scalar @$ai, [0], $ai, $ai1, 0, 1, 0); last } 2 6 8
313 6 ▶ $_ == E_TEXT && do { $i = $self->EncodeC40TEXT(scalar(@$ai), [0], $ai, $ai1, 1, 1, 0); last;};
Branch: 1 branch
BranchTrueFalseTotal
$_ == E_TEXT() and do { $i = $self->EncodeC40TEXT(scalar @$ai, [0], $ai, $ai1, 1, 1, 0); last } 2 4 6
314 4 ▶ $_ == E_BASE256 && do { $i = $self->EncodeBASE256(scalar(@$ai), [0], $ai, [0], $ai1, 0, $as); last;};
Branch: 1 branch
BranchTrueFalseTotal
$_ == E_BASE256() and do { $i = $self->EncodeBASE256(scalar @$ai, [0], $ai, [0], $ai1, 0, $as); last } 2 2 4
315 2 ▶ $_ == E_NONE && do { $ai1 = [ @$ai ]; $i = @$ai; last };
Branch: 1 branch
BranchTrueFalseTotal
$_ == E_NONE() and do { $ai1 = [@$ai]; $i = @$ai; last } 2 0 2
316 }
317 12 ▶ warn "[CB] selected (ai1[" .join(',',@$ai1).'], as[' . scalar(@$as) . "])\n" if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 12 12
318 12 DEBUG and print "Use Encoding: " .typeToString($self->{currentEncoding}). "(".typeToString($self->{encoding}).")\n";
319 12 ▶ warn "[CB]: enc res: ".typeToString($self->{encoding}).", " .typeToString($self->{currentEncoding}). "\n" if $DEBUG{ENC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"ENC"} 0 12 12
320 12 my $k = 0;
321 12 ▶ if($self->{preferredFormat} != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"preferredFormat"} != -1) 0 12 12
322 0 $k = $self->{preferredFormat};
323 0 ▶ $k = 0 if $i > $FORMATS[$k][7];
Branch: 1 branch
BranchTrueFalseTotal
if $i > $Barcode::DataMatrix::Engine::FORMATS[$k][7] 0 0 0
324 }
325 12 ▶ for(; $i > $FORMATS[$k][7] && $k < 30; $k++)
Branch: 1 branch
BranchTrueFalseTotal
if ($i > $Barcode::DataMatrix::Engine::FORMATS[$k][7] and $k < 30) 94 10 104
Condition66%2/3
$i > $Barcode::DataMatrix::Engine::FORMATS[$k][7] and $k < 30
!ll&&!rl&&r
10094
MC/DC50%1/2
$i > $Barcode::DataMatrix::Engine::FORMATS[$k][7] and $k < 30
$i > $Barcode::DataMatrix::Engine::FORMATS[$k][7] $k < 30
Truth table66%2/3
A and B
A= $i > $Barcode::DataMatrix::Engine::FORMATS[$k][7]B= $k < 30
ABresult
0X0
100
111
326 {
327 94 ▶ next if $self->{currentEncoding} != E_C40 && $self->{currentEncoding} != E_TEXT;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"currentEncoding"} != E_C40() and $self->{"currentEncoding"} != E_TEXT() 48 46 94
Condition100%3/3
$self->{"currentEncoding"} != E_C40() and $self->{"currentEncoding"} != E_TEXT()
!ll&&!rl&&r
281848
MC/DC100%2/2
$self->{"currentEncoding"} != E_C40() and $self->{"currentEncoding"} != E_TEXT()
$self->{"currentEncoding"} != E_C40() $self->{"currentEncoding"} != E_TEXT()
Truth table100%3/3
A and B
A= $self->{"currentEncoding"} != E_C40()B= $self->{"currentEncoding"} != E_TEXT()
ABresult
0X0
100
111
328 46 ▶ if($self->{C49rest} == 1 && $ai1->[$i - 2] == 254 && $FORMATS[$k][7] == $i - 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"C49rest"} == 1 and $$ai1[$i - 2] == 254 and $Barcode::DataMatrix::Engine::FORMATS[$k][7] == $i - 1) 0 46 46
Condition33%2/6
$self->{"C49rest"} == 1 and $$ai1[$i - 2] == 254 and $Barcode::DataMatrix::Engine::FORMATS[$k][7] == $i - 1
!ll&&!rl&&r
4600
$self->{"C49rest"} == 1 and $$ai1[$i - 2] == 254
!ll&&!rl&&r
4600
MC/DC0%0/3
$self->{"C49rest"} == 1 and $$ai1[$i - 2] == 254 and $Barcode::DataMatrix::Engine::FORMATS[$k][7] == $i - 1
$self->{"C49rest"} == 1 $$ai1[$i - 2] == 254 $Barcode::DataMatrix::Engine::FORMATS[$k][7] == $i - 1
Truth table25%1/4
A and B and C
A= $self->{"C49rest"} == 1B= $$ai1[$i - 2] == 254C= $Barcode::DataMatrix::Engine::FORMATS[$k][7] == $i - 1
ABCresult
0XX0
10X0
1100
1111
329 0 $ai1->[$i - 2] = $ai1->[$i - 1];
330 0 $ai1->[$i - 1] = 0;
331 0 $i--;
332 0 last;
333 }
334 46 ▶ next if($self->{C49rest} != 0 || $ai1->[$i - 1] != 254 || $FORMATS[$k][7] != $i - 1);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"C49rest"} != 0 or $$ai1[$i - 1] != 254 or $Barcode::DataMatrix::Engine::FORMATS[$k][7] != $i - 1 44 2 46
Condition50%3/6
$self->{"C49rest"} != 0 or $$ai1[$i - 1] != 254 or $Barcode::DataMatrix::Engine::FORMATS[$k][7] != $i - 1
l!l&&r!l&&!r
0442
$self->{"C49rest"} != 0 or $$ai1[$i - 1] != 254
l!l&&r!l&&!r
0046
MC/DC33%1/3
$self->{"C49rest"} != 0 or $$ai1[$i - 1] != 254 or $Barcode::DataMatrix::Engine::FORMATS[$k][7] != $i - 1
$self->{"C49rest"} != 0 $$ai1[$i - 1] != 254 $Barcode::DataMatrix::Engine::FORMATS[$k][7] != $i - 1
Truth table50%2/4
A or B or C
A= $self->{"C49rest"} != 0B= $$ai1[$i - 1] != 254C= $Barcode::DataMatrix::Engine::FORMATS[$k][7] != $i - 1
ABCresult
1XX1
01X1
0011
0000
335 2 $ai1->[$i - 1] = 0;
336 2 $i--;
337 2 last;
338 }
339  
340 12 ▶ return if $k == 30;
Branch: 1 branch
BranchTrueFalseTotal
if $k == 30 0 12 12
341 12 my $l = $k;
342 @$self{qw(
343 rows
344 cols
345 datarows
346 datacols
347 regions
348 maprows
349 mapcols
350 totaldata
351 totalerr
352 reeddata
353 reederr
354 reedblocks
355 12 )} = @{$FORMATS[$l]}[0..11];
356 12 DEBUG and print "Format: $self->{rows}x$self->{cols}; Data: $self->{totaldata}; i=$i; blocks = $self->{reedblocks}\n";
357 $ai1->[$i - 1] = 129 if (
358 ($self->{currentEncoding} == E_C40 || $self->{currentEncoding} == E_TEXT )
359 and
360 12 ▶ $self->{C49rest} == 0 && $i == $self->{totaldata} && $ai1->[$i - 1] == 254
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"currentEncoding"} == E_C40() || $self->{"currentEncoding"} == E_TEXT() and ($self->{"C49rest"} == 0 and $i == $self->{"totaldata"} and $$ai1[$i - 1] == 254) 0 12 12
Condition75%9/12
$self->{"currentEncoding"} == E_C40() || $self->{"currentEncoding"} == E_TEXT() and ($self->{"C49rest"} == 0 and $i == $self->{"totaldata"} and $$ai1[$i - 1] == 254)
!ll&&!rl&&r
660
$self->{"currentEncoding"} == E_C40() or $self->{"currentEncoding"} == E_TEXT()
l!l&&r!l&&!r
426
$self->{"C49rest"} == 0 and $i == $self->{"totaldata"} and $$ai1[$i - 1] == 254
!ll&&!rl&&r
420
$self->{"C49rest"} == 0 and $i == $self->{"totaldata"}
!ll&&!rl&&r
042
MC/DC0%0/5
$self->{"currentEncoding"} == E_C40() || $self->{"currentEncoding"} == E_TEXT() and ($self->{"C49rest"} == 0 and $i == $self->{"totaldata"} and $$ai1[$i - 1] == 254)
$self->{"currentEncoding"} == E_C40() $self->{"currentEncoding"} == E_TEXT() $self->{"C49rest"} == 0 $i == $self->{"totaldata"} $$ai1[$i - 1] == 254
Truth table22%2/9
A or B and C and D and E
A= $self->{"currentEncoding"} == E_C40()B= $self->{"currentEncoding"} == E_TEXT()C= $self->{"C49rest"} == 0D= $i == $self->{"totaldata"}E= $$ai1[$i - 1] == 254
ABCDEresult
00XXX0
1X0XX0
1X10X0
1X1100
010XX0
0110X0
011100
1X1111
011111
361 );
362 12 my $flag = 1;
363 12 ▶ warn "Calc begin from $i..$self->{totaldata} ai1=[@{$ai1}]\n" if $DEBUG{CALC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"CALC"} 0 12 12
364 12 ▶ for(my $i1 = $i; $i1 < $self->{totaldata}; $i1++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i1 < $self->{"totaldata"}) 158 12 170
365 158 ▶ $ai1->[$i1] = $flag ? 129 : A253(129, $i1 + 1);
Branch: 1 branch
BranchTrueFalseTotal
$flag ? : 9 149 158
366 158 $flag = 0;
367 }
368 12 return $self->{bitmap} = $self->GenData($self->ecc($l,$ai1));
369 }
370  
371 =head2 ecc (format, ai)
372  
373 Return the ECC200 (DataMatrix) array, formatted for the appropriate matrix
374 size.
375  
376 =cut
377  
378 sub ecc {
379 12 ▶ my $self = shift;
Subroutine ecc: called CC=12 SCAR=26.2
Pod documented
380 12 my $format = shift;
381 12 my $ai = shift;
382 12 my ($data,$err,$blocks) = @{$FORMATS[$format]}[9..11];
383 12 $blocks--;$data--;
384 12 ▶ warn "ECC: ai=[@{$ai}], blocks=$blocks\n" if $DEBUG{CALC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"CALC"} 0 12 12
385 12 my @blocks = map {[]} 0..$blocks;
386 12 my $block = 0;
387 12 for (@$ai) {
388 1228 push @{$blocks[$block++]}, $_;
389 1228 ▶ $block = 0 if $block > $blocks;
Branch: 1 branch
BranchTrueFalseTotal
if $block > $blocks 782 446 1228
390 }
391 12 ▶ warn "Calc blocks=".Dumper \@blocks if $DEBUG{CALC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"CALC"} 0 12 12
392 12 for (0..$#blocks) {
393 16 $#{ $blocks[$_] } = $data; # correct padding
394 16 ▶ if($self->{rows} == 144 and $_ > 7) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"rows"} == 144 and $_ > 7) 0 16 16
Condition33%1/3
$self->{"rows"} == 144 and $_ > 7
!ll&&!rl&&r
1600
MC/DC0%0/2
$self->{"rows"} == 144 and $_ > 7
$self->{"rows"} == 144 $_ > 7
Truth table33%1/3
A and B
A= $self->{"rows"} == 144B= $_ > 7
ABresult
0X0
100
111
395 0 $#{$blocks[$_]} -= 1;
396 }
397  
398 16 CalcReed($blocks[$_], $err);
399 }
400 warn "Calc reed=\n".
401 12 ▶ join "\n", map { '['.join(',',@$_).']' } @blocks if $DEBUG{CALC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"CALC"} 0 12 12
402 12 my @rv;
403 12 for my $n (0..$data+$err) {
404 1130 for my $b (0..$#blocks) {
405 1758 ▶ if ( $n < @{$blocks[$b]} ) { # 144 fix
Branch: 1 branch
BranchTrueFalseTotal
if ($n < @{$blocks[$b];}) 1758 0 1758
406 1758 push @rv, $blocks[$b][$n];
407 }
408 }
409 }
410 12 return \@rv;
411 }
412  
413 =head2 isIDigit (character_code)
414  
415 Return true if the character code represents a digit.
416  
417 =cut
418  
419 sub isIDigit { # C1
420 494 ▶ my $i = shift;
Subroutine isIDigit: called CC=3 SCAR=13.1
Pod documented
421 494 ▶ return ( $i >= 48 && $i <= 57 ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i >= 48 && $i <= 57 ? : 0 494 494
Condition33%1/3
$i >= 48 and $i <= 57
!ll&&!rl&&r
04940
MC/DC0%0/2
$i >= 48 and $i <= 57
$i >= 48 $i <= 57
Truth table33%1/3
A and B
A= $i >= 48B= $i <= 57
ABresult
0X0
100
111
422 }
423  
424 =head2 isILower (character_code)
425  
426 Return true if the character code represents a lower case letter.
427  
428 =cut
429  
430 sub isILower {
431 308 ▶ my $i = shift;
Subroutine isILower: called CC=3 SCAR=13.1
Pod documented
432 308 ▶ return ( $i >= ord('a') && $i <= ord('z') ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i >= 97 && $i <= 122 ? : 0 308 308
Condition33%1/3
$i >= 97 and $i <= 122
!ll&&!rl&&r
30800
MC/DC0%0/2
$i >= 97 and $i <= 122
$i >= 97 $i <= 122
Truth table33%1/3
A and B
A= $i >= 97B= $i <= 122
ABresult
0X0
100
111
433 }
434  
435 =head2 isIUpper (character_code)
436  
437 Return true if the character code represents an upper case letter.
438  
439 =cut
440  
441 sub isIUpper {
442 308 ▶ my $i = shift;
Subroutine isIUpper: called CC=3 SCAR=13.1
Pod documented
443 308 ▶ return ( $i >= ord('A') && $i <= ord('Z') ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$i >= 65 && $i <= 90 ? : 308 0 308
Condition33%1/3
$i >= 65 and $i <= 90
!ll&&!rl&&r
00308
MC/DC0%0/2
$i >= 65 and $i <= 90
$i >= 65 $i <= 90
Truth table33%1/3
A and B
A= $i >= 65B= $i <= 90
ABresult
0X0
100
111
444 }
445  
446 =head2 DetectEncoding
447  
448 Detect the encoding type.
449  
450 =cut
451  
452 sub DetectEncoding() #C4 (int i, int ai[], int ai1[], String as[]) : int
453 {
454 2 ▶ my $self = shift;
Subroutine DetectEncoding: called CC=29 SCAR=46.8
Pod documented
455 2 ▶ warn "[C4] DetectEncoding(@_)\n" if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 2 2
456 2 my $ai = $self->{ai};
457 2 my $i = scalar (@$ai);
458 2 my $as = $self->{as};
459 2 my $ai1 = shift;
460 2 my $ai2 = [ ];
461 2 my $ai3 = [ ];
462 2 my $flag = 0;
463 2 my $j1 = 0;
464 2 my $k1 = E_ASCII;
465 2 my $ai4 = [ 0 ];
466 2 my $l2 = E_ASCII;
467 2 my $as1 = [ ];
468 2 my $iterator = 0;
469 2 $self->{currentEncoding} = E_ASCII;
470 2 ▶ warn("DetectENC: starting from ".$encName[$self->{currentEncoding}]."\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
471 2 ▶ while($iterator < $i) { # while iterator less than length of data
Branch: 1 branch
BranchTrueFalseTotal
if ($iterator < $i) 2 2 4
472 2 ▶ warn("DetectENC: at $iterator ce=$encName[$self->{currentEncoding}] k1=$encName[$k1] l2=$encName[$l2]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
473 2 ▶ while($self->{currentEncoding} == E_ASCII and $iterator < $i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"currentEncoding"} == E_ASCII() and $iterator < $i) 2 2 4
Condition66%2/3
$self->{"currentEncoding"} == E_ASCII() and $iterator < $i
!ll&&!rl&&r
202
MC/DC50%1/2
$self->{"currentEncoding"} == E_ASCII() and $iterator < $i
$self->{"currentEncoding"} == E_ASCII() $iterator < $i
Truth table66%2/3
A and B
A= $self->{"currentEncoding"} == E_ASCII()B= $iterator < $i
ABresult
0X0
100
111
474 2 ▶ warn("DetectENC: while at $iterator ce=$encName[$self->{currentEncoding}] k1=$encName[$k1] l2=$encName[$l2]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
475 2 my $flag1 = 0;
476 2 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($iterator + 1 < $i and isIDigit($ai->[$iterator]) and isIDigit($$ai[$iterator + 1])) 0 2 2
Condition33%2/6
$iterator + 1 < $i and isIDigit($ai->[$iterator]) and isIDigit($$ai[$iterator + 1])
!ll&&!rl&&r
200
$iterator + 1 < $i and isIDigit($ai->[$iterator])
!ll&&!rl&&r
020
MC/DC0%0/3
$iterator + 1 < $i and isIDigit($ai->[$iterator]) and isIDigit($$ai[$iterator + 1])
$iterator + 1 < $i isIDigit($ai->[$iterator]) isIDigit($$ai[$iterator + 1])
Truth table25%1/4
A and B and C
A= $iterator + 1 < $iB= isIDigit($ai->[$iterator])C= isIDigit($$ai[$iterator + 1])
ABCresult
0XX0
10X0
1100
1111
477 $iterator + 1 < $i
478 and isIDigit($ai->[$iterator])
479 and isIDigit($ai->[$iterator + 1])
480 ){
481 0 ▶ warn("DetectENC: 2dig $ai->[$iterator]+$ai->[$iterator+1] at $iterator ce=$encName[$self->{currentEncoding}] k1=$encName[$k1] l2=$encName[$l2]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 0 0
482 0 ▶ $ai1->[$j1++] = 254 if($l2 != E_ASCII);
Branch: 1 branch
BranchTrueFalseTotal
if $l2 != E_ASCII() 0 0 0
483 0 $ai2->[0] = $ai->[$iterator];
484 0 $ai2->[1] = $ai->[$iterator + 1];
485 0 my $j = $self->EncodeASCII(2, $ai2, $ai3, $as1);
486 0 splice(@$ai1,$j1,$j, @$ai3[0 .. $j-1 ]);
487 0 $j1 += $j;
488 0 $iterator++;
489 0 $iterator++;
490 0 $flag1 = 1;
491 0 $l2 = E_ASCII;
492 }
493 2 ▶ if(!$flag1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($flag1) 2 0 2
494 2 ▶ warn("DetectENC: !dig !flag1 at $iterator ce=$encName[$self->{currentEncoding}] k1=$encName[$k1] l2=$encName[$l2]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
495 2 my $l1 = $self->SelectEncoding( $iterator );
496 2 ▶ if( $l1 != E_ASCII) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l1 != E_ASCII()) 2 0 2
497 2 ▶ warn("DetectENC: $encName[$self->{currentEncoding}] => $encName[$l1]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
498 2 $l2 = $self->{currentEncoding};
499 2 $self->{currentEncoding} = $l1;
500 }
501 }
502 2 ▶ if(!$flag1 and $self->{currentEncoding} == E_ASCII){
Branch: 1 branch
BranchTrueFalseTotal
if (not $flag1 and $self->{"currentEncoding"} == E_ASCII()) 0 2 2
Condition33%1/3
not $flag1 and $self->{"currentEncoding"} == E_ASCII()
!ll&&!rl&&r
020
MC/DC0%0/2
not $flag1 and $self->{"currentEncoding"} == E_ASCII()
not $flag1 $self->{"currentEncoding"} == E_ASCII()
Truth table33%1/3
not(A) and B
A= not $flag1B= $self->{"currentEncoding"} == E_ASCII()
ABresult
0X0
100
111
503 0 ▶ $ai1->[$j1++] = 254 if($l2 != E_ASCII);
Branch: 1 branch
BranchTrueFalseTotal
if $l2 != E_ASCII() 0 0 0
504 0 $ai2->[0] = $ai->[$iterator];
505 0 $as1->[0] = $as->[$iterator];
506 0 my $k = $self->EncodeASCII(1, $ai2, $ai3, $as1);
507 0 $as1->[0] = undef;
508 0 splice(@$ai1,$j1,$k, @$ai3[0 .. $k-1 ]);
509 0 $j1 += $k;
510 0 $iterator++;
511 0 $l2 = E_ASCII;
512 }
513 }
514 2 ▶ warn("DetectENC: after while at $iterator ce=$encName[$self->{currentEncoding}] k1=$encName[$k1] l2=$encName[$l2]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
515 2 my $i2;
516 2 ▶ for(; $self->{currentEncoding} == E_C40 and $iterator < $i; $self->{currentEncoding} = $i2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"currentEncoding"} == E_C40() and $iterator < $i) 62 2 64
Condition66%2/3
$self->{"currentEncoding"} == E_C40() and $iterator < $i
!ll&&!rl&&r
0262
MC/DC50%1/2
$self->{"currentEncoding"} == E_C40() and $iterator < $i
$self->{"currentEncoding"} == E_C40() $iterator < $i
Truth table66%2/3
A and B
A= $self->{"currentEncoding"} == E_C40()B= $iterator < $i
ABresult
0X0
100
111
517 62 $ai4->[0] = $iterator;
518 62 my $l = $self->EncodeC40TEXT($i, $ai4, $ai, $ai3, 0, $l2 != E_C40, 1);
519 62 $iterator = $ai4->[0];
520 62 splice(@$ai1,$j1,$l, @$ai3[0 .. $l-1 ]);
521 62 $j1 += $l;
522 62 $i2 = $self->SelectEncoding($iterator);
523 62 $l2 = $self->{currentEncoding};
524 }
525 2 ▶ warn("DetectENC: after C40 at $iterator ce=$encName[$self->{currentEncoding}] k1=$encName[$k1] l2=$encName[$l2]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
526  
527 2 my $j2;
528 2 ▶ for(; $self->{currentEncoding} == E_TEXT and $iterator < $i; $self->{currentEncoding} = $j2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"currentEncoding"} == E_TEXT() and $iterator < $i) 0 2 2
Condition33%1/3
$self->{"currentEncoding"} == E_TEXT() and $iterator < $i
!ll&&!rl&&r
200
MC/DC0%0/2
$self->{"currentEncoding"} == E_TEXT() and $iterator < $i
$self->{"currentEncoding"} == E_TEXT() $iterator < $i
Truth table33%1/3
A and B
A= $self->{"currentEncoding"} == E_TEXT()B= $iterator < $i
ABresult
0X0
100
111
529 0 $ai4->[0] = $iterator;
530 0 my $i1 = $self->EncodeC40TEXT($i, $ai4, $ai, $ai3, 1, $l2 != E_TEXT, 1);
531 0 $iterator = $ai4->[0];
532 0 splice(@$ai1,$j1,$i1, @$ai3[0 .. $i1-1 ]);
533 0 $j1 += $i1;
534 0 $j2 = $self->SelectEncoding($iterator);
535 0 $l2 = $self->{currentEncoding};
536 }
537 2 ▶ warn("DetectENC: after TEXT at $iterator ce=$encName[$self->{currentEncoding}] k1=$encName[$k1] l2=$encName[$l2]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
538  
539 2 ▶ if($self->{currentEncoding} == E_BASE256) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"currentEncoding"} == E_BASE256()) 0 2 2
540 0 $ai4->[0] = $iterator;
541 0 $j1 = $self->EncodeBASE256($i, $ai4, $ai, [$j1], $ai1, 1);
542 0 $iterator = $ai4->[0];
543 0 my $k2 = $self->SelectEncoding($iterator);
544 0 $l2 = $self->{currentEncoding};
545 0 $self->{currentEncoding} = $k2;
546 }
547 2 ▶ warn("DetectENC: after B256 at $iterator ce=$encName[$self->{currentEncoding}] k1=$encName[$k1] l2=$encName[$l2]\n") if $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 2 2
548 }
549 2 return $j1;
550 }
551  
552 =head2 EncodeASCII (i, ai, ai1, as)
553  
554 Encode the message as ASCII.
555  
556 =cut
557  
558 sub EncodeASCII { #CE (int i; int ai[], int ai1[], String as[]) : int
559 2 ▶ my $self = shift;
Subroutine EncodeASCII: called CC=19 SCAR=46.8
Pod documented
560 2 ▶ warn "[CE] EncodeASCII(@_)\n" if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 2 2
561 2 my ($i,$ai,$ai1,$as) = @_;
562 2 ▶ warn "[CE] ai:{".join(" ",grep{+defined}@$ai)."}; ai1:{".join(" ",grep{+defined}@$ai1)."}; as:{".join(" ",grep{+defined}@$as)."}\n" if $DEBUG{ENC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"ENC"} 0 2 2
563 2 my $j = 0;
564 2 my $flag = 0;
565 2 ▶ for(my $k = 0; $k < $i; $k++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < $i) 186 2 188
566 186 my $flag1 = 0;
567 186 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($k < $i - 1 and isIDigit($ai->[$k]) and isIDigit($$ai[$k + 1])) 0 186 186
Condition50%3/6
$k < $i - 1 and isIDigit($ai->[$k]) and isIDigit($$ai[$k + 1])
!ll&&!rl&&r
18600
$k < $i - 1 and isIDigit($ai->[$k])
!ll&&!rl&&r
21840
MC/DC0%0/3
$k < $i - 1 and isIDigit($ai->[$k]) and isIDigit($$ai[$k + 1])
$k < $i - 1 isIDigit($ai->[$k]) isIDigit($$ai[$k + 1])
Truth table50%2/4
A and B and C
A= $k < $i - 1B= isIDigit($ai->[$k])C= isIDigit($$ai[$k + 1])
ABCresult
0XX0
10X0
1100
1111
568 $k < $i - 1
569 and isIDigit($ai->[$k])
570 and isIDigit($ai->[$k+1])
571 ) {
572 0 my $l = ($ai->[$k] - 48) * 10 + ($ai->[$k + 1] - 48);
573 0 $ai1->[$j++] = 130 + $l;
574 0 $k++;
575 0 $flag1 = 1;
576 }
577 186 ▶ if(!$flag1 and defined $as->[$k]) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $flag1 and defined $as->[$k]) 0 186 186
Condition33%1/3
not $flag1 and defined $as->[$k]
!ll&&!rl&&r
01860
MC/DC0%0/2
not $flag1 and defined $as->[$k]
not $flag1 defined $as->[$k]
Truth table33%1/3
not(A) and B
A= not $flag1B= defined $as->[$k]
ABresult
0X0
100
111
578 0 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($ai->[$k] == 234 or $ai->[$k] == 237 or $ai->[$k] == 236 or $ai->[$k] == 232) 0 0 0
Condition0%0/9
$ai->[$k] == 234 or $ai->[$k] == 237 or $ai->[$k] == 236 or $ai->[$k] == 232
l!l&&r!l&&!r
000
$ai->[$k] == 234 or $ai->[$k] == 237 or $ai->[$k] == 236
l!l&&r!l&&!r
000
$ai->[$k] == 234 or $ai->[$k] == 237
l!l&&r!l&&!r
000
MC/DC0%0/4
$ai->[$k] == 234 or $ai->[$k] == 237 or $ai->[$k] == 236 or $ai->[$k] == 232
$ai->[$k] == 234 $ai->[$k] == 237 $ai->[$k] == 236 $ai->[$k] == 232
Truth table0%0/5
A or B or C or D
A= $ai->[$k] == 234B= $ai->[$k] == 237C= $ai->[$k] == 236D= $ai->[$k] == 232
ABCDresult
1XXX1
01XX1
001X1
00011
00000
579 $ai->[$k] == 234
580 or $ai->[$k] == 237
581 or $ai->[$k] == 236
582 or $ai->[$k] == 232
583 ) {
584 0 $ai1->[$j++] = $ai->[$k];
585 0 $flag1 = 1;
586 }
587 0 ▶ if($ai->[$k] == 233 || $ai->[$k] == 241) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ai->[$k] == 233 or $ai->[$k] == 241) 0 0 0
Condition0%0/3
$ai->[$k] == 233 or $ai->[$k] == 241
l!l&&r!l&&!r
000
MC/DC0%0/2
$ai->[$k] == 233 or $ai->[$k] == 241
$ai->[$k] == 233 $ai->[$k] == 241
Truth table0%0/3
A or B
A= $ai->[$k] == 233B= $ai->[$k] == 241
ABresult
1X1
011
000
588 0 $ai1->[$j++] = $ai->[$k];
589 0 ▶ for(my $i1 = 0; $i1 < length $as->[$k]; $i1++){
Branch: 1 branch
BranchTrueFalseTotal
if ($i1 < length $as->[$k]) 0 0 0
590 0 $ai1->[$j++] = ord substr($as->[$k],$i1,1);
591 }
592 0 $flag1 = 1;
593 }
594 }
595 186 ▶ if(!$flag1){
Branch: 1 branch
BranchTrueFalseTotal
unless ($flag1) 186 0 186
596 186 ▶ if($ai->[$k] < 128) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ai->[$k] < 128) { } 186 0 186
597 186 $ai1->[$j++] = $ai->[$k] + 1;
598 } else {
599 0 $ai1->[$j++] = 235;
600 0 $ai1->[$j++] = ($ai->[$k] - 128) + 1;
601 }
602 }
603 }
604 2 ▶ warn "[CE] end $j ai1:{".join(" ",@$ai1)."};\n" if $DEBUG{ENC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"ENC"} 0 2 2
605 2 return $j;
606 }
607  
608 =head2 SelectEncoding (j, ai, i)
609  
610 Select a new encoding type for the message.
611  
612 =cut
613  
614 sub SelectEncoding #C3 (int ai[], int i, int j, String as[]) : int # DefineEncoding??
615 #iterator, ai, encoding
616 {
617 #(iterator[,ai[,encoding]])
618 #(ai,i: encoding,j: iterator,as)
619 64 ▶ my $self = shift;
Subroutine SelectEncoding: called CC=43 SCAR=48.7
Pod documented
620 64 ▶ warn "[C3] SelectEncoding(@_)\n" if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 64 64
621  
622 64 my $j = shift;
623  
624 64 my $ai = shift;
625 64 ▶ $ai = $self->{ai} unless defined $ai;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ai 64 0 64
626  
627 64 ▶ my $i = shift || $self->{currentEncoding};
Condition66%2/3
shift() || $self->{'currentEncoding'}
l!l&&r!l&&!r
0622
MC/DC50%1/2
shift() || $self->{'currentEncoding'}
shift() $self->{'currentEncoding'}
Truth table66%2/3
A || B
A= shift()B= $self->{'currentEncoding'}
ABresult
1X1
011
000
628 64 ▶ $i = $self->{currentEncoding} unless defined $i;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $i 0 64 64
629  
630 64 my $as = $self->{as};
631 64 my $d = 0.0;
632 64 my $d2 = 1.0;
633 64 my $d3 = 1.0;
634 64 my $d4 = 1.25;
635 64 my $k = $j;
636 64 ▶ if($i != E_ASCII)
Branch: 1 branch
BranchTrueFalseTotal
if ($i != E_ASCII()) 62 2 64
637 {
638 62 $d = 1.0;
639 62 $d2 = 2.0;
640 62 $d3 = 2.0;
641 62 $d4 = 2.25;
642 }
643 64 ▶ $d2 = 0.0 if $i == E_C40;
Branch: 1 branch
BranchTrueFalseTotal
if $i == E_C40() 62 2 64
644 64 ▶ $d3 = 0.0 if $i == E_TEXT;
Branch: 1 branch
BranchTrueFalseTotal
if $i == E_TEXT() 0 64 64
645 64 ▶ $d4 = 0.0 if $i == E_BASE256;
Branch: 1 branch
BranchTrueFalseTotal
if $i == E_BASE256() 0 64 64
646 64 ▶ for(; $j < @$ai; $j++)
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @$ai) 308 4 312
647 {
648 308 ▶ warn "SelectEncoding: have as[$j]: $as->[$j]\n" if defined $as->[$j] and $DEBUG{EAUTO};
Branch: 1 branch
BranchTrueFalseTotal
if defined $as->[$j] and $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"} 0 308 308
Condition33%1/3
defined $as->[$j] and $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"}
!ll&&!rl&&r
30800
MC/DC0%0/2
defined $as->[$j] and $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"}
defined $as->[$j] $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"}
Truth table33%1/3
A and B
A= defined $as->[$j]B= $Barcode::DataMatrix::Engine::DEBUG{"EAUTO"}
ABresult
0X0
100
111
649 308 my $c = $ai->[$j];
650 308 ▶ return E_ASCII if defined $as->[$j];
Branch: 1 branch
BranchTrueFalseTotal
if defined $as->[$j] 0 308 308
651  
652 308 ▶ if ( isIDigit($c) ) { $d += 0.5 }
Branch: 2 branches
BranchTrueFalseTotal
if (isIDigit($c)) { } 0 308 308
elsif ($c > 127) { } 0 308 308
653 0 elsif ( $c > 127 ) { $d = int( $d + 0.5 ) + 2; }
654 308 else { $d = int( $d + 0.5 ) + 1; }
655  
656 308 ▶ if ( @{ $C1[$c] } == 1 ) { $d2 += 0.66000000000000003; }
Branch: 2 branches
BranchTrueFalseTotal
if (@{$Barcode::DataMatrix::Engine::C1[$c];} == 1) { } 308 0 308
elsif ($c > 127) { } 0 0 0
657 0 elsif ( $c > 127 ) { $d2 += 2.6600000000000001; }
658 0 else { $d2 += 1.3300000000000001; }
659 308 my $c1 = $c;
660 308 ▶ if( isIUpper($c) ) { $c1 = ord lc chr $c; }
Branch: 1 branch
BranchTrueFalseTotal
if (isIUpper($c)) 308 0 308
661 308 ▶ if( isILower($c) ) { $c1 = ord uc chr $c; }
Branch: 1 branch
BranchTrueFalseTotal
if (isILower($c)) 0 308 308
662  
663 308 ▶ if ( @{ $C1[$c1] } == 1) { $d3 += 0.66000000000000003; }
Branch: 2 branches
BranchTrueFalseTotal
if (@{$Barcode::DataMatrix::Engine::C1[$c1];} == 1) { } 0 308 308
elsif ($c1 > 127) { } 0 308 308
664 0 elsif ( $c1 > 127 ) { $d3 += 2.6600000000000001; }
665 308 else { $d3 += 1.3300000000000001; }
666  
667 308 $d4++;
668  
669 308 ▶ if($j - $k >= 4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j - $k >= 4) 62 246 308
670 62 ▶ return E_ASCII if $d + 1.0 <= $d2 and $d + 1.0 <= $d3 and $d + 1.0 <= $d4;
Branch: 1 branch
BranchTrueFalseTotal
if $d + 1 <= $d2 and $d + 1 <= $d3 and $d + 1 <= $d4 0 62 62
Condition33%2/6
$d + 1 <= $d2 and $d + 1 <= $d3 and $d + 1 <= $d4
!ll&&!rl&&r
6200
$d + 1 <= $d2 and $d + 1 <= $d3
!ll&&!rl&&r
6200
MC/DC0%0/3
$d + 1 <= $d2 and $d + 1 <= $d3 and $d + 1 <= $d4
$d + 1 <= $d2 $d + 1 <= $d3 $d + 1 <= $d4
Truth table25%1/4
A and B and C
A= $d + 1 <= $d2B= $d + 1 <= $d3C= $d + 1 <= $d4
ABCresult
0XX0
10X0
1100
1111
671 62 ▶ return E_BASE256 if $d4 + 1.0 <= $d;
Branch: 1 branch
BranchTrueFalseTotal
if $d4 + 1 <= $d 0 62 62
672 62 ▶ return E_BASE256 if $d4 + 1.0 < $d3 and $d4 + 1.0 < $d2;
Branch: 1 branch
BranchTrueFalseTotal
if $d4 + 1 < $d3 and $d4 + 1 < $d2 0 62 62
Condition33%1/3
$d4 + 1 < $d3 and $d4 + 1 < $d2
!ll&&!rl&&r
0620
MC/DC0%0/2
$d4 + 1 < $d3 and $d4 + 1 < $d2
$d4 + 1 < $d3 $d4 + 1 < $d2
Truth table33%1/3
A and B
A= $d4 + 1 < $d3B= $d4 + 1 < $d2
ABresult
0X0
100
111
673 62 ▶ return E_TEXT if $d3 + 1.0 < $d and $d3 + 1.0 < $d2 and $d3 + 1.0 < $d4;
Branch: 1 branch
BranchTrueFalseTotal
if $d3 + 1 < $d and $d3 + 1 < $d2 and $d3 + 1 < $d4 0 62 62
Condition33%2/6
$d3 + 1 < $d and $d3 + 1 < $d2 and $d3 + 1 < $d4
!ll&&!rl&&r
6200
$d3 + 1 < $d and $d3 + 1 < $d2
!ll&&!rl&&r
6200
MC/DC0%0/3
$d3 + 1 < $d and $d3 + 1 < $d2 and $d3 + 1 < $d4
$d3 + 1 < $d $d3 + 1 < $d2 $d3 + 1 < $d4
Truth table25%1/4
A and B and C
A= $d3 + 1 < $dB= $d3 + 1 < $d2C= $d3 + 1 < $d4
ABCresult
0XX0
10X0
1100
1111
674 62 ▶ return E_C40 if $d2 + 1.0 < $d and $d2 + 1.0 < $d3 and $d2 + 1.0 < $d4;
Branch: 1 branch
BranchTrueFalseTotal
if $d2 + 1 < $d and $d2 + 1 < $d3 and $d2 + 1 < $d4 60 2 62
Condition66%4/6
$d2 + 1 < $d and $d2 + 1 < $d3 and $d2 + 1 < $d4
!ll&&!rl&&r
2060
$d2 + 1 < $d and $d2 + 1 < $d3
!ll&&!rl&&r
2060
MC/DC33%1/3
$d2 + 1 < $d and $d2 + 1 < $d3 and $d2 + 1 < $d4
$d2 + 1 < $d $d2 + 1 < $d3 $d2 + 1 < $d4
Truth table50%2/4
A and B and C
A= $d2 + 1 < $dB= $d2 + 1 < $d3C= $d2 + 1 < $d4
ABCresult
0XX0
10X0
1100
1111
675 }
676 }
677  
678 4 $d = int( $d + 0.5 );
679 4 $d2 = int( $d2 + 0.5 );
680 4 $d3 = int( $d3 + 0.5 );
681 4 $d4 = int( $d4 + 0.5 );
682 4 ▶ return E_ASCII if $d <= $d2 and $d <= $d3 and $d <= $d4;
Branch: 1 branch
BranchTrueFalseTotal
if $d <= $d2 and $d <= $d3 and $d <= $d4 0 4 4
Condition33%2/6
$d <= $d2 and $d <= $d3 and $d <= $d4
!ll&&!rl&&r
400
$d <= $d2 and $d <= $d3
!ll&&!rl&&r
400
MC/DC0%0/3
$d <= $d2 and $d <= $d3 and $d <= $d4
$d <= $d2 $d <= $d3 $d <= $d4
Truth table25%1/4
A and B and C
A= $d <= $d2B= $d <= $d3C= $d <= $d4
ABCresult
0XX0
10X0
1100
1111
683 4 ▶ return E_TEXT if $d3 < $d and $d3 < $d2 and $d3 < $d4;
Branch: 1 branch
BranchTrueFalseTotal
if $d3 < $d and $d3 < $d2 and $d3 < $d4 0 4 4
Condition33%2/6
$d3 < $d and $d3 < $d2 and $d3 < $d4
!ll&&!rl&&r
400
$d3 < $d and $d3 < $d2
!ll&&!rl&&r
400
MC/DC0%0/3
$d3 < $d and $d3 < $d2 and $d3 < $d4
$d3 < $d $d3 < $d2 $d3 < $d4
Truth table25%1/4
A and B and C
A= $d3 < $dB= $d3 < $d2C= $d3 < $d4
ABCresult
0XX0
10X0
1100
1111
684 4 ▶ return E_BASE256 if $d4 < $d and $d4 < $d3 and $d4 < $d2;
Branch: 1 branch
BranchTrueFalseTotal
if $d4 < $d and $d4 < $d3 and $d4 < $d2 0 4 4
Condition33%2/6
$d4 < $d and $d4 < $d3 and $d4 < $d2
!ll&&!rl&&r
400
$d4 < $d and $d4 < $d3
!ll&&!rl&&r
400
MC/DC0%0/3
$d4 < $d and $d4 < $d3 and $d4 < $d2
$d4 < $d $d4 < $d3 $d4 < $d2
Truth table25%1/4
A and B and C
A= $d4 < $dB= $d4 < $d3C= $d4 < $d2
ABCresult
0XX0
10X0
1100
1111
685 4 return E_C40;
686 }
687  
688 =head2 EncodeC40TEXT (i, ai, ai1, ai2, flag, flag1, flag2)
689  
690 Encode the message as C40/TEXT.
691  
692 =cut
693  
694 sub EncodeC40TEXT { # C6 #(int i, int ai[], int ai1[], int ai2[], boolean flag, boolean flag1, boolean flag2) : int
695 66 ▶ my $self = shift;
Subroutine EncodeC40TEXT: called CC=17 SCAR=31.9
Pod documented
696 66 my ($i,$ai,$ai1,$ai2,$flag,$flag1,$flag2) = @_;
697 66 my $j = my $k = 0;
698 66 my $ai3 = [ 0, 0, 0 ];
699 66 my $flag3 = 0;
700 66 my $as = [ ];
701 66 ▶ if($flag1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag1) 6 60 66
702 6 ▶ $ai2->[$j++] = $flag ? 239 : 230;
Branch: 1 branch
BranchTrueFalseTotal
$flag ? : 2 4 6
703 }
704 66 ▶ for(my $j1 = $ai->[0]; $j1 < $i; $j1++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j1 < $i) 558 4 562
705 558 my $l = $ai1->[$j1];
706 558 ▶ if($flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag) 186 372 558
707 186 my $s = chr($l);
708 186 ▶ $s = uc($s) if($l >= 97 && $l <= 122);
Branch: 1 branch
BranchTrueFalseTotal
if $l >= 97 and $l <= 122 0 186 186
Condition33%1/3
$l >= 97 and $l <= 122
!ll&&!rl&&r
18600
MC/DC0%0/2
$l >= 97 and $l <= 122
$l >= 97 $l <= 122
Truth table33%1/3
A and B
A= $l >= 97B= $l <= 122
ABresult
0X0
100
111
709 186 ▶ $s = lc($s) if($l >= 65 && $l <= 90);
Branch: 1 branch
BranchTrueFalseTotal
if $l >= 65 and $l <= 90 186 0 186
Condition33%1/3
$l >= 65 and $l <= 90
!ll&&!rl&&r
00186
MC/DC0%0/2
$l >= 65 and $l <= 90
$l >= 65 $l <= 90
Truth table33%1/3
A and B
A= $l >= 65B= $l <= 90
ABresult
0X0
100
111
710 186 $l = ord(substr($s,0,1));
711 }
712 558 my $ai4 = $C1[$l];
713 558 for my $l1 (0 .. $#$ai4) {
714 744 $ai3->[$k++] = $ai4->[$l1];
715 744 ▶ if($k == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k == 3) 248 496 744
716 248 my $i2 = $ai3->[0] * 1600 + $ai3->[1] * 40 + $ai3->[2] + 1;
717 248 $ai2->[$j++] = int $i2 / 256;
718 248 $ai2->[$j++] = $i2 % 256;
719 248 $k = 0;
720 }
721 }
722  
723 558 ▶ if($flag2 && $k == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag2 and $k == 0) 62 496 558
Condition100%3/3
$flag2 and $k == 0
!ll&&!rl&&r
37212462
MC/DC100%2/2
$flag2 and $k == 0
$flag2 $k == 0
Truth table100%3/3
A and B
A= $flag2B= $k == 0
ABresult
0X0
100
111
724 62 $self->{C49rest} = $k;
725 62 $ai->[0] = $j1 + 1;
726 62 ▶ $ai2->[$j++] = 254 if($ai->[0] == $i);
Branch: 1 branch
BranchTrueFalseTotal
if $ai->[0] == $i 2 60 62
727 62 return $j;
728 }
729 }
730  
731 4 $ai->[0] = $i;
732 4 ▶ if($k > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k > 0) { } 0 4 4
733 0 ▶ if($k == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k == 1) 0 0 0
734 0 $ai2->[$j++] = 254;
735 0 $ai2->[$j++] = $ai1->[$i - 1] + 1;
736 0 return $j;
737 }
738 0 ▶ if($k == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k == 2) 0 0 0
739 0 $ai3->[2] = 0;
740 0 my $k1 = $ai3->[0] * 1600 + $ai3->[1] * 40 + $ai3->[2] + 1;
741 0 $ai2->[$j++] = int $k1 / 256;
742 0 $ai2->[$j++] = $k1 % 256;
743 0 $ai2->[$j++] = 254;
744 0 $self->{C49rest} = $k;
745 0 return $j;
746 }
747 } else {
748 4 $ai2->[$j++] = 254;
749 }
750 4 $self->{C49rest} = $k;
751 4 return $j;
752 }
753  
754 =head2 state255 (V, P)
755  
756 The 255-state algorithm. Used when encoding strings with the BASE256 type.
757  
758 This information originally from
759 L<http://grandzebu.net/informatique/codbar-en/datamatrix.htm>.
760  
761 Let C<P> the number of data C<CW>s from the beginning of datas (C<CW> = code
762 word). Let C<R> be a pseudo random number, C<V> the base 256 C<CW> value
763 and C<CW> the required C<CW>.
764  
765 R = ((149 * P) MOD 255) + 1
766 CW = (V + R) MOD 256
767  
768 =cut
769  
770 sub state255 # (int V, int P) : int
771 {
772 188 ▶ my ($V,$P) = @_;
Subroutine state255: called CC=1 SCAR=0.0
Pod documented
773 188 return ( $V + (149 * $P) % 255 + 1 ) % 256;
774 }
775  
776 =head2 hexary (src)
777  
778 Return a string representation of the input hexadecimal number.
779  
780 =cut
781  
782 sub hexary {
783 0 ▶ join(" ",map{ sprintf '%02x',$_} @{ shift() } )
Subroutine hexary: not called CC=1 SCAR=6.9
Pod documented
784 }
785  
786 =head2 EncodeBASE256 (i, hint, src, stat, res, flag)
787  
788 Encode the message as BASE256.
789  
790 =cut
791  
792 sub EncodeBASE256 {
793 2 ▶ my $self = shift;
Subroutine EncodeBASE256: called CC=10 SCAR=24.5
Pod documented
794 2 my ($i,$hint,$src,$stat,$res,$flag) = @_;
795 2 my $j = 0;
796 2 my $xv = [];
797 2 my $k =
798 my $l = $stat->[0];
799 2 my $flag1 = 0;
800 2 my $j1 = 0;
801 2 ▶ warn "AI1{".hexary($src)."}\n" if $DEBUG{B256};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"B256"} 0 2 2
802 2 ▶ warn "AI4{".hexary($xv)."}\n" if $DEBUG{B256};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"B256"} 0 2 2
803 2 ▶ for( $j1 = $hint->[0]; $j1 < $i; $j1++){
Branch: 1 branch
BranchTrueFalseTotal
if ($j1 < $i) 186 2 188
804 186 $xv->[$j++] = $src->[$j1];
805 186 ▶ last if $flag and $self->SelectEncoding($j1 + 1,$src,E_BASE256) != E_BASE256;
Branch: 1 branch
BranchTrueFalseTotal
if $flag and $self->SelectEncoding($j1 + 1, $src, E_BASE256()) != E_BASE256() 0 186 186
Condition33%1/3
$flag and $self->SelectEncoding($j1 + 1, $src, E_BASE256()) != E_BASE256()
!ll&&!rl&&r
18600
MC/DC0%0/2
$flag and $self->SelectEncoding($j1 + 1, $src, E_BASE256()) != E_BASE256()
$flag $self->SelectEncoding($j1 + 1, $src, E_BASE256()) != E_BASE256()
Truth table33%1/3
A and B
A= $flagB= $self->SelectEncoding($j1 + 1, $src, E_BASE256()) != E_BASE256()
ABresult
0X0
100
111
806 }
807 2 ▶ warn "AI1{".hexary($src)."}\n" if $DEBUG{B256};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"B256"} 0 2 2
808 2 ▶ warn "AI4{".hexary($xv)."}\n" if $DEBUG{B256};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"B256"} 0 2 2
809 2 $hint->[0] = $j1;
810 2 $res->[$l++] = 231;
811 2 ▶ if($j < 250) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < 250) { } 2 0 2
812 2 $res->[$l++] = state255($j, $l + 1);
813 } else {
814 0 $res->[$l++] = state255(249 + ($i - $i % 250) / 250, $l + 1);
815 0 $res->[$l++] = state255($i % 250, $l + 1);
816 }
817 2 $res->[$l++] = state255($xv->[$_], $l + 1) for 0..$j-1;
818 2 $stat->[0] = $l;
819 2 return $l;
820 }
821  
822 =head2 GenData (ai)
823  
824 Generate and return the data for the DataMatrix bitmap from the input array.
825  
826 =cut
827  
828 sub GenData { # CC (int ai[]) : int[][]
829 12 ▶ my $self = shift;
Subroutine GenData: called CC=16 SCAR=28.3
Pod documented
830 12 my ($ai) = @_;
831 12 ▶ warn "[CC] GenData: ".join(",",@$ai)." [$self->{rows} x $self->{cols} : $self->{regions} : $self->{datacols}x$self->{datarows}]\n" if $DEBUG{TRACE};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"TRACE"} 0 12 12
832 12 my $ai1 = [ map { [ (undef) x $self->{rows} ] } 1..$self->{cols} ]; # reverse cols/rows here, for correct access ->[][]
833  
834 12 my $i = my $j = 0;
835 # Draw border
836 12 ▶ if($self->{regions} == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'regions'} == 2) { } 0 12 12
837 0 FillBorder($ai1, $i, $j, $self->{datacols} + 2, $self->{datarows} + 2);
838 0 FillBorder($ai1, $i + $self->{datacols} + 2, $j, $self->{datacols} + 2, $self->{datarows} + 2);
839 } else {
840 12 my $k = int(sqrt($self->{regions}));
841 12 ▶ for(my $l = 0; $l < $k; $l++){
Branch: 1 branch
BranchTrueFalseTotal
if ($l < $k) 20 12 32
842 20 ▶ for(my $i1 = 0; $i1 < $k; $i1++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i1 < $k) 42 20 62
843 FillBorder($ai1, $i + $l * ($self->{datacols} + 2), $j
844 + $i1 * ($self->{datarows} + 2),
845 42 $self->{datacols} + 2, $self->{datarows} + 2);
846 }
847 }
848  
849 }
850 # End draw border
851 12 my $ai2 = [ (undef) x ( ($self->{mapcols} + 10) * $self->{maprows} ) ];
852 12 ▶ warn "[" . join (" ", grep { +defined } @$ai2)."]\n" if $DEBUG{CALC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"CALC"} 0 12 12
853 12 FillCharData($self->{mapcols},$self->{maprows},$ai2);
854 12 ▶ warn "[" . join (" ", grep { +defined } @$ai2)."]\n" if $DEBUG{CALC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"CALC"} 0 12 12
855 12 ▶ warn "--------------\n" if $DEBUG{CALC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"CALC"} 0 12 12
856 12 ▶ warn "[" . join (" ", grep { +defined } @$ai)."]\n" if $DEBUG{CALC};
Branch: 1 branch
BranchTrueFalseTotal
if $Barcode::DataMatrix::Engine::DEBUG{"CALC"} 0 12 12
857 12 my $j1 = 1;
858 12 my $flag = 0;
859 12 my $flag1 = 0;
860 12 ▶ for(my $i2 = 0; $i2 < $self->{maprows}; $i2++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i2 < $self->{"maprows"}) 350 12 362
861 350 my $j2 = 1;
862 350 ▶ for(my $k2 = 0; $k2 < $self->{mapcols}; $k2++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k2 < $self->{"mapcols"}) 14076 350 14426
863 14076 my $l1 = $k2 + $j2;
864 14076 my $k1 = $i2 + $j1;
865 14076 ▶ if($ai2->[$i2 * $self->{mapcols} + $k2] > 9) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$ai2[$i2 * $self->{'mapcols'} + $k2] > 9) { } 14064 12 14076
866 14064 my $l2 = int ( $ai2->[$i2 * $self->{mapcols} + $k2] / 10 );
867 14064 my $i3 = $ai2->[$i2 * $self->{mapcols} + $k2] % 10;
868 14064 my $j3 = $ai->[$l2 - 1] & 1 << 8 - $i3;
869 14064 $ai1->[$l1][$k1] = $j3;
870 } else {
871 12 $ai1->[$l1][$k1] = $ai2->[$i2 * $self->{mapcols} + $k2];
872 }
873 14076 ▶ if($k2 > 0 && ($k2 + 1) % $self->{datacols} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k2 > 0 and ($k2 + 1) % $self->{"datacols"} == 0) 742 13334 14076
Condition100%3/3
$k2 > 0 and ($k2 + 1) % $self->{"datacols"} == 0
!ll&&!rl&&r
35012984742
MC/DC100%2/2
$k2 > 0 and ($k2 + 1) % $self->{"datacols"} == 0
$k2 > 0 ($k2 + 1) % $self->{"datacols"} == 0
Truth table100%3/3
A and B
A= $k2 > 0B= ($k2 + 1) % $self->{"datacols"} == 0
ABresult
0X0
100
111
874 742 $j2 += 2;
875 }
876 }
877  
878 350 ▶ if($i2 > 0 && ($i2 + 1) % $self->{datarows} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i2 > 0 and ($i2 + 1) % $self->{"datarows"} == 0) 20 330 350
Condition100%3/3
$i2 > 0 and ($i2 + 1) % $self->{"datarows"} == 0
!ll&&!rl&&r
1231820
MC/DC100%2/2
$i2 > 0 and ($i2 + 1) % $self->{"datarows"} == 0
$i2 > 0 ($i2 + 1) % $self->{"datarows"} == 0
Truth table100%3/3
A and B
A= $i2 > 0B= ($i2 + 1) % $self->{"datarows"} == 0
ABresult
0X0
100
111
879 20 $j1 += 2;
880 }
881 }
882 12 return $ai1;
883 }
884  
885 =head2 FillBorder (ai, i, j, k, l)
886  
887 Fill the border of the ECC200 data matrix bitmap.
888  
889 =cut
890  
891 sub FillBorder { # CD (int ai[][], int i, int j, int k, int l) : void
892 42 ▶ my ($ai,$i,$j,$k,$l) = @_;
Subroutine FillBorder: called CC=5 SCAR=16.1
Pod documented
893 42 my $i1 = 0;
894 42 ▶ for(my $k1 = 0; $k1 < $k; $k1++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k1 < $k) 826 42 868
895 826 ▶ $i1 = ($k1 % 2 == 0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$k1 % 2 == 0 ? : 413 413 826
896 826 $ai->[$i + $k1][$j + $l - 1] = 1;
897 826 $ai->[$i + $k1][$j] = $i1;
898 }
899 42 $i1 = 0;
900 42 ▶ for(my $l1 = 0; $l1 < $l; $l1++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l1 < $l) 826 42 868
901 826 ▶ my $j1 = (($l1 + 1) % 2 == 0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($l1 + 1) % 2 == 0 ? : 413 413 826
902 826 $ai->[$i][$j + $l1] = 1;
903 826 $ai->[$i + $k - 1][$j + $l1] = $j1;
904 }
905 }
906  
907 =head2 FillCharData (ncol, nrow, array)
908  
909 Fill the data matrix with the character data in the given message array.
910  
911 =cut
912  
913 sub FillCharData { # (int ncol; int nrow; int array;) : void
914 12 ▶ my ($ncol,$nrow,$array) = @_;
Subroutine FillCharData: called CC=1 SCAR=0.0
Pod documented
915 12 Barcode::DataMatrix::CharDataFiller->new($ncol,$nrow,$array);
916 12 return;
917 }
918  
919 2 1;
↑ Summary DataMatrix/CharDataFiller.pm »