예제 #1
0
 public function testBuildMatrix()
 {
     $bytes = array(32, 65, 205, 69, 41, 220, 46, 128, 236, 42, 159, 74, 221, 244, 169, 239, 150, 138, 70, 237, 85, 224, 96, 74, 219, 61);
     $bits = new BitArray();
     foreach ($bytes as $byte) {
         $bits->appendBits($byte, 8);
     }
     $matrix = new ByteMatrix(21, 21);
     MatrixUtil::buildMatrix($bits, new ErrorCorrectionLevel(ErrorCorrectionLevel::H), Version::getVersionForNumber(1), 3, $matrix);
     $expected = " 1 1 1 1 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1\n" . " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1\n" . " 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1\n" . " 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 1 0 1\n" . " 1 0 1 1 1 0 1 0 1 1 0 0 1 0 1 0 1 1 1 0 1\n" . " 1 0 0 0 0 0 1 0 0 0 1 1 1 0 1 0 0 0 0 0 1\n" . " 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1\n" . " 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0\n" . " 0 0 1 1 0 0 1 1 1 0 0 1 1 1 1 0 1 0 0 0 0\n" . " 1 0 1 0 1 0 0 0 0 0 1 1 1 0 0 1 0 1 1 1 0\n" . " 1 1 1 1 0 1 1 0 1 0 1 1 1 0 0 1 1 1 0 1 0\n" . " 1 0 1 0 1 1 0 1 1 1 0 0 1 1 1 0 0 1 0 1 0\n" . " 0 0 1 0 0 1 1 1 0 0 0 0 0 0 1 0 1 1 1 1 1\n" . " 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 1 0 1 1\n" . " 1 1 1 1 1 1 1 0 1 1 1 1 0 0 0 0 1 0 1 1 0\n" . " 1 0 0 0 0 0 1 0 0 0 0 1 0 1 1 1 0 0 0 0 0\n" . " 1 0 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 1\n" . " 1 0 1 1 1 0 1 0 1 1 0 1 0 0 0 0 0 1 1 1 0\n" . " 1 0 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 1 1 0 0\n" . " 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0\n" . " 1 1 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 0 1 0\n";
     $this->assertEquals($expected, $matrix->__toString());
 }
예제 #2
0
 /**
  * Sets a row of data from a BitArray.
  *
  * @param  integer  $y
  * @param  BitArray $row
  * @return void
  */
 public function setRow($y, BitArray $row)
 {
     $bits = $row->getBitArray();
     for ($i = 0; $i < $this->rowSize; $i++) {
         $this->bits[$y * $this->rowSize + $i] = $bits[$i];
     }
 }
예제 #3
0
 /**
  * Appends ECI information to a bit array.
  *
  * @param  CharacterSetEci $eci
  * @param  BitArray        $bits
  * @return void
  */
 protected static function appendEci(CharacterSetEci $eci, BitArray $bits)
 {
     $mode = new Mode(Mode::ECI);
     $bits->appendBits($mode->get(), 4);
     $bits->appendBits($eci->get(), 8);
 }
예제 #4
0
 public function testIsRange()
 {
     $array = new BitArray(64);
     $this->assertTrue($array->isRange(0, 64, false));
     $this->assertFalse($array->isRange(0, 64, true));
     $array->set(32);
     $this->assertTrue($array->isRange(32, 33, true));
     $array->set(31);
     $this->assertTrue($array->isRange(31, 33, true));
     $array->set(34);
     $this->assertFalse($array->isRange(31, 35, true));
     for ($i = 0; $i < 31; $i++) {
         $array->set($i);
     }
     $this->assertTrue($array->isRange(0, 33, true));
     for ($i = 33; $i < 64; $i++) {
         $array->set($i);
     }
     $this->assertTrue($array->isRange(0, 64, true));
     $this->assertFalse($array->isRange(0, 64, false));
 }
예제 #5
0
 /**
  * Makes an exclusive-or comparision on the current bit array.
  *
  * @param  BitArray $other
  * @return void
  * @throws Exception\InvalidArgumentException
  */
 public function xorBits(self $other)
 {
     $bitsLength = count($this->bits);
     $otherBits = $other->getBitArray();
     if ($bitsLength !== count($otherBits)) {
         throw new Exception\InvalidArgumentException('Sizes don\'t match');
     }
     for ($i = 0; $i < $bitsLength; $i++) {
         $this->bits[$i] = $this->bits[$i] ^ $otherBits[$i];
     }
 }
예제 #6
0
 /**
  * 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() . ')');
     }
 }