Tweaked some bit-drawing code for clarity.

pull/134/head
Project Nayuki 6 years ago
parent 0e5e3c1b61
commit b7f8d3a239

@ -241,24 +241,23 @@ public final class QrCode {
int rem = data; int rem = data;
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
rem = (rem << 1) ^ ((rem >>> 9) * 0x537); rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
data = data << 10 | rem; int bits = (data << 10 | rem) ^ 0x5412; // uint15
data ^= 0x5412; // uint15 assert bits >>> 15 == 0;
assert data >>> 15 == 0;
// Draw first copy // Draw first copy
for (int i = 0; i <= 5; i++) for (int i = 0; i <= 5; i++)
setModule(8, i, (data >>> i) & 1); setModule(8, i, (bits >>> i) & 1);
setModule(8, 7, (data >>> 6) & 1); setModule(8, 7, (bits >>> 6) & 1);
setModule(8, 8, (data >>> 7) & 1); setModule(8, 8, (bits >>> 7) & 1);
setModule(7, 8, (data >>> 8) & 1); setModule(7, 8, (bits >>> 8) & 1);
for (int i = 9; i < 15; i++) for (int i = 9; i < 15; i++)
setModule(14 - i, 8, (data >>> i) & 1); setModule(14 - i, 8, (bits >>> i) & 1);
// Draw second copy // Draw second copy
for (int i = 0; i <= 7; i++) for (int i = 0; i <= 7; i++)
setModule(size - 1 - i, 8, (data >>> i) & 1); setModule(size - 1 - i, 8, (bits >>> i) & 1);
for (int i = 8; i < 15; i++) for (int i = 8; i < 15; i++)
setModule(8, size - 15 + i, (data >>> i) & 1); setModule(8, size - 15 + i, (bits >>> i) & 1);
setModule(8, size - 8, 1); setModule(8, size - 8, 1);
} }

@ -168,12 +168,12 @@ final class QrTemplate {
int rem = version; // version is uint6, in the range [7, 40] int rem = version; // version is uint6, in the range [7, 40]
for (int i = 0; i < 12; i++) for (int i = 0; i < 12; i++)
rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25); rem = (rem << 1) ^ ((rem >>> 11) * 0x1F25);
int data = version << 12 | rem; // uint18 int bits = version << 12 | rem; // uint18
assert data >>> 18 == 0; assert bits >>> 18 == 0;
// Draw two copies // Draw two copies
for (int i = 0; i < 18; i++) { for (int i = 0; i < 18; i++) {
int bit = (data >>> i) & 1; int bit = (bits >>> i) & 1;
int a = size - 11 + i % 3, b = i / 3; int a = size - 11 + i % 3, b = i / 3;
darkenFunctionModule(a, b, bit); darkenFunctionModule(a, b, bit);
darkenFunctionModule(b, a, bit); darkenFunctionModule(b, a, bit);

Loading…
Cancel
Save