valarray<int> 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");
}
}
BlackPointEstimationMethod MonochromeBitmapSource::getLastEstimationMethod() {
- return BlackPointEstimationMethod_None;
+ return lastEstimationMethod_;
}
size_t BlackPointEstimator::estimate(valarray<int> &histogram) {
size_t numBuckets = histogram.size();
+ int maxBucketCount = 0;
// Find tallest peak in histogram
size_t firstPeak = 0;
firstPeak = i;
firstPeakSize = histogram[i];
}
+ if (histogram[i] > maxBucketCount) {
+ maxBucketCount = histogram[i];
+ }
}
// Find second-tallest peak -- well, another peak that is tall and not
// 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");
}
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;
cout << "decode(): received = " << &received << ", array = " <<
received.array_ << " (" << received.array_->count_ << ")\n";
#endif
+
Ref<GF256Poly> poly(new GF256Poly(field, received));
+
+#ifdef DEBUG
cout << "decoding with poly " << *poly << "\n";
+#endif
+
ArrayRef<int> syndromeCoefficients(new Array<int>(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));
}
}
if (noError) {
+
#ifdef DEBUG
cout << "before returning: syndromeCoefficients rc = " <<
syndromeCoefficients.array_->count_ << "\n";
#endif
+
return;
}
Ref<GF256Poly> sigma(t->multiply(inverse));
Ref<GF256Poly> omega(r->multiply(inverse));
+#ifdef DEBUG
cout << "t = " << *t << "\n";
cout << "r = " << *r << "\n";
cout << "sigma = " << *sigma << "\n";
cout << "omega = " << *omega << "\n";
+#endif
vector<Ref<GF256Poly> > result(2);
result[0] = sigma;
using namespace std;
Ref<Result> QRCodeReader::decode(Ref<MonochromeBitmapSource> 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> detectorResult(detector.detect());
+#ifdef DEBUG
cout << "(2) detected, have detectorResult " << detectorResult.object_ << "\n" << flush;
+#endif
+
ArrayRef<Ref<ResultPoint> > 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++) {
}
cout << "bits:\n";
cout << *(detectorResult->getBits()) << "\n";
+#endif
+
Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
+#ifdef DEBUG
cout << "(4) decoded, have decoderResult " << decoderResult.object_ << "\n" << flush;
+#endif
+
Ref<Result> 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;
}
functionPattern->setRegion(dimension - 11, 0, 3, 6);
}
+#ifdef DEBUG
cout << "version " << versionNumber_ << " built function pattern:\n";
cout << *functionPattern;
+#endif
return functionPattern;
}