Fixed C++ port's handling of reversed barcodes:

- BitArray.reverse() was inverting, not reversing, bits.
 - OneDReader wasn't reversing x coordinates of the result points.
 - OneDReader wasn't catching Binarizer exceptions properly.

Issue 470 can be closed by this.

git-svn-id: https://zxing.googlecode.com/svn/trunk@1472 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
flyashi 2010-07-09 15:12:46 +00:00
parent 9e1dbf07d9
commit b1032ceba4
2 changed files with 21 additions and 8 deletions

View file

@ -107,10 +107,12 @@ vector<unsigned int>& BitArray::getBitArray() {
return bits_;
}
void BitArray::reverse() {
unsigned int allBits = numeric_limits<unsigned int>::max();
size_t max = bits_.size();
for (size_t i = 0; i < max; i++) {
bits_[i] = bits_[i] ^ allBits;
std::vector<unsigned int> newBits(bits_.size(),(const unsigned int) 0);
for (size_t i = 0; i < size_; i++) {
if (get(size_ - i - 1)) {
newBits[i >> logBits_] |= 1<< (i & bitsMask_);
}
}
bits_ = newBits;
}
}

View file

@ -20,6 +20,7 @@
#include "OneDReader.h"
#include <zxing/ReaderException.h>
#include <zxing/oned/OneDResultPoint.h>
#include <math.h>
#include <limits.h>
@ -93,6 +94,8 @@ namespace zxing {
row = image->getBlackRow(rowNumber, row);
}catch (ReaderException re) {
continue;
}catch (IllegalArgumentException re) {
continue;
}
// While we have the image data in a BitArray, it's fairly cheap to reverse it in place to
@ -109,9 +112,17 @@ namespace zxing {
// // But it was upside down, so note that
// result.putMetadata(ResultMetadataType.ORIENTATION, new Integer(180));
// // And remember to flip the result points horizontally.
// ResultPoint[] points = result.getResultPoints();
// points[0] = new ResultPoint(width - points[0].getX() - 1, points[0].getY());
// points[1] = new ResultPoint(width - points[1].getX() - 1, points[1].getY());
std::vector<Ref<ResultPoint> > points(result->getResultPoints());
if (points.size() == 2) {
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()));
points[1] = pointOne;
result.reset(new Result(result->getText(),result->getRawBytes(),points,result->getBarcodeFormat()));
}
}
return result;
} catch (ReaderException re) {
@ -119,7 +130,7 @@ namespace zxing {
}
}
}
throw ReaderException("");
throw ReaderException("doDecode() failed");
}
unsigned int OneDReader::patternMatchVariance(int counters[], int countersSize, const int pattern[], int maxIndividualVariance) {