Fixed things broken in the last commit.
authorralf.kistner@gmail.com <ralf.kistner@gmail.com@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 2 Apr 2010 17:17:31 +0000 (17:17 +0000)
committerralf.kistner@gmail.com <ralf.kistner@gmail.com@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 2 Apr 2010 17:17:31 +0000 (17:17 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1272 59b500cc-1b3d-0410-9834-0bbf25fbcc57

cpp/core/src/zxing/common/BitArray.cpp
cpp/core/src/zxing/common/BitArray.h
cpp/core/src/zxing/common/BitMatrix.cpp
cpp/core/src/zxing/datamatrix/detector/Detector.cpp
cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.cpp
cpp/core/src/zxing/qrcode/decoder/DecodedBitStreamParser.h
cpp/core/src/zxing/qrcode/detector/AlignmentPatternFinder.cpp
cpp/core/src/zxing/qrcode/detector/Detector.cpp
cpp/core/src/zxing/qrcode/detector/FinderPatternFinder.cpp
cpp/core/src/zxing/qrcode/detector/QREdgeDetector.cpp

index f6ecbdb..e4627c7 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <zxing/common/BitArray.h>
 #include <iostream>
 
 #include <zxing/common/BitArray.h>
 #include <iostream>
+#include <limits>
 
 using namespace std;
 
 
 using namespace std;
 
@@ -33,7 +34,7 @@ static unsigned int logDigits(unsigned digits) {
   }
   return log;
 }
   }
   return log;
 }
-const unsigned int BitArray::bitsPerWord_ = sizeof(unsigned int)*8;
+const unsigned int BitArray::bitsPerWord_ = numeric_limits<unsigned int>::digits;
 const unsigned int BitArray::logBits_ = logDigits(bitsPerWord_);
 const unsigned int BitArray::bitsMask_ = (1 << logBits_) - 1;
 size_t BitArray::wordsForBits(size_t bits) {
 const unsigned int BitArray::logBits_ = logDigits(bitsPerWord_);
 const unsigned int BitArray::bitsMask_ = (1 << logBits_) - 1;
 size_t BitArray::wordsForBits(size_t bits) {
index f91c068..d3b6f66 100644 (file)
@@ -24,7 +24,6 @@
 #include <zxing/common/Counted.h>
 #include <zxing/common/IllegalArgumentException.h>
 #include <vector>
 #include <zxing/common/Counted.h>
 #include <zxing/common/IllegalArgumentException.h>
 #include <vector>
-#include <limits>
 #include <iostream>
 
 namespace zxing {
 #include <iostream>
 
 namespace zxing {
index 1ed71b8..48a074d 100644 (file)
@@ -39,7 +39,7 @@ unsigned int logDigits(unsigned digits) {
 }
 
 
 }
 
 
-const unsigned int bitsPerWord = sizeof(unsigned int)*8;
+const unsigned int bitsPerWord = numeric_limits<unsigned int>::digits;
 const unsigned int logBits = logDigits(bitsPerWord);
 const unsigned int bitsMask = (1 << logBits) - 1;
 
 const unsigned int logBits = logDigits(bitsPerWord);
 const unsigned int bitsMask = (1 << logBits) - 1;
 
index 36a2e88..6c9aad5 100644 (file)
@@ -181,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();
     int fromY = (int) from->getY();
     int toX = (int) to->getX();
     int toY = (int) to->getY();
-    bool steep = labs(toY - fromY) > labs(toX - fromX);
+    bool steep = abs(toY - fromY) > abs(toX - fromX);
     if (steep) {
       int temp = fromX;
       fromX = fromY;
     if (steep) {
       int temp = fromX;
       fromX = fromY;
@@ -191,8 +191,8 @@ Ref<ResultPointsAndTransitions> Detector::transitionsBetween(Ref<CornerPoint> fr
       toY = temp;
     }
 
       toY = temp;
     }
 
-    int dx = labs(toX - fromX);
-    int dy = labs(toY - fromY);
+    int dx = abs(toX - fromX);
+    int dy = abs(toY - fromY);
     int error = -dx >> 1;
     int ystep = fromY < toY ? 1 : -1;
     int xstep = fromX < toX ? 1 : -1;
     int error = -dx >> 1;
     int ystep = fromY < toY ? 1 : -1;
     int xstep = fromX < toX ? 1 : -1;
index 2d0179a..65390ab 100644 (file)
@@ -52,10 +52,10 @@ const char *DecodedBitStreamParser::UTF8 = "UTF-8";
 const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
 const char *DecodedBitStreamParser::EUC_JP = "EUC-JP";
 
 const char *DecodedBitStreamParser::SHIFT_JIS = "SHIFT_JIS";
 const char *DecodedBitStreamParser::EUC_JP = "EUC-JP";
 
-string DecodedBitStreamParser::convert(const unsigned char *bufIn, size_t nIn, const char *src) {
+void DecodedBitStreamParser::append(std::string &result, const unsigned char *bufIn, size_t nIn, const char *src) {
 #ifndef NO_ICONV
   if (nIn == 0) {
 #ifndef NO_ICONV
   if (nIn == 0) {
-    return string();
+    return;
   }
 
   iconv_t cd = iconv_open(UTF8, src);
   }
 
   iconv_t cd = iconv_open(UTF8, src);
@@ -79,15 +79,14 @@ string DecodedBitStreamParser::convert(const unsigned char *bufIn, size_t nIn, c
 
   int nResult = maxOut - nTo;
   bufOut[nResult] = '\0';
 
   int nResult = maxOut - nTo;
   bufOut[nResult] = '\0';
-  string result((const char *)bufOut);
+  result.append((const char *)bufOut);
   delete[] bufOut;
   delete[] bufOut;
-  return result;
  #else
  #else
-  return string((const char *)bufIn, nIn);
+  result.append((const char *)bufIn, nIn);
  #endif
 }
 
  #endif
 }
 
-string DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, int count) {
+void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string &result, 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;
   // Each character will require 2 bytes. Read the characters as 2-byte pairs
   // and decode as Shift_JIS afterwards
   size_t nBytes = 2 * count;
@@ -111,12 +110,11 @@ string DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, int count
     count--;
   }
 
     count--;
   }
 
-  string result = convert(buffer, nBytes, SHIFT_JIS);
+  append(result, buffer, nBytes, SHIFT_JIS);
   delete[] buffer;
   delete[] buffer;
-  return result;
 }
 
 }
 
-string DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, int count) {
+void DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, std::string &result, int count) {
   int nBytes = count;
   unsigned char* readBytes = new unsigned char[nBytes];
   if (count << 3 > bits->available()) {
   int nBytes = count;
   unsigned char* readBytes = new unsigned char[nBytes];
   if (count << 3 > bits->available()) {
@@ -134,12 +132,11 @@ string DecodedBitStreamParser::decodeByteSegment(Ref<BitSource> bits, int count)
   // Shift_JIS -- without anything like an ECI designator to
   // give a hint.
   const char *encoding = guessEncoding(readBytes, nBytes);
   // Shift_JIS -- without anything like an ECI designator to
   // give a hint.
   const char *encoding = guessEncoding(readBytes, nBytes);
-  string result = convert(readBytes, nBytes, encoding);
+  append(result, readBytes, nBytes, encoding);
   delete[] readBytes;
   delete[] readBytes;
-  return result;
 }
 
 }
 
-string DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, int count) {
+void DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, std::string &result, int count) {
   int nBytes = count;
   unsigned char* bytes = new unsigned char[nBytes];
   int i = 0;
   int nBytes = count;
   unsigned char* bytes = new unsigned char[nBytes];
   int i = 0;
@@ -180,12 +177,11 @@ string DecodedBitStreamParser::decodeNumericSegment(Ref<BitSource> bits, int cou
     }
     bytes[i++] = ALPHANUMERIC_CHARS[digitBits];
   }
     }
     bytes[i++] = ALPHANUMERIC_CHARS[digitBits];
   }
