function rsCode($code) { if ($code && strlen($code) == 10) { $data = array(); $rs_code = array(); for ($i = 0; $i < RS_TOTAL_LEN; $i++) { if ($i < RS_DATA_LEN) { $data[] = char_to_num($code[$i]); } else { $data[] = 0; } } $qRrs = new QRrs(); $rs = $qRrs->init_rs(RS_SYMSIZE, RS_GFPOLY, RS_FCR, RS_PRIM, RS_NROOTS, RS_PAD); $newcode =& $data[RS_DATA_LEN]; $qRrsItem = new QRrsItem(); $res = $qRrsItem->encode_rs_char($rs, $data, $newcode); for ($i = 0; $i < RS_DATA_LEN; $i++) { $rs_code[] = num_to_char($data[$i]); } for ($i = 0; $i < count($res); $i++) { $rs_code[] = num_to_char($res[$i]); } $newrs_code = ''; for ($i = 0; $i < count($rs_code); $i++) { $newrs_code .= $rs_code[$i]; } // $newrs_code .= '\0'; return $newrs_code; } return null; }
public function init(array $spec) { $dl = QRspec::rsDataCodes1($spec); $el = QRspec::rsEccCodes1($spec); $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); $blockNo = 0; $dataPos = 0; $eccPos = 0; for ($i = 0; $i < QRspec::rsBlockNum1($spec); $i++) { $ecc = array_slice($this->ecccode, $eccPos); $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); $dataPos += $dl; $eccPos += $el; $blockNo++; } if (QRspec::rsBlockNum2($spec) == 0) { return 0; } $dl = QRspec::rsDataCodes2($spec); $el = QRspec::rsEccCodes2($spec); $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); if ($rs == NULL) { return -1; } for ($i = 0; $i < QRspec::rsBlockNum2($spec); $i++) { $ecc = array_slice($this->ecccode, $eccPos); $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc); $dataPos += $dl; $eccPos += $el; $blockNo++; } return 0; }