Skip to content

Commit e94d32c

Browse files
committed
Add one more test I want to find a fix for
1 parent fbe9206 commit e94d32c

File tree

6 files changed

+20
-6
lines changed

6 files changed

+20
-6
lines changed

lib/Common/HybridBinarizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ private static function thresholdBlock(
266266
for ($y = 0, $offset = $yoffset * $stride + $xoffset; $y < self::$BLOCK_SIZE; $y++, $offset += $stride) {
267267
for ($x = 0; $x < self::$BLOCK_SIZE; $x++) {
268268
// Comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0.
269-
if (($luminances[$offset + $x] & 0xFF) <= $threshold) {
269+
if (($luminances[(int)round($offset + $x)] & 0xFF) <= $threshold) {
270270
$matrix->set($xoffset + $x, $yoffset + $y);
271271
}
272272
}

lib/Common/PerspectiveTransform.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,11 @@ public function transformPoints(array &$points, &$yValues = 0): void
173173
$x = $points[$i];
174174
$y = $points[$i + 1];
175175
$denominator = $a13 * $x + $a23 * $y + $a33;
176-
$points[$i] = ($a11 * $x + $a21 * $y + $a31) / $denominator;
177-
$points[$i + 1] = ($a12 * $x + $a22 * $y + $a32) / $denominator;
176+
// TODO: think what we do if $denominator == 0 (division by zero)
177+
if ($denominator != 0.0) {
178+
$points[$i] = ($a11 * $x + $a21 * $y + $a31) / $denominator;
179+
$points[$i + 1] = ($a12 * $x + $a22 * $y + $a32) / $denominator;
180+
}
178181
}
179182
}
180183

lib/IMagickLuminanceSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function _IMagickLuminanceSource(\Imagick $image, $width, $height): void
9898

9999
$image->setImageColorspace(\Imagick::COLORSPACE_GRAY);
100100
// Check that we actually have enough space to do it
101-
if ($width * $height * 16 * 3 > $this->kmgStringToBytes(ini_get('memory_limit'))) {
101+
if (ini_get('memory_limit') != -1 && $width * $height * 16 * 3 > $this->kmgStringToBytes(ini_get('memory_limit'))) {
102102
throw new \RuntimeException("PHP Memory Limit does not allow pixel export.");
103103
}
104104
$pixels = $image->exportImagePixels(1, 1, $width, $height, "RGB", \Imagick::PIXEL_CHAR);

lib/Qrcode/Detector/FinderPatternFinder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ private function selectBestPatterns()
609609
$startSize = count($this->possibleCenters);
610610
if ($startSize < 3) {
611611
// Couldn't find enough finder patterns
612-
throw new NotFoundException();
612+
throw new NotFoundException("Could not find 3 finder patterns");
613613
}
614614

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

tests/QrReaderTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class QrReaderTest extends TestCase
1111
public function setUp(): void
1212
{
1313
error_reporting(E_ALL);
14-
ini_set('memory_limit','2G');
14+
ini_set('memory_limit', '2G');
1515
}
1616

1717
public function testText1()
@@ -54,4 +54,15 @@ public function testText3()
5454
$this->assertSame(null, $qrcode->getError());
5555
$this->assertSame("https://www.gosuslugi.ru/covid-cert/verify/9770000014233333?lang=ru&ck=733a9d218d312fe134f1c2cc06e1a800", $qrcode->text());
5656
}
57+
58+
public function testText4()
59+
{
60+
$image = __DIR__ . "/qrcodes/174419877-f6b5dae1-2251-4b67-95f1-5e1143e40fae.jpg";
61+
$qrcode = new QrReader($image);
62+
$qrcode->decode([
63+
'NR_ALLOW_SKIP_ROWS' => 0
64+
]);
65+
$this->assertSame(null, $qrcode->getError());
66+
$this->assertSame("some text", $qrcode->text());
67+
}
5768
}
Loading

0 commit comments

Comments
 (0)