From d5d1e96fd3936324b31fe645acc4ce65956ec2e1 Mon Sep 17 00:00:00 2001 From: "christian.brunschen" Date: Tue, 24 Jun 2008 16:27:52 +0000 Subject: [PATCH] debug printout cleanup git-svn-id: http://zxing.googlecode.com/svn/trunk@472 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/core/src/MonochromeBitmapSource.cpp | 10 +++++----- cpp/core/src/common/BlackPointEstimator.cpp | 8 ++++++-- .../common/reedsolomon/ReedSolomonDecoder.cpp | 11 ++++++++++ cpp/core/src/qrcode/QRCodeReader.cpp | 20 +++++++++++++++++++ cpp/core/src/qrcode/decoder/Version.cpp | 2 ++ 5 files changed, 44 insertions(+), 7 deletions(-) diff --git a/cpp/core/src/MonochromeBitmapSource.cpp b/cpp/core/src/MonochromeBitmapSource.cpp index cc6a31f5..e46899b4 100644 --- a/cpp/core/src/MonochromeBitmapSource.cpp +++ b/cpp/core/src/MonochromeBitmapSource.cpp @@ -87,14 +87,14 @@ estimateBlackPoint(BlackPointEstimationMethod method, int arg) { valarray histogram(LUMINANCE_BUCKETS); if (method == BlackPointEstimationMethod_2D) { size_t minDimension = width < height ? width : height; - size_t yOffset = height == minDimension ? 0 : (height - width) >> 1; - size_t xOffset = width == minDimension ? 0 : (width - height) >> 1; + size_t startX = (width - minDimension) >> 1; + size_t startY = (height - minDimension) >> 1; for (size_t n = 0; n < minDimension; n++) { - unsigned char pixel = getPixel(xOffset + n, yOffset + n); + unsigned char pixel = getPixel(startX + n, startY + n); histogram[pixel >> LUMINANCE_SHIFT]++; } } else if (method == BlackPointEstimationMethod_RowSampling) { - if (arg < 0 || arg > (int)height) { + if (arg < 0 || arg >= (int)height) { throw new IllegalArgumentException ("black point estimation argument out of range"); } @@ -114,6 +114,6 @@ estimateBlackPoint(BlackPointEstimationMethod method, int arg) { } BlackPointEstimationMethod MonochromeBitmapSource::getLastEstimationMethod() { - return BlackPointEstimationMethod_None; + return lastEstimationMethod_; } diff --git a/cpp/core/src/common/BlackPointEstimator.cpp b/cpp/core/src/common/BlackPointEstimator.cpp index 976ed228..9b4e1e1f 100644 --- a/cpp/core/src/common/BlackPointEstimator.cpp +++ b/cpp/core/src/common/BlackPointEstimator.cpp @@ -28,6 +28,7 @@ namespace common { size_t BlackPointEstimator::estimate(valarray &histogram) { size_t numBuckets = histogram.size(); + int maxBucketCount = 0; // Find tallest peak in histogram size_t firstPeak = 0; @@ -37,6 +38,9 @@ namespace common { firstPeak = i; firstPeakSize = histogram[i]; } + if (histogram[i] > maxBucketCount) { + maxBucketCount = histogram[i]; + } } // Find second-tallest peak -- well, another peak that is tall and not @@ -65,7 +69,7 @@ namespace common { // Decoding the image/line is either pointless, or may in some cases lead to a false positive // for 1D formats, which are relatively lenient. // We arbitrarily say "close" is "<= 1/16 of the total histogram buckets apart" - if (secondPeak - firstPeak <= histogram.size() >> 4) { + if (secondPeak - firstPeak <= numBuckets >> 4) { throw new IllegalArgumentException ("Too little dynamic range in luminance"); } @@ -77,7 +81,7 @@ namespace common { int fromFirst = i - firstPeak; // Favor a "valley" that is not too close to either peak -- especially not the black peak -- // and that has a low value of course - int score = fromFirst * fromFirst * (secondPeak - i) * (256 - histogram[i]); + int score = fromFirst * fromFirst * (secondPeak - i) * (maxBucketCount - histogram[i]); if (score > bestValleyScore) { bestValley = i; bestValleyScore = score; diff --git a/cpp/core/src/common/reedsolomon/ReedSolomonDecoder.cpp b/cpp/core/src/common/reedsolomon/ReedSolomonDecoder.cpp index 40be310c..c387e972 100644 --- a/cpp/core/src/common/reedsolomon/ReedSolomonDecoder.cpp +++ b/cpp/core/src/common/reedsolomon/ReedSolomonDecoder.cpp @@ -40,13 +40,20 @@ namespace reedsolomon { cout << "decode(): received = " << &received << ", array = " << received.array_ << " (" << received.array_->count_ << ")\n"; #endif + Ref poly(new GF256Poly(field, received)); + +#ifdef DEBUG cout << "decoding with poly " << *poly << "\n"; +#endif + ArrayRef syndromeCoefficients(new Array(twoS)); + #ifdef DEBUG cout << "syndromeCoefficients array = " << syndromeCoefficients.array_ << "\n"; #endif + bool noError = true; for (int i = 0; i < twoS; i++) { int eval = poly->evaluateAt(field.exp(i)); @@ -56,10 +63,12 @@ namespace reedsolomon { } } if (noError) { + #ifdef DEBUG cout << "before returning: syndromeCoefficients rc = " << syndromeCoefficients.array_->count_ << "\n"; #endif + return; } @@ -149,10 +158,12 @@ namespace reedsolomon { Ref sigma(t->multiply(inverse)); Ref omega(r->multiply(inverse)); +#ifdef DEBUG cout << "t = " << *t << "\n"; cout << "r = " << *r << "\n"; cout << "sigma = " << *sigma << "\n"; cout << "omega = " << *omega << "\n"; +#endif vector > result(2); result[0] = sigma; diff --git a/cpp/core/src/qrcode/QRCodeReader.cpp b/cpp/core/src/qrcode/QRCodeReader.cpp index 4b4c69d8..78bb5dd1 100644 --- a/cpp/core/src/qrcode/QRCodeReader.cpp +++ b/cpp/core/src/qrcode/QRCodeReader.cpp @@ -31,12 +31,24 @@ namespace qrcode { using namespace std; Ref QRCodeReader::decode(Ref image) { +#ifdef DEBUG cout << "decoding image " << image.object_ << ":\n" << flush; +#endif + Detector detector(image); + +#ifdef DEBUG cout << "(1) created detector " << &detector << "\n" << flush; +#endif + Ref detectorResult(detector.detect()); +#ifdef DEBUG cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush; +#endif + ArrayRef > points(detectorResult->getPoints()); + +#ifdef DEBUG cout << "(3) extracted points " << &points << "\n" << flush; cout << "found " << points->size() << " points:\n"; for (size_t i = 0; i < points->size(); i++) { @@ -44,13 +56,21 @@ namespace qrcode { } cout << "bits:\n"; cout << *(detectorResult->getBits()) << "\n"; +#endif + Ref decoderResult(decoder_.decode(detectorResult->getBits())); +#ifdef DEBUG cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush; +#endif + Ref result(new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat_QR_CODE)); +#ifdef DEBUG cout << "(5) created result " << result.object_ << ", returning\n" << flush; +#endif + return result; } diff --git a/cpp/core/src/qrcode/decoder/Version.cpp b/cpp/core/src/qrcode/decoder/Version.cpp index a9e7d16b..39bbf7cd 100644 --- a/cpp/core/src/qrcode/decoder/Version.cpp +++ b/cpp/core/src/qrcode/decoder/Version.cpp @@ -166,8 +166,10 @@ namespace qrcode { functionPattern->setRegion(dimension - 11, 0, 3, 6); } +#ifdef DEBUG cout << "version " << versionNumber_ << " built function pattern:\n"; cout << *functionPattern; +#endif return functionPattern; } -- 2.20.1