OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2008 ZXing authors | 8 * Copyright 2008 ZXing authors |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
11 * you may not use this file except in compliance with 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 | 12 * You may obtain a copy of the License at |
13 * | 13 * |
14 * http://www.apache.org/licenses/LICENSE-2.0 | 14 * http://www.apache.org/licenses/LICENSE-2.0 |
15 * | 15 * |
16 * Unless required by applicable law or agreed to in writing, software | 16 * Unless required by applicable law or agreed to in writing, software |
17 * distributed under the License is distributed on an "AS IS" BASIS, | 17 * distributed under the License is distributed on an "AS IS" BASIS, |
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
19 * See the License for the specific language governing permissions and | 19 * See the License for the specific language governing permissions and |
20 * limitations under the License. | 20 * limitations under the License. |
21 */ | 21 */ |
22 | 22 |
23 #include "xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h" | 23 #include "xfa/fxbarcode/qrcode/BC_QRCoderEncoder.h" |
24 | 24 |
25 #include <algorithm> | 25 #include <algorithm> |
26 #include <memory> | 26 #include <memory> |
| 27 #include <utility> |
27 | 28 |
28 #include "xfa/fxbarcode/BC_UtilCodingConvert.h" | 29 #include "xfa/fxbarcode/BC_UtilCodingConvert.h" |
29 #include "xfa/fxbarcode/common/BC_CommonByteArray.h" | 30 #include "xfa/fxbarcode/common/BC_CommonByteArray.h" |
30 #include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" | 31 #include "xfa/fxbarcode/common/BC_CommonByteMatrix.h" |
31 #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h" | 32 #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomon.h" |
32 #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" | 33 #include "xfa/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" |
33 #include "xfa/fxbarcode/qrcode/BC_QRCoder.h" | 34 #include "xfa/fxbarcode/qrcode/BC_QRCoder.h" |
34 #include "xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h" | 35 #include "xfa/fxbarcode/qrcode/BC_QRCoderBitVector.h" |
35 #include "xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h" | 36 #include "xfa/fxbarcode/qrcode/BC_QRCoderBlockPair.h" |
36 #include "xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h" | 37 #include "xfa/fxbarcode/qrcode/BC_QRCoderECBlocks.h" |
37 #include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" | 38 #include "xfa/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" |
38 #include "xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h" | 39 #include "xfa/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h" |
39 #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" | 40 #include "xfa/fxbarcode/qrcode/BC_QRCoderMode.h" |
40 #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" | 41 #include "xfa/fxbarcode/qrcode/BC_QRCoderVersion.h" |
41 | 42 |
42 const int32_t CBC_QRCoderEncoder::m_alphaNumbericTable[] = { | 43 const int32_t CBC_QRCoderEncoder::m_alphaNumbericTable[] = { |
43 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 44 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
44 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, | 45 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
45 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, | 46 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, |
46 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, | 47 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, |
47 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, | 48 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, |
48 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1}; | 49 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1}; |
49 | 50 |
50 CBC_QRCoderEncoder::CBC_QRCoderEncoder() {} | 51 CBC_QRCoderEncoder::CBC_QRCoderEncoder() {} |
| 52 |
51 CBC_QRCoderEncoder::~CBC_QRCoderEncoder() {} | 53 CBC_QRCoderEncoder::~CBC_QRCoderEncoder() {} |
| 54 |
52 class Make_Pair { | 55 class Make_Pair { |
53 public: | 56 public: |
54 CBC_QRCoderMode* m_mode; | 57 CBC_QRCoderMode* m_mode; |
55 CFX_ByteString m_string; | 58 CFX_ByteString m_string; |
56 | 59 |
57 private: | 60 private: |
58 Make_Pair(const Make_Pair& mode_string) {} | 61 Make_Pair(const Make_Pair& mode_string) {} |
59 Make_Pair& operator=(Make_Pair& mode_string) { | 62 Make_Pair& operator=(Make_Pair& mode_string) { |
60 if (this == &mode_string) { | 63 if (this == &mode_string) { |
61 return *this; | 64 return *this; |
(...skipping 17 matching lines...) Expand all Loading... |
79 EncodeWithAutoVersion(content, ecLevel, qrCode, e); | 82 EncodeWithAutoVersion(content, ecLevel, qrCode, e); |
80 BC_EXCEPTION_CHECK_ReturnVoid(e) | 83 BC_EXCEPTION_CHECK_ReturnVoid(e) |
81 } else if (versionSpecify > 0 && versionSpecify <= 40) { | 84 } else if (versionSpecify > 0 && versionSpecify <= 40) { |
82 EncodeWithSpecifyVersion(content, ecLevel, qrCode, versionSpecify, e); | 85 EncodeWithSpecifyVersion(content, ecLevel, qrCode, versionSpecify, e); |
83 BC_EXCEPTION_CHECK_ReturnVoid(e); | 86 BC_EXCEPTION_CHECK_ReturnVoid(e); |
84 } else { | 87 } else { |
85 e = BCExceptionVersionMust1_40; | 88 e = BCExceptionVersionMust1_40; |
86 BC_EXCEPTION_CHECK_ReturnVoid(e); | 89 BC_EXCEPTION_CHECK_ReturnVoid(e); |
87 } | 90 } |
88 } | 91 } |
| 92 |
89 void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} | 93 void CBC_QRCoderEncoder::AppendECI(CBC_QRCoderBitVector* bits) {} |
| 94 |
90 void CBC_QRCoderEncoder::AppendDataModeLenghInfo( | 95 void CBC_QRCoderEncoder::AppendDataModeLenghInfo( |
91 const CFX_ArrayTemplate<Make_Pair*>& splitResult, | 96 const CFX_ArrayTemplate<Make_Pair*>& splitResult, |
92 CBC_QRCoderBitVector& headerAndDataBits, | 97 CBC_QRCoderBitVector& headerAndDataBits, |
93 CBC_QRCoderMode* tempMode, | 98 CBC_QRCoderMode* tempMode, |
94 CBC_QRCoder* qrCode, | 99 CBC_QRCoder* qrCode, |
95 CFX_ByteString& encoding, | 100 CFX_ByteString& encoding, |
96 int32_t& e) { | 101 int32_t& e) { |
97 for (int32_t i = 0; i < splitResult.GetSize(); i++) { | 102 for (int32_t i = 0; i < splitResult.GetSize(); i++) { |
98 tempMode = splitResult[i]->m_mode; | 103 tempMode = splitResult[i]->m_mode; |
99 if (tempMode == CBC_QRCoderMode::sGBK) { | 104 if (tempMode == CBC_QRCoderMode::sGBK) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 BC_EXCEPTION_CHECK_ReturnVoid(e); | 137 BC_EXCEPTION_CHECK_ReturnVoid(e); |
133 AppendBytes(splitResult[i]->m_string, tempMode, &headerAndDataBits, | 138 AppendBytes(splitResult[i]->m_string, tempMode, &headerAndDataBits, |
134 encoding, e); | 139 encoding, e); |
135 BC_EXCEPTION_CHECK_ReturnVoid(e); | 140 BC_EXCEPTION_CHECK_ReturnVoid(e); |
136 } else { | 141 } else { |
137 e = BCExceptionUnknown; | 142 e = BCExceptionUnknown; |
138 BC_EXCEPTION_CHECK_ReturnVoid(e); | 143 BC_EXCEPTION_CHECK_ReturnVoid(e); |
139 } | 144 } |
140 } | 145 } |
141 } | 146 } |
| 147 |
142 void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, | 148 void CBC_QRCoderEncoder::SplitString(const CFX_ByteString& content, |
143 CFX_ArrayTemplate<Make_Pair*>* result) { | 149 CFX_ArrayTemplate<Make_Pair*>* result) { |
144 int32_t index = 0, flag = 0; | 150 int32_t index = 0, flag = 0; |
145 while ( | 151 while ( |
146 (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || | 152 (((uint8_t)content[index] >= 0xA1 && (uint8_t)content[index] <= 0xAA) || |
147 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && | 153 ((uint8_t)content[index] >= 0xB0 && (uint8_t)content[index] <= 0xFA)) && |
148 (index < content.GetLength())) { | 154 (index < content.GetLength())) { |
149 index += 2; | 155 index += 2; |
150 } | 156 } |
151 if (index != flag) { | 157 if (index != flag) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 mergeNum++; | 315 mergeNum++; |
310 } | 316 } |
311 } | 317 } |
312 } | 318 } |
313 if (mergeNum == 0) { | 319 if (mergeNum == 0) { |
314 return; | 320 return; |
315 } | 321 } |
316 MergeString(result, versionNum, e); | 322 MergeString(result, versionNum, e); |
317 BC_EXCEPTION_CHECK_ReturnVoid(e); | 323 BC_EXCEPTION_CHECK_ReturnVoid(e); |
318 } | 324 } |
| 325 |
319 void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes, | 326 void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes, |
320 int32_t versionNumber, | 327 int32_t versionNumber, |
321 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 328 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
322 CBC_QRCoderMode* mode, | 329 CBC_QRCoderMode* mode, |
323 CBC_QRCoder* qrCode, | 330 CBC_QRCoder* qrCode, |
324 int32_t& e) { | 331 int32_t& e) { |
325 qrCode->SetECLevel(ecLevel); | 332 qrCode->SetECLevel(ecLevel); |
326 qrCode->SetMode(mode); | 333 qrCode->SetMode(mode); |
327 CBC_QRCoderVersion* version = | 334 CBC_QRCoderVersion* version = |
328 CBC_QRCoderVersion::GetVersionForNumber(versionNumber, e); | 335 CBC_QRCoderVersion::GetVersionForNumber(versionNumber, e); |
329 BC_EXCEPTION_CHECK_ReturnVoid(e); | 336 BC_EXCEPTION_CHECK_ReturnVoid(e); |
330 int32_t numBytes = version->GetTotalCodeWords(); | 337 int32_t numBytes = version->GetTotalCodeWords(); |
331 CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel); | 338 CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel); |
332 int32_t numEcBytes = ecBlocks->GetTotalECCodeWords(); | 339 int32_t numEcBytes = ecBlocks->GetTotalECCodeWords(); |
333 int32_t numRSBlocks = ecBlocks->GetNumBlocks(); | 340 int32_t numRSBlocks = ecBlocks->GetNumBlocks(); |
334 int32_t numDataBytes = numBytes - numEcBytes; | 341 int32_t numDataBytes = numBytes - numEcBytes; |
335 if (numDataBytes >= numInputBytes + 3) { | 342 if (numDataBytes >= numInputBytes + 3) { |
336 qrCode->SetVersion(versionNumber); | 343 qrCode->SetVersion(versionNumber); |
337 qrCode->SetNumTotalBytes(numBytes); | 344 qrCode->SetNumTotalBytes(numBytes); |
338 qrCode->SetNumDataBytes(numDataBytes); | 345 qrCode->SetNumDataBytes(numDataBytes); |
339 qrCode->SetNumRSBlocks(numRSBlocks); | 346 qrCode->SetNumRSBlocks(numRSBlocks); |
340 qrCode->SetNumECBytes(numEcBytes); | 347 qrCode->SetNumECBytes(numEcBytes); |
341 qrCode->SetMatrixWidth(version->GetDimensionForVersion()); | 348 qrCode->SetMatrixWidth(version->GetDimensionForVersion()); |
342 return; | 349 return; |
343 } | 350 } |
344 e = BCExceptionCannotFindBlockInfo; | 351 e = BCExceptionCannotFindBlockInfo; |
345 BC_EXCEPTION_CHECK_ReturnVoid(e); | 352 BC_EXCEPTION_CHECK_ReturnVoid(e); |
346 } | 353 } |
| 354 |
347 void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( | 355 void CBC_QRCoderEncoder::EncodeWithSpecifyVersion( |
348 const CFX_ByteString& content, | 356 const CFX_ByteString& content, |
349 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 357 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
350 CBC_QRCoder* qrCode, | 358 CBC_QRCoder* qrCode, |
351 int32_t versionSpecify, | 359 int32_t versionSpecify, |
352 int32_t& e) { | 360 int32_t& e) { |
353 CFX_ByteString encoding = "utf8"; | 361 CFX_ByteString encoding = "utf8"; |
354 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; | 362 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; |
355 CFX_ArrayTemplate<Make_Pair*> splitResult; | 363 CFX_ArrayTemplate<Make_Pair*> splitResult; |
356 CBC_QRCoderBitVector dataBits; | 364 CBC_QRCoderBitVector dataBits; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); | 409 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); |
402 matrix->Init(); | 410 matrix->Init(); |
403 int32_t maskPattern = ChooseMaskPattern( | 411 int32_t maskPattern = ChooseMaskPattern( |
404 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); | 412 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); |
405 BC_EXCEPTION_CHECK_ReturnVoid(e); | 413 BC_EXCEPTION_CHECK_ReturnVoid(e); |
406 qrCode->SetMaskPattern(maskPattern); | 414 qrCode->SetMaskPattern(maskPattern); |
407 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), | 415 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), |
408 qrCode->GetVersion(), | 416 qrCode->GetVersion(), |
409 qrCode->GetMaskPattern(), matrix.get(), e); | 417 qrCode->GetMaskPattern(), matrix.get(), e); |
410 BC_EXCEPTION_CHECK_ReturnVoid(e); | 418 BC_EXCEPTION_CHECK_ReturnVoid(e); |
411 qrCode->SetMatrix(matrix.release()); | 419 qrCode->SetMatrix(std::move(matrix)); |
412 if (!qrCode->IsValid()) { | 420 if (!qrCode->IsValid()) { |
413 e = BCExceptionInvalidQRCode; | 421 e = BCExceptionInvalidQRCode; |
414 BC_EXCEPTION_CHECK_ReturnVoid(e); | 422 BC_EXCEPTION_CHECK_ReturnVoid(e); |
415 } | 423 } |
416 } | 424 } |
| 425 |
417 void CBC_QRCoderEncoder::EncodeWithAutoVersion( | 426 void CBC_QRCoderEncoder::EncodeWithAutoVersion( |
418 const CFX_ByteString& content, | 427 const CFX_ByteString& content, |
419 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 428 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
420 CBC_QRCoder* qrCode, | 429 CBC_QRCoder* qrCode, |
421 int32_t& e) { | 430 int32_t& e) { |
422 CFX_ByteString encoding = "utf8"; | 431 CFX_ByteString encoding = "utf8"; |
423 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; | 432 CBC_QRCoderMode* mode = CBC_QRCoderMode::sBYTE; |
424 CFX_ArrayTemplate<Make_Pair*> splitResult; | 433 CFX_ArrayTemplate<Make_Pair*> splitResult; |
425 CBC_QRCoderBitVector dataBits; | 434 CBC_QRCoderBitVector dataBits; |
426 dataBits.Init(); | 435 dataBits.Init(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( | 494 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( |
486 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); | 495 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); |
487 matrix->Init(); | 496 matrix->Init(); |
488 int32_t maskPattern = ChooseMaskPattern( | 497 int32_t maskPattern = ChooseMaskPattern( |
489 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); | 498 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); |
490 BC_EXCEPTION_CHECK_ReturnVoid(e); | 499 BC_EXCEPTION_CHECK_ReturnVoid(e); |
491 qrCode->SetMaskPattern(maskPattern); | 500 qrCode->SetMaskPattern(maskPattern); |
492 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), | 501 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), |
493 qrCode->GetVersion(), | 502 qrCode->GetVersion(), |
494 qrCode->GetMaskPattern(), matrix.get(), e); | 503 qrCode->GetMaskPattern(), matrix.get(), e); |
495 BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(matrix.release()); | 504 BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(std::move(matrix)); |
496 if (!qrCode->IsValid()) { | 505 if (!qrCode->IsValid()) { |
497 e = BCExceptionInvalidQRCode; | 506 e = BCExceptionInvalidQRCode; |
498 BC_EXCEPTION_CHECK_ReturnVoid(e); | 507 BC_EXCEPTION_CHECK_ReturnVoid(e); |
499 } | 508 } |
500 } | 509 } |
| 510 |
501 void CBC_QRCoderEncoder::Encode(const CFX_WideString& content, | 511 void CBC_QRCoderEncoder::Encode(const CFX_WideString& content, |
502 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 512 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
503 CBC_QRCoder* qrCode, | 513 CBC_QRCoder* qrCode, |
504 int32_t& e) { | 514 int32_t& e) { |
505 CFX_ByteString encoding = "utf8"; | 515 CFX_ByteString encoding = "utf8"; |
506 CFX_ByteString utf8Data; | 516 CFX_ByteString utf8Data; |
507 CBC_UtilCodingConvert::UnicodeToUTF8(content, utf8Data); | 517 CBC_UtilCodingConvert::UnicodeToUTF8(content, utf8Data); |
508 CBC_QRCoderMode* mode = ChooseMode(utf8Data, encoding); | 518 CBC_QRCoderMode* mode = ChooseMode(utf8Data, encoding); |
509 CBC_QRCoderBitVector dataBits; | 519 CBC_QRCoderBitVector dataBits; |
510 dataBits.Init(); | 520 dataBits.Init(); |
(...skipping 24 matching lines...) Expand all Loading... |
535 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( | 545 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix( |
536 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); | 546 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth())); |
537 matrix->Init(); | 547 matrix->Init(); |
538 int32_t maskPattern = ChooseMaskPattern( | 548 int32_t maskPattern = ChooseMaskPattern( |
539 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); | 549 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); |
540 BC_EXCEPTION_CHECK_ReturnVoid(e); | 550 BC_EXCEPTION_CHECK_ReturnVoid(e); |
541 qrCode->SetMaskPattern(maskPattern); | 551 qrCode->SetMaskPattern(maskPattern); |
542 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), | 552 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), |
543 qrCode->GetVersion(), | 553 qrCode->GetVersion(), |
544 qrCode->GetMaskPattern(), matrix.get(), e); | 554 qrCode->GetMaskPattern(), matrix.get(), e); |
545 BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(matrix.release()); | 555 BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(std::move(matrix)); |
546 if (!qrCode->IsValid()) { | 556 if (!qrCode->IsValid()) { |
547 e = BCExceptionInvalidQRCode; | 557 e = BCExceptionInvalidQRCode; |
548 BC_EXCEPTION_CHECK_ReturnVoid(e); | 558 BC_EXCEPTION_CHECK_ReturnVoid(e); |
549 } | 559 } |
550 } | 560 } |
| 561 |
551 void CBC_QRCoderEncoder::TerminateBits(int32_t numDataBytes, | 562 void CBC_QRCoderEncoder::TerminateBits(int32_t numDataBytes, |
552 CBC_QRCoderBitVector* bits, | 563 CBC_QRCoderBitVector* bits, |
553 int32_t& e) { | 564 int32_t& e) { |
554 int32_t capacity = numDataBytes << 3; | 565 int32_t capacity = numDataBytes << 3; |
555 if (bits->Size() > capacity) { | 566 if (bits->Size() > capacity) { |
556 e = BCExceptionDataTooMany; | 567 e = BCExceptionDataTooMany; |
557 BC_EXCEPTION_CHECK_ReturnVoid(e); | 568 BC_EXCEPTION_CHECK_ReturnVoid(e); |
558 } | 569 } |
559 for (int32_t i = 0; i < 4 && bits->Size() < capacity; ++i) { | 570 for (int32_t i = 0; i < 4 && bits->Size() < capacity; ++i) { |
560 bits->AppendBit(0, e); | 571 bits->AppendBit(0, e); |
(...skipping 19 matching lines...) Expand all Loading... |
580 } else { | 591 } else { |
581 bits->AppendBits(0x11, 8, e); | 592 bits->AppendBits(0x11, 8, e); |
582 BC_EXCEPTION_CHECK_ReturnVoid(e); | 593 BC_EXCEPTION_CHECK_ReturnVoid(e); |
583 } | 594 } |
584 } | 595 } |
585 if (bits->Size() != capacity) { | 596 if (bits->Size() != capacity) { |
586 e = BCExceptionBitsNotEqualCacity; | 597 e = BCExceptionBitsNotEqualCacity; |
587 BC_EXCEPTION_CHECK_ReturnVoid(e); | 598 BC_EXCEPTION_CHECK_ReturnVoid(e); |
588 } | 599 } |
589 } | 600 } |
| 601 |
590 int32_t CBC_QRCoderEncoder::ChooseMaskPattern( | 602 int32_t CBC_QRCoderEncoder::ChooseMaskPattern( |
591 CBC_QRCoderBitVector* bits, | 603 CBC_QRCoderBitVector* bits, |
592 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 604 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
593 int32_t version, | 605 int32_t version, |
594 CBC_CommonByteMatrix* matrix, | 606 CBC_CommonByteMatrix* matrix, |
595 int32_t& e) { | 607 int32_t& e) { |
596 int32_t minPenalty = 65535; | 608 int32_t minPenalty = 65535; |
597 int32_t bestMaskPattern = -1; | 609 int32_t bestMaskPattern = -1; |
598 for (int32_t maskPattern = 0; maskPattern < CBC_QRCoder::NUM_MASK_PATTERNS; | 610 for (int32_t maskPattern = 0; maskPattern < CBC_QRCoder::kNumMaskPatterns; |
599 maskPattern++) { | 611 maskPattern++) { |
600 CBC_QRCoderMatrixUtil::BuildMatrix(bits, ecLevel, version, maskPattern, | 612 CBC_QRCoderMatrixUtil::BuildMatrix(bits, ecLevel, version, maskPattern, |
601 matrix, e); | 613 matrix, e); |
602 BC_EXCEPTION_CHECK_ReturnValue(e, 0); | 614 BC_EXCEPTION_CHECK_ReturnValue(e, 0); |
603 int32_t penalty = CalculateMaskPenalty(matrix); | 615 int32_t penalty = CalculateMaskPenalty(matrix); |
604 if (penalty < minPenalty) { | 616 if (penalty < minPenalty) { |
605 minPenalty = penalty; | 617 minPenalty = penalty; |
606 bestMaskPattern = maskPattern; | 618 bestMaskPattern = maskPattern; |
607 } | 619 } |
608 } | 620 } |
609 return bestMaskPattern; | 621 return bestMaskPattern; |
610 } | 622 } |
| 623 |
611 int32_t CBC_QRCoderEncoder::CalculateMaskPenalty(CBC_CommonByteMatrix* matrix) { | 624 int32_t CBC_QRCoderEncoder::CalculateMaskPenalty(CBC_CommonByteMatrix* matrix) { |
612 int32_t penalty = 0; | 625 int32_t penalty = 0; |
613 penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1(matrix); | 626 penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule1(matrix); |
614 penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule2(matrix); | 627 penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule2(matrix); |
615 penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule3(matrix); | 628 penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule3(matrix); |
616 penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule4(matrix); | 629 penalty += CBC_QRCoderMaskUtil::ApplyMaskPenaltyRule4(matrix); |
617 return penalty; | 630 return penalty; |
618 } | 631 } |
| 632 |
619 CBC_QRCoderMode* CBC_QRCoderEncoder::ChooseMode(const CFX_ByteString& content, | 633 CBC_QRCoderMode* CBC_QRCoderEncoder::ChooseMode(const CFX_ByteString& content, |
620 CFX_ByteString encoding) { | 634 CFX_ByteString encoding) { |
621 if (encoding.Compare("SHIFT_JIS") == 0) { | 635 if (encoding.Compare("SHIFT_JIS") == 0) { |
622 return CBC_QRCoderMode::sKANJI; | 636 return CBC_QRCoderMode::sKANJI; |
623 } | 637 } |
624 FX_BOOL hasNumeric = FALSE; | 638 FX_BOOL hasNumeric = FALSE; |
625 FX_BOOL hasAlphaNumeric = FALSE; | 639 FX_BOOL hasAlphaNumeric = FALSE; |
626 for (int32_t i = 0; i < content.GetLength(); i++) { | 640 for (int32_t i = 0; i < content.GetLength(); i++) { |
627 if (isdigit((uint8_t)content[i])) { | 641 if (isdigit((uint8_t)content[i])) { |
628 hasNumeric = TRUE; | 642 hasNumeric = TRUE; |
629 } else if (GetAlphaNumericCode((uint8_t)content[i]) != -1) { | 643 } else if (GetAlphaNumericCode((uint8_t)content[i]) != -1) { |
630 hasAlphaNumeric = TRUE; | 644 hasAlphaNumeric = TRUE; |
631 } else { | 645 } else { |
632 return CBC_QRCoderMode::sBYTE; | 646 return CBC_QRCoderMode::sBYTE; |
633 } | 647 } |
634 } | 648 } |
635 if (hasAlphaNumeric) { | 649 if (hasAlphaNumeric) { |
636 return CBC_QRCoderMode::sALPHANUMERIC; | 650 return CBC_QRCoderMode::sALPHANUMERIC; |
637 } else if (hasNumeric) { | 651 } else if (hasNumeric) { |
638 return CBC_QRCoderMode::sNUMERIC; | 652 return CBC_QRCoderMode::sNUMERIC; |
639 } | 653 } |
640 return CBC_QRCoderMode::sBYTE; | 654 return CBC_QRCoderMode::sBYTE; |
641 } | 655 } |
| 656 |
642 int32_t CBC_QRCoderEncoder::GetAlphaNumericCode(int32_t code) { | 657 int32_t CBC_QRCoderEncoder::GetAlphaNumericCode(int32_t code) { |
643 if (code < 96 && code >= 0) { | 658 if (code < 96 && code >= 0) { |
644 return m_alphaNumbericTable[code]; | 659 return m_alphaNumbericTable[code]; |
645 } | 660 } |
646 return -1; | 661 return -1; |
647 } | 662 } |
| 663 |
648 void CBC_QRCoderEncoder::AppendBytes(const CFX_ByteString& content, | 664 void CBC_QRCoderEncoder::AppendBytes(const CFX_ByteString& content, |
649 CBC_QRCoderMode* mode, | 665 CBC_QRCoderMode* mode, |
650 CBC_QRCoderBitVector* bits, | 666 CBC_QRCoderBitVector* bits, |
651 CFX_ByteString encoding, | 667 CFX_ByteString encoding, |
652 int32_t& e) { | 668 int32_t& e) { |
653 if (mode == CBC_QRCoderMode::sNUMERIC) { | 669 if (mode == CBC_QRCoderMode::sNUMERIC) { |
654 AppendNumericBytes(content, bits, e); | 670 AppendNumericBytes(content, bits, e); |
655 BC_EXCEPTION_CHECK_ReturnVoid(e); | 671 BC_EXCEPTION_CHECK_ReturnVoid(e); |
656 } else if (mode == CBC_QRCoderMode::sALPHANUMERIC) { | 672 } else if (mode == CBC_QRCoderMode::sALPHANUMERIC) { |
657 AppendAlphaNumericBytes(content, bits, e); | 673 AppendAlphaNumericBytes(content, bits, e); |
658 BC_EXCEPTION_CHECK_ReturnVoid(e); | 674 BC_EXCEPTION_CHECK_ReturnVoid(e); |
659 } else if (mode == CBC_QRCoderMode::sBYTE) { | 675 } else if (mode == CBC_QRCoderMode::sBYTE) { |
660 Append8BitBytes(content, bits, encoding, e); | 676 Append8BitBytes(content, bits, encoding, e); |
661 BC_EXCEPTION_CHECK_ReturnVoid(e); | 677 BC_EXCEPTION_CHECK_ReturnVoid(e); |
662 } else if (mode == CBC_QRCoderMode::sKANJI) { | 678 } else if (mode == CBC_QRCoderMode::sKANJI) { |
663 AppendKanjiBytes(content, bits, e); | 679 AppendKanjiBytes(content, bits, e); |
664 BC_EXCEPTION_CHECK_ReturnVoid(e); | 680 BC_EXCEPTION_CHECK_ReturnVoid(e); |
665 } else if (mode == CBC_QRCoderMode::sGBK) { | 681 } else if (mode == CBC_QRCoderMode::sGBK) { |
666 AppendGBKBytes(content, bits, e); | 682 AppendGBKBytes(content, bits, e); |
667 BC_EXCEPTION_CHECK_ReturnVoid(e); | 683 BC_EXCEPTION_CHECK_ReturnVoid(e); |
668 } else { | 684 } else { |
669 e = BCExceptionUnsupportedMode; | 685 e = BCExceptionUnsupportedMode; |
670 BC_EXCEPTION_CHECK_ReturnVoid(e); | 686 BC_EXCEPTION_CHECK_ReturnVoid(e); |
671 } | 687 } |
672 } | 688 } |
| 689 |
673 void CBC_QRCoderEncoder::AppendNumericBytes(const CFX_ByteString& content, | 690 void CBC_QRCoderEncoder::AppendNumericBytes(const CFX_ByteString& content, |
674 CBC_QRCoderBitVector* bits, | 691 CBC_QRCoderBitVector* bits, |
675 int32_t& e) { | 692 int32_t& e) { |
676 int32_t length = content.GetLength(); | 693 int32_t length = content.GetLength(); |
677 int32_t i = 0; | 694 int32_t i = 0; |
678 while (i < length) { | 695 while (i < length) { |
679 int32_t num1 = content[i] - '0'; | 696 int32_t num1 = content[i] - '0'; |
680 if (i + 2 < length) { | 697 if (i + 2 < length) { |
681 int32_t num2 = content[i + 1] - '0'; | 698 int32_t num2 = content[i + 1] - '0'; |
682 int32_t num3 = content[i + 2] - '0'; | 699 int32_t num3 = content[i + 2] - '0'; |
683 bits->AppendBits(num1 * 100 + num2 * 10 + num3, 10, e); | 700 bits->AppendBits(num1 * 100 + num2 * 10 + num3, 10, e); |
684 BC_EXCEPTION_CHECK_ReturnVoid(e) i += 3; | 701 BC_EXCEPTION_CHECK_ReturnVoid(e) i += 3; |
685 } else if (i + 1 < length) { | 702 } else if (i + 1 < length) { |
686 int32_t num2 = content[i + 1] - '0'; | 703 int32_t num2 = content[i + 1] - '0'; |
687 bits->AppendBits(num1 * 10 + num2, 7, e); | 704 bits->AppendBits(num1 * 10 + num2, 7, e); |
688 BC_EXCEPTION_CHECK_ReturnVoid(e) i += 2; | 705 BC_EXCEPTION_CHECK_ReturnVoid(e) i += 2; |
689 } else { | 706 } else { |
690 bits->AppendBits(num1, 4, e); | 707 bits->AppendBits(num1, 4, e); |
691 BC_EXCEPTION_CHECK_ReturnVoid(e); | 708 BC_EXCEPTION_CHECK_ReturnVoid(e); |
692 i++; | 709 i++; |
693 } | 710 } |
694 } | 711 } |
695 } | 712 } |
| 713 |
696 void CBC_QRCoderEncoder::AppendAlphaNumericBytes(const CFX_ByteString& content, | 714 void CBC_QRCoderEncoder::AppendAlphaNumericBytes(const CFX_ByteString& content, |
697 CBC_QRCoderBitVector* bits, | 715 CBC_QRCoderBitVector* bits, |
698 int32_t& e) { | 716 int32_t& e) { |
699 int32_t length = content.GetLength(); | 717 int32_t length = content.GetLength(); |
700 int32_t i = 0; | 718 int32_t i = 0; |
701 while (i < length) { | 719 while (i < length) { |
702 int32_t code1 = GetAlphaNumericCode(content[i]); | 720 int32_t code1 = GetAlphaNumericCode(content[i]); |
703 if (code1 == -1) { | 721 if (code1 == -1) { |
704 e = BCExceptionInvalidateCharacter; | 722 e = BCExceptionInvalidateCharacter; |
705 BC_EXCEPTION_CHECK_ReturnVoid(e); | 723 BC_EXCEPTION_CHECK_ReturnVoid(e); |
706 } | 724 } |
707 if (i + 1 < length) { | 725 if (i + 1 < length) { |
708 int32_t code2 = GetAlphaNumericCode(content[i + 1]); | 726 int32_t code2 = GetAlphaNumericCode(content[i + 1]); |
709 if (code2 == -1) { | 727 if (code2 == -1) { |
710 e = BCExceptionInvalidateCharacter; | 728 e = BCExceptionInvalidateCharacter; |
711 BC_EXCEPTION_CHECK_ReturnVoid(e); | 729 BC_EXCEPTION_CHECK_ReturnVoid(e); |
712 } | 730 } |
713 bits->AppendBits(code1 * 45 + code2, 11, e); | 731 bits->AppendBits(code1 * 45 + code2, 11, e); |
714 BC_EXCEPTION_CHECK_ReturnVoid(e); | 732 BC_EXCEPTION_CHECK_ReturnVoid(e); |
715 i += 2; | 733 i += 2; |
716 } else { | 734 } else { |
717 bits->AppendBits(code1, 6, e); | 735 bits->AppendBits(code1, 6, e); |
718 BC_EXCEPTION_CHECK_ReturnVoid(e) i++; | 736 BC_EXCEPTION_CHECK_ReturnVoid(e) i++; |
719 } | 737 } |
720 } | 738 } |
721 } | 739 } |
| 740 |
722 void CBC_QRCoderEncoder::AppendGBKBytes(const CFX_ByteString& content, | 741 void CBC_QRCoderEncoder::AppendGBKBytes(const CFX_ByteString& content, |
723 CBC_QRCoderBitVector* bits, | 742 CBC_QRCoderBitVector* bits, |
724 int32_t& e) { | 743 int32_t& e) { |
725 int32_t length = content.GetLength(); | 744 int32_t length = content.GetLength(); |
726 uint32_t value = 0; | 745 uint32_t value = 0; |
727 for (int32_t i = 0; i < length; i += 2) { | 746 for (int32_t i = 0; i < length; i += 2) { |
728 value = (uint32_t)((uint8_t)content[i] << 8 | (uint8_t)content[i + 1]); | 747 value = (uint32_t)((uint8_t)content[i] << 8 | (uint8_t)content[i + 1]); |
729 if (value <= 0xAAFE && value >= 0xA1A1) { | 748 if (value <= 0xAAFE && value >= 0xA1A1) { |
730 value -= 0xA1A1; | 749 value -= 0xA1A1; |
731 } else if (value <= 0xFAFE && value >= 0xB0A1) { | 750 } else if (value <= 0xFAFE && value >= 0xB0A1) { |
732 value -= 0xA6A1; | 751 value -= 0xA6A1; |
733 } else { | 752 } else { |
734 e = BCExceptionInvalidateCharacter; | 753 e = BCExceptionInvalidateCharacter; |
735 BC_EXCEPTION_CHECK_ReturnVoid(e); | 754 BC_EXCEPTION_CHECK_ReturnVoid(e); |
736 } | 755 } |
737 value = (uint32_t)((value >> 8) * 0x60) + (uint32_t)(value & 0xff); | 756 value = (uint32_t)((value >> 8) * 0x60) + (uint32_t)(value & 0xff); |
738 bits->AppendBits(value, 13, e); | 757 bits->AppendBits(value, 13, e); |
739 BC_EXCEPTION_CHECK_ReturnVoid(e); | 758 BC_EXCEPTION_CHECK_ReturnVoid(e); |
740 } | 759 } |
741 } | 760 } |
| 761 |
742 void CBC_QRCoderEncoder::Append8BitBytes(const CFX_ByteString& content, | 762 void CBC_QRCoderEncoder::Append8BitBytes(const CFX_ByteString& content, |
743 CBC_QRCoderBitVector* bits, | 763 CBC_QRCoderBitVector* bits, |
744 CFX_ByteString encoding, | 764 CFX_ByteString encoding, |
745 int32_t& e) { | 765 int32_t& e) { |
746 for (int32_t i = 0; i < content.GetLength(); i++) { | 766 for (int32_t i = 0; i < content.GetLength(); i++) { |
747 bits->AppendBits(content[i], 8, e); | 767 bits->AppendBits(content[i], 8, e); |
748 BC_EXCEPTION_CHECK_ReturnVoid(e); | 768 BC_EXCEPTION_CHECK_ReturnVoid(e); |
749 } | 769 } |
750 } | 770 } |
| 771 |
751 void CBC_QRCoderEncoder::Append8BitBytes(CFX_ByteArray& bytes, | 772 void CBC_QRCoderEncoder::Append8BitBytes(CFX_ByteArray& bytes, |
752 CBC_QRCoderBitVector* bits, | 773 CBC_QRCoderBitVector* bits, |
753 int32_t& e) { | 774 int32_t& e) { |
754 for (int32_t i = 0; i < bytes.GetSize(); i++) { | 775 for (int32_t i = 0; i < bytes.GetSize(); i++) { |
755 bits->AppendBits(bytes[i], 8, e); | 776 bits->AppendBits(bytes[i], 8, e); |
756 BC_EXCEPTION_CHECK_ReturnVoid(e); | 777 BC_EXCEPTION_CHECK_ReturnVoid(e); |
757 } | 778 } |
758 } | 779 } |
| 780 |
759 void CBC_QRCoderEncoder::AppendKanjiBytes(const CFX_ByteString& content, | 781 void CBC_QRCoderEncoder::AppendKanjiBytes(const CFX_ByteString& content, |
760 CBC_QRCoderBitVector* bits, | 782 CBC_QRCoderBitVector* bits, |
761 int32_t& e) { | 783 int32_t& e) { |
762 CFX_ByteArray bytes; | 784 CFX_ByteArray bytes; |
763 uint32_t value = 0; | 785 uint32_t value = 0; |
764 for (int32_t i = 0; i < bytes.GetSize(); i += 2) { | 786 for (int32_t i = 0; i < bytes.GetSize(); i += 2) { |
765 value = (uint32_t)((uint8_t)(content[i] << 8) | (uint8_t)content[i + 1]); | 787 value = (uint32_t)((uint8_t)(content[i] << 8) | (uint8_t)content[i + 1]); |
766 if (value <= 0x9ffc && value >= 0x8140) { | 788 if (value <= 0x9ffc && value >= 0x8140) { |
767 value -= 0x8140; | 789 value -= 0x8140; |
768 } else if (value <= 0xebbf && value >= 0xe040) { | 790 } else if (value <= 0xebbf && value >= 0xe040) { |
769 value -= 0xc140; | 791 value -= 0xc140; |
770 } else { | 792 } else { |
771 e = BCExceptionInvalidateCharacter; | 793 e = BCExceptionInvalidateCharacter; |
772 BC_EXCEPTION_CHECK_ReturnVoid(e); | 794 BC_EXCEPTION_CHECK_ReturnVoid(e); |
773 } | 795 } |
774 value = (uint32_t)((value >> 8) * 0xc0) + (uint32_t)(value & 0xff); | 796 value = (uint32_t)((value >> 8) * 0xc0) + (uint32_t)(value & 0xff); |
775 bits->AppendBits(value, 13, e); | 797 bits->AppendBits(value, 13, e); |
776 BC_EXCEPTION_CHECK_ReturnVoid(e); | 798 BC_EXCEPTION_CHECK_ReturnVoid(e); |
777 } | 799 } |
778 } | 800 } |
| 801 |
779 void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes, | 802 void CBC_QRCoderEncoder::InitQRCode(int32_t numInputBytes, |
780 CBC_QRCoderErrorCorrectionLevel* ecLevel, | 803 CBC_QRCoderErrorCorrectionLevel* ecLevel, |
781 CBC_QRCoderMode* mode, | 804 CBC_QRCoderMode* mode, |
782 CBC_QRCoder* qrCode, | 805 CBC_QRCoder* qrCode, |
783 int32_t& e) { | 806 int32_t& e) { |
784 qrCode->SetECLevel(ecLevel); | 807 qrCode->SetECLevel(ecLevel); |
785 qrCode->SetMode(mode); | 808 qrCode->SetMode(mode); |
786 for (int32_t versionNum = 1; versionNum <= 40; versionNum++) { | 809 for (int32_t versionNum = 1; versionNum <= 40; versionNum++) { |
787 CBC_QRCoderVersion* version = | 810 CBC_QRCoderVersion* version = |
788 CBC_QRCoderVersion::GetVersionForNumber(versionNum, e); | 811 CBC_QRCoderVersion::GetVersionForNumber(versionNum, e); |
789 BC_EXCEPTION_CHECK_ReturnVoid(e); | 812 BC_EXCEPTION_CHECK_ReturnVoid(e); |
790 int32_t numBytes = version->GetTotalCodeWords(); | 813 int32_t numBytes = version->GetTotalCodeWords(); |
791 CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel); | 814 CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel); |
792 int32_t numEcBytes = ecBlocks->GetTotalECCodeWords(); | 815 int32_t numEcBytes = ecBlocks->GetTotalECCodeWords(); |
793 int32_t numRSBlocks = ecBlocks->GetNumBlocks(); | 816 int32_t numRSBlocks = ecBlocks->GetNumBlocks(); |
794 int32_t numDataBytes = numBytes - numEcBytes; | 817 int32_t numDataBytes = numBytes - numEcBytes; |
795 if (numDataBytes >= numInputBytes + 3) { | 818 if (numDataBytes >= numInputBytes + 3) { |
796 qrCode->SetVersion(versionNum); | 819 qrCode->SetVersion(versionNum); |
797 qrCode->SetNumTotalBytes(numBytes); | 820 qrCode->SetNumTotalBytes(numBytes); |
798 qrCode->SetNumDataBytes(numDataBytes); | 821 qrCode->SetNumDataBytes(numDataBytes); |
799 qrCode->SetNumRSBlocks(numRSBlocks); | 822 qrCode->SetNumRSBlocks(numRSBlocks); |
800 qrCode->SetNumECBytes(numEcBytes); | 823 qrCode->SetNumECBytes(numEcBytes); |
801 qrCode->SetMatrixWidth(version->GetDimensionForVersion()); | 824 qrCode->SetMatrixWidth(version->GetDimensionForVersion()); |
802 return; | 825 return; |
803 } | 826 } |
804 } | 827 } |
805 e = BCExceptionCannotFindBlockInfo; | 828 e = BCExceptionCannotFindBlockInfo; |
806 BC_EXCEPTION_CHECK_ReturnVoid(e); | 829 BC_EXCEPTION_CHECK_ReturnVoid(e); |
807 } | 830 } |
| 831 |
808 void CBC_QRCoderEncoder::AppendModeInfo(CBC_QRCoderMode* mode, | 832 void CBC_QRCoderEncoder::AppendModeInfo(CBC_QRCoderMode* mode, |
809 CBC_QRCoderBitVector* bits, | 833 CBC_QRCoderBitVector* bits, |
810 int32_t& e) { | 834 int32_t& e) { |
811 bits->AppendBits(mode->GetBits(), 4, e); | 835 bits->AppendBits(mode->GetBits(), 4, e); |
812 if (mode == CBC_QRCoderMode::sGBK) { | 836 if (mode == CBC_QRCoderMode::sGBK) { |
813 bits->AppendBits(1, 4, e); | 837 bits->AppendBits(1, 4, e); |
814 BC_EXCEPTION_CHECK_ReturnVoid(e); | 838 BC_EXCEPTION_CHECK_ReturnVoid(e); |
815 } | 839 } |
816 } | 840 } |
| 841 |
817 void CBC_QRCoderEncoder::AppendLengthInfo(int32_t numLetters, | 842 void CBC_QRCoderEncoder::AppendLengthInfo(int32_t numLetters, |
818 int32_t version, | 843 int32_t version, |
819 CBC_QRCoderMode* mode, | 844 CBC_QRCoderMode* mode, |
820 CBC_QRCoderBitVector* bits, | 845 CBC_QRCoderBitVector* bits, |
821 int32_t& e) { | 846 int32_t& e) { |
822 CBC_QRCoderVersion* qcv = CBC_QRCoderVersion::GetVersionForNumber(version, e); | 847 CBC_QRCoderVersion* qcv = CBC_QRCoderVersion::GetVersionForNumber(version, e); |
823 BC_EXCEPTION_CHECK_ReturnVoid(e); | 848 BC_EXCEPTION_CHECK_ReturnVoid(e); |
824 int32_t numBits = mode->GetCharacterCountBits(qcv, e); | 849 int32_t numBits = mode->GetCharacterCountBits(qcv, e); |
825 BC_EXCEPTION_CHECK_ReturnVoid(e); | 850 BC_EXCEPTION_CHECK_ReturnVoid(e); |
826 if (numBits > ((1 << numBits) - 1)) { | 851 if (numBits > ((1 << numBits) - 1)) { |
827 return; | 852 return; |
828 } | 853 } |
829 if (mode == CBC_QRCoderMode::sGBK) { | 854 if (mode == CBC_QRCoderMode::sGBK) { |
830 bits->AppendBits(numLetters / 2, numBits, e); | 855 bits->AppendBits(numLetters / 2, numBits, e); |
831 BC_EXCEPTION_CHECK_ReturnVoid(e); | 856 BC_EXCEPTION_CHECK_ReturnVoid(e); |
832 } | 857 } |
833 bits->AppendBits(numLetters, numBits, e); | 858 bits->AppendBits(numLetters, numBits, e); |
834 BC_EXCEPTION_CHECK_ReturnVoid(e); | 859 BC_EXCEPTION_CHECK_ReturnVoid(e); |
835 } | 860 } |
| 861 |
836 void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, | 862 void CBC_QRCoderEncoder::InterleaveWithECBytes(CBC_QRCoderBitVector* bits, |
837 int32_t numTotalBytes, | 863 int32_t numTotalBytes, |
838 int32_t numDataBytes, | 864 int32_t numDataBytes, |
839 int32_t numRSBlocks, | 865 int32_t numRSBlocks, |
840 CBC_QRCoderBitVector* result, | 866 CBC_QRCoderBitVector* result, |
841 int32_t& e) { | 867 int32_t& e) { |
842 if (bits->sizeInBytes() != numDataBytes) { | 868 if (bits->sizeInBytes() != numDataBytes) { |
843 e = BCExceptionBitsBytesNotMatch; | 869 e = BCExceptionBitsBytesNotMatch; |
844 BC_EXCEPTION_CHECK_ReturnVoid(e); | 870 BC_EXCEPTION_CHECK_ReturnVoid(e); |
845 } | 871 } |
846 int32_t dataBytesOffset = 0; | 872 int32_t dataBytesOffset = 0; |
847 int32_t maxNumDataBytes = 0; | 873 int32_t maxNumDataBytes = 0; |
848 int32_t maxNumEcBytes = 0; | 874 int32_t maxNumEcBytes = 0; |
849 CFX_ArrayTemplate<CBC_QRCoderBlockPair*> blocks; | 875 CFX_ArrayTemplate<CBC_QRCoderBlockPair*> blocks; |
850 int32_t i; | 876 int32_t i; |
851 for (i = 0; i < numRSBlocks; i++) { | 877 for (i = 0; i < numRSBlocks; i++) { |
852 int32_t numDataBytesInBlock; | 878 int32_t numDataBytesInBlock; |
853 int32_t numEcBytesInBlosk; | 879 int32_t numEcBytesInBlosk; |
854 GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes, | 880 GetNumDataBytesAndNumECBytesForBlockID(numTotalBytes, numDataBytes, |
855 numRSBlocks, i, numDataBytesInBlock, | 881 numRSBlocks, i, numDataBytesInBlock, |
856 numEcBytesInBlosk); | 882 numEcBytesInBlosk); |
857 CBC_CommonByteArray* dataBytes = new CBC_CommonByteArray; | 883 std::unique_ptr<CBC_CommonByteArray> dataBytes(new CBC_CommonByteArray); |
858 dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock); | 884 dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock); |
859 CBC_CommonByteArray* ecBytes = | 885 std::unique_ptr<CBC_CommonByteArray> ecBytes( |
860 GenerateECBytes(dataBytes, numEcBytesInBlosk, e); | 886 GenerateECBytes(dataBytes.get(), numEcBytesInBlosk, e)); |
861 BC_EXCEPTION_CHECK_ReturnVoid(e); | 887 BC_EXCEPTION_CHECK_ReturnVoid(e); |
862 blocks.Add(new CBC_QRCoderBlockPair(dataBytes, ecBytes)); | 888 blocks.Add( |
| 889 new CBC_QRCoderBlockPair(std::move(dataBytes), std::move(ecBytes))); |
863 maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size()); | 890 maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size()); |
864 maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size()); | 891 maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size()); |
865 dataBytesOffset += numDataBytesInBlock; | 892 dataBytesOffset += numDataBytesInBlock; |
866 } | 893 } |
867 if (numDataBytes != dataBytesOffset) { | 894 if (numDataBytes != dataBytesOffset) { |
868 e = BCExceptionBytesNotMatchOffset; | 895 e = BCExceptionBytesNotMatchOffset; |
869 BC_EXCEPTION_CHECK_ReturnVoid(e); | 896 BC_EXCEPTION_CHECK_ReturnVoid(e); |
870 } | 897 } |
871 for (int32_t x = 0; x < maxNumDataBytes; x++) { | 898 for (int32_t x = 0; x < maxNumDataBytes; x++) { |
872 for (int32_t j = 0; j < blocks.GetSize(); j++) { | 899 for (int32_t j = 0; j < blocks.GetSize(); j++) { |
873 CBC_CommonByteArray* dataBytes = blocks[j]->GetDataBytes(); | 900 const CBC_CommonByteArray* dataBytes = blocks[j]->GetDataBytes(); |
874 if (x < dataBytes->Size()) { | 901 if (x < dataBytes->Size()) { |
875 result->AppendBits(dataBytes->At(x), 8, e); | 902 result->AppendBits(dataBytes->At(x), 8, e); |
876 BC_EXCEPTION_CHECK_ReturnVoid(e); | 903 BC_EXCEPTION_CHECK_ReturnVoid(e); |
877 } | 904 } |
878 } | 905 } |
879 } | 906 } |
880 for (int32_t y = 0; y < maxNumEcBytes; y++) { | 907 for (int32_t y = 0; y < maxNumEcBytes; y++) { |
881 for (int32_t l = 0; l < blocks.GetSize(); l++) { | 908 for (int32_t l = 0; l < blocks.GetSize(); l++) { |
882 CBC_CommonByteArray* ecBytes = blocks[l]->GetErrorCorrectionBytes(); | 909 const CBC_CommonByteArray* ecBytes = blocks[l]->GetErrorCorrectionBytes(); |
883 if (y < ecBytes->Size()) { | 910 if (y < ecBytes->Size()) { |
884 result->AppendBits(ecBytes->At(y), 8, e); | 911 result->AppendBits(ecBytes->At(y), 8, e); |
885 BC_EXCEPTION_CHECK_ReturnVoid(e); | 912 BC_EXCEPTION_CHECK_ReturnVoid(e); |
886 } | 913 } |
887 } | 914 } |
888 } | 915 } |
889 for (int32_t k = 0; k < blocks.GetSize(); k++) { | 916 for (int32_t k = 0; k < blocks.GetSize(); k++) { |
890 delete blocks[k]; | 917 delete blocks[k]; |
891 } | 918 } |
892 if (numTotalBytes != result->sizeInBytes()) { | 919 if (numTotalBytes != result->sizeInBytes()) { |
893 e = BCExceptionSizeInBytesDiffer; | 920 e = BCExceptionSizeInBytesDiffer; |
894 BC_EXCEPTION_CHECK_ReturnVoid(e); | 921 BC_EXCEPTION_CHECK_ReturnVoid(e); |
895 } | 922 } |
896 } | 923 } |
| 924 |
897 void CBC_QRCoderEncoder::GetNumDataBytesAndNumECBytesForBlockID( | 925 void CBC_QRCoderEncoder::GetNumDataBytesAndNumECBytesForBlockID( |
898 int32_t numTotalBytes, | 926 int32_t numTotalBytes, |
899 int32_t numDataBytes, | 927 int32_t numDataBytes, |
900 int32_t numRSBlocks, | 928 int32_t numRSBlocks, |
901 int32_t blockID, | 929 int32_t blockID, |
902 int32_t& numDataBytesInBlock, | 930 int32_t& numDataBytesInBlock, |
903 int32_t& numECBytesInBlock) { | 931 int32_t& numECBytesInBlock) { |
904 if (blockID >= numRSBlocks) { | 932 if (blockID >= numRSBlocks) { |
905 return; | 933 return; |
906 } | 934 } |
907 int32_t numRsBlocksInGroup2 = numTotalBytes % numRSBlocks; | 935 int32_t numRsBlocksInGroup2 = numTotalBytes % numRSBlocks; |
908 int32_t numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2; | 936 int32_t numRsBlocksInGroup1 = numRSBlocks - numRsBlocksInGroup2; |
909 int32_t numTotalBytesInGroup1 = numTotalBytes / numRSBlocks; | 937 int32_t numTotalBytesInGroup1 = numTotalBytes / numRSBlocks; |
910 int32_t numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1; | 938 int32_t numTotalBytesInGroup2 = numTotalBytesInGroup1 + 1; |
911 int32_t numDataBytesInGroup1 = numDataBytes / numRSBlocks; | 939 int32_t numDataBytesInGroup1 = numDataBytes / numRSBlocks; |
912 int32_t numDataBytesInGroup2 = numDataBytesInGroup1 + 1; | 940 int32_t numDataBytesInGroup2 = numDataBytesInGroup1 + 1; |
913 int32_t numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1; | 941 int32_t numEcBytesInGroup1 = numTotalBytesInGroup1 - numDataBytesInGroup1; |
914 int32_t numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2; | 942 int32_t numEcBytesInGroup2 = numTotalBytesInGroup2 - numDataBytesInGroup2; |
915 if (blockID < numRsBlocksInGroup1) { | 943 if (blockID < numRsBlocksInGroup1) { |
916 numDataBytesInBlock = numDataBytesInGroup1; | 944 numDataBytesInBlock = numDataBytesInGroup1; |
917 numECBytesInBlock = numEcBytesInGroup1; | 945 numECBytesInBlock = numEcBytesInGroup1; |
918 } else { | 946 } else { |
919 numDataBytesInBlock = numDataBytesInGroup2; | 947 numDataBytesInBlock = numDataBytesInGroup2; |
920 numECBytesInBlock = numEcBytesInGroup2; | 948 numECBytesInBlock = numEcBytesInGroup2; |
921 } | 949 } |
922 } | 950 } |
| 951 |
923 CBC_CommonByteArray* CBC_QRCoderEncoder::GenerateECBytes( | 952 CBC_CommonByteArray* CBC_QRCoderEncoder::GenerateECBytes( |
924 CBC_CommonByteArray* dataBytes, | 953 CBC_CommonByteArray* dataBytes, |
925 int32_t numEcBytesInBlock, | 954 int32_t numEcBytesInBlock, |
926 int32_t& e) { | 955 int32_t& e) { |
927 int32_t numDataBytes = dataBytes->Size(); | 956 int32_t numDataBytes = dataBytes->Size(); |
928 CFX_Int32Array toEncode; | 957 CFX_Int32Array toEncode; |
929 toEncode.SetSize(numDataBytes + numEcBytesInBlock); | 958 toEncode.SetSize(numDataBytes + numEcBytesInBlock); |
930 for (int32_t i = 0; i < numDataBytes; i++) { | 959 for (int32_t i = 0; i < numDataBytes; i++) { |
931 toEncode[i] = (dataBytes->At(i)); | 960 toEncode[i] = (dataBytes->At(i)); |
932 } | 961 } |
933 CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeFild); | 962 CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeField); |
934 encode.Init(); | 963 encode.Init(); |
935 encode.Encode(&toEncode, numEcBytesInBlock, e); | 964 encode.Encode(&toEncode, numEcBytesInBlock, e); |
936 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); | 965 BC_EXCEPTION_CHECK_ReturnValue(e, nullptr); |
937 CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock); | 966 CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock); |
938 for (int32_t j = 0; j < numEcBytesInBlock; j++) { | 967 for (int32_t j = 0; j < numEcBytesInBlock; j++) { |
939 ecBytes->Set(j, toEncode[numDataBytes + j]); | 968 ecBytes->Set(j, toEncode[numDataBytes + j]); |
940 } | 969 } |
941 return ecBytes; | 970 return ecBytes; |
942 } | 971 } |
OLD | NEW |