Fixed a bug which prevented this binarizer from caching rows.
authordswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 6 Aug 2010 23:33:48 +0000 (23:33 +0000)
committerdswitkin <dswitkin@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Fri, 6 Aug 2010 23:33:48 +0000 (23:33 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1512 59b500cc-1b3d-0410-9834-0bbf25fbcc57

cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp

index 428a47a..1d2ebfe 100644 (file)
@@ -40,8 +40,7 @@ GlobalHistogramBinarizer::~GlobalHistogramBinarizer() {
 
 
 Ref<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, Ref<BitArray> row) {
-
-  if (row == cached_row_num_) {
+  if (y == cached_row_num_) {
     return cached_row_;
   }
 
@@ -83,17 +82,18 @@ Ref<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, Ref<BitArray> 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<BitMatrix> GlobalHistogramBinarizer::getBlackMatrix() {
-
   if (cached_matrix_ != NULL) {
     return cached_matrix_;
   }
@@ -104,7 +104,6 @@ Ref<BitMatrix> GlobalHistogramBinarizer::getBlackMatrix() {
   int height = source.getHeight();
   vector<int> 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<int> &histogram) {
   int numBuckets = histogram.size();
   int maxBucketCount = 0;
 
-
   // Find tallest peak in histogram
   int firstPeak = 0;
   int firstPeakSize = 0;