Removed an extra BitArray, honored the result of LuminanceSource.getRow(), and fixed
authordswitkin@google.com <dswitkin@google.com@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 11 Aug 2010 15:17:35 +0000 (15:17 +0000)
committerdswitkin@google.com <dswitkin@google.com@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Wed, 11 Aug 2010 15:17:35 +0000 (15:17 +0000)
a bunch of formatting.

git-svn-id: http://zxing.googlecode.com/svn/trunk@1520 59b500cc-1b3d-0410-9834-0bbf25fbcc57

cpp/core/src/zxing/common/GlobalHistogramBinarizer.cpp
cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp
cpp/core/src/zxing/common/GreyscaleLuminanceSource.h
cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp
cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.h

index 581d046..75bb4ff 100644 (file)
@@ -56,44 +56,41 @@ Ref<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, Ref<BitArray> row) {
   } else {
     row->clear();
   }
-  
+
   //TODO(flyashi): cache this instead of allocating and deleting per row
   unsigned char* row_pixels = NULL;
   try {
-      row_pixels = new unsigned char[width];
-      getLuminanceSource()->getRow(y,row_pixels);
-      for (int x = 0; x < width; x++) {
-          histogram[row_pixels[x] >> LUMINANCE_SHIFT]++;
-      }
-      int blackPoint = estimate(histogram) << LUMINANCE_SHIFT;
-
-
-      Ref<BitArray> array_ref(new BitArray(width));
-      BitArray& array = *array_ref;
-
-      int left = row_pixels[0];
-      int center = row_pixels[1];
-      for (int x = 1; x < width - 1; x++) {
-          int right = row_pixels[x + 1];
-          // A simple -1 4 -1 box filter with a weight of 2.
-          int luminance = ((center << 2) - left - right) >> 1;
-          if (luminance < blackPoint) {
-              array.set(x);
-          }
-          left = center;
-          center = right;
+    row_pixels = new unsigned char[width];
+    row_pixels = getLuminanceSource()->getRow(y, row_pixels);
+    for (int x = 0; x < width; x++) {
+      histogram[row_pixels[x] >> LUMINANCE_SHIFT]++;
+    }
+    int blackPoint = estimate(histogram) << LUMINANCE_SHIFT;
+
+    BitArray& array = *row;
+    int left = row_pixels[0];
+    int center = row_pixels[1];
+    for (int x = 1; x < width - 1; x++) {
+      int right = row_pixels[x + 1];
+      // A simple -1 4 -1 box filter with a weight of 2.
+      int luminance = ((center << 2) - left - right) >> 1;
+      if (luminance < blackPoint) {
+        array.set(x);
       }
+      left = center;
+      center = right;
+    }
 
-      cached_row_ = array_ref;
-      cached_row_num_ = y;
-      delete [] row_pixels;
-      return array_ref;
+    cached_row_ = row;
+    cached_row_num_ = y;
+    delete [] row_pixels;
+    return row;
   } catch (IllegalArgumentException const& iae) {
-      // Cache the fact that this row failed.
-      cached_row_ = NULL;
-      cached_row_num_ = y;
-      delete [] row_pixels;
-      throw iae;
+    // Cache the fact that this row failed.
+    cached_row_ = NULL;
+    cached_row_num_ = y;
+    delete [] row_pixels;
+    throw iae;
   }
 }
 
@@ -213,4 +210,3 @@ Ref<Binarizer> GlobalHistogramBinarizer::createBinarizer(Ref<LuminanceSource> so
 }
 
 } // namespace zxing
