mirror of
https://github.com/zxing/zxing.git
synced 2024-09-20 21:47:32 -07:00
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:
parent
9e1dbf07d9
commit
b1032ceba4
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue