Simplified a small bit of variables and logic of QrCode.getPenaltyScore() in all language versions, but in a subtly different way per language.

This commit is contained in:
Project Nayuki 2017-05-08 07:30:53 +00:00
parent e28c1d718e
commit 0482a1ec5b
5 changed files with 26 additions and 32 deletions

View File

@ -716,9 +716,9 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
// Adjacent modules in row having same color // Adjacent modules in row having same color
for (int y = 0; y < qrsize; y++) { for (int y = 0; y < qrsize; y++) {
bool colorX = getModule(qrcode, 0, y); bool colorX;
for (int x = 1, runX = 1; x < qrsize; x++) { for (int x = 0, runX; x < qrsize; x++) {
if (getModule(qrcode, x, y) != colorX) { if (x == 0 || getModule(qrcode, x, y) != colorX) {
colorX = getModule(qrcode, x, y); colorX = getModule(qrcode, x, y);
runX = 1; runX = 1;
} else { } else {
@ -732,9 +732,9 @@ static long getPenaltyScore(const uint8_t qrcode[]) {
} }
// Adjacent modules in column having same color // Adjacent modules in column having same color
for (int x = 0; x < qrsize; x++) { for (int x = 0; x < qrsize; x++) {
bool colorY = getModule(qrcode, x, 0); bool colorY;
for (int y = 1, runY = 1; y < qrsize; y++) { for (int y = 0, runY; y < qrsize; y++) {
if (getModule(qrcode, x, y) != colorY) { if (y == 0 || getModule(qrcode, x, y) != colorY) {
colorY = getModule(qrcode, x, y); colorY = getModule(qrcode, x, y);
runY = 1; runY = 1;
} else { } else {

View File

@ -422,9 +422,9 @@ long QrCode::getPenaltyScore() const {
// Adjacent modules in row having same color // Adjacent modules in row having same color
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
bool colorX = modules.at(y).at(0); bool colorX;
for (int x = 1, runX = 1; x < size; x++) { for (int x = 0, runX; x < size; x++) {
if (modules.at(y).at(x) != colorX) { if (x == 0 || modules.at(y).at(x) != colorX) {
colorX = modules.at(y).at(x); colorX = modules.at(y).at(x);
runX = 1; runX = 1;
} else { } else {
@ -438,9 +438,9 @@ long QrCode::getPenaltyScore() const {
} }
// Adjacent modules in column having same color // Adjacent modules in column having same color
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
bool colorY = modules.at(0).at(x); bool colorY;
for (int y = 1, runY = 1; y < size; y++) { for (int y = 0, runY; y < size; y++) {
if (modules.at(y).at(x) != colorY) { if (y == 0 || modules.at(y).at(x) != colorY) {
colorY = modules.at(y).at(x); colorY = modules.at(y).at(x);
runY = 1; runY = 1;
} else { } else {

View File

@ -579,9 +579,9 @@ public final class QrCode {
// Adjacent modules in row having same color // Adjacent modules in row having same color
for (int y = 0; y < size; y++) { for (int y = 0; y < size; y++) {
boolean colorX = modules[y][0]; boolean colorX = false;
for (int x = 1, runX = 1; x < size; x++) { for (int x = 0, runX = 0; x < size; x++) {
if (modules[y][x] != colorX) { if (x == 0 || modules[y][x] != colorX) {
colorX = modules[y][x]; colorX = modules[y][x];
runX = 1; runX = 1;
} else { } else {
@ -595,9 +595,9 @@ public final class QrCode {
} }
// Adjacent modules in column having same color // Adjacent modules in column having same color
for (int x = 0; x < size; x++) { for (int x = 0; x < size; x++) {
boolean colorY = modules[0][x]; boolean colorY = false;
for (int y = 1, runY = 1; y < size; y++) { for (int y = 0, runY = 0; y < size; y++) {
if (modules[y][x] != colorY) { if (y == 0 || modules[y][x] != colorY) {
colorY = modules[y][x]; colorY = modules[y][x];
runY = 1; runY = 1;
} else { } else {

View File

@ -455,9 +455,8 @@ var qrcodegen = new function() {
// Adjacent modules in row having same color // Adjacent modules in row having same color
for (var y = 0; y < size; y++) { for (var y = 0; y < size; y++) {
var colorX = modules[y][0]; for (var x = 0, runX, colorX; x < size; x++) {
for (var x = 1, runX = 1; x < size; x++) { if (x == 0 || modules[y][x] != colorX) {
if (modules[y][x] != colorX) {
colorX = modules[y][x]; colorX = modules[y][x];
runX = 1; runX = 1;
} else { } else {
@ -471,9 +470,8 @@ var qrcodegen = new function() {
} }
// Adjacent modules in column having same color // Adjacent modules in column having same color
for (var x = 0; x < size; x++) { for (var x = 0; x < size; x++) {
var colorY = modules[0][x]; for (var y = 0, runY, colorY; y < size; y++) {
for (var y = 1, runY = 1; y < size; y++) { if (y == 0 || modules[y][x] != colorY) {
if (modules[y][x] != colorY) {
colorY = modules[y][x]; colorY = modules[y][x];
runY = 1; runY = 1;
} else { } else {

View File

@ -436,10 +436,8 @@ class QrCode(object):
# Adjacent modules in row having same color # Adjacent modules in row having same color
for y in range(size): for y in range(size):
colorx = modules[y][0] for x in range(size):
runx = 1 if x == 0 or modules[y][x] != colorx:
for x in range(1, size):
if modules[y][x] != colorx:
colorx = modules[y][x] colorx = modules[y][x]
runx = 1 runx = 1
else: else:
@ -450,10 +448,8 @@ class QrCode(object):
result += 1 result += 1
# Adjacent modules in column having same color # Adjacent modules in column having same color
for x in range(size): for x in range(size):
colory = modules[0][x] for y in range(size):
runy = 1 if y == 0 or modules[y][x] != colory:
for y in range(1, size):
if modules[y][x] != colory:
colory = modules[y][x] colory = modules[y][x]
runy = 1 runy = 1
else: else: