Small style stuff
[zxing.git] / cpp / core / src / zxing / common / GreyscaleLuminanceSource.cpp
index 8ff6f8c..4910b65 100644 (file)
@@ -48,7 +48,16 @@ unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) {
 }
 
 unsigned char* GreyscaleLuminanceSource::getMatrix() {
-  return greyData_;
+  int size = width_ * height_;
+  unsigned char* result = new unsigned char[size];
+  if (left_ == 0 && top_ == 0 && dataWidth_ == width_ && dataHeight_ == height_) {
+    memcpy(result, greyData_, size);
+  } else {
+    for (int row = 0; row < height_; row++) {
+      memcpy(result + row * width_, greyData_ + (top_ + row) * dataWidth_ + left_, width_);
+    }
+  }
+  return result;
 }
 
 Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() {