Skip to content

Commit 8d53cbe

Browse files
authored
Merge pull request #139 from GenieTim/master
Fix issue where in some cases the bits could be decoded to the neighbouring char
2 parents b331b0e + ec65809 commit 8d53cbe

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

lib/ChecksumException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class ChecksumException extends ReaderException
2727
{
2828
private static ?\Zxing\ChecksumException $instance = null;
2929

30-
public static function getChecksumInstance($cause = null): self
30+
public static function getChecksumInstance($cause = ""): self
3131
{
3232
if (self::$isStackTrace) {
3333
return new ChecksumException($cause);

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[(int)round($offset + $x)] & 0xFF) <= $threshold) {
269+
if ((((int)$luminances[(int)round($offset + $x)]) & 0xFF) <= $threshold) {
270270
$matrix->set($xoffset + $x, $yoffset + $y);
271271
}
272272
}

lib/Qrcode/Decoder/DecodedBitStreamParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ private static function decodeNumericSegment(
208208
if ($threeDigitsBits >= 1000) {
209209
throw new FormatException("Too many three digit bits");
210210
}
211-
$result .= (self::toAlphaNumericChar($threeDigitsBits / 100));
212-
$result .= (self::toAlphaNumericChar(((int)round($threeDigitsBits / 10)) % 10));
211+
$result .= (self::toAlphaNumericChar(intdiv($threeDigitsBits, 100)));
212+
$result .= (self::toAlphaNumericChar(intdiv($threeDigitsBits, 10) % 10));
213213
$result .= (self::toAlphaNumericChar($threeDigitsBits % 10));
214214
$count -= 3;
215215
}
@@ -222,7 +222,7 @@ private static function decodeNumericSegment(
222222
if ($twoDigitsBits >= 100) {
223223
throw new FormatException("Too many bits: $twoDigitsBits expected < 100");
224224
}
225-
$result .= (self::toAlphaNumericChar($twoDigitsBits / 10));
225+
$result .= (self::toAlphaNumericChar(intdiv($twoDigitsBits, 10)));
226226
$result .= (self::toAlphaNumericChar($twoDigitsBits % 10));
227227
} elseif ($count == 1) {
228228
// One digit left over to read
@@ -263,7 +263,7 @@ private static function decodeAlphanumericSegment(
263263
throw new FormatException("Not enough bits available to read two expected characters");
264264
}
265265
$nextTwoCharsBits = $bits->readBits(11);
266-
$result .= (self::toAlphaNumericChar($nextTwoCharsBits / 45));
266+
$result .= (self::toAlphaNumericChar(intdiv($nextTwoCharsBits, 45)));
267267
$result .= (self::toAlphaNumericChar($nextTwoCharsBits % 45));
268268
$count -= 2;
269269
}

0 commit comments

Comments
 (0)