-  string result = convert(bytes, nBytes, ASCII);
+  append(result, bytes, nBytes, ASCII);
   delete[] bytes;
   delete[] bytes;
-  return result;
 }
 
 }
 
-string DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, int count) {
+void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, std::string &result, int count) {
   int nBytes = count;
   unsigned char* bytes = new unsigned char[nBytes];
   int i = 0;
   int nBytes = count;
   unsigned char* bytes = new unsigned char[nBytes];
   int i = 0;
@@ -199,9 +195,8 @@ string DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits, in
   if (count == 1) {
     bytes[i++] = ALPHANUMERIC_CHARS[bits->readBits(6)];
   }
   if (count == 1) {
     bytes[i++] = ALPHANUMERIC_CHARS[bits->readBits(6)];
   }
-  string result = convert(bytes, nBytes, ASCII);
+  append(result, bytes, nBytes, ASCII);
   delete[] bytes;
   delete[] bytes;
-  return result;
 }
 
 const char *
 }
 
 const char *
@@ -273,13 +268,13 @@ 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) {
       // How many characters will follow, encoded in this mode?
       int count = bits->readBits(mode->getCharacterCountBits(version));
       if (mode == &Mode::NUMERIC) {
-        result = decodeNumericSegment(bits, count);
+        decodeNumericSegment(bits, result, count);
       } else if (mode == &Mode::ALPHANUMERIC) {
       } else if (mode == &Mode::ALPHANUMERIC) {
-        result = decodeAlphanumericSegment(bits, count);
+        decodeAlphanumericSegment(bits, result, count);
       } else if (mode == &Mode::BYTE) {
       } else if (mode == &Mode::BYTE) {
-        result = decodeByteSegment(bits, count);
+        decodeByteSegment(bits, result, count);
       } else if (mode == &Mode::KANJI) {
       } else if (mode == &Mode::KANJI) {
-        result = decodeKanjiSegment(bits, count);
+        decodeKanjiSegment(bits, result, count);
       } else {
         throw ReaderException("Unsupported mode indicator");
       }
       } else {
         throw ReaderException("Unsupported mode indicator");
       }
