From 88006a333e7f5daa8f66fb265061ef9a6812aac8 Mon Sep 17 00:00:00 2001 From: "dswitkin@google.com" Date: Tue, 24 Aug 2010 18:59:26 +0000 Subject: [PATCH] Removed an extra memcpy and made getMatrix() pure virtual. git-svn-id: http://zxing.googlecode.com/svn/trunk@1556 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/core/src/zxing/LuminanceSource.cpp | 13 ------------- cpp/core/src/zxing/LuminanceSource.h | 2 +- cpp/core/src/zxing/ResultPointCallback.cpp | 3 +-- .../common/GreyscaleRotatedLuminanceSource.cpp | 7 ++----- 4 files changed, 4 insertions(+), 21 deletions(-) diff --git a/cpp/core/src/zxing/LuminanceSource.cpp b/cpp/core/src/zxing/LuminanceSource.cpp index 0667d4cc..834dba28 100644 --- a/cpp/core/src/zxing/LuminanceSource.cpp +++ b/cpp/core/src/zxing/LuminanceSource.cpp @@ -28,19 +28,6 @@ LuminanceSource::LuminanceSource() { LuminanceSource::~LuminanceSource() { } -unsigned char* LuminanceSource::getMatrix() { - int width = getWidth(); - int height = getHeight(); - unsigned char* matrix = new unsigned char[width * height]; - unsigned char* row = new unsigned char[width]; - for (int y = 0; y < height; y++) { - row = getRow(y, row); - memcpy(&matrix[y * width], row, width); - } - delete [] row; - return matrix; -} - bool LuminanceSource::isCropSupported() const { return false; } diff --git a/cpp/core/src/zxing/LuminanceSource.h b/cpp/core/src/zxing/LuminanceSource.h index bbcfa26a..68a6e351 100644 --- a/cpp/core/src/zxing/LuminanceSource.h +++ b/cpp/core/src/zxing/LuminanceSource.h @@ -34,7 +34,7 @@ public: // Callers take ownership of the returned memory and must call delete [] on it themselves. virtual unsigned char* getRow(int y, unsigned char* row) = 0; - virtual unsigned char* getMatrix(); + virtual unsigned char* getMatrix() = 0; virtual bool isCropSupported() const; virtual Ref crop(int left, int top, int width, int height); diff --git a/cpp/core/src/zxing/ResultPointCallback.cpp b/cpp/core/src/zxing/ResultPointCallback.cpp index 72474c95..723942ab 100644 --- a/cpp/core/src/zxing/ResultPointCallback.cpp +++ b/cpp/core/src/zxing/ResultPointCallback.cpp @@ -2,8 +2,7 @@ * ResultPointCallback.cpp * zxing * - * Created by Christian Brunschen on 13/05/2008. - * Copyright 2008 ZXing authors All rights reserved. + * Copyright 2010 ZXing authors All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp b/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp index 25c09db9..498b5ea0 100644 --- a/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp +++ b/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp @@ -42,7 +42,6 @@ unsigned char* GreyscaleRotatedLuminanceSource::getRow(int y, unsigned char* row throw IllegalArgumentException("Requested row is outside the image: " + y); } int width = getWidth(); - // TODO(flyashi): determine if row has enough size. if (row == NULL) { row = new unsigned char[width]; } @@ -56,12 +55,10 @@ unsigned char* GreyscaleRotatedLuminanceSource::getRow(int y, unsigned char* row unsigned char* GreyscaleRotatedLuminanceSource::getMatrix() { unsigned char* result = new unsigned char[width_ * height_]; - unsigned char* row = new unsigned char[width_]; + // This depends on getRow() honoring its second parameter. for (int y = 0; y < height_; y++) { - row = getRow(y, row); - memcpy(result + y * width_, row, width_); + getRow(y, &result[y * width_]); } - delete [] row; return result; } -- 2.20.1