summaryrefslogtreecommitdiff
path: root/fxbarcode/qrcode
diff options
context:
space:
mode:
Diffstat (limited to 'fxbarcode/qrcode')
-rw-r--r--fxbarcode/qrcode/BC_QRCoderEncoder.cpp22
-rw-r--r--fxbarcode/qrcode/BC_QRCoderVersion.cpp91
-rw-r--r--fxbarcode/qrcode/BC_QRCoderVersion.h13
3 files changed, 27 insertions, 99 deletions
diff --git a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
index d74063d3fe..0971caab51 100644
--- a/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderEncoder.cpp
@@ -171,8 +171,8 @@ bool AppendLengthInfo(int32_t numLetters,
CBC_QRCoderMode* mode,
CBC_QRCoderBitVector* bits) {
int32_t e = BCExceptionNO;
- CBC_QRCoderVersion* qcv = CBC_QRCoderVersion::GetVersionForNumber(version, e);
- if (e != BCExceptionNO)
+ CBC_QRCoderVersion* qcv = CBC_QRCoderVersion::GetVersionForNumber(version);
+ if (!qcv)
return false;
int32_t numBits = mode->GetCharacterCountBits(qcv, e);
if (e != BCExceptionNO)
@@ -214,8 +214,8 @@ void InitQRCode(int32_t numInputBytes,
qrCode->SetMode(mode);
for (int32_t versionNum = 1; versionNum <= kMaxVersion; versionNum++) {
CBC_QRCoderVersion* version =
- CBC_QRCoderVersion::GetVersionForNumber(versionNum, e);
- if (e != BCExceptionNO)
+ CBC_QRCoderVersion::GetVersionForNumber(versionNum);
+ if (!version)
return;
int32_t numBytes = version->GetTotalCodeWords();
CBC_QRCoderECBlocks* ecBlocks = version->GetECBlocksForLevel(ecLevel);
@@ -237,16 +237,14 @@ void InitQRCode(int32_t numInputBytes,
std::unique_ptr<CBC_CommonByteArray> GenerateECBytes(
CBC_CommonByteArray* dataBytes,
- int32_t numEcBytesInBlock,
- int32_t& e) {
+ int32_t numEcBytesInBlock) {
int32_t numDataBytes = dataBytes->Size();
std::vector<int32_t> toEncode(numDataBytes + numEcBytesInBlock);
for (int32_t i = 0; i < numDataBytes; ++i)
toEncode[i] = dataBytes->At(i);
CBC_ReedSolomonEncoder encode(CBC_ReedSolomonGF256::QRCodeField);
encode.Init();
- encode.Encode(&toEncode, numEcBytesInBlock, e);
- if (e != BCExceptionNO)
+ if (!encode.Encode(&toEncode, numEcBytesInBlock))
return nullptr;
auto ecBytes = pdfium::MakeUnique<CBC_CommonByteArray>(numEcBytesInBlock);
for (int32_t i = 0; i < numEcBytesInBlock; ++i)
@@ -543,10 +541,12 @@ void InterleaveWithECBytes(CBC_QRCoderBitVector* bits,
numEcBytesInBlosk);
auto dataBytes = pdfium::MakeUnique<CBC_CommonByteArray>();
dataBytes->Set(bits->GetArray(), dataBytesOffset, numDataBytesInBlock);
- std::unique_ptr<CBC_CommonByteArray> ecBytes(
- GenerateECBytes(dataBytes.get(), numEcBytesInBlosk, e));
- if (e != BCExceptionNO)
+ std::unique_ptr<CBC_CommonByteArray> ecBytes =
+ GenerateECBytes(dataBytes.get(), numEcBytesInBlosk);
+ if (!ecBytes) {
+ e = BCExceptionGeneric;
return;
+ }
maxNumDataBytes = std::max(maxNumDataBytes, dataBytes->Size());
maxNumEcBytes = std::max(maxNumEcBytes, ecBytes->Size());
blocks[i].SetData(std::move(dataBytes), std::move(ecBytes));
diff --git a/fxbarcode/qrcode/BC_QRCoderVersion.cpp b/fxbarcode/qrcode/BC_QRCoderVersion.cpp
index f0b708dfc3..67ca42804c 100644
--- a/fxbarcode/qrcode/BC_QRCoderVersion.cpp
+++ b/fxbarcode/qrcode/BC_QRCoderVersion.cpp
@@ -28,25 +28,6 @@
#include "fxbarcode/qrcode/BC_QRCoderVersion.h"
#include "fxbarcode/utils.h"
-namespace {
-
-const uint8_t BITS_SET_IN_HALF_BYTE[] = {0, 1, 1, 2, 1, 2, 2, 3,
- 1, 2, 2, 3, 2, 3, 3, 4};
-
-int32_t NumBitsDiffering(int32_t a, int32_t b) {
- a ^= b;
- return BITS_SET_IN_HALF_BYTE[a & 0x0F] +
- BITS_SET_IN_HALF_BYTE[(a >> 4) & 0x0F] +
- BITS_SET_IN_HALF_BYTE[(a >> 8) & 0x0F] +
- BITS_SET_IN_HALF_BYTE[(a >> 12) & 0x0F] +
- BITS_SET_IN_HALF_BYTE[(a >> 16) & 0x0F] +
- BITS_SET_IN_HALF_BYTE[(a >> 20) & 0x0F] +
- BITS_SET_IN_HALF_BYTE[(a >> 24) & 0x0F] +
- BITS_SET_IN_HALF_BYTE[(a >> 28) & 0x0F];
-}
-
-} // namespace
-
const int32_t CBC_QRCoderVersion::VERSION_DECODE_INFO[] = {
0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6, 0x0C762, 0x0D847,
0x0E60D, 0x0F928, 0x10B78, 0x1145D, 0x12A17, 0x13532, 0x149A6,
@@ -367,57 +348,16 @@ CBC_QRCoderECBlocks* CBC_QRCoderVersion::GetECBlocksForLevel(
CBC_QRCoderErrorCorrectionLevel* ecLevel) {
return m_ecBlocksArray[ecLevel->Ordinal()];
}
-CBC_QRCoderVersion* CBC_QRCoderVersion::GetProvisionalVersionForDimension(
- int32_t dimension,
- int32_t& e) {
- if ((dimension % 4) != 1) {
- e = BCExceptionRead;
- return nullptr;
- }
- CBC_QRCoderVersion* qcv = GetVersionForNumber((dimension - 17) >> 2, e);
- if (e != BCExceptionNO)
- return nullptr;
- return qcv;
-}
-CBC_QRCoderVersion* CBC_QRCoderVersion::DecodeVersionInformation(
- int32_t versionBits,
- int32_t& e) {
- int32_t bestDifference = INT_MAX;
- int32_t bestVersion = 0;
- for (int32_t i = 0; i < 34; i++) {
- int32_t targetVersion = VERSION_DECODE_INFO[i];
- if (targetVersion == versionBits) {
- CBC_QRCoderVersion* qcv = GetVersionForNumber(i + 7, e);
- if (e != BCExceptionNO)
- return nullptr;
- return qcv;
- }
- int32_t bitsDifference = NumBitsDiffering(versionBits, targetVersion);
- if (bitsDifference < bestDifference) {
- bestVersion = i + 7;
- bestDifference = bitsDifference;
- }
- }
- if (bestDifference <= 3) {
- CBC_QRCoderVersion* qcv = GetVersionForNumber(bestVersion, e);
- if (e != BCExceptionNO)
- return nullptr;
- return qcv;
- }
- return nullptr;
-}
+
CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) {
int32_t dimension = GetDimensionForVersion();
CBC_CommonBitMatrix* bitMatrix = new CBC_CommonBitMatrix();
bitMatrix->Init(dimension);
- bitMatrix->SetRegion(0, 0, 9, 9, e);
- if (e != BCExceptionNO)
+ if (!bitMatrix->SetRegion(0, 0, 9, 9))
return nullptr;
- bitMatrix->SetRegion(dimension - 8, 0, 8, 9, e);
- if (e != BCExceptionNO)
+ if (!bitMatrix->SetRegion(dimension - 8, 0, 8, 9))
return nullptr;
- bitMatrix->SetRegion(0, dimension - 8, 9, 8, e);
- if (e != BCExceptionNO)
+ if (!bitMatrix->SetRegion(0, dimension - 8, 9, 8))
return nullptr;
size_t max = m_alignmentPatternCenters.size();
for (size_t x = 0; x < max; x++) {
@@ -426,30 +366,25 @@ CBC_CommonBitMatrix* CBC_QRCoderVersion::BuildFunctionPattern(int32_t& e) {
if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0)) {
continue;
}
- bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5, e);
- if (e != BCExceptionNO)
+ if (!bitMatrix->SetRegion(m_alignmentPatternCenters[y] - 2, i, 5, 5))
return nullptr;
}
}
- bitMatrix->SetRegion(6, 9, 1, dimension - 17, e);
- if (e != BCExceptionNO)
+ if (!bitMatrix->SetRegion(6, 9, 1, dimension - 17))
return nullptr;
- bitMatrix->SetRegion(9, 6, dimension - 17, 1, e);
- if (e != BCExceptionNO)
+ if (!bitMatrix->SetRegion(9, 6, dimension - 17, 1))
return nullptr;
if (m_versionNumber > 6) {
- bitMatrix->SetRegion(dimension - 11, 0, 3, 6, e);
- if (e != BCExceptionNO)
+ if (!bitMatrix->SetRegion(dimension - 11, 0, 3, 6))
return nullptr;
- bitMatrix->SetRegion(0, dimension - 11, 6, 3, e);
- if (e != BCExceptionNO)
+ if (!bitMatrix->SetRegion(0, dimension - 11, 6, 3))
return nullptr;
}
return bitMatrix;
}
+
CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(
- int32_t versionNumber,
- int32_t& e) {
+ int32_t versionNumber) {
if (VERSION->empty()) {
VERSION->push_back(new CBC_QRCoderVersion(
1, new CBC_QRCoderECBlocks(7, new CBC_QRCoderECB(1, 19)),
@@ -780,10 +715,8 @@ CBC_QRCoderVersion* CBC_QRCoderVersion::GetVersionForNumber(
new CBC_QRCoderECBlocks(30, new CBC_QRCoderECB(20, 15),
new CBC_QRCoderECB(61, 16))));
}
- if (versionNumber < 1 || versionNumber > 40) {
- e = BCExceptionIllegalArgument;
+ if (versionNumber < 1 || versionNumber > 40)
return nullptr;
- }
return (*VERSION)[versionNumber - 1];
}
diff --git a/fxbarcode/qrcode/BC_QRCoderVersion.h b/fxbarcode/qrcode/BC_QRCoderVersion.h
index 78ded0d30c..b6dad2299d 100644
--- a/fxbarcode/qrcode/BC_QRCoderVersion.h
+++ b/fxbarcode/qrcode/BC_QRCoderVersion.h
@@ -17,10 +17,13 @@ class CBC_QRCoderErrorCorrectionLevel;
class CBC_QRCoderVersion {
public:
- virtual ~CBC_QRCoderVersion();
+ ~CBC_QRCoderVersion();
static void Initialize();
static void Finalize();
+ static CBC_QRCoderVersion* GetVersionForNumber(int32_t versionNumber);
+ static void Destroy();
+
int32_t GetVersionNumber();
int32_t GetTotalCodeWords();
int32_t GetDimensionForVersion();
@@ -28,14 +31,6 @@ class CBC_QRCoderVersion {
std::vector<int32_t>* GetAlignmentPatternCenters();
CBC_QRCoderECBlocks* GetECBlocksForLevel(
CBC_QRCoderErrorCorrectionLevel* ecLevel);
- static CBC_QRCoderVersion* GetVersionForNumber(int32_t versionNumber,
- int32_t& e);
- static CBC_QRCoderVersion* GetProvisionalVersionForDimension(
- int32_t dimension,
- int32_t& e);
- static CBC_QRCoderVersion* DecodeVersionInformation(int32_t versionBits,
- int32_t& e);
- static void Destroy();
private:
CBC_QRCoderVersion();