LuminanceSource.cpp Example File
appdemos/qtws/QZXing/zxing/zxing/LuminanceSource.cpp
#include <sstream>
#include <zxing/LuminanceSource.h>
#include <zxing/InvertedLuminanceSource.h>
#include <zxing/common/IllegalArgumentException.h>
using zxing::Ref;
using zxing::LuminanceSource;
LuminanceSource::LuminanceSource(int width_, int height_) :width(width_), height(height_) {}
LuminanceSource::~LuminanceSource() {}
bool LuminanceSource::isCropSupported() const {
return false;
}
Ref<LuminanceSource> LuminanceSource::crop(int, int, int, int) const {
throw IllegalArgumentException("This luminance source does not support cropping.");
}
bool LuminanceSource::isRotateSupported() const {
return false;
}
Ref<LuminanceSource> LuminanceSource::rotateCounterClockwise() const {
throw IllegalArgumentException("This luminance source does not support rotation.");
}
Ref<zxing::LuminanceSource> LuminanceSource::rotateCounterClockwise45() const
{
throw IllegalArgumentException("This luminance source does not support rotation 45.");
}
LuminanceSource::operator std::string() const {
ArrayRef<byte> row;
std::ostringstream oss;
for (int y = 0; y < getHeight(); y++) {
row = getRow(y, row);
for (int x = 0; x < getWidth(); x++) {
int luminance = row[x] & 0xFF;
char c;
if (luminance < 0x40) {
c = '#';
} else if (luminance < 0x80) {
c = '+';
} else if (luminance < 0xC0) {
c = '.';
} else {
c = ' ';
}
oss << c;
}
oss << '\n';
}
return oss.str();
}
Ref<LuminanceSource> LuminanceSource::invert() const {
return Ref<LuminanceSource>
(new InvertedLuminanceSource(Ref<LuminanceSource>(const_cast<LuminanceSource*>(this))));
}