sub
DEBUG { 0 }
sub
mult {
my
(
$x
,
$y
) =
@_
;
return
0
unless
$x
*
$y
;
return
$Barcode::DataMatrix::Constants::GFI
[(
$Barcode::DataMatrix::Constants::GFL
[
$x
] +
$Barcode::DataMatrix::Constants::GFL
[
$y
]) % 255];
}
sub
encode {
my
(
$ai
,
$j
) =
@_
;
my
$i
=
@$ai
;
for
(0..
$#$ai
) {
(
$ai
->[
$_
] & 0xFF ) !=
$ai
->[
$_
] and
warn
(
"number $ai->[$_] at index $_ is not a byte size"
),
$ai
->[
$_
] =
$ai
->[
$_
] & 0xFF;
}
warn
"CalcReed: ai [@$ai], $j\n"
if
DEBUG;
my
$p
=
exists
$Barcode::DataMatrix::Constants::POLY
{
$j
} ?
$Barcode::DataMatrix::Constants::POLY
{
$j
} :
$Barcode::DataMatrix::Constants::POLY
{68};
warn
"CalcReed: poly [@$p]\n"
if
DEBUG;
@$ai
[
$i
..
$i
+
$j
- 1 ] = (0) x
$j
;
for
my
$l
(0 ..
$i
- 1) {
my
$word0
= (
$ai
->[
$i
] ^
$ai
->[
$l
]);
for
my
$i1
(0 ..
$j
- 2) {
$ai
->[
$i
+
$i1
] = (
$ai
->[
$i
+
$i1
+ 1] ^ mult(
$word0
,
$p
->[
$i1
]) );
}
$ai
->[
$i
+
$j
-1] = mult(
$word0
,
$p
->[
$j
- 1]);
}
warn
"CalcReed: result [@$ai]\n"
if
DEBUG;
return
$ai
;
}
1;