1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef _BC_DATAMATRIXDETECTOR_H_
8 #define _BC_DATAMATRIXDETECTOR_H_
9 class CBC_CommonBitMatrix;
10 class CBC_WhiteRectangleDetector;
11 class CBC_ResultPoint;
12 class CBC_QRDetectorResult;
13 class CBC_DataMatrixDetector;
14 class ResultPointsAndTransitions;
15 class CBC_ResultPointsAndTransitions {
16  public:
CBC_ResultPointsAndTransitions(CBC_ResultPoint * from,CBC_ResultPoint * to,int32_t transitions)17   CBC_ResultPointsAndTransitions(CBC_ResultPoint* from,
18                                  CBC_ResultPoint* to,
19                                  int32_t transitions) {
20     m_from = from;
21     m_to = to;
22     m_transitions = transitions;
23   }
~CBC_ResultPointsAndTransitions()24   ~CBC_ResultPointsAndTransitions() {}
GetFrom()25   CBC_ResultPoint* GetFrom() { return m_from; }
GetTo()26   CBC_ResultPoint* GetTo() { return m_to; }
GetTransitions()27   int32_t GetTransitions() { return m_transitions; }
28 
29  private:
30   CBC_ResultPoint* m_from;
31   CBC_ResultPoint* m_to;
32   int32_t m_transitions;
33 };
34 class CBC_DataMatrixDetector {
35  public:
36   CBC_DataMatrixDetector(CBC_CommonBitMatrix* image);
37   virtual ~CBC_DataMatrixDetector();
38   CBC_QRDetectorResult* Detect(int32_t& e);
39   CBC_ResultPoint* CorrectTopRightRectangular(CBC_ResultPoint* bottomLeft,
40                                               CBC_ResultPoint* bottomRight,
41                                               CBC_ResultPoint* topLeft,
42                                               CBC_ResultPoint* topRight,
43                                               int32_t dimensionTop,
44                                               int32_t dimensionRight);
45   CBC_ResultPoint* CorrectTopRight(CBC_ResultPoint* bottomLeft,
46                                    CBC_ResultPoint* bottomRight,
47                                    CBC_ResultPoint* topLeft,
48                                    CBC_ResultPoint* topRight,
49                                    int32_t dimension);
50   CBC_CommonBitMatrix* SampleGrid(CBC_CommonBitMatrix* image,
51                                   CBC_ResultPoint* topLeft,
52                                   CBC_ResultPoint* bottomLeft,
53                                   CBC_ResultPoint* bottomRight,
54                                   CBC_ResultPoint* topRight,
55                                   int32_t dimensionX,
56                                   int32_t dimensionY,
57                                   int32_t& e);
58   CBC_ResultPointsAndTransitions* TransitionsBetween(CBC_ResultPoint* from,
59                                                      CBC_ResultPoint* to);
60   FX_BOOL IsValid(CBC_ResultPoint* p);
61   int32_t Distance(CBC_ResultPoint* a, CBC_ResultPoint* b);
62   void Increment(CFX_MapPtrTemplate<CBC_ResultPoint*, int32_t>& table,
63                  CBC_ResultPoint* key);
64   int32_t Round(FX_FLOAT d);
65   void OrderBestPatterns(CFX_PtrArray* patterns);
66   virtual void Init(int32_t& e);
67 
68  private:
69   CBC_CommonBitMatrix* m_image;
70   CBC_WhiteRectangleDetector* m_rectangleDetector;
71   const static int32_t INTEGERS[5];
72 };
73 #endif
74