diff --git a/cpp/core/src/zxing/Binarizer.cpp b/cpp/core/src/zxing/Binarizer.cpp index b1d8b642d..86d891558 100644 --- a/cpp/core/src/zxing/Binarizer.cpp +++ b/cpp/core/src/zxing/Binarizer.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Binarizer.cpp * zxing @@ -24,7 +25,7 @@ namespace zxing { Binarizer::Binarizer(Ref source) : source_(source) { - } + } Binarizer::~Binarizer() { } diff --git a/cpp/core/src/zxing/Result.cpp b/cpp/core/src/zxing/Result.cpp index 6ea658272..db705bcfc 100644 --- a/cpp/core/src/zxing/Result.cpp +++ b/cpp/core/src/zxing/Result.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Result.cpp * zxing @@ -25,7 +26,7 @@ using namespace std; Result::Result(Ref text, ArrayRef rawBytes, std::vector > resultPoints, BarcodeFormat format) : - text_(text), rawBytes_(rawBytes), resultPoints_(resultPoints), format_(format) { + text_(text), rawBytes_(rawBytes), resultPoints_(resultPoints), format_(format) { } Result::~Result() { diff --git a/cpp/core/src/zxing/common/BitArray.cpp b/cpp/core/src/zxing/common/BitArray.cpp index ee3d1726d..7229f70b8 100644 --- a/cpp/core/src/zxing/common/BitArray.cpp +++ b/cpp/core/src/zxing/common/BitArray.cpp @@ -73,7 +73,7 @@ void BitArray::setBulk(size_t i, unsigned int newBits) { void BitArray::setRange(int start, int end) { if (end < start) { - throw new IllegalArgumentException("invalid call to BitArray::setRange"); + throw IllegalArgumentException("invalid call to BitArray::setRange"); } if (end == start) { return; diff --git a/cpp/core/src/zxing/common/DetectorResult.cpp b/cpp/core/src/zxing/common/DetectorResult.cpp index a314cfe79..0769137de 100644 --- a/cpp/core/src/zxing/common/DetectorResult.cpp +++ b/cpp/core/src/zxing/common/DetectorResult.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * DetectorResult.cpp * zxing @@ -23,7 +24,7 @@ namespace zxing { DetectorResult::DetectorResult(Ref bits, std::vector > points, Ref transform) : - bits_(bits), points_(points), transform_(transform) { + bits_(bits), points_(points), transform_(transform) { } Ref DetectorResult::getBits() { diff --git a/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp b/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp index 5d5451d1d..e0ce81ed0 100644 --- a/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp +++ b/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * GlobalHistogramBinarizer.cpp * zxing diff --git a/cpp/core/src/zxing/common/HybridBinarizer.cpp b/cpp/core/src/zxing/common/HybridBinarizer.cpp index 91e9e0547..0bab00a50 100644 --- a/cpp/core/src/zxing/common/HybridBinarizer.cpp +++ b/cpp/core/src/zxing/common/HybridBinarizer.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * HybridBinarizer.cpp * zxing @@ -31,7 +32,7 @@ static const int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS; static const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS; HybridBinarizer::HybridBinarizer(Ref source) : - GlobalHistogramBinarizer(source), cached_matrix_(NULL), cached_row_(NULL), cached_row_num_(-1) { + GlobalHistogramBinarizer(source), matrix_(NULL), cached_row_(NULL), cached_row_num_(-1) { } @@ -39,40 +40,43 @@ HybridBinarizer::~HybridBinarizer() { } -Ref HybridBinarizer::getBlackMatrix() { - binarizeEntireImage(); - return cached_matrix_; -} - Ref HybridBinarizer::createBinarizer(Ref source) { return Ref (new HybridBinarizer(source)); } -void HybridBinarizer::binarizeEntireImage() { - if (cached_matrix_ == NULL) { - Ref source = getLuminanceSource(); - if (source->getWidth() >= MINIMUM_DIMENSION && source->getHeight() >= MINIMUM_DIMENSION) { - unsigned char* luminances = source->getMatrix(); - int width = source->getWidth(); - int height = source->getHeight(); - int subWidth = width >> 3; - if (width & 0x07) { - subWidth++; - } - int subHeight = height >> 3; - if (height & 0x07) { - subHeight++; - } - int *blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); - cached_matrix_.reset(new BitMatrix(width,height)); - calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, cached_matrix_); - delete [] blackPoints; - delete [] luminances; - } else { - // If the image is too small, fall back to the global histogram approach. - cached_matrix_.reset(GlobalHistogramBinarizer::getBlackMatrix()); - } +Ref HybridBinarizer::getBlackMatrix() { + // Calculates the final BitMatrix once for all requests. This could be called once from the + // constructor instead, but there are some advantages to doing it lazily, such as making + // profiling easier, and not doing heavy lifting when callers don't expect it. + if (matrix_) { + return matrix_; } + LuminanceSource& source = *getLuminanceSource(); + if (source.getWidth() >= MINIMUM_DIMENSION && source.getHeight() >= MINIMUM_DIMENSION) { + unsigned char* luminances = source.getMatrix(); + int width = source.getWidth(); + int height = source.getHeight(); + int subWidth = width >> 3; + if ((width & 0x07) != 0) { + subWidth++; + } + int subHeight = height >> 3; + if ((height & 0x07) != 0) { + subHeight++; + } + int* blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); + + Ref newMatrix (new BitMatrix(width, height)); + calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix); + matrix_ = newMatrix; + + delete [] blackPoints; + delete [] luminances; + } else { + // If the image is too small, fall back to the global histogram approach. + matrix_ = GlobalHistogramBinarizer::getBlackMatrix(); + } + return matrix_; } void HybridBinarizer::calculateThresholdForBlock(unsigned char* luminances, int subWidth, int subHeight, diff --git a/cpp/core/src/zxing/common/HybridBinarizer.h b/cpp/core/src/zxing/common/HybridBinarizer.h index 2d7653d6e..6c18f46dc 100644 --- a/cpp/core/src/zxing/common/HybridBinarizer.h +++ b/cpp/core/src/zxing/common/HybridBinarizer.h @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- #ifndef __HYBRIDBINARIZER_H__ #define __HYBRIDBINARIZER_H__ /* @@ -29,7 +30,7 @@ namespace zxing { class HybridBinarizer : public GlobalHistogramBinarizer { private: - Ref cached_matrix_; + Ref matrix_; Ref cached_row_; int cached_row_num_; @@ -40,7 +41,6 @@ namespace zxing { virtual Ref getBlackMatrix(); Ref createBinarizer(Ref source); private: - void binarizeEntireImage(); // We'll be using one-D arrays because C++ can't dynamically allocate 2D arrays int* calculateBlackPoints(unsigned char* luminances, int subWidth, int subHeight, int width, int height); diff --git a/cpp/core/src/zxing/datamatrix/detector/Detector.cpp b/cpp/core/src/zxing/datamatrix/detector/Detector.cpp index 54b1a1165..b46100964 100644 --- a/cpp/core/src/zxing/datamatrix/detector/Detector.cpp +++ b/cpp/core/src/zxing/datamatrix/detector/Detector.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * Detector.cpp * zxing diff --git a/cpp/core/src/zxing/datamatrix/detector/Detector.h b/cpp/core/src/zxing/datamatrix/detector/Detector.h index 96f58f502..4258d5c86 100644 --- a/cpp/core/src/zxing/datamatrix/detector/Detector.h +++ b/cpp/core/src/zxing/datamatrix/detector/Detector.h @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- #ifndef __DETECTOR_H__ #define __DETECTOR_H__ @@ -21,17 +22,17 @@ * limitations under the License. */ - -#include -#include -#include -#include + +#include +#include +#include +#include #include - - -namespace zxing { + + +namespace zxing { namespace datamatrix { - + class ResultPointsAndTransitions : public Counted { private: Ref to_; @@ -45,11 +46,11 @@ public: Ref getTo(); int getTransitions(); }; - -class Detector : public Counted { -private: - Ref image_; - + +class Detector : public Counted { +private: + Ref image_; + protected: Ref sampleGrid(Ref image, int dimension, Ref transform); @@ -57,14 +58,14 @@ protected: Ref transitionsBetween(Ref from, Ref to); int min(int a, int b) { return a > b ? b : a; }; - -public: - Ref getImage(); + +public: + Ref getImage(); Detector(Ref image); - - virtual Ref createTransform(Ref topLeft, Ref topRight, Ref < + + virtual Ref createTransform(Ref topLeft, Ref topRight, Ref < ResultPoint > bottomLeft, Ref bottomRight, int dimension); - + Ref detect(); void orderBestPatterns(std::vector > &patterns); float distance(float x1, float x2, float y1, float y2); @@ -72,8 +73,8 @@ private: int compare(Ref a, Ref b); float crossProductZ(Ref pointA, Ref pointB, Ref pointC); }; - -} -} - + +} +} + #endif // __DETECTOR_H__ diff --git a/cpp/core/src/zxing/oned/OneDReader.cpp b/cpp/core/src/zxing/oned/OneDReader.cpp index c52c2b311..3a82a04a8 100644 --- a/cpp/core/src/zxing/oned/OneDReader.cpp +++ b/cpp/core/src/zxing/oned/OneDReader.cpp @@ -1,3 +1,4 @@ +// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*- /* * OneDReader.cpp * ZXing