[SCM] Multi-format 1D/2D barcode image processing library branch, upstream, updated. 3b22568664b0c0017ea793fd3cf5fde433e95717

ralf.kistner at gmail.com ralf.kistner at gmail.com
Wed Jun 30 15:30:19 UTC 2010


The following commit has been merged in the upstream branch:
commit 269eca430e865769973f91653e23c0f1dec386a7
Author: ralf.kistner at gmail.com <ralf.kistner at gmail.com@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Date:   Fri Apr 2 14:11:53 2010 +0000

    C++ port made more compatible with uSTL (no functional changes).
    
    
    git-svn-id: http://zxing.googlecode.com/svn/trunk@1271 59b500cc-1b3d-0410-9834-0bbf25fbcc57

diff --git a/cpp/core/src/zxing/Reader.h b/cpp/core/src/zxing/Reader.h
index 3de270f..b4d96a4 100755
--- a/cpp/core/src/zxing/Reader.h
+++ b/cpp/core/src/zxing/Reader.h
@@ -21,7 +21,6 @@
  * limitations under the License.
  */
 
-#include <map>
 #include <zxing/BinaryBitmap.h>
 #include <zxing/Result.h>
 
diff --git a/cpp/core/src/zxing/common/Array.h b/cpp/core/src/zxing/common/Array.h
index 39b1786..9b82269 100644
--- a/cpp/core/src/zxing/common/Array.h
+++ b/cpp/core/src/zxing/common/Array.h
@@ -21,8 +21,7 @@
  * limitations under the License.
  */
 
-#include <valarray>
-#include <cstdarg>
+#include <vector>
 
 #ifdef DEBUG_COUNTING
 #include <iostream>
