getBlackRow method
Converts the row y
of luminance data to row
(true means black).
If row
is null or too small, it will be ignored.
if the row y
can't be binarized NotFoundException will be thrown
May actually do the conversion, or return cached data.
Callers should assume this method is expensive and call it as seldom as possible.
This method is intended for decoding 1D barcodes and may choose to apply sharpening.
For callers which only examine one row of pixels at a time, the same BitArray should be reused
and passed in with each call for performance. However it is legal to keep more than one row
at a time if needed
Implementation
@override
BitArray getBlackRow(int y, BitArray? row) {
final source = luminanceSource;
final width = source.width;
if (row == null || row.size < width) {
row = BitArray(width);
} else {
row.clear();
}
_initArrays(width);
final localLuminances = source.getRow(y, _luminances);
final localBuckets = _buckets;
for (int x = 0; x < width; x++) {
localBuckets[localLuminances[x] >> _luminanceShift]++;
}
final blackPoint = _estimateBlackPoint(localBuckets);
if (width < 3) {
// Special case for very small images
for (int x = 0; x < width; x++) {
if (localLuminances[x] < blackPoint) {
row.set(x);
}
}
} else {
int left = localLuminances[0];
int center = localLuminances[1];
for (int x = 1; x < width - 1; x++) {
final right = localLuminances[x + 1];
// A simple -1 4 -1 box filter with a weight of 2.
if (((center * 4) - left - right) ~/ 2 < blackPoint) {
row.set(x);
}
left = center;
center = right;
}
}
return row;
}