Milon\Barcode\PDF417::getErrorCorrection PHP Метод

getErrorCorrection() защищенный Метод

Returns the error correction codewords
protected getErrorCorrection ( $cw, $ecl ) : array
$cw (array) array of codewords including Symbol Lenght Descriptor and pad
$ecl (int) error correction level 0-8
Результат array of error correction codewords
    protected function getErrorCorrection($cw, $ecl)
    {
        // get error correction coefficients
        $ecc = $this->rsfactors[$ecl];
        // number of error correction factors
        $eclsize = 2 << $ecl;
        // maximum index for $rsfactors[$ecl]
        $eclmaxid = $eclsize - 1;
        // initialize array of error correction codewords
        $ecw = array_fill(0, $eclsize, 0);
        // for each data codeword
        foreach ($cw as $k => $d) {
            $t1 = ($d + $ecw[$eclmaxid]) % 929;
            for ($j = $eclmaxid; $j > 0; --$j) {
                $t2 = $t1 * $ecc[$j] % 929;
                $t3 = 929 - $t2;
                $ecw[$j] = ($ecw[$j - 1] + $t3) % 929;
            }
            $t2 = $t1 * $ecc[0] % 929;
            $t3 = 929 - $t2;
            $ecw[0] = $t3 % 929;
        }
        foreach ($ecw as $j => $e) {
            if ($e != 0) {
                $ecw[$j] = 929 - $e;
            }
        }
        $ecw = array_reverse($ecw);
        return $ecw;
    }