X-Git-Url: http://git.rot13.org/?p=zxing.git;a=blobdiff_plain;f=cpp%2Fcore%2Fsrc%2Fcommon%2FBlackPointEstimator.cpp;h=9b4e1e1f5091abba85c5f1781813e0612ae2fae3;hp=976ed228fcefc564ae8e943c387288d34c9b5b17;hb=d5d1e96fd3936324b31fe645acc4ce65956ec2e1;hpb=ca9d7b07d124cc454c38b984677c511476fd8d9b 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;