Skip to content

Commit

Permalink
Ignore additional PDF417 barcode rows
Browse files Browse the repository at this point in the history
Some barcode generators (e.g. Okapi) seem to generate additional barcode
rows at the end of the barcode, which can be decoded as valid barcode
rows, but actually contain garbage. The barcode metadata states that
these additional rows are not part of the barcode. So we ignore those
addional rows when parsing the barcode. This could potentially also
happen (though quite unlikely) if data after the barcode looks like a
barcode row.
  • Loading branch information
graug committed Sep 1, 2015
1 parent 585667b commit 825a31e
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ int[] getRowHeights() throws FormatException {
if (codeword != null) {
int rowNumber = codeword.getRowNumber();
if (rowNumber >= result.length) {
throw FormatException.getFormatInstance();
// We have more rows than the barcode metadata allows for, ignore them.
continue;
}
result[rowNumber]++;
} // else throw exception?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,8 @@ private static BarcodeValue[][] createBarcodeMatrix(DetectionResult detectionRes
int rowNumber = codeword.getRowNumber();
if (rowNumber >= 0) {
if (rowNumber >= barcodeMatrix.length) {
throw FormatException.getFormatInstance();
// We have more rows than the barcode metadata allows for, ignore them.
continue;
}
barcodeMatrix[rowNumber][column].setValue(codeword.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public final class PDF417BlackBox1TestCase extends AbstractBlackBoxTestCase {

public PDF417BlackBox1TestCase() {
super("src/test/resources/blackbox/pdf417-1", new MultiFormatReader(), BarcodeFormat.PDF_417);
addTest(9, 9, 0.0f);
addTest(9, 9, 180.0f);
addTest(10, 10, 0.0f);
addTest(10, 10, 180.0f);
}

}
Binary file added core/src/test/resources/blackbox/pdf417-1/11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions core/src/test/resources/blackbox/pdf417-1/11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is just a test.

0 comments on commit 825a31e

Please sign in to comment.