MaskPattern
in package
ISO/IEC 18004:2000 Section 8.8.1 ISO/IEC 18004:2000 Section 8.8.2 - Evaluation of masking results
Tags
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
AUTO
public
int
AUTO
= -1
Tags
PATTERN_000
public
mixed
PATTERN_000
= 0b0
PATTERN_001
public
mixed
PATTERN_001
= 0b1
PATTERN_010
public
mixed
PATTERN_010
= 0b10
PATTERN_011
public
mixed
PATTERN_011
= 0b11
PATTERN_100
public
mixed
PATTERN_100
= 0b100
PATTERN_101
public
mixed
PATTERN_101
= 0b101
PATTERN_110
public
mixed
PATTERN_110
= 0b110
PATTERN_111
public
mixed
PATTERN_111
= 0b111
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]
PENALTY_N1
private
mixed
PENALTY_N1
= 3
PENALTY_N2
private
mixed
PENALTY_N2
= 3
PENALTY_N3
private
mixed
PENALTY_N3
= 40
PENALTY_N4
private
mixed
PENALTY_N4
= 10
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
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
selfgetMask()
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
Return values
ClosuregetPattern()
Returns the current mask pattern
public
getPattern() : int
Return values
inttestRule1()
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
inttestRule2()
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
inttestRule3()
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
inttestRule4()
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
intapplyRule1()
private
static applyRule1(array<string|int, bool> $rc) : int
Parameters
- $rc : array<string|int, bool>
Return values
intisWhiteHorizontal()
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
boolisWhiteVertical()
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