Esempio n. 1
0
 public static function getInstance()
 {
     if (!isset(self::$iInstance)) {
         $c = __CLASS__;
         self::$iInstance = new $c();
     }
     return self::$iInstance;
 }
Esempio n. 2
0
 function Tst13Pattern()
 {
     $mask = QRMask::getInstance();
     $mask->_setDbgLevel(2);
     $n = 11;
     $m = array();
     for ($i = 0; $i < $n; ++$i) {
         $m[$i] = array_fill(0, $n, QRMatrixLayout::ZERO);
     }
     $pattern = array(QRMatrixLayout::ONE, QRMatrixLayout::ZERO, QRMatrixLayout::ONE, QRMatrixLayout::ONE, QRMatrixLayout::ONE, QRMatrixLayout::ZERO, QRMatrixLayout::ZERO, QRMatrixLayout::ONE);
     for ($j = 0; $j < count($pattern); ++$j) {
         $m[$j + 2][1] = $pattern[$j];
     }
     $val = $mask->_eval11311Pattern($m, $n, false);
     echo $this->fmtInfo("Result: \n" . $mask . "\n");
 }
Esempio n. 3
0
 function selectApplyMask()
 {
     $mask = QRMask::getInstance();
     // For special purposes (mainly verification) we can override the automatic
     // selection of a mask pattern and force the mask to to be a selected one by
     // storing that index in iForcedMaskIdx instance variable
     if ($this->iForcedMaskIdx >= 0) {
         $maskidx = $this->iForcedMaskIdx;
         $this->_dbgInfo(1, "  Selected FORCED Mask {$maskidx} \n");
     } else {
         $maskidx = -1;
         // Try all 8 masks on the matrix in turn and select the one which
         // gives the lowest penalty score when the mask is evaluted
         $score = array();
         $minscore = 100000;
         // Dummy inital value
         $this->_dbgInfo(2, "Evaluating different layout matrix masks \n");
         $this->_dbgInfo(2, "------------------------------------------\n");
         for ($i = 0; $i < 8; ++$i) {
             // We must use a temp variable since applyMaskAndEval is call by reference
             // and will destroy the parameter
             $tmp = $this->iMatrix;
             $mask->applyMask($tmp, $i);
             $this->addFormatInfo($tmp, $i);
             $score = $mask->evaluate($tmp, $i);
             $this->_dbgInfo(2, "Evaluated mask nr {$i} score={$score} \n");
             if ($score < $minscore) {
                 $minscore = $score;
                 $maskidx = $i;
             }
         }
         $this->_dbgInfo(2, "SELECTED Mask {$maskidx}, score = {$minscore} \n");
     }
     $mask->applyMask($this->iMatrix, $maskidx);
     $this->addFormatInfo($this->iMatrix, $maskidx);
     $this->iMaskIdx = $maskidx;
     return $maskidx;
 }
Esempio n. 4
0
 function __construct($aVersion = -1, $aErrLevel = QRCapacity::ErrM)
 {
     $this->SetSize($aVersion);
     // If error level is set < 0 this is interpretated as that the user
     // wants us to choose the level of error redundancy.
     if ($aErrLevel < 0) {
         if ($aVersion > 30) {
             $aErrLevel = QRCapacity::ErrH;
             // Use more error redundancy for large data
             $this->iGeneralInfo .= "Automatically set error level to H\n";
         } elseif ($aVersion > 20) {
             $aErrLevel = QRCapacity::ErrQ;
             // Use more error redundancy for large data
             $this->iGeneralInfo .= "Automatically set error level to Q\n";
         } else {
             $aErrLevel = QRCapacity::ErrM;
             $this->iGeneralInfo .= "Automatically set error level to M\n";
         }
     }
     $this->iErrLevel = $aErrLevel;
     // Initialize translation table for alphanumeric
     for ($i = 0; $i < 10; ++$i) {
         $this->iAlphaNumTable[ord('0') + $i] = $i;
     }
     for ($i = 0; $i < 26; ++$i) {
         $this->iAlphaNumTable[ord('A') + $i] = 10 + $i;
     }
     $punct = array(ord(' ') => 36, ord('$') => 37, ord('%') => 38, ord('*') => 39, ord('+') => 40, ord('-') => 41, ord('.') => 42, ord('/') => 43, ord(':') => 44);
     $this->iAlphaNumTable = $this->iAlphaNumTable + $punct;
     foreach ($this->iAlphaNumTable as $key => $val) {
         $this->iAlphaNumInvTable[$val] = $key;
     }
     $this->iQRCapacity = QRCapacity::getInstance();
     $this->iQRMask = QRMask::getInstance();
 }