[SCM] Multi-format 1D/2D barcode image processing library branch, upstream, updated. 24d4480bc48cf9eabf7b2bd2f528248b0e458809

luizcroc luizcroc at 59b500cc-1b3d-0410-9834-0bbf25fbcc57
Wed Aug 4 01:32:21 UTC 2010


The following commit has been merged in the upstream branch:
commit 4430403d20762773119a1db47c0a4c2776d778f1
Author: luizcroc <luizcroc at 59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Date:   Wed Jun 23 03:05:34 2010 +0000

    Fixing some issues in C++ port regarding 1D barcode readers
    
    git-svn-id: http://zxing.googlecode.com/svn/trunk@1454 59b500cc-1b3d-0410-9834-0bbf25fbcc57

diff --git a/cpp/core/src/zxing/LuminanceSource.cpp b/cpp/core/src/zxing/LuminanceSource.cpp
index d7af375..6c8ef1e 100644
--- a/cpp/core/src/zxing/LuminanceSource.cpp
+++ b/cpp/core/src/zxing/LuminanceSource.cpp
@@ -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];
diff --git a/cpp/core/src/zxing/LuminanceSource.h b/cpp/core/src/zxing/LuminanceSource.h
index fcc6588..e23621e 100644
--- a/cpp/core/src/zxing/LuminanceSource.h
+++ b/cpp/core/src/zxing/LuminanceSource.h
@@ -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();
 };
 
 }
diff --git a/cpp/core/src/zxing/oned/Code128Reader.cpp b/cpp/core/src/zxing/oned/Code128Reader.cpp
index 6f638d5..36ab5dc 100644
--- a/cpp/core/src/zxing/oned/Code128Reader.cpp
+++ b/cpp/core/src/zxing/oned/Code128Reader.cpp
@@ -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
diff --git a/cpp/core/src/zxing/oned/Code128Reader.h b/cpp/core/src/zxing/oned/Code128Reader.h
index ad191aa..2b6752e 100644
--- a/cpp/core/src/zxing/oned/Code128Reader.h
+++ b/cpp/core/src/zxing/oned/Code128Reader.h
@@ -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;
diff --git a/cpp/core/src/zxing/oned/ITFReader.cpp b/cpp/core/src/zxing/oned/ITFReader.cpp
index 51a712f..4464326 100644
--- a/cpp/core/src/zxing/oned/ITFReader.cpp
+++ b/cpp/core/src/zxing/oned/ITFReader.cpp
@@ -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;
diff --git a/cpp/core/src/zxing/oned/ITFReader.h b/cpp/core/src/zxing/oned/ITFReader.h
index 759d841..41c22cd 100644
--- a/cpp/core/src/zxing/oned/ITFReader.h
+++ b/cpp/core/src/zxing/oned/ITFReader.h
@@ -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.
diff --git a/cpp/core/src/zxing/oned/OneDReader.cpp b/cpp/core/src/zxing/oned/OneDReader.cpp
index 0b557d6..7610b87 100644
--- a/cpp/core/src/zxing/oned/OneDReader.cpp
+++ b/cpp/core/src/zxing/oned/OneDReader.cpp
@@ -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;
diff --git a/cpp/core/src/zxing/oned/OneDReader.h b/cpp/core/src/zxing/oned/OneDReader.h
index 92a7e77..bb3b649 100644
--- a/cpp/core/src/zxing/oned/OneDReader.h
+++ b/cpp/core/src/zxing/oned/OneDReader.h
@@ -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();
 		};
diff --git a/cpp/core/src/zxing/oned/UPCEANReader.cpp b/cpp/core/src/zxing/oned/UPCEANReader.cpp
index b5923bf..e0154c5 100644
--- a/cpp/core/src/zxing/oned/UPCEANReader.cpp
+++ b/cpp/core/src/zxing/oned/UPCEANReader.cpp
@@ -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;
diff --git a/cpp/core/src/zxing/oned/UPCEANReader.h b/cpp/core/src/zxing/oned/UPCEANReader.h
index d673dc9..6ee2186 100644
--- a/cpp/core/src/zxing/oned/UPCEANReader.h
+++ b/cpp/core/src/zxing/oned/UPCEANReader.h
@@ -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

-- 
Multi-format 1D/2D barcode image processing library



More information about the Pkg-google-commits mailing list