Added support to DecoderFormat_CODE_128_GS1

Refactoring on all classes that derive from OneDReader to have DecodeHints as argument to the decodeRow function.
Need to populate the test images and get proper expected values.
#36
This commit is contained in:
favoritas37 2017-06-18 11:17:59 +03:00
parent 06950e3bfe
commit e5b88fc2cb
29 changed files with 114 additions and 80 deletions

View File

@ -126,6 +126,9 @@ QString QZXing::decoderFormatToString(int fmt)
case DecoderFormat_CODE_128:
return "CODE_128";
case DecoderFormat_CODE_128_GS1:
return "CODE_128_GS1";
case DecoderFormat_DATA_MATRIX:
return "DATA_MATRIX";
@ -230,6 +233,12 @@ void QZXing::setDecoder(const uint &hint)
if(hint & DecoderFormat_UPC_EAN_EXTENSION)
newHints |= DecodeHints::UPC_EAN_EXTENSION_HINT;
if(hint & DecoderFormat_CODE_128_GS1)
{
newHints |= DecodeHints::CODE_128_HINT;
newHints |= DecodeHints::ASSUME_GS1;
}
enabledDecoders = newHints;
emit enabledFormatsChanged();

View File

@ -74,7 +74,8 @@ public:
DecoderFormat_RSS_EXPANDED = 1 << 14,
DecoderFormat_UPC_A = 1 << 15,
DecoderFormat_UPC_E = 1 << 16,
DecoderFormat_UPC_EAN_EXTENSION = 1 << 17
DecoderFormat_UPC_EAN_EXTENSION = 1 << 17,
DecoderFormat_CODE_128_GS1 = 1 << 18
} ;
typedef unsigned int DecoderFormatType;

View File

@ -36,5 +36,6 @@ const char* zxing::BarcodeFormat::barcodeFormatNames[] = {
"RSS_EXPANDED",
"UPC_A",
"UPC_E",
"UPC_EAN_EXTENSION"
"UPC_EAN_EXTENSION",
"ASSUME_GS1"
};

View File

