mirror of
https://github.com/zxing/zxing.git
synced 2025-03-05 20:48:51 -08:00
Issue #116 add range check and simplify some conditions
This commit is contained in:
parent
41caac38e8
commit
7d878d701e
|
@ -241,34 +241,34 @@ public class FinderPatternFinder {
|
||||||
* @return true if proportions are withing expected limits
|
* @return true if proportions are withing expected limits
|
||||||
*/
|
*/
|
||||||
private boolean crossCheckDiagonal(int startI, int centerJ, int maxCount, int originalStateCountTotal) {
|
private boolean crossCheckDiagonal(int startI, int centerJ, int maxCount, int originalStateCountTotal) {
|
||||||
int maxI = image.getHeight();
|
|
||||||
int maxJ = image.getWidth();
|
|
||||||
int[] stateCount = getCrossCheckStateCount();
|
int[] stateCount = getCrossCheckStateCount();
|
||||||
|
|
||||||
// Start counting up, left from center finding black center mass
|
// Start counting up, left from center finding black center mass
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (startI - i >= 0 && image.get(centerJ - i, startI - i)) {
|
while (startI >= i && centerJ >= i && image.get(centerJ - i, startI - i)) {
|
||||||
stateCount[2]++;
|
stateCount[2]++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((startI - i < 0) || (centerJ - i < 0)) {
|
if (startI < i || centerJ < i) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue up, left finding white space
|
// Continue up, left finding white space
|
||||||
while ((startI - i >= 0) && (centerJ - i >= 0) && !image.get(centerJ - i, startI - i) && stateCount[1] <= maxCount) {
|
while (startI >= i && centerJ >= i && !image.get(centerJ - i, startI - i) &&
|
||||||
|
stateCount[1] <= maxCount) {
|
||||||
stateCount[1]++;
|
stateCount[1]++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If already too many modules in this state or ran off the edge:
|
// If already too many modules in this state or ran off the edge:
|
||||||
if ((startI - i < 0) || (centerJ - i < 0) || stateCount[1] > maxCount) {
|
if (startI < i || centerJ < i || stateCount[1] > maxCount) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue up, left finding black border
|
// Continue up, left finding black border
|
||||||
while ((startI - i >= 0) && (centerJ - i >= 0) && image.get(centerJ - i, startI - i) && stateCount[0] <= maxCount) {
|
while (startI >= i && centerJ >= i && image.get(centerJ - i, startI - i) &&
|
||||||
|
stateCount[0] <= maxCount) {
|
||||||
stateCount[0]++;
|
stateCount[0]++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -276,28 +276,33 @@ public class FinderPatternFinder {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int maxI = image.getHeight();
|
||||||
|
int maxJ = image.getWidth();
|
||||||
|
|
||||||
// Now also count down, right from center
|
// Now also count down, right from center
|
||||||
i = 1;
|
i = 1;
|
||||||
while ((startI + i < maxI) && (centerJ + i < maxJ) && image.get(centerJ + i, startI + i)) {
|
while (startI + i < maxI && centerJ + i < maxJ && image.get(centerJ + i, startI + i)) {
|
||||||
stateCount[2]++;
|
stateCount[2]++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ran off the edge?
|
// Ran off the edge?
|
||||||
if ((startI + i >= maxI) || (centerJ + i >= maxJ)) {
|
if (startI + i >= maxI || centerJ + i >= maxJ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((startI + i < maxI) && (centerJ + i < maxJ) && !image.get(centerJ + i, startI + i) && stateCount[3] < maxCount) {
|
while (startI + i < maxI && centerJ + i < maxJ && !image.get(centerJ + i, startI + i) &&
|
||||||
|
stateCount[3] < maxCount) {
|
||||||
stateCount[3]++;
|
stateCount[3]++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((startI + i >= maxI) || (centerJ + i >= maxJ) || stateCount[3] >= maxCount) {
|
if (startI + i >= maxI || centerJ + i >= maxJ || stateCount[3] >= maxCount) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((startI + i < maxI) && (centerJ + i < maxJ) && image.get(centerJ + i, startI + i) && stateCount[4] < maxCount) {
|
while (startI + i < maxI && centerJ + i < maxJ && image.get(centerJ + i, startI + i) &&
|
||||||
|
stateCount[4] < maxCount) {
|
||||||
stateCount[4]++;
|
stateCount[4]++;
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue