From eb33b62a51b1ea51fa585306e6852e70cea96ed7 Mon Sep 17 00:00:00 2001 From: codemasher Date: Mon, 29 Nov 2021 19:08:00 +0100 Subject: [PATCH] :shower: --- src/Decoder/Binarizer.php | 2 +- src/Decoder/Decoder.php | 3 +-- src/Detector/Detector.php | 7 ++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Decoder/Binarizer.php b/src/Decoder/Binarizer.php index a148703e3..bed797d04 100644 --- a/src/Decoder/Binarizer.php +++ b/src/Decoder/Binarizer.php @@ -160,7 +160,7 @@ final class Binarizer{ /** * */ - public function getHistogramBlackMatrix(int $width, int $height):BitMatrix{ + private function getHistogramBlackMatrix(int $width, int $height):BitMatrix{ $matrix = new BitMatrix(max($width, $height)); // Quickly calculates the histogram by sampling four rows from the image. This proved to be diff --git a/src/Decoder/Decoder.php b/src/Decoder/Decoder.php index b7b55ed5c..d99f7b9c8 100644 --- a/src/Decoder/Decoder.php +++ b/src/Decoder/Decoder.php @@ -37,8 +37,7 @@ final class Decoder{ * @throws \Throwable if the QR Code cannot be decoded */ public function decode(LuminanceSourceInterface $source):DecoderResult{ - $matrix = (new Binarizer($source))->getBlackMatrix(); - $bitMatrix = (new Detector($matrix))->detect(); + $bitMatrix = (new Detector($source))->detect(); try{ // clone the BitMatrix to avoid errors in case we run into mirroring diff --git a/src/Detector/Detector.php b/src/Detector/Detector.php index 46dba837a..d8a56695e 100644 --- a/src/Detector/Detector.php +++ b/src/Detector/Detector.php @@ -11,6 +11,7 @@ namespace chillerlan\QRCode\Detector; +use chillerlan\QRCode\Decoder\{Binarizer, LuminanceSourceInterface}; use RuntimeException; use chillerlan\QRCode\Common\Version; use chillerlan\QRCode\Decoder\BitMatrix; @@ -30,8 +31,8 @@ final class Detector{ /** * Detector constructor. */ - public function __construct(BitMatrix $image){ - $this->bitMatrix = $image; + public function __construct(LuminanceSourceInterface $source){ + $this->bitMatrix = (new Binarizer($source))->getBlackMatrix(); } /** @@ -40,7 +41,7 @@ final class Detector{ public function detect():BitMatrix{ [$bottomLeft, $topLeft, $topRight] = (new FinderPatternFinder($this->bitMatrix))->find(); - $moduleSize = (float)$this->calculateModuleSize($topLeft, $topRight, $bottomLeft); + $moduleSize = $this->calculateModuleSize($topLeft, $topRight, $bottomLeft); $dimension = $this->computeDimension($topLeft, $topRight, $bottomLeft, $moduleSize); $provisionalVersion = new Version((int)(($dimension - 17) / 4)); $alignmentPattern = null;