Menu

## AlignmentPatternFinder
in package

AlignmentPatternFinder.php : 31

This class attempts to find alignment patterns in a QR Code. Alignment patterns look like finder patterns but are smaller and appear at regular intervals throughout the image.

At the moment this only looks for the bottom-right alignment pattern.

This is mostly a simplified copy of FinderPatternFinder. It is copied, pasted and stripped down here for maximum performance but does unfortunately duplicate some code.

This class is thread-safe but not reentrant. Each thread must allocate its own object.

##### Tags

author

  Sean Owen

### Table of Contents

$matrix : BitMatrix
$moduleSize : float
$possibleCenters : array<string|int, mixed>
__construct() : mixed
  Creates a finder that will look in a portion of the whole image.
find() : AlignmentPattern|null
  This method attempts to find the bottom-right alignment pattern in the image. It is a bit messy since it's pretty performance-critical and so is written to be fast foremost.
centerFromEnd() : float
  Given a count of black/white/black pixels just seen and an end position, figures the location of the center of this black/white/black run.
crossCheckVertical() : float|null
  After a horizontal scan finds a potential alignment pattern, this method "cross-checks" by scanning down vertically through the center of the possible alignment pattern to see if the same proportion is detected.
foundPatternCross() : bool
handlePossibleCenter() : AlignmentPattern|null
  This is called when a horizontal scan finds a possible alignment pattern. It will cross-check with a vertical scan, and if successful, will see if this pattern had been found on a previous horizontal scan. If so, we consider it confirmed and conclude we have found the alignment pattern.

### Properties

#### $matrix

AlignmentPatternFinder.php : 33
`private BitMatrix $matrix`

#### $moduleSize

AlignmentPatternFinder.php : 34
`private float $moduleSize`

#### $possibleCenters

AlignmentPatternFinder.php : 36
`private array<string|int, mixed> $possibleCenters`

### Methods

#### __construct()

AlignmentPatternFinder.php : 44

Creates a finder that will look in a portion of the whole image.

`public __construct(BitMatrix $matrix, float $moduleSize) : mixed`

##### Parameters

$matrix : BitMatrix

  image to search

$moduleSize : float

  estimated module size so far

##### Return values

mixed —

#### find()

AlignmentPatternFinder.php : 61

This method attempts to find the bottom-right alignment pattern in the image. It is a bit messy since it's pretty performance-critical and so is written to be fast foremost.

`public find(int $startX, int $startY, int $width, int $height) : AlignmentPattern|null`

##### Parameters

$startX : int

  left column from which to start searching

$startY : int

  top row from which to start searching

$width : int

  width of region to search

$height : int

  height of region to search

##### Return values

AlignmentPattern|null —

#### centerFromEnd()

AlignmentPatternFinder.php : 209

Given a count of black/white/black pixels just seen and an end position, figures the location of the center of this black/white/black run.

`private centerFromEnd(array<string|int, int> $stateCount, int $end) : float`

##### Parameters

$stateCount : array<string|int, int>
$end : int

##### Return values

float —

#### crossCheckVertical()

AlignmentPatternFinder.php : 226

After a horizontal scan finds a potential alignment pattern, this method "cross-checks" by scanning down vertically through the center of the possible alignment pattern to see if the same proportion is detected.

`private crossCheckVertical(int $startI, int $centerJ, int $maxCount, int $originalStateCountTotal) : float|null`

##### Parameters

$startI : int

  row where an alignment pattern was detected

$centerJ : int

  center of the section that appears to cross an alignment pattern

$maxCount : int

  maximum reasonable number of modules that should be observed in any reading state, based on the results of the horizontal scan

$originalStateCountTotal : int

##### Return values

float|null —

vertical center of alignment pattern, or null if not found

#### foundPatternCross()

AlignmentPatternFinder.php : 152
`private foundPatternCross(array<string|int, int> $stateCount) : bool`

##### Parameters

$stateCount : array<string|int, int>

  count of black/white/black pixels just read

##### Return values

bool —

true if the proportions of the counts is close enough to the 1/1/1 ratios used by alignment patterns to be considered a match

#### handlePossibleCenter()

AlignmentPatternFinder.php : 177

This is called when a horizontal scan finds a possible alignment pattern. It will cross-check with a vertical scan, and if successful, will see if this pattern had been found on a previous horizontal scan. If so, we consider it confirmed and conclude we have found the alignment pattern.

`private handlePossibleCenter(array<string|int, int> $stateCount, int $i, int $j) : AlignmentPattern|null`

##### Parameters

$stateCount : array<string|int, int>

  reading state module counts from horizontal scan

$i : int

  row where alignment pattern may be found

$j : int

  end of possible alignment pattern in row

##### Return values

AlignmentPattern|null —

if we have found the same pattern twice, or null if not

## Search results