diff --git a/src/Decoder/Decoder.php b/src/Decoder/Decoder.php index 3661b682c..49035b400 100644 --- a/src/Decoder/Decoder.php +++ b/src/Decoder/Decoder.php @@ -28,17 +28,13 @@ use function chr, str_replace; */ final class Decoder{ - private SettingsContainerInterface|QROptions $options; - private Version|null $version = null; - private EccLevel|null $eccLevel = null; - private MaskPattern|null $maskPattern = null; - private BitBuffer $bitBuffer; /** @noinspection PhpPropertyOnlyWrittenInspection (currently unused) */ private SettingsContainerInterface|QROptions $options; private Version|null $version = null; private EccLevel|null $eccLevel = null; private MaskPattern|null $maskPattern = null; private BitBuffer $bitBuffer; + private Detector $detector; public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){ $this->options = $options; @@ -51,7 +47,8 @@ final class Decoder{ * @throws \Throwable|\chillerlan\QRCode\Decoder\QRCodeDecoderException */ public function decode(LuminanceSourceInterface $source):DecoderResult{ - $matrix = (new Detector($source))->detect(); + $this->detector = new Detector($source); + $matrix = $this->detector->detect(); try{ // clone the BitMatrix to avoid errors in case we run into mirroring @@ -162,6 +159,7 @@ final class Decoder{ 'data' => $result, 'version' => $this->version, 'eccLevel' => $this->eccLevel, + 'finderPatterns' => $this->detector->getFinderPatterns(), 'maskPattern' => $this->maskPattern, 'structuredAppendParity' => $parityData, 'structuredAppendSequence' => $symbolSequence, diff --git a/src/Decoder/DecoderResult.php b/src/Decoder/DecoderResult.php index c79e134d3..a683b5029 100644 --- a/src/Decoder/DecoderResult.php +++ b/src/Decoder/DecoderResult.php @@ -21,13 +21,14 @@ use function property_exists; * applies to 2D barcode formats. For now, it contains the raw bytes obtained * as well as a String interpretation of those bytes, if applicable. * - * @property \chillerlan\QRCode\Common\BitBuffer $rawBytes - * @property string $data - * @property \chillerlan\QRCode\Common\Version $version - * @property \chillerlan\QRCode\Common\EccLevel $eccLevel - * @property \chillerlan\QRCode\Common\MaskPattern $maskPattern - * @property int $structuredAppendParity - * @property int $structuredAppendSequence + * @property \chillerlan\QRCode\Common\BitBuffer $rawBytes + * @property string $data + * @property \chillerlan\QRCode\Common\Version $version + * @property \chillerlan\QRCode\Common\EccLevel $eccLevel + * @property \chillerlan\QRCode\Common\MaskPattern $maskPattern + * @property int $structuredAppendParity + * @property int $structuredAppendSequence + * @property \chillerlan\QRCode\Detector\FinderPattern[] $finderPatterns */ final class DecoderResult{ @@ -38,6 +39,8 @@ final class DecoderResult{ private string $data = ''; private int $structuredAppendParity = -1; private int $structuredAppendSequence = -1; + /** @var \chillerlan\QRCode\Detector\FinderPattern[] */ + private array $finderPatterns = []; /** * DecoderResult constructor. diff --git a/src/Detector/Detector.php b/src/Detector/Detector.php index d8473f6cc..e0aa5d0ab 100644 --- a/src/Detector/Detector.php +++ b/src/Detector/Detector.php @@ -26,6 +26,8 @@ use const NAN; final class Detector{ private BitMatrix $matrix; + /** @var \chillerlan\QRCode\Detector\FinderPattern[] */ + private array $finderPatterns = []; /** * Detector constructor. @@ -34,11 +36,20 @@ final class Detector{ $this->matrix = (new Binarizer($source))->getBlackMatrix(); } + /** + * @return \chillerlan\QRCode\Detector\FinderPattern[] + */ + public function getFinderPatterns():array{ + return $this->finderPatterns; + } + /** * Detects a QR Code in an image. */ public function detect():BitMatrix{ - [$bottomLeft, $topLeft, $topRight] = (new FinderPatternFinder($this->matrix))->find(); + $this->finderPatterns = (new FinderPatternFinder($this->matrix))->find(); + + [$bottomLeft, $topLeft, $topRight] = $this->finderPatterns; $moduleSize = $this->calculateModuleSize($topLeft, $topRight, $bottomLeft); $dimension = $this->computeDimension($topLeft, $topRight, $bottomLeft, $moduleSize);