Skip to content

Commit daf01b9

Browse files
committed
:octocat: hand over finder pattern coordinates to the decoder result (#248)
1 parent d65911a commit daf01b9

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

src/Decoder/Decoder.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,13 @@
2828
*/
2929
final class Decoder{
3030

31-
private SettingsContainerInterface|QROptions $options;
32-
private Version|null $version = null;
33-
private EccLevel|null $eccLevel = null;
34-
private MaskPattern|null $maskPattern = null;
35-
private BitBuffer $bitBuffer;
3631
/** @noinspection PhpPropertyOnlyWrittenInspection (currently unused) */
3732
private SettingsContainerInterface|QROptions $options;
3833
private Version|null $version = null;
3934
private EccLevel|null $eccLevel = null;
4035
private MaskPattern|null $maskPattern = null;
4136
private BitBuffer $bitBuffer;
37+
private Detector $detector;
4238

4339
public function __construct(SettingsContainerInterface|QROptions $options = new QROptions){
4440
$this->options = $options;
@@ -51,7 +47,8 @@ public function __construct(SettingsContainerInterface|QROptions $options = new
5147
* @throws \Throwable|\chillerlan\QRCode\Decoder\QRCodeDecoderException
5248
*/
5349
public function decode(LuminanceSourceInterface $source):DecoderResult{
54-
$matrix = (new Detector($source))->detect();
50+
$this->detector = new Detector($source);
51+
$matrix = $this->detector->detect();
5552

5653
try{
5754
// clone the BitMatrix to avoid errors in case we run into mirroring
@@ -162,6 +159,7 @@ private function decodeBitStream(BitBuffer $bitBuffer):DecoderResult{
162159
'data' => $result,
163160
'version' => $this->version,
164161
'eccLevel' => $this->eccLevel,
162+
'finderPatterns' => $this->detector->getFinderPatterns(),
165163
'maskPattern' => $this->maskPattern,
166164
'structuredAppendParity' => $parityData,
167165
'structuredAppendSequence' => $symbolSequence,

src/Decoder/DecoderResult.php

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

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

4245
/**
4346
* DecoderResult constructor.

src/Detector/Detector.php

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

2828
private BitMatrix $matrix;
29+
/** @var \chillerlan\QRCode\Detector\FinderPattern[] */
30+
private array $finderPatterns = [];
2931

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

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

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

0 commit comments

Comments
 (0)