Issue 396

git-svn-id: https://zxing.googlecode.com/svn/trunk@1333 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
srowen 2010-05-04 09:25:18 +00:00
parent 515f743dc0
commit 4c91a1279a
9 changed files with 99 additions and 24 deletions

View file

@ -49,6 +49,10 @@ namespace zxing {
throw ReaderException("No code detected");
}
MultiFormatReader::~MultiFormatReader(){
int size = readers->size();
for (int i = 0; i < size; i++) {
delete (*readers)[i];
}
delete readers;
}
}

View file

@ -86,12 +86,15 @@ Ref<CornerPoint> MonochromeRectangleDetector::findCornerFromCenter(int centerX,
if (lastRange[1] > centerX) {
// straddle, choose one or the other based on direction
Ref<CornerPoint> result(new CornerPoint(deltaY > 0 ? lastRange[0] : lastRange[1], lastY));
delete [] lastRange;
return result;
}
Ref<CornerPoint> result(new CornerPoint(lastRange[0], lastY));
delete [] lastRange;
return result;
} else {
Ref<CornerPoint> result(new CornerPoint(lastRange[1], lastY));
delete [] lastRange;
return result;
}
} else {
@ -99,19 +102,24 @@ Ref<CornerPoint> MonochromeRectangleDetector::findCornerFromCenter(int centerX,
if (lastRange[0] < centerY) {
if (lastRange[1] > centerY) {
Ref<CornerPoint> result(new CornerPoint(lastX, deltaX < 0 ? lastRange[0] : lastRange[1]));
delete [] lastRange;
return result;
}
Ref<CornerPoint> result(new CornerPoint(lastX, lastRange[0]));
delete [] lastRange;
return result;
} else {
Ref<CornerPoint> result(new CornerPoint(lastX, lastRange[1]));
delete [] lastRange;
return result;
}
}
}
}
delete [] lastRange;
lastRange = range;
}
delete [] lastRange;
throw ReaderException("Couldn't find corners");
}

View file

