Skip to content

Commit

Permalink
Merge pull request #139 from GenieTim/master
Browse files Browse the repository at this point in the history
Fix issue where in some cases the bits could be decoded to the neighbouring char
  • Loading branch information
khanamiryan authored Nov 17, 2022
2 parents b331b0e + ec65809 commit 8d53cbe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/ChecksumException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ChecksumException extends ReaderException
{
private static ?\Zxing\ChecksumException $instance = null;

public static function getChecksumInstance($cause = null): self
public static function getChecksumInstance($cause = ""): self
{
if (self::$isStackTrace) {
return new ChecksumException($cause);
Expand Down
2 changes: 1 addition & 1 deletion lib/Common/HybridBinarizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private static function thresholdBlock(
for ($y = 0, $offset = $yoffset * $stride + $xoffset; $y < self::$BLOCK_SIZE; $y++, $offset += $stride) {
for ($x = 0; $x < self::$BLOCK_SIZE; $x++) {
// Comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0.
if (($luminances[(int)round($offset + $x)] & 0xFF) <= $threshold) {
if ((((int)$luminances[(int)round($offset + $x)]) & 0xFF) <= $threshold) {
$matrix->set($xoffset + $x, $yoffset + $y);
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Qrcode/Decoder/DecodedBitStreamParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ private static function decodeNumericSegment(
if ($threeDigitsBits >= 1000) {
throw new FormatException("Too many three digit bits");
}
$result .= (self::toAlphaNumericChar($threeDigitsBits / 100));
$result .= (self::toAlphaNumericChar(((int)round($threeDigitsBits / 10)) % 10));
$result .= (self::toAlphaNumericChar(intdiv($threeDigitsBits, 100)));
$result .= (self::toAlphaNumericChar(intdiv($threeDigitsBits, 10) % 10));
$result .= (self::toAlphaNumericChar($threeDigitsBits % 10));
$count -= 3;
}
Expand All @@ -222,7 +222,7 @@ private static function decodeNumericSegment(
if ($twoDigitsBits >= 100) {
throw new FormatException("Too many bits: $twoDigitsBits expected < 100");
}
$result .= (self::toAlphaNumericChar($twoDigitsBits / 10));
$result .= (self::toAlphaNumericChar(intdiv($twoDigitsBits, 10)));
$result .= (self::toAlphaNumericChar($twoDigitsBits % 10));
} elseif ($count == 1) {
// One digit left over to read
Expand Down Expand Up @@ -263,7 +263,7 @@ private static function decodeAlphanumericSegment(
throw new FormatException("Not enough bits available to read two expected characters");
}
$nextTwoCharsBits = $bits->readBits(11);
$result .= (self::toAlphaNumericChar($nextTwoCharsBits / 45));
$result .= (self::toAlphaNumericChar(intdiv($nextTwoCharsBits, 45)));
$result .= (self::toAlphaNumericChar($nextTwoCharsBits % 45));
$count -= 2;
}
Expand Down

0 comments on commit 8d53cbe

Please sign in to comment.