@ -24,48 +24,68 @@
using zxing::Ref;
using zxing::ResultPointCallback;
using zxing::DecodeHintType;
using zxing::DecodeHints;
// VC++
using zxing::BarcodeFormat;
//favoritas37-22-01-14-change
#ifndef Q_CC_MSVC
const zxing::DecodeHintType DecodeHints::CHARACTER_SET;
#endif // Q_CC_MSVC
const zxing::DecodeHintType DecodeHints::AZTEC_HINT = 1 << BarcodeFormat::AZTEC;
const zxing::DecodeHintType DecodeHints::CODABAR_HINT = 1 << BarcodeFormat::CODABAR;
const zxing::DecodeHintType DecodeHints::CODE_39_HINT = 1 << BarcodeFormat::CODE_39;
const zxing::DecodeHintType DecodeHints::CODE_93_HINT = 1 << BarcodeFormat::CODE_93;
const zxing::DecodeHintType DecodeHints::CODE_128_HINT = 1 << BarcodeFormat::CODE_128;
const zxing::DecodeHintType DecodeHints::DATA_MATRIX_HINT = 1 << BarcodeFormat::DATA_MATRIX;
const zxing::DecodeHintType DecodeHints::EAN_8_HINT = 1 << BarcodeFormat::EAN_8;
const zxing::DecodeHintType DecodeHints::EAN_13_HINT = 1 << BarcodeFormat::EAN_13;
const zxing::DecodeHintType DecodeHints::ITF_HINT = 1 << BarcodeFormat::ITF;
const zxing::DecodeHintType DecodeHints::MAXICODE_HINT = 1 << BarcodeFormat::MAXICODE;
const zxing::DecodeHintType DecodeHints::PDF_417_HINT = 1 << BarcodeFormat::PDF_417;
const zxing::DecodeHintType DecodeHints::QR_CODE_HINT = 1 << BarcodeFormat::QR_CODE;
const zxing::DecodeHintType DecodeHints::RSS_14_HINT = 1 << BarcodeFormat::RSS_14;
const zxing::DecodeHintType DecodeHints::RSS_EXPANDED_HINT = 1 << BarcodeFormat::RSS_EXPANDED;
const zxing::DecodeHintType DecodeHints::UPC_A_HINT = 1 << BarcodeFormat::UPC_A;
const zxing::DecodeHintType DecodeHints::UPC_E_HINT = 1 << BarcodeFormat::UPC_E;
const zxing::DecodeHintType DecodeHints::UPC_EAN_EXTENSION_HINT = 1 << BarcodeFormat::UPC_EAN_EXTENSION;
const zxing::DecodeHintType DecodeHints::ASSUME_GS1 = 1 << BarcodeFormat::ASSUME_GS1;
const zxing::DecodeHintType DecodeHints::TRYHARDER_HINT = 1 << 31;
const zxing::DecodeHintType DecodeHints::CHARACTER_SET = 1 << 30;
const zxing::DecodeHints DecodeHints::PRODUCT_HINT(
UPC_A_HINT |
UPC_E_HINT |
EAN_13_HINT |
EAN_8_HINT |
RSS_14_HINT
DecodeHints::UPC_A_HINT |
DecodeHints::UPC_E_HINT |
DecodeHints::EAN_13_HINT |
DecodeHints::EAN_8_HINT |
DecodeHints::RSS_14_HINT
);
const zxing::DecodeHints DecodeHints::ONED_HINT(
CODE_39_HINT |
CODE_93_HINT |
CODE_128_HINT |
ITF_HINT |
CODABAR_HINT |
DecodeHints::CODE_39_HINT |
DecodeHints::CODE_93_HINT |
DecodeHints::CODE_128_HINT |
DecodeHints::ITF_HINT |
DecodeHints::CODABAR_HINT |
DecodeHints::PRODUCT_HINT
);
const zxing::DecodeHints DecodeHints::DEFAULT_HINT(
ONED_HINT |
QR_CODE_HINT |
DATA_MATRIX_HINT |
AZTEC_HINT |
PDF_417_HINT
DecodeHints::ONED_HINT |
DecodeHints::QR_CODE_HINT |
DecodeHints::DATA_MATRIX_HINT |
DecodeHints::AZTEC_HINT |
DecodeHints::PDF_417_HINT
);
DecodeHints::DecodeHints() {
hints = 0;
}
DecodeHints::DecodeHints(DecodeHintType init) {
hints = init;
DecodeHints::DecodeHints(const zxing::DecodeHintType &init) {
hints = init;
}
DecodeHints::DecodeHints(const DecodeHints &other) {
hints = other.hints;
callback = other.callback;
}
void DecodeHints::addFormat(BarcodeFormat toadd) {
@ -87,6 +107,7 @@ void DecodeHints::addFormat(BarcodeFormat toadd) {
case BarcodeFormat::UPC_A: hints |= UPC_A_HINT; break;
case BarcodeFormat::UPC_E: hints |= UPC_E_HINT; break;
case BarcodeFormat::UPC_EAN_EXTENSION: hints |= UPC_EAN_EXTENSION_HINT; break;
case BarcodeFormat::ASSUME_GS1: hints |= ASSUME_GS1; break;
default: throw IllegalArgumentException("Unrecognizd barcode format");
}
}
@ -134,7 +155,14 @@ void DecodeHints::setResultPointCallback(Ref<ResultPointCallback> const& _callba
}
Ref<ResultPointCallback> DecodeHints::getResultPointCallback() const {
return callback;
return callback;
}
zxing::DecodeHints &zxing::DecodeHints::operator =(const zxing::DecodeHints &other)
{
hints = other.hints;
callback = other.callback;
return *this;
}
zxing::DecodeHints zxing::operator | (DecodeHints const& l, DecodeHints const& r) {

View File

@ -35,29 +35,29 @@ class DecodeHints {
Ref<ResultPointCallback> callback;
public:
static const DecodeHintType AZTEC_HINT = 1 << BarcodeFormat::AZTEC;
static const DecodeHintType CODABAR_HINT = 1 << BarcodeFormat::CODABAR;
static const DecodeHintType CODE_39_HINT = 1 << BarcodeFormat::CODE_39;
static const DecodeHintType CODE_93_HINT = 1 << BarcodeFormat::CODE_93;
static const DecodeHintType CODE_128_HINT = 1 << BarcodeFormat::CODE_128;
static const DecodeHintType DATA_MATRIX_HINT = 1 << BarcodeFormat::DATA_MATRIX;
static const DecodeHintType EAN_8_HINT = 1 << BarcodeFormat::EAN_8;
static const DecodeHintType EAN_13_HINT = 1 << BarcodeFormat::EAN_13;
static const DecodeHintType ITF_HINT = 1 << BarcodeFormat::ITF;
static const DecodeHintType MAXICODE_HINT = 1 << BarcodeFormat::MAXICODE;
static const DecodeHintType PDF_417_HINT = 1 << BarcodeFormat::PDF_417;
static const DecodeHintType QR_CODE_HINT = 1 << BarcodeFormat::QR_CODE;
static const DecodeHintType RSS_14_HINT = 1 << BarcodeFormat::RSS_14;
static const DecodeHintType RSS_EXPANDED_HINT = 1 << BarcodeFormat::RSS_EXPANDED;
static const DecodeHintType UPC_A_HINT = 1 << BarcodeFormat::UPC_A;
static const DecodeHintType UPC_E_HINT = 1 << BarcodeFormat::UPC_E;
static const DecodeHintType UPC_EAN_EXTENSION_HINT = 1 << BarcodeFormat::UPC_EAN_EXTENSION;
static const DecodeHintType AZTEC_HINT;
static const DecodeHintType CODABAR_HINT;
static const DecodeHintType CODE_39_HINT;
static const DecodeHintType CODE_93_HINT;
static const DecodeHintType CODE_128_HINT;
static const DecodeHintType DATA_MATRIX_HINT;
static const DecodeHintType EAN_8_HINT;
static const DecodeHintType EAN_13_HINT;
static const DecodeHintType ITF_HINT;
static const DecodeHintType MAXICODE_HINT;
static const DecodeHintType PDF_417_HINT;
static const DecodeHintType QR_CODE_HINT;
static const DecodeHintType RSS_14_HINT;
static const DecodeHintType RSS_EXPANDED_HINT;
static const DecodeHintType UPC_A_HINT;
static const DecodeHintType UPC_E_HINT;
static const DecodeHintType UPC_EAN_EXTENSION_HINT;
static const DecodeHintType ASSUME_GS1;
static const DecodeHintType TRYHARDER_HINT = 1 << 31;
static const DecodeHintType CHARACTER_SET = 1 << 30;
static const DecodeHintType TRYHARDER_HINT;
static const DecodeHintType CHARACTER_SET;
// static const DecodeHintType ALLOWED_LENGTHS = 1 << 29;
// static const DecodeHintType ASSUME_CODE_39_CHECK_DIGIT = 1 << 28;
static const DecodeHintType ASSUME_GS1 = 1 << BarcodeFormat::ASSUME_GS1;
// static const DecodeHintType NEED_RESULT_POINT_CALLBACK = 1 << 26;
static const DecodeHints PRODUCT_HINT;
@ -65,7 +65,8 @@ class DecodeHints {
static const DecodeHints DEFAULT_HINT;
DecodeHints();
DecodeHints(DecodeHintType init);
DecodeHints(const DecodeHintType &init);
DecodeHints(const DecodeHints &other);
void addFormat(BarcodeFormat toadd);
bool containsFormat(BarcodeFormat tocheck) const;
@ -77,7 +78,9 @@ class DecodeHints {
void setResultPointCallback(Ref<ResultPointCallback> const&);
Ref<ResultPointCallback> getResultPointCallback() const;
friend DecodeHints operator | (DecodeHints const&, DecodeHints const&);
DecodeHints& operator =(DecodeHints const &other);
friend DecodeHints operator| (DecodeHints const&, DecodeHints const&);
};
}

View File

@ -76,7 +76,7 @@ const int CodaBarReader::PADDING =
CodaBarReader::CodaBarReader()
: counters(80, 0), counterLength(0) {}
Ref<Result> CodaBarReader::decodeRow(int rowNumber, Ref<BitArray> row) {
Ref<Result> CodaBarReader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints /*hints*/) {
{ // Arrays.fill(counters, 0);
int size = counters.size();

View File

@ -37,7 +37,7 @@ private:
public:
CodaBarReader();
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
void validatePattern(int start);

View File

@ -249,9 +249,9 @@ int Code128Reader::decodeCode(Ref<BitArray> row, vector<int>& counters, int rowO
}
}
Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
//bool convertFNC1 = activeHints.containsFormat(zxing::BarcodeFormat(zxing::BarcodeFormat::Value::ASSUME_GS1));
bool convertFNC1 = true;
Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints hints) {
bool convertFNC1 = hints.containsFormat(zxing::BarcodeFormat(zxing::BarcodeFormat::Value::ASSUME_GS1));
vector<int> startPatternInfo (findStartPattern(row));
int startCode = startPatternInfo[2];
int codeSet;

View File

@ -35,7 +35,7 @@ private:
int rowOffset);
public:
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
Code128Reader();
~Code128Reader();

View File

@ -92,7 +92,7 @@ Code39Reader::Code39Reader(bool usingCheckDigit_, bool extendedMode_) {
init(usingCheckDigit_, extendedMode_);
}
Ref<Result> Code39Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
Ref<Result> Code39Reader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints /*hints*/) {
std::vector<int>& theCounters (counters);
{ // Arrays.fill(counters, 0);
int size = theCounters.size();

View File

@ -54,7 +54,7 @@ public:
Code39Reader(bool usingCheckDigit_);
Code39Reader(bool usingCheckDigit_, bool extendedMode_);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
};
}

View File

@ -64,7 +64,7 @@ Code93Reader::Code93Reader() {
counters.resize(6);
}
Ref<Result> Code93Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
Ref<Result> Code93Reader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints /*hints*/) {
Range start (findAsteriskPattern(row));
// Read off white space
int nextStart = row->getNextSet(start[1]);

View File

@ -35,7 +35,7 @@ namespace oned {
class Code93Reader : public OneDReader {
public:
Code93Reader();
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
private:
std::string decodeRowResult;

View File

@ -81,7 +81,7 @@ ITFReader::ITFReader() : narrowLineWidth(-1) {
}
Ref<Result> ITFReader::decodeRow(int rowNumber, Ref<BitArray> row) {
Ref<Result> ITFReader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints /*hints*/) {
// Find out where the Middle section (payload) starts & ends
Range startRange = decodeStart(row);

View File

@ -43,7 +43,7 @@ private:
void append(char* s, char c);
public:
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
ITFReader();
~ITFReader();
};

View File

@ -80,12 +80,12 @@ MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() {
#include <typeinfo>
Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row) {
Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints hints) {
int size = readers.size();
for (int i = 0; i < size; i++) {
OneDReader* reader = readers[i];
try {
Ref<Result> result = reader->decodeRow(rowNumber, row);
Ref<Result> result = reader->decodeRow(rowNumber, row, hints);
return result;
} catch (ReaderException const& re) {
(void)re;

View File

@ -30,7 +30,7 @@ namespace zxing {
public:
MultiFormatOneDReader(DecodeHints hints);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
};
}
}

View File

@ -61,7 +61,7 @@ MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers()
#include <typeinfo>
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row) {
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints /*hints*/) {
// Compute this location once and reuse it on multiple implementations
UPCEANReader::Range startGuardPattern = UPCEANReader::findStartGuardPattern(row);
for (int i = 0, e = readers.size(); i < e; i++) {

View File

@ -32,7 +32,7 @@ private:
std::vector< Ref<UPCEANReader> > readers;
public:
MultiFormatUPCEANReader(DecodeHints hints);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
};
}

View File

@ -35,8 +35,6 @@ using zxing::BinaryBitmap;
using zxing::BitArray;
using zxing::DecodeHints;
OneDReader::OneDReader() {}
Ref<Result> OneDReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
try {
return doDecode(image, hints);
@ -120,13 +118,10 @@ Ref<Result> OneDReader::doDecode(Ref<BinaryBitmap> image, DecodeHints hints) {
row->reverse(); // reverse the row and continue
}
// Java hints stuff missing
activeHints = hints;
try {
// Look for a barcode
// std::cerr << "rn " << rowNumber << " " << typeid(*this).name() << std::endl;
Ref<Result> result = decodeRow(rowNumber, row);
Ref<Result> result = decodeRow(rowNumber, row, hints);
// We found our barcode
if (attempt == 1) {
// But it was upside down, so note that
@ -146,8 +141,6 @@ Ref<Result> OneDReader::doDecode(Ref<BinaryBitmap> image, DecodeHints hints) {
(void)re;
continue;
}
activeHints = DecodeHints();
}
}
throw NotFoundException();

View File

@ -33,7 +33,6 @@ private:
protected:
static const int INTEGER_MATH_SHIFT = 8;
DecodeHints activeHints;
struct Range {
private:
@ -64,12 +63,11 @@ protected:
public:
OneDReader();
virtual Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
// Implementations must not throw any exceptions. If a barcode is not found on this row,
// a empty ref should be returned e.g. return Ref<Result>();
virtual Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row) = 0;
virtual Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints) = 0;
static void recordPattern(Ref<BitArray> row,
int start,

View File

@ -32,8 +32,8 @@ using zxing::DecodeHints;
UPCAReader::UPCAReader() : ean13Reader() {}
Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row) {
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row));
Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints hints) {
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, hints));
}
Ref<Result> UPCAReader::decodeRow(int rowNumber,

View File

@ -37,7 +37,7 @@ public:
int decodeMiddle(Ref<BitArray> row, Range const& startRange, std::string& resultString);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, Range const& startGuardRange);
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);

