diff options
author | Lei Zhang <thestig@chromium.org> | 2017-04-06 14:23:26 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-06 23:30:04 +0000 |
commit | 8a24b25ee0b08128b28dfae0ee86b8348a51b40b (patch) | |
tree | a1dcaba3bddca1316bb9ba8fb9e2c0e0b1242301 /fxbarcode/qrcode/BC_QRCoderEncoder.cpp | |
parent | c758d9dd3f94c2dee89e7fdd50195af08f7e456c (diff) | |
download | pdfium-8a24b25ee0b08128b28dfae0ee86b8348a51b40b.tar.xz |
Clean up CBC_QRCoderVersion and friends.
Change-Id: Iff738c99fb4fe38d35515c280057b489624d734f
Reviewed-on: https://pdfium-review.googlesource.com/3752
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'fxbarcode/qrcode/BC_QRCoderEncoder.cpp')
-rw-r--r-- | fxbarcode/qrcode/BC_QRCoderEncoder.cpp | 27 |
1 files changed, 12 insertions, 15 deletions
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"; |