handlePossibleCenter method

bool handlePossibleCenter(
  1. List<int> stateCount,
  2. int i,
  3. int j, [
  4. bool pureBarcode = false,
])

This is called when a horizontal scan finds a possible alignment pattern. It will cross check with a vertical scan, and if successful, will, ah, cross-cross-check with another horizontal scan. This is needed primarily to locate the real horizontal center of the pattern in cases of extreme skew. And then we cross-cross-cross check with another diagonal scan.

If that succeeds the finder pattern location is added to a list that tracks the number of times each location has been nearly-matched as a finder pattern. Each additional find is more evidence that the location is in fact a finder pattern center

@param stateCount reading state module counts from horizontal scan @param i row where finder pattern may be found @param j end of possible finder pattern in row @return true if a finder pattern candidate was found this time

Implementation

//@protected
bool handlePossibleCenter(
  List<int> stateCount,
  int i,
  int j, [
  bool pureBarcode = false,
]) {
  final stateCountTotal = stateCount[0] +
      stateCount[1] +
      stateCount[2] +
      stateCount[3] +
      stateCount[4];
  double centerJ = _centerFromEnd(stateCount, j);
  final centerI =
      _crossCheckVertical(i, centerJ.toInt(), stateCount[2], stateCountTotal);
  if (!(centerI).isNaN) {
    // Re-cross check
    centerJ = _crossCheckHorizontal(
      centerJ.toInt(),
      centerI.toInt(),
      stateCount[2],
      stateCountTotal,
    );
    if (!(centerJ).isNaN &&
        _crossCheckDiagonal(centerI.toInt(), centerJ.toInt())) {
      final estimatedModuleSize = stateCountTotal / 7.0;
      bool found = false;
      for (int index = 0; index < _possibleCenters.length; index++) {
        final center = _possibleCenters[index];
        // Look for about the same center and module size:
        if (center.aboutEquals(estimatedModuleSize, centerI, centerJ)) {
          _possibleCenters[index] =
              center.combineEstimate(centerI, centerJ, estimatedModuleSize);
          found = true;
          break;
        }
      }
      if (!found) {
        final point = FinderPattern(centerJ, centerI, estimatedModuleSize);
        _possibleCenters.add(point);
        if (_resultPointCallback != null) {
          _resultPointCallback!.foundPossibleResultPoint(point);
        }
      }
      return true;
    }
  }
  return false;
}