View File

@ -118,7 +118,7 @@ UPCEANReader::L_AND_G_PATTERNS (VECTOR_INIT(L_AND_G_PATTERNS_));
UPCEANReader::UPCEANReader() {}
Ref<Result> UPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row) {
Ref<Result> UPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row, zxing::DecodeHints /*hints*/) {
return decodeRow(rowNumber, row, findStartGuardPattern(row));
}

View File

@ -66,7 +66,7 @@ public:
Range const& startRange,
std::string& resultString) = 0;
virtual Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
virtual Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, DecodeHints hints);
virtual Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, Range const& range);
static int decodeDigit(Ref<BitArray> row,

View File

Before

Width:  |  Height:  |  Size: 763 KiB

After

Width:  |  Height:  |  Size: 763 KiB

View File

Before

Width:  |  Height:  |  Size: 710 KiB

After

Width:  |  Height:  |  Size: 710 KiB

View File

@ -23,6 +23,7 @@ void DecodeValidator::initializeDecoderCorrelation()
decoderCorrelationMap["code39"] = QZXing::DecoderFormat_CODE_39;
decoderCorrelationMap["code93"] = QZXing::DecoderFormat_CODE_93;
decoderCorrelationMap["code128"] = QZXing::DecoderFormat_CODE_128;
decoderCorrelationMap["code128gs1"] = QZXing::DecoderFormat_CODE_128_GS1;
decoderCorrelationMap["datamatrix"] = QZXing::DecoderFormat_DATA_MATRIX;
decoderCorrelationMap["ean8"] = QZXing::DecoderFormat_EAN_8;
decoderCorrelationMap["ean13"] = QZXing::DecoderFormat_EAN_13;