Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
BC_QRCoderVersion.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6// Original code is licensed as follows:
7/*
8 * Copyright 2007 ZXing authors
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23#include "fxbarcode/qrcode/BC_QRCoderVersion.h"
24
25#include <memory>
26#include <vector>
27
28#include "fxbarcode/common/BC_CommonBitMatrix.h"
29#include "fxbarcode/qrcode/BC_QRCoderBitVector.h"
30#include "fxbarcode/qrcode/BC_QRCoderECBlocksData.h"
31#include "fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h"
32
33namespace {
34
35std::vector<std::unique_ptr<CBC_QRCoderVersion>>* g_VERSION = nullptr;
36
37} // namespace
38
40 const CBC_QRCoderECBlockData data[4])
41 : m_versionNumber(versionNumber) {
42 m_ecBlocksArray[0] = std::make_unique<CBC_QRCoderECBlocks>(data[0]);
43 m_ecBlocksArray[1] = std::make_unique<CBC_QRCoderECBlocks>(data[1]);
44 m_ecBlocksArray[2] = std::make_unique<CBC_QRCoderECBlocks>(data[2]);
45 m_ecBlocksArray[3] = std::make_unique<CBC_QRCoderECBlocks>(data[3]);
46 m_totalCodeWords = m_ecBlocksArray[0]->GetTotalDataCodeWords();
47}
48
50
51// static
53 g_VERSION = new std::vector<std::unique_ptr<CBC_QRCoderVersion>>();
54}
55
56// static
58 delete g_VERSION;
59 g_VERSION = nullptr;
60}
61
62// static
64 int32_t versionNumber) {
65 if (g_VERSION->empty()) {
66 for (int i = 0; i < kMaxVersion; ++i) {
67 g_VERSION->push_back(
68 std::make_unique<CBC_QRCoderVersion>(i + 1, fxbarcode::kECBData[i]));
69 }
70 }
71 if (versionNumber < 1 || versionNumber > kMaxVersion)
72 return nullptr;
73 return (*g_VERSION)[versionNumber - 1].get();
74}
75
77 return m_versionNumber;
78}
79
81 return m_totalCodeWords;
82}
83
85 return 17 + 4 * m_versionNumber;
86}
87
89 const CBC_QRCoderErrorCorrectionLevel& ecLevel) const {
90 return m_ecBlocksArray[ecLevel.Ordinal()].get();
91}
int32_t GetDimensionForVersion() const
CBC_QRCoderVersion(int32_t versionNumber, const CBC_QRCoderECBlockData data[4])
int32_t GetVersionNumber() const
static const CBC_QRCoderVersion * GetVersionForNumber(int32_t versionNumber)
static constexpr int32_t kMaxVersion
int32_t GetTotalCodeWords() const
const CBC_QRCoderECBlocks * GetECBlocksForLevel(const CBC_QRCoderErrorCorrectionLevel &ecLevel) const
const CBC_QRCoderECBlockData kECBData[40][4]