summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn4
-rw-r--r--fxbarcode/qrcode/BC_QRCoder.cpp4
-rw-r--r--fxbarcode/qrcode/BC_QRCoder.h6
-rw-r--r--fxbarcode/qrcode/BC_QRCoderECB.cpp35
-rw-r--r--fxbarcode/qrcode/BC_QRCoderECB.h24
-rw-r--r--fxbarcode/qrcode/BC_QRCoderECBlocks.cpp36
-rw-r--r--fxbarcode/qrcode/BC_QRCoderECBlocks.h15
-rw-r--r--fxbarcode/qrcode/BC_QRCoderECBlocksData.cpp180
-rw-r--r--fxbarcode/qrcode/BC_QRCoderECBlocksData.h22
-rw-r--r--fxbarcode/qrcode/BC_QRCoderEncoder.cpp27
-rw-r--r--fxbarcode/qrcode/BC_QRCoderEncoder.h2
-rw-r--r--fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp6
-rw-r--r--fxbarcode/qrcode/BC_QRCoderMatrixUtil.h29
-rw-r--r--fxbarcode/qrcode/BC_QRCoderMode.cpp4
-rw-r--r--fxbarcode/qrcode/BC_QRCoderMode.h4
-rw-r--r--fxbarcode/qrcode/BC_QRCoderVersion.cpp732
-rw-r--r--fxbarcode/qrcode/BC_QRCoderVersion.h38
17 files changed, 325 insertions, 843 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 67be8cde74..5d8ac0ed7c 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1312,10 +1312,10 @@ if (pdf_enable_xfa) {
"fxbarcode/qrcode/BC_QRCoderBitVector.h",
"fxbarcode/qrcode/BC_QRCoderBlockPair.cpp",
"fxbarcode/qrcode/BC_QRCoderBlockPair.h",
- "fxbarcode/qrcode/BC_QRCoderECB.cpp",
- "fxbarcode/qrcode/BC_QRCoderECB.h",
"fxbarcode/qrcode/BC_QRCoderECBlocks.cpp",
"fxbarcode/qrcode/BC_QRCoderECBlocks.h",
+ "fxbarcode/qrcode/BC_QRCoderECBlocksData.cpp",
+ "fxbarcode/qrcode/BC_QRCoderECBlocksData.h",
"fxbarcode/qrcode/BC_QRCoderEncoder.cpp",
"fxbarcode/qrcode/BC_QRCoderEncoder.h",
"fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.cpp",
diff --git a/fxbarcode/qrcode/BC_QRCoder.cpp b/fxbarcode/qrcode/BC_QRCoder.cpp
index 93f0d00455..e3ac763499 100644
--- a/fxbarcode/qrcode/BC_QRCoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoder.cpp
@@ -45,7 +45,7 @@ CBC_QRCoderMode* CBC_QRCoder::GetMode() const {
return m_mode;
}
-CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const {
+const CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const {
return m_ecLevel;
}
@@ -104,7 +104,7 @@ void CBC_QRCoder::SetMode(CBC_QRCoderMode* value) {
m_mode = value;
}
-void CBC_QRCoder::SetECLevel(CBC_QRCoderErrorCorrectionLevel* ecLevel) {
+void CBC_QRCoder::SetECLevel(const CBC_QRCoderErrorCorrectionLevel* ecLevel) {
m_ecLevel = ecLevel;
}
diff --git a/fxbarcode/qrcode/BC_QRCoder.h b/fxbarcode/qrcode/BC_QRCoder.h
index 0925a8e5cd..adeae6c521 100644
--- a/fxbarcode/qrcode/BC_QRCoder.h
+++ b/fxbarcode/qrcode/BC_QRCoder.h
@@ -23,7 +23,7 @@ class CBC_QRCoder {
static bool IsValidMaskPattern(int32_t maskPattern);
CBC_QRCoderMode* GetMode() const;
- CBC_QRCoderErrorCorrectionLevel* GetECLevel() const;
+ const CBC_QRCoderErrorCorrectionLevel* GetECLevel() const;
int32_t GetVersion() const;
int32_t GetMatrixWidth() const;
int32_t GetMaskPattern() const;
@@ -37,7 +37,7 @@ class CBC_QRCoder {
bool IsValid();
void SetMode(CBC_QRCoderMode* value);
- void SetECLevel(CBC_QRCoderErrorCorrectionLevel* ecLevel);
+ void SetECLevel(const CBC_QRCoderErrorCorrectionLevel* ecLevel);
void SetVersion(int32_t version);
void SetMatrixWidth(int32_t width);
void SetMaskPattern(int32_t pattern);
@@ -49,7 +49,7 @@ class CBC_QRCoder {
private:
CBC_QRCoderMode* m_mode;
- CBC_QRCoderErrorCorrectionLevel* m_ecLevel;
+ const CBC_QRCoderErrorCorrectionLevel* m_ecLevel;
int32_t m_version;
int32_t m_matrixWidth;
int32_t m_maskPattern;
diff --git a/fxbarcode/qrcode/BC_QRCoderECB.cpp b/fxbarcode/qrcode/BC_QRCoderECB.cpp
deleted file mode 100644
index 65fbe33447..0000000000
--- a/fxbarcode/qrcode/BC_QRCoderECB.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-// Original code is licensed as follows:
-/*
- * Copyright 2007 ZXing authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "fxbarcode/qrcode/BC_QRCoderECB.h"
-
-CBC_QRCoderECB::CBC_QRCoderECB(int32_t count, int32_t dataCodeWords) {
- m_dataCodeWords = dataCodeWords;
- m_count = count;
-}
-CBC_QRCoderECB::~CBC_QRCoderECB() {}
-int32_t CBC_QRCoderECB::GetCount() {
- return m_count;
-}
-int32_t CBC_QRCoderECB::GetDataCodeWords() {
- return m_dataCodeWords;
-}
diff --git a/fxbarcode/qrcode/BC_QRCoderECB.h b/fxbarcode/qrcode/BC_QRCoderECB.h
deleted file mode 100644
index b774a3c19c..0000000000
--- a/fxbarcode/qrcode/BC_QRCoderECB.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FXBARCODE_QRCODE_BC_QRCODERECB_H_
-#define FXBARCODE_QRCODE_BC_QRCODERECB_H_
-
-#include <stdint.h>
-
-class CBC_QRCoderECB {
- private:
- int32_t m_count;
- int32_t m_dataCodeWords;
-
- public:
- CBC_QRCoderECB(int32_t count, int32_t dataCodeWords);
- virtual ~CBC_QRCoderECB();
- int32_t GetCount();
- int32_t GetDataCodeWords();
-};
-
-#endif // FXBARCODE_QRCODE_BC_QRCODERECB_H_
diff --git a/fxbarcode/qrcode/BC_QRCoderECBlocks.cpp b/fxbarcode/qrcode/BC_QRCoderECBlocks.cpp
index e07197df93..28f46882d9 100644
--- a/fxbarcode/qrcode/BC_QRCoderECBlocks.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderECBlocks.cpp
@@ -20,44 +20,28 @@
* limitations under the License.
*/
-#include "fxbarcode/qrcode/BC_QRCoderECB.h"
#include "fxbarcode/qrcode/BC_QRCoderECBlocks.h"
-CBC_QRCoderECBlocks::CBC_QRCoderECBlocks(int32_t ecCodeWordsPerBlock,
- CBC_QRCoderECB* ecBlocks)
- : m_ecCodeWordsPerBlock(ecCodeWordsPerBlock) {
- m_ecBlocksArray.push_back(ecBlocks);
-}
+#include "fxbarcode/qrcode/BC_QRCoderECBlocksData.h"
-CBC_QRCoderECBlocks::CBC_QRCoderECBlocks(int32_t ecCodeWordsPerBlock,
- CBC_QRCoderECB* ecBlocks1,
- CBC_QRCoderECB* ecBlocks2)
- : m_ecCodeWordsPerBlock(ecCodeWordsPerBlock) {
- m_ecBlocksArray.push_back(ecBlocks1);
- m_ecBlocksArray.push_back(ecBlocks2);
-}
+CBC_QRCoderECBlocks::CBC_QRCoderECBlocks(const CBC_QRCoderECBlockData& data)
+ : m_data(data) {}
-CBC_QRCoderECBlocks::~CBC_QRCoderECBlocks() {
- for (size_t i = 0; i < m_ecBlocksArray.size(); i++)
- delete m_ecBlocksArray[i];
-}
+CBC_QRCoderECBlocks::~CBC_QRCoderECBlocks() {}
int32_t CBC_QRCoderECBlocks::GetECCodeWordsPerBlock() const {
- return m_ecCodeWordsPerBlock;
+ return m_data.ecCodeWordsPerBlock;
}
int32_t CBC_QRCoderECBlocks::GetNumBlocks() const {
- int32_t total = 0;
- for (size_t i = 0; i < m_ecBlocksArray.size(); i++)
- total += m_ecBlocksArray[i]->GetCount();
-
- return total;
+ return m_data.count1 + m_data.count2;
}
int32_t CBC_QRCoderECBlocks::GetTotalECCodeWords() const {
- return m_ecCodeWordsPerBlock * GetNumBlocks();
+ return GetECCodeWordsPerBlock() * GetNumBlocks();
}
-std::vector<CBC_QRCoderECB*>* CBC_QRCoderECBlocks::GetECBlocks() {
- return &m_ecBlocksArray;
+int32_t CBC_QRCoderECBlocks::GetTotalDataCodeWords() const {
+ return m_data.count1 * (m_data.dataCodeWords1 + GetECCodeWordsPerBlock()) +
+ m_data.count2 * (m_data.dataCodeWords2 + GetECCodeWordsPerBlock());
}
diff --git a/fxbarcode/qrcode/BC_QRCoderECBlocks.h b/fxbarcode/qrcode/BC_QRCoderECBlocks.h
index bf4f76dc84..4ea7a7abd5 100644
--- a/fxbarcode/qrcode/BC_QRCoderECBlocks.h
+++ b/fxbarcode/qrcode/BC_QRCoderECBlocks.h
@@ -11,24 +11,21 @@
#include "core/fxcrt/fx_basic.h"
-class CBC_QRCoderECB;
+struct CBC_QRCoderECBlockData;
class CBC_QRCoderECBlocks {
public:
- CBC_QRCoderECBlocks(int32_t ecCodeWordsPerBlock, CBC_QRCoderECB* ecBlocks);
- CBC_QRCoderECBlocks(int32_t ecCodeWordsPerBlock,
- CBC_QRCoderECB* ecBlocks1,
- CBC_QRCoderECB* ecBlocks2);
+ explicit CBC_QRCoderECBlocks(const CBC_QRCoderECBlockData& data);
~CBC_QRCoderECBlocks();
- int32_t GetECCodeWordsPerBlock() const;
int32_t GetNumBlocks() const;
int32_t GetTotalECCodeWords() const;
- std::vector<CBC_QRCoderECB*>* GetECBlocks();
+ int32_t GetTotalDataCodeWords() const;
private:
- int32_t m_ecCodeWordsPerBlock;
- std::vector<CBC_QRCoderECB*> m_ecBlocksArray;
+ int32_t GetECCodeWordsPerBlock() const;
+
+ const CBC_QRCoderECBlockData& m_data;
};
#endif // FXBARCODE_QRCODE_BC_QRCODERECBLOCKS_H_
diff --git a/fxbarcode/qrcode/BC_QRCoderECBlocksData.cpp b/fxbarcode/qrcode/BC_QRCoderECBlocksData.cpp
new file mode 100644
index 0000000000..26ff748373
--- /dev/null
+++ b/fxbarcode/qrcode/BC_QRCoderECBlocksData.cpp
@@ -0,0 +1,180 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+// Original code is licensed as follows:
+/*
+ * Copyright 2007 ZXing authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "fxbarcode/qrcode/BC_QRCoderECBlocksData.h"
+
+const CBC_QRCoderECBlockData g_ECBData[40][4] = {
+ {{7, 1, 19, 0, 0}, {10, 1, 16, 0, 0}, {13, 1, 13, 0, 0}, {17, 1, 9, 0, 0}},
+ {{10, 1, 34, 0, 0},
+ {16, 1, 28, 0, 0},
+ {22, 1, 22, 0, 0},
+ {28, 1, 16, 0, 0}},
+ {{15, 1, 55, 0, 0},
+ {26, 1, 44, 0, 0},
+ {18, 2, 17, 0, 0},
+ {22, 2, 13, 0, 0}},
+ {{20, 1, 80, 0, 0}, {18, 2, 32, 0, 0}, {26, 2, 24, 0, 0}, {16, 4, 9, 0, 0}},
+ {{26, 1, 108, 0, 0},
+ {24, 2, 43, 0, 0},
+ {18, 2, 15, 2, 16},
+ {22, 2, 11, 2, 12}},
+ {{18, 2, 68, 0, 0},
+ {16, 4, 27, 0, 0},
+ {24, 4, 19, 0, 0},
+ {28, 4, 15, 0, 0}},
+ {{20, 2, 78, 0, 0},
+ {18, 4, 31, 0, 0},
+ {18, 2, 14, 4, 15},
+ {26, 4, 13, 1, 14}},
+ {{24, 2, 97, 0, 0},
+ {22, 2, 38, 2, 39},
+ {22, 4, 18, 2, 19},
+ {26, 4, 14, 2, 15}},
+ {{30, 2, 116, 0, 0},
+ {22, 3, 36, 2, 37},
+ {20, 4, 16, 4, 17},
+ {24, 4, 12, 4, 13}},
+ {{18, 2, 68, 2, 69},
+ {26, 4, 43, 1, 44},
+ {24, 6, 19, 2, 20},
+ {28, 6, 15, 2, 16}},
+ {{20, 4, 81, 0, 0},
+ {30, 1, 50, 4, 51},
+ {28, 4, 22, 4, 23},
+ {24, 3, 12, 8, 13}},
+ {{24, 2, 92, 2, 93},
+ {22, 6, 36, 2, 37},
+ {26, 4, 20, 6, 21},
+ {28, 7, 14, 4, 15}},
+ {{26, 4, 107, 0, 0},
+ {22, 8, 37, 1, 38},
+ {24, 8, 20, 4, 21},
+ {22, 12, 11, 4, 12}},
+ {{30, 3, 115, 1, 116},
+ {24, 4, 40, 5, 41},
+ {20, 11, 16, 5, 17},
+ {24, 11, 12, 5, 13}},
+ {{22, 5, 87, 1, 88},
+ {24, 5, 41, 5, 42},
+ {30, 5, 24, 7, 25},
+ {24, 11, 12, 7, 13}},
+ {{24, 5, 98, 1, 99},
+ {28, 7, 45, 3, 46},
+ {24, 15, 19, 2, 20},
+ {30, 3, 15, 13, 16}},
+ {{28, 1, 107, 5, 108},
+ {28, 10, 46, 1, 47},
+ {28, 1, 22, 15, 23},
+ {28, 2, 14, 17, 15}},
+ {{30, 5, 120, 1, 121},
+ {26, 9, 43, 4, 44},
+ {28, 17, 22, 1, 23},
+ {28, 2, 14, 19, 15}},
+ {{28, 3, 113, 4, 114},
+ {26, 3, 44, 11, 45},
+ {26, 17, 21, 4, 22},
+ {26, 9, 13, 16, 14}},
+ {{28, 3, 107, 5, 108},
+ {26, 3, 41, 13, 42},
+ {30, 15, 24, 5, 25},
+ {28, 15, 15, 10, 16}},
+ {{28, 4, 116, 4, 117},
+ {26, 17, 42, 0, 0},
+ {28, 17, 22, 6, 23},
+ {30, 19, 16, 6, 17}},
+ {{28, 2, 111, 7, 112},
+ {28, 17, 46, 0, 0},
+ {30, 7, 24, 16, 25},
+ {24, 34, 13, 0, 0}},
+ {{30, 4, 121, 5, 122},
+ {28, 4, 47, 14, 48},
+ {30, 11, 24, 14, 25},
+ {30, 16, 15, 14, 16}},
+ {{30, 6, 117, 4, 118},
+ {28, 6, 45, 14, 46},
+ {30, 11, 24, 16, 25},
+ {30, 30, 16, 2, 17}},
+ {{26, 8, 106, 4, 107},
+ {28, 8, 47, 13, 48},
+ {30, 7, 24, 22, 25},
+ {30, 22, 15, 13, 16}},
+ {{28, 10, 114, 2, 115},
+ {28, 19, 46, 4, 47},
+ {28, 28, 22, 6, 23},
+ {30, 33, 16, 4, 17}},
+ {{30, 8, 122, 4, 123},
+ {28, 22, 45, 3, 46},
+ {30, 8, 23, 26, 24},
+ {30, 12, 15, 28, 16}},
+ {{30, 3, 117, 10, 118},
+ {28, 3, 45, 23, 46},
+ {30, 4, 24, 31, 25},
+ {30, 11, 15, 31, 16}},
+ {{30, 7, 116, 7, 117},
+ {28, 21, 45, 7, 46},
+ {30, 1, 23, 37, 24},
+ {30, 19, 15, 26, 16}},
+ {{30, 5, 115, 10, 116},
+ {28, 19, 47, 10, 48},
+ {30, 15, 24, 25, 25},
+ {30, 23, 15, 25, 16}},
+ {{30, 13, 115, 3, 116},
+ {28, 2, 46, 29, 47},
+ {30, 42, 24, 1, 25},
+ {30, 23, 15, 28, 16}},
+ {{30, 17, 115, 0, 0},
+ {28, 10, 46, 23, 47},
+ {30, 10, 24, 35, 25},
+ {30, 19, 15, 35, 16}},
+ {{30, 17, 115, 1, 116},
+ {28, 14, 46, 21, 47},
+ {30, 29, 24, 19, 25},
+ {30, 11, 15, 46, 16}},
+ {{30, 13, 115, 6, 116},
+ {28, 14, 46, 23, 47},
+ {30, 44, 24, 7, 25},
+ {30, 59, 16, 1, 17}},
+ {{30, 12, 121, 7, 122},
+ {28, 12, 47, 26, 48},
+ {30, 39, 24, 14, 25},
+ {30, 22, 15, 41, 16}},
+ {{30, 6, 121, 14, 122},
+ {28, 6, 47, 34, 48},
+ {30, 46, 24, 10, 25},
+ {30, 2, 15, 64, 16}},
+ {{30, 17, 122, 4, 123},
+ {28, 29, 46, 14, 47},
+ {30, 49, 24, 10, 25},
+ {30, 24, 15, 46, 16}},
+ {{30, 4, 122, 18, 123},
+ {28, 13, 46, 32, 47},
+ {30, 48, 24, 14, 25},
+ {30, 42, 15, 32, 16}},
+ {{30, 20, 117, 4, 118},
+ {28, 40, 47, 7, 48},
+ {30, 43, 24, 22, 25},
+ {30, 10, 15, 67, 16}},
+ {{30, 19, 118, 6, 119},
+ {28, 18, 47, 31, 48},
+ {30, 34, 24, 34, 25},
+ {30, 20, 15, 61, 16}},
+};
diff --git a/fxbarcode/qrcode/BC_QRCoderECBlocksData.h b/fxbarcode/qrcode/BC_QRCoderECBlocksData.h
new file mode 100644
index 0000000000..0f1ae20b84
--- /dev/null
+++ b/fxbarcode/qrcode/BC_QRCoderECBlocksData.h
@@ -0,0 +1,22 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef FXBARCODE_QRCODE_BC_QRCODERECBLOCKSDATA_H_
+#define FXBARCODE_QRCODE_BC_QRCODERECBLOCKSDATA_H_
+
+#include "core/fxcrt/fx_basic.h"
+
+struct CBC_QRCoderECBlockData {
+ uint8_t ecCodeWordsPerBlock;
+ uint8_t count1;
+ uint8_t dataCodeWords1;
+ uint8_t count2;
+ uint8_t dataCodeWords2;
+};
+
+extern const CBC_QRCoderECBlockData g_ECBData[40][4];
+
+#endif // FXBARCODE_QRCODE_BC_QRCODERECBLOCKSDATA_H_
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index 0971caab51..a08bf31ea4 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -43,8 +43,6 @@
using ModeStringPair = std::pair<CBC_QRCoderMode*, CFX_ByteString>;
-const int32_t kMaxVersion = 40;
-
namespace {
// This is a mapping for an ASCII table, starting at an index of 32.
@@ -171,10 +169,10 @@ bool AppendLengthInfo(int32_t numLetters,
CBC_QRCoderMode* mode,
CBC_QRCoderBitVector* bits) {
int32_t e = BCExceptionNO;
- CBC_QRCoderVersion* qcv = CBC_QRCoderVersion::GetVersionForNumber(version);
+ const auto* qcv = CBC_QRCoderVersion::GetVersionForNumber(version);
if (!qcv)
return false;
- int32_t numBits = mode->GetCharacterCountBits(qcv, e);
+ int32_t numBits = mode->GetCharacterCountBits(qcv->GetVersionNumber(), e);
if (e != BCExceptionNO)
return false;
if (numBits > ((1 << numBits) - 1))
@@ -206,24 +204,23 @@ void AppendBytes(const CFX_ByteString& content,
}
void InitQRCode(int32_t numInputBytes,
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
CBC_QRCoderMode* mode,
CBC_QRCoder* qrCode,
int32_t& e) {
qrCode->SetECLevel(ecLevel);
qrCode->SetMode(mode);
- for (int32_t versionNum = 1; versionNum <= kMaxVersion; versionNum++) {
- CBC_QRCoderVersion* version =
- CBC_QRCoderVersion::GetVersionForNumber(versionNum);
+ for (int32_t i = 1; i <= CBC_QRCoderVersion::kMaxVersion; ++i) {
+ const auto* version = CBC_QRCoderVersion::GetVersionForNumber(i);
if (!version)
return;
int32_t numBytes = version->GetTotalCodeWords();
- CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel);
+ const auto* ecBlocks = version->GetECBlocksForLevel(*ecLevel);
int32_t numEcBytes = ecBlocks->GetTotalECCodeWords();
int32_t numRSBlocks = ecBlocks->GetNumBlocks();
int32_t numDataBytes = numBytes - numEcBytes;
if (numDataBytes >= numInputBytes + 3) {
- qrCode->SetVersion(versionNum);
+ qrCode->SetVersion(i);
qrCode->SetNumTotalBytes(numBytes);
qrCode->SetNumDataBytes(numDataBytes);
qrCode->SetNumRSBlocks(numRSBlocks);
@@ -265,7 +262,7 @@ int32_t GetSpanByVersion(CBC_QRCoderMode* modeFirst,
return 11;
if (versionNum >= 10 && versionNum <= 26)
return 15;
- if (versionNum >= 27 && versionNum <= kMaxVersion)
+ if (versionNum >= 27 && versionNum <= CBC_QRCoderVersion::kMaxVersion)
return 16;
e = BCExceptionNoSuchVersion;
return 0;
@@ -276,7 +273,7 @@ int32_t GetSpanByVersion(CBC_QRCoderMode* modeFirst,
return 13;
if (versionNum >= 10 && versionNum <= 26)
return 15;
- if (versionNum >= 27 && versionNum <= kMaxVersion)
+ if (versionNum >= 27 && versionNum <= CBC_QRCoderVersion::kMaxVersion)
return 17;
e = BCExceptionNoSuchVersion;
return 0;
@@ -287,7 +284,7 @@ int32_t GetSpanByVersion(CBC_QRCoderMode* modeFirst,
return 6;
if (versionNum >= 10 && versionNum <= 26)
return 8;
- if (versionNum >= 27 && versionNum <= kMaxVersion)
+ if (versionNum >= 27 && versionNum <= CBC_QRCoderVersion::kMaxVersion)
return 9;
e = BCExceptionNoSuchVersion;
return 0;
@@ -303,7 +300,7 @@ int32_t CalculateMaskPenalty(CBC_CommonByteMatrix* matrix) {
}
int32_t ChooseMaskPattern(CBC_QRCoderBitVector* bits,
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
int32_t version,
CBC_CommonByteMatrix* matrix,
int32_t& e) {
@@ -581,7 +578,7 @@ CBC_QRCoderEncoder::CBC_QRCoderEncoder() {}
CBC_QRCoderEncoder::~CBC_QRCoderEncoder() {}
void CBC_QRCoderEncoder::Encode(const CFX_WideString& content,
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
CBC_QRCoder* qrCode,
int32_t& e) {
CFX_ByteString encoding = "utf8";
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.h b/fxbarcode/qrcode/BC_QRCoderEncoder.h
index 75611ff180..46ee05b43b 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.h
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.h
@@ -22,7 +22,7 @@ class CBC_QRCoderEncoder {
~CBC_QRCoderEncoder();
static void Encode(const CFX_WideString& content,
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
CBC_QRCoder* qrCode,
int32_t& e);
};
diff --git a/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp b/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp
index b0be2b6f2a..d5b7bcd69d 100644
--- a/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderMatrixUtil.cpp
@@ -85,7 +85,7 @@ void CBC_QRCoderMatrixUtil::ClearMatrix(CBC_CommonByteMatrix* matrix,
}
void CBC_QRCoderMatrixUtil::BuildMatrix(
CBC_QRCoderBitVector* dataBits,
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
int32_t version,
int32_t maskPattern,
CBC_CommonByteMatrix* matrix,
@@ -132,7 +132,7 @@ void CBC_QRCoderMatrixUtil::EmbedBasicPatterns(int32_t version,
}
void CBC_QRCoderMatrixUtil::EmbedTypeInfo(
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
int32_t maskPattern,
CBC_CommonByteMatrix* matrix,
int32_t& e) {
@@ -254,7 +254,7 @@ int32_t CBC_QRCoderMatrixUtil::CalculateBCHCode(int32_t value, int32_t poly) {
return value;
}
void CBC_QRCoderMatrixUtil::MakeTypeInfoBits(
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
int32_t maskPattern,
CBC_QRCoderBitVector* bits,
int32_t& e) {
diff --git a/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h b/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h
index 3535c43c74..23fe0df8da 100644
--- a/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h
+++ b/fxbarcode/qrcode/BC_QRCoderMatrixUtil.h
@@ -10,24 +10,14 @@
class CBC_CommonByteMatrix;
class CBC_QRCoderErrorCorrectionLevel;
class CBC_QRCoderBitVector;
-class CBC_QRCoderMatrixUtil {
- private:
- static const int32_t POSITION_DETECTION_PATTERN[7][7];
- static const int32_t VERTICAL_SEPARATION_PATTERN[7][1];
- static const int32_t HORIZONTAL_SEPARATION_PATTERN[1][8];
- static const int32_t POSITION_ADJUSTMENT_PATTERN[5][5];
- static const int32_t POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[40][7];
- static const int32_t TYPE_INFO_COORDINATES[15][2];
- static const int32_t VERSION_INFO_POLY;
- static const int32_t TYPE_INFO_POLY;
- static const int32_t TYPE_INFO_MASK_PATTERN;
+class CBC_QRCoderMatrixUtil {
public:
CBC_QRCoderMatrixUtil();
virtual ~CBC_QRCoderMatrixUtil();
static void ClearMatrix(CBC_CommonByteMatrix* matrix, int32_t& e);
static void BuildMatrix(CBC_QRCoderBitVector* dataBits,
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ const CBC_QRCoderErrorCorrectionLevel* ecLevel,
int32_t version,
int32_t maskPattern,
CBC_CommonByteMatrix* matrix,
@@ -35,7 +25,7 @@ class CBC_QRCoderMatrixUtil {
static void EmbedBasicPatterns(int32_t version,
CBC_CommonByteMatrix* matrix,
int32_t& e);
- static void EmbedTypeInfo(CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ static void EmbedTypeInfo(const CBC_QRCoderErrorCorrectionLevel* ecLevel,
int32_t maskPattern,
CBC_CommonByteMatrix* matrix,
int32_t& e);
@@ -48,7 +38,7 @@ class CBC_QRCoderMatrixUtil {
int32_t& e);
static int32_t FindMSBSet(int32_t value);
static int32_t CalculateBCHCode(int32_t code, int32_t poly);
- static void MakeTypeInfoBits(CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ static void MakeTypeInfoBits(const CBC_QRCoderErrorCorrectionLevel* ecLevel,
int32_t maskPattern,
CBC_QRCoderBitVector* bits,
int32_t& e);
@@ -82,6 +72,17 @@ class CBC_QRCoderMatrixUtil {
static void MaybeEmbedPositionAdjustmentPatterns(int32_t version,
CBC_CommonByteMatrix* matrix,
int32_t& e);
+
+ private:
+ static const int32_t POSITION_DETECTION_PATTERN[7][7];
+ static const int32_t VERTICAL_SEPARATION_PATTERN[7][1];
+ static const int32_t HORIZONTAL_SEPARATION_PATTERN[1][8];
+ static const int32_t POSITION_ADJUSTMENT_PATTERN[5][5];
+ static const int32_t POSITION_ADJUSTMENT_PATTERN_COORDINATE_TABLE[40][7];
+ static const int32_t TYPE_INFO_COORDINATES[15][2];
+ static const int32_t VERSION_INFO_POLY;
+ static const int32_t TYPE_INFO_POLY;
+ static const int32_t TYPE_INFO_MASK_PATTERN;
};
#endif // FXBARCODE_QRCODE_BC_QRCODERMATRIXUTIL_H_
diff --git a/fxbarcode/qrcode/BC_QRCoderMode.cpp b/fxbarcode/qrcode/BC_QRCoderMode.cpp
index 3127145465..5f9ce5bf25 100644
--- a/fxbarcode/qrcode/BC_QRCoderMode.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderMode.cpp
@@ -24,7 +24,6 @@
#include <utility>
-#include "fxbarcode/qrcode/BC_QRCoderVersion.h"
#include "fxbarcode/utils.h"
CBC_QRCoderMode* CBC_QRCoderMode::sBYTE = nullptr;
@@ -112,13 +111,12 @@ CFX_ByteString CBC_QRCoderMode::GetName() const {
return m_name;
}
-int32_t CBC_QRCoderMode::GetCharacterCountBits(CBC_QRCoderVersion* version,
+int32_t CBC_QRCoderMode::GetCharacterCountBits(int32_t number,
int32_t& e) const {
if (m_characterCountBitsForVersions.empty()) {
e = BCExceptionCharacterNotThisMode;
return 0;
}
- int32_t number = version->GetVersionNumber();
int32_t offset;
if (number <= 9) {
offset = 0;
diff --git a/fxbarcode/qrcode/BC_QRCoderMode.h b/fxbarcode/qrcode/BC_QRCoderMode.h
index 4402e3fe26..6669cbfbc9 100644
--- a/fxbarcode/qrcode/BC_QRCoderMode.h
+++ b/fxbarcode/qrcode/BC_QRCoderMode.h
@@ -13,8 +13,6 @@
#include "core/fxcrt/fx_string.h"
-class CBC_QRCoderVersion;
-
class CBC_QRCoderMode {
public:
virtual ~CBC_QRCoderMode();
@@ -24,7 +22,7 @@ class CBC_QRCoderMode {
static CBC_QRCoderMode* ForBits(int32_t bits, int32_t& e);
static void Destroy();
- int32_t GetCharacterCountBits(CBC_QRCoderVersion* version, int32_t& e) const;
+ int32_t GetCharacterCountBits(int32_t number, int32_t& e) const;
int32_t GetBits() const;
CFX_ByteString GetName() const;
diff --git a/fxbarcode/qrcode/BC_QRCoderVersion.cpp b/fxbarcode/qrcode/BC_QRCoderVersion.cpp
index 67ca42804c..7da603359d 100644
--- a/fxbarcode/qrcode/BC_QRCoderVersion.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderVersion.cpp
@@ -20,708 +20,80 @@
* limitations under the License.
*/
+#include "fxbarcode/qrcode/BC_QRCoderVersion.h"
+
+#include <memory>
+#include <vector>
+
#include "fxbarcode/common/BC_CommonBitMatrix.h"
#include "fxbarcode/qrcode/BC_QRCoderBitVector.h"
-#include "fxbarcode/qrcode/BC_QRCoderECB.h"
-#include "fxbarcode/qrcode/BC_QRCoderECBlocks.h"
+#include "fxbarcode/qrcode/BC_QRCoderECBlocksData.h"
#include "fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h"
-#include "fxbarcode/qrcode/BC_QRCoderVersion.h"
#include "fxbarcode/utils.h"
+#include "third_party/base/ptr_util.h"
-const int32_t CBC_QRCoderVersion::VERSION_DECODE_INFO[] = {
- 0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847,
- 0x0E60D, 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6,
- 0x15683, 0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB, 0x1B08E,
- 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250, 0x209D5, 0x216F0, 0x228BA,
- 0x2379F, 0x24B0B, 0x2542E, 0x26A64, 0x27541, 0x28C69};
+namespace {
-std::vector<CBC_QRCoderVersion*>* CBC_QRCoderVersion::VERSION = nullptr;
+std::vector<std::unique_ptr<CBC_QRCoderVersion>>* g_VERSION = nullptr;
-void CBC_QRCoderVersion::Initialize() {
- VERSION = new std::vector<CBC_QRCoderVersion*>();
-}
-void CBC_QRCoderVersion::Finalize() {
- for (size_t i = 0; i < VERSION->size(); i++)
- delete (*VERSION)[i];
+} // namespace
- delete VERSION;
- VERSION = nullptr;
-}
CBC_QRCoderVersion::CBC_QRCoderVersion(int32_t versionNumber,
- CBC_QRCoderECBlocks* ecBlocks1,
- CBC_QRCoderECBlocks* ecBlocks2,
- CBC_QRCoderECBlocks* ecBlocks3,
- CBC_QRCoderECBlocks* ecBlocks4) {
- m_versionNumber = versionNumber;
- m_ecBlocksArray.push_back(ecBlocks1);
- m_ecBlocksArray.push_back(ecBlocks2);
- m_ecBlocksArray.push_back(ecBlocks3);
- m_ecBlocksArray.push_back(ecBlocks4);
- int32_t total = 0;
- int32_t ecCodeWords = ecBlocks1->GetECCodeWordsPerBlock();
- std::vector<CBC_QRCoderECB*>* ecbArray = ecBlocks1->GetECBlocks();
- for (size_t i = 0; i < ecbArray->size(); i++) {
- CBC_QRCoderECB* ecBlock = (*ecbArray)[i];
- total += ecBlock->GetCount() * (ecBlock->GetDataCodeWords() + ecCodeWords);
- }
- m_totalCodeWords = total;
- switch (versionNumber) {
- case 1:
- break;
- case 2:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(18);
- break;
- case 3:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(22);
- break;
- case 4:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- break;
- case 5:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- break;
- case 6:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(34);
- break;
- case 7:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(22);
- m_alignmentPatternCenters.push_back(38);
- break;
- case 8:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(24);
- m_alignmentPatternCenters.push_back(42);
- break;
- case 9:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- m_alignmentPatternCenters.push_back(46);
- break;
- case 10:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(28);
- m_alignmentPatternCenters.push_back(50);
- break;
- case 11:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(54);
- break;
- case 12:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(32);
- m_alignmentPatternCenters.push_back(58);
- break;
- case 13:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(34);
- m_alignmentPatternCenters.push_back(62);
- break;
- case 14:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- m_alignmentPatternCenters.push_back(46);
- m_alignmentPatternCenters.push_back(66);
- break;
- case 15:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- m_alignmentPatternCenters.push_back(48);
- m_alignmentPatternCenters.push_back(70);
- break;
- case 16:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- m_alignmentPatternCenters.push_back(50);
- m_alignmentPatternCenters.push_back(74);
- break;
- case 17:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(54);
- m_alignmentPatternCenters.push_back(78);
- break;
- case 18:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(56);
- m_alignmentPatternCenters.push_back(82);
- break;
- case 19:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(58);
- m_alignmentPatternCenters.push_back(86);
- break;
- case 20:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(34);
- m_alignmentPatternCenters.push_back(62);
- m_alignmentPatternCenters.push_back(90);
- break;
- case 21:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(28);
- m_alignmentPatternCenters.push_back(50);
- m_alignmentPatternCenters.push_back(72);
- m_alignmentPatternCenters.push_back(94);
- break;
- case 22:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- m_alignmentPatternCenters.push_back(50);
- m_alignmentPatternCenters.push_back(74);
- m_alignmentPatternCenters.push_back(98);
- break;
- case 23:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(54);
- m_alignmentPatternCenters.push_back(74);
- m_alignmentPatternCenters.push_back(102);
- break;
- case 24:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(28);
- m_alignmentPatternCenters.push_back(54);
- m_alignmentPatternCenters.push_back(80);
- m_alignmentPatternCenters.push_back(106);
- break;
- case 25:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(32);
- m_alignmentPatternCenters.push_back(58);
- m_alignmentPatternCenters.push_back(84);
- m_alignmentPatternCenters.push_back(110);
- break;
- case 26:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(58);
- m_alignmentPatternCenters.push_back(86);
- m_alignmentPatternCenters.push_back(114);
- break;
- case 27:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(34);
- m_alignmentPatternCenters.push_back(62);
- m_alignmentPatternCenters.push_back(90);
- m_alignmentPatternCenters.push_back(118);
- break;
- case 28:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- m_alignmentPatternCenters.push_back(50);
- m_alignmentPatternCenters.push_back(74);
- m_alignmentPatternCenters.push_back(98);
- m_alignmentPatternCenters.push_back(122);
- break;
- case 29:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(54);
- m_alignmentPatternCenters.push_back(78);
- m_alignmentPatternCenters.push_back(102);
- m_alignmentPatternCenters.push_back(126);
- break;
- case 30:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- m_alignmentPatternCenters.push_back(52);
- m_alignmentPatternCenters.push_back(78);
- m_alignmentPatternCenters.push_back(104);
- m_alignmentPatternCenters.push_back(130);
- break;
- case 31:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(56);
- m_alignmentPatternCenters.push_back(82);
- m_alignmentPatternCenters.push_back(108);
- m_alignmentPatternCenters.push_back(134);
- break;
- case 32:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(34);
- m_alignmentPatternCenters.push_back(60);
- m_alignmentPatternCenters.push_back(86);
- m_alignmentPatternCenters.push_back(112);
- m_alignmentPatternCenters.push_back(138);
- break;
- case 33:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(58);
- m_alignmentPatternCenters.push_back(86);
- m_alignmentPatternCenters.push_back(114);
- m_alignmentPatternCenters.push_back(142);
- break;
- case 34:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(34);
- m_alignmentPatternCenters.push_back(62);
- m_alignmentPatternCenters.push_back(90);
- m_alignmentPatternCenters.push_back(118);
- m_alignmentPatternCenters.push_back(146);
- break;
- case 35:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(54);
- m_alignmentPatternCenters.push_back(78);
- m_alignmentPatternCenters.push_back(102);
- m_alignmentPatternCenters.push_back(126);
- m_alignmentPatternCenters.push_back(150);
- break;
- case 36:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(24);
- m_alignmentPatternCenters.push_back(50);
- m_alignmentPatternCenters.push_back(76);
- m_alignmentPatternCenters.push_back(102);
- m_alignmentPatternCenters.push_back(128);
- m_alignmentPatternCenters.push_back(154);
- break;
- case 37:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(28);
- m_alignmentPatternCenters.push_back(54);
- m_alignmentPatternCenters.push_back(80);
- m_alignmentPatternCenters.push_back(106);
- m_alignmentPatternCenters.push_back(132);
- m_alignmentPatternCenters.push_back(158);
- break;
- case 38:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(32);
- m_alignmentPatternCenters.push_back(58);
- m_alignmentPatternCenters.push_back(84);
- m_alignmentPatternCenters.push_back(110);
- m_alignmentPatternCenters.push_back(136);
- m_alignmentPatternCenters.push_back(162);
- break;
- case 39:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(26);
- m_alignmentPatternCenters.push_back(54);
- m_alignmentPatternCenters.push_back(82);
- m_alignmentPatternCenters.push_back(110);
- m_alignmentPatternCenters.push_back(138);
- m_alignmentPatternCenters.push_back(166);
- break;
- case 40:
- m_alignmentPatternCenters.push_back(6);
- m_alignmentPatternCenters.push_back(30);
- m_alignmentPatternCenters.push_back(58);
- m_alignmentPatternCenters.push_back(86);
- m_alignmentPatternCenters.push_back(114);
- m_alignmentPatternCenters.push_back(142);
- m_alignmentPatternCenters.push_back(170);
- break;
- }
+ const CBC_QRCoderECBlockData data[4])
+ : m_versionNumber(versionNumber) {
+ m_ecBlocksArray[0] = pdfium::MakeUnique<CBC_QRCoderECBlocks>(data[0]);
+ m_ecBlocksArray[1] = pdfium::MakeUnique<CBC_QRCoderECBlocks>(data[1]);
+ m_ecBlocksArray[2] = pdfium::MakeUnique<CBC_QRCoderECBlocks>(data[2]);
+ m_ecBlocksArray[3] = pdfium::MakeUnique<CBC_QRCoderECBlocks>(data[3]);
+ m_totalCodeWords = m_ecBlocksArray[0]->GetTotalDataCodeWords();
}
CBC_QRCoderVersion::~CBC_QRCoderVersion() {
- for (size_t i = 0; i < m_ecBlocksArray.size(); ++i)
- delete m_ecBlocksArray[i];
}
-int32_t CBC_QRCoderVersion::GetVersionNumber() {
- return m_versionNumber;
-}
-std::vector<int32_t>* CBC_QRCoderVersion::GetAlignmentPatternCenters() {
- return &m_alignmentPatternCenters;
-}
-int32_t CBC_QRCoderVersion::GetTotalCodeWords() {
- return m_totalCodeWords;
-}
-int32_t CBC_QRCoderVersion::GetDimensionForVersion() {
- return 17 + 4 * m_versionNumber;
-}
-CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel(
- CBC_QRCoderErrorCorrectionLevel* ecLevel) {
- return m_ecBlocksArray[ecLevel->Ordinal()];
+// static
+void CBC_QRCoderVersion::Initialize() {
+ g_VERSION = new std::vector<std::unique_ptr<CBC_QRCoderVersion>>();
}
-CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) {
- int32_t dimension = GetDimensionForVersion();
- CBC_CommonBitMatrix* bitMatrix = new CBC_CommonBitMatrix();
- bitMatrix->Init(dimension);
- if (!bitMatrix->SetRegion(0, 0, 9, 9))
- return nullptr;
- if (!bitMatrix->SetRegion(dimension - 8, 0, 8, 9))
- return nullptr;
- if (!bitMatrix->SetRegion(0, dimension - 8, 9, 8))
- return nullptr;
- size_t max = m_alignmentPatternCenters.size();
- for (size_t x = 0; x < max; x++) {
- int32_t i = m_alignmentPatternCenters[x] - 2;
- for (size_t y = 0; y < max; y++) {
- if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
- continue;
- }
- if (!bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5))
- return nullptr;
- }
- }
- if (!bitMatrix->SetRegion(6, 9, 1, dimension - 17))
- return nullptr;
- if (!bitMatrix->SetRegion(9, 6, dimension - 17, 1))
- return nullptr;
- if (m_versionNumber > 6) {
- if (!bitMatrix->SetRegion(dimension - 11, 0, 3, 6))
- return nullptr;
- if (!bitMatrix->SetRegion(0, dimension - 11, 6, 3))
- return nullptr;
- }
- return bitMatrix;
+// static
+void CBC_QRCoderVersion::Finalize() {
+ delete g_VERSION;
+ g_VERSION = nullptr;
}
-CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(
+// static
+const CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(
int32_t versionNumber) {
- if (VERSION->empty()) {
- VERSION->push_back(new CBC_QRCoderVersion(
- 1, new CBC_QRCoderECBlocks(7, new CBC_QRCoderECB(1, 19)),
- new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 16)),
- new CBC_QRCoderECBlocks(13, new CBC_QRCoderECB(1, 13)),
- new CBC_QRCoderECBlocks(17, new CBC_QRCoderECB(1, 9))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 2, new CBC_QRCoderECBlocks(10, new CBC_QRCoderECB(1, 34)),
- new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(1, 28)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(1, 22)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 3, new CBC_QRCoderECBlocks(15, new CBC_QRCoderECB(1, 55)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(1, 44)),
- new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 17)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 13))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 4, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(1, 80)),
- new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 32)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(2, 24)),
- new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(4, 9))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 5, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(1, 108)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 43)),
- new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 15),
- new CBC_QRCoderECB(2, 16)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 11),
- new CBC_QRCoderECB(2, 12))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 6, new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 68)),
- new CBC_QRCoderECBlocks(16, new CBC_QRCoderECB(4, 27)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 19)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 15))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 7, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(2, 78)),
- new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(4, 31)),
- new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 14),
- new CBC_QRCoderECB(4, 15)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 13),
- new CBC_QRCoderECB(1, 14))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 8, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 97)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(2, 38),
- new CBC_QRCoderECB(2, 39)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(4, 18),
- new CBC_QRCoderECB(2, 19)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 14),
- new CBC_QRCoderECB(2, 15))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 9, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(2, 116)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(3, 36),
- new CBC_QRCoderECB(2, 37)),
- new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(4, 16),
- new CBC_QRCoderECB(4, 17)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 12),
- new CBC_QRCoderECB(4, 13))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 10, new CBC_QRCoderECBlocks(18, new CBC_QRCoderECB(2, 68),
- new CBC_QRCoderECB(2, 69)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 43),
- new CBC_QRCoderECB(1, 44)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(6, 19),
- new CBC_QRCoderECB(2, 20)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 15),
- new CBC_QRCoderECB(2, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 11, new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(4, 81)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(1, 50),
- new CBC_QRCoderECB(4, 51)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 22),
- new CBC_QRCoderECB(4, 23)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(3, 12),
- new CBC_QRCoderECB(8, 13))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 12, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(2, 92),
- new CBC_QRCoderECB(2, 93)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(6, 36),
- new CBC_QRCoderECB(2, 37)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 20),
- new CBC_QRCoderECB(6, 21)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(7, 14),
- new CBC_QRCoderECB(4, 15))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 13, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(4, 107)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(8, 37),
- new CBC_QRCoderECB(1, 38)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(8, 20),
- new CBC_QRCoderECB(4, 21)),
- new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(12, 11),
- new CBC_QRCoderECB(4, 12))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 14, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 115),
- new CBC_QRCoderECB(1, 116)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(4, 40),
- new CBC_QRCoderECB(5, 41)),
- new CBC_QRCoderECBlocks(20, new CBC_QRCoderECB(11, 16),
- new CBC_QRCoderECB(5, 17)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(11, 12),
- new CBC_QRCoderECB(5, 13))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 15, new CBC_QRCoderECBlocks(22, new CBC_QRCoderECB(5, 87),
- new CBC_QRCoderECB(1, 88)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(5, 41),
- new CBC_QRCoderECB(5, 42)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 24),
- new CBC_QRCoderECB(7, 25)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(11, 12),
- new CBC_QRCoderECB(7, 13))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 16, new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(5, 98),
- new CBC_QRCoderECB(1, 99)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(7, 45),
- new CBC_QRCoderECB(3, 46)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(15, 19),
- new CBC_QRCoderECB(2, 20)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 15),
- new CBC_QRCoderECB(13, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 17, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 107),
- new CBC_QRCoderECB(5, 108)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 46),
- new CBC_QRCoderECB(1, 47)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(1, 22),
- new CBC_QRCoderECB(15, 23)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 14),
- new CBC_QRCoderECB(17, 15))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 18, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 120),
- new CBC_QRCoderECB(1, 121)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(9, 43),
- new CBC_QRCoderECB(4, 44)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 22),
- new CBC_QRCoderECB(1, 23)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 14),
- new CBC_QRCoderECB(19, 15))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 19, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 113),
- new CBC_QRCoderECB(4, 114)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(3, 44),
- new CBC_QRCoderECB(11, 45)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(17, 21),
- new CBC_QRCoderECB(4, 22)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(9, 13),
- new CBC_QRCoderECB(16, 14))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 20, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 107),
- new CBC_QRCoderECB(5, 108)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(3, 41),
- new CBC_QRCoderECB(13, 42)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(15, 24),
- new CBC_QRCoderECB(5, 25)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(15, 15),
- new CBC_QRCoderECB(10, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 21, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 116),
- new CBC_QRCoderECB(4, 117)),
- new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(17, 42)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 22),
- new CBC_QRCoderECB(6, 23)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 16),
- new CBC_QRCoderECB(6, 17))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 22, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 111),
- new CBC_QRCoderECB(7, 112)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(17, 46)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 24),
- new CBC_QRCoderECB(16, 25)),
- new CBC_QRCoderECBlocks(24, new CBC_QRCoderECB(34, 13))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 23, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 121),
- new CBC_QRCoderECB(5, 122)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(4, 47),
- new CBC_QRCoderECB(14, 48)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 24),
- new CBC_QRCoderECB(14, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(16, 15),
- new CBC_QRCoderECB(14, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 24, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(6, 117),
- new CBC_QRCoderECB(4, 118)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 45),
- new CBC_QRCoderECB(14, 46)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 24),
- new CBC_QRCoderECB(16, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(30, 16),
- new CBC_QRCoderECB(2, 17))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 25, new CBC_QRCoderECBlocks(26, new CBC_QRCoderECB(8, 106),
- new CBC_QRCoderECB(4, 107)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(8, 47),
- new CBC_QRCoderECB(13, 48)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 24),
- new CBC_QRCoderECB(22, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(22, 15),
- new CBC_QRCoderECB(13, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 26, new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 114),
- new CBC_QRCoderECB(2, 115)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(19, 46),
- new CBC_QRCoderECB(4, 47)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(28, 22),
- new CBC_QRCoderECB(6, 23)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(33, 16),
- new CBC_QRCoderECB(4, 17))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 27, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(8, 122),
- new CBC_QRCoderECB(4, 123)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(22, 45),
- new CBC_QRCoderECB(3, 46)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(8, 23),
- new CBC_QRCoderECB(26, 24)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(12, 15),
- new CBC_QRCoderECB(28, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 28, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(3, 117),
- new CBC_QRCoderECB(10, 118)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(3, 45),
- new CBC_QRCoderECB(23, 46)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 24),
- new CBC_QRCoderECB(31, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 15),
- new CBC_QRCoderECB(31, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 29, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(7, 116),
- new CBC_QRCoderECB(7, 117)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(21, 45),
- new CBC_QRCoderECB(7, 46)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(1, 23),
- new CBC_QRCoderECB(37, 24)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 15),
- new CBC_QRCoderECB(26, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 30, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(5, 115),
- new CBC_QRCoderECB(10, 116)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(19, 47),
- new CBC_QRCoderECB(10, 48)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(15, 24),
- new CBC_QRCoderECB(25, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(23, 15),
- new CBC_QRCoderECB(25, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 31, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(13, 115),
- new CBC_QRCoderECB(3, 116)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(2, 46),
- new CBC_QRCoderECB(29, 47)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(42, 24),
- new CBC_QRCoderECB(1, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(23, 15),
- new CBC_QRCoderECB(28, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 32, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 115)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(10, 46),
- new CBC_QRCoderECB(23, 47)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(10, 24),
- new CBC_QRCoderECB(35, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 15),
- new CBC_QRCoderECB(35, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 33, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 115),
- new CBC_QRCoderECB(1, 116)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(14, 46),
- new CBC_QRCoderECB(21, 47)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(29, 24),
- new CBC_QRCoderECB(19, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(11, 15),
- new CBC_QRCoderECB(46, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 34, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(13, 115),
- new CBC_QRCoderECB(6, 116)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(14, 46),
- new CBC_QRCoderECB(23, 47)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(44, 24),
- new CBC_QRCoderECB(7, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(59, 16),
- new CBC_QRCoderECB(1, 17))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 35, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(12, 121),
- new CBC_QRCoderECB(7, 122)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(12, 47),
- new CBC_QRCoderECB(26, 48)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(39, 24),
- new CBC_QRCoderECB(14, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(22, 15),
- new CBC_QRCoderECB(41, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 36, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(6, 121),
- new CBC_QRCoderECB(14, 122)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(6, 47),
- new CBC_QRCoderECB(34, 48)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(46, 24),
- new CBC_QRCoderECB(10, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(2, 15),
- new CBC_QRCoderECB(64, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 37, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(17, 122),
- new CBC_QRCoderECB(4, 123)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(29, 46),
- new CBC_QRCoderECB(14, 47)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(49, 24),
- new CBC_QRCoderECB(10, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(24, 15),
- new CBC_QRCoderECB(46, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 38, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(4, 122),
- new CBC_QRCoderECB(18, 123)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(13, 46),
- new CBC_QRCoderECB(32, 47)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(48, 24),
- new CBC_QRCoderECB(14, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(42, 15),
- new CBC_QRCoderECB(32, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 39, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 117),
- new CBC_QRCoderECB(4, 118)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(40, 47),
- new CBC_QRCoderECB(7, 48)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(43, 24),
- new CBC_QRCoderECB(22, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(10, 15),
- new CBC_QRCoderECB(67, 16))));
- VERSION->push_back(new CBC_QRCoderVersion(
- 40, new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(19, 118),
- new CBC_QRCoderECB(6, 119)),
- new CBC_QRCoderECBlocks(28, new CBC_QRCoderECB(18, 47),
- new CBC_QRCoderECB(31, 48)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(34, 24),
- new CBC_QRCoderECB(34, 25)),
- new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 15),
- new CBC_QRCoderECB(61, 16))));
+ if (g_VERSION->empty()) {
+ for (int i = 0; i < kMaxVersion; ++i) {
+ g_VERSION->push_back(
+ pdfium::MakeUnique<CBC_QRCoderVersion>(i + 1, g_ECBData[i]));
+ }
}
- if (versionNumber < 1 || versionNumber > 40)
+ if (versionNumber < 1 || versionNumber > kMaxVersion)
return nullptr;
- return (*VERSION)[versionNumber - 1];
+ return (*g_VERSION)[versionNumber - 1].get();
}
+// static
void CBC_QRCoderVersion::Destroy() {
- for (size_t i = 0; i < VERSION->size(); i++)
- delete (*VERSION)[i];
- VERSION->clear();
+ g_VERSION->clear();
+}
+
+int32_t CBC_QRCoderVersion::GetVersionNumber() const {
+ return m_versionNumber;
+}
+
+int32_t CBC_QRCoderVersion::GetTotalCodeWords() const {
+ return m_totalCodeWords;
+}
+
+int32_t CBC_QRCoderVersion::GetDimensionForVersion() const {
+ return 17 + 4 * m_versionNumber;
+}
+
+const CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel(
+ const CBC_QRCoderErrorCorrectionLevel& ecLevel) const {
+ return m_ecBlocksArray[ecLevel.Ordinal()].get();
}
diff --git a/fxbarcode/qrcode/BC_QRCoderVersion.h b/fxbarcode/qrcode/BC_QRCoderVersion.h
index b6dad2299d..0c9509b457 100644
--- a/fxbarcode/qrcode/BC_QRCoderVersion.h
+++ b/fxbarcode/qrcode/BC_QRCoderVersion.h
@@ -7,46 +7,38 @@
#ifndef FXBARCODE_QRCODE_BC_QRCODERVERSION_H_
#define FXBARCODE_QRCODE_BC_QRCODERVERSION_H_
+#include <memory>
#include <vector>
#include "core/fxcrt/fx_basic.h"
+#include "fxbarcode/qrcode/BC_QRCoderECBlocks.h"
-class CBC_CommonBitMatrix;
-class CBC_QRCoderECBlocks;
class CBC_QRCoderErrorCorrectionLevel;
class CBC_QRCoderVersion {
public:
+ static constexpr int32_t kMaxVersion = 40;
+
+ CBC_QRCoderVersion(int32_t versionNumber,
+ const CBC_QRCoderECBlockData data[4]);
~CBC_QRCoderVersion();
+
static void Initialize();
static void Finalize();
- static CBC_QRCoderVersion* GetVersionForNumber(int32_t versionNumber);
+ static const CBC_QRCoderVersion* GetVersionForNumber(int32_t versionNumber);
static void Destroy();
- int32_t GetVersionNumber();
- int32_t GetTotalCodeWords();
- int32_t GetDimensionForVersion();
- CBC_CommonBitMatrix* BuildFunctionPattern(int32_t& e);
- std::vector<int32_t>* GetAlignmentPatternCenters();
- CBC_QRCoderECBlocks* GetECBlocksForLevel(
- CBC_QRCoderErrorCorrectionLevel* ecLevel);
+ int32_t GetVersionNumber() const;
+ int32_t GetTotalCodeWords() const;
+ int32_t GetDimensionForVersion() const;
+ const CBC_QRCoderECBlocks* GetECBlocksForLevel(
+ const CBC_QRCoderErrorCorrectionLevel& ecLevel) const;
private:
- CBC_QRCoderVersion();
- CBC_QRCoderVersion(int32_t versionNumber,
- CBC_QRCoderECBlocks* ecBlocks1,
- CBC_QRCoderECBlocks* ecBlocks2,
- CBC_QRCoderECBlocks* ecBlocks3,
- CBC_QRCoderECBlocks* ecBlocks4);
-
- static const int32_t VERSION_DECODE_INFO[34];
- static std::vector<CBC_QRCoderVersion*>* VERSION;
-
- int32_t m_versionNumber;
+ const int32_t m_versionNumber;
int32_t m_totalCodeWords;
- std::vector<int32_t> m_alignmentPatternCenters;
- std::vector<CBC_QRCoderECBlocks*> m_ecBlocksArray;
+ std::unique_ptr<CBC_QRCoderECBlocks> m_ecBlocksArray[4];
};
#endif // FXBARCODE_QRCODE_BC_QRCODERVERSION_H_