Reordered calls to applyMask()/drawFormatBits() for conceptual clarity, without changing output (because masks don't affect format bits), in all language versions.
This commit is contained in:
parent
22319bf90f
commit
fd083f70e8
|
@ -264,8 +264,8 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
|
||||||
long minPenalty = LONG_MAX;
|
long minPenalty = LONG_MAX;
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
enum qrcodegen_Mask msk = (enum qrcodegen_Mask)i;
|
enum qrcodegen_Mask msk = (enum qrcodegen_Mask)i;
|
||||||
drawFormatBits(ecl, msk, qrcode);
|
|
||||||
applyMask(tempBuffer, qrcode, msk);
|
applyMask(tempBuffer, qrcode, msk);
|
||||||
|
drawFormatBits(ecl, msk, qrcode);
|
||||||
long penalty = getPenaltyScore(qrcode);
|
long penalty = getPenaltyScore(qrcode);
|
||||||
if (penalty < minPenalty) {
|
if (penalty < minPenalty) {
|
||||||
mask = msk;
|
mask = msk;
|
||||||
|
@ -275,8 +275,8 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(0 <= (int)mask && (int)mask <= 7);
|
assert(0 <= (int)mask && (int)mask <= 7);
|
||||||
drawFormatBits(ecl, mask, qrcode);
|
|
||||||
applyMask(tempBuffer, qrcode, mask);
|
applyMask(tempBuffer, qrcode, mask);
|
||||||
|
drawFormatBits(ecl, mask, qrcode);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,8 +148,8 @@ QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask)
|
||||||
if (mask == -1) { // Automatically choose best mask
|
if (mask == -1) { // Automatically choose best mask
|
||||||
long minPenalty = LONG_MAX;
|
long minPenalty = LONG_MAX;
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
drawFormatBits(i);
|
|
||||||
applyMask(i);
|
applyMask(i);
|
||||||
|
drawFormatBits(i);
|
||||||
long penalty = getPenaltyScore();
|
long penalty = getPenaltyScore();
|
||||||
if (penalty < minPenalty) {
|
if (penalty < minPenalty) {
|
||||||
mask = i;
|
mask = i;
|
||||||
|
@ -161,8 +161,8 @@ QrCode::QrCode(int ver, Ecc ecl, const vector<uint8_t> &dataCodewords, int mask)
|
||||||
if (mask < 0 || mask > 7)
|
if (mask < 0 || mask > 7)
|
||||||
throw std::logic_error("Assertion error");
|
throw std::logic_error("Assertion error");
|
||||||
this->mask = mask;
|
this->mask = mask;
|
||||||
drawFormatBits(mask); // Overwrite old format bits
|
|
||||||
applyMask(mask); // Apply the final choice of mask
|
applyMask(mask); // Apply the final choice of mask
|
||||||
|
drawFormatBits(mask); // Overwrite old format bits
|
||||||
|
|
||||||
isFunction.clear();
|
isFunction.clear();
|
||||||
isFunction.shrink_to_fit();
|
isFunction.shrink_to_fit();
|
||||||
|
|
|
@ -573,8 +573,8 @@ public final class QrCode {
|
||||||
if (mask == -1) { // Automatically choose best mask
|
if (mask == -1) { // Automatically choose best mask
|
||||||
int minPenalty = Integer.MAX_VALUE;
|
int minPenalty = Integer.MAX_VALUE;
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
drawFormatBits(i);
|
|
||||||
applyMask(i);
|
applyMask(i);
|
||||||
|
drawFormatBits(i);
|
||||||
int penalty = getPenaltyScore();
|
int penalty = getPenaltyScore();
|
||||||
if (penalty < minPenalty) {
|
if (penalty < minPenalty) {
|
||||||
mask = i;
|
mask = i;
|
||||||
|
@ -584,8 +584,8 @@ public final class QrCode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert 0 <= mask && mask <= 7;
|
assert 0 <= mask && mask <= 7;
|
||||||
drawFormatBits(mask); // Overwrite old format bits
|
|
||||||
applyMask(mask); // Apply the final choice of mask
|
applyMask(mask); // Apply the final choice of mask
|
||||||
|
drawFormatBits(mask); // Overwrite old format bits
|
||||||
return mask; // The caller shall assign this value to the final-declared field
|
return mask; // The caller shall assign this value to the final-declared field
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,8 @@ var qrcodegen = new function() {
|
||||||
if (mask == -1) { // Automatically choose best mask
|
if (mask == -1) { // Automatically choose best mask
|
||||||
var minPenalty = Infinity;
|
var minPenalty = Infinity;
|
||||||
for (var i = 0; i < 8; i++) {
|
for (var i = 0; i < 8; i++) {
|
||||||
drawFormatBits(i);
|
|
||||||
applyMask(i);
|
applyMask(i);
|
||||||
|
drawFormatBits(i);
|
||||||
var penalty = getPenaltyScore();
|
var penalty = getPenaltyScore();
|
||||||
if (penalty < minPenalty) {
|
if (penalty < minPenalty) {
|
||||||
mask = i;
|
mask = i;
|
||||||
|
@ -125,8 +125,8 @@ var qrcodegen = new function() {
|
||||||
}
|
}
|
||||||
if (mask < 0 || mask > 7)
|
if (mask < 0 || mask > 7)
|
||||||
throw "Assertion error";
|
throw "Assertion error";
|
||||||
drawFormatBits(mask); // Overwrite old format bits
|
|
||||||
applyMask(mask); // Apply the final choice of mask
|
applyMask(mask); // Apply the final choice of mask
|
||||||
|
drawFormatBits(mask); // Overwrite old format bits
|
||||||
|
|
||||||
isFunction = null;
|
isFunction = null;
|
||||||
|
|
||||||
|
|
|
@ -209,16 +209,16 @@ class QrCode(object):
|
||||||
if mask == -1: # Automatically choose best mask
|
if mask == -1: # Automatically choose best mask
|
||||||
minpenalty = 1 << 32
|
minpenalty = 1 << 32
|
||||||
for i in range(8):
|
for i in range(8):
|
||||||
self._draw_format_bits(i)
|
|
||||||
self._apply_mask(i)
|
self._apply_mask(i)
|
||||||
|
self._draw_format_bits(i)
|
||||||
penalty = self._get_penalty_score()
|
penalty = self._get_penalty_score()
|
||||||
if penalty < minpenalty:
|
if penalty < minpenalty:
|
||||||
mask = i
|
mask = i
|
||||||
minpenalty = penalty
|
minpenalty = penalty
|
||||||
self._apply_mask(i) # Undoes the mask due to XOR
|
self._apply_mask(i) # Undoes the mask due to XOR
|
||||||
assert 0 <= mask <= 7
|
assert 0 <= mask <= 7
|
||||||
self._draw_format_bits(mask) # Overwrite old format bits
|
|
||||||
self._apply_mask(mask) # Apply the final choice of mask
|
self._apply_mask(mask) # Apply the final choice of mask
|
||||||
|
self._draw_format_bits(mask) # Overwrite old format bits
|
||||||
|
|
||||||
# The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
|
# The index of the mask pattern used in this QR Code, which is between 0 and 7 (inclusive).
|
||||||
# Even if a QR Code is created with automatic masking requested (mask = -1),
|
# Even if a QR Code is created with automatic masking requested (mask = -1),
|
||||||
|
|
|
@ -302,8 +302,8 @@ impl QrCode {
|
||||||
let mut minpenalty: i32 = std::i32::MAX;
|
let mut minpenalty: i32 = std::i32::MAX;
|
||||||
for i in 0u8 .. 8 {
|
for i in 0u8 .. 8 {
|
||||||
let newmask = Mask::new(i);
|
let newmask = Mask::new(i);
|
||||||
result.draw_format_bits(newmask);
|
|
||||||
result.apply_mask(newmask);
|
result.apply_mask(newmask);
|
||||||
|
result.draw_format_bits(newmask);
|
||||||
let penalty: i32 = result.get_penalty_score();
|
let penalty: i32 = result.get_penalty_score();
|
||||||
if penalty < minpenalty {
|
if penalty < minpenalty {
|
||||||
mask = Some(newmask);
|
mask = Some(newmask);
|
||||||
|
@ -314,8 +314,8 @@ impl QrCode {
|
||||||
}
|
}
|
||||||
let mask: Mask = mask.unwrap();
|
let mask: Mask = mask.unwrap();
|
||||||
result.mask = mask;
|
result.mask = mask;
|
||||||
result.draw_format_bits(mask); // Overwrite old format bits
|
|
||||||
result.apply_mask(mask); // Apply the final choice of mask
|
result.apply_mask(mask); // Apply the final choice of mask
|
||||||
|
result.draw_format_bits(mask); // Overwrite old format bits
|
||||||
|
|
||||||
result.isfunction.clear();
|
result.isfunction.clear();
|
||||||
result.isfunction.shrink_to_fit();
|
result.isfunction.shrink_to_fit();
|
||||||
|
|
|
@ -209,8 +209,8 @@ namespace qrcodegen {
|
||||||
if (mask == -1) { // Automatically choose best mask
|
if (mask == -1) { // Automatically choose best mask
|
||||||
let minPenalty: int = 1000000000;
|
let minPenalty: int = 1000000000;
|
||||||
for (let i = 0; i < 8; i++) {
|
for (let i = 0; i < 8; i++) {
|
||||||
this.drawFormatBits(i);
|
|
||||||
this.applyMask(i);
|
this.applyMask(i);
|
||||||
|
this.drawFormatBits(i);
|
||||||
const penalty: int = this.getPenaltyScore();
|
const penalty: int = this.getPenaltyScore();
|
||||||
if (penalty < minPenalty) {
|
if (penalty < minPenalty) {
|
||||||
mask = i;
|
mask = i;
|
||||||
|
@ -222,8 +222,8 @@ namespace qrcodegen {
|
||||||
if (mask < 0 || mask > 7)
|
if (mask < 0 || mask > 7)
|
||||||
throw "Assertion error";
|
throw "Assertion error";
|
||||||
this.mask = mask;
|
this.mask = mask;
|
||||||
this.drawFormatBits(mask); // Overwrite old format bits
|
|
||||||
this.applyMask(mask); // Apply the final choice of mask
|
this.applyMask(mask); // Apply the final choice of mask
|
||||||
|
this.drawFormatBits(mask); // Overwrite old format bits
|
||||||
|
|
||||||
this.isFunction = [];
|
this.isFunction = [];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue