- if (tryHarder) {
- row.reverse(); // try scanning the row backwards
- try {
- return decodeRow(rowNumber, row, hints);
- } catch (ReaderException re2) {
- // continue
+ continue;
+ }
+ row = image.getBlackRow(rowNumber, row, 0, width);
+
+ // While we have the image data in a BitArray, it's fairly cheap to reverse it in place to
+ // handle decoding upside down barcodes.
+ for (int attempt = 0; attempt < 2; attempt++) {
+ if (attempt == 1) { // trying again?
+ row.reverse(); // reverse the row and continue
+ }
+ try {
+ // Look for a barcode
+ Result result = decodeRow(rowNumber, row, hints);
+ // We found our barcode
+ if (attempt == 1) {
+ // But it was upside down, so note that
+ result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180));
+ // And remember to flip the result points horizontally.
+ ResultPoint[] points = result.getResultPoints();
+ points[0] = new ResultPoint(width - points[0].getX() - 1, points[0].getY());
+ points[1] = new ResultPoint(width - points[1].getX() - 1, points[1].getY());