[fix] Fixed several warnings and use QElapsedTimer (#150)

* [fix] Fixed several warnings and use QElapsedTimer

* [fix] Now using explicit type for c++98
This commit is contained in:
Leroy.H.Y 2019-12-22 02:35:05 +08:00 committed by Nikolaos Ftylitakis
parent bad0b6551c
commit 1082c3b9e5
8 changed files with 118 additions and 117 deletions

View File

@ -378,7 +378,7 @@ QRectF getTagRect(const ArrayRef<Ref<ResultPoint> > &resultPoints, const Ref<Bit
QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bool smoothTransformation) QString QZXing::decodeImage(const QImage &image, int maxWidth, int maxHeight, bool smoothTransformation)
{ {
QTime t; QElapsedTimer t;
t.start(); t.start();
processingTime = -1; processingTime = -1;
Ref<Result> res; Ref<Result> res;

View File

@ -22,6 +22,7 @@
#include <QObject> #include <QObject>
#include <QImage> #include <QImage>
#include <QVariantList> #include <QVariantList>
#include <QElapsedTimer>
#include <set> #include <set>

View File

@ -69,47 +69,47 @@ namespace {
const int NB_BITS_COMPACT[] = { const int NB_BITS_COMPACT[] = {
0, 104, 240, 408, 608 0, 104, 240, 408, 608
}; };
const int NB_BITS[] = { const int NB_BITS[] = {
0, 128, 288, 480, 704, 960, 1248, 1568, 1920, 2304, 2720, 3168, 3648, 4160, 4704, 5280, 5888, 6528, 0, 128, 288, 480, 704, 960, 1248, 1568, 1920, 2304, 2720, 3168, 3648, 4160, 4704, 5280, 5888, 6528,
7200, 7904, 8640, 9408, 10208, 11040, 11904, 12800, 13728, 14688, 15680, 16704, 17760, 18848, 19968 7200, 7904, 8640, 9408, 10208, 11040, 11904, 12800, 13728, 14688, 15680, 16704, 17760, 18848, 19968
}; };
const int NB_DATABLOCK_COMPACT[] = { const int NB_DATABLOCK_COMPACT[] = {
0, 17, 40, 51, 76 0, 17, 40, 51, 76
}; };
const int NB_DATABLOCK[] = { const int NB_DATABLOCK[] = {
0, 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790, 864, 0, 21, 48, 60, 88, 120, 156, 196, 240, 230, 272, 316, 364, 416, 470, 528, 588, 652, 720, 790, 864,
940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664 940, 1020, 920, 992, 1066, 1144, 1224, 1306, 1392, 1480, 1570, 1664
}; };
const char* UPPER_TABLE[] = { const char* UPPER_TABLE[] = {
"CTRL_PS", " ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "CTRL_PS", " ", "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", "CTRL_LL", "CTRL_ML", "CTRL_DL", "CTRL_BS" "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "CTRL_LL", "CTRL_ML", "CTRL_DL", "CTRL_BS"
}; };
const char* LOWER_TABLE[] = { const char* LOWER_TABLE[] = {
"CTRL_PS", " ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "CTRL_PS", " ", "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", "CTRL_US", "CTRL_ML", "CTRL_DL", "CTRL_BS" "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "CTRL_US", "CTRL_ML", "CTRL_DL", "CTRL_BS"
}; };
const char* MIXED_TABLE[] = { const char* MIXED_TABLE[] = {
"CTRL_PS", " ", "\1", "\2", "\3", "\4", "\5", "\6", "\7", "\b", "\t", "\n", "CTRL_PS", " ", "\1", "\2", "\3", "\4", "\5", "\6", "\7", "\b", "\t", "\n",
"\13", "\f", "\r", "\33", "\34", "\35", "\36", "\37", "@", "\\", "^", "_", "\13", "\f", "\r", "\33", "\34", "\35", "\36", "\37", "@", "\\", "^", "_",
"`", "|", "~", "\177", "CTRL_LL", "CTRL_UL", "CTRL_PL", "CTRL_BS" "`", "|", "~", "\177", "CTRL_LL", "CTRL_UL", "CTRL_PL", "CTRL_BS"
}; };
const char* PUNCT_TABLE[] = { const char* PUNCT_TABLE[] = {
"", "\r", "\r\n", ". ", ", ", ": ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "", "\r", "\r\n", ". ", ", ", ": ", "!", "\"", "#", "$", "%", "&", "'", "(", ")",
"*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "[", "]", "{", "}", "CTRL_UL" "*", "+", ",", "-", ".", "/", ":", ";", "<", "=", ">", "?", "[", "]", "{", "}", "CTRL_UL"
}; };
const char* DIGIT_TABLE[] = { const char* DIGIT_TABLE[] = {
"CTRL_PS", " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", "CTRL_UL", "CTRL_US" "CTRL_PS", " ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", "CTRL_UL", "CTRL_US"
}; };
} }
Decoder::Table Decoder::getTable(char t) { Decoder::Table Decoder::getTable(char t) {
switch (t) { switch (t) {
case 'L': case 'L':
@ -127,7 +127,7 @@ Decoder::Table Decoder::getTable(char t) {
return UPPER; return UPPER;
} }
} }
const char* Decoder::getCharacter(zxing::aztec::Decoder::Table table, int code) { const char* Decoder::getCharacter(zxing::aztec::Decoder::Table table, int code) {
switch (table) { switch (table) {
case UPPER: case UPPER:
@ -144,50 +144,50 @@ const char* Decoder::getCharacter(zxing::aztec::Decoder::Table table, int code)
return ""; return "";
} }
} }
Decoder::Decoder() { Decoder::Decoder() {
// nothing // nothing
} }
Ref<DecoderResult> Decoder::decode(Ref<zxing::aztec::AztecDetectorResult> detectorResult) { Ref<DecoderResult> Decoder::decode(Ref<zxing::aztec::AztecDetectorResult> detectorResult) {
ddata_ = detectorResult; ddata_ = detectorResult;
// std::printf("getting bits\n"); // std::printf("getting bits\n");
Ref<BitMatrix> matrix = detectorResult->getBits(); Ref<BitMatrix> matrix = detectorResult->getBits();
if (!ddata_->isCompact()) { if (!ddata_->isCompact()) {
// std::printf("removing lines\n"); // std::printf("removing lines\n");
matrix = removeDashedLines(ddata_->getBits()); matrix = removeDashedLines(ddata_->getBits());
} }
// std::printf("extracting bits\n"); // std::printf("extracting bits\n");
Ref<BitArray> rawbits = extractBits(matrix); Ref<BitArray> rawbits = extractBits(matrix);
// std::printf("correcting bits\n"); // std::printf("correcting bits\n");
Ref<BitArray> aCorrectedBits = correctBits(rawbits); Ref<BitArray> aCorrectedBits = correctBits(rawbits);
// std::printf("decoding bits\n"); // std::printf("decoding bits\n");
Ref<String> result = getEncodedData(aCorrectedBits); Ref<String> result = getEncodedData(aCorrectedBits);
// std::printf("constructing array\n"); // std::printf("constructing array\n");
ArrayRef<zxing::byte> arrayOut(aCorrectedBits->getSize()); ArrayRef<zxing::byte> arrayOut(aCorrectedBits->getSize());
for (int i = 0; i < aCorrectedBits->count(); i++) { for (size_t i = 0; i < aCorrectedBits->count(); i++) {
arrayOut[i] = (zxing::byte)aCorrectedBits->get(i); arrayOut[i] = (zxing::byte)aCorrectedBits->get(i);
} }
// std::printf("returning\n"); // std::printf("returning\n");
return Ref<DecoderResult>(new DecoderResult(arrayOut, result)); return Ref<DecoderResult>(new DecoderResult(arrayOut, result));
} }
Ref<String> Decoder::getEncodedData(Ref<zxing::BitArray> correctedBits) { Ref<String> Decoder::getEncodedData(Ref<zxing::BitArray> correctedBits) {
int endIndex = codewordSize_ * ddata_->getNBDatablocks() - invertedBitCount_; int endIndex = codewordSize_ * ddata_->getNBDatablocks() - invertedBitCount_;
if (endIndex > (int)correctedBits->getSize()) { if (endIndex > (int)correctedBits->getSize()) {
// std::printf("invalid input\n"); // std::printf("invalid input\n");
throw FormatException("invalid input data"); throw FormatException("invalid input data");
} }
Table lastTable = UPPER; Table lastTable = UPPER;
Table table = UPPER; Table table = UPPER;
int startIndex = 0; int startIndex = 0;
@ -196,29 +196,29 @@ Ref<String> Decoder::getEncodedData(Ref<zxing::BitArray> correctedBits) {
bool shift = false; bool shift = false;
bool switchShift = false; bool switchShift = false;
bool binaryShift = false; bool binaryShift = false;
while (!end) { while (!end) {
// std::printf("decoooooding\n"); // std::printf("decoooooding\n");
if (shift) { if (shift) {
switchShift = true; switchShift = true;
} else { } else {
lastTable = table; lastTable = table;
} }
int code; int code;
if (binaryShift) { if (binaryShift) {
if (endIndex - startIndex < 5) { if (endIndex - startIndex < 5) {
break; break;
} }
int length = readCode(correctedBits, startIndex, 5); int length = readCode(correctedBits, startIndex, 5);
startIndex += 5; startIndex += 5;
if (length == 0) { if (length == 0) {
if (endIndex - startIndex < 11) { if (endIndex - startIndex < 11) {
break; break;
} }
length = readCode(correctedBits, startIndex, 11) + 31; length = readCode(correctedBits, startIndex, 11) + 31;
startIndex += 11; startIndex += 11;
} }
@ -227,7 +227,7 @@ Ref<String> Decoder::getEncodedData(Ref<zxing::BitArray> correctedBits) {
end = true; end = true;
break; break;
} }
code = readCode(correctedBits, startIndex, 8); code = readCode(correctedBits, startIndex, 8);
add(result, code); add(result, code);
startIndex += 8; startIndex += 8;
@ -240,27 +240,27 @@ Ref<String> Decoder::getEncodedData(Ref<zxing::BitArray> correctedBits) {
} }
code = readCode(correctedBits, startIndex, 8); code = readCode(correctedBits, startIndex, 8);
startIndex += 8; startIndex += 8;
add(result, code); add(result, code);
} else { } else {
int size = 5; int size = 5;
if (table == DIGIT) { if (table == DIGIT) {
size = 4; size = 4;
} }
if (endIndex - startIndex < size) { if (endIndex - startIndex < size) {
break; break;
} }
code = readCode(correctedBits, startIndex, size); code = readCode(correctedBits, startIndex, size);
startIndex += size; startIndex += size;
const char *str = getCharacter(table, code); const char *str = getCharacter(table, code);
std::string string(str); std::string string(str);
if ((int)string.find("CTRL_") != -1) { if ((int)string.find("CTRL_") != -1) {
table = getTable(str[5]); table = getTable(str[5]);
if (str[6] == 'S') { if (str[6] == 'S') {
shift = true; shift = true;
if (str[5] == 'B') { if (str[5] == 'B') {
@ -270,29 +270,29 @@ Ref<String> Decoder::getEncodedData(Ref<zxing::BitArray> correctedBits) {
} else { } else {
result.append(string); result.append(string);
} }
} }
} }
if (switchShift) { if (switchShift) {
table = lastTable; table = lastTable;
shift = false; shift = false;
switchShift = false; switchShift = false;
} }
} }
return Ref<String>(new String(result)); return Ref<String>(new String(result));
} }
Ref<BitArray> Decoder::correctBits(Ref<zxing::BitArray> rawbits) { Ref<BitArray> Decoder::correctBits(Ref<zxing::BitArray> rawbits) {
//return rawbits; //return rawbits;
// std::printf("decoding stuff:%d datablocks in %d layers\n", ddata_->getNBDatablocks(), ddata_->getNBLayers()); // std::printf("decoding stuff:%d datablocks in %d layers\n", ddata_->getNBDatablocks(), ddata_->getNBLayers());
Ref<GenericGF> gf = GenericGF::AZTEC_DATA_6; Ref<GenericGF> gf = GenericGF::AZTEC_DATA_6;
if (ddata_->getNBLayers() <= 2) { if (ddata_->getNBLayers() <= 2) {
codewordSize_ = 6; codewordSize_ = 6;
gf = GenericGF::AZTEC_DATA_6; gf = GenericGF::AZTEC_DATA_6;
@ -306,11 +306,11 @@ Ref<BitArray> Decoder::correctBits(Ref<zxing::BitArray> rawbits) {
codewordSize_ = 12; codewordSize_ = 12;
gf = GenericGF::AZTEC_DATA_12; gf = GenericGF::AZTEC_DATA_12;
} }
int numDataCodewords = ddata_->getNBDatablocks(); int numDataCodewords = ddata_->getNBDatablocks();
int numECCodewords; int numECCodewords;
int offset; int offset;
if (ddata_->isCompact()) { if (ddata_->isCompact()) {
offset = NB_BITS_COMPACT[ddata_->getNBLayers()] - numCodewords_ * codewordSize_; offset = NB_BITS_COMPACT[ddata_->getNBLayers()] - numCodewords_ * codewordSize_;
numECCodewords = NB_DATABLOCK_COMPACT[ddata_->getNBLayers()] - numDataCodewords; numECCodewords = NB_DATABLOCK_COMPACT[ddata_->getNBLayers()] - numDataCodewords;
@ -318,9 +318,9 @@ Ref<BitArray> Decoder::correctBits(Ref<zxing::BitArray> rawbits) {
offset = NB_BITS[ddata_->getNBLayers()] - numCodewords_ * codewordSize_; offset = NB_BITS[ddata_->getNBLayers()] - numCodewords_ * codewordSize_;
numECCodewords = NB_DATABLOCK[ddata_->getNBLayers()] - numDataCodewords; numECCodewords = NB_DATABLOCK[ddata_->getNBLayers()] - numDataCodewords;
} }
ArrayRef<int> dataWords(numCodewords_); ArrayRef<int> dataWords(numCodewords_);
for (int i = 0; i < numCodewords_; i++) { for (int i = 0; i < numCodewords_; i++) {
int flag = 1; int flag = 1;
for (int j = 1; j <= codewordSize_; j++) { for (int j = 1; j <= codewordSize_; j++) {
@ -329,12 +329,12 @@ Ref<BitArray> Decoder::correctBits(Ref<zxing::BitArray> rawbits) {
} }
flag <<= 1; flag <<= 1;
} }
// //
// //
// //
} }
try { try {
ReedSolomonDecoder rsDecoder(gf); ReedSolomonDecoder rsDecoder(gf);
rsDecoder.decode(dataWords, numECCodewords); rsDecoder.decode(dataWords, numECCodewords);
@ -346,56 +346,56 @@ Ref<BitArray> Decoder::correctBits(Ref<zxing::BitArray> rawbits) {
(void)iae; (void)iae;
// std::printf("illegal argument exception: %s", iae.what()); // std::printf("illegal argument exception: %s", iae.what());
} }
offset = 0; offset = 0;
invertedBitCount_ = 0; invertedBitCount_ = 0;
Ref<BitArray> correctedBits(new BitArray(numDataCodewords * codewordSize_)); Ref<BitArray> correctedBits(new BitArray(numDataCodewords * codewordSize_));
for (int i = 0; i < numDataCodewords; i++) { for (int i = 0; i < numDataCodewords; i++) {
bool seriesColor = false; bool seriesColor = false;
int seriesCount = 0; int seriesCount = 0;
int flag = 1 << (codewordSize_ - 1); int flag = 1 << (codewordSize_ - 1);
for (int j = 0; j < codewordSize_; j++) { for (int j = 0; j < codewordSize_; j++) {
bool color = (dataWords[i] & flag) == flag; bool color = (dataWords[i] & flag) == flag;
if (seriesCount == codewordSize_ - 1) { if (seriesCount == codewordSize_ - 1) {
if (color == seriesColor) { if (color == seriesColor) {
throw FormatException("bit was not inverted"); throw FormatException("bit was not inverted");
} }
seriesColor = false; seriesColor = false;
seriesCount = 0; seriesCount = 0;
offset++; offset++;
invertedBitCount_++; invertedBitCount_++;
} else { } else {
if (seriesColor == color) { if (seriesColor == color) {
seriesCount++; seriesCount++;
} else { } else {
seriesCount = 1; seriesCount = 1;
seriesColor = color; seriesColor = color;
} }
if (color) correctedBits->set(i * codewordSize_ + j - offset); if (color) correctedBits->set(i * codewordSize_ + j - offset);
} }
flag = ((unsigned int)flag) >> 1; flag = ((unsigned int)flag) >> 1;
} }
} }
return correctedBits; return correctedBits;
} }
Ref<BitArray> Decoder::extractBits(Ref<zxing::BitMatrix> matrix) { Ref<BitArray> Decoder::extractBits(Ref<zxing::BitMatrix> matrix) {
std::vector<bool> rawbits; std::vector<bool> rawbits;
if (ddata_->isCompact()) { if (ddata_->isCompact()) {
if (ddata_->getNBLayers() > 5) { //NB_BITS_COMPACT length if (ddata_->getNBLayers() > 5) { //NB_BITS_COMPACT length
throw FormatException("data is too long"); throw FormatException("data is too long");
@ -409,22 +409,22 @@ Ref<BitArray> Decoder::extractBits(Ref<zxing::BitMatrix> matrix) {
rawbits = std::vector<bool>(NB_BITS[ddata_->getNBLayers()]); rawbits = std::vector<bool>(NB_BITS[ddata_->getNBLayers()]);
numCodewords_ = NB_DATABLOCK[ddata_->getNBLayers()]; numCodewords_ = NB_DATABLOCK[ddata_->getNBLayers()];
} }
int layer = ddata_->getNBLayers(); int layer = ddata_->getNBLayers();
int size = matrix->getHeight(); int size = matrix->getHeight();
int rawbitsOffset = 0; int rawbitsOffset = 0;
int matrixOffset = 0; int matrixOffset = 0;
while (layer != 0) { while (layer != 0) {
int flip = 0; int flip = 0;
for (int i = 0; i < 2 * size - 4; i++) { for (int i = 0; i < 2 * size - 4; i++) {
rawbits[rawbitsOffset + i] = matrix->get(matrixOffset + flip, matrixOffset + i / 2); rawbits[rawbitsOffset + i] = matrix->get(matrixOffset + flip, matrixOffset + i / 2);
rawbits[rawbitsOffset + 2 * size - 4 + i] = matrix->get(matrixOffset + i / 2, matrixOffset + size - 1 - flip); rawbits[rawbitsOffset + 2 * size - 4 + i] = matrix->get(matrixOffset + i / 2, matrixOffset + size - 1 - flip);
flip = (flip + 1) % 2; flip = (flip + 1) % 2;
} }
flip = 0; flip = 0;
for (int i = 2 * size + 1; i > 5; i--) { for (int i = 2 * size + 1; i > 5; i--) {
rawbits[rawbitsOffset + 4 * size - 8 + (2 * size - i) + 1] = rawbits[rawbitsOffset + 4 * size - 8 + (2 * size - i) + 1] =
@ -433,63 +433,63 @@ Ref<BitArray> Decoder::extractBits(Ref<zxing::BitMatrix> matrix) {
matrix->get(matrixOffset + i / 2 - 1, matrixOffset + flip); matrix->get(matrixOffset + i / 2 - 1, matrixOffset + flip);
flip = (flip + 1) % 2; flip = (flip + 1) % 2;
} }
matrixOffset += 2; matrixOffset += 2;
rawbitsOffset += 8 * size - 16; rawbitsOffset += 8 * size - 16;
layer--; layer--;
size -= 4; size -= 4;
} }
Ref<BitArray> returnValue(new BitArray(int(rawbits.size()))); Ref<BitArray> returnValue(new BitArray(int(rawbits.size())));
for (int i = 0; i < (int)rawbits.size(); i++) { for (int i = 0; i < (int)rawbits.size(); i++) {
if (rawbits[i]) returnValue->set(i); if (rawbits[i]) returnValue->set(i);
} }
return returnValue; return returnValue;
} }
Ref<BitMatrix> Decoder::removeDashedLines(Ref<zxing::BitMatrix> matrix) { Ref<BitMatrix> Decoder::removeDashedLines(Ref<zxing::BitMatrix> matrix) {
int nbDashed = 1 + 2 * ((matrix->getWidth() - 1) / 2 / 16); int nbDashed = 1 + 2 * ((matrix->getWidth() - 1) / 2 / 16);
Ref<BitMatrix> newMatrix(new BitMatrix(matrix->getWidth() - nbDashed, matrix->getHeight() - nbDashed)); Ref<BitMatrix> newMatrix(new BitMatrix(matrix->getWidth() - nbDashed, matrix->getHeight() - nbDashed));
int nx = 0; int nx = 0;
for (int x = 0; x < (int)matrix->getWidth(); x++) { for (int x = 0; x < (int)matrix->getWidth(); x++) {
if ((matrix->getWidth() / 2 - x) % 16 == 0) { if ((matrix->getWidth() / 2 - x) % 16 == 0) {
continue; continue;
} }
int ny = 0; int ny = 0;
for (int y = 0; y < (int)matrix->getHeight(); y++) { for (int y = 0; y < (int)matrix->getHeight(); y++) {
if ((matrix->getWidth() / 2 - y) % 16 == 0) { if ((matrix->getWidth() / 2 - y) % 16 == 0) {
continue; continue;
} }
if (matrix->get(x, y)) { if (matrix->get(x, y)) {
newMatrix->set(nx, ny); newMatrix->set(nx, ny);
} }
ny++; ny++;
} }
nx++; nx++;
} }
return newMatrix; return newMatrix;
} }
int Decoder::readCode(Ref<zxing::BitArray> rawbits, int startIndex, int length) { int Decoder::readCode(Ref<zxing::BitArray> rawbits, int startIndex, int length) {
int res = 0; int res = 0;
for (int i = startIndex; i < startIndex + length; i++) { for (int i = startIndex; i < startIndex + length; i++) {
res <<= 1; res <<= 1;
if (rawbits->get(i)) { if (rawbits->get(i)) {
res ++; res ++;
} }
} }
return res; return res;
} }

View File

@ -34,7 +34,7 @@ GridSampler::GridSampler() {
Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) { Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<PerspectiveTransform> transform) {
Ref<BitMatrix> bits(new BitMatrix(dimension)); Ref<BitMatrix> bits(new BitMatrix(dimension));
vector<float> points(dimension << 1, (const float)0.0f); vector<float> points(dimension << 1, 0.0f);
for (int y = 0; y < dimension; y++) { for (int y = 0; y < dimension; y++) {
int max = int(points.size()); int max = int(points.size());
float yValue = (float)y + 0.5f; float yValue = (float)y + 0.5f;
@ -55,7 +55,7 @@ Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimension, Ref<
Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimensionX, int dimensionY, Ref<PerspectiveTransform> transform) { Ref<BitMatrix> GridSampler::sampleGrid(Ref<BitMatrix> image, int dimensionX, int dimensionY, Ref<PerspectiveTransform> transform) {
Ref<BitMatrix> bits(new BitMatrix(dimensionX, dimensionY)); Ref<BitMatrix> bits(new BitMatrix(dimensionX, dimensionY));
vector<float> points(dimensionX << 1, (const float)0.0f); vector<float> points(dimensionX << 1, 0.0f);
for (int y = 0; y < dimensionY; y++) { for (int y = 0; y < dimensionY; y++) {
int max = int(points.size()); int max = int(points.size());
float yValue = (float)y + 0.5f; float yValue = (float)y + 0.5f;

View File

@ -36,11 +36,11 @@ Ref<GenericGF> GenericGF::QR_CODE_FIELD_256(new GenericGF(0x011D, 256, 0));
Ref<GenericGF> GenericGF::DATA_MATRIX_FIELD_256(new GenericGF(0x012D, 256, 1)); Ref<GenericGF> GenericGF::DATA_MATRIX_FIELD_256(new GenericGF(0x012D, 256, 1));
Ref<GenericGF> GenericGF::AZTEC_DATA_8 = DATA_MATRIX_FIELD_256; Ref<GenericGF> GenericGF::AZTEC_DATA_8 = DATA_MATRIX_FIELD_256;
Ref<GenericGF> GenericGF::MAXICODE_FIELD_64 = AZTEC_DATA_6; Ref<GenericGF> GenericGF::MAXICODE_FIELD_64 = AZTEC_DATA_6;
namespace { namespace {
size_t INITIALIZATION_THRESHOLD = 0; size_t INITIALIZATION_THRESHOLD = 0;
} }
GenericGF::GenericGF(int primitive_, size_t size_, int b) GenericGF::GenericGF(int primitive_, size_t size_, int b)
: size(size_), primitive(primitive_), generatorBase(b), initialized(false) { : size(size_), primitive(primitive_), generatorBase(b), initialized(false) {
if (size <= INITIALIZATION_THRESHOLD) { if (size <= INITIALIZATION_THRESHOLD) {
@ -56,9 +56,9 @@ GenericGF::~GenericGF()
void GenericGF::initialize() { void GenericGF::initialize() {
expTable = std::vector<int>(size); expTable = std::vector<int>(size);
logTable = std::vector<int>(size); logTable = std::vector<int>(size);
int x = 1; size_t x = 1;
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
expTable[i] = x; expTable[i] = x;
x <<= 1; // x = x * 2; we're assuming the generator alpha is 2 x <<= 1; // x = x * 2; we're assuming the generator alpha is 2
@ -81,26 +81,26 @@ void GenericGF::initialize() {
one = Ref<GenericGFPoly>(new GenericGFPoly(this, coefficients_one)); one = Ref<GenericGFPoly>(new GenericGFPoly(this, coefficients_one));
initialized = true; initialized = true;
} }
void GenericGF::checkInit() { void GenericGF::checkInit() {
if (!initialized) { if (!initialized) {
initialize(); initialize();
} }
} }
Ref<GenericGFPoly> GenericGF::getZero() { Ref<GenericGFPoly> GenericGF::getZero() {
checkInit(); checkInit();
return zero; return zero;
} }
Ref<GenericGFPoly> GenericGF::getOne() { Ref<GenericGFPoly> GenericGF::getOne() {
checkInit(); checkInit();
return one; return one;
} }
Ref<GenericGFPoly> GenericGF::buildMonomial(int degree, int coefficient) { Ref<GenericGFPoly> GenericGF::buildMonomial(int degree, int coefficient) {
checkInit(); checkInit();
if (degree < 0) { if (degree < 0) {
throw IllegalArgumentException("Degree must be non-negative"); throw IllegalArgumentException("Degree must be non-negative");
} }
@ -109,19 +109,19 @@ Ref<GenericGFPoly> GenericGF::buildMonomial(int degree, int coefficient) {
} }
ArrayRef<int> coefficients(degree + 1); ArrayRef<int> coefficients(degree + 1);
coefficients[0] = coefficient; coefficients[0] = coefficient;
return Ref<GenericGFPoly>(new GenericGFPoly(this, coefficients)); return Ref<GenericGFPoly>(new GenericGFPoly(this, coefficients));
} }
int GenericGF::addOrSubtract(int a, int b) { int GenericGF::addOrSubtract(int a, int b) {
return a ^ b; return a ^ b;
} }
int GenericGF::exp(int a) { int GenericGF::exp(int a) {
checkInit(); checkInit();
return expTable[a]; return expTable[a];
} }
int GenericGF::log(int a) { int GenericGF::log(int a) {
checkInit(); checkInit();
if (a == 0) { if (a == 0) {
@ -129,7 +129,7 @@ int GenericGF::log(int a) {
} }
return logTable[a]; return logTable[a];
} }
int GenericGF::inverse(int a) { int GenericGF::inverse(int a) {
checkInit(); checkInit();
if (a == 0) { if (a == 0) {
@ -137,17 +137,17 @@ int GenericGF::inverse(int a) {
} }
return expTable[size - logTable[a] - 1]; return expTable[size - logTable[a] - 1];
} }
int GenericGF::multiply(int a, int b) { int GenericGF::multiply(int a, int b) {
checkInit(); checkInit();
if (a == 0 || b == 0) { if (a == 0 || b == 0) {
return 0; return 0;
} }
return expTable[(logTable[a] + logTable[b]) % (size - 1)]; return expTable[(logTable[a] + logTable[b]) % (size - 1)];
} }
size_t GenericGF::getSize() { size_t GenericGF::getSize() {
return size; return size;
} }

View File

@ -138,7 +138,7 @@ ArrayRef<int> ReedSolomonDecoder::findErrorLocations(Ref<GenericGFPoly> errorLoc
} }
ArrayRef<int> result(new Array<int>(numErrors)); ArrayRef<int> result(new Array<int>(numErrors));
int e = 0; int e = 0;
for (int i = 1; i < field->getSize() && e < numErrors; i++) { for (size_t i = 1; i < field->getSize() && e < numErrors; i++) {
if (errorLocator->evaluateAt(i) == 0) { if (errorLocator->evaluateAt(i) == 0) {
result[e] = field->inverse(i); result[e] = field->inverse(i);
e++; e++;

View File

@ -51,7 +51,7 @@ void ReedSolomonEncoder::encode(std::vector<zxing::byte> &toEncode, int ecBytes)
ArrayRef<int> infoCoefficients(dataBytes); ArrayRef<int> infoCoefficients(dataBytes);
//to-do optimize the following loop //to-do optimize the following loop
for(size_t i=0; i< dataBytes; i++) for(int i=0; i< dataBytes; i++)
infoCoefficients[i] = toEncode[size_t(i)]; infoCoefficients[i] = toEncode[size_t(i)];
Ref<GenericGFPoly> info(new GenericGFPoly(field_, infoCoefficients)); Ref<GenericGFPoly> info(new GenericGFPoly(field_, infoCoefficients));

View File

@ -161,11 +161,11 @@ int Encoder::getAlphanumericCode(int code)
*/ */
Mode Encoder::chooseMode(const std::wstring& content, const std::string& encoding) Mode Encoder::chooseMode(const std::wstring& content, const std::string& encoding)
{ {
if (encoding == "Shift_JIS") if (encoding == "Shift_JIS")
{ {
std::cout << "DEBUG: Shift_JIS detected...be aware!" << std::endl; std::cout << "DEBUG: Shift_JIS detected...be aware!" << std::endl;
return Mode::BYTE; return Mode::BYTE;
} }
bool hasNumeric = false; bool hasNumeric = false;
bool hasAlphanumeric = false; bool hasAlphanumeric = false;
@ -542,7 +542,7 @@ void Encoder::append8BitBytes(const std::wstring& content, BitArray& bits, const
QString str = QString::fromStdWString(content); QString str = QString::fromStdWString(content);
QByteArray array = str.toUtf8(); QByteArray array = str.toUtf8();
for (size_t i=0; i<array.size(); i++) { for (int i=0; i<array.size(); i++) {
bits.appendBits(array.at(i), 8); bits.appendBits(array.at(i), 8);
} }
} }