diff --git a/c/qrcodegen.c b/c/qrcodegen.c index 62fd04b..0aa39c9 100644 --- a/c/qrcodegen.c +++ b/c/qrcodegen.c @@ -633,8 +633,9 @@ static long getPenaltyScore(const uint8_t qrcode[]) { // Adjacent modules in row having same color for (int y = 0; y < qrsize; y++) { bool color = false; - for (int x = 0, runX = -1; x < qrsize; x++) { - if (x == 0 || getModule(qrcode, x, y) != color) { + int runX = 0; + for (int x = 0; x < qrsize; x++) { + if (getModule(qrcode, x, y) != color) { color = getModule(qrcode, x, y); runX = 1; } else { @@ -649,8 +650,9 @@ static long getPenaltyScore(const uint8_t qrcode[]) { // Adjacent modules in column having same color for (int x = 0; x < qrsize; x++) { bool color = false; - for (int y = 0, runY = -1; y < qrsize; y++) { - if (y == 0 || getModule(qrcode, x, y) != color) { + int runY = 0; + for (int y = 0; y < qrsize; y++) { + if (getModule(qrcode, x, y) != color) { color = getModule(qrcode, x, y); runY = 1; } else { diff --git a/cpp/QrCode.cpp b/cpp/QrCode.cpp index 0d51cb6..7e71887 100644 --- a/cpp/QrCode.cpp +++ b/cpp/QrCode.cpp @@ -431,8 +431,9 @@ long QrCode::getPenaltyScore() const { // Adjacent modules in row having same color for (int y = 0; y < size; y++) { bool color = false; - for (int x = 0, runX = -1; x < size; x++) { - if (x == 0 || module(x, y) != color) { + int runX = 0; + for (int x = 0; x < size; x++) { + if (module(x, y) != color) { color = module(x, y); runX = 1; } else { @@ -447,8 +448,9 @@ long QrCode::getPenaltyScore() const { // Adjacent modules in column having same color for (int x = 0; x < size; x++) { bool color = false; - for (int y = 0, runY = -1; y < size; y++) { - if (y == 0 || module(x, y) != color) { + int runY = 0; + for (int y = 0; y < size; y++) { + if (module(x, y) != color) { color = module(x, y); runY = 1; } else { diff --git a/java/io/nayuki/qrcodegen/QrCode.java b/java/io/nayuki/qrcodegen/QrCode.java index fd73760..2e327b6 100644 --- a/java/io/nayuki/qrcodegen/QrCode.java +++ b/java/io/nayuki/qrcodegen/QrCode.java @@ -598,8 +598,9 @@ public final class QrCode { // Adjacent modules in row having same color for (int y = 0; y < size; y++) { boolean color = false; - for (int x = 0, runX = 0; x < size; x++) { - if (x == 0 || modules[y][x] != color) { + int runX = 0; + for (int x = 0; x < size; x++) { + if (modules[y][x] != color) { color = modules[y][x]; runX = 1; } else { @@ -614,8 +615,9 @@ public final class QrCode { // Adjacent modules in column having same color for (int x = 0; x < size; x++) { boolean color = false; - for (int y = 0, runY = 0; y < size; y++) { - if (y == 0 || modules[y][x] != color) { + int runY = 0; + for (int y = 0; y < size; y++) { + if (modules[y][x] != color) { color = modules[y][x]; runY = 1; } else { diff --git a/javascript/qrcodegen.js b/javascript/qrcodegen.js index fda02bd..18ae79e 100644 --- a/javascript/qrcodegen.js +++ b/javascript/qrcodegen.js @@ -429,8 +429,10 @@ var qrcodegen = new function() { // Adjacent modules in row having same color for (var y = 0; y < size; y++) { - for (var x = 0, runX, color; x < size; x++) { - if (x == 0 || modules[y][x] != color) { + var color = false; + var runX = 0; + for (var x = 0; x < size; x++) { + if (modules[y][x] != color) { color = modules[y][x]; runX = 1; } else { @@ -444,8 +446,10 @@ var qrcodegen = new function() { } // Adjacent modules in column having same color for (var x = 0; x < size; x++) { - for (var y = 0, runY, color; y < size; y++) { - if (y == 0 || modules[y][x] != color) { + var color = false; + var runY = 0; + for (var y = 0; y < size; y++) { + if (modules[y][x] != color) { color = modules[y][x]; runY = 1; } else { diff --git a/python/qrcodegen.py b/python/qrcodegen.py index 9a1bcb4..1459644 100644 --- a/python/qrcodegen.py +++ b/python/qrcodegen.py @@ -464,8 +464,10 @@ class QrCode(object): # Adjacent modules in row having same color for y in range(size): + color = False + runx = 0 for x in range(size): - if x == 0 or modules[y][x] != color: + if modules[y][x] != color: color = modules[y][x] runx = 1 else: @@ -476,8 +478,10 @@ class QrCode(object): result += 1 # Adjacent modules in column having same color for x in range(size): + color = False + runy = 0 for y in range(size): - if y == 0 or modules[y][x] != color: + if modules[y][x] != color: color = modules[y][x] runy = 1 else: diff --git a/rust/src/lib.rs b/rust/src/lib.rs index e556b50..9a2c2ae 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -650,7 +650,7 @@ impl QrCode { let mut color = false; let mut runx: i32 = 0; for x in 0 .. size { - if x == 0 || self.module(x, y) != color { + if self.module(x, y) != color { color = self.module(x, y); runx = 1; } else { @@ -668,7 +668,7 @@ impl QrCode { let mut color = false; let mut runy: i32 = 0; for y in 0 .. size { - if y == 0 || self.module(x, y) != color { + if self.module(x, y) != color { color = self.module(x, y); runy = 1; } else { diff --git a/typescript/qrcodegen.ts b/typescript/qrcodegen.ts index 199e151..45d5c1b 100644 --- a/typescript/qrcodegen.ts +++ b/typescript/qrcodegen.ts @@ -512,8 +512,10 @@ namespace qrcodegen { // Adjacent modules in row having same color for (let y = 0; y < this.size; y++) { - for (let x = 0, runX = 0, color = false; x < this.size; x++) { - if (x == 0 || this.modules[y][x] != color) { + let color = false; + let runX = 0; + for (let x = 0; x < this.size; x++) { + if (this.modules[y][x] != color) { color = this.modules[y][x]; runX = 1; } else { @@ -527,8 +529,10 @@ namespace qrcodegen { } // Adjacent modules in column having same color for (let x = 0; x < this.size; x++) { - for (let y = 0, runY = 0, color = false; y < this.size; y++) { - if (y == 0 || this.modules[y][x] != color) { + let color = false; + let runY = 0; + for (let y = 0; y < this.size; y++) { + if (this.modules[y][x] != color) { color = this.modules[y][x]; runY = 1; } else {