• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 // Original code is licensed as follows:
7 /*
8  * Copyright 2008 ZXing authors
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 
23 #include <utility>
24 
25 #include "fxbarcode/common/BC_CommonByteMatrix.h"
26 #include "fxbarcode/qrcode/BC_QRCoder.h"
27 #include "fxbarcode/qrcode/BC_QRCoderErrorCorrectionLevel.h"
28 #include "fxbarcode/qrcode/BC_QRCoderMode.h"
29 #include "fxbarcode/utils.h"
30 
CBC_QRCoder()31 CBC_QRCoder::CBC_QRCoder()
32     : m_mode(nullptr),
33       m_ecLevel(nullptr),
34       m_version(-1),
35       m_matrixWidth(-1),
36       m_maskPattern(-1),
37       m_numTotalBytes(-1),
38       m_numDataBytes(-1),
39       m_numECBytes(-1),
40       m_numRSBlocks(-1) {}
41 
~CBC_QRCoder()42 CBC_QRCoder::~CBC_QRCoder() {}
43 
GetMode() const44 CBC_QRCoderMode* CBC_QRCoder::GetMode() const {
45   return m_mode.Get();
46 }
47 
GetECLevel() const48 const CBC_QRCoderErrorCorrectionLevel* CBC_QRCoder::GetECLevel() const {
49   return m_ecLevel.Get();
50 }
51 
GetVersion() const52 int32_t CBC_QRCoder::GetVersion() const {
53   return m_version;
54 }
55 
GetMatrixWidth() const56 int32_t CBC_QRCoder::GetMatrixWidth() const {
57   return m_matrixWidth;
58 }
59 
GetMaskPattern() const60 int32_t CBC_QRCoder::GetMaskPattern() const {
61   return m_maskPattern;
62 }
63 
GetNumTotalBytes() const64 int32_t CBC_QRCoder::GetNumTotalBytes() const {
65   return m_numTotalBytes;
66 }
67 
GetNumDataBytes() const68 int32_t CBC_QRCoder::GetNumDataBytes() const {
69   return m_numDataBytes;
70 }
71 
GetNumECBytes() const72 int32_t CBC_QRCoder::GetNumECBytes() const {
73   return m_numECBytes;
74 }
75 
GetNumRSBlocks() const76 int32_t CBC_QRCoder::GetNumRSBlocks() const {
77   return m_numRSBlocks;
78 }
79 
GetMatrix() const80 CBC_CommonByteMatrix* CBC_QRCoder::GetMatrix() const {
81   return m_matrix.get();
82 }
83 
At(int32_t x,int32_t y,int32_t & e)84 int32_t CBC_QRCoder::At(int32_t x, int32_t y, int32_t& e) {
85   int32_t value = m_matrix->Get(x, y);
86   if (!(value == 0 || value == 1)) {
87     e = BCExceptionValueMustBeEither0or1;
88     return 0;
89   }
90   return value;
91 }
92 
IsValid()93 bool CBC_QRCoder::IsValid() {
94   return m_mode && m_ecLevel && m_version != -1 && m_matrixWidth != -1 &&
95          m_maskPattern != -1 && m_numTotalBytes != -1 && m_numDataBytes != -1 &&
96          m_numECBytes != -1 && m_numRSBlocks != -1 &&
97          IsValidMaskPattern(m_maskPattern) &&
98          m_numTotalBytes == m_numDataBytes + m_numECBytes && m_matrix &&
99          m_matrixWidth == m_matrix->GetWidth() &&
100          m_matrix->GetWidth() == m_matrix->GetHeight();
101 }
102 
SetMode(CBC_QRCoderMode * value)103 void CBC_QRCoder::SetMode(CBC_QRCoderMode* value) {
104   m_mode = value;
105 }
106 
SetECLevel(const CBC_QRCoderErrorCorrectionLevel * ecLevel)107 void CBC_QRCoder::SetECLevel(const CBC_QRCoderErrorCorrectionLevel* ecLevel) {
108   m_ecLevel = ecLevel;
109 }
110 
SetVersion(int32_t version)111 void CBC_QRCoder::SetVersion(int32_t version) {
112   m_version = version;
113 }
114 
SetMatrixWidth(int32_t width)115 void CBC_QRCoder::SetMatrixWidth(int32_t width) {
116   m_matrixWidth = width;
117 }
118 
SetMaskPattern(int32_t pattern)119 void CBC_QRCoder::SetMaskPattern(int32_t pattern) {
120   m_maskPattern = pattern;
121 }
122 
SetNumDataBytes(int32_t bytes)123 void CBC_QRCoder::SetNumDataBytes(int32_t bytes) {
124   m_numDataBytes = bytes;
125 }
126 
SetNumTotalBytes(int32_t value)127 void CBC_QRCoder::SetNumTotalBytes(int32_t value) {
128   m_numTotalBytes = value;
129 }
130 
SetNumRSBlocks(int32_t block)131 void CBC_QRCoder::SetNumRSBlocks(int32_t block) {
132   m_numRSBlocks = block;
133 }
134 
SetNumECBytes(int32_t value)135 void CBC_QRCoder::SetNumECBytes(int32_t value) {
136   m_numECBytes = value;
137 }
138 
IsValidMaskPattern(int32_t maskPattern)139 bool CBC_QRCoder::IsValidMaskPattern(int32_t maskPattern) {
140   return maskPattern >= 0 && maskPattern < kNumMaskPatterns;
141 }
142 
SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix)143 void CBC_QRCoder::SetMatrix(std::unique_ptr<CBC_CommonByteMatrix> pMatrix) {
144   m_matrix = std::move(pMatrix);
145 }
146