コード例 #1
0
ファイル: MaskUtilTest.php プロジェクト: jumong/BaconQrCode
 /**
  * @dataProvider dataMaskBitProvider
  * @param        integer $maskPattern
  * @param        array   $expected
  * @return       void
  */
 public function testGetDatMaskBit($maskPattern, array $expected)
 {
     for ($x = 0; $x < 6; $x++) {
         for ($y = 0; $y < 6; $y++) {
             if (($expected[$y][$x] === 1) !== MaskUtil::getDataMaskBit($maskPattern, $x, $y)) {
                 $this->fail('Data mask bit did not match');
             }
         }
     }
 }
コード例 #2
0
ファイル: MatrixUtil.php プロジェクト: jumong/BaconQrCode
 /**
  * Embeds "dataBits" using "getMaskPattern".
  *
  *  For debugging purposes, it skips masking process if "getMaskPattern" is
  * -1. See 8.7 of JISX0510:2004 (p.38) for how to embed data bits.
  *
  * @param  BitArray   $dataBits
  * @param  integer    $maskPattern
  * @param  ByteMatrix $matrix
  * @return void
  * @throws Exception\WriterException
  */
 protected static function embedDataBits(BitArray $dataBits, $maskPattern, ByteMatrix $matrix)
 {
     $bitIndex = 0;
     $direction = -1;
     // Start from the right bottom cell.
     $x = $matrix->getWidth() - 1;
     $y = $matrix->getHeight() - 1;
     while ($x > 0) {
         // Skip vertical timing pattern.
         if ($x === 6) {
             $x--;
         }
         while ($y >= 0 && $y < $matrix->getHeight()) {
             for ($i = 0; $i < 2; $i++) {
                 $xx = $x - $i;
                 // Skip the cell if it's not empty.
                 if ($matrix->get($xx, $y) !== -1) {
                     continue;
                 }
                 if ($bitIndex < $dataBits->getSize()) {
                     $bit = $dataBits->get($bitIndex);
                     $bitIndex++;
                 } else {
                     // Padding bit. If there is no bit left, we'll fill the
                     // left cells with 0, as described in 8.4.9 of
                     // JISX0510:2004 (p. 24).
                     $bit = false;
                 }
                 // Skip masking if maskPattern is -1.
                 if ($maskPattern !== -1 && MaskUtil::getDataMaskBit($maskPattern, $xx, $y)) {
                     $bit = !$bit;
                 }
                 $matrix->set($xx, $y, $bit);
             }
             $y += $direction;
         }
         $direction = -$direction;
         $y += $direction;
         $x -= 2;
     }
     // All bits should be consumed
     if ($bitIndex !== $dataBits->getSize()) {
         throw new Exception\WriterException('Not all bits consumed (' . $bitIndex . ' out of ' . $dataBits->getSize() . ')');
     }
 }