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 FXBARCODE_QRCODE_BC_QRCODERMATRIXUTIL_H_
8 #define FXBARCODE_QRCODE_BC_QRCODERMATRIXUTIL_H_
9 
10 class CBC_CommonByteMatrix;
11 class CBC_QRCoderErrorCorrectionLevel;
12 class CBC_QRCoderBitVector;
13 
14 class CBC_QRCoderMatrixUtil {
15  public:
16   CBC_QRCoderMatrixUtil();
17   virtual ~CBC_QRCoderMatrixUtil();
18   static void ClearMatrix(CBC_CommonByteMatrix* matrix, int32_t& e);
19   static void BuildMatrix(CBC_QRCoderBitVector* dataBits,
20                           const CBC_QRCoderErrorCorrectionLevel* ecLevel,
21                           int32_t version,
22                           int32_t maskPattern,
23                           CBC_CommonByteMatrix* matrix,
24                           int32_t& e);
25   static void EmbedBasicPatterns(int32_t version,
26                                  CBC_CommonByteMatrix* matrix,
27                                  int32_t& e);
28   static void EmbedTypeInfo(const CBC_QRCoderErrorCorrectionLevel* ecLevel,
29                             int32_t maskPattern,
30                             CBC_CommonByteMatrix* matrix,
31                             int32_t& e);
32   static void EmbedDataBits(CBC_QRCoderBitVector* dataBits,
33                             int32_t maskPattern,
34                             CBC_CommonByteMatrix* matrix,
35                             int32_t& e);
36   static void MaybeEmbedVersionInfo(int32_t version,
37                                     CBC_CommonByteMatrix* matrix,
38                                     int32_t& e);
39   static int32_t FindMSBSet(int32_t value);
40   static int32_t CalculateBCHCode(int32_t code, int32_t poly);
41   static void MakeTypeInfoBits(const CBC_QRCoderErrorCorrectionLevel* ecLevel,
42                                int32_t maskPattern,
43                                CBC_QRCoderBitVector* bits,
44                                int32_t& e);
45   static void MakeVersionInfoBits(int32_t version,
46                                   CBC_QRCoderBitVector* bits,
47                                   int32_t& e);
48   static bool IsEmpty(int32_t value);
49   static bool IsValidValue(int32_t value);
50   static void EmbedTimingPatterns(CBC_CommonByteMatrix* matrix, int32_t& e);
51   static void EmbedDarkDotAtLeftBottomCorner(CBC_CommonByteMatrix* matrix,
52                                              int32_t& e);
53   static void EmbedHorizontalSeparationPattern(int32_t xStart,
54                                                int32_t yStart,
55                                                CBC_CommonByteMatrix* matrix,
56                                                int32_t& e);
57   static void EmbedVerticalSeparationPattern(int32_t xStart,
58                                              int32_t yStart,
59                                              CBC_CommonByteMatrix* matrix,
60                                              int32_t& e);
61   static void EmbedPositionAdjustmentPattern(int32_t xStart,
62                                              int32_t yStart,
63                                              CBC_CommonByteMatrix* matrix,
64                                              int32_t& e);
65   static void EmbedPositionDetectionPattern(int32_t xStart,
66                                             int32_t yStart,
67                                             CBC_CommonByteMatrix* matrix,
68                                             int32_t& e);
69   static void EmbedPositionDetectionPatternsAndSeparators(
70       CBC_CommonByteMatrix* matrix,
71       int32_t& e);
72   static void MaybeEmbedPositionAdjustmentPatterns(int32_t version,
73                                                    CBC_CommonByteMatrix* matrix,
74                                                    int32_t& e);
75 
76  private:
77   static const int32_t POSITION_DETECTION_PATTERN[7][7];
78   static const int32_t VERTICAL_SEPARATION_PATTERN[7][1];
79   static const int32_t HORIZONTAL_SEPARATION_PATTERN[1][8];
80   static const int32_t POSITION_ADJUSTMENT_PATTERN[5][5];
81   static const int32_t POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[40][7];
82   static const int32_t TYPE_INFO_COORDINATES[15][2];
83   static const int32_t VERSION_INFO_POLY;
84   static const int32_t TYPE_INFO_POLY;
85   static const int32_t TYPE_INFO_MASK_PATTERN;
86 };
87 
88 #endif  // FXBARCODE_QRCODE_BC_QRCODERMATRIXUTIL_H_
89