Skip to content

Commit ab0e6e1

Browse files
committed
Fix even more possible Implicit conversion from float
1 parent e94d32c commit ab0e6e1

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

lib/Common/HybridBinarizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private static function calculateBlackPoints(
146146
// finish the rest of the rows quickly
147147
for ($yy++, $offset += $width; $yy < self::$BLOCK_SIZE; $yy++, $offset += $width) {
148148
for ($xx = 0; $xx < self::$BLOCK_SIZE; $xx++) {
149-
$sum += ($luminances[$offset + $xx] & 0xFF);
149+
$sum += (((int)$luminances[(int)round($offset + $xx)]) & 0xFF);
150150
}
151151
}
152152
}

lib/Qrcode/Detector/FinderPatternFinder.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
5858
$tryHarder = $hints != null && array_key_exists('TRY_HARDER', $hints) && $hints['TRY_HARDER'];
5959
$pureBarcode = $hints != null && array_key_exists('PURE_BARCODE', $hints) && $hints['PURE_BARCODE'];
6060
$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;
6162
$maxI = $this->image->getHeight();
6263
$maxJ = $this->image->getWidth();
6364
// We are looking for black/white/black/white/black modules in
@@ -99,7 +100,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
99100
// expensive and didn't improve performance.
100101
$iSkip = 3;
101102
if ($this->hasSkipped) {
102-
$done = $this->haveMultiplyConfirmedCenters();
103+
$done = $this->haveMultiplyConfirmedCenters($allowedDeviation);
103104
} else {
104105
$rowSkip = $nrOfRowsSkippable === null ? $this->findRowSkip() : $nrOfRowsSkippable;
105106
if ($rowSkip > $stateCount[2]) {
@@ -153,7 +154,7 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
153154
$iSkip = $stateCount[0];
154155
if ($this->hasSkipped) {
155156
// Found a third one
156-
$done = $this->haveMultiplyConfirmedCenters();
157+
$done = $this->haveMultiplyConfirmedCenters($allowedDeviation);
157158
}
158159
}
159160
}
@@ -537,7 +538,7 @@ private function crossCheckDiagonal(int $startI, int $centerJ, $maxCount, int|fl
537538
/**
538539
* @return bool iff we have found at least 3 finder patterns that have been detected at least {@link #CENTER_QUORUM} times each, and, the estimated module size of the candidates is "pretty similar"
539540
*/
540-
private function haveMultiplyConfirmedCenters(): bool
541+
private function haveMultiplyConfirmedCenters(?float $allowedDeviation = 0.05): bool
541542
{
542543
$confirmedCount = 0;
543544
$totalModuleSize = 0.0;
@@ -561,7 +562,7 @@ private function haveMultiplyConfirmedCenters(): bool
561562
$totalDeviation += abs($pattern->getEstimatedModuleSize() - $average);
562563
}
563564

564-
return $totalDeviation <= 0.05 * $totalModuleSize;
565+
return $totalDeviation <= $allowedDeviation * $totalModuleSize;
565566
}
566567

567568
/**
@@ -609,7 +610,7 @@ private function selectBestPatterns()
609610
$startSize = count($this->possibleCenters);
610611
if ($startSize < 3) {
611612
// Couldn't find enough finder patterns
612-
throw new NotFoundException("Could not find 3 finder patterns");
613+
throw new NotFoundException("Could not find 3 finder patterns ($startSize found)");
613614
}
614615

615616
// Filter outlier possibilities whose module size is too different

tests/QrReaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public function testText4()
6060
$image = __DIR__ . "/qrcodes/174419877-f6b5dae1-2251-4b67-95f1-5e1143e40fae.jpg";
6161
$qrcode = new QrReader($image);
6262
$qrcode->decode([
63-
'NR_ALLOW_SKIP_ROWS' => 0
63+
'NR_ALLOW_SKIP_ROWS' => 0,
64+
'ALLOWED_DEVIATION' => 0.1
6465
]);
6566
$this->assertSame(null, $qrcode->getError());
6667
$this->assertSame("some text", $qrcode->text());

0 commit comments

Comments
 (0)