First version of the iphone client that actually works, for at least a subset
[zxing.git] / cpp / core / src / 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 Google Inc. 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 "FinderPattern.h"
25 #include "FinderPatternInfo.h"
26 #include "../../common/Counted.h"
27 #include "../../MonochromeBitmapSource.h"
28 #include <vector>
29
30 namespace qrcode {
31   namespace detector {
32     using namespace std;
33     using namespace common;
34     
35     class FinderPatternFinder {
36     private:
37       static int CENTER_QUORUM;
38       static int MIN_SKIP;
39       static int MAX_MODULES;
40       
41       Ref<MonochromeBitmapSource> image_;
42       vector<Ref<FinderPattern> > possibleCenters_;
43       bool hasSkipped_;
44       
45       static float centerFromEnd(valarray<int> &stateCount, int end);
46       static bool foundPatternCross(valarray<int> &stateCount);
47       
48       float crossCheckVertical(size_t startI, size_t centerJ, int maxCount,
49                                int originalStateCountTotal);
50       float crossCheckHorizontal(size_t startJ, size_t centerI, int maxCount,
51                                  int originalStateCountTotal);
52       
53       bool handlePossibleCenter(valarray<int> &stateCount, size_t i, size_t j);
54       int findRowSkip();
55       bool haveMultiplyConfirmedCenters();
56       ArrayRef<Ref<FinderPattern> > selectBestPatterns();
57       static ArrayRef<Ref<FinderPattern> > orderBestPatterns
58       (ArrayRef<Ref<FinderPattern> > patterns);
59             
60     public:
61       static float distance(Ref<ResultPoint> p1, Ref<ResultPoint> p2);
62       FinderPatternFinder(Ref<MonochromeBitmapSource> image);
63       Ref<FinderPatternInfo> find();
64     };
65   }
66 }
67
68 #endif // __FINDER_PATTERN_FINDER_H__