mirror of
https://github.com/zxing/zxing.git
synced 2025-02-02 05:41:08 -08:00
C++ port made more compatible with uSTL (no functional changes).
git-svn-id: https://zxing.googlecode.com/svn/trunk@1271 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
a7ed5f7b5c
commit
d2aacefff2
|
@ -21,7 +21,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <zxing/BinaryBitmap.h>
|
#include <zxing/BinaryBitmap.h>
|
||||||
#include <zxing/Result.h>
|
#include <zxing/Result.h>
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <valarray>
|
#include <vector>
|
||||||
#include <cstdarg>
|
|
||||||
|
|
||||||
#ifdef DEBUG_COUNTING
|
#ifdef DEBUG_COUNTING
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -37,17 +36,17 @@ namespace zxing {
|
||||||
template<typename T> class Array : public Counted {
|
template<typename T> class Array : public Counted {
|
||||||
protected:
|
protected:
|
||||||
public:
|
public:
|
||||||
std::valarray<T> values_;
|
std::vector<T> values_;
|
||||||
Array(size_t n) :
|
Array(size_t n) :
|
||||||
Counted(), values_(T(), n) {
|
Counted(), values_(n, T()) {
|
||||||
}
|
}
|
||||||
Array(T *ts, size_t n) :
|
Array(T *ts, size_t n) :
|
||||||
Counted(), values_(ts, n) {
|
Counted(), values_(ts, ts+n) {
|
||||||
}
|
}
|
||||||
Array(T v, size_t n) :
|
Array(T v, size_t n) :
|
||||||
Counted(), values_(v, n) {
|
Counted(), values_(n, v) {
|
||||||
}
|
}
|
||||||
Array(std::valarray<T> &v) :
|
Array(std::vector<T> &v) :
|
||||||
Counted(), values_(v) {
|
Counted(), values_(v) {
|
||||||
}
|
}
|
||||||
Array(Array<T> &other) :
|
Array(Array<T> &other) :
|
||||||
|
@ -68,7 +67,7 @@ public:
|
||||||
#endif
|
#endif
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Array<T>& operator=(const std::valarray<T> &array) {
|
Array<T>& operator=(const std::vector<T> &array) {
|
||||||
#ifdef DEBUG_COUNTING
|
#ifdef DEBUG_COUNTING
|
||||||
cout << "assigning values from Array " << &array << " to this Array " << this << ", ";
|
cout << "assigning values from Array " << &array << " to this Array " << this << ", ";
|
||||||
#endif
|
#endif
|
||||||
|
@ -87,10 +86,10 @@ public:
|
||||||
size_t size() const {
|
size_t size() const {
|
||||||
return values_.size();
|
return values_.size();
|
||||||
}
|
}
|
||||||
std::valarray<T> values() const {
|
std::vector<T> values() const {
|
||||||
return values_;
|
return values_;
|
||||||
}
|
}
|
||||||
std::valarray<T>& values() {
|
std::vector<T>& values() {
|
||||||
return values_;
|
return values_;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,7 +33,7 @@ static unsigned int logDigits(unsigned digits) {
|
||||||
}
|
}
|
||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
const unsigned int BitArray::bitsPerWord_ = numeric_limits<unsigned int>::digits;
|
const unsigned int BitArray::bitsPerWord_ = sizeof(unsigned int)*8;
|
||||||
const unsigned int BitArray::logBits_ = logDigits(bitsPerWord_);
|
const unsigned int BitArray::logBits_ = logDigits(bitsPerWord_);
|
||||||
const unsigned int BitArray::bitsMask_ = (1 << logBits_) - 1;
|
const unsigned int BitArray::bitsMask_ = (1 << logBits_) - 1;
|
||||||
size_t BitArray::wordsForBits(size_t bits) {
|
size_t BitArray::wordsForBits(size_t bits) {
|
||||||
|
@ -48,7 +48,7 @@ BitArray::BitArray() {
|
||||||
}
|
}
|
||||||
|
|
||||||
BitArray::BitArray(size_t size) :
|
BitArray::BitArray(size_t size) :
|
||||||
size_(size), bits_((const unsigned int)0, wordsForBits(size)) {
|
size_(size), bits_(wordsForBits(size), (const unsigned int)0) {
|
||||||
}
|
}
|
||||||
BitArray::~BitArray() {
|
BitArray::~BitArray() {
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ bool BitArray::isRange(size_t start, size_t end, bool value) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
valarray<unsigned int>& BitArray::getBitArray() {
|
vector<unsigned int>& BitArray::getBitArray() {
|
||||||
return bits_;
|
return bits_;
|
||||||
}
|
}
|
||||||
void BitArray::reverse() {
|
void BitArray::reverse() {
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
#include <zxing/common/Counted.h>
|
#include <zxing/common/Counted.h>
|
||||||
#include <zxing/common/IllegalArgumentException.h>
|
#include <zxing/common/IllegalArgumentException.h>
|
||||||
#include <valarray>
|
#include <vector>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ namespace zxing {
|
||||||
class BitArray : public Counted {
|
class BitArray : public Counted {
|
||||||
private:
|
private:
|
||||||
size_t size_;
|
size_t size_;
|
||||||
std::valarray<unsigned int> bits_;
|
std::vector<unsigned int> bits_;
|
||||||
static const unsigned int bitsPerWord_;
|
static const unsigned int bitsPerWord_;
|
||||||
static const unsigned int logBits_;
|
static const unsigned int logBits_;
|
||||||
static const unsigned int bitsMask_;
|
static const unsigned int bitsMask_;
|
||||||
|
@ -48,7 +48,7 @@ public:
|
||||||
void setBulk(size_t i, unsigned int newBits);
|
void setBulk(size_t i, unsigned int newBits);
|
||||||
void clear();
|
void clear();
|
||||||
bool isRange(size_t start, size_t end, bool value);
|
bool isRange(size_t start, size_t end, bool value);
|
||||||
std::valarray<unsigned int>& getBitArray();
|
std::vector<unsigned int>& getBitArray();
|
||||||
void reverse();
|
void reverse();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -40,7 +39,7 @@ unsigned int logDigits(unsigned digits) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const unsigned int bitsPerWord = std::numeric_limits<unsigned int>::digits;
|
const unsigned int bitsPerWord = sizeof(unsigned int)*8;
|
||||||
const unsigned int logBits = logDigits(bitsPerWord);
|
const unsigned int logBits = logDigits(bitsPerWord);
|
||||||
const unsigned int bitsMask = (1 << logBits) - 1;
|
const unsigned int bitsMask = (1 << logBits) - 1;
|
||||||
|
|
||||||
|
@ -90,7 +89,7 @@ void BitMatrix::flip(size_t x, size_t y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitMatrix::clear() {
|
void BitMatrix::clear() {
|
||||||
std::memset(bits_, 0, sizeof(unsigned int) * words_);
|
std::fill(bits_, bits_+words_, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BitMatrix::setRegion(size_t left, size_t top, size_t width, size_t height) {
|
void BitMatrix::setRegion(size_t left, size_t top, size_t width, size_t height) {
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zxing/common/Counted.h>
|
#include <zxing/common/Counted.h>
|
||||||
#include <valarray>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include <zxing/common/EdgeDetector.h>
|
#include <zxing/common/EdgeDetector.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace zxing {
|
||||||
|
|
||||||
|
|
||||||
Ref<BitArray> GlobalHistogramBinarizer::estimateBlackRow(int y, Ref<BitArray> row){
|
Ref<BitArray> GlobalHistogramBinarizer::estimateBlackRow(int y, Ref<BitArray> row){
|
||||||
valarray<int> histogram(0, LUMINANCE_BUCKETS);
|
vector<int> histogram(LUMINANCE_BUCKETS, 0);
|
||||||
LuminanceSource& source = *getSource();
|
LuminanceSource& source = *getSource();
|
||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
if (row == NULL || row->getSize() < width) {
|
if (row == NULL || row->getSize() < width) {
|
||||||
|
@ -80,7 +80,7 @@ namespace zxing {
|
||||||
LuminanceSource& source = *getSource();
|
LuminanceSource& source = *getSource();
|
||||||
int width = source.getWidth();
|
int width = source.getWidth();
|
||||||
int height = source.getHeight();
|
int height = source.getHeight();
|
||||||
valarray<int> histogram(0, LUMINANCE_BUCKETS);
|
vector<int> histogram(LUMINANCE_BUCKETS, 0);
|
||||||
|
|
||||||
|
|
||||||
// Quickly calculates the histogram by sampling four rows from the image. This proved to be
|
// Quickly calculates the histogram by sampling four rows from the image. This proved to be
|
||||||
|
@ -109,7 +109,7 @@ namespace zxing {
|
||||||
return matrix_ref;
|
return matrix_ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GlobalHistogramBinarizer::estimate(valarray<int> &histogram) {
|
int GlobalHistogramBinarizer::estimate(vector<int> &histogram) {
|
||||||
int numBuckets = histogram.size();
|
int numBuckets = histogram.size();
|
||||||
int maxBucketCount = 0;
|
int maxBucketCount = 0;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#ifndef GLOBALHISTOGRAMBINARIZER_H_
|
#ifndef GLOBALHISTOGRAMBINARIZER_H_
|
||||||
#define GLOBALHISTOGRAMBINARIZER_H_
|
#define GLOBALHISTOGRAMBINARIZER_H_
|
||||||
|
|
||||||
#include <valarray>
|
#include <vector>
|
||||||
#include <zxing/Binarizer.h>
|
#include <zxing/Binarizer.h>
|
||||||
#include <zxing/common/BitArray.h>
|
#include <zxing/common/BitArray.h>
|
||||||
#include <zxing/common/BitMatrix.h>
|
#include <zxing/common/BitMatrix.h>
|
||||||
|
@ -36,7 +36,7 @@ namespace zxing {
|
||||||
|
|
||||||
virtual Ref<BitArray> estimateBlackRow(int y, Ref<BitArray> row);
|
virtual Ref<BitArray> estimateBlackRow(int y, Ref<BitArray> row);
|
||||||
virtual Ref<BitMatrix> estimateBlackMatrix();
|
virtual Ref<BitMatrix> estimateBlackMatrix();
|
||||||
static int estimate(std::valarray<int> &histogram);
|
static int estimate(std::vector<int> &histogram);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ GridSampler::GridSampler() {
|
||||||
|
|
||||||
Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {
|
Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {
|
||||||
Ref<BitMatrix> bits(new BitMatrix(dimension));
|
Ref<BitMatrix> bits(new BitMatrix(dimension));
|
||||||
valarray<float> points((const float)0.0f, dimension << 1);
|
vector<float> points(dimension << 1, (const float)0.0f);
|
||||||
for (int y = 0; y < dimension; y++) {
|
for (int y = 0; y < dimension; y++) {
|
||||||
int max = points.size();
|
int max = points.size();
|
||||||
float yValue = (float)y + 0.5f;
|
float yValue = (float)y + 0.5f;
|
||||||
|
@ -63,7 +63,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, floa
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GridSampler::checkAndNudgePoints(Ref<BitMatrix> image, valarray<float> &points) {
|
void GridSampler::checkAndNudgePoints(Ref<BitMatrix> image, vector<float> &points) {
|
||||||
int width = image->getWidth();
|
int width = image->getWidth();
|
||||||
int height = image->getHeight();
|
int height = image->getHeight();
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
Ref<BitMatrix> sampleGrid(Ref<BitMatrix> image, int dimension, float p1ToX, float p1ToY, float p2ToX, float p2ToY,
|
Ref<BitMatrix> sampleGrid(Ref<BitMatrix> image, int dimension, float p1ToX, float p1ToY, float p2ToX, float p2ToY,
|
||||||
float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX,
|
float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX,
|
||||||
float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY);
|
float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY);
|
||||||
static void checkAndNudgePoints(Ref<BitMatrix> image, std::valarray<float> &points);
|
static void checkAndNudgePoints(Ref<BitMatrix> image, std::vector<float> &points);
|
||||||
static GridSampler &getInstance();
|
static GridSampler &getInstance();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,7 +91,7 @@ Ref<PerspectiveTransform> PerspectiveTransform::times(Ref<PerspectiveTransform>
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PerspectiveTransform::transformPoints(valarray<float> &points) {
|
void PerspectiveTransform::transformPoints(vector<float> &points) {
|
||||||
int max = points.size();
|
int max = points.size();
|
||||||
float a11 = this->a11;
|
float a11 = this->a11;
|
||||||
float a12 = this->a12;
|
float a12 = this->a12;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zxing/common/Counted.h>
|
#include <zxing/common/Counted.h>
|
||||||
#include <valarray>
|
#include <vector>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
class PerspectiveTransform : public Counted {
|
class PerspectiveTransform : public Counted {
|
||||||
|
@ -41,7 +41,7 @@ public:
|
||||||
float x3, float y3);
|
float x3, float y3);
|
||||||
Ref<PerspectiveTransform> buildAdjoint();
|
Ref<PerspectiveTransform> buildAdjoint();
|
||||||
Ref<PerspectiveTransform> times(Ref<PerspectiveTransform> other);
|
Ref<PerspectiveTransform> times(Ref<PerspectiveTransform> other);
|
||||||
void transformPoints(std::valarray<float> &points);
|
void transformPoints(std::vector<float> &points);
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& out, PerspectiveTransform &pt);
|
friend std::ostream& operator<<(std::ostream& out, PerspectiveTransform &pt);
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,10 +18,10 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ZXING_POINT_H_
|
#ifndef ZXING_POINT_H_
|
||||||
#define ZXING_POINT_H_
|
#define ZXING_POINT_H_
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
class PointI {
|
class PointI {
|
||||||
public:
|
public:
|
||||||
int x;
|
int x;
|
||||||
|
@ -30,6 +30,7 @@ public:
|
||||||
|
|
||||||
class Point {
|
class Point {
|
||||||
public:
|
public:
|
||||||
|
Point() : x(0.0f), y(0.0f) {};
|
||||||
Point(float x_, float y_) : x(x_), y(y_) {};
|
Point(float x_, float y_) : x(x_), y(y_) {};
|
||||||
|
|
||||||
float x;
|
float x;
|
||||||
|
@ -42,6 +43,6 @@ public:
|
||||||
|
|
||||||
Point start;
|
Point start;
|
||||||
Point end;
|
Point end;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // POINT_H_
|
#endif // POINT_H_
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <valarray>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <zxing/common/reedsolomon/GF256.h>
|
#include <zxing/common/reedsolomon/GF256.h>
|
||||||
|
@ -42,7 +41,7 @@ static inline Ref<GF256Poly> refPoly(GF256 &field, int value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GF256::GF256(int primitive) :
|
GF256::GF256(int primitive) :
|
||||||
exp_((const int)0, 256), log_((const int)0, 256), zero_(refPoly(*this, 0)), one_(refPoly(*this, 1)) {
|
exp_(256, (const int)0), log_(256, (const int)0), zero_(refPoly(*this, 0)), one_(refPoly(*this, 1)) {
|
||||||
int x = 1;
|
int x = 1;
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
exp_[i] = x;
|
exp_[i] = x;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <valarray>
|
#include <vector>
|
||||||
#include <zxing/common/Counted.h>
|
#include <zxing/common/Counted.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
|
@ -42,8 +42,8 @@ class GF256 {
|
||||||
* @author christian.brunschen@gmail.com (Christian Brunschen)
|
* @author christian.brunschen@gmail.com (Christian Brunschen)
|
||||||
*/
|
*/
|
||||||
private:
|
private:
|
||||||
std::valarray<int> exp_;
|
std::vector<int> exp_;
|
||||||
std::valarray<int> log_;
|
std::vector<int> log_;
|
||||||
Ref<GF256Poly> zero_;
|
Ref<GF256Poly> zero_;
|
||||||
Ref<GF256Poly> one_;
|
Ref<GF256Poly> one_;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zxing/datamatrix/Version.h>
|
#include <zxing/datamatrix/Version.h>
|
||||||
#include <cstdarg>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -66,135 +65,135 @@ ECBlocks::~ECBlocks() {
|
||||||
|
|
||||||
vector<Ref<Version> > Version::VERSIONS;
|
vector<Ref<Version> > Version::VERSIONS;
|
||||||
static int N_VERSIONS = Version::buildVersions();
|
static int N_VERSIONS = Version::buildVersions();
|
||||||
|
|
||||||
Version::Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows,
|
Version::Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows,
|
||||||
int dataRegionSizeColumns, ECBlocks* ecBlocks) : versionNumber_(versionNumber),
|
int dataRegionSizeColumns, ECBlocks* ecBlocks) : versionNumber_(versionNumber),
|
||||||
symbolSizeRows_(symbolSizeRows), symbolSizeColumns_(symbolSizeColumns),
|
symbolSizeRows_(symbolSizeRows), symbolSizeColumns_(symbolSizeColumns),
|
||||||
dataRegionSizeRows_(dataRegionSizeRows), dataRegionSizeColumns_(dataRegionSizeColumns),
|
dataRegionSizeRows_(dataRegionSizeRows), dataRegionSizeColumns_(dataRegionSizeColumns),
|
||||||
ecBlocks_(ecBlocks) {
|
ecBlocks_(ecBlocks) {
|
||||||
// Calculate the total number of codewords
|
// Calculate the total number of codewords
|
||||||
int total = 0;
|
int total = 0;
|
||||||
int ecCodewords = ecBlocks_->getECCodewords();
|
int ecCodewords = ecBlocks_->getECCodewords();
|
||||||
vector<ECB*> &ecbArray = ecBlocks_->getECBlocks();
|
vector<ECB*> &ecbArray = ecBlocks_->getECBlocks();
|
||||||
for (unsigned int i = 0; i < ecbArray.size(); i++) {
|
for (unsigned int i = 0; i < ecbArray.size(); i++) {
|
||||||
ECB *ecBlock = ecbArray[i];
|
ECB *ecBlock = ecbArray[i];
|
||||||
total += ecBlock->getCount() * (ecBlock->getDataCodewords() + ecCodewords);
|
total += ecBlock->getCount() * (ecBlock->getDataCodewords() + ecCodewords);
|
||||||
}
|
}
|
||||||
totalCodewords_ = total;
|
totalCodewords_ = total;
|
||||||
}
|
}
|
||||||
|
|
||||||
Version::~Version() {
|
Version::~Version() {
|
||||||
delete ecBlocks_;
|
delete ecBlocks_;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Version::getVersionNumber() {
|
|
||||||
return versionNumber_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Version::getSymbolSizeRows() {
|
int Version::getVersionNumber() {
|
||||||
return symbolSizeRows_;
|
return versionNumber_;
|
||||||
}
|
|
||||||
|
|
||||||
int Version::getSymbolSizeColumns() {
|
|
||||||
return symbolSizeColumns_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Version::getDataRegionSizeRows() {
|
|
||||||
return dataRegionSizeRows_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Version::getDataRegionSizeColumns() {
|
|
||||||
return dataRegionSizeColumns_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Version::getTotalCodewords() {
|
|
||||||
return totalCodewords_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ECBlocks* Version::getECBlocks() {
|
int Version::getSymbolSizeRows() {
|
||||||
return ecBlocks_;
|
return symbolSizeRows_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Version* Version::getVersionForDimensions(int numRows, int numColumns) {
|
int Version::getSymbolSizeColumns() {
|
||||||
if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
|
return symbolSizeColumns_;
|
||||||
throw ReaderException("Number of rows and columns must be even");
|
}
|
||||||
}
|
|
||||||
|
int Version::getDataRegionSizeRows() {
|
||||||
// TODO(bbrown): This is doing a linear search through the array of versions.
|
return dataRegionSizeRows_;
|
||||||
// If we interleave the rectangular versions with the square versions we could
|
}
|
||||||
// do a binary search.
|
|
||||||
for (int i = 0; i < N_VERSIONS; ++i){
|
int Version::getDataRegionSizeColumns() {
|
||||||
Version* version = VERSIONS[i];
|
return dataRegionSizeColumns_;
|
||||||
if (version->getSymbolSizeRows() == numRows && version->getSymbolSizeColumns() == numColumns) {
|
}
|
||||||
return version;
|
|
||||||
}
|
int Version::getTotalCodewords() {
|
||||||
|
return totalCodewords_;
|
||||||
|
}
|
||||||
|
|
||||||
|
ECBlocks* Version::getECBlocks() {
|
||||||
|
return ecBlocks_;
|
||||||
|
}
|
||||||
|
|
||||||
|
Version* Version::getVersionForDimensions(int numRows, int numColumns) {
|
||||||
|
if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {
|
||||||
|
throw ReaderException("Number of rows and columns must be even");
|
||||||
}
|
}
|
||||||
throw ReaderException("Error version not found");
|
|
||||||
|
// TODO(bbrown): This is doing a linear search through the array of versions.
|
||||||
|
// If we interleave the rectangular versions with the square versions we could
|
||||||
|
// do a binary search.
|
||||||
|
for (int i = 0; i < N_VERSIONS; ++i){
|
||||||
|
Version* version = VERSIONS[i];
|
||||||
|
if (version->getSymbolSizeRows() == numRows && version->getSymbolSizeColumns() == numColumns) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw ReaderException("Error version not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See ISO 16022:2006 5.5.1 Table 7
|
* See ISO 16022:2006 5.5.1 Table 7
|
||||||
*/
|
*/
|
||||||
int Version::buildVersions() {
|
int Version::buildVersions() {
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(1, 10, 10, 8, 8,
|
VERSIONS.push_back(Ref<Version>(new Version(1, 10, 10, 8, 8,
|
||||||
new ECBlocks(5, new ECB(1, 3)))));
|
new ECBlocks(5, new ECB(1, 3)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(2, 12, 12, 10, 10,
|
VERSIONS.push_back(Ref<Version>(new Version(2, 12, 12, 10, 10,
|
||||||
new ECBlocks(7, new ECB(1, 5)))));
|
new ECBlocks(7, new ECB(1, 5)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(3, 14, 14, 12, 12,
|
VERSIONS.push_back(Ref<Version>(new Version(3, 14, 14, 12, 12,
|
||||||
new ECBlocks(10, new ECB(1, 8)))));
|
new ECBlocks(10, new ECB(1, 8)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(4, 16, 16, 14, 14,
|
VERSIONS.push_back(Ref<Version>(new Version(4, 16, 16, 14, 14,
|
||||||
new ECBlocks(12, new ECB(1, 12)))));
|
new ECBlocks(12, new ECB(1, 12)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(5, 18, 18, 16, 16,
|
VERSIONS.push_back(Ref<Version>(new Version(5, 18, 18, 16, 16,
|
||||||
new ECBlocks(14, new ECB(1, 18)))));
|
new ECBlocks(14, new ECB(1, 18)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(6, 20, 20, 18, 18,
|
VERSIONS.push_back(Ref<Version>(new Version(6, 20, 20, 18, 18,
|
||||||
new ECBlocks(18, new ECB(1, 22)))));
|
new ECBlocks(18, new ECB(1, 22)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(7, 22, 22, 20, 20,
|
VERSIONS.push_back(Ref<Version>(new Version(7, 22, 22, 20, 20,
|
||||||
new ECBlocks(20, new ECB(1, 30)))));
|
new ECBlocks(20, new ECB(1, 30)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(8, 24, 24, 22, 22,
|
VERSIONS.push_back(Ref<Version>(new Version(8, 24, 24, 22, 22,
|
||||||
new ECBlocks(24, new ECB(1, 36)))));
|
new ECBlocks(24, new ECB(1, 36)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(9, 26, 26, 24, 24,
|
VERSIONS.push_back(Ref<Version>(new Version(9, 26, 26, 24, 24,
|
||||||
new ECBlocks(28, new ECB(1, 44)))));
|
new ECBlocks(28, new ECB(1, 44)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(10, 32, 32, 14, 14,
|
VERSIONS.push_back(Ref<Version>(new Version(10, 32, 32, 14, 14,
|
||||||
new ECBlocks(36, new ECB(1, 62)))));
|
new ECBlocks(36, new ECB(1, 62)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(11, 36, 36, 16, 16,
|
VERSIONS.push_back(Ref<Version>(new Version(11, 36, 36, 16, 16,
|
||||||
new ECBlocks(42, new ECB(1, 86)))));
|
new ECBlocks(42, new ECB(1, 86)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(12, 40, 40, 18, 18,
|
VERSIONS.push_back(Ref<Version>(new Version(12, 40, 40, 18, 18,
|
||||||
new ECBlocks(48, new ECB(1, 114)))));
|
new ECBlocks(48, new ECB(1, 114)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(13, 44, 44, 20, 20,
|
VERSIONS.push_back(Ref<Version>(new Version(13, 44, 44, 20, 20,
|
||||||
new ECBlocks(56, new ECB(1, 144)))));
|
new ECBlocks(56, new ECB(1, 144)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(14, 48, 48, 22, 22,
|
VERSIONS.push_back(Ref<Version>(new Version(14, 48, 48, 22, 22,
|
||||||
new ECBlocks(68, new ECB(1, 174)))));
|
new ECBlocks(68, new ECB(1, 174)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(15, 52, 52, 24, 24,
|
VERSIONS.push_back(Ref<Version>(new Version(15, 52, 52, 24, 24,
|
||||||
new ECBlocks(42, new ECB(2, 102)))));
|
new ECBlocks(42, new ECB(2, 102)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(16, 64, 64, 14, 14,
|
VERSIONS.push_back(Ref<Version>(new Version(16, 64, 64, 14, 14,
|
||||||
new ECBlocks(56, new ECB(2, 140)))));
|
new ECBlocks(56, new ECB(2, 140)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(17, 72, 72, 16, 16,
|
VERSIONS.push_back(Ref<Version>(new Version(17, 72, 72, 16, 16,
|
||||||
new ECBlocks(36, new ECB(4, 92)))));
|
new ECBlocks(36, new ECB(4, 92)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(18, 80, 80, 18, 18,
|
VERSIONS.push_back(Ref<Version>(new Version(18, 80, 80, 18, 18,
|
||||||
new ECBlocks(48, new ECB(4, 114)))));
|
new ECBlocks(48, new ECB(4, 114)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(19, 88, 88, 20, 20,
|
VERSIONS.push_back(Ref<Version>(new Version(19, 88, 88, 20, 20,
|
||||||
new ECBlocks(56, new ECB(4, 144)))));
|
new ECBlocks(56, new ECB(4, 144)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(20, 96, 96, 22, 22,
|
VERSIONS.push_back(Ref<Version>(new Version(20, 96, 96, 22, 22,
|
||||||
new ECBlocks(68, new ECB(4, 174)))));
|
new ECBlocks(68, new ECB(4, 174)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(21, 104, 104, 24, 24,
|
VERSIONS.push_back(Ref<Version>(new Version(21, 104, 104, 24, 24,
|
||||||
new ECBlocks(56, new ECB(6, 136)))));
|
new ECBlocks(56, new ECB(6, 136)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(22, 120, 120, 18, 18,
|
VERSIONS.push_back(Ref<Version>(new Version(22, 120, 120, 18, 18,
|
||||||
new ECBlocks(68, new ECB(6, 175)))));
|
new ECBlocks(68, new ECB(6, 175)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(23, 132, 132, 20, 20,
|
VERSIONS.push_back(Ref<Version>(new Version(23, 132, 132, 20, 20,
|
||||||
new ECBlocks(62, new ECB(8, 163)))));
|
new ECBlocks(62, new ECB(8, 163)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(24, 144, 144, 22, 22,
|
VERSIONS.push_back(Ref<Version>(new Version(24, 144, 144, 22, 22,
|
||||||
new ECBlocks(62, new ECB(8, 156), new ECB(2, 155)))));
|
new ECBlocks(62, new ECB(8, 156), new ECB(2, 155)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(25, 8, 18, 6, 16,
|
VERSIONS.push_back(Ref<Version>(new Version(25, 8, 18, 6, 16,
|
||||||
new ECBlocks(7, new ECB(1, 5)))));
|
new ECBlocks(7, new ECB(1, 5)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(26, 8, 32, 6, 14,
|
VERSIONS.push_back(Ref<Version>(new Version(26, 8, 32, 6, 14,
|
||||||
new ECBlocks(11, new ECB(1, 10)))));
|
new ECBlocks(11, new ECB(1, 10)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(27, 12, 26, 10, 24,
|
VERSIONS.push_back(Ref<Version>(new Version(27, 12, 26, 10, 24,
|
||||||
new ECBlocks(14, new ECB(1, 16)))));
|
new ECBlocks(14, new ECB(1, 16)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(28, 12, 36, 10, 16,
|
VERSIONS.push_back(Ref<Version>(new Version(28, 12, 36, 10, 16,
|
||||||
new ECBlocks(18, new ECB(1, 22)))));
|
new ECBlocks(18, new ECB(1, 22)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(29, 16, 36, 10, 16,
|
VERSIONS.push_back(Ref<Version>(new Version(29, 16, 36, 10, 16,
|
||||||
new ECBlocks(24, new ECB(1, 32)))));
|
new ECBlocks(24, new ECB(1, 32)))));
|
||||||
VERSIONS.push_back(Ref<Version>(new Version(30, 16, 48, 14, 22,
|
VERSIONS.push_back(Ref<Version>(new Version(30, 16, 48, 14, 22,
|
||||||
new ECBlocks(28, new ECB(1, 49)))));
|
new ECBlocks(28, new ECB(1, 49)))));
|
||||||
return VERSIONS.size();
|
return VERSIONS.size();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include <zxing/common/BitMatrix.h>
|
#include <zxing/common/BitMatrix.h>
|
||||||
#include <zxing/common/Counted.h>
|
#include <zxing/common/Counted.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <valarray>
|
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace datamatrix {
|
namespace datamatrix {
|
||||||
|
@ -54,11 +53,11 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class Version : public Counted {
|
class Version : public Counted {
|
||||||
private:
|
private:
|
||||||
int versionNumber_;
|
int versionNumber_;
|
||||||
int symbolSizeRows_;
|
int symbolSizeRows_;
|
||||||
int symbolSizeColumns_;
|
int symbolSizeColumns_;
|
||||||
int dataRegionSizeRows_;
|
int dataRegionSizeRows_;
|
||||||
int dataRegionSizeColumns_;
|
int dataRegionSizeColumns_;
|
||||||
ECBlocks* ecBlocks_;
|
ECBlocks* ecBlocks_;
|
||||||
int totalCodewords_;
|
int totalCodewords_;
|
||||||
|
@ -69,14 +68,14 @@ public:
|
||||||
static std::vector<Ref<Version> > VERSIONS;
|
static std::vector<Ref<Version> > VERSIONS;
|
||||||
|
|
||||||
~Version();
|
~Version();
|
||||||
int getVersionNumber();
|
int getVersionNumber();
|
||||||
int getSymbolSizeRows();
|
int getSymbolSizeRows();
|
||||||
int getSymbolSizeColumns();
|
int getSymbolSizeColumns();
|
||||||
int getDataRegionSizeRows();
|
int getDataRegionSizeRows();
|
||||||
int getDataRegionSizeColumns();
|
int getDataRegionSizeColumns();
|
||||||
int getTotalCodewords();
|
int getTotalCodewords();
|
||||||
ECBlocks* getECBlocks();
|
ECBlocks* getECBlocks();
|
||||||
static int buildVersions();
|
static int buildVersions();
|
||||||
Version* getVersionForDimensions(int numRows, int numColumns);
|
Version* getVersionForDimensions(int numRows, int numColumns);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <valarray>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <zxing/common/Counted.h>
|
#include <zxing/common/Counted.h>
|
||||||
#include <zxing/common/Array.h>
|
#include <zxing/common/Array.h>
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include <zxing/common/Array.h>
|
#include <zxing/common/Array.h>
|
||||||
#include <zxing/common/DecoderResult.h>
|
#include <zxing/common/DecoderResult.h>
|
||||||
#include <zxing/common/BitMatrix.h>
|
#include <zxing/common/BitMatrix.h>
|
||||||
#include <valarray>
|
|
||||||
|
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
|
@ -47,5 +46,5 @@ public:
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __DECODER_DM_H__
|
#endif // __DECODER_DM_H__
|
||||||
|
|
|
@ -19,13 +19,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <zxing/common/GridSampler.h>
|
#include <zxing/common/GridSampler.h>
|
||||||
#include <zxing/datamatrix/detector/Detector.h>
|
#include <zxing/datamatrix/detector/Detector.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstdlib>
|
||||||
namespace zxing {
|
|
||||||
namespace datamatrix {
|
namespace zxing {
|
||||||
|
namespace datamatrix {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
ResultPointsAndTransitions::ResultPointsAndTransitions() {
|
ResultPointsAndTransitions::ResultPointsAndTransitions() {
|
||||||
|
@ -52,13 +53,13 @@ Ref<CornerPoint> ResultPointsAndTransitions::getTo() {
|
||||||
int ResultPointsAndTransitions::getTransitions() {
|
int ResultPointsAndTransitions::getTransitions() {
|
||||||
return transitions_;
|
return transitions_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Detector::Detector(Ref<BitMatrix> image) : image_(image) { }
|
Detector::Detector(Ref<BitMatrix> image) : image_(image) { }
|
||||||
|
|
||||||
Ref<BitMatrix> Detector::getImage() {
|
Ref<BitMatrix> Detector::getImage() {
|
||||||
return image_;
|
return image_;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<DetectorResult> Detector::detect() {
|
Ref<DetectorResult> Detector::detect() {
|
||||||
Ref<MonochromeRectangleDetector> rectangleDetector_(new MonochromeRectangleDetector(image_));
|
Ref<MonochromeRectangleDetector> rectangleDetector_(new MonochromeRectangleDetector(image_));
|
||||||
std::vector<Ref<CornerPoint> > cornerPoints = rectangleDetector_->detect();
|
std::vector<Ref<CornerPoint> > cornerPoints = rectangleDetector_->detect();
|
||||||
|
@ -70,10 +71,10 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
// Point A and D are across the diagonal from one another,
|
// Point A and D are across the diagonal from one another,
|
||||||
// as are B and C. Figure out which are the solid black lines
|
// as are B and C. Figure out which are the solid black lines
|
||||||
// by counting transitions
|
// by counting transitions
|
||||||
std::vector<Ref<ResultPointsAndTransitions> > transitions(4);
|
std::vector<Ref<ResultPointsAndTransitions> > transitions(4);
|
||||||
transitions[0].reset(transitionsBetween(pointA, pointB));
|
transitions[0].reset(transitionsBetween(pointA, pointB));
|
||||||
transitions[1].reset(transitionsBetween(pointA, pointC));
|
transitions[1].reset(transitionsBetween(pointA, pointC));
|
||||||
transitions[2].reset(transitionsBetween(pointB, pointD));
|
transitions[2].reset(transitionsBetween(pointB, pointD));
|
||||||
transitions[3].reset(transitionsBetween(pointC, pointD));
|
transitions[3].reset(transitionsBetween(pointC, pointD));
|
||||||
insertionSort(transitions);
|
insertionSort(transitions);
|
||||||
|
|
||||||
|
@ -119,9 +120,9 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bottom left is correct but top left and bottom right might be switched
|
// Bottom left is correct but top left and bottom right might be switched
|
||||||
std::vector<Ref<CornerPoint> > corners(3);
|
std::vector<Ref<CornerPoint> > corners(3);
|
||||||
corners[0].reset(maybeTopLeft);
|
corners[0].reset(maybeTopLeft);
|
||||||
corners[1].reset(bottomLeft);
|
corners[1].reset(bottomLeft);
|
||||||
corners[2].reset(maybeBottomRight);
|
corners[2].reset(maybeBottomRight);
|
||||||
// Use the dot product trick to sort them out
|
// Use the dot product trick to sort them out
|
||||||
orderBestPatterns(corners);
|
orderBestPatterns(corners);
|
||||||
|
@ -162,8 +163,8 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
dimension++;
|
dimension++;
|
||||||
}
|
}
|
||||||
dimension += 2;
|
dimension += 2;
|
||||||
|
|
||||||
Ref<PerspectiveTransform> transform = createTransform(topLeft, topR, bottomLeft, bottomRight, dimension);
|
Ref<PerspectiveTransform> transform = createTransform(topLeft, topR, bottomLeft, bottomRight, dimension);
|
||||||
Ref<BitMatrix> bits(sampleGrid(image_, dimension, transform));
|
Ref<BitMatrix> bits(sampleGrid(image_, dimension, transform));
|
||||||
std::vector<Ref<ResultPoint> > points(4);
|
std::vector<Ref<ResultPoint> > points(4);
|
||||||
points[0].reset(pointA);
|
points[0].reset(pointA);
|
||||||
|
@ -171,8 +172,8 @@ Ref<DetectorResult> Detector::detect() {
|
||||||
points[2].reset(pointC);
|
points[2].reset(pointC);
|
||||||
points[3].reset(pointD);
|
points[3].reset(pointD);
|
||||||
Ref<DetectorResult> detectorResult(new DetectorResult(bits, points, transform));
|
Ref<DetectorResult> detectorResult(new DetectorResult(bits, points, transform));
|
||||||
return detectorResult;
|
return detectorResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> from, Ref<CornerPoint> to) {
|
Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> from, Ref<CornerPoint> to) {
|
||||||
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
|
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
|
||||||
|
@ -180,7 +181,7 @@ Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> fr
|
||||||
int fromY = (int) from->getY();
|
int fromY = (int) from->getY();
|
||||||
int toX = (int) to->getX();
|
int toX = (int) to->getX();
|
||||||
int toY = (int) to->getY();
|
int toY = (int) to->getY();
|
||||||
bool steep = abs(toY - fromY) > abs(toX - fromX);
|
bool steep = labs(toY - fromY) > labs(toX - fromX);
|
||||||
if (steep) {
|
if (steep) {
|
||||||
int temp = fromX;
|
int temp = fromX;
|
||||||
fromX = fromY;
|
fromX = fromY;
|
||||||
|
@ -190,8 +191,8 @@ Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> fr
|
||||||
toY = temp;
|
toY = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dx = abs(toX - fromX);
|
int dx = labs(toX - fromX);
|
||||||
int dy = abs(toY - fromY);
|
int dy = labs(toY - fromY);
|
||||||
int error = -dx >> 1;
|
int error = -dx >> 1;
|
||||||
int ystep = fromY < toY ? 1 : -1;
|
int ystep = fromY < toY ? 1 : -1;
|
||||||
int xstep = fromX < toX ? 1 : -1;
|
int xstep = fromX < toX ? 1 : -1;
|
||||||
|
@ -215,10 +216,10 @@ Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> fr
|
||||||
Ref<ResultPointsAndTransitions> result(new ResultPointsAndTransitions(from, to, transitions));
|
Ref<ResultPointsAndTransitions> result(new ResultPointsAndTransitions(from, to, transitions));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref <
|
Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref <
|
||||||
ResultPoint > bottomLeft, Ref<ResultPoint> bottomRight, int dimension) {
|
ResultPoint > bottomLeft, Ref<ResultPoint> bottomRight, int dimension) {
|
||||||
|
|
||||||
Ref<PerspectiveTransform> transform(PerspectiveTransform::quadrilateralToQuadrilateral(
|
Ref<PerspectiveTransform> transform(PerspectiveTransform::quadrilateralToQuadrilateral(
|
||||||
0.0f,
|
0.0f,
|
||||||
0.0f,
|
0.0f,
|
||||||
|
@ -235,13 +236,13 @@ Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Re
|
||||||
bottomRight->getX(),
|
bottomRight->getX(),
|
||||||
bottomRight->getY(),
|
bottomRight->getY(),
|
||||||
bottomLeft->getX(),
|
bottomLeft->getX(),
|
||||||
bottomLeft->getY()));
|
bottomLeft->getY()));
|
||||||
return transform;
|
return transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {
|
Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {
|
||||||
GridSampler &sampler = GridSampler::getInstance();
|
GridSampler &sampler = GridSampler::getInstance();
|
||||||
return sampler.sampleGrid(image, dimension, transform);
|
return sampler.sampleGrid(image, dimension, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Detector::insertionSort(std::vector<Ref<ResultPointsAndTransitions> > &vector) {
|
void Detector::insertionSort(std::vector<Ref<ResultPointsAndTransitions> > &vector) {
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
|
|
||||||
#include <zxing/qrcode/Version.h>
|
#include <zxing/qrcode/Version.h>
|
||||||
#include <zxing/qrcode/FormatInformation.h>
|
#include <zxing/qrcode/FormatInformation.h>
|
||||||
#include <cstdarg>
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cstdarg>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace qrcode {
|
namespace qrcode {
|
||||||
|
@ -78,7 +78,7 @@ int Version::getVersionNumber() {
|
||||||
return versionNumber_;
|
return versionNumber_;
|
||||||
}
|
}
|
||||||
|
|
||||||
valarray<int> &Version::getAlignmentPatternCenters() {
|
vector<int> &Version::getAlignmentPatternCenters() {
|
||||||
return alignmentPatternCenters_;
|
return alignmentPatternCenters_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ Version *Version::getVersionForNumber(int versionNumber) {
|
||||||
return VERSIONS[versionNumber - 1];
|
return VERSIONS[versionNumber - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
Version::Version(int versionNumber, valarray<int> *alignmentPatternCenters, ECBlocks *ecBlocks1, ECBlocks *ecBlocks2,
|
Version::Version(int versionNumber, vector<int> *alignmentPatternCenters, ECBlocks *ecBlocks1, ECBlocks *ecBlocks2,
|
||||||
ECBlocks *ecBlocks3, ECBlocks *ecBlocks4) :
|
ECBlocks *ecBlocks3, ECBlocks *ecBlocks4) :
|
||||||
versionNumber_(versionNumber), alignmentPatternCenters_(*alignmentPatternCenters), ecBlocks_(4) {
|
versionNumber_(versionNumber), alignmentPatternCenters_(*alignmentPatternCenters), ecBlocks_(4) {
|
||||||
ecBlocks_[0] = ecBlocks1;
|
ecBlocks_[0] = ecBlocks1;
|
||||||
|
@ -207,10 +207,10 @@ Ref<BitMatrix> Version::buildFunctionPattern() {
|
||||||
return functionPattern;
|
return functionPattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
static valarray<int> *intArray(size_t n...) {
|
static vector<int> *intArray(size_t n...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, n);
|
va_start(ap, n);
|
||||||
valarray<int> *result = new valarray<int>(n);
|
vector<int> *result = new vector<int>(n);
|
||||||
for (size_t i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
(*result)[i] = va_arg(ap, int);
|
(*result)[i] = va_arg(ap, int);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include <zxing/common/BitMatrix.h>
|
#include <zxing/common/BitMatrix.h>
|
||||||
#include <zxing/common/Counted.h>
|
#include <zxing/common/Counted.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <valarray>
|
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace qrcode {
|
namespace qrcode {
|
||||||
|
@ -58,10 +57,10 @@ class Version : public Counted {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int versionNumber_;
|
int versionNumber_;
|
||||||
std::valarray<int> &alignmentPatternCenters_;
|
std::vector<int> &alignmentPatternCenters_;
|
||||||
std::vector<ECBlocks*> ecBlocks_;
|
std::vector<ECBlocks*> ecBlocks_;
|
||||||
int totalCodewords_;
|
int totalCodewords_;
|
||||||
Version(int versionNumber, std::valarray<int> *alignmentPatternCenters, ECBlocks *ecBlocks1, ECBlocks *ecBlocks2,
|
Version(int versionNumber, std::vector<int> *alignmentPatternCenters, ECBlocks *ecBlocks1, ECBlocks *ecBlocks2,
|
||||||
ECBlocks *ecBlocks3, ECBlocks *ecBlocks4);
|
ECBlocks *ecBlocks3, ECBlocks *ecBlocks4);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -71,7 +70,7 @@ public:
|
||||||
|
|
||||||
~Version();
|
~Version();
|
||||||
int getVersionNumber();
|
int getVersionNumber();
|
||||||
std::valarray<int> &getAlignmentPatternCenters();
|
std::vector<int> &getAlignmentPatternCenters();
|
||||||
int getTotalCodewords();
|
int getTotalCodewords();
|
||||||
int getDimensionForVersion();
|
int getDimensionForVersion();
|
||||||
ECBlocks &getECBlocksForLevel(ErrorCorrectionLevel &ecLevel);
|
ECBlocks &getECBlocksForLevel(ErrorCorrectionLevel &ecLevel);
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <valarray>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <zxing/common/Counted.h>
|
#include <zxing/common/Counted.h>
|
||||||
#include <zxing/common/Array.h>
|
#include <zxing/common/Array.h>
|
||||||
|
|
|
@ -20,7 +20,9 @@
|
||||||
|
|
||||||
#include <zxing/qrcode/decoder/DecodedBitStreamParser.h>
|
#include <zxing/qrcode/decoder/DecodedBitStreamParser.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#ifndef NO_ICONV
|
||||||
#include <iconv.h>
|
#include <iconv.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// Required for compatibility. TODO: test on Symbian
|
// Required for compatibility. TODO: test on Symbian
|
||||||
#ifdef ZXING_ICONV_CONST
|
#ifdef ZXING_ICONV_CONST
|
||||||
|
@ -50,9 +52,10 @@ const char *DecodedBitStreamParser::UTF8 = "UTF-8";
|
||||||
const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
|
const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
|
||||||
const char *DecodedBitStreamParser::EUC_JP = "EUC-JP";
|
const char *DecodedBitStreamParser::EUC_JP = "EUC-JP";
|
||||||
|
|
||||||
void DecodedBitStreamParser::append(ostream &ost, const unsigned char *bufIn, size_t nIn, const char *src) {
|
string DecodedBitStreamParser::convert(const unsigned char *bufIn, size_t nIn, const char *src) {
|
||||||
|
#ifndef NO_ICONV
|
||||||
if (nIn == 0) {
|
if (nIn == 0) {
|
||||||
return;
|
return string();
|
||||||
}
|
}
|
||||||
|
|
||||||
iconv_t cd = iconv_open(UTF8, src);
|
iconv_t cd = iconv_open(UTF8, src);
|
||||||
|
@ -76,12 +79,15 @@ void DecodedBitStreamParser::append(ostream &ost, const unsigned char *bufIn, si
|
||||||
|
|
||||||
int nResult = maxOut - nTo;
|
int nResult = maxOut - nTo;
|
||||||
bufOut[nResult] = '\0';
|
bufOut[nResult] = '\0';
|
||||||
|
string result((const char *)bufOut);
|
||||||
ost << bufOut;
|
|
||||||
delete[] bufOut;
|
delete[] bufOut;
|
||||||
|
return result;
|
||||||
|
#else
|
||||||
|
return string((const char *)bufIn, nIn);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, ostringstream &result, int count) {
|
string DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, int count) {
|
||||||
// Each character will require 2 bytes. Read the characters as 2-byte pairs
|
// Each character will require 2 bytes. Read the characters as 2-byte pairs
|
||||||
// and decode as Shift_JIS afterwards
|
// and decode as Shift_JIS afterwards
|
||||||
size_t nBytes = 2 * count;
|
size_t nBytes = 2 * count;
|
||||||
|
@ -105,11 +111,12 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, ostringstre
|
||||||
count--;
|
count--;
|
||||||
}
|
}
|
||||||
|
|
||||||
append(result, buffer, nBytes, SHIFT_JIS);
|
string result = convert(buffer, nBytes, SHIFT_JIS);
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, ostringstream &result, int count) {
|
string DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, int count) {
|
||||||
int nBytes = count;
|
int nBytes = count;
|
||||||
unsigned char* readBytes = new unsigned char[nBytes];
|
unsigned char* readBytes = new unsigned char[nBytes];
|
||||||
if (count << 3 > bits->available()) {
|
if (count << 3 > bits->available()) {
|
||||||
|
@ -127,11 +134,12 @@ void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, ostringstrea
|
||||||
// Shift_JIS -- without anything like an ECI designator to
|
// Shift_JIS -- without anything like an ECI designator to
|
||||||
// give a hint.
|
// give a hint.
|
||||||
const char *encoding = guessEncoding(readBytes, nBytes);
|
const char *encoding = guessEncoding(readBytes, nBytes);
|
||||||
append(result, readBytes, nBytes, encoding);
|
string result = convert(readBytes, nBytes, encoding);
|
||||||
delete[] readBytes;
|
delete[] readBytes;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, ostringstream &result, int count) {
|
string DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, int count) {
|
||||||
int nBytes = count;
|
int nBytes = count;
|
||||||
unsigned char* bytes = new unsigned char[nBytes];
|
unsigned char* bytes = new unsigned char[nBytes];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -172,11 +180,12 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, ostringst
|
||||||
}
|
}
|
||||||
bytes[i++] = ALPHANUMERIC_CHARS[digitBits];
|
bytes[i++] = ALPHANUMERIC_CHARS[digitBits];
|
||||||
}
|
}
|
||||||
append(result, bytes, nBytes, ASCII);
|
string result = convert(bytes, nBytes, ASCII);
|
||||||
delete[] bytes;
|
delete[] bytes;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, ostringstream &result, int count) {
|
string DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, int count) {
|
||||||
int nBytes = count;
|
int nBytes = count;
|
||||||
unsigned char* bytes = new unsigned char[nBytes];
|
unsigned char* bytes = new unsigned char[nBytes];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -190,8 +199,9 @@ void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, ostr
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
bytes[i++] = ALPHANUMERIC_CHARS[bits->readBits(6)];
|
bytes[i++] = ALPHANUMERIC_CHARS[bits->readBits(6)];
|
||||||
}
|
}
|
||||||
append(result, bytes, nBytes, ASCII);
|
string result = convert(bytes, nBytes, ASCII);
|
||||||
delete[] bytes;
|
delete[] bytes;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -248,7 +258,7 @@ DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) {
|
||||||
}
|
}
|
||||||
|
|
||||||
string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *version) {
|
string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *version) {
|
||||||
ostringstream result;
|
string result;
|
||||||
Ref<BitSource> bits(new BitSource(bytes));
|
Ref<BitSource> bits(new BitSource(bytes));
|
||||||
Mode *mode = &Mode::TERMINATOR;
|
Mode *mode = &Mode::TERMINATOR;
|
||||||
do {
|
do {
|
||||||
|
@ -263,19 +273,19 @@ string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *ve
|
||||||
// How many characters will follow, encoded in this mode?
|
// How many characters will follow, encoded in this mode?
|
||||||
int count = bits->readBits(mode->getCharacterCountBits(version));
|
int count = bits->readBits(mode->getCharacterCountBits(version));
|
||||||
if (mode == &Mode::NUMERIC) {
|
if (mode == &Mode::NUMERIC) {
|
||||||
decodeNumericSegment(bits, result, count);
|
result = decodeNumericSegment(bits, count);
|
||||||
} else if (mode == &Mode::ALPHANUMERIC) {
|
} else if (mode == &Mode::ALPHANUMERIC) {
|
||||||
decodeAlphanumericSegment(bits, result, count);
|
result = decodeAlphanumericSegment(bits, count);
|
||||||
} else if (mode == &Mode::BYTE) {
|
} else if (mode == &Mode::BYTE) {
|
||||||
decodeByteSegment(bits, result, count);
|
result = decodeByteSegment(bits, count);
|
||||||
} else if (mode == &Mode::KANJI) {
|
} else if (mode == &Mode::KANJI) {
|
||||||
decodeKanjiSegment(bits, result, count);
|
result = decodeKanjiSegment(bits, count);
|
||||||
} else {
|
} else {
|
||||||
throw ReaderException("Unsupported mode indicator");
|
throw ReaderException("Unsupported mode indicator");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (mode != &Mode::TERMINATOR);
|
} while (mode != &Mode::TERMINATOR);
|
||||||
return result.str();
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,12 +43,12 @@ private:
|
||||||
static const char *SHIFT_JIS;
|
static const char *SHIFT_JIS;
|
||||||
static const char *EUC_JP;
|
static const char *EUC_JP;
|
||||||
|
|
||||||
static void decodeKanjiSegment(Ref<BitSource> bits, std::ostringstream &result, int count);
|
static std::string decodeKanjiSegment(Ref<BitSource> bits, int count);
|
||||||
static void decodeByteSegment(Ref<BitSource> bits, std::ostringstream &result, int count);
|
static std::string decodeByteSegment(Ref<BitSource> bits, int count);
|
||||||
static void decodeAlphanumericSegment(Ref<BitSource> bits, std::ostringstream &result, int count);
|
static std::string decodeAlphanumericSegment(Ref<BitSource> bits, int count);
|
||||||
static void decodeNumericSegment(Ref<BitSource> bits, std::ostringstream &result, int count);
|
static std::string decodeNumericSegment(Ref<BitSource> bits, int count);
|
||||||
static const char *guessEncoding(unsigned char *bytes, int length);
|
static const char *guessEncoding(unsigned char *bytes, int length);
|
||||||
static void append(std::ostream &ost, const unsigned char *bufIn, size_t nIn, const char *src);
|
static std::string convert(const unsigned char *bufIn, size_t nIn, const char *src);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static std::string decode(ArrayRef<unsigned char> bytes, Version *version);
|
static std::string decode(ArrayRef<unsigned char> bytes, Version *version);
|
||||||
|
|
|
@ -27,7 +27,6 @@
|
||||||
#include <zxing/common/Array.h>
|
#include <zxing/common/Array.h>
|
||||||
#include <zxing/common/DecoderResult.h>
|
#include <zxing/common/DecoderResult.h>
|
||||||
#include <zxing/common/BitMatrix.h>
|
#include <zxing/common/BitMatrix.h>
|
||||||
#include <valarray>
|
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace qrcode {
|
namespace qrcode {
|
||||||
|
|
|
@ -23,20 +23,21 @@
|
||||||
#include <zxing/common/BitArray.h>
|
#include <zxing/common/BitArray.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace qrcode {
|
namespace qrcode {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
float AlignmentPatternFinder::centerFromEnd(valarray<int> &stateCount, int end) {
|
float AlignmentPatternFinder::centerFromEnd(vector<int> &stateCount, int end) {
|
||||||
return (float)(end - stateCount[2]) - stateCount[1] / 2.0f;
|
return (float)(end - stateCount[2]) - stateCount[1] / 2.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AlignmentPatternFinder::foundPatternCross(valarray<int> &stateCount) {
|
bool AlignmentPatternFinder::foundPatternCross(vector<int> &stateCount) {
|
||||||
float maxVariance = moduleSize_ / 2.0f;
|
float maxVariance = moduleSize_ / 2.0f;
|
||||||
for (size_t i = 0; i < 3; i++) {
|
for (size_t i = 0; i < 3; i++) {
|
||||||
if (abs(moduleSize_ - stateCount[i]) >= maxVariance) {
|
if (labs(moduleSize_ - stateCount[i]) >= maxVariance) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,7 +47,7 @@ bool AlignmentPatternFinder::foundPatternCross(valarray<int> &stateCount) {
|
||||||
float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount,
|
float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount,
|
||||||
int originalStateCountTotal) {
|
int originalStateCountTotal) {
|
||||||
int maxI = image_->getHeight();
|
int maxI = image_->getHeight();
|
||||||
valarray<int> stateCount(0, 3);
|
vector<int> stateCount(3, 0);
|
||||||
|
|
||||||
|
|
||||||
// Start counting up from center
|
// Start counting up from center
|
||||||
|
@ -85,14 +86,14 @@ float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ,
|
||||||
}
|
}
|
||||||
|
|
||||||
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
|
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
|
||||||
if (5 * abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
|
if (5 * labs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : NAN;
|
return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<AlignmentPattern> AlignmentPatternFinder::handlePossibleCenter(valarray<int> &stateCount, size_t i, size_t j) {
|
Ref<AlignmentPattern> AlignmentPatternFinder::handlePossibleCenter(vector<int> &stateCount, size_t i, size_t j) {
|
||||||
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
|
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
|
||||||
float centerJ = centerFromEnd(stateCount, j);
|
float centerJ = centerFromEnd(stateCount, j);
|
||||||
float centerI = crossCheckVertical(i, (int)centerJ, 2 * stateCount[1], stateCountTotal);
|
float centerI = crossCheckVertical(i, (int)centerJ, 2 * stateCount[1], stateCountTotal);
|
||||||
|
@ -136,7 +137,7 @@ Ref<AlignmentPattern> AlignmentPatternFinder::find() {
|
||||||
// Ref<BitArray> luminanceRow(new BitArray(width_));
|
// Ref<BitArray> luminanceRow(new BitArray(width_));
|
||||||
// We are looking for black/white/black modules in 1:1:1 ratio;
|
// We are looking for black/white/black modules in 1:1:1 ratio;
|
||||||
// this tracks the number of black/white/black modules seen so far
|
// this tracks the number of black/white/black modules seen so far
|
||||||
valarray<int> stateCount(0, 3);
|
vector<int> stateCount(3, 0);
|
||||||
for (size_t iGen = 0; iGen < height_; iGen++) {
|
for (size_t iGen = 0; iGen < height_; iGen++) {
|
||||||
// Search from middle outwards
|
// Search from middle outwards
|
||||||
size_t i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1));
|
size_t i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1));
|
||||||
|
|
|
@ -43,12 +43,12 @@ private:
|
||||||
size_t height_;
|
size_t height_;
|
||||||
float moduleSize_;
|
float moduleSize_;
|
||||||
|
|
||||||
static float centerFromEnd(std::valarray<int> &stateCount, int end);
|
static float centerFromEnd(std::vector<int> &stateCount, int end);
|
||||||
bool foundPatternCross(std::valarray<int> &stateCount);
|
bool foundPatternCross(std::vector<int> &stateCount);
|
||||||
|
|
||||||
float crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal);
|
float crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal);
|
||||||
|
|
||||||
Ref<AlignmentPattern> handlePossibleCenter(std::valarray<int> &stateCount, size_t i, size_t j);
|
Ref<AlignmentPattern> handlePossibleCenter(std::vector<int> &stateCount, size_t i, size_t j);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width, size_t height,
|
AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width, size_t height,
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <zxing/common/GridSampler.h>
|
#include <zxing/common/GridSampler.h>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace qrcode {
|
namespace qrcode {
|
||||||
|
@ -133,8 +134,8 @@ Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<Per
|
||||||
|
|
||||||
int Detector::computeDimension(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft,
|
int Detector::computeDimension(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft,
|
||||||
float moduleSize) {
|
float moduleSize) {
|
||||||
int tltrCentersDimension = lround(FinderPatternFinder::distance(topLeft, topRight) / moduleSize);
|
int tltrCentersDimension = int(FinderPatternFinder::distance(topLeft, topRight) / moduleSize + 0.5f);
|
||||||
int tlblCentersDimension = lround(FinderPatternFinder::distance(topLeft, bottomLeft) / moduleSize);
|
int tlblCentersDimension = int(FinderPatternFinder::distance(topLeft, bottomLeft) / moduleSize + 0.5f);
|
||||||
int dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7;
|
int dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7;
|
||||||
switch (dimension & 0x03) { // mod 4
|
switch (dimension & 0x03) { // mod 4
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -200,7 +201,7 @@ float Detector::sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX,
|
||||||
float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) {
|
float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) {
|
||||||
// Mild variant of Bresenham's algorithm;
|
// Mild variant of Bresenham's algorithm;
|
||||||
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
|
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
|
||||||
bool steep = abs(toY - fromY) > abs(toX - fromX);
|
bool steep = labs(toY - fromY) > labs(toX - fromX);
|
||||||
if (steep) {
|
if (steep) {
|
||||||
int temp = fromX;
|
int temp = fromX;
|
||||||
fromX = fromY;
|
fromX = fromY;
|
||||||
|
@ -210,8 +211,8 @@ float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY)
|
||||||
toY = temp;
|
toY = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dx = abs(toX - fromX);
|
int dx = labs(toX - fromX);
|
||||||
int dy = abs(toY - fromY);
|
int dy = labs(toY - fromY);
|
||||||
int error = -dx >> 1;
|
int error = -dx >> 1;
|
||||||
int ystep = fromY < toY ? 1 : -1;
|
int ystep = fromY < toY ? 1 : -1;
|
||||||
int xstep = fromX < toX ? 1 : -1;
|
int xstep = fromX < toX ? 1 : -1;
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include <zxing/ReaderException.h>
|
#include <zxing/ReaderException.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace qrcode {
|
namespace qrcode {
|
||||||
|
@ -32,6 +34,8 @@ class ClosestToAverageComparator {
|
||||||
private:
|
private:
|
||||||
float averageModuleSize_;
|
float averageModuleSize_;
|
||||||
public:
|
public:
|
||||||
|
ClosestToAverageComparator() : averageModuleSize_(0.0f) { }
|
||||||
|
|
||||||
ClosestToAverageComparator(float averageModuleSize) :
|
ClosestToAverageComparator(float averageModuleSize) :
|
||||||
averageModuleSize_(averageModuleSize) {
|
averageModuleSize_(averageModuleSize) {
|
||||||
}
|
}
|
||||||
|
@ -136,7 +140,7 @@ float FinderPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int
|
||||||
// If we found a finder-pattern-like section, but its size is more than 40% different than
|
// If we found a finder-pattern-like section, but its size is more than 40% different than
|
||||||
// the original, assume it's a false positive
|
// the original, assume it's a false positive
|
||||||
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
|
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
|
||||||
if (5 * abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
|
if (5 * labs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +204,7 @@ float FinderPatternFinder::crossCheckHorizontal(size_t startJ, size_t centerI, i
|
||||||
// If we found a finder-pattern-like section, but its size is significantly different than
|
// If we found a finder-pattern-like section, but its size is significantly different than
|
||||||
// the original, assume it's a false positive
|
// the original, assume it's a false positive
|
||||||
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
|
int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4];
|
||||||
if (5 * abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) {
|
if (5 * labs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) {
|
||||||
return NAN;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +397,7 @@ Ref<FinderPatternInfo> FinderPatternFinder::find() {
|
||||||
// We are looking for black/white/black/white/black modules in
|
// We are looking for black/white/black/white/black modules in
|
||||||
// 1:1:3:1:1 ratio; this tracks the number of such modules seen so far
|
// 1:1:3:1:1 ratio; this tracks the number of such modules seen so far
|
||||||
|
|
||||||
// As this is used often, we use an integer array instead of valarray
|
// As this is used often, we use an integer array instead of vector
|
||||||
int stateCount[5];
|
int stateCount[5];
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
#include <zxing/qrcode/detector/QREdgeDetector.h>
|
#include <zxing/qrcode/detector/QREdgeDetector.h>
|
||||||
#include <zxing/common/EdgeDetector.h>
|
#include <zxing/common/EdgeDetector.h>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ Point QREdgeDetector::endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Poi
|
||||||
int toX = (int)to.x;
|
int toX = (int)to.x;
|
||||||
int toY = (int)to.y;
|
int toY = (int)to.y;
|
||||||
|
|
||||||
bool steep = abs(toY - fromY) > abs(toX - fromX);
|
bool steep = labs(toY - fromY) > labs(toX - fromX);
|
||||||
if (steep) {
|
if (steep) {
|
||||||
int temp = fromX;
|
int temp = fromX;
|
||||||
fromX = fromY;
|
fromX = fromY;
|
||||||
|
@ -123,8 +124,8 @@ Point QREdgeDetector::endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Poi
|
||||||
toY = temp;
|
toY = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
int dx = abs(toX - fromX);
|
int dx = labs(toX - fromX);
|
||||||
int dy = abs(toY - fromY);
|
int dy = labs(toY - fromY);
|
||||||
int error = -dx >> 1;
|
int error = -dx >> 1;
|
||||||
int ystep = fromY < toY ? -1 : 1;
|
int ystep = fromY < toY ? -1 : 1;
|
||||||
int xstep = fromX < toX ? -1 : 1;
|
int xstep = fromX < toX ? -1 : 1;
|
||||||
|
|
|
@ -65,7 +65,7 @@ void BitArrayTest::testGetArray() {
|
||||||
BitArray array(2*bits);
|
BitArray array(2*bits);
|
||||||
array.set(0);
|
array.set(0);
|
||||||
array.set(2*bits - 1);
|
array.set(2*bits - 1);
|
||||||
valarray<unsigned> words(array.getBitArray());
|
vector<unsigned> words(array.getBitArray());
|
||||||
CPPUNIT_ASSERT_EQUAL(1u, words[0]);
|
CPPUNIT_ASSERT_EQUAL(1u, words[0]);
|
||||||
CPPUNIT_ASSERT_EQUAL((1u << (bits - 1)), words[1]);
|
CPPUNIT_ASSERT_EQUAL((1u << (bits - 1)), words[1]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include "BlackPointEstimatorTest.h"
|
#include "BlackPointEstimatorTest.h"
|
||||||
#include <zxing/common/IllegalArgumentException.h>
|
#include <zxing/common/IllegalArgumentException.h>
|
||||||
#include <valarray>
|
#include <vector>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -28,7 +28,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BlackPointEstimatorTest);
|
||||||
|
|
||||||
void BlackPointEstimatorTest::testBasic() {
|
void BlackPointEstimatorTest::testBasic() {
|
||||||
int histogramRaw[] = { 0, 0, 11, 43, 37, 18, 3, 1, 0, 0, 13, 36, 24, 0, 11, 2 };
|
int histogramRaw[] = { 0, 0, 11, 43, 37, 18, 3, 1, 0, 0, 13, 36, 24, 0, 11, 2 };
|
||||||
valarray<int> histogram(histogramRaw, 16);
|
vector<int> histogram(histogramRaw, histogramRaw+16);
|
||||||
size_t point = GlobalHistogramBinarizer::estimate(histogram);
|
size_t point = GlobalHistogramBinarizer::estimate(histogram);
|
||||||
CPPUNIT_ASSERT_EQUAL((size_t)8, point);
|
CPPUNIT_ASSERT_EQUAL((size_t)8, point);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ void BlackPointEstimatorTest::testBasic() {
|
||||||
void BlackPointEstimatorTest::testTooLittleRange() {
|
void BlackPointEstimatorTest::testTooLittleRange() {
|
||||||
try {
|
try {
|
||||||
int histogramRaw[] = { 0, 0, 0, 0, 0, 0, 1, 43, 48, 18, 3, 1, 0, 0, 0, 0 };
|
int histogramRaw[] = { 0, 0, 0, 0, 0, 0, 1, 43, 48, 18, 3, 1, 0, 0, 0, 0 };
|
||||||
valarray<int> histogram(histogramRaw, 16);
|
vector<int> histogram(histogramRaw, histogramRaw+16);
|
||||||
GlobalHistogramBinarizer::estimate(histogram);
|
GlobalHistogramBinarizer::estimate(histogram);
|
||||||
CPPUNIT_FAIL("Should have thrown an exception");
|
CPPUNIT_FAIL("Should have thrown an exception");
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ void PerspectiveTransformTest::assertPointEquals(float expectedX,
|
||||||
float sourceX,
|
float sourceX,
|
||||||
float sourceY,
|
float sourceY,
|
||||||
Ref<PerspectiveTransform> pt) {
|
Ref<PerspectiveTransform> pt) {
|
||||||
valarray<float> points(2);
|
vector<float> points(2);
|
||||||
points[0] = sourceX;
|
points[0] = sourceX;
|
||||||
points[1] = sourceY;
|
points[1] = sourceY;
|
||||||
pt->transformPoints(points);
|
pt->transformPoints(points);
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <zxing/common/IllegalArgumentException.h>
|
#include <zxing/common/IllegalArgumentException.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
|
@ -82,7 +82,7 @@ void save_grid(Ref<BitMatrix> matrix, string filename, Ref<PerspectiveTransform>
|
||||||
image.strokeWidth(1);
|
image.strokeWidth(1);
|
||||||
|
|
||||||
for (int i = 0; i <= dimension; i++) {
|
for (int i = 0; i <= dimension; i++) {
|
||||||
valarray<float> tpoints(0.0, 4);
|
vector<float> tpoints(4);
|
||||||
|
|
||||||
tpoints[0] = 0;
|
tpoints[0] = 0;
|
||||||
tpoints[1] = i;
|
tpoints[1] = i;
|
||||||
|
|
Loading…
Reference in a new issue