adjustCompleteIndicatorColumnRowNumbers method
void
adjustCompleteIndicatorColumnRowNumbers(
- BarcodeMetadata barcodeMetadata
)
Implementation
void adjustCompleteIndicatorColumnRowNumbers(
BarcodeMetadata barcodeMetadata,
) {
_setRowNumbers();
_removeIncorrectCodewords(codewords, barcodeMetadata);
final top = isLeft ? boundingBox.topLeft : boundingBox.topRight;
final bottom = isLeft ? boundingBox.bottomLeft : boundingBox.bottomRight;
final firstRow = imageRowToCodewordIndex(top.y.toInt());
final lastRow = imageRowToCodewordIndex(bottom.y.toInt());
// We need to be careful using the average row height. Barcode could be skewed so that we have smaller and
// taller rows
//double averageRowHeight = (lastRow - firstRow) / (double) barcodeMetadata.getRowCount();
int barcodeRow = -1;
int maxRowHeight = 1;
int currentRowHeight = 0;
for (int codewordsRow = firstRow; codewordsRow < lastRow; codewordsRow++) {
if (codewords[codewordsRow] == null) {
continue;
}
final codeword = codewords[codewordsRow]!;
final rowDifference = codeword.rowNumber - barcodeRow;
// TODO improve handling with case where first row indicator doesn't start with 0
if (rowDifference == 0) {
currentRowHeight++;
} else if (rowDifference == 1) {
maxRowHeight = math.max(maxRowHeight, currentRowHeight);
currentRowHeight = 1;
barcodeRow = codeword.rowNumber;
} else if (rowDifference < 0 ||
codeword.rowNumber >= barcodeMetadata.rowCount ||
rowDifference > codewordsRow) {
codewords[codewordsRow] = null;
} else {
int checkedRows;
if (maxRowHeight > 2) {
checkedRows = (maxRowHeight - 2) * rowDifference;
} else {
checkedRows = rowDifference;
}
bool closePreviousCodewordFound = checkedRows >= codewordsRow;
for (int i = 1; i <= checkedRows && !closePreviousCodewordFound; i++) {
// there must be (height * rowDifference) number of codewords missing. For now we assume height = 1.
// This should hopefully get rid of most problems already.
closePreviousCodewordFound = codewords[codewordsRow - i] != null;
}
if (closePreviousCodewordFound) {
codewords[codewordsRow] = null;
} else {
barcodeRow = codeword.rowNumber;
currentRowHeight = 1;
}
}
}
//return (int) (averageRowHeight + 0.5);
}