From 27e82de5003ae8866939ba60d8f1aee08a3e4486 Mon Sep 17 00:00:00 2001 From: smiley Date: Fri, 13 May 2022 21:43:20 +0200 Subject: [PATCH] :shower: --- src/Common/MaskPattern.php | 21 ++++++++++++++++----- src/Decoder/Binarizer.php | 6 +++--- src/Detector/Detector.php | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/Common/MaskPattern.php b/src/Common/MaskPattern.php index 810797ed5..23e569562 100644 --- a/src/Common/MaskPattern.php +++ b/src/Common/MaskPattern.php @@ -3,9 +3,10 @@ * Class MaskPattern * * @created 19.01.2021 - * @author smiley - * @copyright 2021 smiley - * @license MIT + * @author ZXing Authors + * @author Smiley + * @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){ diff --git a/src/Decoder/Binarizer.php b/src/Decoder/Binarizer.php index 2a6f6d085..f6bf11f7b 100644 --- a/src/Decoder/Binarizer.php +++ b/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; } } diff --git a/src/Detector/Detector.php b/src/Detector/Detector.php index 78694476f..5f8f0f45f 100644 --- a/src/Detector/Detector.php +++ b/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;