* limitations under the License.
*/
-#include <map>
#include <zxing/BinaryBitmap.h>
#include <zxing/Result.h>
* limitations under the License.\r
*/\r
\r
-#include <valarray>\r
-#include <cstdarg>\r
+#include <vector>\r
\r
#ifdef DEBUG_COUNTING\r
#include <iostream>\r
template<typename T> class Array : public Counted {\r
protected:\r
public:\r
- std::valarray<T> values_;\r
+ std::vector<T> values_;\r
Array(size_t n) :\r
- Counted(), values_(T(), n) {\r
+ Counted(), values_(n, T()) {\r
}\r
Array(T *ts, size_t n) :\r
- Counted(), values_(ts, n) {\r
+ Counted(), values_(ts, ts+n) {\r
}\r
Array(T v, size_t n) :\r
- Counted(), values_(v, n) {\r
+ Counted(), values_(n, v) {\r
}\r
- Array(std::valarray<T> &v) :\r
+ Array(std::vector<T> &v) :\r
Counted(), values_(v) {\r
}\r
Array(Array<T> &other) :\r
#endif\r
return *this;\r
}\r
- Array<T>& operator=(const std::valarray<T> &array) {\r
+ Array<T>& operator=(const std::vector<T> &array) {\r
#ifdef DEBUG_COUNTING\r
cout << "assigning values from Array " << &array << " to this Array " << this << ", ";\r
#endif\r
size_t size() const {\r
return values_.size();\r
}\r
- std::valarray<T> values() const {\r
+ std::vector<T> values() const {\r
return values_;\r
}\r
- std::valarray<T>& values() {\r
+ std::vector<T>& values() {\r
return values_;\r
}\r
};\r
}
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::bitsMask_ = (1 << logBits_) - 1;
size_t BitArray::wordsForBits(size_t bits) {
}
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() {
}
}
return true;
}
-valarray<unsigned int>& BitArray::getBitArray() {
+vector<unsigned int>& BitArray::getBitArray() {
return bits_;
}
void BitArray::reverse() {
#include <zxing/common/Counted.h>
#include <zxing/common/IllegalArgumentException.h>
-#include <valarray>
+#include <vector>
#include <limits>
#include <iostream>
class BitArray : public Counted {
private:
size_t size_;
- std::valarray<unsigned int> bits_;
+ std::vector<unsigned int> bits_;
static const unsigned int bitsPerWord_;
static const unsigned int logBits_;
static const unsigned int bitsMask_;
void setBulk(size_t i, unsigned int newBits);
void clear();
bool isRange(size_t start, size_t end, bool value);
- std::valarray<unsigned int>& getBitArray();
+ std::vector<unsigned int>& getBitArray();
void reverse();
};
#include <iostream>
#include <sstream>
#include <string>
-#include <cstring>
namespace zxing {
using namespace std;
}
-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 bitsMask = (1 << logBits) - 1;
}
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) {
*/
#include <zxing/common/Counted.h>
-#include <valarray>
#include <limits>
namespace zxing {
#include <zxing/common/EdgeDetector.h>
#include <algorithm>
+#include <cmath>
using namespace std;
Ref<BitArray> GlobalHistogramBinarizer::estimateBlackRow(int y, Ref<BitArray> row){
- valarray<int> histogram(0, LUMINANCE_BUCKETS);
+ vector<int> histogram(LUMINANCE_BUCKETS, 0);
LuminanceSource& source = *getSource();
int width = source.getWidth();
if (row == NULL || row->getSize() < width) {
LuminanceSource& source = *getSource();
int width = source.getWidth();
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
return matrix_ref;
}
- int GlobalHistogramBinarizer::estimate(valarray<int> &histogram) {
+ int GlobalHistogramBinarizer::estimate(vector<int> &histogram) {
int numBuckets = histogram.size();
int maxBucketCount = 0;
#ifndef GLOBALHISTOGRAMBINARIZER_H_
#define GLOBALHISTOGRAMBINARIZER_H_
-#include <valarray>
+#include <vector>
#include <zxing/Binarizer.h>
#include <zxing/common/BitArray.h>
#include <zxing/common/BitMatrix.h>
virtual Ref<BitArray> estimateBlackRow(int y, Ref<BitArray> row);
virtual Ref<BitMatrix> estimateBlackMatrix();
- static int estimate(std::valarray<int> &histogram);
+ static int estimate(std::vector<int> &histogram);
};
}
Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {
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++) {
int max = points.size();
float yValue = (float)y + 0.5f;
}
-void GridSampler::checkAndNudgePoints(Ref<BitMatrix> image, valarray<float> &points) {
+void GridSampler::checkAndNudgePoints(Ref<BitMatrix> image, vector<float> &points) {
int width = image->getWidth();
int height = image->getHeight();
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 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();
};
}
return result;
}
-void PerspectiveTransform::transformPoints(valarray<float> &points) {
+void PerspectiveTransform::transformPoints(vector<float> &points) {
int max = points.size();
float a11 = this->a11;
float a12 = this->a12;
*/
#include <zxing/common/Counted.h>
-#include <valarray>
+#include <vector>
namespace zxing {
class PerspectiveTransform : public Counted {
float x3, float y3);
Ref<PerspectiveTransform> buildAdjoint();
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);
};
* limitations under the License.
*/
-#ifndef ZXING_POINT_H_\r
-#define ZXING_POINT_H_\r
+#ifndef ZXING_POINT_H_
+#define ZXING_POINT_H_
-namespace zxing {\r
+namespace zxing {
class PointI {
public:
int x;
class Point {
public:
+ Point() : x(0.0f), y(0.0f) {};
Point(float x_, float y_) : x(x_), y(y_) {};
float x;
Point start;
Point end;
-};\r
-}\r
-#endif // POINT_H_\r
+};
+}
+#endif // POINT_H_
* limitations under the License.
*/
-#include <valarray>
#include <vector>
#include <iostream>
#include <zxing/common/reedsolomon/GF256.h>
}
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;
for (int i = 0; i < 256; i++) {
exp_[i] = x;
*/
#include <memory>
-#include <valarray>
+#include <vector>
#include <zxing/common/Counted.h>
namespace zxing {
* @author christian.brunschen@gmail.com (Christian Brunschen)
*/
private:
- std::valarray<int> exp_;
- std::valarray<int> log_;
+ std::vector<int> exp_;
+ std::vector<int> log_;
Ref<GF256Poly> zero_;
Ref<GF256Poly> one_;
*/
#include <zxing/datamatrix/Version.h>
-#include <cstdarg>
#include <limits>
#include <iostream>
vector<Ref<Version> > Version::VERSIONS;
static int N_VERSIONS = Version::buildVersions();
-\r
+
Version::Version(int versionNumber, int symbolSizeRows, int symbolSizeColumns, int dataRegionSizeRows,
int dataRegionSizeColumns, ECBlocks* ecBlocks) : versionNumber_(versionNumber),
symbolSizeRows_(symbolSizeRows), symbolSizeColumns_(symbolSizeColumns),
dataRegionSizeRows_(dataRegionSizeRows), dataRegionSizeColumns_(dataRegionSizeColumns),
- ecBlocks_(ecBlocks) {\r
- // Calculate the total number of codewords\r
- int total = 0;\r
- int ecCodewords = ecBlocks_->getECCodewords();\r
- vector<ECB*> &ecbArray = ecBlocks_->getECBlocks();\r
- for (unsigned int i = 0; i < ecbArray.size(); i++) {\r
- ECB *ecBlock = ecbArray[i];\r
- total += ecBlock->getCount() * (ecBlock->getDataCodewords() + ecCodewords);\r
- }\r
- totalCodewords_ = total;\r
-}\r
+ ecBlocks_(ecBlocks) {
+ // Calculate the total number of codewords
+ int total = 0;
+ int ecCodewords = ecBlocks_->getECCodewords();
+ vector<ECB*> &ecbArray = ecBlocks_->getECBlocks();
+ for (unsigned int i = 0; i < ecbArray.size(); i++) {
+ ECB *ecBlock = ecbArray[i];
+ total += ecBlock->getCount() * (ecBlock->getDataCodewords() + ecCodewords);
+ }
+ totalCodewords_ = total;
+}
Version::~Version() {
delete ecBlocks_;
}
-\r
-int Version::getVersionNumber() {\r
- return versionNumber_;\r
-}\r
-
-int Version::getSymbolSizeRows() {\r
- return symbolSizeRows_;\r
-}\r
- \r
-int Version::getSymbolSizeColumns() {\r
- return symbolSizeColumns_;\r
-}\r
-\r
-int Version::getDataRegionSizeRows() {\r
- return dataRegionSizeRows_;\r
-}\r
- \r
-int Version::getDataRegionSizeColumns() {\r
- return dataRegionSizeColumns_;\r
-}\r
- \r
-int Version::getTotalCodewords() {\r
- return totalCodewords_;\r
-}
-\r
-ECBlocks* Version::getECBlocks() {\r
- return ecBlocks_;\r
-}\r
- \r
-Version* Version::getVersionForDimensions(int numRows, int numColumns) {\r
- if ((numRows & 0x01) != 0 || (numColumns & 0x01) != 0) {\r
- throw ReaderException("Number of rows and columns must be even");\r
- }\r
- \r
- // TODO(bbrown): This is doing a linear search through the array of versions.\r
- // If we interleave the rectangular versions with the square versions we could\r
- // do a binary search.\r
- for (int i = 0; i < N_VERSIONS; ++i){\r
- Version* version = VERSIONS[i];\r
- if (version->getSymbolSizeRows() == numRows && version->getSymbolSizeColumns() == numColumns) {\r
- return version;\r
- }\r
+
+int Version::getVersionNumber() {
+ return versionNumber_;
+}
+
+int Version::getSymbolSizeRows() {
+ return symbolSizeRows_;
+}
+
+int Version::getSymbolSizeColumns() {
+ return symbolSizeColumns_;
+}
+
+int Version::getDataRegionSizeRows() {
+ return dataRegionSizeRows_;
+}
+
+int Version::getDataRegionSizeColumns() {
+ return dataRegionSizeColumns_;
+}
+
+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");
+ }
+
+ // 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");\r
+ throw ReaderException("Error version not found");
}
-/**\r
- * See ISO 16022:2006 5.5.1 Table 7\r
+/**
+ * See ISO 16022:2006 5.5.1 Table 7
*/
int Version::buildVersions() {
- VERSIONS.push_back(Ref<Version>(new Version(1, 10, 10, 8, 8,\r
+ VERSIONS.push_back(Ref<Version>(new Version(1, 10, 10, 8, 8,
new ECBlocks(5, new ECB(1, 3)))));
- VERSIONS.push_back(Ref<Version>(new Version(2, 12, 12, 10, 10,\r
+ VERSIONS.push_back(Ref<Version>(new Version(2, 12, 12, 10, 10,
new ECBlocks(7, new ECB(1, 5)))));
- VERSIONS.push_back(Ref<Version>(new Version(3, 14, 14, 12, 12,\r
+ VERSIONS.push_back(Ref<Version>(new Version(3, 14, 14, 12, 12,
new ECBlocks(10, new ECB(1, 8)))));
- VERSIONS.push_back(Ref<Version>(new Version(4, 16, 16, 14, 14,\r
+ VERSIONS.push_back(Ref<Version>(new Version(4, 16, 16, 14, 14,
new ECBlocks(12, new ECB(1, 12)))));
- VERSIONS.push_back(Ref<Version>(new Version(5, 18, 18, 16, 16,\r
+ VERSIONS.push_back(Ref<Version>(new Version(5, 18, 18, 16, 16,
new ECBlocks(14, new ECB(1, 18)))));
- VERSIONS.push_back(Ref<Version>(new Version(6, 20, 20, 18, 18,\r
+ VERSIONS.push_back(Ref<Version>(new Version(6, 20, 20, 18, 18,
new ECBlocks(18, new ECB(1, 22)))));
- VERSIONS.push_back(Ref<Version>(new Version(7, 22, 22, 20, 20,\r
+ VERSIONS.push_back(Ref<Version>(new Version(7, 22, 22, 20, 20,
new ECBlocks(20, new ECB(1, 30)))));
- VERSIONS.push_back(Ref<Version>(new Version(8, 24, 24, 22, 22,\r
+ VERSIONS.push_back(Ref<Version>(new Version(8, 24, 24, 22, 22,
new ECBlocks(24, new ECB(1, 36)))));
- VERSIONS.push_back(Ref<Version>(new Version(9, 26, 26, 24, 24,\r
+ VERSIONS.push_back(Ref<Version>(new Version(9, 26, 26, 24, 24,
new ECBlocks(28, new ECB(1, 44)))));
- VERSIONS.push_back(Ref<Version>(new Version(10, 32, 32, 14, 14,\r
+ VERSIONS.push_back(Ref<Version>(new Version(10, 32, 32, 14, 14,
new ECBlocks(36, new ECB(1, 62)))));
- VERSIONS.push_back(Ref<Version>(new Version(11, 36, 36, 16, 16,\r
+ VERSIONS.push_back(Ref<Version>(new Version(11, 36, 36, 16, 16,
new ECBlocks(42, new ECB(1, 86)))));
- VERSIONS.push_back(Ref<Version>(new Version(12, 40, 40, 18, 18,\r
+ VERSIONS.push_back(Ref<Version>(new Version(12, 40, 40, 18, 18,
new ECBlocks(48, new ECB(1, 114)))));
- VERSIONS.push_back(Ref<Version>(new Version(13, 44, 44, 20, 20,\r
+ VERSIONS.push_back(Ref<Version>(new Version(13, 44, 44, 20, 20,
new ECBlocks(56, new ECB(1, 144)))));
- VERSIONS.push_back(Ref<Version>(new Version(14, 48, 48, 22, 22,\r
+ VERSIONS.push_back(Ref<Version>(new Version(14, 48, 48, 22, 22,
new ECBlocks(68, new ECB(1, 174)))));
- VERSIONS.push_back(Ref<Version>(new Version(15, 52, 52, 24, 24,\r
+ VERSIONS.push_back(Ref<Version>(new Version(15, 52, 52, 24, 24,
new ECBlocks(42, new ECB(2, 102)))));
- VERSIONS.push_back(Ref<Version>(new Version(16, 64, 64, 14, 14,\r
+ VERSIONS.push_back(Ref<Version>(new Version(16, 64, 64, 14, 14,
new ECBlocks(56, new ECB(2, 140)))));
- VERSIONS.push_back(Ref<Version>(new Version(17, 72, 72, 16, 16,\r
+ VERSIONS.push_back(Ref<Version>(new Version(17, 72, 72, 16, 16,
new ECBlocks(36, new ECB(4, 92)))));
- VERSIONS.push_back(Ref<Version>(new Version(18, 80, 80, 18, 18,\r
+ VERSIONS.push_back(Ref<Version>(new Version(18, 80, 80, 18, 18,
new ECBlocks(48, new ECB(4, 114)))));
- VERSIONS.push_back(Ref<Version>(new Version(19, 88, 88, 20, 20,\r
+ VERSIONS.push_back(Ref<Version>(new Version(19, 88, 88, 20, 20,
new ECBlocks(56, new ECB(4, 144)))));
- VERSIONS.push_back(Ref<Version>(new Version(20, 96, 96, 22, 22,\r
+ VERSIONS.push_back(Ref<Version>(new Version(20, 96, 96, 22, 22,
new ECBlocks(68, new ECB(4, 174)))));
- VERSIONS.push_back(Ref<Version>(new Version(21, 104, 104, 24, 24,\r
+ VERSIONS.push_back(Ref<Version>(new Version(21, 104, 104, 24, 24,
new ECBlocks(56, new ECB(6, 136)))));
- VERSIONS.push_back(Ref<Version>(new Version(22, 120, 120, 18, 18,\r
+ VERSIONS.push_back(Ref<Version>(new Version(22, 120, 120, 18, 18,
new ECBlocks(68, new ECB(6, 175)))));
- VERSIONS.push_back(Ref<Version>(new Version(23, 132, 132, 20, 20,\r
+ VERSIONS.push_back(Ref<Version>(new Version(23, 132, 132, 20, 20,
new ECBlocks(62, new ECB(8, 163)))));
- VERSIONS.push_back(Ref<Version>(new Version(24, 144, 144, 22, 22,\r
+ VERSIONS.push_back(Ref<Version>(new Version(24, 144, 144, 22, 22,
new ECBlocks(62, new ECB(8, 156), new ECB(2, 155)))));
- VERSIONS.push_back(Ref<Version>(new Version(25, 8, 18, 6, 16,\r
+ VERSIONS.push_back(Ref<Version>(new Version(25, 8, 18, 6, 16,
new ECBlocks(7, new ECB(1, 5)))));
- VERSIONS.push_back(Ref<Version>(new Version(26, 8, 32, 6, 14,\r
+ VERSIONS.push_back(Ref<Version>(new Version(26, 8, 32, 6, 14,
new ECBlocks(11, new ECB(1, 10)))));
- VERSIONS.push_back(Ref<Version>(new Version(27, 12, 26, 10, 24,\r
+ VERSIONS.push_back(Ref<Version>(new Version(27, 12, 26, 10, 24,
new ECBlocks(14, new ECB(1, 16)))));
- VERSIONS.push_back(Ref<Version>(new Version(28, 12, 36, 10, 16,\r
+ VERSIONS.push_back(Ref<Version>(new Version(28, 12, 36, 10, 16,
new ECBlocks(18, new ECB(1, 22)))));
- VERSIONS.push_back(Ref<Version>(new Version(29, 16, 36, 10, 16,\r
+ VERSIONS.push_back(Ref<Version>(new Version(29, 16, 36, 10, 16,
new ECBlocks(24, new ECB(1, 32)))));
- VERSIONS.push_back(Ref<Version>(new Version(30, 16, 48, 14, 22,\r
+ VERSIONS.push_back(Ref<Version>(new Version(30, 16, 48, 14, 22,
new ECBlocks(28, new ECB(1, 49)))));
return VERSIONS.size();
}
#include <zxing/common/BitMatrix.h>
#include <zxing/common/Counted.h>
#include <vector>
-#include <valarray>
namespace zxing {
namespace datamatrix {
};
class Version : public Counted {
-private:\r
- int versionNumber_;\r
- int symbolSizeRows_;\r
- int symbolSizeColumns_;\r
- int dataRegionSizeRows_;\r
+private:
+ int versionNumber_;
+ int symbolSizeRows_;
+ int symbolSizeColumns_;
+ int dataRegionSizeRows_;
int dataRegionSizeColumns_;
ECBlocks* ecBlocks_;
int totalCodewords_;
static std::vector<Ref<Version> > VERSIONS;
~Version();
- int getVersionNumber();\r
- int getSymbolSizeRows();\r
- int getSymbolSizeColumns(); \r
- int getDataRegionSizeRows(); \r
+ int getVersionNumber();
+ int getSymbolSizeRows();
+ int getSymbolSizeColumns();
+ int getDataRegionSizeRows();
int getDataRegionSizeColumns();
int getTotalCodewords();
ECBlocks* getECBlocks();
- static int buildVersions(); \r
+ static int buildVersions();
Version* getVersionForDimensions(int numRows, int numColumns);
};
}
* limitations under the License.
*/
-#include <valarray>
#include <vector>
#include <zxing/common/Counted.h>
#include <zxing/common/Array.h>
#include <zxing/common/Array.h>
#include <zxing/common/DecoderResult.h>
#include <zxing/common/BitMatrix.h>
-#include <valarray>
namespace zxing {
}
}
-\r
+
#endif // __DECODER_DM_H__
*/
#include <zxing/common/GridSampler.h>
-#include <zxing/datamatrix/detector/Detector.h>\r
-#include <cmath>\r
+#include <zxing/datamatrix/detector/Detector.h>
+#include <cmath>
#include <sstream>
-\r
-namespace zxing {\r
-namespace datamatrix {\r
-\r
+#include <cstdlib>
+
+namespace zxing {
+namespace datamatrix {
+
using namespace std;
ResultPointsAndTransitions::ResultPointsAndTransitions() {
int ResultPointsAndTransitions::getTransitions() {
return transitions_;
}
-\r
-Detector::Detector(Ref<BitMatrix> image) : image_(image) { }\r
-\r
-Ref<BitMatrix> Detector::getImage() {\r
- return image_;\r
-}\r
-\r
+
+Detector::Detector(Ref<BitMatrix> image) : image_(image) { }
+
+Ref<BitMatrix> Detector::getImage() {
+ return image_;
+}
+
Ref<DetectorResult> Detector::detect() {
Ref<MonochromeRectangleDetector> rectangleDetector_(new MonochromeRectangleDetector(image_));
std::vector<Ref<CornerPoint> > cornerPoints = rectangleDetector_->detect();
// Point A and D are across the diagonal from one another,
// as are B and C. Figure out which are the solid black lines
// by counting transitions
- std::vector<Ref<ResultPointsAndTransitions> > transitions(4);\r
- transitions[0].reset(transitionsBetween(pointA, pointB));\r
- transitions[1].reset(transitionsBetween(pointA, pointC));\r
- transitions[2].reset(transitionsBetween(pointB, pointD));\r
+ std::vector<Ref<ResultPointsAndTransitions> > transitions(4);
+ transitions[0].reset(transitionsBetween(pointA, pointB));
+ transitions[1].reset(transitionsBetween(pointA, pointC));
+ transitions[2].reset(transitionsBetween(pointB, pointD));
transitions[3].reset(transitionsBetween(pointC, pointD));
insertionSort(transitions);
}
// Bottom left is correct but top left and bottom right might be switched
- std::vector<Ref<CornerPoint> > corners(3);\r
- corners[0].reset(maybeTopLeft);\r
- corners[1].reset(bottomLeft);\r
+ std::vector<Ref<CornerPoint> > corners(3);
+ corners[0].reset(maybeTopLeft);
+ corners[1].reset(bottomLeft);
corners[2].reset(maybeBottomRight);
// Use the dot product trick to sort them out
orderBestPatterns(corners);
dimension++;
}
dimension += 2;
-\r
- Ref<PerspectiveTransform> transform = createTransform(topLeft, topR, bottomLeft, bottomRight, dimension);\r
+
+ Ref<PerspectiveTransform> transform = createTransform(topLeft, topR, bottomLeft, bottomRight, dimension);
Ref<BitMatrix> bits(sampleGrid(image_, dimension, transform));
std::vector<Ref<ResultPoint> > points(4);
points[0].reset(pointA);
points[2].reset(pointC);
points[3].reset(pointD);
Ref<DetectorResult> detectorResult(new DetectorResult(bits, points, transform));
- return detectorResult;\r
-}\r
+ return detectorResult;
+}
Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> from, Ref<CornerPoint> to) {
// See QR Code Detector, sizeOfBlackWhiteBlackRun()
int fromY = (int) from->getY();
int toX = (int) to->getX();
int toY = (int) to->getY();
- bool steep = abs(toY - fromY) > abs(toX - fromX);
+ bool steep = labs(toY - fromY) > labs(toX - fromX);
if (steep) {
int temp = fromX;
fromX = fromY;
toY = temp;
}
- int dx = abs(toX - fromX);
- int dy = abs(toY - fromY);
+ int dx = labs(toX - fromX);
+ int dy = labs(toY - fromY);
int error = -dx >> 1;
int ystep = fromY < toY ? 1 : -1;
int xstep = fromX < toX ? 1 : -1;
Ref<ResultPointsAndTransitions> result(new ResultPointsAndTransitions(from, to, transitions));
return result;
}
-\r
-Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref <\r
- ResultPoint > bottomLeft, Ref<ResultPoint> bottomRight, int dimension) {\r
-\r
+
+Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref <
+ ResultPoint > bottomLeft, Ref<ResultPoint> bottomRight, int dimension) {
+
Ref<PerspectiveTransform> transform(PerspectiveTransform::quadrilateralToQuadrilateral(
0.0f,
0.0f,
bottomRight->getX(),
bottomRight->getY(),
bottomLeft->getX(),
- bottomLeft->getY()));\r
- return transform;\r
-}\r
-\r
-Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {\r
- GridSampler &sampler = GridSampler::getInstance();\r
- return sampler.sampleGrid(image, dimension, transform);\r
+ bottomLeft->getY()));
+ return transform;
+}
+
+Ref<BitMatrix> Detector::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {
+ GridSampler &sampler = GridSampler::getInstance();
+ return sampler.sampleGrid(image, dimension, transform);
}
void Detector::insertionSort(std::vector<Ref<ResultPointsAndTransitions> > &vector) {
#include <zxing/qrcode/Version.h>
#include <zxing/qrcode/FormatInformation.h>
-#include <cstdarg>
#include <limits>
#include <iostream>
+#include <cstdarg>
namespace zxing {
namespace qrcode {
return versionNumber_;
}
-valarray<int> &Version::getAlignmentPatternCenters() {
+vector<int> &Version::getAlignmentPatternCenters() {
return alignmentPatternCenters_;
}
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) :
versionNumber_(versionNumber), alignmentPatternCenters_(*alignmentPatternCenters), ecBlocks_(4) {
ecBlocks_[0] = ecBlocks1;
return functionPattern;
}
-static valarray<int> *intArray(size_t n...) {
+static vector<int> *intArray(size_t n...) {
va_list ap;
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++) {
(*result)[i] = va_arg(ap, int);
}
#include <zxing/common/BitMatrix.h>
#include <zxing/common/Counted.h>
#include <vector>
-#include <valarray>
namespace zxing {
namespace qrcode {
private:
int versionNumber_;
- std::valarray<int> &alignmentPatternCenters_;
+ std::vector<int> &alignmentPatternCenters_;
std::vector<ECBlocks*> ecBlocks_;
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);
public:
~Version();
int getVersionNumber();
- std::valarray<int> &getAlignmentPatternCenters();
+ std::vector<int> &getAlignmentPatternCenters();
int getTotalCodewords();
int getDimensionForVersion();
ECBlocks &getECBlocksForLevel(ErrorCorrectionLevel &ecLevel);
* limitations under the License.
*/
-#include <valarray>
#include <vector>
#include <zxing/common/Counted.h>
#include <zxing/common/Array.h>
#include <zxing/qrcode/decoder/DecodedBitStreamParser.h>
#include <iostream>
+#ifndef NO_ICONV
#include <iconv.h>
+#endif
// Required for compatibility. TODO: test on Symbian
#ifdef ZXING_ICONV_CONST
const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
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) {
- return;
+ return string();
}
iconv_t cd = iconv_open(UTF8, src);
int nResult = maxOut - nTo;
bufOut[nResult] = '\0';
-
- ost << bufOut;
+ string result((const char *)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
// and decode as Shift_JIS afterwards
size_t nBytes = 2 * count;
count--;
}
- append(result, buffer, nBytes, SHIFT_JIS);
+ string result = convert(buffer, nBytes, SHIFT_JIS);
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;
unsigned char* readBytes = new unsigned char[nBytes];
if (count << 3 > bits->available()) {
// Shift_JIS -- without anything like an ECI designator to
// give a hint.
const char *encoding = guessEncoding(readBytes, nBytes);
- append(result, readBytes, nBytes, encoding);
+ string result = convert(readBytes, nBytes, encoding);
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;
unsigned char* bytes = new unsigned char[nBytes];
int i = 0;
}
bytes[i++] = ALPHANUMERIC_CHARS[digitBits];
}
- append(result, bytes, nBytes, ASCII);
+ string result = convert(bytes, nBytes, ASCII);
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;
unsigned char* bytes = new unsigned char[nBytes];
int i = 0;
if (count == 1) {
bytes[i++] = ALPHANUMERIC_CHARS[bits->readBits(6)];
}
- append(result, bytes, nBytes, ASCII);
+ string result = convert(bytes, nBytes, ASCII);
delete[] bytes;
+ return result;
}
const char *
}
string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *version) {
- ostringstream result;
+ string result;
Ref<BitSource> bits(new BitSource(bytes));
Mode *mode = &Mode::TERMINATOR;
do {
// How many characters will follow, encoded in this mode?
int count = bits->readBits(mode->getCharacterCountBits(version));
if (mode == &Mode::NUMERIC) {
- decodeNumericSegment(bits, result, count);
+ result = decodeNumericSegment(bits, count);
} else if (mode == &Mode::ALPHANUMERIC) {
- decodeAlphanumericSegment(bits, result, count);
+ result = decodeAlphanumericSegment(bits, count);
} else if (mode == &Mode::BYTE) {
- decodeByteSegment(bits, result, count);
+ result = decodeByteSegment(bits, count);
} else if (mode == &Mode::KANJI) {
- decodeKanjiSegment(bits, result, count);
+ result = decodeKanjiSegment(bits, count);
} else {
throw ReaderException("Unsupported mode indicator");
}
}
} while (mode != &Mode::TERMINATOR);
- return result.str();
+ return result;
}
}
static const char *SHIFT_JIS;
static const char *EUC_JP;
- static void decodeKanjiSegment(Ref<BitSource> bits, std::ostringstream &result, int count);
- static void decodeByteSegment(Ref<BitSource> bits, std::ostringstream &result, int count);
- static void decodeAlphanumericSegment(Ref<BitSource> bits, std::ostringstream &result, int count);
- static void decodeNumericSegment(Ref<BitSource> bits, std::ostringstream &result, int count);
+ static std::string decodeKanjiSegment(Ref<BitSource> bits, int count);
+ static std::string decodeByteSegment(Ref<BitSource> bits, int count);
+ static std::string decodeAlphanumericSegment(Ref<BitSource> bits, int count);
+ static std::string decodeNumericSegment(Ref<BitSource> bits, int count);
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:
static std::string decode(ArrayRef<unsigned char> bytes, Version *version);
#include <zxing/common/Array.h>
#include <zxing/common/DecoderResult.h>
#include <zxing/common/BitMatrix.h>
-#include <valarray>
namespace zxing {
namespace qrcode {
#include <zxing/common/BitArray.h>
#include <vector>
#include <cmath>
+#include <cstdlib>
namespace zxing {
namespace qrcode {
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;
}
-bool AlignmentPatternFinder::foundPatternCross(valarray<int> &stateCount) {
+bool AlignmentPatternFinder::foundPatternCross(vector<int> &stateCount) {
float maxVariance = moduleSize_ / 2.0f;
for (size_t i = 0; i < 3; i++) {
- if (abs(moduleSize_ - stateCount[i]) >= maxVariance) {
+ if (labs(moduleSize_ - stateCount[i]) >= maxVariance) {
return false;
}
}
float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ, int maxCount,
int originalStateCountTotal) {
int maxI = image_->getHeight();
- valarray<int> stateCount(0, 3);
+ vector<int> stateCount(3, 0);
// Start counting up from center
}
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 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];
float centerJ = centerFromEnd(stateCount, j);
float centerI = crossCheckVertical(i, (int)centerJ, 2 * stateCount[1], stateCountTotal);
// Ref<BitArray> luminanceRow(new BitArray(width_));
// 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
- valarray<int> stateCount(0, 3);
+ vector<int> stateCount(3, 0);
for (size_t iGen = 0; iGen < height_; iGen++) {
// Search from middle outwards
size_t i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1));
size_t height_;
float moduleSize_;
- static float centerFromEnd(std::valarray<int> &stateCount, int end);
- bool foundPatternCross(std::valarray<int> &stateCount);
+ static float centerFromEnd(std::vector<int> &stateCount, int end);
+ bool foundPatternCross(std::vector<int> &stateCount);
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:
AlignmentPatternFinder(Ref<BitMatrix> image, size_t startX, size_t startY, size_t width, size_t height,
#include <zxing/common/GridSampler.h>\r
#include <cmath>\r
#include <sstream>\r
+#include <cstdlib>\r
\r
namespace zxing {\r
namespace qrcode {\r
\r
int Detector::computeDimension(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref<ResultPoint> bottomLeft,\r
float moduleSize) {\r
- int tltrCentersDimension = lround(FinderPatternFinder::distance(topLeft, topRight) / moduleSize);\r
- int tlblCentersDimension = lround(FinderPatternFinder::distance(topLeft, bottomLeft) / moduleSize);\r
+ int tltrCentersDimension = int(FinderPatternFinder::distance(topLeft, topRight) / moduleSize + 0.5f);\r
+ int tlblCentersDimension = int(FinderPatternFinder::distance(topLeft, bottomLeft) / moduleSize + 0.5f);\r
int dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7;\r
switch (dimension & 0x03) { // mod 4\r
case 0:\r
float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) {\r
// Mild variant of Bresenham's algorithm;\r
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm\r
- bool steep = abs(toY - fromY) > abs(toX - fromX);\r
+ bool steep = labs(toY - fromY) > labs(toX - fromX);\r
if (steep) {\r
int temp = fromX;\r
fromX = fromY;\r
toY = temp;\r
}\r
\r
- int dx = abs(toX - fromX);\r
- int dy = abs(toY - fromY);\r
+ int dx = labs(toX - fromX);\r
+ int dy = labs(toY - fromY);\r
int error = -dx >> 1;\r
int ystep = fromY < toY ? 1 : -1;\r
int xstep = fromX < toX ? 1 : -1;\r
#include <zxing/ReaderException.h>
#include <vector>
#include <cmath>
+#include <cstdlib>
+#include <algorithm>
namespace zxing {
namespace qrcode {
private:
float averageModuleSize_;
public:
+ ClosestToAverageComparator() : averageModuleSize_(0.0f) { }
+
ClosestToAverageComparator(float averageModuleSize) :
averageModuleSize_(averageModuleSize) {
}
// 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
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;
}
// If we found a finder-pattern-like section, but its size is significantly different than
// the original, assume it's a false positive
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;
}
// 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
- // 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];
bool done = false;
\r
#include <zxing/qrcode/detector/QREdgeDetector.h>\r
#include <zxing/common/EdgeDetector.h>\r
+#include <cstdlib>\r
\r
using namespace std;\r
\r
int toX = (int)to.x;\r
int toY = (int)to.y;\r
\r
- bool steep = abs(toY - fromY) > abs(toX - fromX);\r
+ bool steep = labs(toY - fromY) > labs(toX - fromX);\r
if (steep) {\r
int temp = fromX;\r
fromX = fromY;\r
toY = temp;\r
}\r
\r
- int dx = abs(toX - fromX);\r
- int dy = abs(toY - fromY);\r
+ int dx = labs(toX - fromX);\r
+ int dy = labs(toY - fromY);\r
int error = -dx >> 1;\r
int ystep = fromY < toY ? -1 : 1;\r
int xstep = fromX < toX ? -1 : 1;\r
BitArray array(2*bits);
array.set(0);
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 << (bits - 1)), words[1]);
}
#include "BlackPointEstimatorTest.h"
#include <zxing/common/IllegalArgumentException.h>
-#include <valarray>
+#include <vector>
namespace zxing {
using namespace std;
void BlackPointEstimatorTest::testBasic() {
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);
CPPUNIT_ASSERT_EQUAL((size_t)8, point);
}
void BlackPointEstimatorTest::testTooLittleRange() {
try {
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);
CPPUNIT_FAIL("Should have thrown an exception");
float sourceX,
float sourceY,
Ref<PerspectiveTransform> pt) {
- valarray<float> points(2);
+ vector<float> points(2);
points[0] = sourceX;
points[1] = sourceY;
pt->transformPoints(points);
#include <zxing/common/IllegalArgumentException.h>
#include <vector>
#include <cmath>
+#include <cstdlib>
namespace zxing {
using namespace std;
image.strokeWidth(1);
for (int i = 0; i <= dimension; i++) {
- valarray<float> tpoints(0.0, 4);
+ vector<float> tpoints(4);
tpoints[0] = 0;
tpoints[1] = i;