mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Converted tabs to spaces.
git-svn-id: https://zxing.googlecode.com/svn/trunk@1561 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
7db3546ea6
commit
aca11201ed
|
@ -24,21 +24,21 @@
|
||||||
#include <zxing/Result.h>
|
#include <zxing/Result.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
class EAN13Reader : public UPCEANReader {
|
class EAN13Reader : public UPCEANReader {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool determineFirstDigit(std::string& resultString, int lgPatternFound);
|
static bool determineFirstDigit(std::string& resultString, int lgPatternFound);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EAN13Reader();
|
EAN13Reader();
|
||||||
|
|
||||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||||
std::string& resultString);
|
std::string& resultString);
|
||||||
|
|
||||||
BarcodeFormat getBarcodeFormat();
|
BarcodeFormat getBarcodeFormat();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -24,18 +24,18 @@
|
||||||
#include <zxing/Result.h>
|
#include <zxing/Result.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
class EAN8Reader : public UPCEANReader {
|
class EAN8Reader : public UPCEANReader {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EAN8Reader();
|
EAN8Reader();
|
||||||
|
|
||||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||||
std::string& resultString);
|
std::string& resultString);
|
||||||
|
|
||||||
BarcodeFormat getBarcodeFormat();
|
BarcodeFormat getBarcodeFormat();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
#include <zxing/ReaderException.h>
|
#include <zxing/ReaderException.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() {
|
MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() {
|
||||||
if (hints.containsFormat(BarcodeFormat_EAN_13) ||
|
if (hints.containsFormat(BarcodeFormat_EAN_13) ||
|
||||||
hints.containsFormat(BarcodeFormat_EAN_8) ||
|
hints.containsFormat(BarcodeFormat_EAN_8) ||
|
||||||
hints.containsFormat(BarcodeFormat_UPC_A) ||
|
hints.containsFormat(BarcodeFormat_UPC_A) ||
|
||||||
|
@ -49,18 +49,18 @@ namespace zxing {
|
||||||
readers.push_back(Ref<OneDReader>(new Code128Reader()));
|
readers.push_back(Ref<OneDReader>(new Code128Reader()));
|
||||||
readers.push_back(Ref<OneDReader>(new ITFReader()));
|
readers.push_back(Ref<OneDReader>(new ITFReader()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||||
int size = readers.size();
|
int size = readers.size();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
OneDReader* reader = readers[i];
|
OneDReader* reader = readers[i];
|
||||||
Ref<Result> result = reader->decodeRow(rowNumber, row);
|
Ref<Result> result = reader->decodeRow(rowNumber, row);
|
||||||
if (!result.empty()) {
|
if (!result.empty()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Ref<Result>();
|
return Ref<Result>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,17 +22,17 @@
|
||||||
#include <zxing/oned/OneDReader.h>
|
#include <zxing/oned/OneDReader.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
class MultiFormatOneDReader : public OneDReader {
|
class MultiFormatOneDReader : public OneDReader {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Ref<OneDReader> > readers;
|
std::vector<Ref<OneDReader> > readers;
|
||||||
public:
|
public:
|
||||||
MultiFormatOneDReader(DecodeHints hints);
|
MultiFormatOneDReader(DecodeHints hints);
|
||||||
|
|
||||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -28,60 +28,60 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
|
|
||||||
MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() {
|
MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() {
|
||||||
if (hints.containsFormat(BarcodeFormat_EAN_13)) {
|
if (hints.containsFormat(BarcodeFormat_EAN_13)) {
|
||||||
readers.push_back(Ref<OneDReader>(new EAN13Reader()));
|
readers.push_back(Ref<OneDReader>(new EAN13Reader()));
|
||||||
} else if (hints.containsFormat(BarcodeFormat_UPC_A)) {
|
} else if (hints.containsFormat(BarcodeFormat_UPC_A)) {
|
||||||
readers.push_back(Ref<OneDReader>(new UPCAReader()));
|
readers.push_back(Ref<OneDReader>(new UPCAReader()));
|
||||||
}
|
}
|
||||||
if (hints.containsFormat(BarcodeFormat_EAN_8)) {
|
if (hints.containsFormat(BarcodeFormat_EAN_8)) {
|
||||||
readers.push_back(Ref<OneDReader>(new EAN8Reader()));
|
readers.push_back(Ref<OneDReader>(new EAN8Reader()));
|
||||||
}
|
}
|
||||||
if (hints.containsFormat(BarcodeFormat_UPC_E)) {
|
if (hints.containsFormat(BarcodeFormat_UPC_E)) {
|
||||||
readers.push_back(Ref<OneDReader>(new UPCEReader()));
|
readers.push_back(Ref<OneDReader>(new UPCEReader()));
|
||||||
}
|
}
|
||||||
if (readers.size() == 0) {
|
if (readers.size() == 0) {
|
||||||
readers.push_back(Ref<OneDReader>(new EAN13Reader()));
|
readers.push_back(Ref<OneDReader>(new EAN13Reader()));
|
||||||
// UPC-A is covered by EAN-13
|
// UPC-A is covered by EAN-13
|
||||||
readers.push_back(Ref<OneDReader>(new EAN8Reader()));
|
readers.push_back(Ref<OneDReader>(new EAN8Reader()));
|
||||||
readers.push_back(Ref<OneDReader>(new UPCEReader()));
|
readers.push_back(Ref<OneDReader>(new UPCEReader()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||||
// Compute this location once and reuse it on multiple implementations
|
// Compute this location once and reuse it on multiple implementations
|
||||||
int size = readers.size();
|
int size = readers.size();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
Ref<OneDReader> reader = readers[i];
|
Ref<OneDReader> reader = readers[i];
|
||||||
Ref<Result> result = reader->decodeRow(rowNumber, row);
|
Ref<Result> result = reader->decodeRow(rowNumber, row);
|
||||||
if (result.empty()) {
|
if (result.empty()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special case: a 12-digit code encoded in UPC-A is identical to a "0"
|
// Special case: a 12-digit code encoded in UPC-A is identical to a "0"
|
||||||
// followed by those 12 digits encoded as EAN-13. Each will recognize such a code,
|
// followed by those 12 digits encoded as EAN-13. Each will recognize such a code,
|
||||||
// UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0".
|
// UPC-A as a 12-digit string and EAN-13 as a 13-digit string starting with "0".
|
||||||
// Individually these are correct and their readers will both read such a code
|
// Individually these are correct and their readers will both read such a code
|
||||||
// and correctly call it EAN-13, or UPC-A, respectively.
|
// and correctly call it EAN-13, or UPC-A, respectively.
|
||||||
//
|
//
|
||||||
// In this case, if we've been looking for both types, we'd like to call it
|
// In this case, if we've been looking for both types, we'd like to call it
|
||||||
// a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
|
// a UPC-A code. But for efficiency we only run the EAN-13 decoder to also read
|
||||||
// UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
|
// UPC-A. So we special case it here, and convert an EAN-13 result to a UPC-A
|
||||||
// result if appropriate.
|
// result if appropriate.
|
||||||
if (result->getBarcodeFormat() == BarcodeFormat_EAN_13) {
|
if (result->getBarcodeFormat() == BarcodeFormat_EAN_13) {
|
||||||
const std::string& text = (result->getText())->getText();
|
const std::string& text = (result->getText())->getText();
|
||||||
if (text[0] == '0') {
|
if (text[0] == '0') {
|
||||||
Ref<String> resultString(new String(text.substr(1)));
|
Ref<String> resultString(new String(text.substr(1)));
|
||||||
Ref<Result> res(new Result(resultString, result->getRawBytes(),
|
Ref<Result> res(new Result(resultString, result->getRawBytes(),
|
||||||
result->getResultPoints(), BarcodeFormat_UPC_A));
|
result->getResultPoints(), BarcodeFormat_UPC_A));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return Ref<Result>();
|
return Ref<Result>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,17 +22,17 @@
|
||||||
#include <zxing/oned/OneDReader.h>
|
#include <zxing/oned/OneDReader.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
class MultiFormatUPCEANReader : public OneDReader {
|
class MultiFormatUPCEANReader : public OneDReader {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Ref<OneDReader> > readers;
|
std::vector<Ref<OneDReader> > readers;
|
||||||
public:
|
public:
|
||||||
MultiFormatUPCEANReader(DecodeHints hints);
|
MultiFormatUPCEANReader(DecodeHints hints);
|
||||||
|
|
||||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,43 +21,43 @@
|
||||||
#include <zxing/ReaderException.h>
|
#include <zxing/ReaderException.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
UPCAReader::UPCAReader() : ean13Reader() {
|
UPCAReader::UPCAReader() : ean13Reader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||||
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row));
|
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]) {
|
Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]) {
|
||||||
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange));
|
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Result> UPCAReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
|
Ref<Result> UPCAReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
|
||||||
return maybeReturnResult(ean13Reader.decode(image, hints));
|
return maybeReturnResult(ean13Reader.decode(image, hints));
|
||||||
}
|
}
|
||||||
|
|
||||||
int UPCAReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
int UPCAReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||||
std::string& resultString) {
|
std::string& resultString) {
|
||||||
return ean13Reader.decodeMiddle(row, startRange, startRangeLen, resultString);
|
return ean13Reader.decodeMiddle(row, startRange, startRangeLen, resultString);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Result> UPCAReader::maybeReturnResult(Ref<Result> result) {
|
Ref<Result> UPCAReader::maybeReturnResult(Ref<Result> result) {
|
||||||
if (result.empty()) {
|
if (result.empty()) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
const std::string& text = (result->getText())->getText();
|
const std::string& text = (result->getText())->getText();
|
||||||
if (text[0] == '0') {
|
if (text[0] == '0') {
|
||||||
Ref<String> resultString(new String(text.substr(1)));
|
Ref<String> resultString(new String(text.substr(1)));
|
||||||
Ref<Result> res(new Result(resultString, result->getRawBytes(), result->getResultPoints(),
|
Ref<Result> res(new Result(resultString, result->getRawBytes(), result->getResultPoints(),
|
||||||
BarcodeFormat_UPC_A));
|
BarcodeFormat_UPC_A));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
return Ref<Result>();
|
return Ref<Result>();
|
||||||
}
|
}
|
||||||
|
|
||||||
BarcodeFormat UPCAReader::getBarcodeFormat(){
|
BarcodeFormat UPCAReader::getBarcodeFormat(){
|
||||||
return BarcodeFormat_UPC_A;
|
return BarcodeFormat_UPC_A;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,26 +23,26 @@
|
||||||
#include <zxing/DecodeHints.h>
|
#include <zxing/DecodeHints.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
class UPCAReader : public UPCEANReader {
|
class UPCAReader : public UPCEANReader {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
EAN13Reader ean13Reader;
|
EAN13Reader ean13Reader;
|
||||||
static Ref<Result> maybeReturnResult(Ref<Result> result);
|
static Ref<Result> maybeReturnResult(Ref<Result> result);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UPCAReader();
|
UPCAReader();
|
||||||
|
|
||||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||||
std::string& resultString);
|
std::string& resultString);
|
||||||
|
|
||||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]);
|
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]);
|
||||||
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
|
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
|
||||||
|
|
||||||
BarcodeFormat getBarcodeFormat();
|
BarcodeFormat getBarcodeFormat();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,122 +21,122 @@
|
||||||
#include <zxing/ReaderException.h>
|
#include <zxing/ReaderException.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The pattern that marks the middle, and end, of a UPC-E pattern.
|
* The pattern that marks the middle, and end, of a UPC-E pattern.
|
||||||
* There is no "second half" to a UPC-E barcode.
|
* There is no "second half" to a UPC-E barcode.
|
||||||
*/
|
*/
|
||||||
static const int MIDDLE_END_PATTERN[6] = {1, 1, 1, 1, 1, 1};
|
static const int MIDDLE_END_PATTERN[6] = {1, 1, 1, 1, 1, 1};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See {@link #L_AND_G_PATTERNS}; these values similarly represent patterns of
|
* See {@link #L_AND_G_PATTERNS}; these values similarly represent patterns of
|
||||||
* even-odd parity encodings of digits that imply both the number system (0 or 1)
|
* even-odd parity encodings of digits that imply both the number system (0 or 1)
|
||||||
* used, and the check digit.
|
* used, and the check digit.
|
||||||
*/
|
*/
|
||||||
static const int NUMSYS_AND_CHECK_DIGIT_PATTERNS[2][10] = {
|
static const int NUMSYS_AND_CHECK_DIGIT_PATTERNS[2][10] = {
|
||||||
{0x38, 0x34, 0x32, 0x31, 0x2C, 0x26, 0x23, 0x2A, 0x29, 0x25},
|
{0x38, 0x34, 0x32, 0x31, 0x2C, 0x26, 0x23, 0x2A, 0x29, 0x25},
|
||||||
{0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A}
|
{0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A}
|
||||||
};
|
};
|
||||||
|
|
||||||
UPCEReader::UPCEReader() {
|
UPCEReader::UPCEReader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int UPCEReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
int UPCEReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||||
std::string& resultString) {
|
std::string& resultString) {
|
||||||
const int countersLen = 4;
|
const int countersLen = 4;
|
||||||
int counters[countersLen] = { 0, 0, 0, 0 };
|
int counters[countersLen] = { 0, 0, 0, 0 };
|
||||||
|
|
||||||
int end = row->getSize();
|
int end = row->getSize();
|
||||||
int rowOffset = startRange[1];
|
int rowOffset = startRange[1];
|
||||||
int lgPatternFound = 0;
|
int lgPatternFound = 0;
|
||||||
|
|
||||||
for (int x = 0; x < 6 && rowOffset < end; x++) {
|
for (int x = 0; x < 6 && rowOffset < end; x++) {
|
||||||
int bestMatch = decodeDigit(row, counters, countersLen, rowOffset,
|
int bestMatch = decodeDigit(row, counters, countersLen, rowOffset,
|
||||||
UPC_EAN_PATTERNS_L_AND_G_PATTERNS);
|
UPC_EAN_PATTERNS_L_AND_G_PATTERNS);
|
||||||
if (bestMatch < 0) {
|
if (bestMatch < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
resultString.append(1, (char) ('0' + bestMatch % 10));
|
resultString.append(1, (char) ('0' + bestMatch % 10));
|
||||||
for (int i = 0; i < countersLen; i++) {
|
for (int i = 0; i < countersLen; i++) {
|
||||||
rowOffset += counters[i];
|
rowOffset += counters[i];
|
||||||
}
|
}
|
||||||
if (bestMatch >= 10) {
|
if (bestMatch >= 10) {
|
||||||
lgPatternFound |= 1 << (5 - x);
|
lgPatternFound |= 1 << (5 - x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!determineNumSysAndCheckDigit(resultString, lgPatternFound)) {
|
if (!determineNumSysAndCheckDigit(resultString, lgPatternFound)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return rowOffset;
|
return rowOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int* UPCEReader::decodeEnd(Ref<BitArray> row, int endStart) {
|
int* UPCEReader::decodeEnd(Ref<BitArray> row, int endStart) {
|
||||||
return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN,
|
return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN,
|
||||||
sizeof(MIDDLE_END_PATTERN) / sizeof(int));
|
sizeof(MIDDLE_END_PATTERN) / sizeof(int));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UPCEReader::checkChecksum(std::string s){
|
bool UPCEReader::checkChecksum(std::string s){
|
||||||
return UPCEANReader::checkChecksum(convertUPCEtoUPCA(s));
|
return UPCEANReader::checkChecksum(convertUPCEtoUPCA(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool UPCEReader::determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound) {
|
bool UPCEReader::determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound) {
|
||||||
for (int numSys = 0; numSys <= 1; numSys++) {
|
for (int numSys = 0; numSys <= 1; numSys++) {
|
||||||
for (int d = 0; d < 10; d++) {
|
for (int d = 0; d < 10; d++) {
|
||||||
if (lgPatternFound == NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d]) {
|
if (lgPatternFound == NUMSYS_AND_CHECK_DIGIT_PATTERNS[numSys][d]) {
|
||||||
resultString.insert(0, 1, (char) ('0' + numSys));
|
resultString.insert(0, 1, (char) ('0' + numSys));
|
||||||
resultString.append(1, (char) ('0' + d));
|
resultString.append(1, (char) ('0' + d));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Expands a UPC-E value back into its full, equivalent UPC-A code value.
|
* Expands a UPC-E value back into its full, equivalent UPC-A code value.
|
||||||
*
|
*
|
||||||
* @param upce UPC-E code as string of digits
|
* @param upce UPC-E code as string of digits
|
||||||
* @return equivalent UPC-A code as string of digits
|
* @return equivalent UPC-A code as string of digits
|
||||||
*/
|
*/
|
||||||
std::string UPCEReader::convertUPCEtoUPCA(std::string upce) {
|
std::string UPCEReader::convertUPCEtoUPCA(std::string upce) {
|
||||||
std::string result;
|
std::string result;
|
||||||
result.append(1, upce[0]);
|
result.append(1, upce[0]);
|
||||||
char lastChar = upce[6];
|
char lastChar = upce[6];
|
||||||
switch (lastChar) {
|
switch (lastChar) {
|
||||||
case '0':
|
case '0':
|
||||||
case '1':
|
case '1':
|
||||||
case '2':
|
case '2':
|
||||||
result.append(upce.substr(1,2));
|
result.append(upce.substr(1,2));
|
||||||
result.append(1, lastChar);
|
result.append(1, lastChar);
|
||||||
result.append("0000");
|
result.append("0000");
|
||||||
result.append(upce.substr(3,3));
|
result.append(upce.substr(3,3));
|
||||||
break;
|
break;
|
||||||
case '3':
|
case '3':
|
||||||
result.append(upce.substr(1,3));
|
result.append(upce.substr(1,3));
|
||||||
result.append("00000");
|
result.append("00000");
|
||||||
result.append(upce.substr(4,2));
|
result.append(upce.substr(4,2));
|
||||||
break;
|
break;
|
||||||
case '4':
|
case '4':
|
||||||
result.append(upce.substr(1,4));
|
result.append(upce.substr(1,4));
|
||||||
result.append("00000");
|
result.append("00000");
|
||||||
result.append(1, upce[5]);
|
result.append(1, upce[5]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result.append(upce.substr(1,5));
|
result.append(upce.substr(1,5));
|
||||||
result.append("0000");
|
result.append("0000");
|
||||||
result.append(1, lastChar);
|
result.append(1, lastChar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
result.append(1, upce[7]);
|
result.append(1, upce[7]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BarcodeFormat UPCEReader::getBarcodeFormat() {
|
BarcodeFormat UPCEReader::getBarcodeFormat() {
|
||||||
return BarcodeFormat_UPC_E;
|
return BarcodeFormat_UPC_E;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,24 +24,24 @@
|
||||||
#include <zxing/Result.h>
|
#include <zxing/Result.h>
|
||||||
|
|
||||||
namespace zxing {
|
namespace zxing {
|
||||||
namespace oned {
|
namespace oned {
|
||||||
class UPCEReader : public UPCEANReader {
|
class UPCEReader : public UPCEANReader {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound);
|
static bool determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound);
|
||||||
protected:
|
protected:
|
||||||
int* decodeEnd(Ref<BitArray> row, int endStart);
|
int* decodeEnd(Ref<BitArray> row, int endStart);
|
||||||
bool checkChecksum(std::string s);
|
bool checkChecksum(std::string s);
|
||||||
public:
|
public:
|
||||||
UPCEReader();
|
UPCEReader();
|
||||||
|
|
||||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||||
std::string& resultString);
|
std::string& resultString);
|
||||||
static std::string convertUPCEtoUPCA(std::string upce);
|
static std::string convertUPCEtoUPCA(std::string upce);
|
||||||
|
|
||||||
BarcodeFormat getBarcodeFormat();
|
BarcodeFormat getBarcodeFormat();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue