[SCM] Multi-format 1D/2D barcode image processing library branch, upstream, updated. 24d4480bc48cf9eabf7b2bd2f528248b0e458809
flyashi
flyashi at 59b500cc-1b3d-0410-9834-0bbf25fbcc57
Wed Aug 4 01:32:34 UTC 2010
The following commit has been merged in the upstream branch:
commit 2a55b4c8357dc05b12b02f34b0db6c2b2f6a36cc
Author: flyashi <flyashi at 59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Date: Mon Jul 19 20:53:17 2010 +0000
C++: added GreyscaleLuminanceSource
It takes a block of greyscale data, width, height, and cropping parameters, and provides a LuminanceSource interface, with rotation (although only 1D is supported for the rotated object at the moment.)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1488 59b500cc-1b3d-0410-9834-0bbf25fbcc57
diff --git a/cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp b/cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp
new file mode 100644
index 0000000..4868003
--- /dev/null
+++ b/cpp/core/src/zxing/common/GreyscaleLuminanceSource.cpp
@@ -0,0 +1,65 @@
+/*
+ * GreyscaleLuminanceSource.cpp
+ * zxing
+ *
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <zxing/common/GreyscaleLuminanceSource.h>
+#include <zxing/common/GreyscaleRotatedLuminanceSource.h>
+#include <zxing/common/IllegalArgumentException.h>
+
+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) {
+
+ if (left + width > dataWidth || top + height > dataHeight || top < 0 || left < 0) {
+ throw IllegalArgumentException("Crop rectangle does not fit within image data.");
+ }
+}
+
+unsigned char* GreyscaleLuminanceSource::getRow(int y, unsigned char* row) {
+
+ if (y < 0 || y >= this->getHeight()) {
+ 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_];
+ }
+ int offset = (y + top_) * dataWidth_ + left_;
+ memcpy(row, &greyData_[offset], width);
+
+ return row;
+}
+
+
+unsigned char* GreyscaleLuminanceSource::getMatrix() {
+ return greyData_;
+}
+
+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_));
+}
+
+
+} /* namespace */
+
diff --git a/cpp/core/src/zxing/common/GreyscaleLuminanceSource.h b/cpp/core/src/zxing/common/GreyscaleLuminanceSource.h
new file mode 100644
index 0000000..cfc6285
--- /dev/null
+++ b/cpp/core/src/zxing/common/GreyscaleLuminanceSource.h
@@ -0,0 +1,64 @@
+/*
+ * GreyscaleLuminanceSource.h
+ * zxing
+ *
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __GREYSCALE_LUMINANCE_SOURCE__
+#define __GREYSCALE_LUMINANCE_SOURCE__
+
+#include <zxing/LuminanceSource.h>
+
+namespace zxing {
+
+class GreyscaleLuminanceSource : public LuminanceSource {
+
+ private:
+ unsigned char* greyData_;
+ int dataWidth_;
+ int dataHeight_;
+ int left_;
+ int top_;
+ int width_;
+ int height_;
+
+ public:
+ 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 {
+ return true;
+ }
+
+ int getWidth() const {
+ return width_;
+ }
+
+ int getHeight() const {
+ return height_;
+ }
+
+ Ref<LuminanceSource> rotateCounterClockwise();
+
+};
+
+} /* namespace */
+
+#endif
diff --git a/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp b/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp
new file mode 100644
index 0000000..2f5d236
--- /dev/null
+++ b/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.cpp
@@ -0,0 +1,61 @@
+/*
+ * GreyscaleRotatedLuminanceSource.cpp
+ * zxing
+ *
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include <zxing/common/GreyscaleRotatedLuminanceSource.h>
+#include <zxing/common/IllegalArgumentException.h>
+
+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) {
+
+ // Intentionally comparing to the opposite dimension since we're rotated.
+ if (left + width > dataHeight || top + height > dataWidth) {
+ throw IllegalArgumentException("Crop rectangle does not fit within image data.");
+ }
+}
+
+// The API asks for rows, but we're rotated, so we return columns.
+unsigned char* GreyscaleRotatedLuminanceSource::getRow(int y, unsigned char* row) {
+ if (y < 0 || y >= getHeight()) {
+ 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];
+ }
+ int offset = (left_ * dataWidth_) + (dataWidth_ - (y + top_));
+ for (int x = 0; x < width; x++) {
+ row[x] = greyData_[offset];
+ offset += dataWidth_;
+ }
+ return row;
+}
+
+unsigned char* GreyscaleRotatedLuminanceSource::getMatrix() {
+ // FIXME(flyashi): fine for 1D scanning, need to implement for 2D scanning
+ return NULL;
+}
+
+} // namespace
diff --git a/cpp/magick/src/MagickBitmapSource.h b/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.h
similarity index 51%
copy from cpp/magick/src/MagickBitmapSource.h
copy to cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.h
index 2bc3b96..d9896e4 100644
--- a/cpp/magick/src/MagickBitmapSource.h
+++ b/cpp/core/src/zxing/common/GreyscaleRotatedLuminanceSource.h
@@ -1,9 +1,8 @@
/*
- * MagickBitmapSource.h
+ * GreyscaleRotatedLuminanceSource.h
* zxing
*
- * Created by Ralf Kistner on 16/10/2009.
- * 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.
@@ -18,32 +17,46 @@
* limitations under the License.
*/
-#ifndef MAGICKMONOCHROMEBITMAPSOURCE_H_
-#define MAGICKMONOCHROMEBITMAPSOURCE_H_
-#include <Magick++.h>
+#ifndef __GREYSCALE_ROTATED_LUMINANCE_SOURCE__
+#define __GREYSCALE_ROTATED_LUMINANCE_SOURCE__
+
#include <zxing/LuminanceSource.h>
namespace zxing {
-class MagickBitmapSource : public LuminanceSource {
-private:
- Magick::Image& image_;
- int width;
- int height;
- const Magick::PixelPacket* pixel_cache;
+class GreyscaleRotatedLuminanceSource : public LuminanceSource {
+ private:
+ unsigned char* greyData_;
+ int dataWidth_;
+ int dataHeight_;
+ int left_;
+ int top_;
+ int width_;
+ int height_;
public:
- MagickBitmapSource(Magick::Image& image);
-
- ~MagickBitmapSource();
+ GreyscaleRotatedLuminanceSource(unsigned char* greyData, int dataWidth, int dataHeight, int left, int top,
+ int width, int height);
- int getWidth() const;
- int getHeight() const;
unsigned char* getRow(int y, unsigned char* row);
+
unsigned char* getMatrix();
+
+ bool isRotateSupported() const {
+ return false;
+ }
+
+ int getWidth() const {
+ return width_;
+ }
+
+ int getHeight() const {
+ return height_;
+ }
+
};
+} /* namespace */
-}
-#endif /* MAGICKMONOCHROMEBITMAPSOURCE_H_ */
+#endif
--
Multi-format 1D/2D barcode image processing library
More information about the Pkg-google-commits
mailing list