decode method
Locates and decodes a barcode in some format within an image
. This method also accepts
hints
, each possibly associated to some data, which may help the implementation decode.
@param image image of barcode to decode @param hints passed as a Map from DecodeHintType to arbitrary data. The meaning of the data depends upon the hint type. The implementation may or may not do anything with these hints. @return String which the barcode encodes @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 decode(BinaryBitmap image, [DecodeHint? hints]) {
final width = image.width;
final height = image.height;
final halfWidth = width ~/ 2;
final halfHeight = height ~/ 2;
try {
// No need to call makeAbsolute as results will be relative to original top left here
return _delegate.decode(image.crop(0, 0, halfWidth, halfHeight), hints);
} on NotFoundException catch (_) {
// continue
}
try {
final result = _delegate.decode(
image.crop(halfWidth, 0, halfWidth, halfHeight),
hints,
);
_makeAbsolute(result.resultPoints, halfWidth, 0);
return result;
} on NotFoundException catch (_) {
// continue
}
try {
final result = _delegate.decode(
image.crop(0, halfHeight, halfWidth, halfHeight),
hints,
);
_makeAbsolute(result.resultPoints, 0, halfHeight);
return result;
} on NotFoundException catch (_) {
// continue
}
try {
final result = _delegate.decode(
image.crop(halfWidth, halfHeight, halfWidth, halfHeight),
hints,
);
_makeAbsolute(result.resultPoints, halfWidth, halfHeight);
return result;
} on NotFoundException catch (_) {
// continue
}
final quarterWidth = halfWidth ~/ 2;
final quarterHeight = halfHeight ~/ 2;
final center =
image.crop(quarterWidth, quarterHeight, halfWidth, halfHeight);
final result = _delegate.decode(center, hints);
_makeAbsolute(result.resultPoints, quarterWidth, quarterHeight);
return result;
}