🚿 some docblocks and typos

This commit is contained in:
smiley
2023-01-31 23:49:33 +01:00
parent a02012a283
commit 9c0f6ac065
17 changed files with 81 additions and 66 deletions
+2 -2
View File
@@ -19,7 +19,7 @@ use function array_fill, count, max;
* GlobalHistogramBinarizer, is fairly efficient for what it does. It is designed for
* high frequency images of barcodes with black data on white backgrounds. For this application,
* it does a much better job than a global blackpoint with severe shadows and gradients.
* However it tends to produce artifacts on lower frequency images and is therefore not
* However, it tends to produce artifacts on lower frequency images and is therefore not
* a good general purpose binarizer for uses outside ZXing.
*
* This class extends GlobalHistogramBinarizer, using the older histogram approach for 1D readers,
@@ -295,7 +295,7 @@ final class Binarizer{
/**
* For each block in the image, calculate the average black point using a 5x5 grid
* of the blocks around it. Also handles the corner cases (fractional blocks are computed based
* of the surrounding blocks. Also handles the corner cases (fractional blocks are computed based
* on the last pixels in the row/column which are also used in the previous block).
*/
private function calculateThresholdForBlock(int $subWidth, int $subHeight, int $width, int $height):BitMatrix{
+14 -20
View File
@@ -17,7 +17,7 @@ use function array_fill, count;
use const PHP_INT_MAX, PHP_INT_SIZE;
/**
*
* Extended QRMatrix to map read data from the Binarizer
*/
final class BitMatrix extends QRMatrix{
@@ -78,8 +78,6 @@ final class BitMatrix extends QRMatrix{
* This flag has effect only on the readFormatInformation() and the
* readVersion() methods. Before proceeding with readCodewords() the
* mirror() method should be called.
*
* @param bool $mirror Whether to read version and format information mirrored.
*/
public function setMirror(bool $mirror):self{
$this->version = null;
@@ -110,10 +108,9 @@ final class BitMatrix extends QRMatrix{
/**
* Reads the bits in the BitMatrix representing the finder pattern in the
* correct order in order to reconstruct the codewords bytes contained within the
* QR Code.
* QR Code. Throws if the exact number of bytes expected is not read.
*
* @return array bytes encoded within the QR Code
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException if the exact number of bytes expected is not read
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
*/
public function readCodewords():array{
@@ -172,14 +169,15 @@ final class BitMatrix extends QRMatrix{
throw new QRCodeDecoderException('result count differs from total codewords for version');
}
// bytes encoded within the QR Code
return $result;
}
/**
* Reads format information from one of its two locations within the QR Code.
* Throws if both format information locations cannot be parsed as the valid encoding of format information.
*
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException if both format information locations cannot be parsed as
* the valid encoding of format information
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
*/
private function readFormatInformation():self{
@@ -194,11 +192,11 @@ final class BitMatrix extends QRMatrix{
$formatInfoBits1 = $this->copyVersionBit($i, 8, $formatInfoBits1);
}
// .. and skip a bit in the timing pattern ...
// ... and skip a bit in the timing pattern ...
$formatInfoBits1 = $this->copyVersionBit(7, 8, $formatInfoBits1);
$formatInfoBits1 = $this->copyVersionBit(8, 8, $formatInfoBits1);
$formatInfoBits1 = $this->copyVersionBit(8, 7, $formatInfoBits1);
// .. and skip a bit in the timing pattern ...
// ... and skip a bit in the timing pattern ...
for($j = 5; $j >= 0; $j--){
$formatInfoBits1 = $this->copyVersionBit(8, $j, $formatInfoBits1);
}
@@ -252,17 +250,13 @@ final class BitMatrix extends QRMatrix{
}
/**
* @param int $maskedFormatInfo1 format info indicator, with mask still applied
* @param int $maskedFormatInfo2 second copy of same info; both are checked at the same time
* to establish best match
*
* @return int|null information about the format it specifies, or null if doesn't seem to match any known pattern
* Returns information about the format it specifies, or null if it doesn't seem to match any known pattern
*/
private function doDecodeFormatInformation(int $maskedFormatInfo1, int $maskedFormatInfo2):?int{
// Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing
$bestDifference = PHP_INT_MAX;
$bestFormatInfo = 0;
// Find the int in FORMAT_INFO_DECODE_LOOKUP with the fewest bits differing
foreach($this::DECODE_LOOKUP as $maskedBits => $dataBits){
if($maskedFormatInfo1 === $dataBits || $maskedFormatInfo2 === $dataBits){
@@ -297,9 +291,9 @@ final class BitMatrix extends QRMatrix{
/**
* Reads version information from one of its two locations within the QR Code.
* Throws if both version information locations cannot be parsed as the valid encoding of version information.
*
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException if both version information locations cannot be parsed as
* the valid encoding of version information
* @throws \chillerlan\QRCode\Decoder\QRCodeDecoderException
* @noinspection DuplicatedCode
*/
private function readVersion():self{
@@ -352,7 +346,7 @@ final class BitMatrix extends QRMatrix{
}
/**
*
* Decodes the version information from the given bit sequence, returns null if no valid match is found.
*/
private function decodeVersionInformation(int $versionBits):?Version{
$bestDifference = PHP_INT_MAX;
@@ -405,7 +399,7 @@ final class BitMatrix extends QRMatrix{
private function numBitsDiffering(int $a, int $b):int{
// a now has a 1 bit exactly where its bit differs with b's
$a ^= $b;
// Offset i holds the number of 1 bits in the binary representation of i
// Offset $i holds the number of 1-bits in the binary representation of $i
$BITS_SET_IN_HALF_BYTE = [0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4];
// Count bits set quickly with a series of lookups:
$count = 0;
+1 -1
View File
@@ -15,7 +15,7 @@ use chillerlan\QRCode\Common\{BitBuffer, EccLevel, MaskPattern, Mode, ReedSolomo
use chillerlan\QRCode\Data\{AlphaNum, Byte, ECI, Hanzi, Kanji, Number};
use chillerlan\QRCode\Detector\Detector;
use Throwable;
use function array_fill, chr, count, mb_convert_encoding, mb_detect_encoding, mb_internal_encoding, str_replace;
use function chr, mb_convert_encoding, mb_detect_encoding, mb_internal_encoding, str_replace;
/**
* The main class which implements QR Code decoding -- as opposed to locating and extracting
+3 -3
View File
@@ -17,10 +17,10 @@ use function property_exists;
/**
* Encapsulates the result of decoding a matrix of bits. This typically
* applies to 2D barcode formats. For now it contains the raw bytes obtained,
* applies to 2D barcode formats. For now, it contains the raw bytes obtained
* as well as a String interpretation of those bytes, if applicable.
*
* @property int[] $rawBytes
* @property \chillerlan\QRCode\Common\BitBuffer $rawBytes
* @property string $data
* @property \chillerlan\QRCode\Common\Version $version
* @property \chillerlan\QRCode\Common\EccLevel $eccLevel
@@ -31,10 +31,10 @@ use function property_exists;
final class DecoderResult{
private BitBuffer $rawBytes;
private string $data;
private Version $version;
private EccLevel $eccLevel;
private MaskPattern $maskPattern;
private string $data = '';
private int $structuredAppendParity = -1;
private int $structuredAppendSequence = -1;
+2 -2
View File
@@ -18,8 +18,8 @@ interface LuminanceSourceInterface{
* Fetches luminance data for the underlying bitmap. Values should be fetched using:
* `int luminance = array[y * width + x] & 0xff`
*
* @return array A row-major 2D array of luminance values. Do not use result.length as it may be
* larger than width * height bytes on some platforms. Do not modify the contents
* @return array A row-major 2D array of luminance values. Do not use result $length as it may be
* larger than $width * $height bytes on some platforms. Do not modify the contents
* of the result.
*/
public function getLuminances():array;