ported implementation of Code128Reader from current zxing implementation in the hope that GS1 separators will be functional. Partially successful but not finished. #36

This commit is contained in:
favoritas37 2017-06-13 21:34:04 +03:00
parent fbc505c3f2
commit 6307040787
9 changed files with 74 additions and 11 deletions

View File

@ -45,7 +45,8 @@ public:
RSS_EXPANDED,
UPC_A,
UPC_E,
UPC_EAN_EXTENSION
UPC_EAN_EXTENSION,
ASSUME_GS1
};
BarcodeFormat(Value v) : value(v) {}

View File

@ -111,6 +111,7 @@ bool DecodeHints::containsFormat(BarcodeFormat tocheck) const {
case BarcodeFormat::UPC_A: checkAgainst |= UPC_A_HINT; break;
case BarcodeFormat::UPC_E: checkAgainst |= UPC_E_HINT; break;
case BarcodeFormat::UPC_EAN_EXTENSION: checkAgainst |= UPC_EAN_EXTENSION_HINT; break;
case BarcodeFormat::ASSUME_GS1: checkAgainst |= ASSUME_GS1; break;
default: throw IllegalArgumentException("Unrecognizd barcode format");
}
return (hints & checkAgainst) != 0;

View File

@ -57,7 +57,7 @@ class DecodeHints {
static const DecodeHintType CHARACTER_SET = 1 << 30;
// static const DecodeHintType ALLOWED_LENGTHS = 1 << 29;
// static const DecodeHintType ASSUME_CODE_39_CHECK_DIGIT = 1 << 28;
static const DecodeHintType ASSUME_GS1 = 1 << 27;
static const DecodeHintType ASSUME_GS1 = 1 << BarcodeFormat::ASSUME_GS1;
// static const DecodeHintType NEED_RESULT_POINT_CALLBACK = 1 << 26;
static const DecodeHints PRODUCT_HINT;

View File

@ -23,6 +23,8 @@
#include <zxing/NotFoundException.h>
#include <zxing/FormatException.h>
#include <zxing/ChecksumException.h>
#include <zxing/DecodeHints.h>
#include <zxing/BarcodeFormat.h>
#include <math.h>
#include <string.h>
#include <sstream>
@ -248,8 +250,8 @@ int Code128Reader::decodeCode(Ref<BitArray> row, vector<int>& counters, int rowO
}
Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
// boolean convertFNC1 = hints != null && hints.containsKey(DecodeHintType.ASSUME_GS1);
boolean convertFNC1 = false;
//bool convertFNC1 = activeHints.containsFormat(zxing::BarcodeFormat(zxing::BarcodeFormat::Value::ASSUME_GS1));
bool convertFNC1 = true;
vector<int> startPatternInfo (findStartPattern(row));
int startCode = startPatternInfo[2];
int codeSet;
@ -282,6 +284,8 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
int checksumTotal = startCode;
int multiplier = 0;
bool lastCharacterWasPrintable = true;
bool upperMode = false;
bool shiftUpperMode = false;
std::ostringstream oss;
@ -324,9 +328,19 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
case CODE_CODE_A:
if (code < 64) {
result.append(1, (byte) (' ' + code));
if (shiftUpperMode == upperMode) {
result.append(1,(byte) (' ' + code));
} else {
result.append(1,(byte) (' ' + code + 128));
}
shiftUpperMode = false;
} else if (code < 96) {
result.append(1, (byte) (code - 64));
if (shiftUpperMode == upperMode) {
result.append(1, (byte) (code - 64));
} else {
result.append(1, (byte) (code + 64));
}
shiftUpperMode = false;
} else {
// Don't let CODE_STOP, which always appears, affect whether whether we think the
// last code was printable or not.
@ -348,8 +362,17 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
break;
case CODE_FNC_2:
case CODE_FNC_3:
break;
case CODE_FNC_4_A:
// do nothing?
if (!upperMode && shiftUpperMode) {
upperMode = true;
shiftUpperMode = false;
} else if (upperMode && shiftUpperMode) {
upperMode = false;
shiftUpperMode = false;
} else {
shiftUpperMode = true;
}
break;
case CODE_SHIFT:
isNextShifted = true;
@ -369,17 +392,41 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
break;
case CODE_CODE_B:
if (code < 96) {
result.append(1, (byte) (' ' + code));
if (shiftUpperMode == upperMode) {
result.append(1, (byte) (' ' + code));
} else {
result.append(1, (byte) (' ' + code + 128));
}
shiftUpperMode = false;
} else {
if (code != CODE_STOP) {
lastCharacterWasPrintable = false;
}
switch (code) {
case CODE_FNC_1:
case CODE_FNC_1:
if (convertFNC1) {
if (result.length() == 0) {
// GS1 specification 5.4.3.7. and 5.4.6.4. If the first char after the start code
// is FNC1 then this is GS1-128. We add the symbology identifier.
result.append("]C1");
} else {
// GS1 specification 5.4.7.5. Every subsequent FNC1 is returned as ASCII 29 (GS)
result.append(1, (byte) 29);
}
}
break;
case CODE_FNC_2:
case CODE_FNC_3:
case CODE_FNC_4_B:
// do nothing?
if (!upperMode && shiftUpperMode) {
upperMode = true;
shiftUpperMode = false;
} else if (upperMode && shiftUpperMode) {
upperMode = false;
shiftUpperMode = false;
} else {
shiftUpperMode = true;
}
break;
case CODE_SHIFT:
isNextShifted = true;
@ -412,7 +459,16 @@ Ref<Result> Code128Reader::decodeRow(int rowNumber, Ref<BitArray> row) {
}
switch (code) {
case CODE_FNC_1:
// do nothing?
if (convertFNC1) {
if (result.length() == 0) {
// GS1 specification 5.4.3.7. and 5.4.6.4. If the first char after the start code
// is FNC1 then this is GS1-128. We add the symbology identifier.
result.append("]C1");
} else {
// GS1 specification 5.4.7.5. Every subsequent FNC1 is returned as ASCII 29 (GS)
result.append(1, (byte) 29);
}
}
break;
case CODE_CODE_A:
codeSet = CODE_CODE_A;

View File

@ -121,6 +121,7 @@ Ref<Result> OneDReader::doDecode(Ref<BinaryBitmap> image, DecodeHints hints) {
}
// Java hints stuff missing
activeHints = hints;
try {
// Look for a barcode
@ -145,6 +146,8 @@ Ref<Result> OneDReader::doDecode(Ref<BinaryBitmap> image, DecodeHints hints) {
(void)re;
continue;
}
activeHints = DecodeHints();
}
}
throw NotFoundException();

View File

@ -22,6 +22,7 @@
*/
#include <zxing/Reader.h>
#include <zxing/DecodeHints.h>
namespace zxing {
namespace oned {
@ -32,6 +33,7 @@ private:
protected:
static const int INTEGER_MATH_SHIFT = 8;
DecodeHints activeHints;
struct Range {
private:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 763 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 KiB