mirror of
https://github.com/zxing/zxing.git
synced 2025-02-21 02:55:27 -08:00
C++ updates for r2574 and other java reconciliation
git-svn-id: https://zxing.googlecode.com/svn/trunk@2622 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
94cacd59f7
commit
849866a07a
44
cpp/core/src/zxing/InvertedLuminanceSource.cpp
Normal file
44
cpp/core/src/zxing/InvertedLuminanceSource.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
/*
|
||||
* Copyright 2013 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/ZXing.h>
|
||||
#include <zxing/InvertedLuminanceSource.h>
|
||||
|
||||
using zxing::ArrayRef;
|
||||
using zxing::InvertedLuminanceSource;
|
||||
|
||||
InvertedLuminanceSource::InvertedLuminanceSource(Ref<LuminanceSource> const& delegate_)
|
||||
: Super(delegate_->getWidth(), delegate_->getHeight()), delegate(delegate_) {}
|
||||
|
||||
ArrayRef<char> InvertedLuminanceSource::getRow(int y, ArrayRef<char> row) const {
|
||||
row = delegate->getRow(y, row);
|
||||
int width = getWidth();
|
||||
for (int i = 0; i < width; i++) {
|
||||
row[i] = (byte) (255 - (row[i] & 0xFF));
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
ArrayRef<char> InvertedLuminanceSource::getMatrix() const {
|
||||
ArrayRef<char> matrix = delegate->getMatrix();
|
||||
int length = getWidth() * getHeight();
|
||||
ArrayRef<char> invertedMatrix(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
invertedMatrix[i] = (byte) (255 - (matrix[i] & 0xFF));
|
||||
}
|
||||
return invertedMatrix;
|
||||
}
|
38
cpp/core/src/zxing/InvertedLuminanceSource.h
Normal file
38
cpp/core/src/zxing/InvertedLuminanceSource.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
// -*- mode:c++; tab-width:2; indent-tabs-mode:nil; c-basic-offset:2 -*-
|
||||
#ifndef __INVERTEDLUMINANCESOURCE_H__
|
||||
#define __INVERTEDLUMINANCESOURCE_H__
|
||||
/*
|
||||
* Copyright 2013 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/LuminanceSource.h>
|
||||
|
||||
namespace zxing {
|
||||
|
||||
class InvertedLuminanceSource : public LuminanceSource {
|
||||
private:
|
||||
typedef LuminanceSource Super;
|
||||
const Ref<LuminanceSource> delegate;
|
||||
|
||||
public:
|
||||
InvertedLuminanceSource(Ref<LuminanceSource> const&);
|
||||
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrix() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* INVERTEDLUMINANCESOURCE_H_ */
|
|
@ -20,16 +20,15 @@
|
|||
|
||||
#include <sstream>
|
||||
#include <zxing/LuminanceSource.h>
|
||||
#include <zxing/InvertedLuminanceSource.h>
|
||||
#include <zxing/common/IllegalArgumentException.h>
|
||||
|
||||
using zxing::Ref;
|
||||
using zxing::LuminanceSource;
|
||||
|
||||
LuminanceSource::LuminanceSource() {
|
||||
}
|
||||
LuminanceSource::LuminanceSource(int width_, int height_) :width(width_), height(height_) {}
|
||||
|
||||
LuminanceSource::~LuminanceSource() {
|
||||
}
|
||||
LuminanceSource::~LuminanceSource() {}
|
||||
|
||||
bool LuminanceSource::isCropSupported() const {
|
||||
return false;
|
||||
|
@ -51,7 +50,7 @@ Ref<LuminanceSource> LuminanceSource::rotateCounterClockwise() {
|
|||
throw IllegalArgumentException("This luminance source does not support rotation.");
|
||||
}
|
||||
|
||||
LuminanceSource::operator std::string() {
|
||||
LuminanceSource::operator std::string() const {
|
||||
ArrayRef<char> row;
|
||||
std::ostringstream oss;
|
||||
for (int y = 0; y < getHeight(); y++) {
|
||||
|
@ -74,3 +73,7 @@ LuminanceSource::operator std::string() {
|
|||
}
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
Ref<LuminanceSource> LuminanceSource::invert(Ref<LuminanceSource> const& that) {
|
||||
return Ref<LuminanceSource>(new InvertedLuminanceSource(that));
|
||||
}
|
||||
|
|
|
@ -25,29 +25,35 @@
|
|||
#include <string.h>
|
||||
|
||||
namespace zxing {
|
||||
class LuminanceSource;
|
||||
}
|
||||
|
||||
class zxing::LuminanceSource : public Counted {
|
||||
public:
|
||||
LuminanceSource();
|
||||
class LuminanceSource : public Counted {
|
||||
private:
|
||||
const int width;
|
||||
const int height;
|
||||
|
||||
public:
|
||||
LuminanceSource(int width, int height);
|
||||
virtual ~LuminanceSource();
|
||||
|
||||
virtual int getWidth() const = 0;
|
||||
virtual int getHeight() const = 0;
|
||||
int getWidth() const { return width; }
|
||||
int getHeight() const { return height; }
|
||||
|
||||
// Callers take ownership of the returned memory and must call delete [] on it themselves.
|
||||
virtual ArrayRef<char> getRow(int y, ArrayRef<char> row) = 0;
|
||||
virtual ArrayRef<char> getMatrix() = 0;
|
||||
virtual ArrayRef<char> getRow(int y, ArrayRef<char> row) const = 0;
|
||||
virtual ArrayRef<char> getMatrix() const = 0;
|
||||
|
||||
virtual bool isCropSupported() const;
|
||||
virtual Ref<LuminanceSource> crop(int left, int top, int width, int height);
|
||||
|
||||
virtual bool isRotateSupported() const;
|
||||
|
||||
static Ref<LuminanceSource> invert(Ref<LuminanceSource> const&);
|
||||
|
||||
virtual Ref<LuminanceSource> rotateCounterClockwise();
|
||||
|
||||
operator std::string (); // should be const but don't want to make sure a
|
||||
// large breaking change right now
|
||||
operator std::string () const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* LUMINANCESOURCE_H_ */
|
||||
|
|
|
@ -23,6 +23,12 @@
|
|||
#define ZXING_DEBUG 0
|
||||
#endif
|
||||
|
||||
namespace zxing {
|
||||
|
||||
typedef char byte;
|
||||
|
||||
}
|
||||
|
||||
#if ZXING_DEBUG
|
||||
|
||||
#include <iostream>
|
||||
|
@ -40,10 +46,8 @@ using std::ostream;
|
|||
#include <sys/time.h>
|
||||
|
||||
namespace zxing {
|
||||
class DebugTimer;
|
||||
}
|
||||
|
||||
class zxing::DebugTimer {
|
||||
class DebugTimer {
|
||||
public:
|
||||
DebugTimer(char const* string_) : chars(string_) {
|
||||
gettimeofday(&start, 0);
|
||||
|
@ -80,6 +84,8 @@ private:
|
|||
struct timeval start;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#define ZXING_TIME(string) DebugTimer __timer__ (string)
|
||||
#define ZXING_TIME_MARK(string) __timer__.mark(string)
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public:
|
|||
values_ = array;
|
||||
return *this;
|
||||
}
|
||||
T operator[](int i) const {
|
||||
T const& operator[](int i) const {
|
||||
return values_[i];
|
||||
}
|
||||
T& operator[](int i) {
|
||||
|
@ -117,7 +117,7 @@ public:
|
|||
array_ = 0;
|
||||
}
|
||||
|
||||
T operator[](int i) const {
|
||||
T const& operator[](int i) const {
|
||||
return (*array_)[i];
|
||||
}
|
||||
T& operator[](int i) {
|
||||
|
|
|
@ -32,17 +32,17 @@ GreyscaleLuminanceSource(ArrayRef<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) {
|
||||
|
||||
: Super(width, height),
|
||||
greyData_(greyData),
|
||||
dataWidth_(dataWidth), dataHeight_(dataHeight),
|
||||
left_(left), top_(top) {
|
||||
|
||||
if (left + width > dataWidth || top + height > dataHeight || top < 0 || left < 0) {
|
||||
throw IllegalArgumentException("Crop rectangle does not fit within image data.");
|
||||
}
|
||||
}
|
||||
|
||||
ArrayRef<char> GreyscaleLuminanceSource::getRow(int y, ArrayRef<char> row) {
|
||||
ArrayRef<char> GreyscaleLuminanceSource::getRow(int y, ArrayRef<char> row) const {
|
||||
if (y < 0 || y >= this->getHeight()) {
|
||||
throw IllegalArgumentException("Requested row is outside the image.");
|
||||
}
|
||||
|
@ -56,14 +56,14 @@ ArrayRef<char> GreyscaleLuminanceSource::getRow(int y, ArrayRef<char> row) {
|
|||
return row;
|
||||
}
|
||||
|
||||
ArrayRef<char> GreyscaleLuminanceSource::getMatrix() {
|
||||
int size = width_ * height_;
|
||||
ArrayRef<char> GreyscaleLuminanceSource::getMatrix() const {
|
||||
int size = getWidth() * getHeight();
|
||||
ArrayRef<char> result (size);
|
||||
if (left_ == 0 && top_ == 0 && dataWidth_ == width_ && dataHeight_ == height_) {
|
||||
if (left_ == 0 && top_ == 0 && dataWidth_ == getWidth() && dataHeight_ == getHeight()) {
|
||||
memcpy(&result[0], &greyData_[0], size);
|
||||
} else {
|
||||
for (int row = 0; row < height_; row++) {
|
||||
memcpy(&result[row * width_], &greyData_[(top_ + row) * dataWidth_ + left_], width_);
|
||||
for (int row = 0; row < getHeight(); row++) {
|
||||
memcpy(&result[row * getWidth()], &greyData_[(top_ + row) * dataWidth_ + left_], getWidth());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@ -77,35 +77,7 @@ Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() {
|
|||
Ref<LuminanceSource> result (
|
||||
new GreyscaleRotatedLuminanceSource(greyData_,
|
||||
dataWidth_, dataHeight_,
|
||||
top_, left_, height_, width_)
|
||||
top_, left_, getHeight(), getWidth())
|
||||
);
|
||||
|
||||
/*
|
||||
// testing code ... remove when we trust everything.
|
||||
// NB: very slow, so don't forget and leave on.
|
||||
for(int r = top_; r < top_+height_; ++r) {
|
||||
for(int c = left_; c < left_+width_; ++c) {
|
||||
int rot_r = r;
|
||||
int rot_c = c;
|
||||
// transpose
|
||||
int tmp = rot_r;
|
||||
rot_r = rot_c;
|
||||
rot_c = tmp;
|
||||
// flip vert
|
||||
rot_r = width_-rot_r-1;
|
||||
if (getRow(r, ArrayRef<char>())[c] !=
|
||||
result->getRow(rot_r, ArrayRef<char>())[rot_c]) {
|
||||
using namespace std;
|
||||
cerr << r << "," << c << " "
|
||||
<< rot_r << "," << rot_c << " "
|
||||
<< (0+getRow(r, ArrayRef<char>())[c]) << " "
|
||||
<< (0+result->getRow(rot_r, ArrayRef<char>())[rot_c]) << " "
|
||||
<< endl;
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -23,41 +23,32 @@
|
|||
#include <zxing/LuminanceSource.h>
|
||||
|
||||
namespace zxing {
|
||||
class GreyscaleLuminanceSource;
|
||||
}
|
||||
|
||||
class zxing::GreyscaleLuminanceSource : public LuminanceSource {
|
||||
class GreyscaleLuminanceSource : public LuminanceSource {
|
||||
|
||||
private:
|
||||
typedef LuminanceSource Super;
|
||||
ArrayRef<char> greyData_;
|
||||
int dataWidth_;
|
||||
int dataHeight_;
|
||||
int left_;
|
||||
int top_;
|
||||
int width_;
|
||||
int height_;
|
||||
const int dataWidth_;
|
||||
const int dataHeight_;
|
||||
const int left_;
|
||||
const int top_;
|
||||
|
||||
public:
|
||||
GreyscaleLuminanceSource(ArrayRef<char> greyData, int dataWidth, int dataHeight, int left,
|
||||
int top, int width, int height);
|
||||
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row);
|
||||
ArrayRef<char> getMatrix();
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrix() const;
|
||||
|
||||
bool isRotateSupported() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
int getWidth() const {
|
||||
return width_;
|
||||
}
|
||||
|
||||
int getHeight() const {
|
||||
return height_;
|
||||
}
|
||||
|
||||
Ref<LuminanceSource> rotateCounterClockwise();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -32,11 +32,11 @@ GreyscaleRotatedLuminanceSource::
|
|||
GreyscaleRotatedLuminanceSource(ArrayRef<char> greyData,
|
||||
int dataWidth, int dataHeight,
|
||||
int left, int top,
|
||||
int width, int height)
|
||||
: greyData_(greyData),
|
||||
dataWidth_(dataWidth),
|
||||
left_(left), top_(top), width_(width),
|
||||
height_(height) {
|
||||
int width, int height)
|
||||
: Super(width, height),
|
||||
greyData_(greyData),
|
||||
dataWidth_(dataWidth),
|
||||
left_(left), top_(top) {
|
||||
// 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.");
|
||||
|
@ -45,34 +45,34 @@ GreyscaleRotatedLuminanceSource(ArrayRef<char> greyData,
|
|||
|
||||
// The API asks for rows, but we're rotated, so we return columns.
|
||||
ArrayRef<char>
|
||||
GreyscaleRotatedLuminanceSource::getRow(int y, ArrayRef<char> row) {
|
||||
GreyscaleRotatedLuminanceSource::getRow(int y, ArrayRef<char> row) const {
|
||||
if (y < 0 || y >= getHeight()) {
|
||||
throw IllegalArgumentException("Requested row is outside the image.");
|
||||
}
|
||||
if (!row || row.size() < width_) {
|
||||
row = ArrayRef<char>(width_);
|
||||
if (!row || row.size() < getWidth()) {
|
||||
row = ArrayRef<char>(getWidth());
|
||||
}
|
||||
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
|
||||
using namespace std;
|
||||
if (false) {
|
||||
cerr << offset << " = "
|
||||
<< top_ << " " << left_ << " "
|
||||
<< height_ << " " << width_ << " "
|
||||
<< getHeight() << " " << getWidth() << " "
|
||||
<< y << endl;
|
||||
}
|
||||
for (int x = 0; x < width_; x++) {
|
||||
for (int x = 0; x < getWidth(); x++) {
|
||||
row[x] = greyData_[offset];
|
||||
offset += dataWidth_;
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
ArrayRef<char> GreyscaleRotatedLuminanceSource::getMatrix() {
|
||||
ArrayRef<char> result (width_ * height_);
|
||||
for (int y = 0; y < height_; y++) {
|
||||
char* row = &result[y * width_];
|
||||
ArrayRef<char> GreyscaleRotatedLuminanceSource::getMatrix() const {
|
||||
ArrayRef<char> result (getWidth() * getHeight());
|
||||
for (int y = 0; y < getHeight(); y++) {
|
||||
char* row = &result[y * getWidth()];
|
||||
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
|
||||
for (int x = 0; x < width_; x++) {
|
||||
for (int x = 0; x < getWidth(); x++) {
|
||||
row[x] = greyData_[offset];
|
||||
offset += dataWidth_;
|
||||
}
|
||||
|
|
|
@ -24,37 +24,27 @@
|
|||
#include <zxing/LuminanceSource.h>
|
||||
|
||||
namespace zxing {
|
||||
class GreyscaleRotatedLuminanceSource;
|
||||
}
|
||||
|
||||
class zxing::GreyscaleRotatedLuminanceSource : public LuminanceSource {
|
||||
class GreyscaleRotatedLuminanceSource : public LuminanceSource {
|
||||
private:
|
||||
typedef LuminanceSource Super;
|
||||
ArrayRef<char> greyData_;
|
||||
const int dataWidth_;
|
||||
const int left_;
|
||||
const int top_;
|
||||
const int width_;
|
||||
const int height_;
|
||||
|
||||
public:
|
||||
GreyscaleRotatedLuminanceSource(ArrayRef<char> greyData, int dataWidth, int dataHeight,
|
||||
int left, int top, int width, int height);
|
||||
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row);
|
||||
ArrayRef<char> getMatrix();
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrix() const;
|
||||
|
||||
bool isRotateSupported() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
int getWidth() const {
|
||||
return width_;
|
||||
}
|
||||
|
||||
int getHeight() const {
|
||||
return height_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,27 +26,18 @@ using zxing::Ref;
|
|||
using zxing::LuminanceSource;
|
||||
using zxing::MagickBitmapSource;
|
||||
|
||||
MagickBitmapSource::MagickBitmapSource(Image& image) : image_(image) {
|
||||
width = image.columns();
|
||||
height = image.rows();
|
||||
}
|
||||
MagickBitmapSource::MagickBitmapSource(Image& image)
|
||||
: Super(image.columns(), image.rows()), image_(image) {}
|
||||
|
||||
MagickBitmapSource::~MagickBitmapSource() {
|
||||
}
|
||||
|
||||
int MagickBitmapSource::getWidth() const {
|
||||
return width;
|
||||
}
|
||||
ArrayRef<char> MagickBitmapSource::getRow(int y, ArrayRef<char> row) const {
|
||||
const int width = getWidth();
|
||||
|
||||
int MagickBitmapSource::getHeight() const {
|
||||
return height;
|
||||
}
|
||||
|
||||
ArrayRef<char> MagickBitmapSource::getRow(int y, ArrayRef<char> row) {
|
||||
const Magick::PixelPacket* pixel_cache =
|
||||
image_.getConstPixels(0, y, width, 1);
|
||||
image_.getConstPixels(0, y, width, 1);
|
||||
|
||||
int width = getWidth();
|
||||
if (!row || row->size() < width) {
|
||||
row =ArrayRef<char>(width);
|
||||
}
|
||||
|
@ -62,10 +53,10 @@ ArrayRef<char> MagickBitmapSource::getRow(int y, ArrayRef<char> row) {
|
|||
}
|
||||
|
||||
/** This is a more efficient implementation. */
|
||||
ArrayRef<char> MagickBitmapSource::getMatrix() {
|
||||
ArrayRef<char> MagickBitmapSource::getMatrix() const {
|
||||
const int width = getWidth();
|
||||
const int height = getHeight();
|
||||
const Magick::PixelPacket* pixel_cache = image_.getConstPixels(0, 0, width, height);
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
ArrayRef<char> matrix = ArrayRef<char>(width*height);
|
||||
char* m = &matrix[0];
|
||||
const Magick::PixelPacket* p = pixel_cache;
|
||||
|
|
|
@ -21,28 +21,26 @@
|
|||
#include <zxing/LuminanceSource.h>
|
||||
|
||||
namespace zxing {
|
||||
class MagickBitmapSource;
|
||||
}
|
||||
|
||||
class zxing::MagickBitmapSource : public LuminanceSource {
|
||||
class MagickBitmapSource : public LuminanceSource {
|
||||
private:
|
||||
typedef LuminanceSource Super;
|
||||
Magick::Image image_;
|
||||
int width;
|
||||
int height;
|
||||
|
||||
public:
|
||||
MagickBitmapSource(Magick::Image& image);
|
||||
|
||||
~MagickBitmapSource();
|
||||
|
||||
int getWidth() const;
|
||||
int getHeight() const;
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row);
|
||||
ArrayRef<char> getMatrix();
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrix() const;
|
||||
|
||||
bool isCropSupported() const;
|
||||
Ref<LuminanceSource> crop(int left, int top, int width, int height);
|
||||
bool isRotateSupported() const;
|
||||
Ref<LuminanceSource> rotateCounterClockwise();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* MAGICKMONOCHROMEBITMAPSOURCE_H_ */
|
||||
|
|
Loading…
Reference in a new issue