*/\r
FinderPatternFinder(MonochromeBitmapSource image) {\r
this.image = image;\r
- this.possibleCenters = new Vector(5);\r
+ this.possibleCenters = new Vector();\r
}\r
\r
FinderPatternInfo find() throws ReaderException {\r
/**\r
* @param stateCount count of black/white/black/white/black pixels just read\r
* @return true iff the proportions of the counts is close enough to the 1/13/1/1 ratios\r
- * used by finder patterns to be considered a match\r
+ * used by finder patterns to be considered a match\r
*/\r
private static boolean foundPatternCross(int[] stateCount) {\r
int totalModuleSize = 0;\r
float moduleSize = (float) totalModuleSize / 7.0f;\r
float maxVariance = moduleSize / 2.5f;\r
// Allow less than 40% variance from 1-1-3-1-1 proportions\r
- return Math.abs(moduleSize - stateCount[0]) < maxVariance &&\r
- Math.abs(moduleSize - stateCount[1]) < maxVariance &&\r
- Math.abs(3.0f * moduleSize - stateCount[2]) < 3.0f * maxVariance &&\r
- Math.abs(moduleSize - stateCount[3]) < maxVariance &&\r
- Math.abs(moduleSize - stateCount[4]) < maxVariance;\r
+ return Math.abs(moduleSize - stateCount[0]) < maxVariance &&\r
+ Math.abs(moduleSize - stateCount[1]) < maxVariance &&\r
+ Math.abs(3.0f * moduleSize - stateCount[2]) < 3.0f * maxVariance &&\r
+ Math.abs(moduleSize - stateCount[3]) < maxVariance &&\r
+ Math.abs(moduleSize - stateCount[4]) < maxVariance;\r
}\r
\r
/**\r
* @param startI row where a finder pattern was detected\r
* @param centerJ center of the section that appears to cross a finder pattern\r
* @param maxCount maximum reasonable number of modules that should be\r
- * observed in any reading state, based on the results of the horizontal scan\r
+ * observed in any reading state, based on the results of the horizontal scan\r
* @return vertical center of finder pattern, or {@link Float#NaN} if not found\r
*/\r
private float crossCheckVertical(int startI, int centerJ, int maxCount) {\r
stateCount[0]++;\r
i--;\r
}\r
- if (i < 0 || stateCount[0] > maxCount) {\r
+ if (stateCount[0] > maxCount) {\r
return Float.NaN;\r
}\r
\r
stateCount[0]++;\r
j--;\r
}\r
- if (j < 0 || stateCount[0] > maxCount) {\r
+ if (stateCount[0] > maxCount) {\r
return Float.NaN;\r
}\r
\r
centerJ = crossCheckHorizontal((int) centerJ, (int) centerI, stateCount[2]);\r
if (!Float.isNaN(centerJ)) {\r
float estimatedModuleSize =\r
- (float) (stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]) / 7.0f;\r
+ (float) (stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]) / 7.0f;\r
boolean found = false;\r
int max = possibleCenters.size();\r
for (int index = 0; index < max; index++) {\r
\r
/**\r
* @return number of rows we could safely skip during scanning, based on the first\r
- * two finder patterns that have been located. In some cases their position will\r
- * allow us to infer that the third pattern must lie below a certain point farther\r
- * down in the image.\r
+ * two finder patterns that have been located. In some cases their position will\r
+ * allow us to infer that the third pattern must lie below a certain point farther\r
+ * down in the image.\r
*/\r
private int findRowSkip() {\r
int max = possibleCenters.size();\r
// This is the case where you find top left first. Draw it out.\r
hasSkipped = true;\r
return (int) Math.abs(Math.abs(firstConfirmedCenter.getX() - center.getX()) -\r
- Math.abs(firstConfirmedCenter.getY() - center.getY()));\r
+ Math.abs(firstConfirmedCenter.getY() - center.getY()));\r
}\r
}\r
}\r
\r
/**\r
* @return true iff we have found at least 3 finder patterns that have been detected\r
- * at least {@link #CENTER_QUORUM} times each\r
+ * at least {@link #CENTER_QUORUM} times each\r
*/\r
private boolean haveMulitplyConfirmedCenters() {\r
int count = 0;\r
\r
/**\r
* @return the 3 best {@link FinderPattern}s from our list of candidates. The "best" are\r
- * those that have been detected at least {@link #CENTER_QUORUM} times, and whose module\r
- * size differs from the average among those patterns the least\r
+ * those that have been detected at least {@link #CENTER_QUORUM} times, and whose module\r
+ * size differs from the average among those patterns the least\r
* @throws ReaderException if 3 such finder patterns do not exist\r
*/\r
private FinderPattern[] selectBestPatterns() throws ReaderException {\r
\r
if (size == 3) {\r
// Found just enough -- hope these are good!\r
- // toArray() is not available\r
- FinderPattern[] result = new FinderPattern[possibleCenters.size()];\r
- for (int i = 0; i < possibleCenters.size(); i++) {\r
- result[i] = (FinderPattern) possibleCenters.elementAt(i);\r
- }\r
- return result;\r
+ return new FinderPattern[]{\r
+ (FinderPattern) possibleCenters.elementAt(0),\r
+ (FinderPattern) possibleCenters.elementAt(1),\r
+ (FinderPattern) possibleCenters.elementAt(2)\r
+ };\r
}\r
\r
possibleCenters.setSize(size);\r
// We don't have java.util.Collections in J2ME\r
Collections.insertionSort(possibleCenters, new ClosestToAverageComparator(averageModuleSize));\r
\r
- FinderPattern[] result = new FinderPattern[3];\r
- for (int i = 0; i < 3; i++) {\r
- result[i] = (FinderPattern) possibleCenters.elementAt(i);\r
- }\r
- return result;\r
+ return new FinderPattern[]{\r
+ (FinderPattern) possibleCenters.elementAt(0),\r
+ (FinderPattern) possibleCenters.elementAt(1),\r
+ (FinderPattern) possibleCenters.elementAt(2)\r
+ };\r
}\r
\r
/**\r
* <p>Orders by variance from average module size, ascending.</p>\r
*/\r
private static class ClosestToAverageComparator implements Comparator {\r
- private float averageModuleSize;\r
+ private final float averageModuleSize;\r
\r
private ClosestToAverageComparator(float averageModuleSize) {\r
this.averageModuleSize = averageModuleSize;\r
}\r
\r
public int compare(Object center1, Object center2) {\r
- return\r
- Math.abs(((FinderPattern) center1).getEstimatedModuleSize() - averageModuleSize) <\r
- Math.abs(((FinderPattern) center2).getEstimatedModuleSize() - averageModuleSize) ?\r
- -1 :\r
- 1;\r
+ return Math.abs(((FinderPattern) center1).getEstimatedModuleSize() - averageModuleSize) <\r
+ Math.abs(((FinderPattern) center2).getEstimatedModuleSize() - averageModuleSize) ?\r
+ -1 :\r
+ 1;\r
}\r
}\r
\r