mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-24 12:17:57 +00:00
:octocat: hand over finder pattern coordinates to the decoder result (#248)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user