index 7b480e2..83582e1 100644 (file)
@@ -43,12 +43,12 @@ private:
   static const char *SHIFT_JIS;
   static const char *EUC_JP;
 
   static const char *SHIFT_JIS;
   static const char *EUC_JP;
 
-  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 void decodeKanjiSegment(Ref<BitSource> bits, std::string &result, int count);
+  static void decodeByteSegment(Ref<BitSource> bits, std::string &result, int count);
+  static void decodeAlphanumericSegment(Ref<BitSource> bits, std::string &result, int count);
+  static void decodeNumericSegment(Ref<BitSource> bits, std::string &result, int count);
   static const char *guessEncoding(unsigned char *bytes, int length);
   static const char *guessEncoding(unsigned char *bytes, int length);
-  static std::string convert(const unsigned char *bufIn, size_t nIn, const char *src);
+  static void append(std::string &ost, const unsigned char *bufIn, size_t nIn, const char *src);
 
 public:
   static std::string decode(ArrayRef<unsigned char> bytes, Version *version);
 
 public:
   static std::string decode(ArrayRef<unsigned char> bytes, Version *version);
index bc4aaac..017e2ee 100644 (file)
@@ -37,7 +37,7 @@ float AlignmentPatternFinder::centerFromEnd(vector<int> &stateCount, int end) {
 bool AlignmentPatternFinder::foundPatternCross(vector<int> &stateCount) {
   float maxVariance = moduleSize_ / 2.0f;
   for (size_t i = 0; i < 3; i++) {
 bool AlignmentPatternFinder::foundPatternCross(vector<int> &stateCount) {
   float maxVariance = moduleSize_ / 2.0f;
   for (size_t i = 0; i < 3; i++) {
-    if (labs(moduleSize_ - stateCount[i]) >= maxVariance) {
+    if (abs(moduleSize_ - stateCount[i]) >= maxVariance) {
       return false;
     }
   }
       return false;
     }
   }
@@ -86,7 +86,7 @@ float AlignmentPatternFinder::crossCheckVertical(size_t startI, size_t centerJ,
   }
 
   int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
   }
 
   int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2];
-  if (5 * labs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
+  if (5 * abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
     return NAN;
   }
 
     return NAN;
   }
 
index 9b46188..a50424c 100644 (file)
@@ -201,7 +201,7 @@ float Detector::sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX,
 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
 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 = labs(toY - fromY) > labs(toX - fromX);\r
+  bool steep = abs(toY - fromY) > abs(toX - fromX);\r
   if (steep) {\r
     int temp = fromX;\r
     fromX = fromY;\r
   if (steep) {\r
     int temp = fromX;\r
     fromX = fromY;\r
@@ -211,8 +211,8 @@ float Detector::sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY)
     toY = temp;\r
   }\r
 \r
     toY = temp;\r
   }\r
 \r
-  int dx = labs(toX - fromX);\r
-  int dy = labs(toY - fromY);\r
+  int dx = abs(toX - fromX);\r
+  int dy = abs(toY - fromY);\r
   int error = -dx >> 1;\r
   int ystep = fromY < toY ? 1 : -1;\r
   int xstep = fromX < toX ? 1 : -1;\r
   int error = -dx >> 1;\r
   int ystep = fromY < toY ? 1 : -1;\r
   int xstep = fromX < toX ? 1 : -1;\r
index 0dcbd3c..8b46b0f 100644 (file)
@@ -140,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 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 * labs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
+  if (5 * abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) {
     return NAN;
   }
 
     return NAN;
   }
 
@@ -204,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 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 * labs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) {
+  if (5 * abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) {
     return NAN;
   }
 
     return NAN;
   }
 
index 7566fb5..b2162ef 100644 (file)
@@ -114,7 +114,7 @@ Point QREdgeDetector::endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Poi
   int toX = (int)to.x;\r
   int toY = (int)to.y;\r
 \r
   int toX = (int)to.x;\r
   int toY = (int)to.y;\r
 \r
-  bool steep = labs(toY - fromY) > labs(toX - fromX);\r
+  bool steep = abs(toY - fromY) > abs(toX - fromX);\r
   if (steep) {\r
     int temp = fromX;\r
     fromX = fromY;\r
   if (steep) {\r
     int temp = fromX;\r
     fromX = fromY;\r
@@ -124,8 +124,8 @@ Point QREdgeDetector::endOfReverseBlackWhiteBlackRun(const BitMatrix& image, Poi
     toY = temp;\r
   }\r
 \r
     toY = temp;\r
   }\r
 \r
-  int dx = labs(toX - fromX);\r
-  int dy = labs(toY - fromY);\r
+  int dx = abs(toX - fromX);\r
+  int dy = abs(toY - fromY);\r
   int error = -dx >> 1;\r
   int ystep = fromY < toY ? -1 : 1;\r
   int xstep = fromX < toX ? -1 : 1;\r
   int error = -dx >> 1;\r
   int ystep = fromY < toY ? -1 : 1;\r
   int xstep = fromX < toX ? -1 : 1;\r