• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_PDF417SCANNINGDECODER_H_
8 #define _BC_PDF417SCANNINGDECODER_H_
9 class CBC_CommonDecoderResult;
10 class CBC_CommonBitMatrix;
11 class CBC_ErrorCorrection;
12 class CBC_Codeword;
13 class CBC_BoundingBox;
14 class CBC_ResultPoint;
15 class CBC_BarcodeMetadata;
16 class CBC_BarcodeValue;
17 class CBC_DetectionResult;
18 class CBC_DetectionResultRowIndicatorColumn;
19 
20 class CBC_PDF417ScanningDecoder {
21  public:
22   CBC_PDF417ScanningDecoder();
23   virtual ~CBC_PDF417ScanningDecoder();
24   static void Initialize();
25   static void Finalize();
26   static CBC_CommonDecoderResult* decode(CBC_CommonBitMatrix* image,
27                                          CBC_ResultPoint* imageTopLeft,
28                                          CBC_ResultPoint* imageBottomLeft,
29                                          CBC_ResultPoint* imageTopRight,
30                                          CBC_ResultPoint* imageBottomRight,
31                                          int32_t minCodewordWidth,
32                                          int32_t maxCodewordWidth,
33                                          int32_t& e);
34   static CFX_ByteString toString(CFX_PtrArray* barcodeMatrix);
35 
36  private:
37   static int32_t CODEWORD_SKEW_SIZE;
38   static int32_t MAX_ERRORS;
39   static int32_t MAX_EC_CODEWORDS;
40   static CBC_PDF417ECErrorCorrection* errorCorrection;
41   static CBC_DetectionResult* merge(
42       CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn,
43       CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn,
44       int32_t& e);
45   static CBC_BoundingBox* adjustBoundingBox(
46       CBC_DetectionResultRowIndicatorColumn* rowIndicatorColumn,
47       int32_t& e);
48   static int32_t getMax(CFX_Int32Array& values);
49   static CBC_BarcodeMetadata* getBarcodeMetadata(
50       CBC_DetectionResultRowIndicatorColumn* leftRowIndicatorColumn,
51       CBC_DetectionResultRowIndicatorColumn* rightRowIndicatorColumn);
52   static CBC_DetectionResultRowIndicatorColumn* getRowIndicatorColumn(
53       CBC_CommonBitMatrix* image,
54       CBC_BoundingBox* boundingBox,
55       CBC_ResultPoint startPoint,
56       FX_BOOL leftToRight,
57       int32_t minCodewordWidth,
58       int32_t maxCodewordWidth);
59   static void adjustCodewordCount(CBC_DetectionResult* detectionResult,
60                                   CFX_PtrArray* barcodeMatrix,
61                                   int32_t& e);
62   static CBC_CommonDecoderResult* createDecoderResult(
63       CBC_DetectionResult* detectionResult,
64       int32_t& e);
65   static CBC_CommonDecoderResult* createDecoderResultFromAmbiguousValues(
66       int32_t ecLevel,
67       CFX_Int32Array& codewords,
68       CFX_Int32Array& erasureArray,
69       CFX_Int32Array& ambiguousIndexes,
70       CFX_PtrArray& ambiguousIndexValues,
71       int32_t& e);
72   static CFX_PtrArray* createBarcodeMatrix(
73       CBC_DetectionResult* detectionResult);
74   static FX_BOOL isValidBarcodeColumn(CBC_DetectionResult* detectionResult,
75                                       int32_t barcodeColumn);
76   static int32_t getStartColumn(CBC_DetectionResult* detectionResult,
77                                 int32_t barcodeColumn,
78                                 int32_t imageRow,
79                                 FX_BOOL leftToRight);
80   static CBC_Codeword* detectCodeword(CBC_CommonBitMatrix* image,
81                                       int32_t minColumn,
82                                       int32_t maxColumn,
83                                       FX_BOOL leftToRight,
84                                       int32_t startColumn,
85                                       int32_t imageRow,
86                                       int32_t minCodewordWidth,
87                                       int32_t maxCodewordWidth);
88   static CFX_Int32Array* getModuleBitCount(CBC_CommonBitMatrix* image,
89                                            int32_t minColumn,
90                                            int32_t maxColumn,
91                                            FX_BOOL leftToRight,
92                                            int32_t startColumn,
93                                            int32_t imageRow);
94   static int32_t getNumberOfECCodeWords(int32_t barcodeECLevel);
95   static int32_t adjustCodewordStartColumn(CBC_CommonBitMatrix* image,
96                                            int32_t minColumn,
97                                            int32_t maxColumn,
98                                            FX_BOOL leftToRight,
99                                            int32_t codewordStartColumn,
100                                            int32_t imageRow);
101   static FX_BOOL checkCodewordSkew(int32_t codewordSize,
102                                    int32_t minCodewordWidth,
103                                    int32_t maxCodewordWidth);
104   static CBC_CommonDecoderResult* decodeCodewords(CFX_Int32Array& codewords,
105                                                   int32_t ecLevel,
106                                                   CFX_Int32Array& erasures,
107                                                   int32_t& e);
108   static int32_t correctErrors(CFX_Int32Array& codewords,
109                                CFX_Int32Array& erasures,
110                                int32_t numECCodewords,
111                                int32_t& e);
112   static void verifyCodewordCount(CFX_Int32Array& codewords,
113                                   int32_t numECCodewords,
114                                   int32_t& e);
115   static CFX_Int32Array* getBitCountForCodeword(int32_t codeword);
116   static int32_t getCodewordBucketNumber(int32_t codeword);
117   static int32_t getCodewordBucketNumber(CFX_Int32Array& moduleBitCount);
118 };
119 #endif
120