@@ -58,7 +58,8 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
58
58
$ tryHarder = $ hints != null && array_key_exists ('TRY_HARDER ' , $ hints ) && $ hints ['TRY_HARDER ' ];
59
59
$ pureBarcode = $ hints != null && array_key_exists ('PURE_BARCODE ' , $ hints ) && $ hints ['PURE_BARCODE ' ];
60
60
$ nrOfRowsSkippable = $ hints != null && array_key_exists ('NR_ALLOW_SKIP_ROWS ' , $ hints ) ? $ hints ['NR_ALLOW_SKIP_ROWS ' ] : ($ tryHarder ? 0 : null );
61
- $ allowedDeviation = $ hints != null && array_key_exists ('ALLOWED_DEVIATION ' , $ hints ) ? $ hints ['ALLOWED_DEVIATION ' ] : null ;
61
+ $ allowedDeviation = $ hints != null && array_key_exists ('ALLOWED_DEVIATION ' , $ hints ) ? $ hints ['ALLOWED_DEVIATION ' ] : 0.05 ;
62
+ $ maxVariance = $ hints != null && array_key_exists ('MAX_VARIANCE ' , $ hints ) ? $ hints ['MAX_VARIANCE ' ] : 0.5 ;
62
63
$ maxI = $ this ->image ->getHeight ();
63
64
$ maxJ = $ this ->image ->getWidth ();
64
65
// We are looking for black/white/black/white/black modules in
@@ -93,7 +94,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
93
94
} else { // White pixel
94
95
if (($ currentState & 1 ) == 0 ) { // Counting black pixels
95
96
if ($ currentState == 4 ) { // A winner?
96
- if (self ::foundPatternCross ($ stateCount )) { // Yes
97
+ if (self ::foundPatternCross ($ stateCount, $ maxVariance )) { // Yes
97
98
$ confirmed = $ this ->handlePossibleCenter ($ stateCount , $ i , $ j , $ pureBarcode );
98
99
if ($ confirmed ) {
99
100
// Start examining every other line. Checking each line turned out to be too
@@ -148,7 +149,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
148
149
}
149
150
}
150
151
}
151
- if (self ::foundPatternCross ($ stateCount )) {
152
+ if (self ::foundPatternCross ($ stateCount, $ maxVariance )) {
152
153
$ confirmed = $ this ->handlePossibleCenter ($ stateCount , $ i , $ maxJ , $ pureBarcode );
153
154
if ($ confirmed ) {
154
155
$ iSkip = $ stateCount [0 ];
@@ -174,7 +175,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
174
175
*
175
176
* @psalm-param array<0|positive-int, int> $stateCount
176
177
*/
177
- protected static function foundPatternCross (array $ stateCount ): bool
178
+ protected static function foundPatternCross (array $ stateCount, float $ maxVariance = 0.5 ): bool
178
179
{
179
180
$ totalModuleSize = 0 ;
180
181
for ($ i = 0 ; $ i < 5 ; $ i ++) {
@@ -188,7 +189,7 @@ protected static function foundPatternCross(array $stateCount): bool
188
189
return false ;
189
190
}
190
191
$ moduleSize = $ totalModuleSize / 7.0 ;
191
- $ maxVariance = $ moduleSize / 2.0 ;
192
+ $ maxVariance = $ moduleSize * $ maxVariance ;
192
193
193
194
// Allow less than 50% variance from 1-1-3-1-1 proportions
194
195
return
0 commit comments