mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
1d complete; tests pass; need to valgrind
git-svn-id: https://zxing.googlecode.com/svn/trunk@2606 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
71df521610
commit
913f87b1ce
|
@ -1 +1,3 @@
|
|||
set history save on
|
||||
b __cxa_throw
|
||||
r
|
||||
|
|
|
@ -9,4 +9,29 @@
|
|||
dlsym
|
||||
Memcheck:Cond
|
||||
fun:_ZN4dyld9mkstringfEPKcz
|
||||
}
|
||||
|
||||
{
|
||||
osx
|
||||
Memcheck:Leak
|
||||
fun:malloc_zone_malloc
|
||||
fun:recursive_mutex_init
|
||||
fun:_objc_init
|
||||
fun:libSystem_initializer
|
||||
}
|
||||
|
||||
{
|
||||
throws
|
||||
Memcheck:Leak
|
||||
fun:calloc
|
||||
fun:__cxa_get_globals
|
||||
fun:__cxa_throw
|
||||
}
|
||||
|
||||
{
|
||||
osx
|
||||
Memcheck:Leak
|
||||
fun:malloc_zone_calloc
|
||||
...
|
||||
fun:map_images
|
||||
}
|
|
@ -20,75 +20,74 @@
|
|||
using std::vector;
|
||||
using zxing::BitArray;
|
||||
|
||||
int BitArray::wordsForBits(int bits) {
|
||||
int arraySize = (bits + bitsPerWord_ - 1) >> logBits_;
|
||||
return arraySize;
|
||||
int BitArray::makeArraySize(int size) {
|
||||
return (size + bitsPerWord-1) >> logBits;
|
||||
}
|
||||
|
||||
BitArray::BitArray(int size) :
|
||||
size_(size), bits_(wordsForBits(size), 0) {
|
||||
}
|
||||
BitArray::BitArray(int size_)
|
||||
: size(size_), bits(makeArraySize(size)) {}
|
||||
|
||||
BitArray::~BitArray() {
|
||||
}
|
||||
|
||||
int BitArray::getSize() const {
|
||||
return size_;
|
||||
return size;
|
||||
}
|
||||
|
||||
void BitArray::setBulk(int i, int newBits) {
|
||||
bits_[i >> logBits_] = newBits;
|
||||
bits[i >> logBits] = newBits;
|
||||
}
|
||||
|
||||
void BitArray::setRange(int start, int end) {
|
||||
/*
|
||||
void BitArray::setRange(int start, int end) {
|
||||
if (end < start) {
|
||||
throw IllegalArgumentException("invalid call to BitArray::setRange");
|
||||
throw IllegalArgumentException("invalid call to BitArray::setRange");
|
||||
}
|
||||
if (end == start) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
end--; // will be easier to treat this as the last actually set bit -- inclusive
|
||||
int firstInt = start >> 5;
|
||||
int lastInt = end >> 5;
|
||||
for (int i = firstInt; i <= lastInt; i++) {
|
||||
int firstBit = i > firstInt ? 0 : start & 0x1F;
|
||||
int lastBit = i < lastInt ? 31 : end & 0x1F;
|
||||
int mask;
|
||||
if (firstBit == 0 && lastBit == 31) {
|
||||
mask = -1;
|
||||
} else {
|
||||
mask = 0;
|
||||
for (int j = firstBit; j <= lastBit; j++) {
|
||||
mask |= 1 << j;
|
||||
}
|
||||
}
|
||||
bits_[i] |= mask;
|
||||
int firstBit = i > firstInt ? 0 : start & 0x1F;
|
||||
int lastBit = i < lastInt ? 31 : end & 0x1F;
|
||||
int mask;
|
||||
if (firstBit == 0 && lastBit == 31) {
|
||||
mask = -1;
|
||||
} else {
|
||||
mask = 0;
|
||||
for (int j = firstBit; j <= lastBit; j++) {
|
||||
mask |= 1 << j;
|
||||
}
|
||||
}
|
||||
}
|
||||
bits_[i] |= mask;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void BitArray::clear() {
|
||||
int max = bits_.size();
|
||||
int max = bits.size();
|
||||
for (int i = 0; i < max; i++) {
|
||||
bits_[i] = 0;
|
||||
bits[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool BitArray::isRange(int start, int end, bool value) {
|
||||
if (end < start) {
|
||||
throw IllegalArgumentException("end must be after start");
|
||||
throw IllegalArgumentException();
|
||||
}
|
||||
if (end == start) {
|
||||
return true;
|
||||
return true; // empty range matches
|
||||
}
|
||||
// treat the 'end' as inclusive, rather than exclusive
|
||||
end--;
|
||||
int firstWord = start >> logBits_;
|
||||
int lastWord = end >> logBits_;
|
||||
for (int i = firstWord; i <= lastWord; i++) {
|
||||
int firstBit = i > firstWord ? 0 : start & bitsMask_;
|
||||
int lastBit = i < lastWord ? bitsPerWord_ - 1: end & bitsMask_;
|
||||
end--; // will be easier to treat this as the last actually set bit -- inclusive
|
||||
int firstInt = start >> logBits;
|
||||
int lastInt = end >> logBits;
|
||||
for (int i = firstInt; i <= lastInt; i++) {
|
||||
int firstBit = i > firstInt ? 0 : start & bitsMask;
|
||||
int lastBit = i < lastInt ? (bitsPerWord-1) : end & bitsMask;
|
||||
int mask;
|
||||
if (firstBit == 0 && lastBit == bitsPerWord_ - 1) {
|
||||
if (firstBit == 0 && lastBit == (bitsPerWord-1)) {
|
||||
mask = -1;
|
||||
} else {
|
||||
mask = 0;
|
||||
|
@ -96,88 +95,87 @@ bool BitArray::isRange(int start, int end, bool value) {
|
|||
mask |= 1 << j;
|
||||
}
|
||||
}
|
||||
if (value) {
|
||||
if ((bits_[i] & mask) != mask) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if ((bits_[i] & mask) != 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is,
|
||||
// equals the mask, or we're looking for 0s and the masked portion is not all 0s
|
||||
if ((bits[i] & mask) != (value ? mask : 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
vector<int>& BitArray::getBitArray() {
|
||||
return bits_;
|
||||
return bits;
|
||||
}
|
||||
|
||||
void BitArray::reverse() {
|
||||
// std::cerr << "reverse" << std::endl;
|
||||
std::vector<int> newBits(bits_.size(), 0);
|
||||
for (int i = 0; i < size_; i++) {
|
||||
if (get(size_ - i - 1)) {
|
||||
newBits[i >> logBits_] |= 1<< (i & bitsMask_);
|
||||
vector<int> newBits(bits.size());
|
||||
int size = this->size;
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (get(size - i - 1)) {
|
||||
newBits[i >> logBits] |= 1 << (i & bitsMask);
|
||||
}
|
||||
}
|
||||
bits_ = newBits;
|
||||
bits = newBits;
|
||||
}
|
||||
|
||||
BitArray::Reverse::Reverse(Ref<BitArray> array_) : array(array_) {
|
||||
/*
|
||||
BitArray::Reverse::Reverse(Ref<BitArray> array_) : array(array_) {
|
||||
array->reverse();
|
||||
}
|
||||
|
||||
BitArray::Reverse::~Reverse() {
|
||||
array->reverse();
|
||||
}
|
||||
|
||||
namespace {
|
||||
int numberOfTrailingZeros(int i) {
|
||||
// HD, Figure 5-14
|
||||
int y;
|
||||
if (i == 0) return 32;
|
||||
int n = 31;
|
||||
y = i <<16; if (y != 0) { n = n -16; i = y; }
|
||||
y = i << 8; if (y != 0) { n = n - 8; i = y; }
|
||||
y = i << 4; if (y != 0) { n = n - 4; i = y; }
|
||||
y = i << 2; if (y != 0) { n = n - 2; i = y; }
|
||||
return n - (((unsigned int)(i << 1)) >> 31);
|
||||
}
|
||||
}
|
||||
|
||||
int BitArray::getNextSet(int from) {
|
||||
BitArray::Reverse::~Reverse() {
|
||||
array->reverse();
|
||||
}
|
||||
|
||||
namespace {
|
||||
int numberOfTrailingZeros(int i) {
|
||||
// HD, Figure 5-14
|
||||
int y;
|
||||
if (i == 0) return 32;
|
||||
int n = 31;
|
||||
y = i <<16; if (y != 0) { n = n -16; i = y; }
|
||||
y = i << 8; if (y != 0) { n = n - 8; i = y; }
|
||||
y = i << 4; if (y != 0) { n = n - 4; i = y; }
|
||||
y = i << 2; if (y != 0) { n = n - 2; i = y; }
|
||||
return n - (((unsigned int)(i << 1)) >> 31);
|
||||
}
|
||||
}
|
||||
|
||||
int BitArray::getNextSet(int from) {
|
||||
if (from >= size_) {
|
||||
return size_;
|
||||
return size_;
|
||||
}
|
||||
int bitsOffset = from >> 5;
|
||||
int currentBits = bits_[bitsOffset];
|
||||
// mask off lesser bits first
|
||||
currentBits &= ~((1 << (from & 0x1F)) - 1);
|
||||
while (currentBits == 0) {
|
||||
if (++bitsOffset == (int)bits_.size()) {
|
||||
return size_;
|
||||
}
|
||||
currentBits = bits_[bitsOffset];
|
||||
if (++bitsOffset == (int)bits_.size()) {
|
||||
return size_;
|
||||
}
|
||||
currentBits = bits_[bitsOffset];
|
||||
}
|
||||
int result = (bitsOffset << 5) + numberOfTrailingZeros(currentBits);
|
||||
return result > size_ ? size_ : result;
|
||||
}
|
||||
}
|
||||
|
||||
int BitArray::getNextUnset(int from) {
|
||||
int BitArray::getNextUnset(int from) {
|
||||
if (from >= size_) {
|
||||
return size_;
|
||||
return size_;
|
||||
}
|
||||
int bitsOffset = from >> 5;
|
||||
int currentBits = ~bits_[bitsOffset];
|
||||
// mask off lesser bits first
|
||||
currentBits &= ~((1 << (from & 0x1F)) - 1);
|
||||
while (currentBits == 0) {
|
||||
if (++bitsOffset == (int)bits_.size()) {
|
||||
return size_;
|
||||
}
|
||||
currentBits = ~bits_[bitsOffset];
|
||||
if (++bitsOffset == (int)bits_.size()) {
|
||||
return size_;
|
||||
}
|
||||
currentBits = ~bits_[bitsOffset];
|
||||
}
|
||||
int result = (bitsOffset << 5) + numberOfTrailingZeros(currentBits);
|
||||
return result > size_ ? size_ : result;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -38,15 +38,14 @@ namespace zxing {
|
|||
(-1))))))
|
||||
|
||||
class zxing::BitArray : public Counted {
|
||||
public:
|
||||
static const int bitsPerWord = std::numeric_limits<unsigned int>::digits;
|
||||
|
||||
private:
|
||||
int size_;
|
||||
std::vector<int> bits_;
|
||||
static const int bitsPerWord_ =
|
||||
std::numeric_limits<unsigned int>::digits;
|
||||
static const int logBits_ = ZX_LOG_DIGITS(bitsPerWord_);
|
||||
static const int bitsMask_ = (1 << logBits_) - 1;
|
||||
static int wordsForBits(int bits);
|
||||
explicit BitArray();
|
||||
int size;
|
||||
std::vector<int> bits;
|
||||
static const int logBits = ZX_LOG_DIGITS(bitsPerWord);
|
||||
static const int bitsMask = (1 << logBits) - 1;
|
||||
|
||||
public:
|
||||
BitArray(int size);
|
||||
|
@ -54,11 +53,11 @@ public:
|
|||
int getSize() const;
|
||||
|
||||
bool get(int i) const {
|
||||
return (bits_[i >> logBits_] & (1 << (i & bitsMask_))) != 0;
|
||||
return (bits[i >> logBits] & (1 << (i & bitsMask))) != 0;
|
||||
}
|
||||
|
||||
void set(int i) {
|
||||
bits_[i >> logBits_] |= 1 << (i & bitsMask_);
|
||||
bits[i >> logBits] |= 1 << (i & bitsMask);
|
||||
}
|
||||
|
||||
int getNextSet(int from);
|
||||
|
@ -72,6 +71,9 @@ public:
|
|||
|
||||
void reverse();
|
||||
class Reverse;
|
||||
|
||||
private:
|
||||
static int makeArraySize(int size);
|
||||
};
|
||||
|
||||
class zxing::BitArray::Reverse {
|
||||
|
|
|
@ -30,43 +30,58 @@ using zxing::BitArray;
|
|||
using zxing::ArrayRef;
|
||||
using zxing::Ref;
|
||||
|
||||
namespace {
|
||||
int wordsForSize(int width,
|
||||
int height,
|
||||
int bitsPerWord,
|
||||
int logBits) {
|
||||
int bits = width * height;
|
||||
int arraySize = (bits + bitsPerWord - 1) >> logBits;
|
||||
return arraySize;
|
||||
void BitMatrix::init(int width, int height) {
|
||||
if (width < 1 || height < 1) {
|
||||
throw IllegalArgumentException("Both dimensions must be greater than 0");
|
||||
}
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
this->rowSize = (width + bitsPerWord - 1) >> logBits;
|
||||
bits = ArrayRef<int>(rowSize * height);
|
||||
}
|
||||
|
||||
BitMatrix::BitMatrix(int dimension) :
|
||||
width_(dimension), height_(dimension), words_(0) {
|
||||
words_ = wordsForSize(width_, height_, bitsPerWord, logBits);
|
||||
bits_ = ArrayRef<int>(words_);
|
||||
clear();
|
||||
BitMatrix::BitMatrix(int dimension) {
|
||||
init(dimension, dimension);
|
||||
}
|
||||
|
||||
BitMatrix::BitMatrix(int width, int height) :
|
||||
width_(width), height_(height), words_(0) {
|
||||
words_ = wordsForSize(width_, height_, bitsPerWord, logBits);
|
||||
bits_ = ArrayRef<int>(words_);
|
||||
clear();
|
||||
BitMatrix::BitMatrix(int width, int height) {
|
||||
init(width, height);
|
||||
}
|
||||
|
||||
BitMatrix::~BitMatrix() {}
|
||||
|
||||
|
||||
void BitMatrix::flip(int x, int y) {
|
||||
int offset = x + width_ * y;
|
||||
bits_[offset >> logBits] ^= 1 << (offset & bitsMask);
|
||||
int offset = y * rowSize + (x >> logBits);
|
||||
bits[offset] ^= 1 << (x & bitsMask);
|
||||
}
|
||||
|
||||
/*
|
||||
void BitMatrix::clear() {
|
||||
std::fill(&bits_[0], &bits_[words_], 0);
|
||||
std::fill(&bits[0], &bits[rowSize], 0);
|
||||
}
|
||||
*/
|
||||
|
||||
void BitMatrix::setRegion(int left, int top, int width, int height) {
|
||||
if (top < 0 || left < 0) {
|
||||
throw IllegalArgumentException("Left and top must be nonnegative");
|
||||
}
|
||||
if (height < 1 || width < 1) {
|
||||
throw IllegalArgumentException("Height and width must be at least 1");
|
||||
}
|
||||
int right = left + width;
|
||||
int bottom = top + height;
|
||||
if (bottom > this->height || right > this->width) {
|
||||
throw new IllegalArgumentException("The region must fit inside the matrix");
|
||||
}
|
||||
for (int y = top; y < bottom; y++) {
|
||||
int offset = y * rowSize;
|
||||
for (int x = left; x < right; x++) {
|
||||
bits[offset + (x >> logBits)] |= 1 << (x & bitsMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void BitMatrix::setRegion(int left, int top, int width, int height) {
|
||||
if ((long)top < 0 || (long)left < 0) {
|
||||
throw IllegalArgumentException("topI and leftJ must be nonnegative");
|
||||
|
@ -76,71 +91,43 @@ void BitMatrix::setRegion(int left, int top, int width, int height) {
|
|||
}
|
||||
int right = left + width;
|
||||
int bottom = top + height;
|
||||
if (right > width_ || bottom > height_) {
|
||||
if (right > this->width || bottom > this->height) {
|
||||
throw IllegalArgumentException("top + height and left + width must be <= matrix dimension");
|
||||
}
|
||||
for (int y = top; y < bottom; y++) {
|
||||
int yOffset = width_ * y;
|
||||
int offset = y * rowSize;
|
||||
for (int x = left; x < right; x++) {
|
||||
int offset = x + yOffset;
|
||||
bits_[offset >> logBits] |= 1 << (offset & bitsMask);
|
||||
bits[offset + (x >> 5)] |= 1 << (offset & bitsMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
Ref<BitArray> BitMatrix::getRow(int y, Ref<BitArray> row) {
|
||||
if (row.empty() || row->getSize() < width_) {
|
||||
row = new BitArray(width_);
|
||||
} else {
|
||||
row->clear();
|
||||
if (row.empty() || row->getSize() < width) {
|
||||
row = new BitArray(width);
|
||||
}
|
||||
int start = y * width_;
|
||||
int end = start + width_ - 1; // end is inclusive
|
||||
int firstWord = start >> logBits;
|
||||
int lastWord = end >> logBits;
|
||||
int bitOffset = start & bitsMask;
|
||||
for (int i = firstWord; i <= lastWord; i++) {
|
||||
int firstBit = i > firstWord ? 0 : start & bitsMask;
|
||||
int lastBit = i < lastWord ? bitsPerWord - 1 : end & bitsMask;
|
||||
int mask;
|
||||
if (firstBit == 0 && lastBit == logBits) {
|
||||
mask = std::numeric_limits<int>::max();
|
||||
} else {
|
||||
mask = 0;
|
||||
for (int j = firstBit; j <= lastBit; j++) {
|
||||
mask |= 1 << j;
|
||||
}
|
||||
}
|
||||
row->setBulk((i - firstWord) << logBits, (bits_[i] & mask) >> bitOffset);
|
||||
if (firstBit == 0 && bitOffset != 0) {
|
||||
int prevBulk = row->getBitArray()[i - firstWord - 1];
|
||||
prevBulk |= (bits_[i] & mask) << (bitsPerWord - bitOffset);
|
||||
row->setBulk((i - firstWord - 1) << logBits, prevBulk);
|
||||
}
|
||||
int offset = y * rowSize;
|
||||
for (int x = 0; x < rowSize; x++) {
|
||||
row->setBulk(x << logBits, bits[offset + x]);
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
int BitMatrix::getWidth() const {
|
||||
return width_;
|
||||
return width;
|
||||
}
|
||||
|
||||
int BitMatrix::getHeight() const {
|
||||
return height_;
|
||||
}
|
||||
|
||||
int BitMatrix::getDimension() const {
|
||||
return width_;
|
||||
}
|
||||
|
||||
ArrayRef<int> BitMatrix::getBits() const {
|
||||
return bits_;
|
||||
return height;
|
||||
}
|
||||
|
||||
/*
|
||||
namespace zxing {
|
||||
ostream& operator<<(ostream &out, const BitMatrix &bm) {
|
||||
for (int y = 0; y < bm.height_; y++) {
|
||||
for (int x = 0; x < bm.width_; x++) {
|
||||
for (int y = 0; y < bm.height; y++) {
|
||||
for (int x = 0; x < bm.width; x++) {
|
||||
out << (bm.get(x, y) ? "X " : " ");
|
||||
}
|
||||
out << "\n";
|
||||
|
@ -154,3 +141,5 @@ const char* BitMatrix::description() {
|
|||
out << *this;
|
||||
return out.str().c_str();
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
|
@ -31,11 +31,14 @@ namespace zxing {
|
|||
}
|
||||
|
||||
class zxing::BitMatrix : public Counted {
|
||||
public:
|
||||
static const int bitsPerWord = std::numeric_limits<unsigned int>::digits;
|
||||
|
||||
private:
|
||||
int width_;
|
||||
int height_;
|
||||
int words_;
|
||||
ArrayRef<int> bits_;
|
||||
int width;
|
||||
int height;
|
||||
int rowSize;
|
||||
ArrayRef<int> bits;
|
||||
|
||||
#define ZX_LOG_DIGITS(digits) \
|
||||
((digits == 8) ? 3 : \
|
||||
|
@ -45,8 +48,6 @@ private:
|
|||
((digits == 128) ? 7 : \
|
||||
(-1))))))
|
||||
|
||||
static const int bitsPerWord =
|
||||
std::numeric_limits<unsigned int>::digits;
|
||||
static const int logBits = ZX_LOG_DIGITS(bitsPerWord);
|
||||
static const int bitsMask = (1 << logBits) - 1;
|
||||
|
||||
|
@ -57,13 +58,13 @@ public:
|
|||
~BitMatrix();
|
||||
|
||||
bool get(int x, int y) const {
|
||||
int offset = x + width_ * y;
|
||||
return ((bits_[offset >> logBits] >> (offset & bitsMask)) & 0x01) != 0;
|
||||
int offset = y * rowSize + (x >> logBits);
|
||||
return ((((unsigned)bits[offset]) >> (x & bitsMask)) & 1) != 0;
|
||||
}
|
||||
|
||||
void set(int x, int y) {
|
||||
int offset = x + width_ * y;
|
||||
bits_[offset >> logBits] |= 1 << (offset & bitsMask);
|
||||
int offset = y * rowSize + (x >> logBits);
|
||||
bits[offset] |= 1 << (x & bitsMask);
|
||||
}
|
||||
|
||||
void flip(int x, int y);
|
||||
|
@ -71,16 +72,17 @@ public:
|
|||
void setRegion(int left, int top, int width, int height);
|
||||
Ref<BitArray> getRow(int y, Ref<BitArray> row);
|
||||
|
||||
int getDimension() const;
|
||||
int getWidth() const;
|
||||
int getHeight() const;
|
||||
|
||||
ArrayRef<int> getBits() const;
|
||||
// ArrayRef<int> getBits() const;
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &out, const BitMatrix &bm);
|
||||
const char *description();
|
||||
|
||||
private:
|
||||
inline void init(int, int);
|
||||
|
||||
BitMatrix(const BitMatrix&);
|
||||
BitMatrix& operator =(const BitMatrix&);
|
||||
};
|
||||
|
|
|
@ -20,12 +20,8 @@
|
|||
|
||||
#include <zxing/common/IllegalArgumentException.h>
|
||||
|
||||
namespace zxing {
|
||||
using zxing::IllegalArgumentException;
|
||||
|
||||
IllegalArgumentException::IllegalArgumentException(const char *msg) :
|
||||
Exception(msg) {
|
||||
}
|
||||
IllegalArgumentException::~IllegalArgumentException() throw() {
|
||||
|
||||
}
|
||||
}
|
||||
IllegalArgumentException::IllegalArgumentException() : Exception() {}
|
||||
IllegalArgumentException::IllegalArgumentException(const char *msg) : Exception(msg) {}
|
||||
IllegalArgumentException::~IllegalArgumentException() throw() {}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
namespace zxing {
|
||||
class IllegalArgumentException : public zxing::Exception {
|
||||
public:
|
||||
IllegalArgumentException();
|
||||
IllegalArgumentException(const char *msg);
|
||||
~IllegalArgumentException() throw();
|
||||
};
|
||||
|
|
|
@ -33,7 +33,7 @@ int BitMatrixParser::copyBit(size_t x, size_t y, int versionBits) {
|
|||
BitMatrixParser::BitMatrixParser(Ref<BitMatrix> bitMatrix) : bitMatrix_(NULL),
|
||||
parsedVersion_(NULL),
|
||||
readBitMatrix_(NULL) {
|
||||
size_t dimension = bitMatrix->getDimension();
|
||||
size_t dimension = bitMatrix->getHeight();
|
||||
if (dimension < 8 || dimension > 144 || (dimension & 0x01) != 0)
|
||||
throw ReaderException("Dimension must be even, > 8 < 144");
|
||||
|
||||
|
@ -47,8 +47,8 @@ Ref<Version> BitMatrixParser::readVersion(Ref<BitMatrix> bitMatrix) {
|
|||
return parsedVersion_;
|
||||
}
|
||||
|
||||
int numRows = bitMatrix->getHeight();//getDimension();
|
||||
int numColumns = bitMatrix->getWidth();//numRows;
|
||||
int numRows = bitMatrix->getHeight();
|
||||
int numColumns = bitMatrix->getWidth();
|
||||
|
||||
Ref<Version> version = parsedVersion_->getVersionForDimensions(numRows, numColumns);
|
||||
if (version != 0) {
|
||||
|
|
|
@ -31,7 +31,7 @@ int BitMatrixParser::copyBit(size_t x, size_t y, int versionBits) {
|
|||
|
||||
BitMatrixParser::BitMatrixParser(Ref<BitMatrix> bitMatrix) :
|
||||
bitMatrix_(bitMatrix), parsedVersion_(0), parsedFormatInfo_() {
|
||||
size_t dimension = bitMatrix->getDimension();
|
||||
size_t dimension = bitMatrix->getHeight();
|
||||
if ((dimension < 21) || (dimension & 0x03) != 1) {
|
||||
throw ReaderException("Dimension must be 1 mod 4 and >= 21");
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ Ref<FormatInformation> BitMatrixParser::readFormatInformation() {
|
|||
}
|
||||
|
||||
// Read the top-right/bottom-left pattern
|
||||
int dimension = bitMatrix_->getDimension();
|
||||
int dimension = bitMatrix_->getHeight();
|
||||
int formatInfoBits2 = 0;
|
||||
int jMin = dimension - 7;
|
||||
for (int j = dimension - 1; j >= jMin; j--) {
|
||||
|
@ -79,7 +79,7 @@ Version *BitMatrixParser::readVersion() {
|
|||
return parsedVersion_;
|
||||
}
|
||||
|
||||
int dimension = bitMatrix_->getDimension();
|
||||
int dimension = bitMatrix_->getHeight();
|
||||
|
||||
int provisionalVersion = (dimension - 17) >> 2;
|
||||
if (provisionalVersion <= 6) {
|
||||
|
@ -121,14 +121,11 @@ ArrayRef<char> BitMatrixParser::readCodewords() {
|
|||
Version *version = readVersion();
|
||||
|
||||
|
||||
// cerr << *bitMatrix_ << endl;
|
||||
// cerr << bitMatrix_->getDimension() << endl;
|
||||
|
||||
// Get the data mask for the format used in this QR Code. This will exclude
|
||||
// some bits from reading as we wind through the bit matrix.
|
||||
DataMask &dataMask = DataMask::forReference((int)formatInfo->getDataMask());
|
||||
// cout << (int)formatInfo->getDataMask() << endl;
|
||||
int dimension = bitMatrix_->getDimension();
|
||||
int dimension = bitMatrix_->getHeight();
|
||||
dataMask.unmaskBitMatrix(*bitMatrix_, dimension);
|
||||
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ namespace zxing {
|
|||
CPPUNIT_TEST_SUITE_REGISTRATION(BitArrayTest);
|
||||
|
||||
void BitArrayTest::testGetSet() {
|
||||
size_t bits = numeric_limits<unsigned int>::digits + 1;
|
||||
const int bits = BitArray::bitsPerWord + 1;
|
||||
BitArray array(bits);
|
||||
for(size_t i = 0; i < bits; i++) {
|
||||
for(int i = 0; i < bits; i++) {
|
||||
CPPUNIT_ASSERT_EQUAL(false, array.get(i));
|
||||
array.set(i);
|
||||
CPPUNIT_ASSERT_EQUAL(true, array.get(i));
|
||||
|
@ -50,19 +50,19 @@ void BitArrayTest::testSetBulk() {
|
|||
}
|
||||
|
||||
void BitArrayTest::testClear() {
|
||||
size_t bits = numeric_limits<unsigned int>::digits;
|
||||
const int bits = BitArray::bitsPerWord;
|
||||
BitArray array(bits);
|
||||
for(size_t i = 0; i < bits; i++) {
|
||||
for(int i = 0; i < bits; i++) {
|
||||
array.set(i);
|
||||
}
|
||||
array.clear();
|
||||
for(size_t i = 0; i < bits; i++) {
|
||||
for(int i = 0; i < bits; i++) {
|
||||
CPPUNIT_ASSERT_EQUAL(false, array.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
void BitArrayTest::testGetArray() {
|
||||
size_t bits = numeric_limits<unsigned int>::digits;
|
||||
const int bits = BitArray::bitsPerWord;
|
||||
BitArray array(2 * bits);
|
||||
array.set(0);
|
||||
array.set(2 * bits - 1);
|
||||
|
@ -72,8 +72,8 @@ void BitArrayTest::testGetArray() {
|
|||
}
|
||||
|
||||
void BitArrayTest::testIsRange() {
|
||||
size_t bits = numeric_limits<unsigned int>::digits;
|
||||
size_t bits2 = 2 * bits;
|
||||
const int bits = BitArray::bitsPerWord;
|
||||
int bits2 = 2 * bits;
|
||||
BitArray array(bits2);
|
||||
CPPUNIT_ASSERT_EQUAL(true, array.isRange(0, bits2, false));
|
||||
CPPUNIT_ASSERT_EQUAL(false, array.isRange(0, bits2, true));
|
||||
|
@ -83,7 +83,7 @@ void BitArrayTest::testIsRange() {
|
|||
CPPUNIT_ASSERT_EQUAL(true, array.isRange(bits - 1, bits + 1, true));
|
||||
array.set(bits + 2);
|
||||
CPPUNIT_ASSERT_EQUAL(false, array.isRange(bits - 1, bits + 3, true));
|
||||
for(size_t i = 0; i < bits - 1; i++) {
|
||||
for(int i = 0; i < bits - 1; i++) {
|
||||
array.set(i);
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL(true, array.isRange(0, bits + 1, true));
|
||||
|
@ -108,39 +108,39 @@ void BitArrayTest::fillRandom(BitArray& test, BitArray& reference) {
|
|||
void BitArrayTest::testReverseHalves() {
|
||||
// one word test, split in half
|
||||
{
|
||||
size_t bits = numeric_limits<unsigned int>::digits;
|
||||
const int bits = BitArray::bitsPerWord;
|
||||
BitArray test(bits);
|
||||
|
||||
test.clear();
|
||||
for(size_t i = 0; i < bits / 2; ++i) {
|
||||
for(int i = 0; i < bits / 2; ++i) {
|
||||
test.set(i);
|
||||
}
|
||||
|
||||
test.reverse();
|
||||
for(size_t i = 0; i < bits / 2; ++i) {
|
||||
for(int i = 0; i < bits / 2; ++i) {
|
||||
CPPUNIT_ASSERT_EQUAL(test.get(i), !test.get(bits - 1 - i));
|
||||
}
|
||||
}
|
||||
|
||||
// two word test
|
||||
{
|
||||
size_t bits2 = numeric_limits<unsigned int>::digits * 2;
|
||||
const int bits2 = BitArray::bitsPerWord * 2;
|
||||
BitArray test2(bits2);
|
||||
|
||||
test2.clear();
|
||||
for(size_t i = 0; i < bits2 / 2; ++i) {
|
||||
for(int i = 0; i < bits2 / 2; ++i) {
|
||||
test2.set(i);
|
||||
}
|
||||
|
||||
test2.reverse();
|
||||
for(size_t i = 0; i < bits2 / 2; ++i) {
|
||||
for(int i = 0; i < bits2 / 2; ++i) {
|
||||
CPPUNIT_ASSERT_EQUAL(test2.get(i), !test2.get(bits2 - 1 - i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BitArrayTest::testReverseEven() {
|
||||
size_t bits = numeric_limits<unsigned int>::digits * 8;
|
||||
const int bits = BitArray::bitsPerWord * 8;
|
||||
BitArray test(bits);
|
||||
BitArray reference(bits);
|
||||
|
||||
|
@ -150,13 +150,13 @@ void BitArrayTest::testReverseEven() {
|
|||
fillRandom(test, reference);
|
||||
|
||||
test.reverse();
|
||||
for(size_t i = 0; i < bits; ++i) {
|
||||
for(int i = 0; i < bits; ++i) {
|
||||
CPPUNIT_ASSERT_EQUAL(test.get(i), reference.get(bits - 1 - i));
|
||||
}
|
||||
}
|
||||
|
||||
void BitArrayTest::testReverseOdd() {
|
||||
size_t bits = numeric_limits<unsigned int>::digits * 6 + 11;
|
||||
const int bits = BitArray::bitsPerWord * 6 + 11;
|
||||
BitArray test(bits);
|
||||
BitArray reference(bits);
|
||||
|
||||
|
@ -166,14 +166,14 @@ void BitArrayTest::testReverseOdd() {
|
|||
fillRandom(test, reference);
|
||||
|
||||
test.reverse();
|
||||
for(size_t i = 0; i < bits; ++i) {
|
||||
for(int i = 0; i < bits; ++i) {
|
||||
CPPUNIT_ASSERT_EQUAL(test.get(i), reference.get(bits - 1 - i));
|
||||
}
|
||||
}
|
||||
|
||||
void BitArrayTest::testReverseSweep() {
|
||||
size_t bits;
|
||||
size_t bitsHigh = numeric_limits<unsigned int>::digits * 10;
|
||||
int bits;
|
||||
const int bitsHigh = BitArray::bitsPerWord * 10;
|
||||
|
||||
for(bits = 1; bits < bitsHigh; ++bits) {
|
||||
BitArray test(bits);
|
||||
|
@ -185,14 +185,14 @@ void BitArrayTest::testReverseSweep() {
|
|||
fillRandom(test, reference);
|
||||
|
||||
test.reverse();
|
||||
for(size_t i = 0; i < bits; ++i) {
|
||||
for(int i = 0; i < bits; ++i) {
|
||||
CPPUNIT_ASSERT_EQUAL(test.get(i), reference.get(bits - 1 - i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BitArrayTest::testReverseReverse() {
|
||||
size_t bits = numeric_limits<unsigned int>::digits * 4 + 17;
|
||||
const int bits = BitArray::bitsPerWord * 4 + 17;
|
||||
BitArray test(bits);
|
||||
BitArray reference(bits);
|
||||
|
||||
|
@ -203,12 +203,12 @@ void BitArrayTest::testReverseReverse() {
|
|||
|
||||
// flip it once and test
|
||||
test.reverse();
|
||||
for(size_t i = 0; i < bits; ++i) {
|
||||
for(int i = 0; i < bits; ++i) {
|
||||
CPPUNIT_ASSERT_EQUAL(test.get(i), reference.get(bits - 1 - i));
|
||||
}
|
||||
// flip it back and test
|
||||
test.reverse();
|
||||
for(size_t i = 0; i < bits; ++i) {
|
||||
for(int i = 0; i < bits; ++i) {
|
||||
CPPUNIT_ASSERT_EQUAL(test.get(i), reference.get(i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,9 +32,9 @@ BitMatrixTest::BitMatrixTest() {
|
|||
}
|
||||
|
||||
void BitMatrixTest::testGetSet() {
|
||||
int bits = numeric_limits<int>::digits;
|
||||
const int bits = BitMatrix::bitsPerWord;
|
||||
BitMatrix matrix(bits + 1);
|
||||
CPPUNIT_ASSERT_EQUAL(bits + 1, matrix.getDimension());
|
||||
CPPUNIT_ASSERT_EQUAL(bits + 1, matrix.getHeight());
|
||||
for (int i = 0; i < bits + 1; i++) {
|
||||
for (int j = 0; j < bits + 1; j++) {
|
||||
if (i * j % 3 == 0) {
|
||||
|
@ -60,13 +60,10 @@ void BitMatrixTest::testSetRegion() {
|
|||
}
|
||||
}
|
||||
|
||||
void BitMatrixTest::testGetBits() {
|
||||
BitMatrix matrix(6);
|
||||
matrix.set(0, 0);
|
||||
matrix.set(5, 5);
|
||||
ArrayRef<int> bits = matrix.getBits();
|
||||
CPPUNIT_ASSERT_EQUAL(1, bits[0]);
|
||||
CPPUNIT_ASSERT_EQUAL(8, bits[1]);
|
||||
void BitMatrixTest::testGetRow0() {
|
||||
const int width = 2;
|
||||
const int height = 2;
|
||||
runBitMatrixGetRowTest(width, height);
|
||||
}
|
||||
|
||||
void BitMatrixTest::testGetRow1() {
|
||||
|
@ -91,7 +88,8 @@ void BitMatrixTest::runBitMatrixGetRowTest(int width, int height) {
|
|||
BitMatrix mat(width, height);
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
if ((rand() & 0x01) != 0) {
|
||||
bool v = ((rand() & 0x01) != 0);
|
||||
if (v) {
|
||||
mat.set(x, y);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class BitMatrixTest : public CPPUNIT_NS::TestFixture {
|
|||
CPPUNIT_TEST_SUITE(BitMatrixTest);
|
||||
CPPUNIT_TEST(testGetSet);
|
||||
CPPUNIT_TEST(testSetRegion);
|
||||
CPPUNIT_TEST(testGetBits);
|
||||
CPPUNIT_TEST(testGetRow0);
|
||||
CPPUNIT_TEST(testGetRow1);
|
||||
CPPUNIT_TEST(testGetRow2);
|
||||
CPPUNIT_TEST(testGetRow3);
|
||||
|
@ -41,7 +41,7 @@ public:
|
|||
protected:
|
||||
void testGetSet();
|
||||
void testSetRegion();
|
||||
void testGetBits();
|
||||
void testGetRow0();
|
||||
void testGetRow1();
|
||||
void testGetRow2();
|
||||
void testGetRow3();
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* BlackPointEstimatorTest.cpp
|
||||
* zxing
|
||||
*
|
||||
* Created by Christian Brunschen on 12/05/2008.
|
||||
* Copyright 2008 Google UK. All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "BlackPointEstimatorTest.h"
|
||||
#include <zxing/common/IllegalArgumentException.h>
|
||||
#include <vector>
|
||||
|
||||
namespace zxing {
|
||||
using namespace std;
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(BlackPointEstimatorTest);
|
||||
|
||||
void BlackPointEstimatorTest::testBasic() {
|
||||
int histogramRaw[] = { 0, 0, 11, 43, 37, 18, 3, 1, 0, 0, 13, 36, 24, 0, 11, 2 };
|
||||
vector<int> histogram(histogramRaw, histogramRaw+16);
|
||||
ArrayRef<int> array (new Array<int>(histogram));
|
||||
int point = GlobalHistogramBinarizer::estimateBlackPoint(array);
|
||||
CPPUNIT_ASSERT_EQUAL((int)64, point);
|
||||
}
|
||||
|
||||
void BlackPointEstimatorTest::testTooLittleRange() {
|
||||
try {
|
||||
int histogramRaw[] = { 0, 0, 0, 0, 0, 0, 1, 43, 48, 18, 3, 1, 0, 0, 0, 0 };
|
||||
vector<int> histogram(histogramRaw, histogramRaw+16);
|
||||
ArrayRef<int> array (new Array<int>(histogram));
|
||||
GlobalHistogramBinarizer::estimateBlackPoint(array);
|
||||
CPPUNIT_FAIL("Should have thrown an exception");
|
||||
|
||||
} catch (IllegalArgumentException ie) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
#ifndef __BLACK_POINT_ESTIMATOR_TEST_H__
|
||||
#define __BLACK_POINT_ESTIMATOR_TEST_H__
|
||||
|
||||
/*
|
||||
* BlackPointEstimatorTest.h
|
||||
* zxing
|
||||
*
|
||||
* Copyright 2010 ZXing authors All rights reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <zxing/common/GlobalHistogramBinarizer.h>
|
||||
|
||||
namespace zxing {
|
||||
class BlackPointEstimatorTest : public CPPUNIT_NS::TestFixture {
|
||||
CPPUNIT_TEST_SUITE(BlackPointEstimatorTest);
|
||||
CPPUNIT_TEST(testBasic);
|
||||
CPPUNIT_TEST(testTooLittleRange);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
void testBasic();
|
||||
void testTooLittleRange();
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
#endif // __BLACK_POINT_ESTIMATOR_TEST_H__
|
|
@ -58,6 +58,7 @@ void ReedSolomonTest::setUp() {
|
|||
}
|
||||
|
||||
void ReedSolomonTest::tearDown() {
|
||||
delete qrRSDecoder_;
|
||||
}
|
||||
|
||||
void ReedSolomonTest::testNoError() {
|
||||
|
|
|
@ -48,7 +48,7 @@ static void checkVersion(Version *version, int number, int dimension) {
|
|||
CPPUNIT_TEST_SUITE_REGISTRATION(VersionTest);
|
||||
|
||||
void VersionTest::testVersionForNumber() {
|
||||
for (size_t i = 1; i <= Version::VERSIONS.size(); i++) {
|
||||
for (int i = 1; i <= (int)Version::VERSIONS.size(); i++) {
|
||||
Version *v = Version::VERSIONS[i-1];
|
||||
CPPUNIT_ASSERT_EQUAL((int)i, v->getVersionNumber());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue