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
This commit is contained in:
smparkes@smparkes.net 2013-04-23 13:52:11 +00:00
parent 57dc2ca742
commit 71a01f1558
2 changed files with 34 additions and 36 deletions

View file

@ -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) {
}

View file

@ -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<int> DEFAULT_ALLOWED_LENGTHS (new Array<int>(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<int> DEFAULT_ALLOWED_LENGTHS (new Array<int>(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<int> 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<int> 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<int> END_PATTERN_REVERSED (VECTOR_INIT(END_PATTERN_REVERSED_));
const int END_PATTERN_REVERSED_[] = {N, N, W};
const vector<int> 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<int>& 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);