mirror of
https://github.com/status-im/qzxing.git
synced 2025-02-15 12:26:25 +00:00
completed the transition from char to byte.
This commit is contained in:
parent
53c80b3313
commit
f6bf265df7
@ -69,7 +69,7 @@ QImage CameraImageWrapper::getOriginalImage()
|
||||
return *image;
|
||||
}
|
||||
|
||||
ArrayRef<char> CameraImageWrapper::getRow(int y, ArrayRef<char> row) const
|
||||
ArrayRef<byte> CameraImageWrapper::getRow(int y, ArrayRef<byte> row) const
|
||||
{
|
||||
if(delegate)
|
||||
return delegate->getRow(y, row);
|
||||
@ -77,7 +77,7 @@ ArrayRef<char> CameraImageWrapper::getRow(int y, ArrayRef<char> row) const
|
||||
return getRowP(y, row);
|
||||
}
|
||||
|
||||
ArrayRef<char> CameraImageWrapper::getMatrix() const
|
||||
ArrayRef<byte> CameraImageWrapper::getMatrix() const
|
||||
{
|
||||
if(delegate)
|
||||
return delegate->getMatrix();
|
||||
@ -125,12 +125,12 @@ Ref<LuminanceSource> CameraImageWrapper::rotateCounterClockwise() const
|
||||
return LuminanceSource::rotateCounterClockwise();
|
||||
}
|
||||
|
||||
ArrayRef<char> CameraImageWrapper::getRowP(int y, ArrayRef<char> row) const
|
||||
ArrayRef<byte> CameraImageWrapper::getRowP(int y, ArrayRef<byte> row) const
|
||||
{
|
||||
int width = getWidth();
|
||||
|
||||
if (row->size() != width)
|
||||
row.reset(ArrayRef<char>(width));
|
||||
row.reset(ArrayRef<byte>(width));
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
@ -144,15 +144,15 @@ ArrayRef<char> CameraImageWrapper::getRowP(int y, ArrayRef<char> row) const
|
||||
return row;
|
||||
}
|
||||
|
||||
ArrayRef<char> CameraImageWrapper::getMatrixP() const
|
||||
ArrayRef<byte> CameraImageWrapper::getMatrixP() const
|
||||
{
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
|
||||
ArrayRef<char> tmpRow(0);
|
||||
ArrayRef<char> arr(width*height);
|
||||
ArrayRef<byte> tmpRow(0);
|
||||
ArrayRef<byte> arr(width*height);
|
||||
|
||||
char* m = &arr[0];
|
||||
byte* m = &arr[0];
|
||||
|
||||
for(int y=0; y<height; y++)
|
||||
{
|
||||
|
@ -20,8 +20,8 @@ public:
|
||||
QImage getOriginalImage();
|
||||
Ref<GreyscaleLuminanceSource> getDelegate() { return delegate; }
|
||||
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrix() const;
|
||||
ArrayRef<byte> getRow(int y, ArrayRef<byte> row) const;
|
||||
ArrayRef<byte> getMatrix() const;
|
||||
|
||||
bool isCropSupported() const;
|
||||
Ref<LuminanceSource> crop(int left, int top, int width, int height) const;
|
||||
@ -30,8 +30,8 @@ public:
|
||||
Ref<LuminanceSource> rotateCounterClockwise() const;
|
||||
|
||||
private:
|
||||
ArrayRef<char> getRowP(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrixP() const;
|
||||
ArrayRef<byte> getRowP(int y, ArrayRef<byte> row) const;
|
||||
ArrayRef<byte> getMatrixP() const;
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0))
|
||||
QImage* grayScaleImage(const QImage *origin);
|
||||
#endif
|
||||
|
@ -22,12 +22,13 @@ using zxing::boolean;
|
||||
using zxing::Ref;
|
||||
using zxing::ArrayRef;
|
||||
using zxing::LuminanceSource;
|
||||
using zxing::InvertedLuminanceSource;
|
||||
|
||||
namespace zxing {
|
||||
|
||||
InvertedLuminanceSource::InvertedLuminanceSource(Ref<LuminanceSource> const& delegate_)
|
||||
: Super(delegate_->getWidth(), delegate_->getHeight()), delegate(delegate_) {}
|
||||
|
||||
ArrayRef<char> InvertedLuminanceSource::getRow(int y, ArrayRef<char> row) const {
|
||||
ArrayRef<byte> InvertedLuminanceSource::getRow(int y, ArrayRef<byte> row) const {
|
||||
row = delegate->getRow(y, row);
|
||||
int width = getWidth();
|
||||
for (int i = 0; i < width; i++) {
|
||||
@ -36,10 +37,10 @@ ArrayRef<char> InvertedLuminanceSource::getRow(int y, ArrayRef<char> row) const
|
||||
return row;
|
||||
}
|
||||
|
||||
ArrayRef<char> InvertedLuminanceSource::getMatrix() const {
|
||||
ArrayRef<char> matrix = delegate->getMatrix();
|
||||
ArrayRef<byte> InvertedLuminanceSource::getMatrix() const {
|
||||
ArrayRef<byte> matrix = delegate->getMatrix();
|
||||
int length = getWidth() * getHeight();
|
||||
ArrayRef<char> invertedMatrix(length);
|
||||
ArrayRef<byte> invertedMatrix(length);
|
||||
for (int i = 0; i < length; i++) {
|
||||
invertedMatrix[i] = (byte) (255 - (matrix[i] & 0xFF));
|
||||
}
|
||||
@ -66,3 +67,4 @@ Ref<LuminanceSource> InvertedLuminanceSource::rotateCounterClockwise() const {
|
||||
return Ref<LuminanceSource>(new InvertedLuminanceSource(delegate->rotateCounterClockwise()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,8 +30,8 @@ private:
|
||||
public:
|
||||
InvertedLuminanceSource(Ref<LuminanceSource> const&);
|
||||
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrix() const;
|
||||
ArrayRef<byte> getRow(int y, ArrayRef<byte> row) const;
|
||||
ArrayRef<byte> getMatrix() const;
|
||||
|
||||
boolean isCropSupported() const;
|
||||
Ref<LuminanceSource> crop(int left, int top, int width, int height) const;
|
||||
|
@ -52,7 +52,7 @@ Ref<zxing::LuminanceSource> LuminanceSource::rotateCounterClockwise45() const
|
||||
}
|
||||
|
||||
LuminanceSource::operator std::string() const {
|
||||
ArrayRef<char> row;
|
||||
ArrayRef<byte> row;
|
||||
std::ostringstream oss;
|
||||
for (int y = 0; y < getHeight(); y++) {
|
||||
row = getRow(y, row);
|
||||
|
@ -40,8 +40,8 @@ class LuminanceSource : public Counted {
|
||||
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) const = 0;
|
||||
virtual ArrayRef<char> getMatrix() const = 0;
|
||||
virtual ArrayRef<byte> getRow(int y, ArrayRef<byte> row) const = 0;
|
||||
virtual ArrayRef<byte> getMatrix() const = 0;
|
||||
|
||||
virtual bool isCropSupported() const;
|
||||
virtual Ref<LuminanceSource> crop(int left, int top, int width, int height) const;
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include <zxing/NotFoundException.h>
|
||||
#include <zxing/common/Array.h>
|
||||
|
||||
using zxing::GlobalHistogramBinarizer;
|
||||
using zxing::Binarizer;
|
||||
using zxing::ArrayRef;
|
||||
using zxing::Ref;
|
||||
@ -32,12 +31,12 @@ using zxing::BitMatrix;
|
||||
// VC++
|
||||
using zxing::LuminanceSource;
|
||||
|
||||
namespace {
|
||||
namespace zxing {
|
||||
|
||||
const int LUMINANCE_BITS = 5;
|
||||
const int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS;
|
||||
const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS;
|
||||
const ArrayRef<char> EMPTY (0);
|
||||
}
|
||||
const ArrayRef<byte> EMPTY (0);
|
||||
|
||||
GlobalHistogramBinarizer::GlobalHistogramBinarizer(Ref<LuminanceSource> source)
|
||||
: Binarizer(source), luminances(EMPTY), buckets(LUMINANCE_BUCKETS) {}
|
||||
@ -46,7 +45,7 @@ GlobalHistogramBinarizer::~GlobalHistogramBinarizer() {}
|
||||
|
||||
void GlobalHistogramBinarizer::initArrays(int luminanceSize) {
|
||||
if (luminances->size() < luminanceSize) {
|
||||
luminances = ArrayRef<char>(luminanceSize);
|
||||
luminances = ArrayRef<byte>(luminanceSize);
|
||||
}
|
||||
// for (int x = 0; x < LUMINANCE_BUCKETS; x++) {
|
||||
// buckets[x] = 0;
|
||||
@ -65,7 +64,7 @@ Ref<BitArray> GlobalHistogramBinarizer::getBlackRow(int y, Ref<BitArray> row) {
|
||||
}
|
||||
|
||||
initArrays(width);
|
||||
ArrayRef<char> localLuminances = source.getRow(y, luminances);
|
||||
ArrayRef<byte> localLuminances = source.getRow(y, luminances);
|
||||
if (false) {
|
||||
std::cerr << "gbr " << y << " r ";
|
||||
for(int i=0, e=localLuminances->size(); i < e; ++i) {
|
||||
@ -109,7 +108,7 @@ Ref<BitMatrix> GlobalHistogramBinarizer::getBlackMatrix() {
|
||||
ArrayRef<int> localBuckets = buckets;
|
||||
for (int y = 1; y < 5; y++) {
|
||||
int row = height * y / 5;
|
||||
ArrayRef<char> localLuminances = source.getRow(row, luminances);
|
||||
ArrayRef<byte> localLuminances = source.getRow(row, luminances);
|
||||
int right = (width << 2) / 5;
|
||||
for (int x = width / 5; x < right; x++) {
|
||||
int pixel = localLuminances[x] & 0xff;
|
||||
@ -119,7 +118,7 @@ Ref<BitMatrix> GlobalHistogramBinarizer::getBlackMatrix() {
|
||||
|
||||
int blackPoint = estimateBlackPoint(localBuckets);
|
||||
|
||||
ArrayRef<char> localLuminances = source.getMatrix();
|
||||
ArrayRef<byte> localLuminances = source.getMatrix();
|
||||
for (int y = 0; y < height; y++) {
|
||||
int offset = y * width;
|
||||
for (int x = 0; x < width; x++) {
|
||||
@ -211,3 +210,5 @@ int GlobalHistogramBinarizer::estimateBlackPoint(ArrayRef<int> const& buckets) {
|
||||
Ref<Binarizer> GlobalHistogramBinarizer::createBinarizer(Ref<LuminanceSource> source) {
|
||||
return Ref<Binarizer> (new GlobalHistogramBinarizer(source));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ namespace zxing {
|
||||
|
||||
class GlobalHistogramBinarizer : public Binarizer {
|
||||
private:
|
||||
ArrayRef<char> luminances;
|
||||
ArrayRef<byte> luminances;
|
||||
ArrayRef<int> buckets;
|
||||
public:
|
||||
GlobalHistogramBinarizer(Ref<LuminanceSource> source);
|
||||
|
@ -25,10 +25,11 @@
|
||||
using zxing::Ref;
|
||||
using zxing::ArrayRef;
|
||||
using zxing::LuminanceSource;
|
||||
using zxing::GreyscaleLuminanceSource;
|
||||
|
||||
namespace zxing {
|
||||
|
||||
GreyscaleLuminanceSource::
|
||||
GreyscaleLuminanceSource(ArrayRef<char> greyData,
|
||||
GreyscaleLuminanceSource(ArrayRef<byte> greyData,
|
||||
int dataWidth, int dataHeight,
|
||||
int left, int top,
|
||||
int width, int height)
|
||||
@ -42,13 +43,13 @@ GreyscaleLuminanceSource(ArrayRef<char> greyData,
|
||||
}
|
||||
}
|
||||
|
||||
ArrayRef<char> GreyscaleLuminanceSource::getRow(int y, ArrayRef<char> row) const {
|
||||
ArrayRef<byte> GreyscaleLuminanceSource::getRow(int y, ArrayRef<byte> row) const {
|
||||
if (y < 0 || y >= this->getHeight()) {
|
||||
throw IllegalArgumentException("Requested row is outside the image.");
|
||||
}
|
||||
int width = getWidth();
|
||||
if (!row || row->size() < width) {
|
||||
ArrayRef<char> temp (width);
|
||||
ArrayRef<byte> temp (width);
|
||||
row = temp;
|
||||
}
|
||||
int offset = (y + top_) * dataWidth_ + left_;
|
||||
@ -56,9 +57,9 @@ ArrayRef<char> GreyscaleLuminanceSource::getRow(int y, ArrayRef<char> row) const
|
||||
return row;
|
||||
}
|
||||
|
||||
ArrayRef<char> GreyscaleLuminanceSource::getMatrix() const {
|
||||
ArrayRef<byte> GreyscaleLuminanceSource::getMatrix() const {
|
||||
int size = getWidth() * getHeight();
|
||||
ArrayRef<char> result (size);
|
||||
ArrayRef<byte> result (size);
|
||||
if (left_ == 0 && top_ == 0 && dataWidth_ == getWidth() && dataHeight_ == getHeight()) {
|
||||
memcpy(&result[0], &greyData_[0], size);
|
||||
} else {
|
||||
@ -78,3 +79,5 @@ Ref<LuminanceSource> GreyscaleLuminanceSource::rotateCounterClockwise() const {
|
||||
top_, left_, getHeight(), getWidth()));
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,18 +28,18 @@ class GreyscaleLuminanceSource : public LuminanceSource {
|
||||
|
||||
private:
|
||||
typedef LuminanceSource Super;
|
||||
ArrayRef<char> greyData_;
|
||||
ArrayRef<byte> greyData_;
|
||||
const int dataWidth_;
|
||||
const int dataHeight_;
|
||||
const int left_;
|
||||
const int top_;
|
||||
|
||||
public:
|
||||
GreyscaleLuminanceSource(ArrayRef<char> greyData, int dataWidth, int dataHeight, int left,
|
||||
GreyscaleLuminanceSource(ArrayRef<byte> greyData, int dataWidth, int dataHeight, int left,
|
||||
int top, int width, int height);
|
||||
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrix() const;
|
||||
ArrayRef<byte> getRow(int y, ArrayRef<byte> row) const;
|
||||
ArrayRef<byte> getMatrix() const;
|
||||
|
||||
bool isRotateSupported() const {
|
||||
return true;
|
||||
|
@ -23,13 +23,14 @@
|
||||
#include <zxing/common/IllegalArgumentException.h>
|
||||
|
||||
using zxing::ArrayRef;
|
||||
using zxing::GreyscaleRotatedLuminanceSource;
|
||||
|
||||
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(ArrayRef<char> greyData,
|
||||
GreyscaleRotatedLuminanceSource(ArrayRef<byte> greyData,
|
||||
int dataWidth, int dataHeight,
|
||||
int left, int top,
|
||||
int width, int height)
|
||||
@ -44,13 +45,13 @@ 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) const {
|
||||
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<char>(getWidth());
|
||||
row = ArrayRef<byte>(getWidth());
|
||||
}
|
||||
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
|
||||
using namespace std;
|
||||
@ -67,10 +68,10 @@ GreyscaleRotatedLuminanceSource::getRow(int y, ArrayRef<char> row) const {
|
||||
return row;
|
||||
}
|
||||
|
||||
ArrayRef<char> GreyscaleRotatedLuminanceSource::getMatrix() const {
|
||||
ArrayRef<char> result (getWidth() * getHeight());
|
||||
ArrayRef<byte> GreyscaleRotatedLuminanceSource::getMatrix() const {
|
||||
ArrayRef<byte> result (getWidth() * getHeight());
|
||||
for (int y = 0; y < getHeight(); y++) {
|
||||
char* row = &result[y * getWidth()];
|
||||
byte* row = &result[y * getWidth()];
|
||||
int offset = (left_ * dataWidth_) + (dataWidth_ - 1 - (y + top_));
|
||||
for (int x = 0; x < getWidth(); x++) {
|
||||
row[x] = greyData_[offset];
|
||||
@ -79,3 +80,5 @@ ArrayRef<char> GreyscaleRotatedLuminanceSource::getMatrix() const {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,17 +28,17 @@ namespace zxing {
|
||||
class GreyscaleRotatedLuminanceSource : public LuminanceSource {
|
||||
private:
|
||||
typedef LuminanceSource Super;
|
||||
ArrayRef<char> greyData_;
|
||||
ArrayRef<byte> greyData_;
|
||||
const int dataWidth_;
|
||||
const int left_;
|
||||
const int top_;
|
||||
|
||||
public:
|
||||
GreyscaleRotatedLuminanceSource(ArrayRef<char> greyData, int dataWidth, int dataHeight,
|
||||
GreyscaleRotatedLuminanceSource(ArrayRef<byte> greyData, int dataWidth, int dataHeight,
|
||||
int left, int top, int width, int height);
|
||||
|
||||
ArrayRef<char> getRow(int y, ArrayRef<char> row) const;
|
||||
ArrayRef<char> getMatrix() const;
|
||||
ArrayRef<byte> getRow(int y, ArrayRef<byte> row) const;
|
||||
ArrayRef<byte> getMatrix() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ Ref<BitMatrix> HybridBinarizer::getBlackMatrix() {
|
||||
int width = source.getWidth();
|
||||
int height = source.getHeight();
|
||||
if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) {
|
||||
ArrayRef<char> luminances = source.getMatrix();
|
||||
ArrayRef<byte> luminances = source.getMatrix();
|
||||
int subWidth = width >> BLOCK_SIZE_POWER;
|
||||
if ((width & BLOCK_SIZE_MASK) != 0) {
|
||||
subWidth++;
|
||||
@ -94,7 +94,7 @@ namespace {
|
||||
}
|
||||
|
||||
void
|
||||
HybridBinarizer::calculateThresholdForBlock(ArrayRef<char> luminances,
|
||||
HybridBinarizer::calculateThresholdForBlock(ArrayRef<byte> luminances,
|
||||
int subWidth,
|
||||
int subHeight,
|
||||
int width,
|
||||
@ -130,7 +130,7 @@ HybridBinarizer::calculateThresholdForBlock(ArrayRef<char> luminances,
|
||||
}
|
||||
}
|
||||
|
||||
void HybridBinarizer::thresholdBlock(ArrayRef<char> luminances,
|
||||
void HybridBinarizer::thresholdBlock(ArrayRef<byte> luminances,
|
||||
int xoffset,
|
||||
int yoffset,
|
||||
int threshold,
|
||||
@ -157,7 +157,7 @@ namespace {
|
||||
}
|
||||
|
||||
|
||||
ArrayRef<int> HybridBinarizer::calculateBlackPoints(ArrayRef<char> luminances,
|
||||
ArrayRef<int> HybridBinarizer::calculateBlackPoints(ArrayRef<byte> luminances,
|
||||
int subWidth,
|
||||
int subHeight,
|
||||
int width,
|
||||
|
@ -42,19 +42,19 @@ namespace zxing {
|
||||
private:
|
||||
// We'll be using one-D arrays because C++ can't dynamically allocate 2D
|
||||
// arrays
|
||||
ArrayRef<int> calculateBlackPoints(ArrayRef<char> luminances,
|
||||
ArrayRef<int> calculateBlackPoints(ArrayRef<byte> luminances,
|
||||
int subWidth,
|
||||
int subHeight,
|
||||
int width,
|
||||
int height);
|
||||
void calculateThresholdForBlock(ArrayRef<char> luminances,
|
||||
void calculateThresholdForBlock(ArrayRef<byte> luminances,
|
||||
int subWidth,
|
||||
int subHeight,
|
||||
int width,
|
||||
int height,
|
||||
ArrayRef<int> blackPoints,
|
||||
Ref<BitMatrix> const& matrix);
|
||||
void thresholdBlock(ArrayRef<char>luminances,
|
||||
void thresholdBlock(ArrayRef<byte>luminances,
|
||||
int xoffset,
|
||||
int yoffset,
|
||||
int threshold,
|
||||
|
@ -41,7 +41,7 @@ private:
|
||||
public:
|
||||
BitMatrixParser(Ref<BitMatrix> bitMatrix);
|
||||
Ref<Version> readVersion(Ref<BitMatrix> bitMatrix);
|
||||
ArrayRef<char> readCodewords();
|
||||
ArrayRef<byte> readCodewords();
|
||||
bool readModule(int row, int column, int numRows, int numColumns);
|
||||
|
||||
private:
|
||||
|
@ -32,15 +32,15 @@ namespace datamatrix {
|
||||
class DataBlock : public Counted {
|
||||
private:
|
||||
int numDataCodewords_;
|
||||
ArrayRef<char> codewords_;
|
||||
ArrayRef<byte> codewords_;
|
||||
|
||||
DataBlock(int numDataCodewords, ArrayRef<char> codewords);
|
||||
DataBlock(int numDataCodewords, ArrayRef<byte> codewords);
|
||||
|
||||
public:
|
||||
static std::vector<Ref<DataBlock> > getDataBlocks(ArrayRef<char> rawCodewords, Version *version);
|
||||
static std::vector<Ref<DataBlock> > getDataBlocks(ArrayRef<byte> rawCodewords, Version *version);
|
||||
|
||||
int getNumDataCodewords();
|
||||
ArrayRef<char> getCodewords();
|
||||
ArrayRef<byte> getCodewords();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ Ref<Version> BitMatrixParser::readVersion(Ref<BitMatrix> bitMatrix) {
|
||||
throw ReaderException("Couldn't decode version");
|
||||
}
|
||||
|
||||
ArrayRef<char> BitMatrixParser::readCodewords() {
|
||||
ArrayRef<char> result(parsedVersion_->getTotalCodewords());
|
||||
ArrayRef<byte> BitMatrixParser::readCodewords() {
|
||||
ArrayRef<byte> result(parsedVersion_->getTotalCodewords());
|
||||
int resultOffset = 0;
|
||||
int row = 4;
|
||||
int column = 0;
|
||||
@ -75,22 +75,22 @@ ArrayRef<char> BitMatrixParser::readCodewords() {
|
||||
do {
|
||||
// Check the four corner cases
|
||||
if ((row == numRows) && (column == 0) && !corner1Read) {
|
||||
result[resultOffset++] = (char) readCorner1(numRows, numColumns);
|
||||
result[resultOffset++] = (byte) readCorner1(numRows, numColumns);
|
||||
row -= 2;
|
||||
column +=2;
|
||||
corner1Read = true;
|
||||
} else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x03) != 0) && !corner2Read) {
|
||||
result[resultOffset++] = (char) readCorner2(numRows, numColumns);
|
||||
result[resultOffset++] = (byte) readCorner2(numRows, numColumns);
|
||||
row -= 2;
|
||||
column +=2;
|
||||
corner2Read = true;
|
||||
} else if ((row == numRows+4) && (column == 2) && ((numColumns & 0x07) == 0) && !corner3Read) {
|
||||
result[resultOffset++] = (char) readCorner3(numRows, numColumns);
|
||||
result[resultOffset++] = (byte) readCorner3(numRows, numColumns);
|
||||
row -= 2;
|
||||
column +=2;
|
||||
corner3Read = true;
|
||||
} else if ((row == numRows-2) && (column == 0) && ((numColumns & 0x07) == 4) && !corner4Read) {
|
||||
result[resultOffset++] = (char) readCorner4(numRows, numColumns);
|
||||
result[resultOffset++] = (byte) readCorner4(numRows, numColumns);
|
||||
row -= 2;
|
||||
column +=2;
|
||||
corner4Read = true;
|
||||
@ -98,7 +98,7 @@ ArrayRef<char> BitMatrixParser::readCodewords() {
|
||||
// Sweep upward diagonally to the right
|
||||
do {
|
||||
if ((row < numRows) && (column >= 0) && !readBitMatrix_->get(column, row)) {
|
||||
result[resultOffset++] = (char) readUtah(row, column, numRows, numColumns);
|
||||
result[resultOffset++] = (byte) readUtah(row, column, numRows, numColumns);
|
||||
}
|
||||
row -= 2;
|
||||
column +=2;
|
||||
@ -109,7 +109,7 @@ ArrayRef<char> BitMatrixParser::readCodewords() {
|
||||
// Sweep downward diagonally to the left
|
||||
do {
|
||||
if ((row >= 0) && (column < numColumns) && !readBitMatrix_->get(column, row)) {
|
||||
result[resultOffset++] = (char) readUtah(row, column, numRows, numColumns);
|
||||
result[resultOffset++] = (byte) readUtah(row, column, numRows, numColumns);
|
||||
}
|
||||
row += 2;
|
||||
column -=2;
|
||||
|
@ -26,7 +26,7 @@ namespace datamatrix {
|
||||
|
||||
using namespace std;
|
||||
|
||||
DataBlock::DataBlock(int numDataCodewords, ArrayRef<char> codewords) :
|
||||
DataBlock::DataBlock(int numDataCodewords, ArrayRef<byte> codewords) :
|
||||
numDataCodewords_(numDataCodewords), codewords_(codewords) {
|
||||
}
|
||||
|
||||
@ -34,11 +34,11 @@ int DataBlock::getNumDataCodewords() {
|
||||
return numDataCodewords_;
|
||||
}
|
||||
|
||||
ArrayRef<char> DataBlock::getCodewords() {
|
||||
ArrayRef<byte> DataBlock::getCodewords() {
|
||||
return codewords_;
|
||||
}
|
||||
|
||||
std::vector<Ref<DataBlock> > DataBlock::getDataBlocks(ArrayRef<char> rawCodewords, Version *version) {
|
||||
std::vector<Ref<DataBlock> > DataBlock::getDataBlocks(ArrayRef<byte> rawCodewords, Version *version) {
|
||||
// Figure out the number and size of data blocks used by this version and
|
||||
// error correction level
|
||||
ECBlocks* ecBlocks = version->getECBlocks();
|
||||
@ -58,7 +58,7 @@ std::vector<Ref<DataBlock> > DataBlock::getDataBlocks(ArrayRef<char> rawCodeword
|
||||
for (int i = 0; i < ecBlock->getCount(); i++) {
|
||||
int numDataCodewords = ecBlock->getDataCodewords();
|
||||
int numBlockCodewords = ecBlocks->getECCodewords() + numDataCodewords;
|
||||
ArrayRef<char> buffer(numBlockCodewords);
|
||||
ArrayRef<byte> buffer(numBlockCodewords);
|
||||
Ref<DataBlock> blockRef(new DataBlock(numDataCodewords, buffer));
|
||||
result[numResultBlocks++] = blockRef;
|
||||
}
|
||||
|
@ -48,14 +48,14 @@ const char DecodedBitStreamParser::TEXT_BASIC_SET_CHARS[] = {
|
||||
|
||||
const char DecodedBitStreamParser::TEXT_SHIFT3_SET_CHARS[] = {
|
||||
'\'', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
|
||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (char) 127
|
||||
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '{', '|', '}', '~', (byte) 127
|
||||
};
|
||||
|
||||
Ref<DecoderResult> DecodedBitStreamParser::decode(ArrayRef<byte> bytes) {
|
||||
Ref<BitSource> bits(new BitSource(bytes));
|
||||
ostringstream result;
|
||||
ostringstream resultTrailer;
|
||||
vector<char> byteSegments;
|
||||
vector<byte> byteSegments;
|
||||
int mode = ASCII_ENCODE;
|
||||
do {
|
||||
if (mode == ASCII_ENCODE) {
|
||||
@ -102,7 +102,7 @@ int DecodedBitStreamParser::decodeAsciiSegment(Ref<BitSource> bits, ostringstrea
|
||||
} else if (oneByte <= 128) { // ASCII data (ASCII value + 1)
|
||||
oneByte = upperShift ? (oneByte + 128) : oneByte;
|
||||
// upperShift = false;
|
||||
result << (char) (oneByte - 1);
|
||||
result << (byte) (oneByte - 1);
|
||||
return ASCII_ENCODE;
|
||||
} else if (oneByte == 129) { // Pad
|
||||
return PAD_ENCODE;
|
||||
@ -117,7 +117,7 @@ int DecodedBitStreamParser::decodeAsciiSegment(Ref<BitSource> bits, ostringstrea
|
||||
} else if (oneByte == 231) { // Latch to Base 256 encodation
|
||||
return BASE256_ENCODE;
|
||||
} else if (oneByte == 232) { // FNC1
|
||||
result << ((char) 29); // translate as ASCII 29
|
||||
result << ((byte) 29); // translate as ASCII 29
|
||||
} else if (oneByte == 233 || oneByte == 234) {
|
||||
// Structured Append, Reader Programming
|
||||
// Ignore these symbols for now
|
||||
@ -178,7 +178,7 @@ void DecodedBitStreamParser::decodeC40Segment(Ref<BitSource> bits, ostringstream
|
||||
shift = cValue + 1;
|
||||
} else {
|
||||
if (upperShift) {
|
||||
result << (char) (C40_BASIC_SET_CHARS[cValue] + 128);
|
||||
result << (byte) (C40_BASIC_SET_CHARS[cValue] + 128);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result << C40_BASIC_SET_CHARS[cValue];
|
||||
@ -187,23 +187,23 @@ void DecodedBitStreamParser::decodeC40Segment(Ref<BitSource> bits, ostringstream
|
||||
break;
|
||||
case 1:
|
||||
if (upperShift) {
|
||||
result << (char) (cValue + 128);
|
||||
result << (byte) (cValue + 128);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result << (char) cValue;
|
||||
result << (byte) cValue;
|
||||
}
|
||||
shift = 0;
|
||||
break;
|
||||
case 2:
|
||||
if (cValue < 27) {
|
||||
if (upperShift) {
|
||||
result << (char) (C40_SHIFT2_SET_CHARS[cValue] + 128);
|
||||
result << (byte) (C40_SHIFT2_SET_CHARS[cValue] + 128);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result << C40_SHIFT2_SET_CHARS[cValue];
|
||||
}
|
||||
} else if (cValue == 27) { // FNC1
|
||||
result << ((char) 29); // translate as ASCII 29
|
||||
result << ((byte) 29); // translate as ASCII 29
|
||||
} else if (cValue == 30) { // Upper Shift
|
||||
upperShift = true;
|
||||
} else {
|
||||
@ -213,10 +213,10 @@ void DecodedBitStreamParser::decodeC40Segment(Ref<BitSource> bits, ostringstream
|
||||
break;
|
||||
case 3:
|
||||
if (upperShift) {
|
||||
result << (char) (cValue + 224);
|
||||
result << (byte) (cValue + 224);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result << (char) (cValue + 96);
|
||||
result << (byte) (cValue + 96);
|
||||
}
|
||||
shift = 0;
|
||||
break;
|
||||
@ -255,7 +255,7 @@ void DecodedBitStreamParser::decodeTextSegment(Ref<BitSource> bits, ostringstrea
|
||||
shift = cValue + 1;
|
||||
} else {
|
||||
if (upperShift) {
|
||||
result << (char) (TEXT_BASIC_SET_CHARS[cValue] + 128);
|
||||
result << (byte) (TEXT_BASIC_SET_CHARS[cValue] + 128);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result << (TEXT_BASIC_SET_CHARS[cValue]);
|
||||
@ -264,10 +264,10 @@ void DecodedBitStreamParser::decodeTextSegment(Ref<BitSource> bits, ostringstrea
|
||||
break;
|
||||
case 1:
|
||||
if (upperShift) {
|
||||
result << (char) (cValue + 128);
|
||||
result << (byte) (cValue + 128);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result << (char) (cValue);
|
||||
result << (byte) (cValue);
|
||||
}
|
||||
shift = 0;
|
||||
break;
|
||||
@ -275,13 +275,13 @@ void DecodedBitStreamParser::decodeTextSegment(Ref<BitSource> bits, ostringstrea
|
||||
// Shift 2 for Text is the same encoding as C40
|
||||
if (cValue < 27) {
|
||||
if (upperShift) {
|
||||
result << (char) (C40_SHIFT2_SET_CHARS[cValue] + 128);
|
||||
result << (byte) (C40_SHIFT2_SET_CHARS[cValue] + 128);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result << (C40_SHIFT2_SET_CHARS[cValue]);
|
||||
}
|
||||
} else if (cValue == 27) { // FNC1
|
||||
result << ((char) 29); // translate as ASCII 29
|
||||
result << ((byte) 29); // translate as ASCII 29
|
||||
} else if (cValue == 30) { // Upper Shift
|
||||
upperShift = true;
|
||||
} else {
|
||||
@ -291,7 +291,7 @@ void DecodedBitStreamParser::decodeTextSegment(Ref<BitSource> bits, ostringstrea
|
||||
break;
|
||||
case 3:
|
||||
if (upperShift) {
|
||||
result << (char) (TEXT_SHIFT3_SET_CHARS[cValue] + 128);
|
||||
result << (byte) (TEXT_SHIFT3_SET_CHARS[cValue] + 128);
|
||||
upperShift = false;
|
||||
} else {
|
||||
result << (TEXT_SHIFT3_SET_CHARS[cValue]);
|
||||
@ -333,9 +333,9 @@ void DecodedBitStreamParser::decodeAnsiX12Segment(Ref<BitSource> bits, ostringst
|
||||
} else if (cValue == 3) { // space
|
||||
result << ' ';
|
||||
} else if (cValue < 14) { // 0 - 9
|
||||
result << (char) (cValue + 44);
|
||||
result << (byte) (cValue + 44);
|
||||
} else if (cValue < 40) { // A - Z
|
||||
result << (char) (cValue + 51);
|
||||
result << (byte) (cValue + 51);
|
||||
} else {
|
||||
throw FormatException("decodeAnsiX12Segment: no case");
|
||||
}
|
||||
@ -376,12 +376,12 @@ void DecodedBitStreamParser::decodeEdifactSegment(Ref<BitSource> bits, ostringst
|
||||
if ((edifactValue & 0x20) == 0) { // no 1 in the leading (6th) bit
|
||||
edifactValue |= 0x40; // Add a leading 01 to the 6 bit binary value
|
||||
}
|
||||
result << (char)(edifactValue);
|
||||
result << (byte)(edifactValue);
|
||||
}
|
||||
} while (bits->available() > 0);
|
||||
}
|
||||
|
||||
void DecodedBitStreamParser::decodeBase256Segment(Ref<BitSource> bits, ostringstream& result, vector<char> byteSegments) {
|
||||
void DecodedBitStreamParser::decodeBase256Segment(Ref<BitSource> bits, ostringstream& result, vector<byte> byteSegments) {
|
||||
// Figure out how long the Base 256 Segment is.
|
||||
int codewordPosition = 1 + bits->getByteOffset(); // position is 1-indexed
|
||||
int d1 = unrandomize255State(bits->readBits(8), codewordPosition++);
|
||||
@ -408,7 +408,7 @@ void DecodedBitStreamParser::decodeBase256Segment(Ref<BitSource> bits, ostringst
|
||||
}
|
||||
bytes[i] = unrandomize255State(bits->readBits(8), codewordPosition++);
|
||||
byteSegments.push_back(bytes[i]);
|
||||
result << (char)bytes[i];
|
||||
result << (byte)bytes[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ using zxing::BitMatrix;
|
||||
|
||||
Decoder::Decoder() : rsDecoder_(GenericGF::DATA_MATRIX_FIELD_256) {}
|
||||
|
||||
void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords) {
|
||||
void Decoder::correctErrors(ArrayRef<byte> codewordBytes, int numDataCodewords) {
|
||||
int numCodewords = codewordBytes->size();
|
||||
ArrayRef<int> codewordInts(numCodewords);
|
||||
for (int i = 0; i < numCodewords; i++) {
|
||||
@ -55,7 +55,7 @@ void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords)
|
||||
// Copy back into array of bytes -- only need to worry about the bytes that were data
|
||||
// We don't care about errors in the error-correction codewords
|
||||
for (int i = 0; i < numDataCodewords; i++) {
|
||||
codewordBytes[i] = (char)codewordInts[i];
|
||||
codewordBytes[i] = (byte)codewordInts[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
|
||||
Version *version = parser.readVersion(bits);
|
||||
|
||||
// Read codewords
|
||||
ArrayRef<char> codewords(parser.readCodewords());
|
||||
ArrayRef<byte> codewords(parser.readCodewords());
|
||||
// Separate into data blocks
|
||||
std::vector<Ref<DataBlock> > dataBlocks = DataBlock::getDataBlocks(codewords, version);
|
||||
|
||||
@ -81,7 +81,7 @@ Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
|
||||
// Error-correct and copy data blocks together into a stream of bytes
|
||||
for (int j = 0; j < dataBlocksCount; j++) {
|
||||
Ref<DataBlock> dataBlock(dataBlocks[j]);
|
||||
ArrayRef<char> codewordBytes = dataBlock->getCodewords();
|
||||
ArrayRef<byte> codewordBytes = dataBlock->getCodewords();
|
||||
int numDataCodewords = dataBlock->getNumDataCodewords();
|
||||
correctErrors(codewordBytes, numDataCodewords);
|
||||
for (int i = 0; i < numDataCodewords; i++) {
|
||||
|
@ -79,7 +79,7 @@ private:
|
||||
/**
|
||||
* See ISO 16022:2006, 5.2.9 and Annex B, B.2
|
||||
*/
|
||||
void decodeBase256Segment(Ref<BitSource> bits, std::ostringstream &result, std::vector<char> byteSegments);
|
||||
void decodeBase256Segment(Ref<BitSource> bits, std::ostringstream &result, std::vector<byte> byteSegments);
|
||||
|
||||
void parseTwoBytes(int firstByte, int secondByte, int* result);
|
||||
/**
|
||||
@ -89,7 +89,7 @@ private:
|
||||
int base256CodewordPosition) {
|
||||
int pseudoRandomNumber = ((149 * base256CodewordPosition) % 255) + 1;
|
||||
int tempVariable = randomizedBase256Codeword - pseudoRandomNumber;
|
||||
return (char) (tempVariable >= 0 ? tempVariable : (tempVariable + 256));
|
||||
return (byte) (tempVariable >= 0 ? tempVariable : (tempVariable + 256));
|
||||
};
|
||||
void append(std::ostream &ost, const char *bufIn, size_t nIn, const char *src);
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Decoder {
|
||||
private:
|
||||
ReedSolomonDecoder rsDecoder_;
|
||||
|
||||
void correctErrors(ArrayRef<char> bytes, int numDataCodewords);
|
||||
void correctErrors(ArrayRef<byte> bytes, int numDataCodewords);
|
||||
|
||||
public:
|
||||
Decoder();
|
||||
|
@ -96,7 +96,7 @@ Ref<Result> CodaBarReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
// Hack: We store the position in the alphabet table into a
|
||||
// StringBuilder, so that we can access the decoded patterns in
|
||||
// validatePattern. We'll translate to the actual characters later.
|
||||
decodeRowResult.append(1, (char)charOffset);
|
||||
decodeRowResult.append(1, (byte)charOffset);
|
||||
nextStart += 8;
|
||||
// Stop as soon as we see the end character.
|
||||
if (decodeRowResult.length() > 1 &&
|
||||
|
@ -271,7 +271,7 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
bool isNextShifted = false;
|
||||
|
||||
string result;
|
||||
vector<char> rawCodes(20, 0);
|
||||
vector<byte> rawCodes(20, 0);
|
||||
|
||||
int lastStart = startPatternInfo[0];
|
||||
int nextStart = startPatternInfo[1];
|
||||
@ -324,9 +324,9 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
|
||||
case CODE_CODE_A:
|
||||
if (code < 64) {
|
||||
result.append(1, (char) (' ' + code));
|
||||
result.append(1, (byte) (' ' + code));
|
||||
} else if (code < 96) {
|
||||
result.append(1, (char) (code - 64));
|
||||
result.append(1, (byte) (code - 64));
|
||||
} else {
|
||||
// Don't let CODE_STOP, which always appears, affect whether whether we think the
|
||||
// last code was printable or not.
|
||||
@ -342,7 +342,7 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
result.append("]C1");
|
||||
} else {
|
||||
// GS1 specification 5.4.7.5. Every subsequent FNC1 is returned as ASCII 29 (GS)
|
||||
result.append(1, (char) 29);
|
||||
result.append(1, (byte) 29);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -369,7 +369,7 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
break;
|
||||
case CODE_CODE_B:
|
||||
if (code < 96) {
|
||||
result.append(1, (char) (' ' + code));
|
||||
result.append(1, (byte) (' ' + code));
|
||||
} else {
|
||||
if (code != CODE_STOP) {
|
||||
lastCharacterWasPrintable = false;
|
||||
|
@ -283,7 +283,7 @@ Ref<String> Code39Reader::decodeExtended(std::string encoded){
|
||||
case '+':
|
||||
// +A to +Z map to a to z
|
||||
if (next >= 'A' && next <= 'Z') {
|
||||
decodedChar = (char) (next + 32);
|
||||
decodedChar = (byte) (next + 32);
|
||||
} else {
|
||||
throw ReaderException("");
|
||||
}
|
||||
@ -291,7 +291,7 @@ Ref<String> Code39Reader::decodeExtended(std::string encoded){
|
||||
case '$':
|
||||
// $A to $Z map to control codes SH to SB
|
||||
if (next >= 'A' && next <= 'Z') {
|
||||
decodedChar = (char) (next - 64);
|
||||
decodedChar = (byte) (next - 64);
|
||||
} else {
|
||||
throw ReaderException("");
|
||||
}
|
||||
@ -299,9 +299,9 @@ Ref<String> Code39Reader::decodeExtended(std::string encoded){
|
||||
case '%':
|
||||
// %A to %E map to control codes ESC to US
|
||||
if (next >= 'A' && next <= 'E') {
|
||||
decodedChar = (char) (next - 38);
|
||||
decodedChar = (byte) (next - 38);
|
||||
} else if (next >= 'F' && next <= 'W') {
|
||||
decodedChar = (char) (next - 11);
|
||||
decodedChar = (byte) (next - 11);
|
||||
} else {
|
||||
throw ReaderException("");
|
||||
}
|
||||
@ -309,7 +309,7 @@ Ref<String> Code39Reader::decodeExtended(std::string encoded){
|
||||
case '/':
|
||||
// /A to /O map to ! to , and /Z maps to :
|
||||
if (next >= 'A' && next <= 'O') {
|
||||
decodedChar = (char) (next - 32);
|
||||
decodedChar = (byte) (next - 32);
|
||||
} else if (next == 'Z') {
|
||||
decodedChar = ':';
|
||||
} else {
|
||||
|
@ -226,7 +226,7 @@ Ref<String> Code93Reader::decodeExtended(string const& encoded) {
|
||||
case 'd':
|
||||
// +A to +Z map to a to z
|
||||
if (next >= 'A' && next <= 'Z') {
|
||||
decodedChar = (char) (next + 32);
|
||||
decodedChar = (byte) (next + 32);
|
||||
} else {
|
||||
throw FormatException::getFormatInstance();
|
||||
}
|
||||
@ -234,7 +234,7 @@ Ref<String> Code93Reader::decodeExtended(string const& encoded) {
|
||||
case 'a':
|
||||
// $A to $Z map to control codes SH to SB
|
||||
if (next >= 'A' && next <= 'Z') {
|
||||
decodedChar = (char) (next - 64);
|
||||
decodedChar = (byte) (next - 64);
|
||||
} else {
|
||||
throw FormatException::getFormatInstance();
|
||||
}
|
||||
@ -242,9 +242,9 @@ Ref<String> Code93Reader::decodeExtended(string const& encoded) {
|
||||
case 'b':
|
||||
// %A to %E map to control codes ESC to US
|
||||
if (next >= 'A' && next <= 'E') {
|
||||
decodedChar = (char) (next - 38);
|
||||
decodedChar = (byte) (next - 38);
|
||||
} else if (next >= 'F' && next <= 'W') {
|
||||
decodedChar = (char) (next - 11);
|
||||
decodedChar = (byte) (next - 11);
|
||||
} else {
|
||||
throw FormatException::getFormatInstance();
|
||||
}
|
||||
@ -252,7 +252,7 @@ Ref<String> Code93Reader::decodeExtended(string const& encoded) {
|
||||
case 'c':
|
||||
// /A to /O map to ! to , and /Z maps to :
|
||||
if (next >= 'A' && next <= 'O') {
|
||||
decodedChar = (char) (next - 32);
|
||||
decodedChar = (byte) (next - 32);
|
||||
} else if (next == 'Z') {
|
||||
decodedChar = ':';
|
||||
} else {
|
||||
|
@ -44,7 +44,7 @@ int EAN13Reader::decodeMiddle(Ref<BitArray> row,
|
||||
|
||||
for (int x = 0; x < 6 && rowOffset < end; x++) {
|
||||
int bestMatch = decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS);
|
||||
resultString.append(1, (char) ('0' + bestMatch % 10));
|
||||
resultString.append(1, (byte) ('0' + bestMatch % 10));
|
||||
for (int i = 0, end = counters.size(); i <end; i++) {
|
||||
rowOffset += counters[i];
|
||||
}
|
||||
@ -61,7 +61,7 @@ int EAN13Reader::decodeMiddle(Ref<BitArray> row,
|
||||
for (int x = 0; x < 6 && rowOffset < end; x++) {
|
||||
int bestMatch =
|
||||
decodeDigit(row, counters, rowOffset, L_PATTERNS);
|
||||
resultString.append(1, (char) ('0' + bestMatch));
|
||||
resultString.append(1, (byte) ('0' + bestMatch));
|
||||
for (int i = 0, end = counters.size(); i < end; i++) {
|
||||
rowOffset += counters[i];
|
||||
}
|
||||
@ -73,7 +73,7 @@ void EAN13Reader::determineFirstDigit(std::string& resultString, int lgPatternFo
|
||||
// std::cerr << "K " << resultString << " " << lgPatternFound << " " <<FIRST_DIGIT_ENCODINGS << std::endl;
|
||||
for (int d = 0; d < 10; d++) {
|
||||
if (lgPatternFound == FIRST_DIGIT_ENCODINGS[d]) {
|
||||
resultString.insert((size_t)0, (size_t)1, (char) ('0' + d));
|
||||
resultString.insert((size_t)0, (size_t)1, (byte) ('0' + d));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ int EAN8Reader::decodeMiddle(Ref<BitArray> row,
|
||||
|
||||
for (int x = 0; x < 4 && rowOffset < end; x++) {
|
||||
int bestMatch = decodeDigit(row, counters, rowOffset, L_PATTERNS);
|
||||
result.append(1, (char) ('0' + bestMatch));
|
||||
result.append(1, (byte) ('0' + bestMatch));
|
||||
for (int i = 0, end = counters.size(); i < end; i++) {
|
||||
rowOffset += counters[i];
|
||||
}
|
||||
@ -52,7 +52,7 @@ int EAN8Reader::decodeMiddle(Ref<BitArray> row,
|
||||
rowOffset = middleRange[1];
|
||||
for (int x = 0; x < 4 && rowOffset < end; x++) {
|
||||
int bestMatch = decodeDigit(row, counters, rowOffset, L_PATTERNS);
|
||||
result.append(1, (char) ('0' + bestMatch));
|
||||
result.append(1, (byte) ('0' + bestMatch));
|
||||
for (int i = 0, end = counters.size(); i < end; i++) {
|
||||
rowOffset += counters[i];
|
||||
}
|
||||
|
@ -151,9 +151,9 @@ void ITFReader::decodeMiddle(Ref<BitArray> row,
|
||||
}
|
||||
|
||||
int bestMatch = decodeDigit(counterBlack);
|
||||
resultString.append(1, (char) ('0' + bestMatch));
|
||||
resultString.append(1, (byte) ('0' + bestMatch));
|
||||
bestMatch = decodeDigit(counterWhite);
|
||||
resultString.append(1, (char) ('0' + bestMatch));
|
||||
resultString.append(1, (byte) ('0' + bestMatch));
|
||||
|
||||
for (int i = 0, e = counterDigitPair.size(); i < e; i++) {
|
||||
payloadStart += counterDigitPair[i];
|
||||
|
@ -64,7 +64,7 @@ int UPCEReader::decodeMiddle(Ref<BitArray> row, Range const& startRange, string&
|
||||
|
||||
for (int x = 0; x < 6 && rowOffset < end; x++) {
|
||||
int bestMatch = decodeDigit(row, counters, rowOffset, L_AND_G_PATTERNS);
|
||||
result.append(1, (char) ('0' + bestMatch % 10));
|
||||
result.append(1, (byte) ('0' + bestMatch % 10));
|
||||
for (int i = 0, e = counters.size(); i < e; i++) {
|
||||
rowOffset += counters[i];
|
||||
}
|
||||
@ -91,8 +91,8 @@ bool UPCEReader::determineNumSysAndCheckDigit(std::string& resultString, int lgP
|
||||
for (int numSys = 0; numSys <= 1; numSys++) {
|
||||
for (int d = 0; d < 10; d++) {
|
||||
if (lgPatternFound == NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d]) {
|
||||
resultString.insert((size_t)0, (size_t)1, (char) ('0' + numSys));
|
||||
resultString.append(1, (char) ('0' + d));
|
||||
resultString.insert((size_t)0, (size_t)1, (byte) ('0' + numSys));
|
||||
resultString.append(1, (byte) ('0' + d));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,9 @@ using zxing::Ref;
|
||||
using zxing::DecoderResult;
|
||||
using zxing::String;
|
||||
|
||||
namespace zxing {
|
||||
namespace pdf417 {
|
||||
|
||||
const int DecodedBitStreamParser::TEXT_COMPACTION_MODE_LATCH = 900;
|
||||
const int DecodedBitStreamParser::BYTE_COMPACTION_MODE_LATCH = 901;
|
||||
const int DecodedBitStreamParser::NUMERIC_COMPACTION_MODE_LATCH = 902;
|
||||
@ -214,7 +217,7 @@ void DecodedBitStreamParser::decodeTextCompaction(ArrayRef<int> textCompactionDa
|
||||
// Alpha (uppercase alphabetic)
|
||||
if (subModeCh < 26) {
|
||||
// Upper case Alpha Character
|
||||
ch = (char) ('A' + subModeCh);
|
||||
ch = (byte) ('A' + subModeCh);
|
||||
} else {
|
||||
if (subModeCh == 26) {
|
||||
ch = ' ';
|
||||
@ -227,7 +230,7 @@ void DecodedBitStreamParser::decodeTextCompaction(ArrayRef<int> textCompactionDa
|
||||
priorToShiftMode = subMode;
|
||||
subMode = PUNCT_SHIFT;
|
||||
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
|
||||
result->append((char) byteCompactionData[i]);
|
||||
result->append((byte) byteCompactionData[i]);
|
||||
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
|
||||
subMode = ALPHA;
|
||||
}
|
||||
@ -237,7 +240,7 @@ void DecodedBitStreamParser::decodeTextCompaction(ArrayRef<int> textCompactionDa
|
||||
case LOWER:
|
||||
// Lower (lowercase alphabetic)
|
||||
if (subModeCh < 26) {
|
||||
ch = (char) ('a' + subModeCh);
|
||||
ch = (byte) ('a' + subModeCh);
|
||||
} else {
|
||||
if (subModeCh == 26) {
|
||||
ch = ' ';
|
||||
@ -252,7 +255,7 @@ void DecodedBitStreamParser::decodeTextCompaction(ArrayRef<int> textCompactionDa
|
||||
priorToShiftMode = subMode;
|
||||
subMode = PUNCT_SHIFT;
|
||||
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
|
||||
result->append((char) byteCompactionData[i]);
|
||||
result->append((byte) byteCompactionData[i]);
|
||||
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
|
||||
subMode = ALPHA;
|
||||
}
|
||||
@ -277,7 +280,7 @@ void DecodedBitStreamParser::decodeTextCompaction(ArrayRef<int> textCompactionDa
|
||||
priorToShiftMode = subMode;
|
||||
subMode = PUNCT_SHIFT;
|
||||
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
|
||||
result->append((char) byteCompactionData[i]);
|
||||
result->append((byte) byteCompactionData[i]);
|
||||
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
|
||||
subMode = ALPHA;
|
||||
}
|
||||
@ -292,7 +295,7 @@ void DecodedBitStreamParser::decodeTextCompaction(ArrayRef<int> textCompactionDa
|
||||
if (subModeCh == PAL) {
|
||||
subMode = ALPHA;
|
||||
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
|
||||
result->append((char) byteCompactionData[i]);
|
||||
result->append((byte) byteCompactionData[i]);
|
||||
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
|
||||
subMode = ALPHA;
|
||||
}
|
||||
@ -303,7 +306,7 @@ void DecodedBitStreamParser::decodeTextCompaction(ArrayRef<int> textCompactionDa
|
||||
// Restore sub-mode
|
||||
subMode = priorToShiftMode;
|
||||
if (subModeCh < 26) {
|
||||
ch = (char) ('A' + subModeCh);
|
||||
ch = (byte) ('A' + subModeCh);
|
||||
} else {
|
||||
if (subModeCh == 26) {
|
||||
ch = ' ';
|
||||
@ -329,7 +332,7 @@ void DecodedBitStreamParser::decodeTextCompaction(ArrayRef<int> textCompactionDa
|
||||
} else if (subModeCh == MODE_SHIFT_TO_BYTE_COMPACTION_MODE) {
|
||||
// PS before Shift-to-Byte is used as a padding character,
|
||||
// see 5.4.2.4 of the specification
|
||||
result->append((char) byteCompactionData[i]);
|
||||
result->append((byte) byteCompactionData[i]);
|
||||
} else if (subModeCh == TEXT_COMPACTION_MODE_LATCH) {
|
||||
subMode = ALPHA;
|
||||
}
|
||||
@ -363,7 +366,7 @@ int DecodedBitStreamParser::byteCompaction(int mode,
|
||||
// is not a multiple of 6
|
||||
int count = 0;
|
||||
int64_t value = 0;
|
||||
ArrayRef<char> decodedData = new Array<char>(6);
|
||||
ArrayRef<byte> decodedData = new Array<byte>(6);
|
||||
ArrayRef<int> byteCompactedCodewords = new Array<int>(6);
|
||||
bool end = false;
|
||||
int nextCode = codewords[codeIndex++];
|
||||
@ -391,10 +394,10 @@ int DecodedBitStreamParser::byteCompaction(int mode,
|
||||
// Convert to Base 256
|
||||
for (int j = 0; j < 6; ++j)
|
||||
{
|
||||
decodedData[5 - j] = (char) (value%256);
|
||||
decodedData[5 - j] = (byte) (value%256);
|
||||
value >>= 8;
|
||||
}
|
||||
result->append(string(&(decodedData->values()[0]), decodedData->values().size()));
|
||||
result->append(string((char*)&(decodedData->values()[0]), decodedData->values().size()));
|
||||
count = 0;
|
||||
}
|
||||
}
|
||||
@ -409,7 +412,7 @@ int DecodedBitStreamParser::byteCompaction(int mode,
|
||||
// as one byte per codeword, without compaction.
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
result->append((char)byteCompactedCodewords[i]);
|
||||
result->append((byte)byteCompactedCodewords[i]);
|
||||
}
|
||||
|
||||
} else if (mode == BYTE_COMPACTION_MODE_LATCH_6) {
|
||||
@ -439,12 +442,12 @@ int DecodedBitStreamParser::byteCompaction(int mode,
|
||||
if ((count % 5 == 0) && (count > 0)) {
|
||||
// Decode every 5 codewords
|
||||
// Convert to Base 256
|
||||
ArrayRef<char> decodedData = new Array<char>(6);
|
||||
ArrayRef<byte> decodedData = new Array<byte>(6);
|
||||
for (int j = 0; j < 6; ++j) {
|
||||
decodedData[5 - j] = (char) (value & 0xFF);
|
||||
decodedData[5 - j] = (byte) (value & 0xFF);
|
||||
value >>= 8;
|
||||
}
|
||||
result->append(string(&decodedData[0],6));
|
||||
result->append(string((char*)&decodedData[0],6));
|
||||
// 2012-11-27 hfn after recent java code/fix by srowen
|
||||
count = 0;
|
||||
}
|
||||
@ -561,3 +564,6 @@ Ref<String> DecodedBitStreamParser::decodeBase900toBase10(ArrayRef<int> codeword
|
||||
Ref<String> res (new String(resultString2));
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -25,28 +25,28 @@
|
||||
#include <iostream>
|
||||
|
||||
namespace zxing {
|
||||
namespace qrcode {
|
||||
|
||||
using namespace std;
|
||||
|
||||
QRCodeReader::QRCodeReader() :decoder_() {
|
||||
}
|
||||
namespace qrcode {
|
||||
|
||||
using namespace std;
|
||||
|
||||
QRCodeReader::QRCodeReader() :decoder_() {
|
||||
}
|
||||
//TODO : see if any of the other files in the qrcode tree need tryHarder
|
||||
Ref<Result> QRCodeReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
|
||||
Detector detector(image->getBlackMatrix());
|
||||
Ref<DetectorResult> detectorResult(detector.detect(hints));
|
||||
ArrayRef< Ref<ResultPoint> > points (detectorResult->getPoints());
|
||||
Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
|
||||
Ref<Result> result(
|
||||
Ref<Result> QRCodeReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
|
||||
Detector detector(image->getBlackMatrix());
|
||||
Ref<DetectorResult> detectorResult(detector.detect(hints));
|
||||
ArrayRef< Ref<ResultPoint> > points (detectorResult->getPoints());
|
||||
Ref<DecoderResult> decoderResult(decoder_.decode(detectorResult->getBits()));
|
||||
Ref<Result> result(
|
||||
new Result(decoderResult->getText(), decoderResult->getRawBytes(), points, BarcodeFormat::QR_CODE, decoderResult->charSet()));
|
||||
return result;
|
||||
}
|
||||
|
||||
QRCodeReader::~QRCodeReader() {
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QRCodeReader::~QRCodeReader() {
|
||||
}
|
||||
|
||||
Decoder& QRCodeReader::getDecoder() {
|
||||
return decoder_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <zxing/qrcode/FormatInformation.h>
|
||||
#include <limits>
|
||||
#include <zxing/common/Types.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace qrcode {
|
||||
@ -39,7 +40,7 @@ int FormatInformation::N_FORMAT_INFO_DECODE_LOOKUPS = 32;
|
||||
int FormatInformation::BITS_SET_IN_HALF_BYTE[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
|
||||
|
||||
FormatInformation::FormatInformation(int formatInfo) :
|
||||
errorCorrectionLevel_(ErrorCorrectionLevel::forBits((formatInfo >> 3) & 0x03)), dataMask_((char)(formatInfo & 0x07)) {
|
||||
errorCorrectionLevel_(ErrorCorrectionLevel::forBits((formatInfo >> 3) & 0x03)), dataMask_((byte)(formatInfo & 0x07)) {
|
||||
}
|
||||
|
||||
ErrorCorrectionLevel& FormatInformation::getErrorCorrectionLevel() {
|
||||
|
@ -43,7 +43,7 @@ public:
|
||||
BitMatrixParser(Ref<BitMatrix> bitMatrix);
|
||||
Ref<FormatInformation> readFormatInformation();
|
||||
Version *readVersion();
|
||||
ArrayRef<char> readCodewords();
|
||||
ArrayRef<byte> readCodewords();
|
||||
void remask();
|
||||
void setMirror(boolean mirror);
|
||||
void mirror();
|
||||
|
@ -32,16 +32,16 @@ namespace qrcode {
|
||||
class DataBlock : public Counted {
|
||||
private:
|
||||
int numDataCodewords_;
|
||||
ArrayRef<char> codewords_;
|
||||
ArrayRef<byte> codewords_;
|
||||
|
||||
DataBlock(int numDataCodewords, ArrayRef<char> codewords);
|
||||
DataBlock(int numDataCodewords, ArrayRef<byte> codewords);
|
||||
|
||||
public:
|
||||
static std::vector<Ref<DataBlock> >
|
||||
getDataBlocks(ArrayRef<char> rawCodewords, Version *version, ErrorCorrectionLevel &ecLevel);
|
||||
getDataBlocks(ArrayRef<byte> rawCodewords, Version *version, ErrorCorrectionLevel &ecLevel);
|
||||
|
||||
int getNumDataCodewords();
|
||||
ArrayRef<char> getCodewords();
|
||||
ArrayRef<byte> getCodewords();
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class Decoder {
|
||||
private:
|
||||
ReedSolomonDecoder rsDecoder_;
|
||||
|
||||
void correctErrors(ArrayRef<char> bytes, int numDataCodewords);
|
||||
void correctErrors(ArrayRef<byte> bytes, int numDataCodewords);
|
||||
|
||||
public:
|
||||
Decoder();
|
||||
|
@ -116,7 +116,7 @@ Version *BitMatrixParser::readVersion() {
|
||||
throw ReaderException("Could not decode version");
|
||||
}
|
||||
|
||||
ArrayRef<char> BitMatrixParser::readCodewords() {
|
||||
ArrayRef<byte> BitMatrixParser::readCodewords() {
|
||||
Ref<FormatInformation> formatInfo = readFormatInformation();
|
||||
Version *version = readVersion();
|
||||
|
||||
@ -138,7 +138,7 @@ ArrayRef<char> BitMatrixParser::readCodewords() {
|
||||
// cout << *functionPattern << endl;
|
||||
|
||||
bool readingUp = true;
|
||||
ArrayRef<char> result(version->getTotalCodewords());
|
||||
ArrayRef<byte> result(version->getTotalCodewords());
|
||||
int resultOffset = 0;
|
||||
int currentByte = 0;
|
||||
int bitsRead = 0;
|
||||
@ -163,7 +163,7 @@ ArrayRef<char> BitMatrixParser::readCodewords() {
|
||||
}
|
||||
// If we've made a whole byte, save it off
|
||||
if (bitsRead == 8) {
|
||||
result[resultOffset++] = (char)currentByte;
|
||||
result[resultOffset++] = (byte)currentByte;
|
||||
bitsRead = 0;
|
||||
currentByte = 0;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ namespace qrcode {
|
||||
|
||||
using namespace std;
|
||||
|
||||
DataBlock::DataBlock(int numDataCodewords, ArrayRef<char> codewords) :
|
||||
DataBlock::DataBlock(int numDataCodewords, ArrayRef<byte> codewords) :
|
||||
numDataCodewords_(numDataCodewords), codewords_(codewords) {
|
||||
}
|
||||
|
||||
@ -34,12 +34,12 @@ int DataBlock::getNumDataCodewords() {
|
||||
return numDataCodewords_;
|
||||
}
|
||||
|
||||
ArrayRef<char> DataBlock::getCodewords() {
|
||||
ArrayRef<byte> DataBlock::getCodewords() {
|
||||
return codewords_;
|
||||
}
|
||||
|
||||
|
||||
std::vector<Ref<DataBlock> > DataBlock::getDataBlocks(ArrayRef<char> rawCodewords, Version *version,
|
||||
std::vector<Ref<DataBlock> > DataBlock::getDataBlocks(ArrayRef<byte> rawCodewords, Version *version,
|
||||
ErrorCorrectionLevel &ecLevel) {
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ std::vector<Ref<DataBlock> > DataBlock::getDataBlocks(ArrayRef<char> rawCodeword
|
||||
for (int i = 0; i < ecBlock->getCount(); i++) {
|
||||
int numDataCodewords = ecBlock->getDataCodewords();
|
||||
int numBlockCodewords = ecBlocks.getECCodewordsPerBloc() + numDataCodewords;
|
||||
ArrayRef<char> buffer(numBlockCodewords);
|
||||
ArrayRef<byte> buffer(numBlockCodewords);
|
||||
Ref<DataBlock> blockRef(new DataBlock(numDataCodewords, buffer));
|
||||
result[numResultBlocks++] = blockRef;
|
||||
}
|
||||
|
@ -132,8 +132,8 @@ void DecodedBitStreamParser::decodeHanziSegment(Ref<BitSource> bits_,
|
||||
// In the 0xB0A1 to 0xFAFE range
|
||||
assembledTwoBytes += 0x0A6A1;
|
||||
}
|
||||
buffer[offset] = (char) ((assembledTwoBytes >> 8) & 0xFF);
|
||||
buffer[offset + 1] = (char) (assembledTwoBytes & 0xFF);
|
||||
buffer[offset] = (byte) ((assembledTwoBytes >> 8) & 0xFF);
|
||||
buffer[offset + 1] = (byte) (assembledTwoBytes & 0xFF);
|
||||
offset += 2;
|
||||
count--;
|
||||
}
|
||||
@ -167,8 +167,8 @@ void DecodedBitStreamParser::decodeKanjiSegment(Ref<BitSource> bits, std::string
|
||||
// In the 0xE040 to 0xEBBF range
|
||||
assembledTwoBytes += 0x0C140;
|
||||
}
|
||||
buffer[offset] = (char)(assembledTwoBytes >> 8);
|
||||
buffer[offset + 1] = (char)assembledTwoBytes;
|
||||
buffer[offset] = (byte)(assembledTwoBytes >> 8);
|
||||
buffer[offset + 1] = (byte)assembledTwoBytes;
|
||||
offset += 2;
|
||||
count--;
|
||||
}
|
||||
@ -319,7 +319,7 @@ void DecodedBitStreamParser::decodeAlphanumericSegment(Ref<BitSource> bits_,
|
||||
r << s[i++];
|
||||
} else {
|
||||
// In alpha mode, % should be converted to FNC1 separator 0x1D
|
||||
r << (char)0x1D;
|
||||
r << (byte)0x1D;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ Decoder::Decoder() :
|
||||
rsDecoder_(GenericGF::QR_CODE_FIELD_256) {
|
||||
}
|
||||
|
||||
void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords) {
|
||||
void Decoder::correctErrors(ArrayRef<byte> codewordBytes, int numDataCodewords) {
|
||||
int numCodewords = codewordBytes->size();
|
||||
ArrayRef<int> codewordInts(numCodewords);
|
||||
for (int i = 0; i < numCodewords; i++) {
|
||||
@ -59,7 +59,7 @@ void Decoder::correctErrors(ArrayRef<char> codewordBytes, int numDataCodewords)
|
||||
}
|
||||
|
||||
for (int i = 0; i < numDataCodewords; i++) {
|
||||
codewordBytes[i] = (char)codewordInts[i];
|
||||
codewordBytes[i] = (byte)codewordInts[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
|
||||
|
||||
|
||||
// Read codewords
|
||||
ArrayRef<char> codewords(parser.readCodewords());
|
||||
ArrayRef<byte> codewords(parser.readCodewords());
|
||||
|
||||
|
||||
// Separate into data blocks
|
||||
@ -93,7 +93,7 @@ Ref<DecoderResult> Decoder::decode(Ref<BitMatrix> bits) {
|
||||
// Error-correct and copy data blocks together into a stream of bytes
|
||||
for (size_t j = 0; j < dataBlocks.size(); j++) {
|
||||
Ref<DataBlock> dataBlock(dataBlocks[j]);
|
||||
ArrayRef<char> codewordBytes = dataBlock->getCodewords();
|
||||
ArrayRef<byte> codewordBytes = dataBlock->getCodewords();
|
||||
int numDataCodewords = dataBlock->getNumDataCodewords();
|
||||
correctErrors(codewordBytes, numDataCodewords);
|
||||
for (int i = 0; i < numDataCodewords; i++) {
|
||||
|
@ -13,17 +13,17 @@ class BlockPair
|
||||
{
|
||||
private:
|
||||
ArrayRef<byte> data_;
|
||||
ArrayRef<char> errorCorrection_;
|
||||
ArrayRef<byte> errorCorrection_;
|
||||
|
||||
public:
|
||||
BlockPair(ArrayRef<byte> data, ArrayRef<char> errorCorrection) :
|
||||
BlockPair(ArrayRef<byte> data, ArrayRef<byte> errorCorrection) :
|
||||
data_(data), errorCorrection_(errorCorrection) {}
|
||||
|
||||
BlockPair(const BlockPair& other) : data_(other.data_), errorCorrection_(other.errorCorrection_) {}
|
||||
|
||||
ArrayRef<byte> getDataBytes() { return data_; }
|
||||
|
||||
ArrayRef<char> getErrorCorrectionBytes() { return errorCorrection_; }
|
||||
ArrayRef<byte> getErrorCorrectionBytes() { return errorCorrection_; }
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ protected:
|
||||
int numDataBytes,
|
||||
int numRSBlocks);
|
||||
|
||||
static ArrayRef<char> generateECBytes(const std::vector<byte> &dataBytes, int numEcBytesInBlock);
|
||||
static ArrayRef<byte> generateECBytes(const std::vector<byte> &dataBytes, int numEcBytesInBlock);
|
||||
|
||||
/**
|
||||
* Append mode info. On success, store the result in "bits".
|
||||
|
@ -182,7 +182,7 @@ Mode Encoder::chooseMode(const QString& content, const QString& encoding)
|
||||
|
||||
//bool Encoder::isOnlyDoubleByteKanji(const QString& content)
|
||||
//{
|
||||
// std::vector<char> bytes;
|
||||
// std::vector<byte> bytes;
|
||||
// try {
|
||||
// bytes = content.getBytes("Shift_JIS");
|
||||
// } catch (UnsupportedEncodingException ignored) {
|
||||
@ -374,7 +374,7 @@ BitArray* Encoder::interleaveWithECBytes(const BitArray& bits,
|
||||
std::vector<byte> dataBytes;
|
||||
dataBytes.resize(size);
|
||||
bits.toBytes(8*dataBytesOffset, dataBytes, 0, size);
|
||||
ArrayRef<char> ecBytes = generateECBytes(dataBytes, numEcBytesInBlock[0]);
|
||||
ArrayRef<byte> ecBytes = generateECBytes(dataBytes, numEcBytesInBlock[0]);
|
||||
blocks.push_back(BlockPair(ArrayRef<byte>(dataBytes.data(), dataBytes.size()),ecBytes)); //?? please revisit
|
||||
|
||||
maxNumDataBytes = max(maxNumDataBytes, size);
|
||||
@ -399,7 +399,7 @@ BitArray* Encoder::interleaveWithECBytes(const BitArray& bits,
|
||||
// Then, place error correction blocks.
|
||||
for (int i = 0; i < maxNumEcBytes; i++) {
|
||||
for (std::vector< BlockPair >::iterator it=blocks.begin(); it != blocks.end(); it++) {
|
||||
ArrayRef<char> ecBytes = it->getErrorCorrectionBytes();
|
||||
ArrayRef<byte> ecBytes = it->getErrorCorrectionBytes();
|
||||
if (i < ecBytes.array_->size()) {
|
||||
result->appendBits(ecBytes[i], 8);
|
||||
}
|
||||
@ -417,7 +417,7 @@ BitArray* Encoder::interleaveWithECBytes(const BitArray& bits,
|
||||
return result;
|
||||
}
|
||||
|
||||
ArrayRef<char> Encoder::generateECBytes(const std::vector<byte>& dataBytes, int numEcBytesInBlock)
|
||||
ArrayRef<byte> Encoder::generateECBytes(const std::vector<byte>& dataBytes, int numEcBytesInBlock)
|
||||
{
|
||||
int numDataBytes = dataBytes.size();
|
||||
std::vector<int> toEncode;
|
||||
@ -429,9 +429,9 @@ ArrayRef<char> Encoder::generateECBytes(const std::vector<byte>& dataBytes, int
|
||||
zxing::ReedSolomonEncoder encoder(GenericGF::QR_CODE_FIELD_256);
|
||||
encoder.encode(toEncode, numEcBytesInBlock);
|
||||
|
||||
ArrayRef<char> ecBytes(numEcBytesInBlock);
|
||||
ArrayRef<byte> ecBytes(numEcBytesInBlock);
|
||||
for (int i = 0; i < numEcBytesInBlock; i++) {
|
||||
ecBytes[i] = (char) toEncode[numDataBytes + i];
|
||||
ecBytes[i] = (byte) toEncode[numDataBytes + i];
|
||||
}
|
||||
return ecBytes;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user