:octocat: hand over finder pattern coordinates to the decoder result (#248)

This commit is contained in:
smiley
2025-06-16 18:47:48 +02:00
parent d65911ada9
commit daf01b96b2
3 changed files with 26 additions and 14 deletions
+4 -6
View File
@@ -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,
+10 -7
View File
@@ -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.
+12 -1
View File
@@ -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);