smiley 3 years ago
parent
commit
27e82de500
3 changed files with 20 additions and 9 deletions
  1. 16 5
      src/Common/MaskPattern.php
  2. 3 3
      src/Decoder/Binarizer.php
  3. 1 1
      src/Detector/Detector.php

+ 16 - 5
src/Common/MaskPattern.php

@@ -3,9 +3,10 @@
  * Class MaskPattern
  *
  * @created      19.01.2021
- * @author       smiley <smiley@chillerlan.net>
- * @copyright    2021 smiley
- * @license      MIT
+ * @author       ZXing Authors
+ * @author       Smiley <smiley@chillerlan.net>
+ * @copyright    2021 Smiley
+ * @license      Apache-2.0
  */
 
 namespace chillerlan\QRCode\Common;
@@ -20,6 +21,7 @@ use function abs, array_search, count, min;
  * ISO/IEC 18004:2000 Section 8.8.2 - Evaluation of masking results
  *
  * @see http://www.thonky.com/qr-code-tutorial/data-masking
+ * @see https://github.com/zxing/zxing/blob/e9e2bd280bcaeabd59d0f955798384fe6c018a6c/core/src/main/java/com/google/zxing/qrcode/encoder/MaskUtil.java
  */
 final class MaskPattern{
 
@@ -128,6 +130,9 @@ final class MaskPattern{
 		return self::applyRule1($matrix, $height, $width, true) + self::applyRule1($matrix, $height, $width, false);
 	}
 
+	/**
+	 *
+	 */
 	private static function applyRule1(array $matrix, int $height, int $width, bool $isHorizontal):int{
 		$penalty = 0;
 		$iLimit  = $isHorizontal ? $height : $width;
@@ -215,7 +220,7 @@ final class MaskPattern{
 					&& !$row[$x + 5]
 					&&  $row[$x + 6]
 					&& (
-						self::isWhiteHorizontal($row, $width, $x - 4, $x)
+						   self::isWhiteHorizontal($row, $width, $x - 4, $x)
 						|| self::isWhiteHorizontal($row, $width, $x + 7, $x + 11)
 					)
 				){
@@ -232,7 +237,7 @@ final class MaskPattern{
 					&& !$matrix[$y + 5][$x]
 					&&  $matrix[$y + 6][$x]
 					&& (
-						self::isWhiteVertical($matrix, $height, $x, $y - 4, $y)
+						   self::isWhiteVertical($matrix, $height, $x, $y - 4, $y)
 						|| self::isWhiteVertical($matrix, $height, $x, $y + 7, $y + 11)
 					)
 				){
@@ -245,6 +250,9 @@ final class MaskPattern{
 		return $penalties * 40;
 	}
 
+	/**
+	 *
+	 */
 	private static function isWhiteHorizontal(array $row, int $width, int $from, int $to):bool{
 
 		if($from < 0 || $width < $to){
@@ -260,6 +268,9 @@ final class MaskPattern{
 		return true;
 	}
 
+	/**
+	 *
+	 */
 	private static function isWhiteVertical(array $matrix, int $height, int $x, int $from, int $to):bool{
 
 		if($from < 0 || $height < $to){

+ 3 - 3
src/Decoder/Binarizer.php

@@ -172,7 +172,7 @@ final class Binarizer{
 			$right           = (int)(($width * 4) / 5);
 
 			for($x = (int)($width / 5); $x < $right; $x++){
-				$pixel = $localLuminances[(int)$x] & 0xff;
+				$pixel = $localLuminances[$x] & 0xff;
 				$buckets[$pixel >> self::LUMINANCE_SHIFT]++;
 			}
 		}
@@ -188,7 +188,7 @@ final class Binarizer{
 			$offset = $y * $width;
 
 			for($x = 0; $x < $width; $x++){
-				$pixel = (int)($localLuminances[$offset + $x] & 0xff);
+				$pixel = $localLuminances[$offset + $x] & 0xff;
 
 				if($pixel < $blackPoint){
 					$matrix->set($x, $y);
@@ -286,7 +286,7 @@ final class Binarizer{
 					}
 				}
 
-				$blackPoints[$y][$x] = (int)($average);
+				$blackPoints[$y][$x] = $average;
 			}
 		}
 

+ 1 - 1
src/Detector/Detector.php

@@ -162,7 +162,7 @@ final class Detector{
 		}
 
 		$otherToX = (int)($fromX + ($otherToX - $fromX) * $scale);
-		$result   += $this->sizeOfBlackWhiteBlackRun((int)$fromX, (int)$fromY, (int)$otherToX, (int)$otherToY);
+		$result   += $this->sizeOfBlackWhiteBlackRun((int)$fromX, (int)$fromY, $otherToX, $otherToY);
 
 		// Middle pixel is double-counted this way; subtract 1
 		return $result - 1.0;