mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Fixing some issues in C++ port regarding 1D barcode readers
git-svn-id: https://zxing.googlecode.com/svn/trunk@1454 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
6943578c18
commit
dc9fcff5cb
|
@ -28,7 +28,7 @@ LuminanceSource::LuminanceSource() {
|
|||
LuminanceSource::~LuminanceSource() {
|
||||
}
|
||||
|
||||
unsigned char* LuminanceSource::copyMatrix() const {
|
||||
unsigned char* LuminanceSource::copyMatrix() {
|
||||
int width = getWidth();
|
||||
int height = getHeight();
|
||||
unsigned char* matrix = new unsigned char[width*height];
|
||||
|
|
|
@ -30,11 +30,11 @@ public:
|
|||
LuminanceSource();
|
||||
virtual ~LuminanceSource();
|
||||
|
||||
virtual int getWidth() const = 0;
|
||||
virtual int getHeight() const = 0;
|
||||
virtual int getWidth() = 0;
|
||||
virtual int getHeight() = 0;
|
||||
|
||||
virtual unsigned char getPixel(int x, int y) const = 0;
|
||||
virtual unsigned char* copyMatrix() const;
|
||||
virtual unsigned char getPixel(int x, int y) = 0;
|
||||
virtual unsigned char* copyMatrix();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <zxing/ReaderException.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace zxing {
|
||||
namespace oned {
|
||||
|
@ -166,10 +167,10 @@ namespace zxing {
|
|||
counters[counterPosition]++;
|
||||
} else {
|
||||
if (counterPosition == patternLength - 1) {
|
||||
int bestVariance = MAX_AVG_VARIANCE;
|
||||
unsigned int bestVariance = MAX_AVG_VARIANCE;
|
||||
int bestMatch = -1;
|
||||
for (int startCode = CODE_START_A; startCode <= CODE_START_C; startCode++) {
|
||||
int variance = patternMatchVariance(counters, sizeof(counters)/sizeof(int), CODE_PATTERNS[startCode], MAX_INDIVIDUAL_VARIANCE);
|
||||
unsigned int variance = patternMatchVariance(counters, sizeof(counters)/sizeof(int), CODE_PATTERNS[startCode], MAX_INDIVIDUAL_VARIANCE);
|
||||
if (variance < bestVariance) {
|
||||
bestVariance = variance;
|
||||
bestMatch = startCode;
|
||||
|
@ -204,7 +205,7 @@ namespace zxing {
|
|||
|
||||
int Code128Reader::decodeCode(Ref<BitArray> row, int counters[], int countersCount, int rowOffset){
|
||||
recordPattern(row, rowOffset, counters, countersCount);
|
||||
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
int bestMatch = -1;
|
||||
for (int d = 0; d < CODE_PATTERNS_LENGTH; d++) {
|
||||
int pattern[countersLength];
|
||||
|
@ -213,7 +214,7 @@ namespace zxing {
|
|||
pattern[ind] = CODE_PATTERNS[d][ind];
|
||||
}
|
||||
// memcpy(pattern, CODE_PATTERNS[d], countersLength);
|
||||
int variance = patternMatchVariance(counters, countersCount, pattern, MAX_INDIVIDUAL_VARIANCE);
|
||||
unsigned int variance = patternMatchVariance(counters, countersCount, pattern, MAX_INDIVIDUAL_VARIANCE);
|
||||
if (variance < bestVariance) {
|
||||
bestVariance = variance;
|
||||
bestMatch = d;
|
||||
|
@ -251,7 +252,7 @@ namespace zxing {
|
|||
bool isNextShifted = false;
|
||||
|
||||
std::string tmpResultString;
|
||||
|
||||
std::stringstream tmpResultSStr; // used if its Code 128C
|
||||
|
||||
int lastStart = startPatternInfo[0];
|
||||
int nextStart = startPatternInfo[1];
|
||||
|
@ -373,11 +374,11 @@ namespace zxing {
|
|||
}
|
||||
break;
|
||||
case CODE_CODE_C:
|
||||
// the code read in this case is the number encoded directly
|
||||
if (code < 100) {
|
||||
if (code < 10) {
|
||||
tmpResultString.append(1, '0');
|
||||
}
|
||||
tmpResultString.append(1, code);
|
||||
if (code < 10)
|
||||
tmpResultSStr << '0';
|
||||
tmpResultSStr << code;
|
||||
} else {
|
||||
if (code != CODE_STOP) {
|
||||
lastCharacterWasPrintable = false;
|
||||
|
@ -437,6 +438,9 @@ namespace zxing {
|
|||
throw ReaderException("");
|
||||
}
|
||||
|
||||
if (codeSet == CODE_CODE_C)
|
||||
tmpResultString.append(tmpResultSStr.str());
|
||||
|
||||
// Need to pull out the check digits from string
|
||||
int resultLength = tmpResultString.length();
|
||||
// Only bother if the result had at least one character, and if the checksum digit happened to
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace zxing {
|
|||
class Code128Reader : public OneDReader {
|
||||
|
||||
private:
|
||||
static const int MAX_AVG_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.25f);
|
||||
static const unsigned int MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.25f);
|
||||
static const int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f);
|
||||
|
||||
static const int CODE_SHIFT = 98;
|
||||
|
|
|
@ -237,7 +237,7 @@ namespace zxing {
|
|||
* @throws ReaderException if the quiet zone cannot be found, a ReaderException is thrown.
|
||||
*/
|
||||
void ITFReader::validateQuietZone(Ref<BitArray> row, int startPattern){
|
||||
#pragma mark needs some corrections
|
||||
//#pragma mark needs some corrections
|
||||
// int quietCount = narrowLineWidth * 10; // expect to find this many pixels of quiet zone
|
||||
//
|
||||
// for (int i = startPattern - 1; quietCount > 0 && i >= 0; i--) {
|
||||
|
@ -335,7 +335,7 @@ namespace zxing {
|
|||
* @throws ReaderException if digit cannot be decoded
|
||||
*/
|
||||
int ITFReader::decodeDigit(int counters[], int countersLen){
|
||||
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
int bestMatch = -1;
|
||||
int max = PATTERNS_LEN;
|
||||
for (int i = 0; i < max; i++) {
|
||||
|
@ -343,7 +343,7 @@ namespace zxing {
|
|||
for(int ind = 0; ind<countersLen; ind++){
|
||||
pattern[ind] = PATTERNS[i][ind];
|
||||
}
|
||||
int variance = patternMatchVariance(counters, countersLen, pattern, MAX_INDIVIDUAL_VARIANCE);
|
||||
unsigned int variance = patternMatchVariance(counters, countersLen, pattern, MAX_INDIVIDUAL_VARIANCE);
|
||||
if (variance < bestVariance) {
|
||||
bestVariance = variance;
|
||||
bestMatch = i;
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace zxing {
|
|||
class ITFReader : public OneDReader {
|
||||
|
||||
private:
|
||||
static const int MAX_AVG_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
|
||||
static const unsigned int MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
|
||||
static const int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.8f);
|
||||
|
||||
// Stores the actual narrow line width of the image being decoded.
|
||||
|
|
|
@ -122,10 +122,10 @@ namespace zxing {
|
|||
throw ReaderException("");
|
||||
}
|
||||
|
||||
int OneDReader::patternMatchVariance(int counters[], int countersSize, const int pattern[], int maxIndividualVariance) {
|
||||
unsigned int OneDReader::patternMatchVariance(int counters[], int countersSize, const int pattern[], int maxIndividualVariance) {
|
||||
int numCounters = countersSize;
|
||||
int total = 0;
|
||||
int patternLength = 0;
|
||||
unsigned int total = 0;
|
||||
unsigned int patternLength = 0;
|
||||
for (int i = 0; i < numCounters; i++) {
|
||||
total += counters[i];
|
||||
patternLength += pattern[i];
|
||||
|
@ -138,10 +138,10 @@ namespace zxing {
|
|||
// We're going to fake floating-point math in integers. We just need to use more bits.
|
||||
// Scale up patternLength so that intermediate values below like scaledCounter will have
|
||||
// more "significant digits"
|
||||
int unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength;
|
||||
unsigned int unitBarWidth = (total << INTEGER_MATH_SHIFT) / patternLength;
|
||||
maxIndividualVariance = (maxIndividualVariance * unitBarWidth) >> INTEGER_MATH_SHIFT;
|
||||
|
||||
int totalVariance = 0;
|
||||
unsigned int totalVariance = 0;
|
||||
for (int x = 0; x < numCounters; x++) {
|
||||
int counter = counters[x] << INTEGER_MATH_SHIFT;
|
||||
int scaledPattern = pattern[x] * unitBarWidth;
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace zxing {
|
|||
virtual Ref<Result> decode(Ref<BinaryBitmap> image);
|
||||
virtual Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row) = 0;
|
||||
|
||||
static int patternMatchVariance(int counters[], int countersSize, const int pattern[], int maxIndividualVariance);
|
||||
static unsigned int patternMatchVariance(int counters[], int countersSize, const int pattern[], int maxIndividualVariance);
|
||||
static void recordPattern(Ref<BitArray> row, int start, int counters[], int countersCount);
|
||||
virtual ~OneDReader();
|
||||
};
|
||||
|
|
|
@ -239,7 +239,7 @@ namespace zxing {
|
|||
// int UPCEANReader::decodeDigit(Ref<BitArray> row, int counters[], int countersLen, int rowOffset, int** patterns/*[][]*/, int paterns1Len, int paterns2Len)
|
||||
int UPCEANReader::decodeDigit(Ref<BitArray> row, int counters[], int countersLen, int rowOffset, UPC_EAN_PATTERNS patternType){
|
||||
recordPattern(row, rowOffset, counters, countersLen);
|
||||
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
unsigned int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
|
||||
int bestMatch = -1;
|
||||
|
||||
int max = 0;
|
||||
|
@ -252,7 +252,7 @@ namespace zxing {
|
|||
pattern[j] = L_PATTERNS[i][j];
|
||||
}
|
||||
|
||||
int variance = patternMatchVariance(counters, countersLen, pattern, MAX_INDIVIDUAL_VARIANCE);
|
||||
unsigned int variance = patternMatchVariance(counters, countersLen, pattern, MAX_INDIVIDUAL_VARIANCE);
|
||||
if (variance < bestVariance) {
|
||||
bestVariance = variance;
|
||||
bestMatch = i;
|
||||
|
@ -267,7 +267,7 @@ namespace zxing {
|
|||
pattern[j] = L_AND_G_PATTERNS[i][j];
|
||||
}
|
||||
|
||||
int variance = patternMatchVariance(counters, countersLen, pattern, MAX_INDIVIDUAL_VARIANCE);
|
||||
unsigned int variance = patternMatchVariance(counters, countersLen, pattern, MAX_INDIVIDUAL_VARIANCE);
|
||||
if (variance < bestVariance) {
|
||||
bestVariance = variance;
|
||||
bestMatch = i;
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace zxing {
|
|||
class UPCEANReader : public OneDReader {
|
||||
|
||||
private:
|
||||
static const int MAX_AVG_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
|
||||
static const unsigned int MAX_AVG_VARIANCE = (unsigned int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.42f);
|
||||
static const int MAX_INDIVIDUAL_VARIANCE = (int) (PATTERN_MATCH_RESULT_SCALE_FACTOR * 0.7f);
|
||||
|
||||
static int* findStartGuardPattern(Ref<BitArray> row); //throws ReaderException
|
||||
|
|
Loading…
Reference in a new issue