decodeDigit static method

int decodeDigit(
  1. BitArray row,
  2. List<int> counters,
  3. int rowOffset,
  4. List<List<int>> patterns,
)

Attempts to decode a single UPC/EAN-encoded digit.

@param row row of black/white values to decode @param counters the counts of runs of observed black/white/black/... values @param rowOffset horizontal offset to start decoding from @param patterns the set of patterns to use to decode -- sometimes different encodings for the digits 0-9 are used, and this indicates the encodings for 0 to 9 that should be used @return horizontal offset of first pixel beyond the decoded digit @throws NotFoundException if digit cannot be decoded

Implementation

static int decodeDigit(
  BitArray row,
  List<int> counters,
  int rowOffset,
  List<List<int>> patterns,
) {
  OneDReader.recordPattern(row, rowOffset, counters);
  double bestVariance = _maxAvgVariance; // worst variance we'll accept
  int bestMatch = -1;
  final max = patterns.length;
  for (int i = 0; i < max; i++) {
    final pattern = patterns[i];
    final variance = OneDReader.patternMatchVariance(
      counters,
      pattern,
      _maxIndividualVariance,
    );

    // todo in zxing java float compare may return true between the same float number
    if (variance < bestVariance) {
      bestVariance = variance;
      bestMatch = i;
    }
  }
  if (bestMatch >= 0) {
    return bestMatch;
  } else {
    throw NotFoundException.instance;
  }
}