Menu

## MaskPattern
in package

MaskPattern.php : 26

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

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]
$maskPattern : int
  The current mask pattern value (0-7)
__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

MaskPattern.php : 28
`public mixed AUTO = -1`

#### PATTERN_000

MaskPattern.php : 30
`public mixed PATTERN_000 = 0b0`

#### PATTERN_001

MaskPattern.php : 31
`public mixed PATTERN_001 = 0b1`

#### PATTERN_010

MaskPattern.php : 32
`public mixed PATTERN_010 = 0b10`

#### PATTERN_011

MaskPattern.php : 33
`public mixed PATTERN_011 = 0b11`

#### PATTERN_100

MaskPattern.php : 34
`public mixed PATTERN_100 = 0b100`

#### PATTERN_101

MaskPattern.php : 35
`public mixed PATTERN_101 = 0b101`

#### PATTERN_110

MaskPattern.php : 36
`public mixed PATTERN_110 = 0b110`

#### PATTERN_111

MaskPattern.php : 37
`public mixed PATTERN_111 = 0b111`

#### PATTERNS

MaskPattern.php : 42
`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

MaskPattern.php : 56

The current mask pattern value (0-7)

`private int $maskPattern`

### Methods

#### __construct()

MaskPattern.php : 63

MaskPattern constructor.

`public __construct(int $maskPattern) : mixed`

##### Parameters

$maskPattern : int

##### Tags

throws
  QRCodeException

##### Return values

mixed —

#### getBestPattern()

MaskPattern.php : 110

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

`public static getBestPattern(QRData $dataInterface) : self`

##### Parameters

$dataInterface : QRData

##### Return values

self —

#### getMask()

MaskPattern.php : 93

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

`public getMask() : Closure`

Encapsulates data masks for the data bits in a QR code, per ISO 18004:2006 6.8. Implementations of this class can un-mask a raw BitMatrix. For simplicity, they will unmask the entire BitMatrix, including areas used for finder patterns, timing patterns, etc. These areas should be unused after the point they are unmasked anyway.

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()

MaskPattern.php : 75

Returns the current mask pattern

`public getPattern() : int`

##### Return values

int —

#### testRule1()

MaskPattern.php : 131

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, mixed> $matrix, int $height, int $width) : int`

##### Parameters

$matrix : array<string|int, mixed>
$height : int
$width : int

##### Return values

int —

#### testRule2()

MaskPattern.php : 176

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, mixed> $matrix, int $height, int $width) : int`

##### Parameters

$matrix : array<string|int, mixed>
$height : int
$width : int

##### Return values

int —

#### testRule3()

MaskPattern.php : 209

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, mixed> $matrix, int $height, int $width) : int`

##### Parameters

$matrix : array<string|int, mixed>
$height : int
$width : int

##### Return values

int —

#### testRule4()

MaskPattern.php : 295

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, mixed> $matrix, int $height, int $width) : int`

##### Parameters

$matrix : array<string|int, mixed>
$height : int
$width : int

##### Return values

int —

#### applyRule1()

MaskPattern.php : 138
`private static applyRule1(array<string|int, mixed> $matrix, int $height, int $width, bool $isHorizontal) : int`

##### Parameters

$matrix : array<string|int, mixed>
$height : int
$width : int
$isHorizontal : bool

##### Return values

int —

#### isWhiteHorizontal()

MaskPattern.php : 258
`private static isWhiteHorizontal(array<string|int, mixed> $row, int $width, int $from, int $to) : bool`

##### Parameters

$row : array<string|int, mixed>
$width : int
$from : int
$to : int

##### Return values

bool —

#### isWhiteVertical()

MaskPattern.php : 276
`private static isWhiteVertical(array<string|int, mixed> $matrix, int $height, int $x, int $from, int $to) : bool`

##### Parameters

$matrix : array<string|int, mixed>
$height : int
$x : int
$from : int
$to : int

##### Return values

bool —

## Search results