@ -28,9 +28,9 @@
namespace zxing {
namespace oned {
const int CODE_PATTERNS_LENGHT = 107;
const int countersLenght = 6;
static const int CODE_PATTERNS[CODE_PATTERNS_LENGHT][countersLenght] = {
const int CODE_PATTERNS_LENGTH = 107;
const int countersLength = 6;
static const int CODE_PATTERNS[CODE_PATTERNS_LENGTH][countersLength] = {
{2, 1, 2, 2, 2, 2}, /* 0 */
{2, 2, 2, 1, 2, 2},
{2, 2, 2, 2, 2, 1},
@ -155,7 +155,7 @@ namespace zxing {
}
int counterPosition = 0;
int counters[countersLenght] = {0,0,0,0,0,0};
int counters[countersLength] = {0,0,0,0,0,0};
int patternStart = rowOffset;
bool isWhite = false;
int patternLength = sizeof(counters) / sizeof(int);
@ -206,13 +206,13 @@ namespace zxing {
recordPattern(row, rowOffset, counters, countersCount);
int bestVariance = MAX_AVG_VARIANCE; // worst variance we'll accept
int bestMatch = -1;
for (int d = 0; d < CODE_PATTERNS_LENGHT; d++) {
int pattern[countersLenght];
for (int d = 0; d < CODE_PATTERNS_LENGTH; d++) {
int pattern[countersLength];
for(int ind = 0; ind< countersLenght; ind++){
for(int ind = 0; ind< countersLength; ind++){
pattern[ind] = CODE_PATTERNS[d][ind];
}
// memcpy(pattern, CODE_PATTERNS[d], countersLenght);
// memcpy(pattern, CODE_PATTERNS[d], countersLength);
int variance = patternMatchVariance(counters, countersCount, pattern, MAX_INDIVIDUAL_VARIANCE);
if (variance < bestVariance) {
bestVariance = variance;
@ -243,6 +243,7 @@ namespace zxing {
codeSet = CODE_CODE_C;
break;
default:
delete [] startPatternInfo;
throw ReaderException("");
}
@ -254,7 +255,7 @@ namespace zxing {
int lastStart = startPatternInfo[0];
int nextStart = startPatternInfo[1];
int counters[countersLenght] = {0,0,0,0,0,0};
int counters[countersLength] = {0,0,0,0,0,0};
int lastCode = 0;
int code = 0;
@ -271,7 +272,12 @@ namespace zxing {
lastCode = code;
// Decode another code from image
try {
code = decodeCode(row, counters, sizeof(counters)/sizeof(int), nextStart);
} catch (ReaderException re) {
delete [] startPatternInfo;
throw re;
}
// Remember whether the last code was printable or not (excluding CODE_STOP)
if (code != CODE_STOP) {
@ -286,8 +292,8 @@ namespace zxing {
// Advance to where the next code will to start
lastStart = nextStart;
int _countersLenght = sizeof(counters) / sizeof(int);
for (int i = 0; i < _countersLenght; i++) {
int _countersLength = sizeof(counters) / sizeof(int);
for (int i = 0; i < _countersLength; i++) {
nextStart += counters[i];
}
@ -296,6 +302,7 @@ namespace zxing {
case CODE_START_A:
case CODE_START_B:
case CODE_START_C:
delete [] startPatternInfo;
throw ReaderException("");
}
@ -418,6 +425,7 @@ namespace zxing {
nextStart++;
}
if (!row->isRange(nextStart, fminl(width, nextStart + (nextStart - lastStart) / 2), false)) {
delete [] startPatternInfo;
throw ReaderException("");
}
@ -425,6 +433,7 @@ namespace zxing {
checksumTotal -= multiplier * lastCode;
// lastCode is the checksum then:
if (checksumTotal % 103 != lastCode) {
delete [] startPatternInfo;
throw ReaderException("");
}
@ -444,6 +453,7 @@ namespace zxing {
// String resultString(tmpResultString);
if (tmpResultString.length() == 0) {
delete [] startPatternInfo;
// Almost surely a false positive
throw ReaderException("");
}

View file

@ -94,9 +94,15 @@ namespace zxing {
char decodedChar;
int lastStart;
do {
try {
recordPattern(row, nextStart, counters, countersLen);
} catch (ReaderException re) {
delete [] start;
throw re;
}
int pattern = toNarrowWidePattern(counters, countersLen);
if (pattern < 0) {
delete [] start;
throw ReaderException("pattern < 0");
}
decodedChar = patternToChar(pattern);
@ -117,10 +123,14 @@ namespace zxing {
for (int i = 0; i < countersLen; i++) {
lastPatternSize += counters[i];
}
// IS begin
delete [] counters;
// IS end
int whiteSpaceAfterEnd = nextStart - lastStart - lastPatternSize;
// If 50% of last pattern size, following last pattern, is not whitespace, fail
// (but if it's whitespace to the very end of the image, that's OK)
if (nextStart != end && whiteSpaceAfterEnd / 2 < lastPatternSize) {
delete [] start;
throw ReaderException("too short end white space");
}
@ -146,6 +156,7 @@ namespace zxing {
}
if (tmpResultString.length() == 0) {
delete [] start;
// Almost surely a false positive
throw ReaderException("");
}
@ -216,6 +227,9 @@ namespace zxing {
isWhite = !isWhite;
}
}
// IS begin
delete [] counters;
// IS end
throw ReaderException("");
}

View file

@ -70,10 +70,22 @@ namespace zxing {
Ref<Result> ITFReader::decodeRow(int rowNumber, Ref<BitArray> row){
// Find out where the Middle section (payload) starts & ends
int* startRange = decodeStart(row);
int* endRange = decodeEnd(row);
int* endRange;
try {
endRange = decodeEnd(row);
} catch (Exception e) {
delete [] startRange;
throw e;
}
std::string tmpResult;
try {
decodeMiddle(row, startRange[1], endRange[0], tmpResult);
} catch (zxing::ReaderException re) {
delete [] startRange;
delete [] endRange;
throw re;
}
// To avoid false positives with 2D barcodes (and other patterns), make
// an assumption that the decoded string must be 6, 10 or 14 digits.
@ -83,7 +95,9 @@ namespace zxing {
lengthOK = true;
}
if (!lengthOK) {
throw ReaderException("not enought characters count");
delete [] startRange;
delete [] endRange;
throw ReaderException("not enough characters count");
}
Ref<String> resultString(new String(tmpResult));
@ -116,13 +130,13 @@ namespace zxing {
// Therefore, need to scan 10 lines and then
// split these into two arrays
int counterDigitPairLen = 10;
int* counterDigitPair = new int[counterDigitPairLen];
int counterDigitPair[counterDigitPairLen];
for (int i=0; i<counterDigitPairLen; i++) {
counterDigitPair[i] = 0;
}
int* counterBlack = new int[5];
int* counterWhite = new int[5];
int counterBlack[5];
int counterWhite[5];
for (int i=0; i<5; i++) {
counterBlack[i] = 0;
counterWhite[i] = 0;
@ -147,9 +161,6 @@ namespace zxing {
payloadStart += counterDigitPair[i];
}
}
delete [] counterDigitPair;
delete [] counterBlack;
delete [] counterWhite;
}
/**
@ -278,7 +289,7 @@ namespace zxing {
// TODO: This is very similar to implementation in UPCEANReader. Consider if they can be
// merged to a single method.
int patternLength = patternLen;
int* counters = new int[patternLength];
int counters[patternLength];
for (int i=0; i<patternLength; i++) {
counters[i] = 0;
}

View file

@ -49,6 +49,10 @@ namespace zxing {
throw ReaderException("No code detected");
}
MultiFormatOneDReader::~MultiFormatOneDReader(){
int size = readers->size();
for (int i = 0; i < size; i++) {
delete (*readers)[i];
}
delete readers;
}
}

View file

@ -73,6 +73,10 @@ namespace zxing {
}
MultiFormatUPCEANReader::~MultiFormatUPCEANReader(){
int size = readers->size();
for (int i = 0; i < size; i++) {
delete (*readers)[i];
}
delete readers;
}
}

View file

@ -100,7 +100,16 @@ namespace zxing {
std::string tmpResultString;
std::string& tmpResultStringRef = tmpResultString;
int endStart = decodeMiddle(row, startGuardRange, 2 /*reference findGuardPattern*/ , tmpResultStringRef);
int endStart;
try {
endStart = decodeMiddle(row, startGuardRange, 2 /*reference findGuardPattern*/ , tmpResultStringRef);
} catch (ReaderException re) {
if (startGuardRange!=NULL) {
delete [] startGuardRange;
startGuardRange = NULL;
}
throw re;
}
int* endRange = decodeEnd(row, endStart);
@ -114,6 +123,14 @@ namespace zxing {
// }
if (!checkChecksum(tmpResultString)) {
if (startGuardRange!=NULL) {
delete [] startGuardRange;
startGuardRange = NULL;
}
if (endRange!=NULL) {
delete [] endRange;
endRange = NULL;
}
throw ReaderException("Checksum fail.");
}
@ -159,6 +176,9 @@ namespace zxing {
if (quietStart >= 0) {
foundStart = row->isRange(quietStart, start, false);
}
if (!foundStart) {
delete [] startRange;
}
}
return startRange;
}
@ -217,13 +237,13 @@ 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 paternType){
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
int bestMatch = -1;
int max = 0;
switch (paternType) {
switch (patternType) {
case UPC_EAN_PATTERNS_L_PATTERNS:
max = L_PATTERNS_LEN;
for (int i = 0; i < max; i++) {

View file

@ -54,7 +54,7 @@ namespace zxing {
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row);
Ref<Result> decodeRow(int rowNumber, Ref<BitArray> row, int startGuardRange[]);
static int decodeDigit(Ref<BitArray> row, int counters[], int countersLen, int rowOffset, UPC_EAN_PATTERNS paternType); //throws ReaderException
static int decodeDigit(Ref<BitArray> row, int counters[], int countersLen, int rowOffset, UPC_EAN_PATTERNS patternType); //throws ReaderException
bool checkChecksum(std::string s); //throws ReaderException