From a2226af690b3c91f7d03cd9c60d57ade54004966 Mon Sep 17 00:00:00 2001 From: dswitkin Date: Fri, 6 Aug 2010 23:33:48 +0000 Subject: [PATCH] Fixed a bug which prevented this binarizer from caching rows. git-svn-id: https://zxing.googlecode.com/svn/trunk@1512 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp b/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp index 428a47a15..1d2ebfe4c 100644 --- a/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp +++ b/cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp @@ -40,8 +40,7 @@ GlobalHistogramBinarizer::~GlobalHistogramBinarizer() { Ref GlobalHistogramBinarizer::getBlackRow(int y, Ref row) { - - if (row == cached_row_num_) { + if (y == cached_row_num_) { return cached_row_; } @@ -83,17 +82,18 @@ Ref GlobalHistogramBinarizer::getBlackRow(int y, Ref row) { cached_row_ = array_ref; cached_row_num_ = y; - delete [] row_pixels; return array_ref; } catch (IllegalArgumentException const& iae) { + // Cache the fact that this row failed. + cached_row_ = NULL; + cached_row_num_ = y; delete [] row_pixels; throw iae; } } Ref GlobalHistogramBinarizer::getBlackMatrix() { - if (cached_matrix_ != NULL) { return cached_matrix_; } @@ -104,7 +104,6 @@ Ref GlobalHistogramBinarizer::getBlackMatrix() { int height = source.getHeight(); vector histogram(LUMINANCE_BUCKETS, 0); - // Quickly calculates the histogram by sampling four rows from the image. // This proved to be more robust on the blackbox tests than sampling a // diagonal as we used to do. @@ -142,7 +141,6 @@ int GlobalHistogramBinarizer::estimate(vector &histogram) { int numBuckets = histogram.size(); int maxBucketCount = 0; - // Find tallest peak in histogram int firstPeak = 0; int firstPeakSize = 0;