From fd083f70e8b9de21e137d44801ee0d9d2d3b7e83 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sun, 4 Nov 2018 19:26:33 +0000 Subject: [PATCH] Reordered calls to applyMask()/drawFormatBits() for conceptual clarity, without changing output (because masks don't affect format bits), in all language versions. --- c/qrcodegen.c | 4 ++-- cpp/QrCode.cpp | 4 ++-- java/src/main/java/io/nayuki/qrcodegen/QrCode.java | 4 ++-- javascript/qrcodegen.js | 4 ++-- python/qrcodegen.py | 4 ++-- rust/src/lib.rs | 4 ++-- typescript/qrcodegen.ts | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 18408eb..67c1917 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -264,8 +264,8 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz long minPenalty = LONG_MAX; for (int i = 0; i < 8; i++) { enum qrcodegen_Mask msk = (enum qrcodegen_Mask)i; - drawFormatBits(ecl, msk, qrcode); applyMask(tempBuffer, qrcode, msk); + drawFormatBits(ecl, msk, qrcode); long penalty = getPenaltyScore(qrcode); if (penalty < minPenalty) { mask = msk; @@ -275,8 +275,8 @@ bool qrcodegen_encodeSegmentsAdvanced(const struct qrcodegen_Segment segs[], siz } } assert(0 <= (int)mask && (int)mask <= 7); - drawFormatBits(ecl, mask, qrcode); applyMask(tempBuffer, qrcode, mask); + drawFormatBits(ecl, mask, qrcode); return true; } diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 1b82517..5232ac6 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -148,8 +148,8 @@ QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int mask) if (mask == -1) { // Automatically choose best mask long minPenalty = LONG_MAX; for (int i = 0; i < 8; i++) { - drawFormatBits(i); applyMask(i); + drawFormatBits(i); long penalty = getPenaltyScore(); if (penalty < minPenalty) { mask = i; @@ -161,8 +161,8 @@ QrCode::QrCode(int ver, Ecc ecl, const vector &dataCodewords, int mask) 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 + drawFormatBits(mask); // Overwrite old format bits isFunction.clear(); isFunction.shrink_to_fit(); diff --git a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java index ce28b10..68f7cc4 100644 --- a/java/src/main/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/src/main/java/io/nayuki/qrcodegen/QrCode.java @@ -573,8 +573,8 @@ public final class QrCode { if (mask == -1) { // Automatically choose best mask int minPenalty = Integer.MAX_VALUE; for (int i = 0; i < 8; i++) { - drawFormatBits(i); applyMask(i); + drawFormatBits(i); int penalty = getPenaltyScore(); if (penalty < minPenalty) { mask = i; @@ -584,8 +584,8 @@ public final class QrCode { } } assert 0 <= mask && mask <= 7; - drawFormatBits(mask); // Overwrite old format bits 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 } diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index 3fa1a20..d03ea89 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -113,8 +113,8 @@ var qrcodegen = new function() { if (mask == -1) { // Automatically choose best mask var minPenalty = Infinity; for (var i = 0; i < 8; i++) { - drawFormatBits(i); applyMask(i); + drawFormatBits(i); var penalty = getPenaltyScore(); if (penalty < minPenalty) { mask = i; @@ -125,8 +125,8 @@ var qrcodegen = new function() { } if (mask < 0 || mask > 7) throw "Assertion error"; - drawFormatBits(mask); // Overwrite old format bits applyMask(mask); // Apply the final choice of mask + drawFormatBits(mask); // Overwrite old format bits isFunction = null; diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 8d82837..e27615b 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -209,16 +209,16 @@ class QrCode(object): if mask == -1: # Automatically choose best mask minpenalty = 1 << 32 for i in range(8): - self._draw_format_bits(i) self._apply_mask(i) + self._draw_format_bits(i) penalty = self._get_penalty_score() if penalty < minpenalty: mask = i minpenalty = penalty self._apply_mask(i) # Undoes the mask due to XOR assert 0 <= mask <= 7 - self._draw_format_bits(mask) # Overwrite old format bits 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). # Even if a QR Code is created with automatic masking requested (mask = -1), diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 0e177ee..4fedaba 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -302,8 +302,8 @@ impl QrCode { let mut minpenalty: i32 = std::i32::MAX; for i in 0u8 .. 8 { let newmask = Mask::new(i); - result.draw_format_bits(newmask); result.apply_mask(newmask); + result.draw_format_bits(newmask); let penalty: i32 = result.get_penalty_score(); if penalty < minpenalty { mask = Some(newmask); @@ -314,8 +314,8 @@ impl QrCode { } let mask: Mask = mask.unwrap(); result.mask = mask; - result.draw_format_bits(mask); // Overwrite old format bits result.apply_mask(mask); // Apply the final choice of mask + result.draw_format_bits(mask); // Overwrite old format bits result.isfunction.clear(); result.isfunction.shrink_to_fit(); diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index d0d7d61..2d6677e 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -209,8 +209,8 @@ namespace qrcodegen { if (mask == -1) { // Automatically choose best mask let minPenalty: int = 1000000000; for (let i = 0; i < 8; i++) { - this.drawFormatBits(i); this.applyMask(i); + this.drawFormatBits(i); const penalty: int = this.getPenaltyScore(); if (penalty < minPenalty) { mask = i; @@ -222,8 +222,8 @@ namespace qrcodegen { if (mask < 0 || mask > 7) throw "Assertion error"; this.mask = mask; - this.drawFormatBits(mask); // Overwrite old format bits this.applyMask(mask); // Apply the final choice of mask + this.drawFormatBits(mask); // Overwrite old format bits this.isFunction = []; }