correction in penalty calculation

pull/134/head
meirumeiru 3 years ago
parent 5990e6a99c
commit 64f04fa6cc

@ -340,7 +340,6 @@ QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int msk)
long minPenalty = LONG_MAX;
for (int i = 0; i < 8; i++) {
applyMask(i);
drawFormatBits(i);
long penalty = getPenaltyScore();
if (penalty < minPenalty) {
msk = i;
@ -408,10 +407,27 @@ void QrCode::drawFunctionPatterns() {
}
// Draw configuration data
drawFormatBits(0); // Dummy mask value; overwritten later in the constructor
markFormatBits();
drawVersion();
}
void QrCode::markFormatBits() {
// Mask first copy
for (int i = 0; i <= 5; i++)
setFunctionModule(8, i, false);
setFunctionModule(8, 7, false);
setFunctionModule(8, 8, false);
setFunctionModule(7, 8, false);
for (int i = 9; i < 15; i++)
setFunctionModule(14 - i, 8, false);
// Mask second copy
for (int i = 0; i < 8; i++)
setFunctionModule(size - 1 - i, 8, false);
for (int i = 8; i < 15; i++)
setFunctionModule(8, size - 15 + i, false);
setFunctionModule(8, size - 8, false); // Always dark
}
void QrCode::drawFormatBits(int msk) {
// Calculate error correction code and pack bits
@ -754,7 +770,7 @@ int QrCode::finderPenaltyCountPatterns(const std::array<int,7> &runHistory) cons
assert(n <= size * 3);
bool core = n > 0 && runHistory.at(2) == n && runHistory.at(3) == n * 3 && runHistory.at(4) == n && runHistory.at(5) == n;
return (core && runHistory.at(0) >= n * 4 && runHistory.at(6) >= n ? 1 : 0)
+ (core && runHistory.at(6) >= n * 4 && runHistory.at(0) >= n ? 1 : 0);
| (core && runHistory.at(6) >= n * 4 && runHistory.at(0) >= n ? 1 : 0);
}

@ -376,6 +376,11 @@ class QrCode final {
private: void drawFunctionPatterns();
// Marks two copies of the format bits.
// Basically this function does the same as drawFormatBits without drawing the bits.
private: void markFormatBits();
// Draws two copies of the format bits (with its own error correction code)
// based on the given mask and this object's error correction level field.
private: void drawFormatBits(int msk);

Loading…
Cancel
Save