Example #1
0
 function createBytes(&$buffer, &$rsBlocks)
 {
     $offset = 0;
     $maxDcCount = 0;
     $maxEcCount = 0;
     $dcdata = QRCode::createNullArray(count($rsBlocks));
     $ecdata = QRCode::createNullArray(count($rsBlocks));
     for ($r = 0; $r < count($rsBlocks); $r++) {
         $dcCount = $rsBlocks[$r]->getDataCount();
         $ecCount = $rsBlocks[$r]->getTotalCount() - $dcCount;
         $maxDcCount = max($maxDcCount, $dcCount);
         $maxEcCount = max($maxEcCount, $ecCount);
         $dcdata[$r] = QRCode::createNullArray($dcCount);
         for ($i = 0; $i < count($dcdata[$r]); $i++) {
             $bdata = $buffer->getBuffer();
             $dcdata[$r][$i] = 0xff & $bdata[$i + $offset];
         }
         $offset += $dcCount;
         $rsPoly = QRUtil::getErrorCorrectPolynomial($ecCount);
         $rawPoly = new QRPolynomial($dcdata[$r], $rsPoly->getLength() - 1);
         $modPoly = $rawPoly->mod($rsPoly);
         $ecdata[$r] = QRCode::createNullArray($rsPoly->getLength() - 1);
         for ($i = 0; $i < count($ecdata[$r]); $i++) {
             $modIndex = $i + $modPoly->getLength() - count($ecdata[$r]);
             $ecdata[$r][$i] = $modIndex >= 0 ? $modPoly->get($modIndex) : 0;
         }
     }
     $totalCodeCount = 0;
     for ($i = 0; $i < count($rsBlocks); $i++) {
         $totalCodeCount += $rsBlocks[$i]->getTotalCount();
     }
     $data = QRCode::createNullArray($totalCodeCount);
     $index = 0;
     for ($i = 0; $i < $maxDcCount; $i++) {
         for ($r = 0; $r < count($rsBlocks); $r++) {
             if ($i < count($dcdata[$r])) {
                 $data[$index++] = $dcdata[$r][$i];
             }
         }
     }
     for ($i = 0; $i < $maxEcCount; $i++) {
         for ($r = 0; $r < count($rsBlocks); $r++) {
             if ($i < count($ecdata[$r])) {
                 $data[$index++] = $ecdata[$r][$i];
             }
         }
     }
     return $data;
 }