Exemple #1
0
 /**
  * Singleton pattern
  * 
  * @return QR_Util
  */
 public static function getInstance()
 {
     if (!self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }
Exemple #2
0
 /**
  * Create bitmap out of the bit buffer using reed solomon blocks
  *
  * @param QR_BitBuffer $buffer          
  * @param array $rsBlocks          
  * @return array
  */
 public function createBytes(QR_BitBuffer $buffer, $rsBlocks)
 {
     $offset = 0;
     $maxDcCount = 0;
     $maxEcCount = 0;
     $dcdata = QR_Util::getInstance()->createEmptyArray(sizeof($rsBlocks));
     $ecdata = QR_Util::getInstance()->createEmptyArray(sizeof($rsBlocks));
     for ($r = 0; $r < sizeof($rsBlocks); $r++) {
         $dcCount = $rsBlocks[$r]->getDataCount();
         $ecCount = $rsBlocks[$r]->getTotalCount() - $dcCount;
         $maxDcCount = max(array($maxDcCount, $dcCount));
         $maxEcCount = max(array($maxEcCount, $ecCount));
         $dcdata[$r] = QR_Util::getInstance()->createEmptyArray($dcCount);
         for ($i = 0; $i < sizeof($dcdata[$r]); $i++) {
             $dcdata[$r][$i] = 0xff & $buffer->getAt($i + $offset);
         }
         $offset += $dcCount;
         $rsPoly = QR_Util::getInstance()->getErrorCorrectPolynominal($ecCount);
         $rawPoly = new QR_Polynominal($dcdata[$r], $rsPoly->getLength() - 1);
         $modPoly = $rawPoly->mod($rsPoly);
         $ecdata[$r] = QR_Util::getInstance()->createEmptyArray($rsPoly->getLength() - 1);
         for ($i = 0; $i < sizeof($ecdata[$r]); $i++) {
             $modIndex = $i + $modPoly->getLength() - sizeof($ecdata[$r]);
             $ecdata[$r][$i] = $modIndex >= 0 ? $modPoly->get($modIndex) : 0;
         }
     }
     $totalCodeCount = 0;
     for ($i = 0; $i < sizeof($rsBlocks); $i++) {
         $totalCodeCount += $rsBlocks[$i]->getTotalCount();
     }
     $data = QR_Util::getInstance()->createEmptyArray($totalCodeCount);
     $index = 0;
     for ($i = 0; $i < $maxDcCount; $i++) {
         for ($r = 0; $r < sizeof($rsBlocks); $r++) {
             if ($i < sizeof($dcdata[$r])) {
                 $data[$index++] = $dcdata[$r][$i];
             }
         }
     }
     for ($i = 0; $i < $maxEcCount; $i++) {
         for ($r = 0; $r < sizeof($rsBlocks); $r++) {
             if ($i < sizeof($ecdata[$r])) {
                 $data[$index++] = $ecdata[$r][$i];
             }
         }
     }
     return $data;
 }
Exemple #3
0
 /**
  * Perform modulus against another polynom
  * 
  * @param QR_Polynominal $e
  * 
  * @return QR_Polynominal
  */
 public function mod(QR_Polynominal $e)
 {
     if ($this->getLength() - $e->getLength() < 0) {
         return $this;
     }
     $ratio = QR_Math::getInstance()->glog($this->get(0)) - QR_Math::getInstance()->glog($e->get(0));
     $num = QR_Util::getInstance()->createEmptyArray($this->getLength());
     for ($i = 0; $i < $this->getLength(); $i++) {
         $num[$i] = $this->get($i);
     }
     for ($i = 0; $i < $e->getLength(); $i++) {
         $num[$i] ^= QR_Math::getInstance()->gexp(QR_Math::getInstance()->glog($e->get($i)) + $ratio);
     }
     $result = new QR_Polynominal($num, 0);
     $result = $result->mod($e);
     return $result;
 }