package com.google.zxing.qrcode.detector;
-import com.google.zxing.BlackPointEstimationMethod;
-import com.google.zxing.MonochromeBitmapSource;
import com.google.zxing.ReaderException;
import com.google.zxing.ResultPoint;
+import com.google.zxing.BinaryBitmap;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.DetectorResult;
import com.google.zxing.common.GridSampler;
*/
public class Detector {
- private final MonochromeBitmapSource image;
+ private final BinaryBitmap image;
- public Detector(MonochromeBitmapSource image) {
+ public Detector(BinaryBitmap image) {
this.image = image;
}
- protected MonochromeBitmapSource getImage() {
+ protected BinaryBitmap getImage() {
return image;
}
*/
public DetectorResult detect(Hashtable hints) throws ReaderException {
- MonochromeBitmapSource image = this.image;
- if (!BlackPointEstimationMethod.TWO_D_SAMPLING.equals(image.getLastEstimationMethod())) {
- image.estimateBlackPoint(BlackPointEstimationMethod.TWO_D_SAMPLING, 0);
- }
-
+ BinaryBitmap image = this.image;
FinderPatternFinder finder = new FinderPatternFinder(image);
FinderPatternInfo info = finder.find(hints);
return new DetectorResult(bits, points);
}
- private static BitMatrix sampleGrid(MonochromeBitmapSource image,
+ private static BitMatrix sampleGrid(BinaryBitmap image,
ResultPoint topLeft,
ResultPoint topRight,
ResultPoint bottomLeft,
* <p>Computes an average estimated module size based on estimated derived from the positions
* of the three finder patterns.</p>
*/
- private float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft) {
+ private float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight,
+ ResultPoint bottomLeft) throws ReaderException {
// Take the average
return (calculateModuleSizeOneWay(topLeft, topRight) +
calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f;
* {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the
* width of each, measuring along the axis between their centers.</p>
*/
- private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) {
+ private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern)
+ throws ReaderException {
float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int) pattern.getX(),
(int) pattern.getY(),
(int) otherPattern.getX(),
* a finder pattern by looking for a black-white-black run from the center in the direction
* of another point (another finder pattern center), and in the opposite direction too.</p>
*/
- private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) {
+ private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY)
+ throws ReaderException {
float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY);
* <p>This is used when figuring out how wide a finder pattern is, when the finder pattern
* may be skewed or rotated.</p>
*/
- private float sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) {
+ private float sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY)
+ throws ReaderException {
// Mild variant of Bresenham's algorithm;
// see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm
boolean steep = Math.abs(toY - fromY) > Math.abs(toX - fromX);