@@ -37,17 +36,17 @@ namespace zxing {
 template<typename T> class Array : public Counted {
 protected:
 public:
-  std::valarray<T> values_;
+  std::vector<T> values_;
   Array(size_t n) :
-      Counted(), values_(T(), n) {
+      Counted(), values_(n, T()) {
   }
   Array(T *ts, size_t n) :
-      Counted(), values_(ts, n) {
+      Counted(), values_(ts, ts+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) {
   }
   Array(Array<T> &other) :
@@ -68,7 +67,7 @@ public:
 #endif
     return *this;
   }
-  Array<T>& operator=(const std::valarray<T> &array) {
+  Array<T>& operator=(const std::vector<T> &array) {
 #ifdef DEBUG_COUNTING
     cout << "assigning values from Array " << &array << " to this Array " << this << ", ";
 #endif
@@ -87,10 +86,10 @@ public:
   size_t size() const {
     return values_.size();
   }
-  std::valarray<T> values() const {
+  std::vector<T> values() const {
     return values_;
   }
-  std::valarray<T>& values() {
+  std::vector<T>& values() {
     return values_;
   }
 };
diff --git a/cpp/core/src/zxing/common/BitArray.cpp b/cpp/core/src/zxing/common/BitArray.cpp
index 26e6869..f6ecbdb 100644
--- a/cpp/core/src/zxing/common/BitArray.cpp
+++ b/cpp/core/src/zxing/common/BitArray.cpp
@@ -33,7 +33,7 @@ static unsigned int logDigits(unsigned digits) {
   }
   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) {
@@ -48,7 +48,7 @@ BitArray::BitArray() {
 }
 
 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() {
 }
@@ -105,7 +105,7 @@ bool BitArray::isRange(size_t start, size_t end, bool value) {
   }
   return true;
 }
-valarray<unsigned int>& BitArray::getBitArray() {
+vector<unsigned int>& BitArray::getBitArray() {
   return bits_;
 }
 void BitArray::reverse() {
diff --git a/cpp/core/src/zxing/common/BitArray.h b/cpp/core/src/zxing/common/BitArray.h
index 1e8828e..f91c068 100644
--- a/cpp/core/src/zxing/common/BitArray.h
+++ b/cpp/core/src/zxing/common/BitArray.h
@@ -23,7 +23,7 @@
 
 #include <zxing/common/Counted.h>
 #include <zxing/common/IllegalArgumentException.h>
-#include <valarray>
+#include <vector>
 #include <limits>
 #include <iostream>
 
@@ -32,7 +32,7 @@ namespace zxing {
 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_;
@@ -48,7 +48,7 @@ public:
   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();
 };
 
diff --git a/cpp/core/src/zxing/common/BitMatrix.cpp b/cpp/core/src/zxing/common/BitMatrix.cpp
index 9256c40..1ed71b8 100644
--- a/cpp/core/src/zxing/common/BitMatrix.cpp
+++ b/cpp/core/src/zxing/common/BitMatrix.cpp
@@ -24,7 +24,6 @@
 #include <iostream>
 #include <sstream>
 #include <string>
-#include <cstring>
 
 namespace zxing {
 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 bitsMask = (1 << logBits) - 1;
 
@@ -90,7 +89,7 @@ void BitMatrix::flip(size_t x, size_t y) {
 }
 
 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) {
diff --git a/cpp/core/src/zxing/common/BitMatrix.h b/cpp/core/src/zxing/common/BitMatrix.h
index e8f8f84..a30e8ca 100644
--- a/cpp/core/src/zxing/common/BitMatrix.h
+++ b/cpp/core/src/zxing/common/BitMatrix.h
@@ -22,7 +22,6 @@
  */
 
 #include <zxing/common/Counted.h>
-#include <valarray>
 #include <limits>
 
 namespace zxing {
diff --git a/cpp/core/src/zxing/common/EdgeDetector.cpp b/cpp/core/src/zxing/common/EdgeDetector.cpp
index 3f0b403..70ac8c5 100644
--- a/cpp/core/src/zxing/common/EdgeDetector.cpp
+++ b/cpp/core/src/zxing/common/EdgeDetector.cpp
@@ -20,6 +20,7 @@
 
 #include <zxing/common/EdgeDetector.h>
 #include <algorithm>
+#include <cmath>
 
 using namespace std;
 
diff --git a/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp b/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp
index 8767dbd..61615d3 100644
--- a/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp
+++ b/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp
@@ -40,7 +40,7 @@ namespace zxing {
 	
 	
 	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) {
@@ -80,7 +80,7 @@ namespace zxing {
 		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
@@ -109,7 +109,7 @@ namespace zxing {
 		return matrix_ref;
 	}
 	
-	int GlobalHistogramBinarizer::estimate(valarray<int> &histogram) {
+	int GlobalHistogramBinarizer::estimate(vector<int> &histogram) {
 		int numBuckets = histogram.size();
 		int maxBucketCount = 0;
 		
diff --git a/cpp/core/src/zxing/common/GlobalHistogramBinarizer.h b/cpp/core/src/zxing/common/GlobalHistogramBinarizer.h
index 6735c5b..42956e9 100644
--- a/cpp/core/src/zxing/common/GlobalHistogramBinarizer.h
+++ b/cpp/core/src/zxing/common/GlobalHistogramBinarizer.h
@@ -22,7 +22,7 @@
 #ifndef GLOBALHISTOGRAMBINARIZER_H_
 #define GLOBALHISTOGRAMBINARIZER_H_
 
-#include <valarray>
+#include <vector>
 #include <zxing/Binarizer.h>
 #include <zxing/common/BitArray.h>
 #include <zxing/common/BitMatrix.h>
@@ -36,7 +36,7 @@ namespace zxing {
 		
 		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);
 	};
 	
 }
diff --git a/cpp/core/src/zxing/common/GridSampler.cpp b/cpp/core/src/zxing/common/GridSampler.cpp
index 06bb602..03a240e 100644
--- a/cpp/core/src/zxing/common/GridSampler.cpp
+++ b/cpp/core/src/zxing/common/GridSampler.cpp
@@ -34,7 +34,7 @@ GridSampler::GridSampler() {
 
 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;
@@ -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 height = image->getHeight();
 
diff --git a/cpp/core/src/zxing/common/GridSampler.h b/cpp/core/src/zxing/common/GridSampler.h
index 3dd577d..a7ad8b9 100644
--- a/cpp/core/src/zxing/common/GridSampler.h
+++ b/cpp/core/src/zxing/common/GridSampler.h
@@ -36,7 +36,7 @@ public:
   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();
 };
 }
diff --git a/cpp/core/src/zxing/common/PerspectiveTransform.cpp b/cpp/core/src/zxing/common/PerspectiveTransform.cpp
index 44d9ddc..0344a81 100644
--- a/cpp/core/src/zxing/common/PerspectiveTransform.cpp
+++ b/cpp/core/src/zxing/common/PerspectiveTransform.cpp
@@ -91,7 +91,7 @@ Ref<PerspectiveTransform> PerspectiveTransform::times(Ref<PerspectiveTransform>
   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;
diff --git a/cpp/core/src/zxing/common/PerspectiveTransform.h b/cpp/core/src/zxing/common/PerspectiveTransform.h
index 581f928..b95a8fb 100644
--- a/cpp/core/src/zxing/common/PerspectiveTransform.h
+++ b/cpp/core/src/zxing/common/PerspectiveTransform.h
@@ -22,7 +22,7 @@
  */
 
 #include <zxing/common/Counted.h>
-#include <valarray>
+#include <vector>
 
 namespace zxing {
 class PerspectiveTransform : public Counted {
@@ -41,7 +41,7 @@ public:
       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);
 };
diff --git a/cpp/core/src/zxing/common/Point.h b/cpp/core/src/zxing/common/Point.h
index a391042..ea27052 100644
--- a/cpp/core/src/zxing/common/Point.h
+++ b/cpp/core/src/zxing/common/Point.h
@@ -18,10 +18,10 @@
  * limitations under the License.
  */
 
-#ifndef ZXING_POINT_H_
-#define ZXING_POINT_H_
+#ifndef ZXING_POINT_H_
+#define ZXING_POINT_H_
 
-namespace zxing {
+namespace zxing {
 class PointI {
 public:
   int x;
@@ -30,6 +30,7 @@ public:
 
 class Point {
 public:
+  Point() : x(0.0f), y(0.0f) {};
   Point(float x_, float y_) : x(x_), y(y_) {};
 
   float x;
@@ -42,6 +43,6 @@ public:
 
   Point start;
   Point end;
-};
-}
-#endif // POINT_H_
+};
+}
+#endif // POINT_H_
diff --git a/cpp/core/src/zxing/common/reedsolomon/GF256.cpp b/cpp/core/src/zxing/common/reedsolomon/GF256.cpp
index 8add889..35fc692 100644
--- a/cpp/core/src/zxing/common/reedsolomon/GF256.cpp
+++ b/cpp/core/src/zxing/common/reedsolomon/GF256.cpp
@@ -18,7 +18,6 @@
  * limitations under the License.
  */
 
-#include <valarray>
 #include <vector>
 #include <iostream>
 #include <zxing/common/reedsolomon/GF256.h>
@@ -42,7 +41,7 @@ static inline Ref<GF256Poly> refPoly(GF256 &field, int value) {
 }
 
 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;
diff --git a/cpp/core/src/zxing/common/reedsolomon/GF256.h b/cpp/core/src/zxing/common/reedsolomon/GF256.h
index 0930f63..070a0fd 100644
--- a/cpp/core/src/zxing/common/reedsolomon/GF256.h
+++ b/cpp/core/src/zxing/common/reedsolomon/GF256.h
@@ -22,7 +22,7 @@
  */
 
 #include <memory>
-#include <valarray>
+#include <vector>
 #include <zxing/common/Counted.h>
 
 namespace zxing {
@@ -42,8 +42,8 @@ class GF256 {
    * @author christian.brunschen at 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_;
 
diff --git a/cpp/core/src/zxing/datamatrix/Version.cpp b/cpp/core/src/zxing/datamatrix/Version.cpp
index f1b25a4..267b334 100644
--- a/cpp/core/src/zxing/datamatrix/Version.cpp
+++ b/cpp/core/src/zxing/datamatrix/Version.cpp
@@ -19,7 +19,6 @@
  */
 
 #include <zxing/datamatrix/Version.h>
-#include <cstdarg>
 #include <limits>
 #include <iostream>
 
@@ -66,135 +65,135 @@ ECBlocks::~ECBlocks() {
 
 vector<Ref<Version> > Version::VERSIONS;
 static int N_VERSIONS = Version::buildVersions();
-
+
 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) {
-    // 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;
-}
+		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_;
 }
-
-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;
-      }
+
+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");
+    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() {
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
-  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)))));
   return VERSIONS.size();
 }
diff --git a/cpp/core/src/zxing/datamatrix/Version.h b/cpp/core/src/zxing/datamatrix/Version.h
index cdcec12..97e3a5a 100644
--- a/cpp/core/src/zxing/datamatrix/Version.h
+++ b/cpp/core/src/zxing/datamatrix/Version.h
@@ -25,7 +25,6 @@
 #include <zxing/common/BitMatrix.h>
 #include <zxing/common/Counted.h>
 #include <vector>
-#include <valarray>
 
 namespace zxing {
 namespace datamatrix {
@@ -54,11 +53,11 @@ public:
 };
 
 class Version : public Counted {
-private:
-  int versionNumber_;
-  int symbolSizeRows_;
-  int symbolSizeColumns_;
-  int dataRegionSizeRows_;
+private:
+  int versionNumber_;
+  int symbolSizeRows_;
+  int symbolSizeColumns_;
+  int dataRegionSizeRows_;
   int dataRegionSizeColumns_;
   ECBlocks* ecBlocks_;
   int totalCodewords_;
@@ -69,14 +68,14 @@ public:
   static std::vector<Ref<Version> > VERSIONS;
   
   ~Version();
-  int getVersionNumber();
-  int getSymbolSizeRows();
-  int getSymbolSizeColumns();  
-  int getDataRegionSizeRows();  
+  int getVersionNumber();
+  int getSymbolSizeRows();
+  int getSymbolSizeColumns();  
+  int getDataRegionSizeRows();  
   int getDataRegionSizeColumns();
   int getTotalCodewords();
   ECBlocks* getECBlocks();
-  static int  buildVersions();  
+  static int  buildVersions();  
   Version* getVersionForDimensions(int numRows, int numColumns);
 };
 }
diff --git a/cpp/core/src/zxing/datamatrix/decoder/DataBlock.h b/cpp/core/src/zxing/datamatrix/decoder/DataBlock.h
index 69c1210..7fc72f6 100644
--- a/cpp/core/src/zxing/datamatrix/decoder/DataBlock.h
+++ b/cpp/core/src/zxing/datamatrix/decoder/DataBlock.h
@@ -21,7 +21,6 @@
  * limitations under the License.
  */
 
-#include <valarray>
 #include <vector>
 #include <zxing/common/Counted.h>
 #include <zxing/common/Array.h>
diff --git a/cpp/core/src/zxing/datamatrix/decoder/Decoder.h b/cpp/core/src/zxing/datamatrix/decoder/Decoder.h
index b305dac..65fdf74 100644
--- a/cpp/core/src/zxing/datamatrix/decoder/Decoder.h
+++ b/cpp/core/src/zxing/datamatrix/decoder/Decoder.h
@@ -27,7 +27,6 @@
 #include <zxing/common/Array.h>
 #include <zxing/common/DecoderResult.h>
 #include <zxing/common/BitMatrix.h>
-#include <valarray>
 
 
 namespace zxing {
@@ -47,5 +46,5 @@ public:
 
 }
 }
-
+
 #endif // __DECODER_DM_H__
diff --git a/cpp/core/src/zxing/datamatrix/detector/Detector.cpp b/cpp/core/src/zxing/datamatrix/detector/Detector.cpp
index bb18f0a..36a2e88 100644
--- a/cpp/core/src/zxing/datamatrix/detector/Detector.cpp
+++ b/cpp/core/src/zxing/datamatrix/detector/Detector.cpp
@@ -19,13 +19,14 @@
  */
 
 #include <zxing/common/GridSampler.h>
-#include <zxing/datamatrix/detector/Detector.h>
-#include <cmath>
+#include <zxing/datamatrix/detector/Detector.h>
+#include <cmath>
 #include <sstream>
-
-namespace zxing {
-namespace datamatrix {
-
+#include <cstdlib>
+
+namespace zxing {
+namespace datamatrix {
+
 using namespace std;
 
 ResultPointsAndTransitions::ResultPointsAndTransitions() { 
@@ -52,13 +53,13 @@ Ref<CornerPoint> ResultPointsAndTransitions::getTo() {
 int ResultPointsAndTransitions::getTransitions() {
       return transitions_;
 }
-
-Detector::Detector(Ref<BitMatrix> image) : image_(image) { }
-
-Ref<BitMatrix> Detector::getImage() {
-   return image_;
-}
-
+
+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();
@@ -70,10 +71,10 @@ Ref<DetectorResult> Detector::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);
-  	transitions[0].reset(transitionsBetween(pointA, pointB));
-  	transitions[1].reset(transitionsBetween(pointA, pointC));
-  	transitions[2].reset(transitionsBetween(pointB, pointD));
+  	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);
 
@@ -119,9 +120,9 @@ Ref<DetectorResult> Detector::detect() {
 	} 
 
     // Bottom left is correct but top left and bottom right might be switched
-    std::vector<Ref<CornerPoint> > corners(3);
-  	corners[0].reset(maybeTopLeft);
-  	corners[1].reset(bottomLeft);
+    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);
@@ -162,8 +163,8 @@ Ref<DetectorResult> Detector::detect() {
       dimension++;
     }
     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));
   	std::vector<Ref<ResultPoint> > points(4);
 	  points[0].reset(pointA);
@@ -171,8 +172,8 @@ Ref<DetectorResult> Detector::detect() {
 	  points[2].reset(pointC);
 	  points[3].reset(pointD);
 	  Ref<DetectorResult> detectorResult(new DetectorResult(bits, points, transform));
-    return detectorResult;
-}
+    return detectorResult;
+}
 
 Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> from, Ref<CornerPoint> to) {
     // See QR Code Detector, sizeOfBlackWhiteBlackRun()
@@ -180,7 +181,7 @@ Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> fr
     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;
@@ -190,8 +191,8 @@ Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> fr
       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;
@@ -215,10 +216,10 @@ Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> fr
 	Ref<ResultPointsAndTransitions> result(new ResultPointsAndTransitions(from, to, transitions));
     return result;
   }
-
-Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Ref<ResultPoint> topRight, Ref <
-    ResultPoint > bottomLeft, Ref<ResultPoint> bottomRight, int dimension) {
-
+
+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,
@@ -235,13 +236,13 @@ Ref<PerspectiveTransform> Detector::createTransform(Ref<ResultPoint> topLeft, Re
         bottomRight->getX(),
         bottomRight->getY(),
         bottomLeft->getX(),
-        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);
+        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) {
diff --git a/cpp/core/src/zxing/qrcode/Version.cpp b/cpp/core/src/zxing/qrcode/Version.cpp
index 5e63c82..367cac1 100644
--- a/cpp/core/src/zxing/qrcode/Version.cpp
+++ b/cpp/core/src/zxing/qrcode/Version.cpp
@@ -20,9 +20,9 @@
 
 #include <zxing/qrcode/Version.h>
 #include <zxing/qrcode/FormatInformation.h>
-#include <cstdarg>
 #include <limits>
 #include <iostream>
+#include <cstdarg>
 
 namespace zxing {
 namespace qrcode {
@@ -78,7 +78,7 @@ int Version::getVersionNumber() {
   return versionNumber_;
 }
 
-valarray<int> &Version::getAlignmentPatternCenters() {
+vector<int> &Version::getAlignmentPatternCenters() {
   return alignmentPatternCenters_;
 }
 
@@ -109,7 +109,7 @@ Version *Version::getVersionForNumber(int versionNumber) {
   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;
@@ -207,10 +207,10 @@ Ref<BitMatrix> Version::buildFunctionPattern() {
   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);
   }
diff --git a/cpp/core/src/zxing/qrcode/Version.h b/cpp/core/src/zxing/qrcode/Version.h
index 181bd98..a89518d 100644
--- a/cpp/core/src/zxing/qrcode/Version.h
+++ b/cpp/core/src/zxing/qrcode/Version.h
@@ -27,7 +27,6 @@
 #include <zxing/common/BitMatrix.h>
 #include <zxing/common/Counted.h>
 #include <vector>
-#include <valarray>
 
 namespace zxing {
 namespace qrcode {
@@ -58,10 +57,10 @@ class Version : public Counted {
 
 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:
@@ -71,7 +70,7 @@ public:
 
   ~Version();
   int getVersionNumber();
-  std::valarray<int> &getAlignmentPatternCenters();
+  std::vector<int> &getAlignmentPatternCenters();
   int getTotalCodewords();
   int getDimensionForVersion();
   ECBlocks &getECBlocksForLevel(ErrorCorrectionLevel &ecLevel);
diff --git a/cpp/core/src/zxing/qrcode/decoder/DataBlock.h b/cpp/core/src/zxing/qrcode/decoder/DataBlock.h
index df536f4..fed669c 100644
--- a/cpp/core/src/zxing/qrcode/decoder/DataBlock.h
+++ b/cpp/core/src/zxing/qrcode/decoder/DataBlock.h
@@ -21,7 +21,6 @@
  * limitations under the License.
  */
 
-#include <valarray>
 #include <vector>
 #include <zxing/common/Counted.h>
 #include <zxing/common/Array.h>
diff --git a/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp b/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp
index e4766ed..2d0179a 100644
--- a/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp
+++ b/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp
@@ -20,7 +20,9 @@
 
 #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
@@ -50,9 +52,10 @@ const char *DecodedBitStreamParser::UTF8 = "UTF-8";
 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);
@@ -76,12 +79,15 @@ void DecodedBitStreamParser::append(ostream &ost, const unsigned char *bufIn, si
 
   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;
@@ -105,11 +111,12 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, ostringstre
     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()) {
@@ -127,11 +134,12 @@ void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, ostringstrea
   // 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;
@@ -172,11 +180,12 @@ void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, ostringst
     }
     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;
@@ -190,8 +199,9 @@ void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, ostr
   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 *
@@ -248,7 +258,7 @@ DecodedBitStreamParser::guessEncoding(unsigned char *bytes, int length) {
 }
 
 string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *version) {
-  ostringstream result;
+  string result;
   Ref<BitSource> bits(new BitSource(bytes));
   Mode *mode = &Mode::TERMINATOR;
   do {
@@ -263,19 +273,19 @@ string DecodedBitStreamParser::decode(ArrayRef<unsigned char> bytes, Version *ve
       // 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;
 }
 
 }
diff --git a/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.h b/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.h
index 8c4ab9b..7b480e2 100644
--- a/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.h
+++ b/cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.h
@@ -43,12 +43,12 @@ private:
   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);
diff --git a/cpp/core/src/zxing/qrcode/decoder/Decoder.h b/cpp/core/src/zxing/qrcode/decoder/Decoder.h
index 96e1dc0..14053a3 100644
--- a/cpp/core/src/zxing/qrcode/decoder/Decoder.h
+++ b/cpp/core/src/zxing/qrcode/decoder/Decoder.h
@@ -27,7 +27,6 @@
 #include <zxing/common/Array.h>
 #include <zxing/common/DecoderResult.h>
 #include <zxing/common/BitMatrix.h>
-#include <valarray>
 
 namespace zxing {
 namespace qrcode {
diff --git a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp
index b3d92d4..bc4aaac 100644
--- a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp
+++ b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp
@@ -23,20 +23,21 @@
 #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;
     }
   }
@@ -46,7 +47,7 @@ bool AlignmentPatternFinder::foundPatternCross(valarray<int> &stateCount) {
 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
@@ -85,14 +86,14 @@ float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ,
   }
 
   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);
@@ -136,7 +137,7 @@ Ref<AlignmentPattern> AlignmentPatternFinder::find() {
   //      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));
diff --git a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h
index 2663643..3b60d60 100644
--- a/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h
+++ b/cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.h
@@ -43,12 +43,12 @@ private:
   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,
diff --git a/cpp/core/src/zxing/qrcode/detector/Detector.cpp b/cpp/core/src/zxing/qrcode/detector/Detector.cpp
index 9dbc297..9b46188 100644
--- a/cpp/core/src/zxing/qrcode/detector/Detector.cpp
+++ b/cpp/core/src/zxing/qrcode/detector/Detector.cpp
@@ -27,6 +27,7 @@
 #include <zxing/common/GridSampler.h>
 #include <cmath>
 #include <sstream>
+#include <cstdlib>
 
 namespace zxing {
 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,
                                float moduleSize) {
-  int tltrCentersDimension = lround(FinderPatternFinder::distance(topLeft, topRight) / moduleSize);
-  int tlblCentersDimension = lround(FinderPatternFinder::distance(topLeft, bottomLeft) / moduleSize);
+  int tltrCentersDimension = int(FinderPatternFinder::distance(topLeft, topRight) / moduleSize + 0.5f);
+  int tlblCentersDimension = int(FinderPatternFinder::distance(topLeft, bottomLeft) / moduleSize + 0.5f);
   int dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7;
   switch (dimension & 0x03) { // mod 4
   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) {
   // Mild variant of Bresenham's 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) {
     int temp = fromX;
     fromX = fromY;
@@ -210,8 +211,8 @@ float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY)
     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;
diff --git a/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp b/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp
index 666c4f2..0dcbd3c 100644
--- a/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp
+++ b/cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp
@@ -22,6 +22,8 @@
 #include <zxing/ReaderException.h>
 #include <vector>
 #include <cmath>
+#include <cstdlib>
+#include <algorithm>
 
 namespace zxing {
 namespace qrcode {
@@ -32,6 +34,8 @@ class ClosestToAverageComparator {
 private:
   float averageModuleSize_;
 public:
+  ClosestToAverageComparator() : averageModuleSize_(0.0f) { }
+  
   ClosestToAverageComparator(float 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
   // 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;
   }
 
@@ -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
   // 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;
   }
 
@@ -393,7 +397,7 @@ Ref<FinderPatternInfo> FinderPatternFinder::find() {
   // 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;
 
diff --git a/cpp/core/src/zxing/qrcode/detector/QREdgeDetector.cpp b/cpp/core/src/zxing/qrcode/detector/QREdgeDetector.cpp
index 18affe6..7566fb5 100644
--- a/cpp/core/src/zxing/qrcode/detector/QREdgeDetector.cpp
+++ b/cpp/core/src/zxing/qrcode/detector/QREdgeDetector.cpp
@@ -20,6 +20,7 @@
 
 #include <zxing/qrcode/detector/QREdgeDetector.h>
 #include <zxing/common/EdgeDetector.h>
+#include <cstdlib>
 
 using namespace std;
 
@@ -113,7 +114,7 @@ Point QREdgeDetector::endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Poi
   int toX = (int)to.x;
   int toY = (int)to.y;
 
-  bool steep = abs(toY - fromY) > abs(toX - fromX);
+  bool steep = labs(toY - fromY) > labs(toX - fromX);
   if (steep) {
     int temp = fromX;
     fromX = fromY;
@@ -123,8 +124,8 @@ Point QREdgeDetector::endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Poi
     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;
diff --git a/cpp/core/tests/src/common/BitArrayTest.cpp b/cpp/core/tests/src/common/BitArrayTest.cpp
index 495bf67..fe2f158 100644
--- a/cpp/core/tests/src/common/BitArrayTest.cpp
+++ b/cpp/core/tests/src/common/BitArrayTest.cpp
@@ -65,7 +65,7 @@ void BitArrayTest::testGetArray() {
   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]);
 }
diff --git a/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp b/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp
index 23813c0..f79b28a 100644
--- a/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp
+++ b/cpp/core/tests/src/common/BlackPointEstimatorTest.cpp
@@ -20,7 +20,7 @@
 
 #include "BlackPointEstimatorTest.h"
 #include <zxing/common/IllegalArgumentException.h>
-#include <valarray>
+#include <vector>
 
 namespace zxing {
 using namespace std;
@@ -28,7 +28,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION(BlackPointEstimatorTest);
 
 void BlackPointEstimatorTest::testBasic() {
   int histogramRaw[] = { 0, 0, 11, 43, 37, 18, 3, 1, 0, 0, 13, 36, 24, 0, 11, 2 };
-  valarray<int> histogram(histogramRaw, 16);
+  vector<int> histogram(histogramRaw, histogramRaw+16);
   size_t point = GlobalHistogramBinarizer::estimate(histogram);
   CPPUNIT_ASSERT_EQUAL((size_t)8, point);
 }
@@ -36,7 +36,7 @@ void BlackPointEstimatorTest::testBasic() {
 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");
 
diff --git a/cpp/core/tests/src/common/PerspectiveTransformTest.cpp b/cpp/core/tests/src/common/PerspectiveTransformTest.cpp
index c36df19..fc306f1 100644
--- a/cpp/core/tests/src/common/PerspectiveTransformTest.cpp
+++ b/cpp/core/tests/src/common/PerspectiveTransformTest.cpp
@@ -57,7 +57,7 @@ void PerspectiveTransformTest::assertPointEquals(float expectedX,
     float sourceX,
     float sourceY,
     Ref<PerspectiveTransform> pt) {
-  valarray<float> points(2);
+  vector<float> points(2);
   points[0] = sourceX;
   points[1] = sourceY;
   pt->transformPoints(points);
diff --git a/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp b/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp
index e85a9f7..db6b1e5 100644
--- a/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp
+++ b/cpp/core/tests/src/common/reedsolomon/ReedSolomonTest.cpp
@@ -26,6 +26,7 @@
 #include <zxing/common/IllegalArgumentException.h>
 #include <vector>
 #include <cmath>
+#include <cstdlib>
 
 namespace zxing {
 using namespace std;
diff --git a/cpp/magick/src/main.cpp b/cpp/magick/src/main.cpp
index ce82e11..65be40c 100644
--- a/cpp/magick/src/main.cpp
+++ b/cpp/magick/src/main.cpp
@@ -82,7 +82,7 @@ void save_grid(Ref<BitMatrix> matrix, string filename, Ref<PerspectiveTransform>
   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;

-- 
Multi-format 1D/2D barcode image processing library



More information about the Pkg-google-commits mailing list