Skip to content

Commit 75a2918

Browse files
committed
:octocat: hand over finder pattern coordinates to the decoder result (#248)
(cherry picked from commit daf01b9)
1 parent 07250c4 commit 75a2918

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/Decoder/Decoder.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ final class Decoder{
2929
private ?EccLevel $eccLevel = null;
3030
private ?MaskPattern $maskPattern = null;
3131
private BitBuffer $bitBuffer;
32+
private Detector $detector;
3233

3334
/**
3435
* Decodes a QR Code represented as a BitMatrix.
@@ -37,7 +38,8 @@ final class Decoder{
3738
* @throws \Throwable|\chillerlan\QRCode\Decoder\QRCodeDecoderException
3839
*/
3940
public function decode(LuminanceSourceInterface $source):DecoderResult{
40-
$matrix = (new Detector($source))->detect();
41+
$this->detector = new Detector($source);
42+
$matrix = $this->detector->detect();
4143

4244
try{
4345
// clone the BitMatrix to avoid errors in case we run into mirroring
@@ -148,6 +150,7 @@ private function decodeBitStream(BitBuffer $bitBuffer):DecoderResult{
148150
'data' => $result,
149151
'version' => $this->version,
150152
'eccLevel' => $this->eccLevel,
153+
'finderPatterns' => $this->detector->getFinderPatterns(),
151154
'maskPattern' => $this->maskPattern,
152155
'structuredAppendParity' => $parityData,
153156
'structuredAppendSequence' => $symbolSequence,

src/Decoder/DecoderResult.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
* applies to 2D barcode formats. For now, it contains the raw bytes obtained
2121
* as well as a String interpretation of those bytes, if applicable.
2222
*
23-
* @property \chillerlan\QRCode\Common\BitBuffer $rawBytes
24-
* @property string $data
25-
* @property \chillerlan\QRCode\Common\Version $version
26-
* @property \chillerlan\QRCode\Common\EccLevel $eccLevel
27-
* @property \chillerlan\QRCode\Common\MaskPattern $maskPattern
28-
* @property int $structuredAppendParity
29-
* @property int $structuredAppendSequence
23+
* @property \chillerlan\QRCode\Common\BitBuffer $rawBytes
24+
* @property string $data
25+
* @property \chillerlan\QRCode\Common\Version $version
26+
* @property \chillerlan\QRCode\Common\EccLevel $eccLevel
27+
* @property \chillerlan\QRCode\Common\MaskPattern $maskPattern
28+
* @property int $structuredAppendParity
29+
* @property int $structuredAppendSequence
30+
* @property \chillerlan\QRCode\Detector\FinderPattern[] $finderPatterns
3031
*/
3132
final class DecoderResult{
3233

@@ -37,6 +38,8 @@ final class DecoderResult{
3738
private string $data = '';
3839
private int $structuredAppendParity = -1;
3940
private int $structuredAppendSequence = -1;
41+
/** @var \chillerlan\QRCode\Detector\FinderPattern[] */
42+
private array $finderPatterns = [];
4043

4144
/**
4245
* DecoderResult constructor.

src/Detector/Detector.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
final class Detector{
2626

2727
private BitMatrix $matrix;
28+
/** @var \chillerlan\QRCode\Detector\FinderPattern[] */
29+
private array $finderPatterns = [];
2830

2931
/**
3032
* Detector constructor.
@@ -33,11 +35,20 @@ public function __construct(LuminanceSourceInterface $source){
3335
$this->matrix = (new Binarizer($source))->getBlackMatrix();
3436
}
3537

38+
/**
39+
* @return \chillerlan\QRCode\Detector\FinderPattern[]
40+
*/
41+
public function getFinderPatterns():array{
42+
return $this->finderPatterns;
43+
}
44+
3645
/**
3746
* Detects a QR Code in an image.
3847
*/
3948
public function detect():BitMatrix{
40-
[$bottomLeft, $topLeft, $topRight] = (new FinderPatternFinder($this->matrix))->find();
49+
$this->finderPatterns = (new FinderPatternFinder($this->matrix))->find();
50+
51+
[$bottomLeft, $topLeft, $topRight] = $this->finderPatterns;
4152

4253
$moduleSize = $this->calculateModuleSize($topLeft, $topRight, $bottomLeft);
4354
$dimension = $this->computeDimension($topLeft, $topRight, $bottomLeft, $moduleSize);

0 commit comments

Comments
 (0)