diff --git a/core/src/com/google/zxing/pdf417/decoder/PDF417CodewordDecoder.java b/core/src/com/google/zxing/pdf417/decoder/PDF417CodewordDecoder.java index 478f0e23a..017f3f399 100644 --- a/core/src/com/google/zxing/pdf417/decoder/PDF417CodewordDecoder.java +++ b/core/src/com/google/zxing/pdf417/decoder/PDF417CodewordDecoder.java @@ -98,9 +98,13 @@ final class PDF417CodewordDecoder { int bestMatch = -1; for (int j = 0; j < RATIOS_TABLE.length; j++) { float error = 0.0f; + float[] ratioTableRow = RATIOS_TABLE[j]; for (int k = 0; k < PDF417Common.BARS_IN_MODULE; k++) { - float diff = RATIOS_TABLE[j][k] - bitCountRatios[k]; + float diff = ratioTableRow[k] - bitCountRatios[k]; error += diff * diff; + if (error >= bestMatchError) { + break; + } } if (error < bestMatchError) { bestMatchError = error; diff --git a/cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp b/cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp index 4ec640ea3..62c005473 100644 --- a/cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp +++ b/cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp @@ -408,7 +408,11 @@ void LinesSampler::linesMatrixToCodewords(vector >& clusterNumbers, for (int j = 0; j < POSSIBLE_SYMBOLS; j++) { float error = 0.0f; for (int k = 0; k < BARS_IN_SYMBOL; k++) { - error += pow(RATIOS_TABLE[j * BARS_IN_SYMBOL + k] - cwRatios[i][k], 2); + float diff = RATIOS_TABLE[j * BARS_IN_SYMBOL + k] - cwRatios[i][k]; + error += diff * diff; + if (error >= bestMatchError) { + break; + } } if (error < bestMatchError) { bestMatchError = error;