decodeRow method
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,
) {
// Find out where the Middle section (payload) starts & ends
final startRange = _decodeStart(row);
final endRange = _decodeEnd(row);
final result = StringBuffer();
_decodeMiddle(row, startRange[1], endRange[0], result);
final resultString = result.toString();
final allowedLengths = hints?.allowedLengths ?? _defaultAllowedLengths;
// To avoid false positives with 2D barcodes (and other patterns), make
// an assumption that the decoded string must be a 'standard' length if it's short
final length = resultString.length;
bool lengthOK = false;
int maxAllowedLength = 0;
for (int allowedLength in allowedLengths) {
if (length == allowedLength) {
lengthOK = true;
break;
}
if (allowedLength > maxAllowedLength) {
maxAllowedLength = allowedLength;
}
}
if (!lengthOK && length > maxAllowedLength) {
lengthOK = true;
}
if (!lengthOK) {
throw FormatsException.instance;
}
final resultObject = Result(
resultString,
null, // no natural byte representation for these barcodes
[
ResultPoint(startRange[1].toDouble(), rowNumber.toDouble()),
ResultPoint(endRange[0].toDouble(), rowNumber.toDouble())
],
BarcodeFormat.itf,
);
resultObject.putMetadata(ResultMetadataType.symbologyIdentifier, ']I0');
return resultObject;
}