From 71a01f1558aef7d782b79bbeb5a12474a4b6d198 Mon Sep 17 00:00:00 2001 From: "smparkes@smparkes.net" Date: Tue, 23 Apr 2013 13:52:11 +0000 Subject: [PATCH] Remove fixed sizes from C++ itf readers Closes Issue 1672 git-svn-id: https://zxing.googlecode.com/svn/trunk@2684 59b500cc-1b3d-0410-9834-0bbf25fbcc57 --- cpp/core/src/zxing/common/Array.h | 3 ++ cpp/core/src/zxing/oned/ITFReader.cpp | 67 +++++++++++++-------------- 2 files changed, 34 insertions(+), 36 deletions(-) diff --git a/cpp/core/src/zxing/common/Array.h b/cpp/core/src/zxing/common/Array.h index 74499b967..45fc28270 100644 --- a/cpp/core/src/zxing/common/Array.h +++ b/cpp/core/src/zxing/common/Array.h @@ -38,6 +38,9 @@ public: Array(T const* ts, int n) : Counted(), values_(ts, ts+n) { } + Array(T const* ts, T const* te) : + Counted(), values_(ts, te) { + } Array(T v, int n) : Counted(), values_(n, v) { } diff --git a/cpp/core/src/zxing/oned/ITFReader.cpp b/cpp/core/src/zxing/oned/ITFReader.cpp index 4d4ded5dc..4315ac5c8 100644 --- a/cpp/core/src/zxing/oned/ITFReader.cpp +++ b/cpp/core/src/zxing/oned/ITFReader.cpp @@ -40,45 +40,40 @@ using zxing::BitArray; namespace { - const int W = 3; // Pixel width of a wide line - const int N = 1; // Pixed width of a narrow line +const int W = 3; // Pixel width of a wide line +const int N = 1; // Pixed width of a narrow line - const int DEFAULT_ALLOWED_LENGTHS_LEN = 10; - const int DEFAULT_ALLOWED_LENGTHS_[DEFAULT_ALLOWED_LENGTHS_LEN] = - { 48, 44, 24, 20, 18, 16, 14, 12, 10, 8, 6 }; - const ArrayRef DEFAULT_ALLOWED_LENGTHS (new Array(DEFAULT_ALLOWED_LENGTHS_, - DEFAULT_ALLOWED_LENGTHS_LEN )); +const int DEFAULT_ALLOWED_LENGTHS_[] = +{ 48, 44, 24, 20, 18, 16, 14, 12, 10, 8, 6 }; +const ArrayRef DEFAULT_ALLOWED_LENGTHS (new Array(VECTOR_INIT(DEFAULT_ALLOWED_LENGTHS_))); - /** - * Start/end guard pattern. - * - * Note: The end pattern is reversed because the row is reversed before - * searching for the END_PATTERN - */ - const int START_PATTERN_LEN = 4; - const int START_PATTERN_[START_PATTERN_LEN] = {N, N, N, N}; - const vector START_PATTERN (VECTOR_INIT(START_PATTERN_)); +/** + * Start/end guard pattern. + * + * Note: The end pattern is reversed because the row is reversed before + * searching for the END_PATTERN + */ +const int START_PATTERN_[] = {N, N, N, N}; +const vector START_PATTERN (VECTOR_INIT(START_PATTERN_)); - const int END_PATTERN_REVERSED_LEN = 3; - const int END_PATTERN_REVERSED_[END_PATTERN_REVERSED_LEN] = {N, N, W}; - const vector END_PATTERN_REVERSED (VECTOR_INIT(END_PATTERN_REVERSED_)); +const int END_PATTERN_REVERSED_[] = {N, N, W}; +const vector END_PATTERN_REVERSED (VECTOR_INIT(END_PATTERN_REVERSED_)); - /** - * Patterns of Wide / Narrow lines to indicate each digit - */ - const int PATTERNS_LEN = 10; - const int PATTERNS[PATTERNS_LEN][5] = { - {N, N, W, W, N}, // 0 - {W, N, N, N, W}, // 1 - {N, W, N, N, W}, // 2 - {W, W, N, N, N}, // 3 - {N, N, W, N, W}, // 4 - {W, N, W, N, N}, // 5 - {N, W, W, N, N}, // 6 - {N, N, N, W, W}, // 7 - {W, N, N, W, N}, // 8 - {N, W, N, W, N} // 9 - }; +/** + * Patterns of Wide / Narrow lines to indicate each digit + */ +const int PATTERNS[][5] = { + {N, N, W, W, N}, // 0 + {W, N, N, N, W}, // 1 + {N, W, N, N, W}, // 2 + {W, W, N, N, N}, // 3 + {N, N, W, N, W}, // 4 + {W, N, W, N, N}, // 5 + {N, W, W, N, N}, // 6 + {N, N, N, W, W}, // 7 + {W, N, N, W, N}, // 8 + {N, W, N, W, N} // 9 +}; } @@ -323,7 +318,7 @@ int ITFReader::decodeDigit(vector& counters){ int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept int bestMatch = -1; - int max = PATTERNS_LEN; + int max = sizeof(PATTERNS)/sizeof(PATTERNS[0]); for (int i = 0; i < max; i++) { int const* pattern = PATTERNS[i]; int variance = patternMatchVariance(counters, pattern, MAX_INDIVIDUAL_VARIANCE);