mirror of
https://github.com/zxing/zxing.git
synced 2024-11-10 13:04:05 -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>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
class EAN13Reader : public UPCEANReader {
|
||||
namespace oned {
|
||||
class EAN13Reader : public UPCEANReader {
|
||||
|
||||
private:
|
||||
static bool determineFirstDigit(std::string& resultString, int lgPatternFound);
|
||||
private:
|
||||
static bool determineFirstDigit(std::string& resultString, int lgPatternFound);
|
||||
|
||||
public:
|
||||
EAN13Reader();
|
||||
public:
|
||||
EAN13Reader();
|
||||
|
||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString);
|
||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString);
|
||||
|
||||
BarcodeFormat getBarcodeFormat();
|
||||
};
|
||||
}
|
||||
BarcodeFormat getBarcodeFormat();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,18 +24,18 @@
|
|||
#include <zxing/Result.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
class EAN8Reader : public UPCEANReader {
|
||||
namespace oned {
|
||||
class EAN8Reader : public UPCEANReader {
|
||||
|
||||
public:
|
||||
EAN8Reader();
|
||||
public:
|
||||
EAN8Reader();
|
||||
|
||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString);
|
||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString);
|
||||
|
||||
BarcodeFormat getBarcodeFormat();
|
||||
};
|
||||
}
|
||||
BarcodeFormat getBarcodeFormat();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
#include <zxing/ReaderException.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() {
|
||||
namespace oned {
|
||||
MultiFormatOneDReader::MultiFormatOneDReader(DecodeHints hints) : readers() {
|
||||
if (hints.containsFormat(BarcodeFormat_EAN_13) ||
|
||||
hints.containsFormat(BarcodeFormat_EAN_8) ||
|
||||
hints.containsFormat(BarcodeFormat_UPC_A) ||
|
||||
|
@ -49,18 +49,18 @@ namespace zxing {
|
|||
readers.push_back(Ref<OneDReader>(new Code128Reader()));
|
||||
readers.push_back(Ref<OneDReader>(new ITFReader()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
int size = readers.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
OneDReader* reader = readers[i];
|
||||
Ref<Result> result = reader->decodeRow(rowNumber, row);
|
||||
if (!result.empty()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return Ref<Result>();
|
||||
}
|
||||
}
|
||||
Ref<Result> MultiFormatOneDReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
int size = readers.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
OneDReader* reader = readers[i];
|
||||
Ref<Result> result = reader->decodeRow(rowNumber, row);
|
||||
if (!result.empty()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return Ref<Result>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,17 +22,17 @@
|
|||
#include <zxing/oned/OneDReader.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
class MultiFormatOneDReader : public OneDReader {
|
||||
|
||||
private:
|
||||
std::vector<Ref<OneDReader> > readers;
|
||||
public:
|
||||
MultiFormatOneDReader(DecodeHints hints);
|
||||
|
||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||
};
|
||||
}
|
||||
namespace oned {
|
||||
class MultiFormatOneDReader : public OneDReader {
|
||||
|
||||
private:
|
||||
std::vector<Ref<OneDReader> > readers;
|
||||
public:
|
||||
MultiFormatOneDReader(DecodeHints hints);
|
||||
|
||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -28,60 +28,60 @@
|
|||
#include <math.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
namespace oned {
|
||||
|
||||
MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() {
|
||||
if (hints.containsFormat(BarcodeFormat_EAN_13)) {
|
||||
readers.push_back(Ref<OneDReader>(new EAN13Reader()));
|
||||
} else if (hints.containsFormat(BarcodeFormat_UPC_A)) {
|
||||
readers.push_back(Ref<OneDReader>(new UPCAReader()));
|
||||
}
|
||||
if (hints.containsFormat(BarcodeFormat_EAN_8)) {
|
||||
readers.push_back(Ref<OneDReader>(new EAN8Reader()));
|
||||
}
|
||||
if (hints.containsFormat(BarcodeFormat_UPC_E)) {
|
||||
readers.push_back(Ref<OneDReader>(new UPCEReader()));
|
||||
}
|
||||
if (readers.size() == 0) {
|
||||
readers.push_back(Ref<OneDReader>(new EAN13Reader()));
|
||||
// UPC-A is covered by EAN-13
|
||||
readers.push_back(Ref<OneDReader>(new EAN8Reader()));
|
||||
readers.push_back(Ref<OneDReader>(new UPCEReader()));
|
||||
}
|
||||
}
|
||||
MultiFormatUPCEANReader::MultiFormatUPCEANReader(DecodeHints hints) : readers() {
|
||||
if (hints.containsFormat(BarcodeFormat_EAN_13)) {
|
||||
readers.push_back(Ref<OneDReader>(new EAN13Reader()));
|
||||
} else if (hints.containsFormat(BarcodeFormat_UPC_A)) {
|
||||
readers.push_back(Ref<OneDReader>(new UPCAReader()));
|
||||
}
|
||||
if (hints.containsFormat(BarcodeFormat_EAN_8)) {
|
||||
readers.push_back(Ref<OneDReader>(new EAN8Reader()));
|
||||
}
|
||||
if (hints.containsFormat(BarcodeFormat_UPC_E)) {
|
||||
readers.push_back(Ref<OneDReader>(new UPCEReader()));
|
||||
}
|
||||
if (readers.size() == 0) {
|
||||
readers.push_back(Ref<OneDReader>(new EAN13Reader()));
|
||||
// UPC-A is covered by EAN-13
|
||||
readers.push_back(Ref<OneDReader>(new EAN8Reader()));
|
||||
readers.push_back(Ref<OneDReader>(new UPCEReader()));
|
||||
}
|
||||
}
|
||||
|
||||
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
// Compute this location once and reuse it on multiple implementations
|
||||
int size = readers.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Ref<OneDReader> reader = readers[i];
|
||||
Ref<Result> result = reader->decodeRow(rowNumber, row);
|
||||
if (result.empty()) {
|
||||
continue;
|
||||
}
|
||||
Ref<Result> MultiFormatUPCEANReader::decodeRow(int rowNumber, Ref<BitArray> row) {
|
||||
// Compute this location once and reuse it on multiple implementations
|
||||
int size = readers.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Ref<OneDReader> reader = readers[i];
|
||||
Ref<Result> result = reader->decodeRow(rowNumber, row);
|
||||
if (result.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 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,
|
||||
// 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
|
||||
// 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
|
||||
// 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
|
||||
// result if appropriate.
|
||||
if (result->getBarcodeFormat() == BarcodeFormat_EAN_13) {
|
||||
const std::string& text = (result->getText())->getText();
|
||||
if (text[0] == '0') {
|
||||
Ref<String> resultString(new String(text.substr(1)));
|
||||
Ref<Result> res(new Result(resultString, result->getRawBytes(),
|
||||
result->getResultPoints(), BarcodeFormat_UPC_A));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return Ref<Result>();
|
||||
}
|
||||
}
|
||||
// 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,
|
||||
// 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
|
||||
// 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
|
||||
// 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
|
||||
// result if appropriate.
|
||||
if (result->getBarcodeFormat() == BarcodeFormat_EAN_13) {
|
||||
const std::string& text = (result->getText())->getText();
|
||||
if (text[0] == '0') {
|
||||
Ref<String> resultString(new String(text.substr(1)));
|
||||
Ref<Result> res(new Result(resultString, result->getRawBytes(),
|
||||
result->getResultPoints(), BarcodeFormat_UPC_A));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return Ref<Result>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,21 +18,21 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include <zxing/oned/OneDReader.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
class MultiFormatUPCEANReader : public OneDReader {
|
||||
|
||||
private:
|
||||
std::vector<Ref<OneDReader> > readers;
|
||||
public:
|
||||
MultiFormatUPCEANReader(DecodeHints hints);
|
||||
|
||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||
namespace oned {
|
||||
class MultiFormatUPCEANReader : public OneDReader {
|
||||
|
||||
private:
|
||||
std::vector<Ref<OneDReader> > readers;
|
||||
public:
|
||||
MultiFormatUPCEANReader(DecodeHints hints);
|
||||
|
||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,43 +21,43 @@
|
|||
#include <zxing/ReaderException.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
UPCAReader::UPCAReader() : ean13Reader() {
|
||||
}
|
||||
namespace oned {
|
||||
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) {
|
||||
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row));
|
||||
}
|
||||
|
||||
Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]) {
|
||||
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange));
|
||||
}
|
||||
Ref<Result> UPCAReader::decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]) {
|
||||
return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange));
|
||||
}
|
||||
|
||||
Ref<Result> UPCAReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
|
||||
return maybeReturnResult(ean13Reader.decode(image, hints));
|
||||
}
|
||||
Ref<Result> UPCAReader::decode(Ref<BinaryBitmap> image, DecodeHints hints) {
|
||||
return maybeReturnResult(ean13Reader.decode(image, hints));
|
||||
}
|
||||
|
||||
int UPCAReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString) {
|
||||
return ean13Reader.decodeMiddle(row, startRange, startRangeLen, resultString);
|
||||
}
|
||||
int UPCAReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString) {
|
||||
return ean13Reader.decodeMiddle(row, startRange, startRangeLen, resultString);
|
||||
}
|
||||
|
||||
Ref<Result> UPCAReader::maybeReturnResult(Ref<Result> result) {
|
||||
if (result.empty()) {
|
||||
return result;
|
||||
}
|
||||
const std::string& text = (result->getText())->getText();
|
||||
if (text[0] == '0') {
|
||||
Ref<String> resultString(new String(text.substr(1)));
|
||||
Ref<Result> res(new Result(resultString, result->getRawBytes(), result->getResultPoints(),
|
||||
BarcodeFormat_UPC_A));
|
||||
return res;
|
||||
}
|
||||
return Ref<Result>();
|
||||
}
|
||||
Ref<Result> UPCAReader::maybeReturnResult(Ref<Result> result) {
|
||||
if (result.empty()) {
|
||||
return result;
|
||||
}
|
||||
const std::string& text = (result->getText())->getText();
|
||||
if (text[0] == '0') {
|
||||
Ref<String> resultString(new String(text.substr(1)));
|
||||
Ref<Result> res(new Result(resultString, result->getRawBytes(), result->getResultPoints(),
|
||||
BarcodeFormat_UPC_A));
|
||||
return res;
|
||||
}
|
||||
return Ref<Result>();
|
||||
}
|
||||
|
||||
BarcodeFormat UPCAReader::getBarcodeFormat(){
|
||||
return BarcodeFormat_UPC_A;
|
||||
}
|
||||
}
|
||||
BarcodeFormat UPCAReader::getBarcodeFormat(){
|
||||
return BarcodeFormat_UPC_A;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,26 +23,26 @@
|
|||
#include <zxing/DecodeHints.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
class UPCAReader : public UPCEANReader {
|
||||
namespace oned {
|
||||
class UPCAReader : public UPCEANReader {
|
||||
|
||||
private:
|
||||
EAN13Reader ean13Reader;
|
||||
static Ref<Result> maybeReturnResult(Ref<Result> result);
|
||||
private:
|
||||
EAN13Reader ean13Reader;
|
||||
static Ref<Result> maybeReturnResult(Ref<Result> result);
|
||||
|
||||
public:
|
||||
UPCAReader();
|
||||
public:
|
||||
UPCAReader();
|
||||
|
||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString);
|
||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString);
|
||||
|
||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]);
|
||||
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
|
||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
|
||||
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]);
|
||||
Ref<Result> decode(Ref<BinaryBitmap> image, DecodeHints hints);
|
||||
|
||||
BarcodeFormat getBarcodeFormat();
|
||||
};
|
||||
}
|
||||
BarcodeFormat getBarcodeFormat();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,122 +21,122 @@
|
|||
#include <zxing/ReaderException.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
namespace oned {
|
||||
|
||||
/**
|
||||
* The pattern that marks the middle, and end, of a UPC-E pattern.
|
||||
* There is no "second half" to a UPC-E barcode.
|
||||
*/
|
||||
static const int MIDDLE_END_PATTERN[6] = {1, 1, 1, 1, 1, 1};
|
||||
/**
|
||||
* The pattern that marks the middle, and end, of a UPC-E pattern.
|
||||
* There is no "second half" to a UPC-E barcode.
|
||||
*/
|
||||
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
|
||||
* even-odd parity encodings of digits that imply both the number system (0 or 1)
|
||||
* used, and the check digit.
|
||||
*/
|
||||
static const int NUMSYS_AND_CHECK_DIGIT_PATTERNS[2][10] = {
|
||||
{0x38, 0x34, 0x32, 0x31, 0x2C, 0x26, 0x23, 0x2A, 0x29, 0x25},
|
||||
{0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A}
|
||||
};
|
||||
/**
|
||||
* 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)
|
||||
* used, and the check digit.
|
||||
*/
|
||||
static const int NUMSYS_AND_CHECK_DIGIT_PATTERNS[2][10] = {
|
||||
{0x38, 0x34, 0x32, 0x31, 0x2C, 0x26, 0x23, 0x2A, 0x29, 0x25},
|
||||
{0x07, 0x0B, 0x0D, 0x0E, 0x13, 0x19, 0x1C, 0x15, 0x16, 0x1A}
|
||||
};
|
||||
|
||||
UPCEReader::UPCEReader() {
|
||||
}
|
||||
UPCEReader::UPCEReader() {
|
||||
}
|
||||
|
||||
int UPCEReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString) {
|
||||
const int countersLen = 4;
|
||||
int counters[countersLen] = { 0, 0, 0, 0 };
|
||||
int UPCEReader::decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString) {
|
||||
const int countersLen = 4;
|
||||
int counters[countersLen] = { 0, 0, 0, 0 };
|
||||
|
||||
int end = row->getSize();
|
||||
int rowOffset = startRange[1];
|
||||
int lgPatternFound = 0;
|
||||
int end = row->getSize();
|
||||
int rowOffset = startRange[1];
|
||||
int lgPatternFound = 0;
|
||||
|
||||
for (int x = 0; x < 6 && rowOffset < end; x++) {
|
||||
int bestMatch = decodeDigit(row, counters, countersLen, rowOffset,
|
||||
UPC_EAN_PATTERNS_L_AND_G_PATTERNS);
|
||||
if (bestMatch < 0) {
|
||||
for (int x = 0; x < 6 && rowOffset < end; x++) {
|
||||
int bestMatch = decodeDigit(row, counters, countersLen, rowOffset,
|
||||
UPC_EAN_PATTERNS_L_AND_G_PATTERNS);
|
||||
if (bestMatch < 0) {
|
||||
return -1;
|
||||
}
|
||||
resultString.append(1, (char) ('0' + bestMatch % 10));
|
||||
for (int i = 0; i < countersLen; i++) {
|
||||
rowOffset += counters[i];
|
||||
}
|
||||
if (bestMatch >= 10) {
|
||||
lgPatternFound |= 1 << (5 - x);
|
||||
}
|
||||
}
|
||||
resultString.append(1, (char) ('0' + bestMatch % 10));
|
||||
for (int i = 0; i < countersLen; i++) {
|
||||
rowOffset += counters[i];
|
||||
}
|
||||
if (bestMatch >= 10) {
|
||||
lgPatternFound |= 1 << (5 - x);
|
||||
}
|
||||
}
|
||||
|
||||
if (!determineNumSysAndCheckDigit(resultString, lgPatternFound)) {
|
||||
if (!determineNumSysAndCheckDigit(resultString, lgPatternFound)) {
|
||||
return -1;
|
||||
}
|
||||
return rowOffset;
|
||||
}
|
||||
return rowOffset;
|
||||
}
|
||||
|
||||
int* UPCEReader::decodeEnd(Ref<BitArray> row, int endStart) {
|
||||
return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN,
|
||||
sizeof(MIDDLE_END_PATTERN) / sizeof(int));
|
||||
}
|
||||
int* UPCEReader::decodeEnd(Ref<BitArray> row, int endStart) {
|
||||
return findGuardPattern(row, endStart, true, MIDDLE_END_PATTERN,
|
||||
sizeof(MIDDLE_END_PATTERN) / sizeof(int));
|
||||
}
|
||||
|
||||
bool UPCEReader::checkChecksum(std::string s){
|
||||
return UPCEANReader::checkChecksum(convertUPCEtoUPCA(s));
|
||||
}
|
||||
bool UPCEReader::checkChecksum(std::string s){
|
||||
return UPCEANReader::checkChecksum(convertUPCEtoUPCA(s));
|
||||
}
|
||||
|
||||
|
||||
bool UPCEReader::determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound) {
|
||||
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(0, 1, (char) ('0' + numSys));
|
||||
resultString.append(1, (char) ('0' + d));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool UPCEReader::determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound) {
|
||||
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(0, 1, (char) ('0' + numSys));
|
||||
resultString.append(1, (char) ('0' + d));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands a UPC-E value back into its full, equivalent UPC-A code value.
|
||||
*
|
||||
* @param upce UPC-E code as string of digits
|
||||
* @return equivalent UPC-A code as string of digits
|
||||
*/
|
||||
std::string UPCEReader::convertUPCEtoUPCA(std::string upce) {
|
||||
std::string result;
|
||||
result.append(1, upce[0]);
|
||||
char lastChar = upce[6];
|
||||
switch (lastChar) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
result.append(upce.substr(1,2));
|
||||
result.append(1, lastChar);
|
||||
result.append("0000");
|
||||
result.append(upce.substr(3,3));
|
||||
break;
|
||||
case '3':
|
||||
result.append(upce.substr(1,3));
|
||||
result.append("00000");
|
||||
result.append(upce.substr(4,2));
|
||||
break;
|
||||
case '4':
|
||||
result.append(upce.substr(1,4));
|
||||
result.append("00000");
|
||||
result.append(1, upce[5]);
|
||||
break;
|
||||
default:
|
||||
result.append(upce.substr(1,5));
|
||||
result.append("0000");
|
||||
result.append(1, lastChar);
|
||||
break;
|
||||
}
|
||||
result.append(1, upce[7]);
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* Expands a UPC-E value back into its full, equivalent UPC-A code value.
|
||||
*
|
||||
* @param upce UPC-E code as string of digits
|
||||
* @return equivalent UPC-A code as string of digits
|
||||
*/
|
||||
std::string UPCEReader::convertUPCEtoUPCA(std::string upce) {
|
||||
std::string result;
|
||||
result.append(1, upce[0]);
|
||||
char lastChar = upce[6];
|
||||
switch (lastChar) {
|
||||
case '0':
|
||||
case '1':
|
||||
case '2':
|
||||
result.append(upce.substr(1,2));
|
||||
result.append(1, lastChar);
|
||||
result.append("0000");
|
||||
result.append(upce.substr(3,3));
|
||||
break;
|
||||
case '3':
|
||||
result.append(upce.substr(1,3));
|
||||
result.append("00000");
|
||||
result.append(upce.substr(4,2));
|
||||
break;
|
||||
case '4':
|
||||
result.append(upce.substr(1,4));
|
||||
result.append("00000");
|
||||
result.append(1, upce[5]);
|
||||
break;
|
||||
default:
|
||||
result.append(upce.substr(1,5));
|
||||
result.append("0000");
|
||||
result.append(1, lastChar);
|
||||
break;
|
||||
}
|
||||
result.append(1, upce[7]);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
BarcodeFormat UPCEReader::getBarcodeFormat() {
|
||||
return BarcodeFormat_UPC_E;
|
||||
}
|
||||
}
|
||||
BarcodeFormat UPCEReader::getBarcodeFormat() {
|
||||
return BarcodeFormat_UPC_E;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,24 +24,24 @@
|
|||
#include <zxing/Result.h>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
class UPCEReader : public UPCEANReader {
|
||||
namespace oned {
|
||||
class UPCEReader : public UPCEANReader {
|
||||
|
||||
private:
|
||||
static bool determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound);
|
||||
protected:
|
||||
int* decodeEnd(Ref<BitArray> row, int endStart);
|
||||
bool checkChecksum(std::string s);
|
||||
public:
|
||||
UPCEReader();
|
||||
private:
|
||||
static bool determineNumSysAndCheckDigit(std::string& resultString, int lgPatternFound);
|
||||
protected:
|
||||
int* decodeEnd(Ref<BitArray> row, int endStart);
|
||||
bool checkChecksum(std::string s);
|
||||
public:
|
||||
UPCEReader();
|
||||
|
||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString);
|
||||
static std::string convertUPCEtoUPCA(std::string upce);
|
||||
int decodeMiddle(Ref<BitArray> row, int startRange[], int startRangeLen,
|
||||
std::string& resultString);
|
||||
static std::string convertUPCEtoUPCA(std::string upce);
|
||||
|
||||
BarcodeFormat getBarcodeFormat();
|
||||
};
|
||||
}
|
||||
BarcodeFormat getBarcodeFormat();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue