Documentation

MaskPattern
in package

FinalYes

ISO/IEC 18004:2000 Section 8.8.1 ISO/IEC 18004:2000 Section 8.8.2 - Evaluation of masking results

Tags
see
http://www.thonky.com/qr-code-tutorial/data-masking
see
https://github.com/zxing/zxing/blob/e9e2bd280bcaeabd59d0f955798384fe6c018a6c/core/src/main/java/com/google/zxing/qrcode/encoder/MaskUtil.java

Table of Contents

Constants

AUTO  = -1
PATTERN_000  = 0b0
PATTERN_001  = 0b1
PATTERN_010  = 0b10
PATTERN_011  = 0b11
PATTERN_100  = 0b100
PATTERN_101  = 0b101
PATTERN_110  = 0b110
PATTERN_111  = 0b111
PATTERNS  = [self::PATTERN_000, self::PATTERN_001, self::PATTERN_010, self::PATTERN_011, self::PATTERN_100, self::PATTERN_101, self::PATTERN_110, self::PATTERN_111]
PENALTY_N1  = 3
PENALTY_N2  = 3
PENALTY_N3  = 40
PENALTY_N4  = 10

Properties

$maskPattern  : int
The current mask pattern value (0-7)

Methods

__construct()  : mixed
MaskPattern constructor.
getBestPattern()  : self
Evaluates the matrix of the given data interface and returns a new mask pattern instance for the best result
getMask()  : Closure
Returns a closure that applies the mask for the chosen mask pattern.
getPattern()  : int
Returns the current mask pattern
testRule1()  : int
Apply mask penalty rule 1 and return the penalty. Find repetitive cells with the same color and give penalty to them. Example: 00000 or 11111.
testRule2()  : int
Apply mask penalty rule 2 and return the penalty. Find 2x2 blocks with the same color and give penalty to them. This is actually equivalent to the spec's rule, which is to find MxN blocks and give a penalty proportional to (M-1)x(N-1), because this is the number of 2x2 blocks inside such a block.
testRule3()  : int
Apply mask penalty rule 3 and return the penalty. Find consecutive runs of 1:1:3:1:1:4 starting with black, or 4:1:1:3:1:1 starting with white, and give penalty to them. If we find patterns like 000010111010000, we give penalty once.
testRule4()  : int
Apply mask penalty rule 4 and return the penalty. Calculate the ratio of dark cells and give penalty if the ratio is far from 50%. It gives 10 penalty for 5% distance.
applyRule1()  : int
isWhiteHorizontal()  : bool
isWhiteVertical()  : bool

Constants

PATTERNS

public array<string|int, int> PATTERNS = [self::PATTERN_000, self::PATTERN_001, self::PATTERN_010, self::PATTERN_011, self::PATTERN_100, self::PATTERN_101, self::PATTERN_110, self::PATTERN_111]

Properties

$maskPattern

The current mask pattern value (0-7)

private int $maskPattern

Methods

__construct()

MaskPattern constructor.

public __construct(int $maskPattern) : mixed
Parameters
$maskPattern : int
Tags
throws
QRCodeException

getBestPattern()

Evaluates the matrix of the given data interface and returns a new mask pattern instance for the best result

public static getBestPattern(QRMatrix $QRMatrix) : self
Parameters
$QRMatrix : QRMatrix
Return values
self

getMask()

Returns a closure that applies the mask for the chosen mask pattern.

public getMask() : Closure

Note that the diagram in section 6.8.1 is misleading since it indicates that $i is column position and $j is row position. In fact, as the text says, $i is row position and $j is column position.

Tags
see
https://www.thonky.com/qr-code-tutorial/mask-patterns
see
https://github.com/zxing/zxing/blob/e9e2bd280bcaeabd59d0f955798384fe6c018a6c/core/src/main/java/com/google/zxing/qrcode/decoder/DataMask.java#L32-L117
Return values
Closure

getPattern()

Returns the current mask pattern

public getPattern() : int
Return values
int

testRule1()

Apply mask penalty rule 1 and return the penalty. Find repetitive cells with the same color and give penalty to them. Example: 00000 or 11111.

public static testRule1(array<string|int, array<string|int, bool>> $matrix, int $height, int $width) : int
Parameters
$matrix : array<string|int, array<string|int, bool>>
$height : int
$width : int
Return values
int

testRule2()

Apply mask penalty rule 2 and return the penalty. Find 2x2 blocks with the same color and give penalty to them. This is actually equivalent to the spec's rule, which is to find MxN blocks and give a penalty proportional to (M-1)x(N-1), because this is the number of 2x2 blocks inside such a block.

public static testRule2(array<string|int, array<string|int, bool>> $matrix, int $height, int $width) : int
Parameters
$matrix : array<string|int, array<string|int, bool>>
$height : int
$width : int
Return values
int

testRule3()

Apply mask penalty rule 3 and return the penalty. Find consecutive runs of 1:1:3:1:1:4 starting with black, or 4:1:1:3:1:1 starting with white, and give penalty to them. If we find patterns like 000010111010000, we give penalty once.

public static testRule3(array<string|int, array<string|int, bool>> $matrix, int $height, int $width) : int
Parameters
$matrix : array<string|int, array<string|int, bool>>
$height : int
$width : int
Return values
int

testRule4()

Apply mask penalty rule 4 and return the penalty. Calculate the ratio of dark cells and give penalty if the ratio is far from 50%. It gives 10 penalty for 5% distance.

public static testRule4(array<string|int, array<string|int, bool>> $matrix, int $height, int $width) : int
Parameters
$matrix : array<string|int, array<string|int, bool>>
$height : int
$width : int
Return values
int

applyRule1()

private static applyRule1(array<string|int, bool> $rc) : int
Parameters
$rc : array<string|int, bool>
Return values
int

isWhiteHorizontal()

private static isWhiteHorizontal(array<string|int, bool> $row, int $width, int $from, int $to) : bool
Parameters
$row : array<string|int, bool>
$width : int
$from : int
$to : int
Return values
bool

isWhiteVertical()

private static isWhiteVertical(array<string|int, array<string|int, bool>> $matrix, int $height, int $x, int $from, int $to) : bool
Parameters
$matrix : array<string|int, array<string|int, bool>>
$height : int
$x : int
$from : int
$to : int
Return values
bool

        
On this page

Search results