final class AlignmentPatternFinder
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
private int[] |
crossCheckStateCount |
private int |
height |
private BitMatrix |
image |
private float |
moduleSize |
private java.util.List<AlignmentPattern> |
possibleCenters |
private ResultPointCallback |
resultPointCallback |
private int |
startX |
private int |
startY |
private int |
width |
Constructor and Description |
---|
AlignmentPatternFinder(BitMatrix image,
int startX,
int startY,
int width,
int height,
float moduleSize,
ResultPointCallback resultPointCallback)
Creates a finder that will look in a portion of the whole image.
|
Modifier and Type | Method and Description |
---|---|
private static float |
centerFromEnd(int[] stateCount,
int end)
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 float |
crossCheckVertical(int startI,
int centerJ,
int maxCount,
int originalStateCountTotal)
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.
|
(package private) AlignmentPattern |
find()
This method attempts to find the bottom-right alignment pattern in the image.
|
private boolean |
foundPatternCross(int[] stateCount) |
private AlignmentPattern |
handlePossibleCenter(int[] stateCount,
int i,
int j)
This is called when a horizontal scan finds a possible alignment pattern.
|
private final BitMatrix image
private final java.util.List<AlignmentPattern> possibleCenters
private final int startX
private final int startY
private final int width
private final int height
private final float moduleSize
private final int[] crossCheckStateCount
private final ResultPointCallback resultPointCallback
AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback)
Creates a finder that will look in a portion of the whole image.
image
- image to searchstartX
- left column from which to start searchingstartY
- top row from which to start searchingwidth
- width of region to searchheight
- height of region to searchmoduleSize
- estimated module size so farAlignmentPattern find() throws NotFoundException
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.
AlignmentPattern
if foundNotFoundException
- if not foundprivate static float centerFromEnd(int[] stateCount, int end)
private boolean foundPatternCross(int[] stateCount)
stateCount
- count of black/white/black pixels just readprivate float crossCheckVertical(int startI, int centerJ, int maxCount, int originalStateCountTotal)
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.
startI
- row where an alignment pattern was detectedcenterJ
- center of the section that appears to cross an alignment patternmaxCount
- maximum reasonable number of modules that should be
observed in any reading state, based on the results of the horizontal scanFloat.NaN
if not foundprivate AlignmentPattern handlePossibleCenter(int[] stateCount, int i, int j)
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.
stateCount
- reading state module counts from horizontal scani
- row where alignment pattern may be foundj
- end of possible alignment pattern in rowAlignmentPattern
if we have found the same pattern twice, or null if not