processFinderPatternInfo method
Implementation
DetectorResult processFinderPatternInfo(FinderPatternInfo info) {
final topLeft = info.topLeft;
final topRight = info.topRight;
final bottomLeft = info.bottomLeft;
final moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft);
if (moduleSize < 1.0) {
throw NotFoundException.instance;
}
final dimension =
_computeDimension(topLeft, topRight, bottomLeft, moduleSize);
final provisionalVersion =
Version.getProvisionalVersionForDimension(dimension);
final modulesBetweenFPCenters = provisionalVersion.dimensionForVersion - 7;
AlignmentPattern? alignmentPattern;
// Anything above version 1 has an alignment pattern
if (provisionalVersion.alignmentPatternCenters.isNotEmpty) {
// Guess where a "bottom right" finder pattern would have been
final bottomRightX = topRight.x - topLeft.x + bottomLeft.x;
final bottomRightY = topRight.y - topLeft.y + bottomLeft.y;
// Estimate that alignment pattern is closer by 3 modules
// from "bottom right" to known top left location
final correctionToTopLeft = 1.0 - 3.0 / modulesBetweenFPCenters;
final estAlignmentX =
(topLeft.x + correctionToTopLeft * (bottomRightX - topLeft.x))
.toInt();
final estAlignmentY =
(topLeft.y + correctionToTopLeft * (bottomRightY - topLeft.y))
.toInt();
// Kind of arbitrary -- expand search radius before giving up
for (int i = 4; i <= 16; i <<= 1) {
try {
alignmentPattern = findAlignmentInRegion(
moduleSize,
estAlignmentX,
estAlignmentY,
i.toDouble(),
);
break;
} on NotFoundException catch (_) {
// try next round
}
}
// If we didn't find alignment pattern... well try anyway without it
}
final transform = _createTransform(
topLeft,
topRight,
bottomLeft,
alignmentPattern,
dimension,
);
final bits = _sampleGrid(_image, transform, dimension);
late List<ResultPoint> points;
if (alignmentPattern == null) {
points = [bottomLeft, topLeft, topRight];
} else {
points = [bottomLeft, topLeft, topRight, alignmentPattern];
}
return DetectorResult(bits, points);
}