From 5fd33bb9d25ef9c483c15c113eab73c7d0cd885d Mon Sep 17 00:00:00 2001 From: "srowen@gmail.com" Date: Mon, 19 Aug 2013 08:54:10 +0000 Subject: [PATCH] Issue 1762 PDF417 speed up and back-port to Java git-svn-id: https://zxing.googlecode.com/svn/trunk@2870 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- .../google/zxing/pdf417/decoder/PDF417CodewordDecoder.java | 6 +++++- cpp/core/src/zxing/pdf417/detector/LinesSampler.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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;