Many changes to the C++ port.
[zxing.git] / cpp / core / src / zxing / qrcode / detector / FinderPatternFinder.h
1 #ifndef __FINDER_PATTERN_FINDER_H__
2 #define __FINDER_PATTERN_FINDER_H__
3
4 /*
5  *  FinderPatternFinder.h
6  *  zxing
7  *
8  *  Created by Christian Brunschen on 13/05/2008.
9  *  Copyright 2008 ZXing authors All rights reserved.
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23
24 #include <zxing/qrcode/detector/FinderPattern.h>
25 #include <zxing/qrcode/detector/FinderPatternInfo.h>
26 #include <zxing/common/Counted.h>
27 #include <zxing/common/BitMatrix.h>
28 #include <vector>
29
30 namespace zxing {
31 namespace qrcode {
32
33 class FinderPatternFinder {
34 private:
35   static int CENTER_QUORUM;
36   static int MIN_SKIP;
37   static int MAX_MODULES;
38
39   Ref<BitMatrix> image_;
40   std::vector<Ref<FinderPattern> > possibleCenters_;
41   bool hasSkipped_;
42
43   /** stateCount must be int[5] */
44   static float centerFromEnd(int* stateCount, int end);
45   static bool foundPatternCross(int* stateCount);
46
47   float crossCheckVertical(size_t startI, size_t centerJ, int maxCount, int originalStateCountTotal);
48   float crossCheckHorizontal(size_t startJ, size_t centerI, int maxCount, int originalStateCountTotal);
49
50   /** stateCount must be int[5] */
51   bool handlePossibleCenter(int* stateCount, size_t i, size_t j);
52   int findRowSkip();
53   bool haveMultiplyConfirmedCenters();
54   std::vector<Ref<FinderPattern> > selectBestPatterns();
55   static std::vector<Ref<FinderPattern> > orderBestPatterns(std::vector<Ref<FinderPattern> > patterns);
56
57 public:
58   static float distance(Ref<ResultPoint> p1, Ref<ResultPoint> p2);
59   FinderPatternFinder(Ref<BitMatrix> image);
60   Ref<FinderPatternInfo> find();
61 };
62 }
63 }
64
65 #endif // __FINDER_PATTERN_FINDER_H__