X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=core%2Fsrc%2Fcom%2Fgoogle%2Fzxing%2Fqrcode%2Fdetector%2FAlignmentPatternFinder.java;h=f9f531cf4edfad8a59eb3e03ccfe0a30af0e1e55;hb=61db77fd4960c475243bfb49cc3b6877aef5d8de;hp=e68d3a185ca0bedecabae90ba49a554823564046;hpb=6980903e85309b4f167d21206d86b467cc6ef4f9;p=zxing.git diff --git a/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java b/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java index e68d3a18..f9f531cf 100644 --- a/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java +++ b/core/src/com/google/zxing/qrcode/detector/AlignmentPatternFinder.java @@ -94,14 +94,14 @@ final class AlignmentPatternFinder { stateCount[0] = 0; stateCount[1] = 0; stateCount[2] = 0; - int currentState = 0; int j = startX; // Burn off leading white pixels before anything else; if we start in the middle of // a white run, it doesn't make sense to count its length, since we don't know if the // white run continued to the left of the start point - while (!luminanceRow.get(j - startX) && j < maxJ) { + while (j < maxJ && !luminanceRow.get(j - startX)) { j++; } + int currentState = 0; while (j < maxJ) { if (luminanceRow.get(j - startX)) { // Black pixel @@ -160,11 +160,11 @@ final class AlignmentPatternFinder { /** * @param stateCount count of black/white/black pixels just read * @return true iff the proportions of the counts is close enough to the 1/1/1 ratios - * used by alignment patterns to be considered a match + * used by alignment patterns to be considered a match */ private boolean foundPatternCross(int[] stateCount) { float moduleSize = this.moduleSize; - float maxVariance = moduleSize / 2.5f; + float maxVariance = moduleSize / 2.0f; for (int i = 0; i < 3; i++) { if (Math.abs(moduleSize - stateCount[i]) >= maxVariance) { return false; @@ -181,10 +181,10 @@ final class AlignmentPatternFinder { * @param startI row where an alignment pattern was detected * @param centerJ center of the section that appears to cross an alignment pattern * @param maxCount maximum reasonable number of modules that should be - * observed in any reading state, based on the results of the horizontal scan + * observed in any reading state, based on the results of the horizontal scan * @return vertical center of alignment pattern, or {@link Float#NaN} if not found */ - private float crossCheckVertical(int startI, int centerJ, int maxCount) { + private float crossCheckVertical(int startI, int centerJ, int maxCount, int originalStateCountTotal) { MonochromeBitmapSource image = this.image; int maxI = image.getHeight(); @@ -225,6 +225,11 @@ final class AlignmentPatternFinder { return Float.NaN; } + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; + if (5 * Math.abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) { + return Float.NaN; + } + return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : Float.NaN; } @@ -240,8 +245,9 @@ final class AlignmentPatternFinder { * @return {@link AlignmentPattern} if we have found the same pattern twice, or null if not */ private AlignmentPattern handlePossibleCenter(int[] stateCount, int i, int j) { + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; float centerJ = centerFromEnd(stateCount, j); - float centerI = crossCheckVertical(i, (int) centerJ, 2 * stateCount[1]); + float centerI = crossCheckVertical(i, (int) centerJ, 2 * stateCount[1], stateCountTotal); if (!Float.isNaN(centerI)) { float estimatedModuleSize = (float) (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f; int max = possibleCenters.size();