• 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 // Original code is licensed as follows:
7 /*
8  * Copyright 2006 Jeremias Maerki
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include "fxbarcode/datamatrix/BC_SymbolInfo.h"
24 
25 #include "fxbarcode/common/BC_CommonBitMatrix.h"
26 #include "fxbarcode/datamatrix/BC_DataMatrixSymbolInfo144.h"
27 #include "fxbarcode/datamatrix/BC_Encoder.h"
28 
29 namespace {
30 
31 constexpr size_t kSymbolsCount = 30;
32 
33 CBC_SymbolInfo* g_symbols[kSymbolsCount] = {
34     nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
35     nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
36     nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
37     nullptr, nullptr, nullptr, nullptr, nullptr, nullptr};
38 
39 }  // namespace
40 
Initialize()41 void CBC_SymbolInfo::Initialize() {
42   g_symbols[0] = new CBC_SymbolInfo(3, 5, 8, 8, 1);
43   g_symbols[1] = new CBC_SymbolInfo(5, 7, 10, 10, 1);
44   g_symbols[2] = new CBC_SymbolInfo(5, 7, 16, 6, 1);
45   g_symbols[3] = new CBC_SymbolInfo(8, 10, 12, 12, 1);
46   g_symbols[4] = new CBC_SymbolInfo(10, 11, 14, 6, 2);
47   g_symbols[5] = new CBC_SymbolInfo(12, 12, 14, 14, 1);
48   g_symbols[6] = new CBC_SymbolInfo(16, 14, 24, 10, 1);
49   g_symbols[7] = new CBC_SymbolInfo(18, 14, 16, 16, 1);
50   g_symbols[8] = new CBC_SymbolInfo(22, 18, 18, 18, 1);
51   g_symbols[9] = new CBC_SymbolInfo(22, 18, 16, 10, 2);
52   g_symbols[10] = new CBC_SymbolInfo(30, 20, 20, 20, 1);
53   g_symbols[11] = new CBC_SymbolInfo(32, 24, 16, 14, 2);
54   g_symbols[12] = new CBC_SymbolInfo(36, 24, 22, 22, 1);
55   g_symbols[13] = new CBC_SymbolInfo(44, 28, 24, 24, 1);
56   g_symbols[14] = new CBC_SymbolInfo(49, 28, 22, 14, 2);
57   g_symbols[15] = new CBC_SymbolInfo(62, 36, 14, 14, 4);
58   g_symbols[16] = new CBC_SymbolInfo(86, 42, 16, 16, 4);
59   g_symbols[17] = new CBC_SymbolInfo(114, 48, 18, 18, 4);
60   g_symbols[18] = new CBC_SymbolInfo(144, 56, 20, 20, 4);
61   g_symbols[19] = new CBC_SymbolInfo(174, 68, 22, 22, 4);
62   g_symbols[20] = new CBC_SymbolInfo(204, 84, 24, 24, 4, 102, 42);
63   g_symbols[21] = new CBC_SymbolInfo(280, 112, 14, 14, 16, 140, 56);
64   g_symbols[22] = new CBC_SymbolInfo(368, 144, 16, 16, 16, 92, 36);
65   g_symbols[23] = new CBC_SymbolInfo(456, 192, 18, 18, 16, 114, 48);
66   g_symbols[24] = new CBC_SymbolInfo(576, 224, 20, 20, 16, 144, 56);
67   g_symbols[25] = new CBC_SymbolInfo(696, 272, 22, 22, 16, 174, 68);
68   g_symbols[26] = new CBC_SymbolInfo(816, 336, 24, 24, 16, 136, 56);
69   g_symbols[27] = new CBC_SymbolInfo(1050, 408, 18, 18, 36, 175, 68);
70   g_symbols[28] = new CBC_SymbolInfo(1304, 496, 20, 20, 36, 163, 62);
71   g_symbols[29] = new CBC_DataMatrixSymbolInfo144();
72 }
73 
Finalize()74 void CBC_SymbolInfo::Finalize() {
75   for (size_t i = 0; i < kSymbolsCount; i++) {
76     delete g_symbols[i];
77     g_symbols[i] = nullptr;
78   }
79 }
80 
CBC_SymbolInfo(size_t dataCapacity,size_t errorCodewords,int32_t matrixWidth,int32_t matrixHeight,int32_t dataRegions)81 CBC_SymbolInfo::CBC_SymbolInfo(size_t dataCapacity,
82                                size_t errorCodewords,
83                                int32_t matrixWidth,
84                                int32_t matrixHeight,
85                                int32_t dataRegions)
86     : CBC_SymbolInfo(dataCapacity,
87                      errorCodewords,
88                      matrixWidth,
89                      matrixHeight,
90                      dataRegions,
91                      dataCapacity,
92                      errorCodewords) {}
93 
CBC_SymbolInfo(size_t dataCapacity,size_t errorCodewords,int32_t matrixWidth,int32_t matrixHeight,int32_t dataRegions,size_t rsBlockData,size_t rsBlockError)94 CBC_SymbolInfo::CBC_SymbolInfo(size_t dataCapacity,
95                                size_t errorCodewords,
96                                int32_t matrixWidth,
97                                int32_t matrixHeight,
98                                int32_t dataRegions,
99                                size_t rsBlockData,
100                                size_t rsBlockError)
101     : m_rectangular(matrixWidth != matrixHeight),
102       m_dataCapacity(dataCapacity),
103       m_errorCodewords(errorCodewords),
104       m_matrixWidth(matrixWidth),
105       m_matrixHeight(matrixHeight),
106       m_dataRegions(dataRegions),
107       m_rsBlockData(rsBlockData),
108       m_rsBlockError(rsBlockError) {}
109 
110 CBC_SymbolInfo::~CBC_SymbolInfo() = default;
111 
Lookup(size_t iDataCodewords,bool bAllowRectangular)112 const CBC_SymbolInfo* CBC_SymbolInfo::Lookup(size_t iDataCodewords,
113                                              bool bAllowRectangular) {
114   for (size_t i = 0; i < kSymbolsCount; i++) {
115     CBC_SymbolInfo* symbol = g_symbols[i];
116     if (symbol->m_rectangular && !bAllowRectangular)
117       continue;
118 
119     if (iDataCodewords <= symbol->dataCapacity())
120       return symbol;
121   }
122   return nullptr;
123 }
124 
getHorizontalDataRegions() const125 int32_t CBC_SymbolInfo::getHorizontalDataRegions() const {
126   switch (m_dataRegions) {
127     case 1:
128       return 1;
129     case 2:
130       return 2;
131     case 4:
132       return 2;
133     case 16:
134       return 4;
135     case 36:
136       return 6;
137     default:
138       NOTREACHED();
139       return 0;
140   }
141 }
142 
getVerticalDataRegions() const143 int32_t CBC_SymbolInfo::getVerticalDataRegions() const {
144   switch (m_dataRegions) {
145     case 1:
146       return 1;
147     case 2:
148       return 1;
149     case 4:
150       return 2;
151     case 16:
152       return 4;
153     case 36:
154       return 6;
155     default:
156       NOTREACHED();
157       return 0;
158   }
159 }
160 
getSymbolDataWidth() const161 int32_t CBC_SymbolInfo::getSymbolDataWidth() const {
162   return getHorizontalDataRegions() * m_matrixWidth;
163 }
164 
getSymbolDataHeight() const165 int32_t CBC_SymbolInfo::getSymbolDataHeight() const {
166   return getVerticalDataRegions() * m_matrixHeight;
167 }
168 
getSymbolWidth() const169 int32_t CBC_SymbolInfo::getSymbolWidth() const {
170   return getSymbolDataWidth() + (getHorizontalDataRegions() * 2);
171 }
172 
getSymbolHeight() const173 int32_t CBC_SymbolInfo::getSymbolHeight() const {
174   return getSymbolDataHeight() + (getVerticalDataRegions() * 2);
175 }
176 
getCodewordCount() const177 size_t CBC_SymbolInfo::getCodewordCount() const {
178   return m_dataCapacity + m_errorCodewords;
179 }
180 
getInterleavedBlockCount() const181 size_t CBC_SymbolInfo::getInterleavedBlockCount() const {
182   return m_dataCapacity / m_rsBlockData;
183 }
184 
getDataLengthForInterleavedBlock() const185 size_t CBC_SymbolInfo::getDataLengthForInterleavedBlock() const {
186   return m_rsBlockData;
187 }
188 
getErrorLengthForInterleavedBlock() const189 size_t CBC_SymbolInfo::getErrorLengthForInterleavedBlock() const {
190   return m_rsBlockError;
191 }
192