}
Ref<Result> OneDReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
- try {
- return doDecode(image, hints);
- } catch (ReaderException re) {
- if (hints.getTryHarder() && image->isRotateSupported()) {
- Ref<BinaryBitmap> rotatedImage(image->rotateCounterClockwise());
- Ref<Result> result(doDecode(rotatedImage, hints));
- /*
+ Ref<Result> result = doDecode(image, hints);
+ if (result.empty() && hints.getTryHarder() && image->isRotateSupported()) {
+ Ref<BinaryBitmap> rotatedImage(image->rotateCounterClockwise());
+ result = doDecode(rotatedImage, hints);
+ if (!result.empty()) {
+ /*
// Record that we found it rotated 90 degrees CCW / 270 degrees CW
Hashtable metadata = result.getResultMetadata();
int orientation = 270;
for (size_t i = 0; i < points.size(); i++) {
points[i].reset(new OneDResultPoint(height - points[i]->getY() - 1, points[i]->getX()));
}
- return result;
- } else {
- throw re;
}
- }
+ }
+ if (result.empty()) {
+ throw ReaderException("");
+ }
+ return result;
}
Ref<Result> OneDReader::doDecode(Ref<BinaryBitmap> image, DecodeHints hints) {
// if there's exactly two points (which there should be), flip the x coordinate
// if there's not exactly 2, I don't know what do do with it
if (points.size() == 2) {
- Ref<ResultPoint> pointZero(new OneDResultPoint(width - points[0]->getX() - 1, points[0]->getY()));
+ Ref<ResultPoint> pointZero(new OneDResultPoint(width - points[0]->getX() - 1,
+ points[0]->getY()));
points[0] = pointZero;
- Ref<ResultPoint> pointOne(new OneDResultPoint(width - points[1]->getX() - 1, points[1]->getY()));
+ Ref<ResultPoint> pointOne(new OneDResultPoint(width - points[1]->getX() - 1,
+ points[1]->getY()));
points[1] = pointOne;
- result.reset(new Result(result->getText(),result->getRawBytes(),points,result->getBarcodeFormat()));
+ result.reset(new Result(result->getText(), result->getRawBytes(), points,
+ result->getBarcodeFormat()));
}
return result;
}
}
}
- throw ReaderException("doDecode() failed");
+ return Ref<Result>();
}
- unsigned int OneDReader::patternMatchVariance(int counters[], int countersSize, const int pattern[], int maxIndividualVariance) {
+ unsigned int OneDReader::patternMatchVariance(int counters[], int countersSize,
+ const int pattern[], int maxIndividualVariance) {
int numCounters = countersSize;
unsigned int total = 0;
unsigned int patternLength = 0;
return totalVariance / total;
}
- void OneDReader::recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount){
+ bool OneDReader::recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount) {
int numCounters = countersCount;//sizeof(counters) / sizeof(int);
for (int i = 0; i < numCounters; i++) {
counters[i] = 0;
}
int end = row->getSize();
if (start >= end) {
- throw ReaderException("recordPattern: start >= end");
+ return false;
}
bool isWhite = !row->get(start);
int counterPosition = 0;
// If we read fully the last section of pixels and filled up our counters -- or filled
// the last counter but ran off the side of the image, OK. Otherwise, a problem.
if (!(counterPosition == numCounters || (counterPosition == numCounters - 1 && i == end))) {
- throw ReaderException("recordPattern");
+ return false;
}
+ return true;
}
OneDReader::~OneDReader() {