diff --git a/src/Decoder/Decoder.php b/src/Decoder/Decoder.php index 0fab160b9..c6aab2516 100644 --- a/src/Decoder/Decoder.php +++ b/src/Decoder/Decoder.php @@ -33,6 +33,12 @@ final class Decoder{ private EccLevel|null $eccLevel = null; private MaskPattern|null $maskPattern = null; private BitBuffer $bitBuffer; + private int $topLeftX; + private int $topLeftY; + private int $topRightX; + private int $topRightY; + private int $bottomLeftX; + private int $bottomLeftY; public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){ $this->options = $options; @@ -45,7 +51,14 @@ public function __construct(SettingsContainerInterface|QROptions $options = new * @throws \Throwable|\chillerlan\QRCode\Decoder\QRCodeDecoderException */ public function decode(LuminanceSourceInterface $source):DecoderResult{ - $matrix = (new Detector($source))->detect(); + $detector = new Detector($source); + $matrix = $detector->detect(); + $this->topLeftX = $detector->topLeftX; + $this->topLeftY = $detector->topLeftY; + $this->topRightX = $detector->topRightX; + $this->topRightY = $detector->topRightY; + $this->bottomLeftX = $detector->bottomLeftX; + $this->bottomLeftY = $detector->bottomLeftY; try{ // clone the BitMatrix to avoid errors in case we run into mirroring @@ -159,6 +172,12 @@ private function decodeBitStream(BitBuffer $bitBuffer):DecoderResult{ 'maskPattern' => $this->maskPattern, 'structuredAppendParity' => $parityData, 'structuredAppendSequence' => $symbolSequence, + 'topLeftX' => $this->topLeftX, + 'topLeftY' => $this->topLeftY, + 'topRightX' => $this->topRightX, + 'topRightY' => $this->topRightY, + 'bottomLeftX' => $this->bottomLeftX, + 'bottomLeftY' => $this->bottomLeftY, ]); } diff --git a/src/Decoder/DecoderResult.php b/src/Decoder/DecoderResult.php index c79e134d3..8024398d3 100644 --- a/src/Decoder/DecoderResult.php +++ b/src/Decoder/DecoderResult.php @@ -38,6 +38,12 @@ final class DecoderResult{ private string $data = ''; private int $structuredAppendParity = -1; private int $structuredAppendSequence = -1; + private int $topLeftX; + private int $topLeftY; + private int $topRightX; + private int $topRightY; + private int $bottomLeftX; + private int $bottomLeftY; /** * DecoderResult constructor. diff --git a/src/Detector/Detector.php b/src/Detector/Detector.php index d8473f6cc..146ff3d27 100644 --- a/src/Detector/Detector.php +++ b/src/Detector/Detector.php @@ -26,6 +26,12 @@ final class Detector{ private BitMatrix $matrix; + public int $topLeftX; + public int $topLeftY; + public int $topRightX; + public int $topRightY; + public int $bottomLeftX; + public int $bottomLeftY; /** * Detector constructor. @@ -40,6 +46,13 @@ public function __construct(LuminanceSourceInterface $source){ public function detect():BitMatrix{ [$bottomLeft, $topLeft, $topRight] = (new FinderPatternFinder($this->matrix))->find(); + $this->topLeftX = (int)floor($topLeft->getX()); + $this->topLeftY = (int)floor($topLeft->getY()); + $this->topRightX = (int)ceil($topRight->getX()); + $this->topRightY = (int)floor($topRight->getY()); + $this->bottomLeftX = (int)floor($bottomLeft->getX()); + $this->bottomLeftY = (int)ceil($bottomLeft->getY()); + $moduleSize = $this->calculateModuleSize($topLeft, $topRight, $bottomLeft); $dimension = $this->computeDimension($topLeft, $topRight, $bottomLeft, $moduleSize); $provisionalVersion = new Version(intdiv(($dimension - 17), 4));