-
index 4868003..8ff6f8c 100644 (file)
 
 namespace zxing {
 
-GreyscaleLuminanceSource::GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, int top,
-      int width, int height) : greyData_(greyData), dataWidth_(dataWidth), dataHeight_(dataHeight),
-      left_(left), top_(top), width_(width), height_(height)  {
+GreyscaleLuminanceSource::GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth,
+    int dataHeight, int left, int top, int width, int height) : greyData_(greyData),
+    dataWidth_(dataWidth), dataHeight_(dataHeight), left_(left), top_(top), width_(width),
+    height_(height) {
 
   if (left + width > dataWidth || top + height > dataHeight || top < 0 || left < 0) {
     throw IllegalArgumentException("Crop rectangle does not fit within image data.");
@@ -33,7 +34,6 @@ GreyscaleLuminanceSource::GreyscaleLuminanceSource(unsigned char* greyData, int
 }
 
 unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) {
-
   if (y < 0 || y >= this->getHeight()) {
     throw IllegalArgumentException("Requested row is outside the image: " + y);
   }
@@ -44,11 +44,9 @@ unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) {
   }
   int offset = (y + top_) * dataWidth_ + left_;
   memcpy(row, &greyData_[offset], width);
-
   return row;
 }
 
-
 unsigned char* GreyscaleLuminanceSource::getMatrix() {
   return greyData_;
 }
@@ -56,10 +54,8 @@ unsigned char* GreyscaleLuminanceSource::getMatrix() {
 Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() {
   // Intentionally flip the left, top, width, and height arguments as needed. dataWidth and
   // dataHeight are always kept unrotated.
-  return Ref<LuminanceSource> (new GreyscaleRotatedLuminanceSource(greyData_, dataWidth_, dataHeight_,
-                               top_, left_, height_, width_));
+  return Ref<LuminanceSource> (new GreyscaleRotatedLuminanceSource(greyData_, dataWidth_,
+      dataHeight_, top_, left_, height_, width_));
 }
 
-
 } /* namespace */
-
index 944b289..4729191 100644 (file)
@@ -35,11 +35,10 @@ class GreyscaleLuminanceSource : public LuminanceSource {
   int height_;
 
  public:
-  GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, int top,
-      int width, int height);
+  GreyscaleLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left,
+      int top, int width, int height);
 
   unsigned char* getRow(int y, unsigned char* row);
-
   unsigned char* getMatrix();
 
   bool isRotateSupported() const {
@@ -55,7 +54,7 @@ class GreyscaleLuminanceSource : public LuminanceSource {
   }
 
   Ref<LuminanceSource> rotateCounterClockwise();
-  
+
 };
 
 } /* namespace */
index 2f5d236..4e3aec8 100644 (file)
@@ -25,9 +25,10 @@ namespace zxing {
 
 // Note that dataWidth and dataHeight are not reversed, as we need to be able to traverse the
 // greyData correctly, which does not get rotated.
-GreyscaleRotatedLuminanceSource::GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight,
-      int left, int top, int width, int height) : greyData_(greyData), dataWidth_(dataWidth), dataHeight_(dataHeight),
-      left_(left), top_(top), width_(width), height_(height) {
+GreyscaleRotatedLuminanceSource::GreyscaleRotatedLuminanceSource(unsigned char* greyData,
+    int dataWidth, int dataHeight, int left, int top, int width, int height) : greyData_(greyData),
+    dataWidth_(dataWidth), dataHeight_(dataHeight), left_(left), top_(top), width_(width),
+    height_(height) {
 
   // Intentionally comparing to the opposite dimension since we're rotated.
   if (left + width > dataHeight || top + height > dataWidth) {
index c38d1a1..80535ab 100644 (file)
@@ -35,11 +35,10 @@ class GreyscaleRotatedLuminanceSource : public LuminanceSource {
   int height_;
 
 public:
-  GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, int top,
-      int width, int height);
+  GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight,
+      int left, int top, int width, int height);
 
   unsigned char* getRow(int y, unsigned char* row);
-
   unsigned char* getMatrix();
 
   bool isRotateSupported() const {
@@ -55,7 +54,7 @@ public:
   }
 
 };
-} /* namespace */
 
+} /* namespace */
 
 #endif