From 53e6b62f9f1859a40fae7d34dee7b35c23533eeb Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Tue, 26 Jun 2012 17:21:13 +0000 Subject: [PATCH] update C++ changes from r2247 git-svn-id: https://zxing.googlecode.com/svn/trunk@2328 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/README | 5 +++++ .../decoder/DecodedBitStreamParser.cpp | 5 ++--- cpp/core/src/zxing/oned/Code128Reader.cpp | 17 ++++++++--------- cpp/core/src/zxing/oned/Code39Reader.cpp | 17 ++++++++--------- cpp/core/src/zxing/qrcode/detector/Detector.cpp | 6 ++++-- 5 files changed, 27 insertions(+), 23 deletions(-) diff --git a/cpp/README b/cpp/README index 20593786b..b9afa1d45 100644 --- a/cpp/README +++ b/cpp/README @@ -41,3 +41,8 @@ To profile the code (very useful to optimize the code): - Install valgrind - "valgrind --tool=callgrind build/zxing - path/to/test/data/*.jpg > report.html" - kcachegrind is a very nice tool to analize the output + +To run the blackbox tests and check for changes: + - build the test util, e.g., scons zxing + - run the tests: bash blackboxtest.sh 2>&1 | tee bb.results + - diff them with the known results: diff bb.results blackboxtest.results \ No newline at end of file diff --git a/cpp/core/src/zxing/datamatrix/decoder/DecodedBitStreamParser.cpp b/cpp/core/src/zxing/datamatrix/decoder/DecodedBitStreamParser.cpp index 6df3a8bce..00ba30349 100644 --- a/cpp/core/src/zxing/datamatrix/decoder/DecodedBitStreamParser.cpp +++ b/cpp/core/src/zxing/datamatrix/decoder/DecodedBitStreamParser.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * DecodedBitStreamParser.cpp * zxing @@ -141,9 +142,7 @@ int DecodedBitStreamParser::decodeAsciiSegment(Ref bits, ostringstrea // Ignore this symbol for now } else if (oneByte >= 242) { // Not to be used in ASCII encodation // ... but work around encoders that end with 254, latch back to ASCII - if (oneByte == 254 && bits->available() == 0) { - // Ignore - } else { + if (oneByte != 254 || bits->available() != 0) { throw FormatException("Not to be used in ASCII encodation"); } } diff --git a/cpp/core/src/zxing/oned/Code128Reader.cpp b/cpp/core/src/zxing/oned/Code128Reader.cpp index 6e68ddafb..8bddc47ba 100644 --- a/cpp/core/src/zxing/oned/Code128Reader.cpp +++ b/cpp/core/src/zxing/oned/Code128Reader.cpp @@ -174,16 +174,15 @@ namespace zxing { bestMatch = startCode; } } - if (bestMatch >= 0) { - // Look for whitespace before start pattern, >= 50% of width of start pattern - if (row->isRange(std::max(0, patternStart - (i - patternStart) / 2), patternStart, + // Look for whitespace before start pattern, >= 50% of width of start pattern + if (bestMatch >= 0 && + row->isRange(std::max(0, patternStart - (i - patternStart) / 2), patternStart, false)) { - int* resultValue = new int[3]; - resultValue[0] = patternStart; - resultValue[1] = i; - resultValue[2] = bestMatch; - return resultValue; - } + int* resultValue = new int[3]; + resultValue[0] = patternStart; + resultValue[1] = i; + resultValue[2] = bestMatch; + return resultValue; } patternStart += counters[0] + counters[1]; for (int y = 2; y < patternLength; y++) { diff --git a/cpp/core/src/zxing/oned/Code39Reader.cpp b/cpp/core/src/zxing/oned/Code39Reader.cpp index dfde3a1c6..5f2244edd 100644 --- a/cpp/core/src/zxing/oned/Code39Reader.cpp +++ b/cpp/core/src/zxing/oned/Code39Reader.cpp @@ -204,15 +204,14 @@ namespace oned { counters[counterPosition]++; } else { if (counterPosition == patternLength - 1) { - if (toNarrowWidePattern(counters, countersLen) == ASTERISK_ENCODING) { - // Look for whitespace before start pattern, >= 50% of width of - // start pattern. - if (row->isRange(std::max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) { - int* resultValue = new int[2]; - resultValue[0] = patternStart; - resultValue[1] = i; - return resultValue; - } + // Look for whitespace before start pattern, >= 50% of width of + // start pattern. + if (toNarrowWidePattern(counters, countersLen) == ASTERISK_ENCODING && + row->isRange(std::max(0, patternStart - ((i - patternStart) >> 1)), patternStart, false)) { + int* resultValue = new int[2]; + resultValue[0] = patternStart; + resultValue[1] = i; + return resultValue; } patternStart += counters[0] + counters[1]; for (int y = 2; y < patternLength; y++) { diff --git a/cpp/core/src/zxing/qrcode/detector/Detector.cpp b/cpp/core/src/zxing/qrcode/detector/Detector.cpp index 4a30fce81..405354b07 100644 --- a/cpp/core/src/zxing/qrcode/detector/Detector.cpp +++ b/cpp/core/src/zxing/qrcode/detector/Detector.cpp @@ -121,12 +121,14 @@ Ref Detector::createTransform(Ref topLeft, Re if (alignmentPattern != 0) { bottomRightX = alignmentPattern->getX(); bottomRightY = alignmentPattern->getY(); - sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0f; + sourceBottomRightX = dimMinusThree - 3.0f; + sourceBottomRightY = sourceBottomRightX; } else { // Don't have an alignment pattern, just make up the bottom-right point bottomRightX = (topRight->getX() - topLeft->getX()) + bottomLeft->getX(); bottomRightY = (topRight->getY() - topLeft->getY()) + bottomLeft->getY(); - sourceBottomRightX = sourceBottomRightY = dimMinusThree; + sourceBottomRightX = dimMinusThree; + sourceBottomRightY = dimMinusThree; } Ref transform(PerspectiveTransform::quadrilateralToQuadrilateral(3.5f, 3.5f, dimMinusThree, 3.5f, sourceBottomRightX,