Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.cpp

Issue 1734823002: Get rid of CBC_AutoPtr and use std::unique_ptr instead. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: rebase Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/src/fxbarcode/qrcode/BC_QRCoderEncoder.h"
24
23 #include <algorithm> 25 #include <algorithm>
26 #include <memory>
24 27
25 #include "xfa/src/fxbarcode/BC_UtilCodingConvert.h" 28 #include "xfa/src/fxbarcode/BC_UtilCodingConvert.h"
26 #include "xfa/src/fxbarcode/common/BC_CommonByteArray.h" 29 #include "xfa/src/fxbarcode/common/BC_CommonByteArray.h"
27 #include "xfa/src/fxbarcode/common/BC_CommonByteMatrix.h" 30 #include "xfa/src/fxbarcode/common/BC_CommonByteMatrix.h"
28 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.h" 31 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomon.h"
29 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h" 32 #include "xfa/src/fxbarcode/common/reedsolomon/BC_ReedSolomonGF256.h"
30 #include "xfa/src/fxbarcode/qrcode/BC_QRCoder.h" 33 #include "xfa/src/fxbarcode/qrcode/BC_QRCoder.h"
31 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderBitVector.h" 34 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderBitVector.h"
32 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderBlockPair.h" 35 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderBlockPair.h"
33 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderECBlocks.h" 36 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderECBlocks.h"
34 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.h"
35 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderEncoder.h"
36 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMaskUtil.h" 37 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMaskUtil.h"
37 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h" 38 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h"
38 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMode.h" 39 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderMode.h"
39 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderVersion.h" 40 #include "xfa/src/fxbarcode/qrcode/BC_QRCoderVersion.h"
40 41
41 const int32_t CBC_QRCoderEncoder::m_alphaNumbericTable[] = { 42 const int32_t CBC_QRCoderEncoder::m_alphaNumbericTable[] = {
42 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 43 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
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 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, 45 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
45 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, 46 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 for (int32_t j = 0; j < splitResult.GetSize(); j++) { 402 for (int32_t j = 0; j < splitResult.GetSize(); j++) {
402 delete (Make_Pair*)splitResult[j]; 403 delete (Make_Pair*)splitResult[j];
403 } 404 }
404 splitResult.RemoveAll(); 405 splitResult.RemoveAll();
405 CBC_QRCoderBitVector finalBits; 406 CBC_QRCoderBitVector finalBits;
406 finalBits.Init(); 407 finalBits.Init();
407 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), 408 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(),
408 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), 409 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(),
409 &finalBits, e); 410 &finalBits, e);
410 BC_EXCEPTION_CHECK_ReturnVoid(e); 411 BC_EXCEPTION_CHECK_ReturnVoid(e);
411 CBC_CommonByteMatrix* pDecoder = new CBC_CommonByteMatrix( 412 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix(
412 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()); 413 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()));
413 pDecoder->Init(); 414 matrix->Init();
414 CBC_AutoPtr<CBC_CommonByteMatrix> matrix(pDecoder);
415 int32_t maskPattern = ChooseMaskPattern( 415 int32_t maskPattern = ChooseMaskPattern(
416 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); 416 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e);
417 BC_EXCEPTION_CHECK_ReturnVoid(e); 417 BC_EXCEPTION_CHECK_ReturnVoid(e);
418 qrCode->SetMaskPattern(maskPattern); 418 qrCode->SetMaskPattern(maskPattern);
419 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), 419 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(),
420 qrCode->GetVersion(), 420 qrCode->GetVersion(),
421 qrCode->GetMaskPattern(), matrix.get(), e); 421 qrCode->GetMaskPattern(), matrix.get(), e);
422 BC_EXCEPTION_CHECK_ReturnVoid(e); 422 BC_EXCEPTION_CHECK_ReturnVoid(e);
423 qrCode->SetMatrix(matrix.release()); 423 qrCode->SetMatrix(matrix.release());
424 if (!qrCode->IsValid()) { 424 if (!qrCode->IsValid()) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 for (int32_t k = 0; k < splitResult.GetSize(); k++) { 492 for (int32_t k = 0; k < splitResult.GetSize(); k++) {
493 delete (Make_Pair*)splitResult[k]; 493 delete (Make_Pair*)splitResult[k];
494 } 494 }
495 splitResult.RemoveAll(); 495 splitResult.RemoveAll();
496 CBC_QRCoderBitVector finalBits; 496 CBC_QRCoderBitVector finalBits;
497 finalBits.Init(); 497 finalBits.Init();
498 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), 498 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(),
499 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), 499 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(),
500 &finalBits, e); 500 &finalBits, e);
501 BC_EXCEPTION_CHECK_ReturnVoid(e); 501 BC_EXCEPTION_CHECK_ReturnVoid(e);
502 CBC_CommonByteMatrix* pDecoder = new CBC_CommonByteMatrix( 502 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix(
503 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()); 503 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()));
504 pDecoder->Init(); 504 matrix->Init();
505 CBC_AutoPtr<CBC_CommonByteMatrix> matrix(pDecoder);
506 int32_t maskPattern = ChooseMaskPattern( 505 int32_t maskPattern = ChooseMaskPattern(
507 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); 506 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e);
508 BC_EXCEPTION_CHECK_ReturnVoid(e); 507 BC_EXCEPTION_CHECK_ReturnVoid(e);
509 qrCode->SetMaskPattern(maskPattern); 508 qrCode->SetMaskPattern(maskPattern);
510 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), 509 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(),
511 qrCode->GetVersion(), 510 qrCode->GetVersion(),
512 qrCode->GetMaskPattern(), matrix.get(), e); 511 qrCode->GetMaskPattern(), matrix.get(), e);
513 BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(matrix.release()); 512 BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(matrix.release());
514 if (!qrCode->IsValid()) { 513 if (!qrCode->IsValid()) {
515 e = BCExceptionInvalidQRCode; 514 e = BCExceptionInvalidQRCode;
(...skipping 27 matching lines...) Expand all
543 headerAndDataBits.AppendBitVector(&dataBits, e); 542 headerAndDataBits.AppendBitVector(&dataBits, e);
544 BC_EXCEPTION_CHECK_ReturnVoid(e) 543 BC_EXCEPTION_CHECK_ReturnVoid(e)
545 TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e); 544 TerminateBits(qrCode->GetNumDataBytes(), &headerAndDataBits, e);
546 BC_EXCEPTION_CHECK_ReturnVoid(e); 545 BC_EXCEPTION_CHECK_ReturnVoid(e);
547 CBC_QRCoderBitVector finalBits; 546 CBC_QRCoderBitVector finalBits;
548 finalBits.Init(); 547 finalBits.Init();
549 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(), 548 InterleaveWithECBytes(&headerAndDataBits, qrCode->GetNumTotalBytes(),
550 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(), 549 qrCode->GetNumDataBytes(), qrCode->GetNumRSBlocks(),
551 &finalBits, e); 550 &finalBits, e);
552 BC_EXCEPTION_CHECK_ReturnVoid(e); 551 BC_EXCEPTION_CHECK_ReturnVoid(e);
553 CBC_CommonByteMatrix* pDecoder = new CBC_CommonByteMatrix( 552 std::unique_ptr<CBC_CommonByteMatrix> matrix(new CBC_CommonByteMatrix(
554 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()); 553 qrCode->GetMatrixWidth(), qrCode->GetMatrixWidth()));
555 pDecoder->Init(); 554 matrix->Init();
556 CBC_AutoPtr<CBC_CommonByteMatrix> matrix(pDecoder);
557 int32_t maskPattern = ChooseMaskPattern( 555 int32_t maskPattern = ChooseMaskPattern(
558 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e); 556 &finalBits, qrCode->GetECLevel(), qrCode->GetVersion(), matrix.get(), e);
559 BC_EXCEPTION_CHECK_ReturnVoid(e); 557 BC_EXCEPTION_CHECK_ReturnVoid(e);
560 qrCode->SetMaskPattern(maskPattern); 558 qrCode->SetMaskPattern(maskPattern);
561 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(), 559 CBC_QRCoderMatrixUtil::BuildMatrix(&finalBits, qrCode->GetECLevel(),
562 qrCode->GetVersion(), 560 qrCode->GetVersion(),
563 qrCode->GetMaskPattern(), matrix.get(), e); 561 qrCode->GetMaskPattern(), matrix.get(), e);
564 BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(matrix.release()); 562 BC_EXCEPTION_CHECK_ReturnVoid(e) qrCode->SetMatrix(matrix.release());
565 if (!qrCode->IsValid()) { 563 if (!qrCode->IsValid()) {
566 e = BCExceptionInvalidQRCode; 564 e = BCExceptionInvalidQRCode;
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeFild); 952 CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeFild);
955 encode.Init(); 953 encode.Init();
956 encode.Encode(&toEncode, numEcBytesInBlock, e); 954 encode.Encode(&toEncode, numEcBytesInBlock, e);
957 BC_EXCEPTION_CHECK_ReturnValue(e, NULL); 955 BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
958 CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock); 956 CBC_CommonByteArray* ecBytes = new CBC_CommonByteArray(numEcBytesInBlock);
959 for (int32_t j = 0; j < numEcBytesInBlock; j++) { 957 for (int32_t j = 0; j < numEcBytesInBlock; j++) {
960 ecBytes->Set(j, toEncode[numDataBytes + j]); 958 ecBytes->Set(j, toEncode[numDataBytes + j]);
961 } 959 }
962 return ecBytes; 960 return ecBytes;
963 } 961 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698