Ejemplo n.º 1
0
 /**
  * @param $version
  *
  * @return float|int|mixed
  */
 public function estimateBitStreamSizeOfEntry($version)
 {
     if ($version == 0) {
         $version = 1;
     }
     switch ($this->mode) {
         case Enum::QR_MODE_NUM:
             $bits = Input::estimateBitsModeNum($this->size);
             break;
         case Enum::QR_MODE_AN:
             $bits = Input::estimateBitsModeAn($this->size);
             break;
         case Enum::QR_MODE_8:
             $bits = Input::estimateBitsMode8($this->size);
             break;
         case Enum::QR_MODE_KANJI:
             $bits = Input::estimateBitsModeKanji($this->size);
             break;
         case Enum::QR_MODE_STRUCTURE:
             return Enum::STRUCTURE_HEADER_BITS;
         default:
             return 0;
     }
     $l = Specifications::lengthIndicator($this->mode, $version);
     $m = 1 << $l;
     $num = (int) (($this->size + $m - 1) / $m);
     $bits += $num * (4 + $l);
     return $bits;
 }
Ejemplo n.º 2
0
 /**
  * @return int
  */
 public function eat8()
 {
     $la = Specifications::lengthIndicator(Enum::QR_MODE_AN, $this->input->getVersion());
     $ln = Specifications::lengthIndicator(Enum::QR_MODE_NUM, $this->input->getVersion());
     $p = 1;
     $dataStrLen = strlen($this->dataStr);
     while ($p < $dataStrLen) {
         $mode = $this->identifyMode($p);
         if ($mode == Enum::QR_MODE_KANJI) {
             break;
         }
         if ($mode == Enum::QR_MODE_NUM) {
             $q = $p;
             while (static::isDigitAt($this->dataStr, $q)) {
                 $q++;
             }
             $dif = Input::estimateBitsMode8($p) + Input::estimateBitsModeNum($q - $p) + 4 + $ln - Input::estimateBitsMode8($q);
             // - 4 - l8
             if ($dif < 0) {
                 break;
             } else {
                 $p = $q;
             }
         } else {
             if ($mode == Enum::QR_MODE_AN) {
                 $q = $p;
                 while (static::isAlNumAt($this->dataStr, $q)) {
                     $q++;
                 }
                 $dif = Input::estimateBitsMode8($p) + Input::estimateBitsModeAn($q - $p) + 4 + $la - Input::estimateBitsMode8($q);
                 // - 4 - l8
                 if ($dif < 0) {
                     break;
                 } else {
                     $p = $q;
                 }
             } else {
                 $p++;
             }
         }
     }
     $run = $p;
     $ret = $this->input->append(Enum::QR_MODE_8, $run, str_split($this->dataStr));
     if ($ret < 0) {
         return -1;
     }
     return $run;
 }
Ejemplo n.º 3
0
 /**
  * @param $mode
  * @param $version
  * @param $bits
  *
  * @return int
  */
 public static function lengthOfCode($mode, $version, $bits)
 {
     $payload = $bits - 4 - Specifications::lengthIndicator($mode, $version);
     switch ($mode) {
         case Enum::QR_MODE_NUM:
             $chunks = (int) ($payload / 10);
             $remain = $payload - $chunks * 10;
             $size = $chunks * 3;
             if ($remain >= 7) {
                 $size += 2;
             } else {
                 if ($remain >= 4) {
                     $size += 1;
                 }
             }
             break;
         case Enum::QR_MODE_AN:
             $chunks = (int) ($payload / 11);
             $remain = $payload - $chunks * 11;
             $size = $chunks * 2;
             if ($remain >= 6) {
                 $size++;
             }
             break;
         case Enum::QR_MODE_8:
             $size = (int) ($payload / 8);
             break;
         case Enum::QR_MODE_KANJI:
             $size = (int) ($payload / 13 * 2);
             break;
         case Enum::QR_MODE_STRUCTURE:
             $size = (int) ($payload / 8);
             break;
         default:
             $size = 0;
             break;
     }
     $maxsize = Specifications::maximumWords($mode, $version);
     if ($size < 0) {
         $size = 0;
     }
     if ($size > $maxsize) {
         $size = $maxsize;
     }
     return $size;
 }