From: flyashi Date: Fri, 9 Jul 2010 15:12:46 +0000 (+0000) Subject: Fixed C++ port's handling of reversed barcodes: X-Git-Url: http://git.rot13.org/?p=zxing.git;a=commitdiff_plain;h=e5776b8d76108d2fb616f19f88bb0ed55d0c2ff6 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: http://zxing.googlecode.com/svn/trunk@1472 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- diff --git a/cpp/core/src/zxing/common/BitArray.cpp b/cpp/core/src/zxing/common/BitArray.cpp index 9355d015..6ba7fd22 100644 --- a/cpp/core/src/zxing/common/BitArray.cpp +++ b/cpp/core/src/zxing/common/BitArray.cpp @@ -107,10 +107,12 @@ vector& BitArray::getBitArray() { return bits_; } void BitArray::reverse() { - unsigned int allBits = numeric_limits::max(); - size_t max = bits_.size(); - for (size_t i = 0; i < max; i++) { - bits_[i] = bits_[i] ^ allBits; + std::vector 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; } } diff --git a/cpp/core/src/zxing/oned/OneDReader.cpp b/cpp/core/src/zxing/oned/OneDReader.cpp index 7610b870..d3e49169 100644 --- a/cpp/core/src/zxing/oned/OneDReader.cpp +++ b/cpp/core/src/zxing/oned/OneDReader.cpp @@ -20,6 +20,7 @@ #include "OneDReader.h" #include +#include #include #include @@ -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 > points(result->getResultPoints()); + if (points.size() == 2) { + Ref pointZero(new OneDResultPoint(width - points[0]->getX() - 1, points[0]->getY())); + points[0] = pointZero; + + Ref 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) {