Exemplo n.º 1
0
 public function encodeMask(QRinput $input, $mask)
 {
     if ($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
         throw new Exception('wrong version');
     }
     if ($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
         throw new Exception('wrong level');
     }
     $raw = new QRrawcode($input);
     QRtools::markTime('after_raw');
     $version = $raw->version;
     $width = QRspec::getWidth($version);
     $frame = QRspec::newFrame($version);
     $filler = new FrameFiller($width, $frame);
     if (is_null($filler)) {
         return null;
     }
     // inteleaved data and ecc codes
     for ($i = 0; $i < $raw->dataLength + $raw->eccLength; $i++) {
         $code = $raw->getCode();
         $bit = 0x80;
         for ($j = 0; $j < 8; $j++) {
             $addr = $filler->next();
             $filler->setFrameAt($addr, 0x2 | ($bit & $code) != 0);
             $bit = $bit >> 1;
         }
     }
     QRtools::markTime('after_filler');
     unset($raw);
     // remainder bits
     $j = QRspec::getRemainder($version);
     for ($i = 0; $i < $j; $i++) {
         $addr = $filler->next();
         $filler->setFrameAt($addr, 0x2);
     }
     $frame = $filler->frame;
     unset($filler);
     // masking
     $maskObj = new QRmask();
     if ($mask < 0) {
         if (QR_FIND_BEST_MASK) {
             $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
         } else {
             $masked = $maskObj->makeMask($width, $frame, (int) QR_DEFAULT_MASK % 8, $input->getErrorCorrectionLevel());
         }
     } else {
         $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
     }
     if ($masked == null) {
         return null;
     }
     QRtools::markTime('after_mask');
     $this->version = $version;
     $this->width = $width;
     $this->data = $masked;
     return $this;
 }
Exemplo n.º 2
0
 public static function buildCache()
 {
     QRtools::markTime('before_build_cache');
     $mask = new QRmask();
     for ($a = 1; $a <= QRSPEC_VERSION_MAX; $a++) {
         $frame = QRspec::newFrame($a);
         if (QR_IMAGE) {
             $fileName = QR_CACHE_DIR . 'frame_' . $a . '.png';
             QRimage::png(self::binarize($frame), $fileName, 1, 0);
         }
         $width = count($frame);
         $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
         for ($maskNo = 0; $maskNo < 8; $maskNo++) {
             $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
         }
     }
     QRtools::markTime('after_build_cache');
 }