OLD | NEW |
| (Empty) |
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 2008 ZXing authors | |
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 "xfa/src/fxbarcode/common/BC_CommonByteMatrix.h" | |
24 #include "xfa/src/fxbarcode/qrcode/BC_QRCoder.h" | |
25 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderBitVector.h" | |
26 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h" | |
27 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" | |
28 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h" | |
29 #include "xfa/src/fxbarcode/utils.h" | |
30 | |
31 const int32_t CBC_QRCoderMatrixUtil::POSITION_DETECTION_PATTERN[7][7] = { | |
32 {1, 1, 1, 1, 1, 1, 1}, | |
33 {1, 0, 0, 0, 0, 0, 1}, | |
34 {1, 0, 1, 1, 1, 0, 1}, | |
35 {1, 0, 1, 1, 1, 0, 1}, | |
36 {1, 0, 1, 1, 1, 0, 1}, | |
37 {1, 0, 0, 0, 0, 0, 1}, | |
38 {1, 1, 1, 1, 1, 1, 1}}; | |
39 const int32_t CBC_QRCoderMatrixUtil::HORIZONTAL_SEPARATION_PATTERN[1][8] = { | |
40 {0, 0, 0, 0, 0, 0, 0, 0}}; | |
41 const int32_t CBC_QRCoderMatrixUtil::VERTICAL_SEPARATION_PATTERN[7][1] = | |
42 {{0}, {0}, {0}, {0}, {0}, {0}, {0}}; | |
43 const int32_t CBC_QRCoderMatrixUtil::POSITION_ADJUSTMENT_PATTERN[5][5] = { | |
44 {1, 1, 1, 1, 1}, | |
45 {1, 0, 0, 0, 1}, | |
46 {1, 0, 1, 0, 1}, | |
47 {1, 0, 0, 0, 1}, | |
48 {1, 1, 1, 1, 1}}; | |
49 const int32_t | |
50 CBC_QRCoderMatrixUtil::POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[40][7] = | |
51 // NOLINTNEXTLINE | |
52 { | |
53 {-1, -1, -1, -1, -1, -1, -1}, {6, 18, -1, -1, -1, -1, -1}, | |
54 {6, 22, -1, -1, -1, -1, -1}, {6, 26, -1, -1, -1, -1, -1}, | |
55 {6, 30, -1, -1, -1, -1, -1}, {6, 34, -1, -1, -1, -1, -1}, | |
56 {6, 22, 38, -1, -1, -1, -1}, {6, 24, 42, -1, -1, -1, -1}, | |
57 {6, 26, 46, -1, -1, -1, -1}, {6, 28, 50, -1, -1, -1, -1}, | |
58 {6, 30, 54, -1, -1, -1, -1}, {6, 32, 58, -1, -1, -1, -1}, | |
59 {6, 34, 62, -1, -1, -1, -1}, {6, 26, 46, 66, -1, -1, -1}, | |
60 {6, 26, 48, 70, -1, -1, -1}, {6, 26, 50, 74, -1, -1, -1}, | |
61 {6, 30, 54, 78, -1, -1, -1}, {6, 30, 56, 82, -1, -1, -1}, | |
62 {6, 30, 58, 86, -1, -1, -1}, {6, 34, 62, 90, -1, -1, -1}, | |
63 {6, 28, 50, 72, 94, -1, -1}, {6, 26, 50, 74, 98, -1, -1}, | |
64 {6, 30, 54, 78, 102, -1, -1}, {6, 28, 54, 80, 106, -1, -1}, | |
65 {6, 32, 58, 84, 110, -1, -1}, {6, 30, 58, 86, 114, -1, -1}, | |
66 {6, 34, 62, 90, 118, -1, -1}, {6, 26, 50, 74, 98, 122, -1}, | |
67 {6, 30, 54, 78, 102, 126, -1}, {6, 26, 52, 78, 104, 130, -1}, | |
68 {6, 30, 56, 82, 108, 134, -1}, {6, 34, 60, 86, 112, 138, -1}, | |
69 {6, 30, 58, 86, 114, 142, -1}, {6, 34, 62, 90, 118, 146, -1}, | |
70 {6, 30, 54, 78, 102, 126, 150}, {6, 24, 50, 76, 102, 128, 154}, | |
71 {6, 28, 54, 80, 106, 132, 158}, {6, 32, 58, 84, 110, 136, 162}, | |
72 {6, 26, 54, 82, 110, 138, 166}, {6, 30, 58, 86, 114, 142, 170}, | |
73 }; | |
74 const int32_t CBC_QRCoderMatrixUtil::TYPE_INFO_COORDINATES[15][2] = { | |
75 {8, 0}, {8, 1}, {8, 2}, {8, 3}, {8, 4}, {8, 5}, {8, 7}, {8, 8}, | |
76 {7, 8}, {5, 8}, {4, 8}, {3, 8}, {2, 8}, {1, 8}, {0, 8}, | |
77 }; | |
78 const int32_t CBC_QRCoderMatrixUtil::VERSION_INFO_POLY = 0x1f25; | |
79 const int32_t CBC_QRCoderMatrixUtil::TYPE_INFO_POLY = 0x0537; | |
80 const int32_t CBC_QRCoderMatrixUtil::TYPE_INFO_MASK_PATTERN = 0x5412; | |
81 | |
82 void CBC_QRCoderMatrixUtil::ClearMatrix(CBC_CommonByteMatrix* matrix, | |
83 int32_t& e) { | |
84 if (matrix == NULL) { | |
85 e = BCExceptionNullPointer; | |
86 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
87 } | |
88 matrix->clear((uint8_t)-1); | |
89 } | |
90 void CBC_QRCoderMatrixUtil::BuildMatrix( | |
91 CBC_QRCoderBitVector* dataBits, | |
92 CBC_QRCoderErrorCorrectionLevel* ecLevel, | |
93 int32_t version, | |
94 int32_t maskPattern, | |
95 CBC_CommonByteMatrix* matrix, | |
96 int32_t& e) { | |
97 if (matrix == NULL) { | |
98 e = BCExceptionNullPointer; | |
99 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
100 } | |
101 ClearMatrix(matrix, e); | |
102 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
103 EmbedBasicPatterns(version, matrix, e); | |
104 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
105 EmbedTypeInfo(ecLevel, maskPattern, matrix, e); | |
106 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
107 MaybeEmbedVersionInfo(version, matrix, e); | |
108 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
109 EmbedDataBits(dataBits, maskPattern, matrix, e); | |
110 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
111 } | |
112 void CBC_QRCoderMatrixUtil::EmbedBasicPatterns(int32_t version, | |
113 CBC_CommonByteMatrix* matrix, | |
114 int32_t& e) { | |
115 if (matrix == NULL) { | |
116 e = BCExceptionNullPointer; | |
117 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
118 } | |
119 EmbedPositionDetectionPatternsAndSeparators(matrix, e); | |
120 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
121 EmbedDarkDotAtLeftBottomCorner(matrix, e); | |
122 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
123 MaybeEmbedPositionAdjustmentPatterns(version, matrix, e); | |
124 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
125 EmbedTimingPatterns(matrix, e); | |
126 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
127 } | |
128 void CBC_QRCoderMatrixUtil::EmbedTypeInfo( | |
129 CBC_QRCoderErrorCorrectionLevel* ecLevel, | |
130 int32_t maskPattern, | |
131 CBC_CommonByteMatrix* matrix, | |
132 int32_t& e) { | |
133 if (matrix == NULL) { | |
134 e = BCExceptionNullPointer; | |
135 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
136 } | |
137 CBC_QRCoderBitVector typeInfoBits; | |
138 typeInfoBits.Init(); | |
139 MakeTypeInfoBits(ecLevel, maskPattern, &typeInfoBits, e); | |
140 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
141 for (int32_t i = 0; i < typeInfoBits.Size(); i++) { | |
142 int32_t bit = typeInfoBits.At(typeInfoBits.Size() - 1 - i, e); | |
143 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
144 int32_t x1 = TYPE_INFO_COORDINATES[i][0]; | |
145 int32_t y1 = TYPE_INFO_COORDINATES[i][1]; | |
146 matrix->Set(x1, y1, bit); | |
147 if (i < 8) { | |
148 int32_t x2 = matrix->GetWidth() - i - 1; | |
149 int32_t y2 = 8; | |
150 matrix->Set(x2, y2, bit); | |
151 } else { | |
152 int32_t x2 = 8; | |
153 int32_t y2 = matrix->GetHeight() - 7 + (i - 8); | |
154 matrix->Set(x2, y2, bit); | |
155 } | |
156 } | |
157 } | |
158 void CBC_QRCoderMatrixUtil::MaybeEmbedVersionInfo(int32_t version, | |
159 CBC_CommonByteMatrix* matrix, | |
160 int32_t& e) { | |
161 if (matrix == NULL) { | |
162 e = BCExceptionNullPointer; | |
163 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
164 } | |
165 if (version < 7) { | |
166 return; | |
167 } | |
168 CBC_QRCoderBitVector versionInfoBits; | |
169 versionInfoBits.Init(); | |
170 MakeVersionInfoBits(version, &versionInfoBits, e); | |
171 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
172 int32_t bitIndex = 6 * 3 - 1; | |
173 for (int32_t i = 0; i < 6; i++) { | |
174 for (int32_t j = 0; j < 3; j++) { | |
175 int32_t bit = versionInfoBits.At(bitIndex, e); | |
176 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
177 bitIndex--; | |
178 matrix->Set(i, matrix->GetHeight() - 11 + j, bit); | |
179 matrix->Set(matrix->GetHeight() - 11 + j, i, bit); | |
180 } | |
181 } | |
182 } | |
183 void CBC_QRCoderMatrixUtil::EmbedDataBits(CBC_QRCoderBitVector* dataBits, | |
184 int32_t maskPattern, | |
185 CBC_CommonByteMatrix* matrix, | |
186 int32_t& e) { | |
187 if (matrix == NULL || dataBits == NULL) { | |
188 e = BCExceptionNullPointer; | |
189 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
190 } | |
191 int32_t bitIndex = 0; | |
192 int32_t direction = -1; | |
193 int32_t x = matrix->GetWidth() - 1; | |
194 int32_t y = matrix->GetHeight() - 1; | |
195 while (x > 0) { | |
196 if (x == 6) { | |
197 x -= 1; | |
198 } | |
199 while (y >= 0 && y < matrix->GetHeight()) { | |
200 if (y == 6) { | |
201 y += direction; | |
202 continue; | |
203 } | |
204 for (int32_t i = 0; i < 2; i++) { | |
205 int32_t xx = x - i; | |
206 if (!IsEmpty(matrix->Get(xx, y))) { | |
207 continue; | |
208 } | |
209 int32_t bit; | |
210 if (bitIndex < dataBits->Size()) { | |
211 bit = dataBits->At(bitIndex, e); | |
212 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
213 bitIndex++; | |
214 } else { | |
215 bit = 0; | |
216 } | |
217 if (maskPattern != -1) { | |
218 FX_BOOL bol = | |
219 CBC_QRCoderMaskUtil::GetDataMaskBit(maskPattern, xx, y, e); | |
220 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
221 if (bol) { | |
222 bit ^= 0x01; | |
223 } | |
224 } | |
225 matrix->Set(xx, y, bit); | |
226 } | |
227 y += direction; | |
228 } | |
229 direction = -direction; | |
230 y += direction; | |
231 x -= 2; | |
232 } | |
233 if (bitIndex != dataBits->Size()) { | |
234 return; | |
235 } | |
236 } | |
237 int32_t CBC_QRCoderMatrixUtil::CalculateBCHCode(int32_t value, int32_t poly) { | |
238 int32_t msbSetInPoly = FindMSBSet(poly); | |
239 value <<= msbSetInPoly - 1; | |
240 while (FindMSBSet(value) >= msbSetInPoly) { | |
241 value ^= poly << (FindMSBSet(value) - msbSetInPoly); | |
242 } | |
243 return value; | |
244 } | |
245 void CBC_QRCoderMatrixUtil::MakeTypeInfoBits( | |
246 CBC_QRCoderErrorCorrectionLevel* ecLevel, | |
247 int32_t maskPattern, | |
248 CBC_QRCoderBitVector* bits, | |
249 int32_t& e) { | |
250 if (bits == NULL) { | |
251 e = BCExceptionNullPointer; | |
252 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
253 } | |
254 if (!CBC_QRCoder::IsValidMaskPattern(maskPattern)) { | |
255 e = BCExceptionBadMask; | |
256 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
257 } | |
258 int32_t typeInfo = (ecLevel->GetBits() << 3) | maskPattern; | |
259 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
260 bits->AppendBits(typeInfo, 5, e); | |
261 int32_t bchCode = CalculateBCHCode(typeInfo, TYPE_INFO_POLY); | |
262 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
263 bits->AppendBits(bchCode, 10, e); | |
264 CBC_QRCoderBitVector maskBits; | |
265 maskBits.Init(); | |
266 maskBits.AppendBits(TYPE_INFO_MASK_PATTERN, 15, e); | |
267 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
268 bits->XOR(&maskBits, e); | |
269 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
270 if (bits->Size() != 15) { | |
271 e = BCExceptionBitSizeNot15; | |
272 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
273 } | |
274 } | |
275 void CBC_QRCoderMatrixUtil::MakeVersionInfoBits(int32_t version, | |
276 CBC_QRCoderBitVector* bits, | |
277 int32_t& e) { | |
278 if (bits == NULL) { | |
279 e = BCExceptionNullPointer; | |
280 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
281 } | |
282 bits->AppendBits(version, 6, e); | |
283 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
284 int32_t bchCode = CalculateBCHCode(version, VERSION_INFO_POLY); | |
285 bits->AppendBits(bchCode, 12, e); | |
286 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
287 if (bits->Size() != 18) { | |
288 e = BCExceptionBitSizeNot18; | |
289 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
290 } | |
291 } | |
292 FX_BOOL CBC_QRCoderMatrixUtil::IsEmpty(int32_t value) { | |
293 return (uint8_t)value == 0xff; | |
294 } | |
295 FX_BOOL CBC_QRCoderMatrixUtil::IsValidValue(int32_t value) { | |
296 return ((uint8_t)value == 0xff || (uint8_t)value == 0x00 || | |
297 (uint8_t)value == 0x01); | |
298 } | |
299 void CBC_QRCoderMatrixUtil::EmbedTimingPatterns(CBC_CommonByteMatrix* matrix, | |
300 int32_t& e) { | |
301 if (matrix == NULL) { | |
302 e = BCExceptionNullPointer; | |
303 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
304 } | |
305 for (int32_t i = 8; i < matrix->GetWidth() - 8; i++) { | |
306 int32_t bit = (i + 1) % 2; | |
307 if (!IsValidValue(matrix->Get(i, 6))) { | |
308 e = BCExceptionInvalidateImageData; | |
309 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
310 } | |
311 if (IsEmpty(matrix->Get(i, 6))) { | |
312 matrix->Set(i, 6, bit); | |
313 } | |
314 if (!IsValidValue(matrix->Get(6, i))) { | |
315 e = BCExceptionInvalidateImageData; | |
316 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
317 } | |
318 if (IsEmpty(matrix->Get(6, i))) { | |
319 matrix->Set(6, i, bit); | |
320 } | |
321 } | |
322 } | |
323 void CBC_QRCoderMatrixUtil::EmbedDarkDotAtLeftBottomCorner( | |
324 CBC_CommonByteMatrix* matrix, | |
325 int32_t& e) { | |
326 if (matrix == NULL) { | |
327 e = BCExceptionNullPointer; | |
328 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
329 } | |
330 if (matrix->Get(8, matrix->GetHeight() - 8) == 0) { | |
331 e = BCExceptionHeight_8BeZero; | |
332 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
333 } | |
334 matrix->Set(8, matrix->GetHeight() - 8, 1); | |
335 } | |
336 void CBC_QRCoderMatrixUtil::EmbedHorizontalSeparationPattern( | |
337 int32_t xStart, | |
338 int32_t yStart, | |
339 CBC_CommonByteMatrix* matrix, | |
340 int32_t& e) { | |
341 if (matrix == NULL) { | |
342 e = BCExceptionNullPointer; | |
343 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
344 } | |
345 for (int32_t x = 0; x < 8; x++) { | |
346 if (!IsEmpty(matrix->Get(xStart + x, yStart))) { | |
347 e = BCExceptionInvalidateData; | |
348 BC_EXCEPTION_CHECK_ReturnVoid(e) | |
349 } | |
350 matrix->Set(xStart + x, yStart, HORIZONTAL_SEPARATION_PATTERN[0][x]); | |
351 } | |
352 } | |
353 void CBC_QRCoderMatrixUtil::EmbedVerticalSeparationPattern( | |
354 int32_t xStart, | |
355 int32_t yStart, | |
356 CBC_CommonByteMatrix* matrix, | |
357 int32_t& e) { | |
358 if (matrix == NULL) { | |
359 e = BCExceptionNullPointer; | |
360 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
361 } | |
362 for (int32_t y = 0; y < 7; y++) { | |
363 if (!IsEmpty(matrix->Get(xStart, yStart + y))) { | |
364 e = BCExceptionInvalidateData; | |
365 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
366 } | |
367 matrix->Set(xStart, yStart + y, VERTICAL_SEPARATION_PATTERN[y][0]); | |
368 } | |
369 } | |
370 void CBC_QRCoderMatrixUtil::EmbedPositionAdjustmentPattern( | |
371 int32_t xStart, | |
372 int32_t yStart, | |
373 CBC_CommonByteMatrix* matrix, | |
374 int32_t& e) { | |
375 if (matrix == NULL) { | |
376 e = BCExceptionNullPointer; | |
377 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
378 } | |
379 for (int32_t y = 0; y < 5; y++) { | |
380 for (int32_t x = 0; x < 5; x++) { | |
381 if (!IsEmpty(matrix->Get(xStart + x, y + yStart))) { | |
382 e = BCExceptionInvalidateData; | |
383 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
384 } | |
385 matrix->Set(xStart + x, yStart + y, POSITION_ADJUSTMENT_PATTERN[y][x]); | |
386 } | |
387 } | |
388 } | |
389 void CBC_QRCoderMatrixUtil::EmbedPositionDetectionPattern( | |
390 int32_t xStart, | |
391 int32_t yStart, | |
392 CBC_CommonByteMatrix* matrix, | |
393 int32_t& e) { | |
394 if (matrix == NULL) { | |
395 e = BCExceptionNullPointer; | |
396 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
397 } | |
398 for (int32_t y = 0; y < 7; y++) { | |
399 for (int32_t x = 0; x < 7; x++) { | |
400 if (!IsEmpty(matrix->Get(xStart + x, yStart + y))) { | |
401 e = BCExceptionInvalidateData; | |
402 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
403 } | |
404 matrix->Set(xStart + x, yStart + y, POSITION_DETECTION_PATTERN[y][x]); | |
405 } | |
406 } | |
407 } | |
408 void CBC_QRCoderMatrixUtil::EmbedPositionDetectionPatternsAndSeparators( | |
409 CBC_CommonByteMatrix* matrix, | |
410 int32_t& e) { | |
411 if (matrix == NULL) { | |
412 e = BCExceptionNullPointer; | |
413 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
414 } | |
415 int32_t pdpWidth = 7; | |
416 EmbedPositionDetectionPattern(0, 0, matrix, e); | |
417 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
418 EmbedPositionDetectionPattern(matrix->GetWidth() - pdpWidth, 0, matrix, e); | |
419 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
420 EmbedPositionDetectionPattern(0, matrix->GetWidth() - pdpWidth, matrix, e); | |
421 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
422 int32_t hspWidth = 8; | |
423 EmbedHorizontalSeparationPattern(0, hspWidth - 1, matrix, e); | |
424 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
425 EmbedHorizontalSeparationPattern(matrix->GetWidth() - hspWidth, hspWidth - 1, | |
426 matrix, e); | |
427 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
428 EmbedHorizontalSeparationPattern(0, matrix->GetWidth() - hspWidth, matrix, e); | |
429 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
430 int32_t vspSize = 7; | |
431 EmbedVerticalSeparationPattern(vspSize, 0, matrix, e); | |
432 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
433 EmbedVerticalSeparationPattern(matrix->GetHeight() - vspSize - 1, 0, matrix, | |
434 e); | |
435 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
436 EmbedVerticalSeparationPattern(vspSize, matrix->GetHeight() - vspSize, matrix, | |
437 e); | |
438 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
439 } | |
440 void CBC_QRCoderMatrixUtil::MaybeEmbedPositionAdjustmentPatterns( | |
441 int32_t version, | |
442 CBC_CommonByteMatrix* matrix, | |
443 int32_t& e) { | |
444 if (matrix == NULL) { | |
445 e = BCExceptionNullPointer; | |
446 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
447 } | |
448 if (version < 2) { | |
449 return; | |
450 } | |
451 int32_t index = version - 1; | |
452 int32_t const* coordinates = | |
453 &(POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[index][0]); | |
454 int32_t numCoordinate = 7; | |
455 for (int32_t i = 0; i < numCoordinate; i++) { | |
456 for (int32_t j = 0; j < numCoordinate; j++) { | |
457 int32_t y = coordinates[i]; | |
458 int32_t x = coordinates[j]; | |
459 if (x == -1 || y == -1) { | |
460 continue; | |
461 } | |
462 if (IsEmpty(matrix->Get(x, y))) { | |
463 EmbedPositionAdjustmentPattern(x - 2, y - 2, matrix, e); | |
464 BC_EXCEPTION_CHECK_ReturnVoid(e); | |
465 } | |
466 } | |
467 } | |
468 } | |
469 int32_t CBC_QRCoderMatrixUtil::FindMSBSet(int32_t value) { | |
470 int32_t numDigits = 0; | |
471 while (value != 0) { | |
472 value >>= 1; | |
473 ++numDigits; | |
474 } | |
475 return numDigits; | |
476 } | |
477 CBC_QRCoderMatrixUtil::CBC_QRCoderMatrixUtil() {} | |
478 CBC_QRCoderMatrixUtil::~CBC_QRCoderMatrixUtil() {} | |
OLD | NEW |