summaryrefslogtreecommitdiff
path: root/xfa/fxbarcode/qrcode
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxbarcode/qrcode')
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp2
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp14
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp22
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRDataBlock.h25
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRDataMask.cpp34
-rw-r--r--xfa/fxbarcode/qrcode/BC_QRDataMask.h7
6 files changed, 53 insertions, 51 deletions
diff --git a/xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp b/xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp
index 53803588b5..3fe6783d38 100644
--- a/xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRBitMatrixParser.cpp
@@ -142,7 +142,7 @@ CFX_ByteArray* CBC_QRBitMatrixParser::ReadCodewords(int32_t& e) {
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
int32_t dimension = m_bitMatrix->GetDimension(e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- dataMask->UnmaskBitMatirx(m_bitMatrix, dimension);
+ dataMask->UnmaskBitMatrix(m_bitMatrix, dimension);
std::unique_ptr<CBC_CommonBitMatrix> functionPattern(
version->BuildFunctionPattern(e));
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
diff --git a/xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp b/xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp
index 1966146805..360a69a0ec 100644
--- a/xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRCoderDecoder.cpp
@@ -74,26 +74,24 @@ CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(CBC_CommonBitMatrix* bits,
CBC_QRCoderErrorCorrectionLevel* ecLevel = temp->GetErrorCorrectionLevel();
std::unique_ptr<CFX_ByteArray> codewords(parser.ReadCodewords(e));
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
- CFX_PtrArray* dataBlocks =
+ CFX_ArrayTemplate<CBC_QRDataBlock*>* dataBlocks =
CBC_QRDataBlock::GetDataBlocks(codewords.get(), version, ecLevel, e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
int32_t totalBytes = 0;
for (int32_t i = 0; i < dataBlocks->GetSize(); i++) {
- totalBytes += ((CBC_QRDataBlock*)((*dataBlocks)[i]))->GetNumDataCodewords();
+ totalBytes += (*dataBlocks)[i]->GetNumDataCodewords();
}
CFX_ByteArray resultBytes;
for (int32_t j = 0; j < dataBlocks->GetSize(); j++) {
- CBC_QRDataBlock* dataBlock = (CBC_QRDataBlock*)((*dataBlocks)[j]);
+ CBC_QRDataBlock* dataBlock = (*dataBlocks)[j];
CFX_ByteArray* codewordBytes = dataBlock->GetCodewords();
int32_t numDataCodewords = dataBlock->GetNumDataCodewords();
CorrectErrors(codewordBytes, numDataCodewords, e);
if (e != BCExceptionNO) {
for (int32_t k = 0; k < dataBlocks->GetSize(); k++) {
- delete (CBC_QRDataBlock*)(*dataBlocks)[k];
+ delete (*dataBlocks)[k];
}
- dataBlocks->RemoveAll();
delete dataBlocks;
- dataBlocks = NULL;
return NULL;
}
for (int32_t i = 0; i < numDataCodewords; i++) {
@@ -101,11 +99,9 @@ CBC_CommonDecoderResult* CBC_QRCoderDecoder::Decode(CBC_CommonBitMatrix* bits,
}
}
for (int32_t k = 0; k < dataBlocks->GetSize(); k++) {
- delete (CBC_QRDataBlock*)(*dataBlocks)[k];
+ delete (*dataBlocks)[k];
}
- dataBlocks->RemoveAll();
delete dataBlocks;
- dataBlocks = NULL;
CBC_CommonDecoderResult* cdr = CBC_QRDecodedBitStreamParser::Decode(
&resultBytes, version, ecLevel, byteModeDecode, e);
BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
diff --git a/xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp b/xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp
index 721301cccc..31f0b1841d 100644
--- a/xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRDataBlock.cpp
@@ -41,7 +41,7 @@ int32_t CBC_QRDataBlock::GetNumDataCodewords() {
CFX_ByteArray* CBC_QRDataBlock::GetCodewords() {
return m_codewords;
}
-CFX_PtrArray* CBC_QRDataBlock::GetDataBlocks(
+CFX_ArrayTemplate<CBC_QRDataBlock*>* CBC_QRDataBlock::GetDataBlocks(
CFX_ByteArray* rawCodewords,
CBC_QRCoderVersion* version,
CBC_QRCoderErrorCorrectionLevel* ecLevel,
@@ -57,7 +57,8 @@ CFX_PtrArray* CBC_QRDataBlock::GetDataBlocks(
for (i = 0; i < ecBlockArray->GetSize(); i++) {
totalBlocks += (*ecBlockArray)[i]->GetCount();
}
- std::unique_ptr<CFX_PtrArray> result(new CFX_PtrArray());
+ std::unique_ptr<CFX_ArrayTemplate<CBC_QRDataBlock*>> result(
+ new CFX_ArrayTemplate<CBC_QRDataBlock*>());
result->SetSize(totalBlocks);
int32_t numResultBlocks = 0;
for (int32_t j = 0; j < ecBlockArray->GetSize(); j++) {
@@ -72,12 +73,11 @@ CFX_PtrArray* CBC_QRDataBlock::GetDataBlocks(
new CBC_QRDataBlock(numDataCodewords, bytearray);
}
}
- int32_t shorterBlocksTotalCodewords =
- ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize();
+ int32_t shorterBlocksTotalCodewords = (*result)[0]->m_codewords->GetSize();
int32_t longerBlocksStartAt = result->GetSize() - 1;
while (longerBlocksStartAt >= 0) {
- int32_t numCodewords = ((CBC_QRDataBlock*)(*result)[longerBlocksStartAt])
- ->m_codewords->GetSize();
+ int32_t numCodewords =
+ (*result)[longerBlocksStartAt]->m_codewords->GetSize();
if (numCodewords == shorterBlocksTotalCodewords) {
break;
}
@@ -90,20 +90,18 @@ CFX_PtrArray* CBC_QRDataBlock::GetDataBlocks(
int32_t x = 0;
for (int32_t k = 0; k < shorterBlocksNumDataCodewords; k++) {
for (x = 0; x < numResultBlocks; x++) {
- (*(((CBC_QRDataBlock*)(*result)[x])->m_codewords))[k] =
- (*rawCodewords)[rawCodewordsOffset++];
+ (*((*result)[x]->m_codewords))[k] = (*rawCodewords)[rawCodewordsOffset++];
}
}
for (x = longerBlocksStartAt; x < numResultBlocks; x++) {
- (*(((CBC_QRDataBlock*)(*result)[x])
- ->m_codewords))[shorterBlocksNumDataCodewords] =
+ (*((*result)[x]->m_codewords))[shorterBlocksNumDataCodewords] =
(*rawCodewords)[rawCodewordsOffset++];
}
- int32_t max = ((CBC_QRDataBlock*)(*result)[0])->m_codewords->GetSize();
+ int32_t max = (*result)[0]->m_codewords->GetSize();
for (i = shorterBlocksNumDataCodewords; i < max; i++) {
for (int32_t y = 0; y < numResultBlocks; y++) {
int32_t iOffset = y < longerBlocksStartAt ? i : i + 1;
- (*(((CBC_QRDataBlock*)(*result)[y])->m_codewords))[iOffset] =
+ (*((*result)[y]->m_codewords))[iOffset] =
(*rawCodewords)[rawCodewordsOffset++];
}
}
diff --git a/xfa/fxbarcode/qrcode/BC_QRDataBlock.h b/xfa/fxbarcode/qrcode/BC_QRDataBlock.h
index 873904f7c6..014018dec0 100644
--- a/xfa/fxbarcode/qrcode/BC_QRDataBlock.h
+++ b/xfa/fxbarcode/qrcode/BC_QRDataBlock.h
@@ -9,22 +9,25 @@
#include "core/fxcrt/include/fx_basic.h"
-class CBC_QRCoderVersion;
class CBC_QRCoderErrorCorrectionLevel;
-class CBC_QRDataBlock {
- private:
- int32_t m_numDataCodewords;
- CFX_ByteArray* m_codewords;
- CBC_QRDataBlock(int32_t numDataCodewords, CFX_ByteArray* codewords);
+class CBC_QRCoderVersion;
+class CBC_QRDataBlock final {
public:
- virtual ~CBC_QRDataBlock();
+ ~CBC_QRDataBlock();
int32_t GetNumDataCodewords();
CFX_ByteArray* GetCodewords();
- static CFX_PtrArray* GetDataBlocks(CFX_ByteArray* rawCodewords,
- CBC_QRCoderVersion* version,
- CBC_QRCoderErrorCorrectionLevel* ecLevel,
- int32_t& e);
+ static CFX_ArrayTemplate<CBC_QRDataBlock*>* GetDataBlocks(
+ CFX_ByteArray* rawCodewords,
+ CBC_QRCoderVersion* version,
+ CBC_QRCoderErrorCorrectionLevel* ecLevel,
+ int32_t& e);
+
+ private:
+ CBC_QRDataBlock(int32_t numDataCodewords, CFX_ByteArray* codewords);
+
+ int32_t m_numDataCodewords;
+ CFX_ByteArray* m_codewords;
};
#endif // XFA_FXBARCODE_QRCODE_BC_QRDATABLOCK_H_
diff --git a/xfa/fxbarcode/qrcode/BC_QRDataMask.cpp b/xfa/fxbarcode/qrcode/BC_QRDataMask.cpp
index 20f94069f4..9b5e3ca014 100644
--- a/xfa/fxbarcode/qrcode/BC_QRDataMask.cpp
+++ b/xfa/fxbarcode/qrcode/BC_QRDataMask.cpp
@@ -24,43 +24,47 @@
#include "xfa/fxbarcode/qrcode/BC_QRDataMask.h"
#include "xfa/fxbarcode/utils.h"
-static int32_t N_DATA_MASKS = 0;
-CFX_PtrArray* CBC_QRDataMask::DATA_MASKS = NULL;
+namespace {
+
+int32_t N_DATA_MASKS = 0;
+CFX_ArrayTemplate<CBC_QRDataMask*>* DATA_MASKS = nullptr;
+
+} // namespace
void CBC_QRDataMask::Initialize() {
- DATA_MASKS = new CFX_PtrArray();
+ DATA_MASKS = new CFX_ArrayTemplate<CBC_QRDataMask*>();
N_DATA_MASKS = BuildDataMasks();
}
+
void CBC_QRDataMask::Finalize() {
Destroy();
delete DATA_MASKS;
+ DATA_MASKS = nullptr;
}
+
void CBC_QRDataMask::Destroy() {
- int32_t i;
- for (i = 0; i < N_DATA_MASKS; i++) {
- CBC_QRDataMask* p = (CBC_QRDataMask*)(*DATA_MASKS)[i];
- if (p) {
- delete p;
- }
- }
+ for (int32_t i = 0; i < N_DATA_MASKS; ++i)
+ delete (*DATA_MASKS)[i];
}
-void CBC_QRDataMask::UnmaskBitMatirx(CBC_CommonBitMatrix* bits,
+
+void CBC_QRDataMask::UnmaskBitMatrix(CBC_CommonBitMatrix* bits,
int32_t dimension) {
for (int32_t i = 0; i < dimension; i++) {
for (int32_t j = 0; j < dimension; j++) {
- if (IsMasked(i, j)) {
+ if (IsMasked(i, j))
bits->Flip(j, i);
- }
}
}
}
+
CBC_QRDataMask* CBC_QRDataMask::ForReference(int32_t reference, int32_t& e) {
if (reference < 0 || reference > 7) {
e = BCExceptionReferenceMustBeBetween0And7;
- BC_EXCEPTION_CHECK_ReturnValue(e, NULL);
+ BC_EXCEPTION_CHECK_ReturnValue(e, nullptr);
}
- return (CBC_QRDataMask*)(*DATA_MASKS)[reference];
+ return (*DATA_MASKS)[reference];
}
+
class DataMask000 : public CBC_QRDataMask {
public:
FX_BOOL IsMasked(int32_t x, int32_t y) { return ((x + y) % 2) == 0; }
diff --git a/xfa/fxbarcode/qrcode/BC_QRDataMask.h b/xfa/fxbarcode/qrcode/BC_QRDataMask.h
index 88aa1140ea..dc8cf498b3 100644
--- a/xfa/fxbarcode/qrcode/BC_QRDataMask.h
+++ b/xfa/fxbarcode/qrcode/BC_QRDataMask.h
@@ -13,16 +13,17 @@ class CBC_CommonBitMatrix;
class CBC_QRDataMask {
public:
- static CFX_PtrArray* DATA_MASKS;
CBC_QRDataMask();
virtual ~CBC_QRDataMask();
+
static void Initialize();
static void Finalize();
- virtual FX_BOOL IsMasked(int32_t i, int32_t j) = 0;
- void UnmaskBitMatirx(CBC_CommonBitMatrix* bits, int32_t dimension);
static CBC_QRDataMask* ForReference(int32_t reference, int32_t& e);
static int32_t BuildDataMasks();
static void Destroy();
+
+ virtual FX_BOOL IsMasked(int32_t i, int32_t j) = 0;
+ void UnmaskBitMatrix(CBC_CommonBitMatrix* bits, int32_t dimension);
};
#endif // XFA_FXBARCODE_QRCODE_BC_QRDATAMASK_H_