mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -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 <sstream>
|
||||||
#include <zxing/LuminanceSource.h>
|
#include <zxing/LuminanceSource.h>
|
||||||
|
#include <zxing/InvertedLuminanceSource.h>
|
||||||
#include <zxing/common/IllegalArgumentException.h>
|
#include <zxing/common/IllegalArgumentException.h>
|
||||||
|
|
||||||
using zxing::Ref;
|
using zxing::Ref;
|
||||||
using zxing::LuminanceSource;
|
using zxing::LuminanceSource;
|
||||||
|
|
||||||
LuminanceSource::LuminanceSource() {
|
LuminanceSource::LuminanceSource(int width_, int height_) :width(width_), height(height_) {}
|
||||||
}
|
|
||||||
|
|
||||||
LuminanceSource::~LuminanceSource() {
|
LuminanceSource::~LuminanceSource() {}
|
||||||
}
|
|
||||||
|
|
||||||
bool LuminanceSource::isCropSupported() const {
|
bool LuminanceSource::isCropSupported() const {
|
||||||
return false;
|
return false;
|
||||||
|
@ -51,7 +50,7 @@ Ref<LuminanceSource> LuminanceSource::rotateCounterClockwise() {
|
||||||
throw IllegalArgumentException("This luminance source does not support rotation.");
|
throw IllegalArgumentException("This luminance source does not support rotation.");
|
||||||
}
|
}
|
||||||
|
|
||||||
LuminanceSource::operator std::string() {
|
LuminanceSource::operator std::string() const {
|
||||||
ArrayRef<char> row;
|
ArrayRef<char> row;
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
for (int y = 0; y < getHeight(); y++) {
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
|
@ -74,3 +73,7 @@ LuminanceSource::operator std::string() {
|
||||||
}
|
}
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ref<LuminanceSource> LuminanceSource::invert(Ref<LuminanceSource> const& that) {
|
||||||
|
return Ref<LuminanceSource>(new InvertedLuminanceSource(that));
|
||||||
|
}
|
||||||
|
|
|
@ -25,29 +25,35 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
class LuminanceSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
class zxing::LuminanceSource : public Counted {
|
class LuminanceSource : public Counted {
|
||||||
|
private:
|
||||||
|
const int width;
|
||||||
|
const int height;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LuminanceSource();
|
LuminanceSource(int width, int height);
|
||||||
virtual ~LuminanceSource();
|
virtual ~LuminanceSource();
|
||||||
|
|
||||||
virtual int getWidth() const = 0;
|
int getWidth() const { return width; }
|
||||||
virtual int getHeight() const = 0;
|
int getHeight() const { return height; }
|
||||||
|
|
||||||
// Callers take ownership of the returned memory and must call delete [] on it themselves.
|
// 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> getRow(int y, ArrayRef<char> row) const = 0;
|
||||||
virtual ArrayRef<char> getMatrix() = 0;
|
virtual ArrayRef<char> getMatrix() const = 0;
|
||||||
|
|
||||||
virtual bool isCropSupported() const;
|
virtual bool isCropSupported() const;
|
||||||
virtual Ref<LuminanceSource> crop(int left, int top, int width, int height);
|
virtual Ref<LuminanceSource> crop(int left, int top, int width, int height);
|
||||||
|
|
||||||
virtual bool isRotateSupported() const;
|
virtual bool isRotateSupported() const;
|
||||||
|
|
||||||
|
static Ref<LuminanceSource> invert(Ref<LuminanceSource> const&);
|
||||||
|
|
||||||
virtual Ref<LuminanceSource> rotateCounterClockwise();
|
virtual Ref<LuminanceSource> rotateCounterClockwise();
|
||||||
|
|
||||||
operator std::string (); // should be const but don't want to make sure a
|
operator std::string () const;
|
||||||
// large breaking change right now
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* LUMINANCESOURCE_H_ */
|
#endif /* LUMINANCESOURCE_H_ */
|
||||||
|
|
|
@ -23,6 +23,12 @@
|
||||||
#define ZXING_DEBUG 0
|
#define ZXING_DEBUG 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace zxing {
|
||||||
|
|
||||||
|
typedef char byte;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#if ZXING_DEBUG
|
#if ZXING_DEBUG
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -40,10 +46,8 @@ using std::ostream;
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
class DebugTimer;
|
|
||||||
}
|
|
||||||
|
|
||||||
class zxing::DebugTimer {
|
class DebugTimer {
|
||||||
public:
|
public:
|
||||||
DebugTimer(char const* string_) : chars(string_) {
|
DebugTimer(char const* string_) : chars(string_) {
|
||||||
gettimeofday(&start, 0);
|
gettimeofday(&start, 0);
|
||||||
|
@ -80,6 +84,8 @@ private:
|
||||||
struct timeval start;
|
struct timeval start;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#define ZXING_TIME(string) DebugTimer __timer__ (string)
|
#define ZXING_TIME(string) DebugTimer __timer__ (string)
|
||||||
#define ZXING_TIME_MARK(string) __timer__.mark(string)
|
#define ZXING_TIME_MARK(string) __timer__.mark(string)
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,7 @@ public:
|
||||||
values_ = array;
|
values_ = array;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
T operator[](int i) const {
|
T const& operator[](int i) const {
|
||||||
return values_[i];
|
return values_[i];
|
||||||
}
|
}
|
||||||
T& operator[](int i) {
|
T& operator[](int i) {
|
||||||
|
@ -117,7 +117,7 @@ public:
|
||||||
array_ = 0;
|
array_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
T operator[](int i) const {
|
T const& operator[](int i) const {
|
||||||
return (*array_)[i];
|
return (*array_)[i];
|
||||||
}
|
}
|
||||||
T& operator[](int i) {
|
T& operator[](int i) {
|
||||||
|
|
|
@ -32,17 +32,17 @@ GreyscaleLuminanceSource(ArrayRef<char> greyData,
|
||||||
int dataWidth, int dataHeight,
|
int dataWidth, int dataHeight,
|
||||||
int left, int top,
|
int left, int top,
|
||||||
int width, int height)
|
int width, int height)
|
||||||
: greyData_(greyData),
|
: Super(width, height),
|
||||||
|
greyData_(greyData),
|
||||||
dataWidth_(dataWidth), dataHeight_(dataHeight),
|
dataWidth_(dataWidth), dataHeight_(dataHeight),
|
||||||
left_(left), top_(top),
|
left_(left), top_(top) {
|
||||||
width_(width), height_(height) {
|
|
||||||
|
|
||||||
if (left + width > dataWidth || top + height > dataHeight || top < 0 || left < 0) {
|
if (left + width > dataWidth || top + height > dataHeight || top < 0 || left < 0) {
|
||||||
throw IllegalArgumentException("Crop rectangle does not fit within image data.");
|
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()) {
|
if (y < 0 || y >= this->getHeight()) {
|
||||||
throw IllegalArgumentException("Requested row is outside the image.");
|
throw IllegalArgumentException("Requested row is outside the image.");
|
||||||
}
|
}
|
||||||
|
@ -56,14 +56,14 @@ ArrayRef<char> GreyscaleLuminanceSource::getRow(int y, ArrayRef<char> row) {
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayRef<char> GreyscaleLuminanceSource::getMatrix() {
|
ArrayRef<char> GreyscaleLuminanceSource::getMatrix() const {
|
||||||
int size = width_ * height_;
|
int size = getWidth() * getHeight();
|
||||||
ArrayRef<char> result (size);
|
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);
|
memcpy(&result[0], &greyData_[0], size);
|
||||||
} else {
|
} else {
|
||||||
for (int row = 0; row < height_; row++) {
|
for (int row = 0; row < getHeight(); row++) {
|
||||||
memcpy(&result[row * width_], &greyData_[(top_ + row) * dataWidth_ + left_], width_);
|
memcpy(&result[row * getWidth()], &greyData_[(top_ + row) * dataWidth_ + left_], getWidth());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -77,35 +77,7 @@ Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() {
|
||||||
Ref<LuminanceSource> result (
|
Ref<LuminanceSource> result (
|
||||||
new GreyscaleRotatedLuminanceSource(greyData_,
|
new GreyscaleRotatedLuminanceSource(greyData_,
|
||||||
dataWidth_, dataHeight_,
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,41 +23,32 @@
|
||||||
#include <zxing/LuminanceSource.h>
|
#include <zxing/LuminanceSource.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
class GreyscaleLuminanceSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
class zxing::GreyscaleLuminanceSource : public LuminanceSource {
|
class GreyscaleLuminanceSource : public LuminanceSource {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
typedef LuminanceSource Super;
|
||||||
ArrayRef<char> greyData_;
|
ArrayRef<char> greyData_;
|
||||||
int dataWidth_;
|
const int dataWidth_;
|
||||||
int dataHeight_;
|
const int dataHeight_;
|
||||||
int left_;
|
const int left_;
|
||||||
int top_;
|
const int top_;
|
||||||
int width_;
|
|
||||||
int height_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GreyscaleLuminanceSource(ArrayRef<char> greyData, int dataWidth, int dataHeight, int left,
|
GreyscaleLuminanceSource(ArrayRef<char> greyData, int dataWidth, int dataHeight, int left,
|
||||||
int top, int width, int height);
|
int top, int width, int height);
|
||||||
|
|
||||||
ArrayRef<char> getRow(int y, ArrayRef<char> row);
|
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||||
ArrayRef<char> getMatrix();
|
ArrayRef<char> getMatrix() const;
|
||||||
|
|
||||||
bool isRotateSupported() const {
|
bool isRotateSupported() const {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getWidth() const {
|
|
||||||
return width_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getHeight() const {
|
|
||||||
return height_;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ref<LuminanceSource> rotateCounterClockwise();
|
Ref<LuminanceSource> rotateCounterClockwise();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,10 +33,10 @@ GreyscaleRotatedLuminanceSource(ArrayRef<char> greyData,
|
||||||
int dataWidth, int dataHeight,
|
int dataWidth, int dataHeight,
|
||||||
int left, int top,
|
int left, int top,
|
||||||
int width, int height)
|
int width, int height)
|
||||||
: greyData_(greyData),
|
: Super(width, height),
|
||||||
|
greyData_(greyData),
|
||||||
dataWidth_(dataWidth),
|
dataWidth_(dataWidth),
|
||||||
left_(left), top_(top), width_(width),
|
left_(left), top_(top) {
|
||||||
height_(height) {
|
|
||||||
// Intentionally comparing to the opposite dimension since we're rotated.
|
// Intentionally comparing to the opposite dimension since we're rotated.
|
||||||
if (left + width > dataHeight || top + height > dataWidth) {
|
if (left + width > dataHeight || top + height > dataWidth) {
|
||||||
throw IllegalArgumentException("Crop rectangle does not fit within image data.");
|
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.
|
// The API asks for rows, but we're rotated, so we return columns.
|
||||||
ArrayRef<char>
|
ArrayRef<char>
|
||||||
GreyscaleRotatedLuminanceSource::getRow(int y, ArrayRef<char> row) {
|
GreyscaleRotatedLuminanceSource::getRow(int y, ArrayRef<char> row) const {
|
||||||
if (y < 0 || y >= getHeight()) {
|
if (y < 0 || y >= getHeight()) {
|
||||||
throw IllegalArgumentException("Requested row is outside the image.");
|
throw IllegalArgumentException("Requested row is outside the image.");
|
||||||
}
|
}
|
||||||
if (!row || row.size() < width_) {
|
if (!row || row.size() < getWidth()) {
|
||||||
row = ArrayRef<char>(width_);
|
row = ArrayRef<char>(getWidth());
|
||||||
}
|
}
|
||||||
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
|
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
|
||||||
using namespace std;
|
using namespace std;
|
||||||
if (false) {
|
if (false) {
|
||||||
cerr << offset << " = "
|
cerr << offset << " = "
|
||||||
<< top_ << " " << left_ << " "
|
<< top_ << " " << left_ << " "
|
||||||
<< height_ << " " << width_ << " "
|
<< getHeight() << " " << getWidth() << " "
|
||||||
<< y << endl;
|
<< y << endl;
|
||||||
}
|
}
|
||||||
for (int x = 0; x < width_; x++) {
|
for (int x = 0; x < getWidth(); x++) {
|
||||||
row[x] = greyData_[offset];
|
row[x] = greyData_[offset];
|
||||||
offset += dataWidth_;
|
offset += dataWidth_;
|
||||||
}
|
}
|
||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayRef<char> GreyscaleRotatedLuminanceSource::getMatrix() {
|
ArrayRef<char> GreyscaleRotatedLuminanceSource::getMatrix() const {
|
||||||
ArrayRef<char> result (width_ * height_);
|
ArrayRef<char> result (getWidth() * getHeight());
|
||||||
for (int y = 0; y < height_; y++) {
|
for (int y = 0; y < getHeight(); y++) {
|
||||||
char* row = &result[y * width_];
|
char* row = &result[y * getWidth()];
|
||||||
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
|
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];
|
row[x] = greyData_[offset];
|
||||||
offset += dataWidth_;
|
offset += dataWidth_;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,37 +24,27 @@
|
||||||
#include <zxing/LuminanceSource.h>
|
#include <zxing/LuminanceSource.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
class GreyscaleRotatedLuminanceSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
class zxing::GreyscaleRotatedLuminanceSource : public LuminanceSource {
|
class GreyscaleRotatedLuminanceSource : public LuminanceSource {
|
||||||
private:
|
private:
|
||||||
|
typedef LuminanceSource Super;
|
||||||
ArrayRef<char> greyData_;
|
ArrayRef<char> greyData_;
|
||||||
const int dataWidth_;
|
const int dataWidth_;
|
||||||
const int left_;
|
const int left_;
|
||||||
const int top_;
|
const int top_;
|
||||||
const int width_;
|
|
||||||
const int height_;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GreyscaleRotatedLuminanceSource(ArrayRef<char> greyData, int dataWidth, int dataHeight,
|
GreyscaleRotatedLuminanceSource(ArrayRef<char> greyData, int dataWidth, int dataHeight,
|
||||||
int left, int top, int width, int height);
|
int left, int top, int width, int height);
|
||||||
|
|
||||||
ArrayRef<char> getRow(int y, ArrayRef<char> row);
|
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||||
ArrayRef<char> getMatrix();
|
ArrayRef<char> getMatrix() const;
|
||||||
|
|
||||||
bool isRotateSupported() const {
|
bool isRotateSupported() const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getWidth() const {
|
|
||||||
return width_;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getHeight() const {
|
|
||||||
return height_;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,27 +26,18 @@ using zxing::Ref;
|
||||||
using zxing::LuminanceSource;
|
using zxing::LuminanceSource;
|
||||||
using zxing::MagickBitmapSource;
|
using zxing::MagickBitmapSource;
|
||||||
|
|
||||||
MagickBitmapSource::MagickBitmapSource(Image& image) : image_(image) {
|
MagickBitmapSource::MagickBitmapSource(Image& image)
|
||||||
width = image.columns();
|
: Super(image.columns(), image.rows()), image_(image) {}
|
||||||
height = image.rows();
|
|
||||||
}
|
|
||||||
|
|
||||||
MagickBitmapSource::~MagickBitmapSource() {
|
MagickBitmapSource::~MagickBitmapSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int MagickBitmapSource::getWidth() const {
|
ArrayRef<char> MagickBitmapSource::getRow(int y, ArrayRef<char> row) const {
|
||||||
return width;
|
const int width = getWidth();
|
||||||
}
|
|
||||||
|
|
||||||
int MagickBitmapSource::getHeight() const {
|
|
||||||
return height;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayRef<char> MagickBitmapSource::getRow(int y, ArrayRef<char> row) {
|
|
||||||
const Magick::PixelPacket* pixel_cache =
|
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) {
|
if (!row || row->size() < width) {
|
||||||
row =ArrayRef<char>(width);
|
row =ArrayRef<char>(width);
|
||||||
}
|
}
|
||||||
|
@ -62,10 +53,10 @@ ArrayRef<char> MagickBitmapSource::getRow(int y, ArrayRef<char> row) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This is a more efficient implementation. */
|
/** 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);
|
const Magick::PixelPacket* pixel_cache = image_.getConstPixels(0, 0, width, height);
|
||||||
int width = getWidth();
|
|
||||||
int height = getHeight();
|
|
||||||
ArrayRef<char> matrix = ArrayRef<char>(width*height);
|
ArrayRef<char> matrix = ArrayRef<char>(width*height);
|
||||||
char* m = &matrix[0];
|
char* m = &matrix[0];
|
||||||
const Magick::PixelPacket* p = pixel_cache;
|
const Magick::PixelPacket* p = pixel_cache;
|
||||||
|
|
|
@ -21,28 +21,26 @@
|
||||||
#include <zxing/LuminanceSource.h>
|
#include <zxing/LuminanceSource.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
class MagickBitmapSource;
|
|
||||||
}
|
|
||||||
|
|
||||||
class zxing::MagickBitmapSource : public LuminanceSource {
|
class MagickBitmapSource : public LuminanceSource {
|
||||||
private:
|
private:
|
||||||
|
typedef LuminanceSource Super;
|
||||||
Magick::Image image_;
|
Magick::Image image_;
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MagickBitmapSource(Magick::Image& image);
|
MagickBitmapSource(Magick::Image& image);
|
||||||
|
|
||||||
~MagickBitmapSource();
|
~MagickBitmapSource();
|
||||||
|
|
||||||
int getWidth() const;
|
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||||
int getHeight() const;
|
ArrayRef<char> getMatrix() const;
|
||||||
ArrayRef<char> getRow(int y, ArrayRef<char> row);
|
|
||||||
ArrayRef<char> getMatrix();
|
|
||||||
bool isCropSupported() const;
|
bool isCropSupported() const;
|
||||||
Ref<LuminanceSource> crop(int left, int top, int width, int height);
|
Ref<LuminanceSource> crop(int left, int top, int width, int height);
|
||||||
bool isRotateSupported() const;
|
bool isRotateSupported() const;
|
||||||
Ref<LuminanceSource> rotateCounterClockwise();
|
Ref<LuminanceSource> rotateCounterClockwise();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* MAGICKMONOCHROMEBITMAPSOURCE_H_ */
|
#endif /* MAGICKMONOCHROMEBITMAPSOURCE_H_ */
|
||||||
|
|
Loading…
Reference in a new issue