Tweaked QrCode.getPenaltyScore() to use binary literals for clarity, for Java (SE 7+) and TypeScript (ES6+).

This commit is contained in:
Project Nayuki 2018-08-31 19:50:40 +00:00
parent 957219dc91
commit f1ec2a8f43
2 changed files with 8 additions and 8 deletions

View File

@ -608,16 +608,16 @@ public final class QrCode {
// Finder-like pattern in rows
for (int y = 0; y < size; y++) {
for (int x = 0, bits = 0; x < size; x++) {
bits = ((bits << 1) & 0x7FF) | (modules[y][x] ? 1 : 0);
if (x >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
bits = ((bits << 1) & 0b11111111111) | (modules[y][x] ? 1 : 0);
if (x >= 10 && (bits == 0b00001011101 || bits == 0b10111010000)) // Needs 11 bits accumulated
result += PENALTY_N3;
}
}
// Finder-like pattern in columns
for (int x = 0; x < size; x++) {
for (int y = 0, bits = 0; y < size; y++) {
bits = ((bits << 1) & 0x7FF) | (modules[y][x] ? 1 : 0);
if (y >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
bits = ((bits << 1) & 0b11111111111) | (modules[y][x] ? 1 : 0);
if (y >= 10 && (bits == 0b00001011101 || bits == 0b10111010000)) // Needs 11 bits accumulated
result += PENALTY_N3;
}
}

View File

@ -527,16 +527,16 @@ namespace qrcodegen {
// Finder-like pattern in rows
for (let y = 0; y < this.size; y++) {
for (let x = 0, bits = 0; x < this.size; x++) {
bits = ((bits << 1) & 0x7FF) | (this.modules[y][x] ? 1 : 0);
if (x >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
bits = ((bits << 1) & 0b11111111111) | (this.modules[y][x] ? 1 : 0);
if (x >= 10 && (bits == 0b00001011101 || bits == 0b10111010000)) // Needs 11 bits accumulated
result += QrCode.PENALTY_N3;
}
}
// Finder-like pattern in columns
for (let x = 0; x < this.size; x++) {
for (let y = 0, bits = 0; y < this.size; y++) {
bits = ((bits << 1) & 0x7FF) | (this.modules[y][x] ? 1 : 0);
if (y >= 10 && (bits == 0x05D || bits == 0x5D0)) // Needs 11 bits accumulated
bits = ((bits << 1) & 0b11111111111) | (this.modules[y][x] ? 1 : 0);
if (y >= 10 && (bits == 0b00001011101 || bits == 0b10111010000)) // Needs 11 bits accumulated
result += QrCode.PENALTY_N3;
}
}