Tweaked C++ code to inline handleConstructorMasking() because the mask field is private instead of public const.

pull/47/head
Project Nayuki 6 years ago
parent 76de28378e
commit 2359d68243

@ -139,11 +139,31 @@ QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask)
modules = vector<vector<bool> >(size, vector<bool>(size)); // Initially all white
isFunction = vector<vector<bool> >(size, vector<bool>(size));
// Compute ECC, draw modules, do masking
// Compute ECC, draw modules
drawFunctionPatterns();
const vector<uint8_t> allCodewords = addEccAndInterleave(dataCodewords);
drawCodewords(allCodewords);
this->mask = handleConstructorMasking(mask);
// Do masking
if (mask == -1) { // Automatically choose best mask
long minPenalty = LONG_MAX;
for (int i = 0; i < 8; i++) {
drawFormatBits(i);
applyMask(i);
long penalty = getPenaltyScore();
if (penalty < minPenalty) {
mask = i;
minPenalty = penalty;
}
applyMask(i); // Undoes the mask due to XOR
}
}
if (mask < 0 || mask > 7)
throw std::logic_error("Assertion error");
this->mask = mask;
drawFormatBits(mask); // Overwrite old format bits
applyMask(mask); // Apply the final choice of mask
isFunction.clear();
isFunction.shrink_to_fit();
}
@ -403,28 +423,6 @@ void QrCode::applyMask(int mask) {
}
int QrCode::handleConstructorMasking(int mask) {
if (mask == -1) { // Automatically choose best mask
long minPenalty = LONG_MAX;
for (int i = 0; i < 8; i++) {
drawFormatBits(i);
applyMask(i);
long penalty = getPenaltyScore();
if (penalty < minPenalty) {
mask = i;
minPenalty = penalty;
}
applyMask(i); // Undoes the mask due to XOR
}
}
if (mask < 0 || mask > 7)
throw std::logic_error("Assertion error");
drawFormatBits(mask); // Overwrite old format bits
applyMask(mask); // Apply the final choice of mask
return mask; // The caller shall assign this value to the final-declared field
}
long QrCode::getPenaltyScore() const {
long result = 0;

@ -247,12 +247,6 @@ class QrCode final {
private: void applyMask(int mask);
// A messy helper function for the constructors. This QR Code must be in an unmasked state when this
// method is called. The given argument is the requested mask, which is -1 for auto or 0 to 7 for fixed.
// This method applies and returns the actual mask chosen, from 0 to 7.
private: int handleConstructorMasking(int mask);
// Calculates and returns the penalty score based on state of this QR Code's current modules.
// This is used by the automatic mask choice algorithm to find the mask pattern that yields the lowest score.
private: long getPenaltyScore() const;

Loading…
Cancel
Save