GreyscaleRotatedLuminanceSource.cpp Example File
appdemos/qtws/QZXing/zxing/zxing/common/GreyscaleRotatedLuminanceSource.cpp
#include <zxing/common/GreyscaleRotatedLuminanceSource.h>
#include <zxing/common/IllegalArgumentException.h>
using zxing::ArrayRef;
namespace zxing {
GreyscaleRotatedLuminanceSource::
GreyscaleRotatedLuminanceSource(ArrayRef<byte> greyData,
int dataWidth, int dataHeight,
int left, int top,
int width, int height)
: Super(width, height),
greyData_(greyData),
dataWidth_(dataWidth),
left_(left), top_(top) {
if (left + width > dataHeight || top + height > dataWidth) {
throw IllegalArgumentException("Crop rectangle does not fit within image data.");
}
}
ArrayRef<byte>
GreyscaleRotatedLuminanceSource::getRow(int y, ArrayRef<byte> row) const {
if (y < 0 || y >= getHeight()) {
throw IllegalArgumentException("Requested row is outside the image.");
}
if (!row || row->size() < getWidth()) {
row = ArrayRef<byte>(getWidth());
}
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
using namespace std;
if (false) {
cerr << offset << " = "
<< top_ << " " << left_ << " "
<< getHeight() << " " << getWidth() << " "
<< y << endl;
}
for (int x = 0; x < getWidth(); x++) {
row[x] = greyData_[offset];
offset += dataWidth_;
}
return row;
}
ArrayRef<byte> GreyscaleRotatedLuminanceSource::getMatrix() const {
ArrayRef<byte> result (getWidth() * getHeight());
for (int y = 0; y < getHeight(); y++) {
byte* row = &result[y * getWidth()];
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
for (int x = 0; x < getWidth(); x++) {
row[x] = greyData_[offset];
offset += dataWidth_;
}
}
return result;
}
}