decodeRow method

  1. @override
Result decodeRow(
  1. int rowNumber,
  2. BitArray row,
  3. DecodeHint? hints
)
override

Attempts to decode a one-dimensional barcode format given a single row of an image.

@param rowNumber row number from top of the row @param row the black/white pixel data of the row @param hints decode hints @return Result containing encoded string and start/end of barcode @throws NotFoundException if no potential barcode is found @throws ChecksumException if a potential barcode is found but does not pass its checksum @throws FormatException if a potential barcode is found but format is invalid

Implementation

@override
Result decodeRow(
  int rowNumber,
  BitArray row,
  DecodeHint? hints,
) {
  final start = _findAsteriskPattern(row);
  // Read off white space
  int nextStart = row.getNextSet(start[1]);
  final end = row.size;

  final theCounters = _counters;
  theCounters.fillRange(0, theCounters.length, 0);
  final result = _decodeRowResult;
  result.clear();

  String decodedChar;
  int lastStart;
  do {
    OneDReader.recordPattern(row, nextStart, theCounters);
    final pattern = _toPattern(theCounters);
    if (pattern < 0) {
      throw NotFoundException.instance;
    }
    decodedChar = _patternToChar(pattern);
    result.write(decodedChar);
    lastStart = nextStart;
    for (int counter in theCounters) {
      nextStart += counter;
    }
    // Read off white space
    nextStart = row.getNextSet(nextStart);
  } while (decodedChar != '*');
  result.deleteCharAt(result.length - 1); // remove asterisk

  int lastPatternSize = 0;
  for (int counter in theCounters) {
    lastPatternSize += counter;
  }

  // Should be at least one more black module
  if (nextStart == end || !row.get(nextStart)) {
    throw NotFoundException.instance;
  }

  if (result.length < 2) {
    // false positive -- need at least 2 checksum digits
    throw NotFoundException.instance;
  }

  _checkChecksums(result.toString());
  // Remove checksum digits
  result.setLength(result.length - 2);

  final resultString = _decodeExtended(result.toString());

  final left = (start[1] + start[0]) / 2.0;
  final right = lastStart + lastPatternSize / 2.0;

  final resultObject = Result(
    resultString,
    null,
    [
      ResultPoint(left, rowNumber.toDouble()),
      ResultPoint(right, rowNumber.toDouble()),
    ],
    BarcodeFormat.code93,
  );
  resultObject.putMetadata(ResultMetadataType.symbologyIdentifier, ']G0');
  return resultObject;
}