Added variable for clarity to QrCode.drawFormatBits() in all language versions.

pull/39/merge
Project Nayuki 6 years ago
parent ea29e58e9c
commit 23ae555dde

@ -437,25 +437,24 @@ static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uin
int rem = data;
for (int i = 0; i < 10; i++)
rem = (rem << 1) ^ ((rem >> 9) * 0x537);
data = data << 10 | rem;
data ^= 0x5412; // uint15
assert(data >> 15 == 0);
int bits = (data << 10 | rem) ^ 0x5412; // uint15
assert(bits >> 15 == 0);
// Draw first copy
for (int i = 0; i <= 5; i++)
setModule(qrcode, 8, i, getBit(data, i));
setModule(qrcode, 8, 7, getBit(data, 6));
setModule(qrcode, 8, 8, getBit(data, 7));
setModule(qrcode, 7, 8, getBit(data, 8));
setModule(qrcode, 8, i, getBit(bits, i));
setModule(qrcode, 8, 7, getBit(bits, 6));
setModule(qrcode, 8, 8, getBit(bits, 7));
setModule(qrcode, 7, 8, getBit(bits, 8));
for (int i = 9; i < 15; i++)
setModule(qrcode, 14 - i, 8, getBit(data, i));
setModule(qrcode, 14 - i, 8, getBit(bits, i));
// Draw second copy
int qrsize = qrcodegen_getSize(qrcode);
for (int i = 0; i <= 7; i++)
setModule(qrcode, qrsize - 1 - i, 8, getBit(data, i));
setModule(qrcode, qrsize - 1 - i, 8, getBit(bits, i));
for (int i = 8; i < 15; i++)
setModule(qrcode, 8, qrsize - 15 + i, getBit(data, i));
setModule(qrcode, 8, qrsize - 15 + i, getBit(bits, i));
setModule(qrcode, 8, qrsize - 8, true); // Always black
}

@ -222,25 +222,24 @@ void QrCode::drawFormatBits(int mask) {
int rem = data;
for (int i = 0; i < 10; i++)
rem = (rem << 1) ^ ((rem >> 9) * 0x537);
data = data << 10 | rem;
data ^= 0x5412; // uint15
if (data >> 15 != 0)
int bits = (data << 10 | rem) ^ 0x5412; // uint15
if (bits >> 15 != 0)
throw std::logic_error("Assertion error");
// Draw first copy
for (int i = 0; i <= 5; i++)
setFunctionModule(8, i, getBit(data, i));
setFunctionModule(8, 7, getBit(data, 6));
setFunctionModule(8, 8, getBit(data, 7));
setFunctionModule(7, 8, getBit(data, 8));
setFunctionModule(8, i, getBit(bits, i));
setFunctionModule(8, 7, getBit(bits, 6));
setFunctionModule(8, 8, getBit(bits, 7));
setFunctionModule(7, 8, getBit(bits, 8));
for (int i = 9; i < 15; i++)
setFunctionModule(14 - i, 8, getBit(data, i));
setFunctionModule(14 - i, 8, getBit(bits, i));
// Draw second copy
for (int i = 0; i <= 7; i++)
setFunctionModule(size - 1 - i, 8, getBit(data, i));
setFunctionModule(size - 1 - i, 8, getBit(bits, i));
for (int i = 8; i < 15; i++)
setFunctionModule(8, size - 15 + i, getBit(data, i));
setFunctionModule(8, size - 15 + i, getBit(bits, i));
setFunctionModule(8, size - 8, true); // Always black
}

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

@ -227,25 +227,24 @@ var qrcodegen = new function() {
var rem = data;
for (var i = 0; i < 10; i++)
rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
data = data << 10 | rem;
data ^= 0x5412; // uint15
if (data >>> 15 != 0)
var bits = (data << 10 | rem) ^ 0x5412; // uint15
if (bits >>> 15 != 0)
throw "Assertion error";
// Draw first copy
for (var i = 0; i <= 5; i++)
setFunctionModule(8, i, getBit(data, i));
setFunctionModule(8, 7, getBit(data, 6));
setFunctionModule(8, 8, getBit(data, 7));
setFunctionModule(7, 8, getBit(data, 8));
setFunctionModule(8, i, getBit(bits, i));
setFunctionModule(8, 7, getBit(bits, 6));
setFunctionModule(8, 8, getBit(bits, 7));
setFunctionModule(7, 8, getBit(bits, 8));
for (var i = 9; i < 15; i++)
setFunctionModule(14 - i, 8, getBit(data, i));
setFunctionModule(14 - i, 8, getBit(bits, i));
// Draw second copy
for (var i = 0; i <= 7; i++)
setFunctionModule(size - 1 - i, 8, getBit(data, i));
setFunctionModule(size - 1 - i, 8, getBit(bits, i));
for (var i = 8; i < 15; i++)
setFunctionModule(8, size - 15 + i, getBit(data, i));
setFunctionModule(8, size - 15 + i, getBit(bits, i));
setFunctionModule(8, size - 8, true); // Always black
}

@ -274,24 +274,23 @@ class QrCode(object):
rem = data
for _ in range(10):
rem = (rem << 1) ^ ((rem >> 9) * 0x537)
data = data << 10 | rem
data ^= 0x5412 # uint15
assert data >> 15 == 0
bits = (data << 10 | rem) ^ 0x5412 # uint15
assert bits >> 15 == 0
# Draw first copy
for i in range(0, 6):
self._set_function_module(8, i, _get_bit(data, i))
self._set_function_module(8, 7, _get_bit(data, 6))
self._set_function_module(8, 8, _get_bit(data, 7))
self._set_function_module(7, 8, _get_bit(data, 8))
self._set_function_module(8, i, _get_bit(bits, i))
self._set_function_module(8, 7, _get_bit(bits, 6))
self._set_function_module(8, 8, _get_bit(bits, 7))
self._set_function_module(7, 8, _get_bit(bits, 8))
for i in range(9, 15):
self._set_function_module(14 - i, 8, _get_bit(data, i))
self._set_function_module(14 - i, 8, _get_bit(bits, i))
# Draw second copy
for i in range(0, 8):
self._set_function_module(self._size - 1 - i, 8, _get_bit(data, i))
self._set_function_module(self._size - 1 - i, 8, _get_bit(bits, i))
for i in range(8, 15):
self._set_function_module(8, self._size - 15 + i, _get_bit(data, i))
self._set_function_module(8, self._size - 15 + i, _get_bit(bits, i))
self._set_function_module(8, self._size - 8, True) # Always black

@ -313,27 +313,26 @@ impl QrCode {
for _ in 0 .. 10 {
rem = (rem << 1) ^ ((rem >> 9) * 0x537);
}
data = data << 10 | rem;
data ^= 0x5412; // uint15
assert_eq!(data >> 15, 0, "Assertion error");
let bits: u32 = (data << 10 | rem) ^ 0x5412; // uint15
assert_eq!(bits >> 15, 0, "Assertion error");
// Draw first copy
for i in 0 .. 6 {
self.set_function_module(8, i, get_bit(data, i));
self.set_function_module(8, i, get_bit(bits, i));
}
self.set_function_module(8, 7, get_bit(data, 6));
self.set_function_module(8, 8, get_bit(data, 7));
self.set_function_module(7, 8, get_bit(data, 8));
self.set_function_module(8, 7, get_bit(bits, 6));
self.set_function_module(8, 8, get_bit(bits, 7));
self.set_function_module(7, 8, get_bit(bits, 8));
for i in 9 .. 15 {
self.set_function_module(14 - i, 8, get_bit(data, i));
self.set_function_module(14 - i, 8, get_bit(bits, i));
}
// Draw second copy
for i in 0 .. 8 {
self.set_function_module(size - 1 - i, 8, get_bit(data, i));
self.set_function_module(size - 1 - i, 8, get_bit(bits, i));
}
for i in 8 .. 15 {
self.set_function_module(8, size - 15 + i, get_bit(data, i));
self.set_function_module(8, size - 15 + i, get_bit(bits, i));
}
self.set_function_module(8, size - 8, true); // Always black
}

@ -290,25 +290,24 @@ namespace qrcodegen {
let rem: int = data;
for (let i = 0; i < 10; i++)
rem = (rem << 1) ^ ((rem >>> 9) * 0x537);
data = data << 10 | rem;
data ^= 0x5412; // uint15
if (data >>> 15 != 0)
let bits = (data << 10 | rem) ^ 0x5412; // uint15
if (bits >>> 15 != 0)
throw "Assertion error";
// Draw first copy
for (let i = 0; i <= 5; i++)
this.setFunctionModule(8, i, getBit(data, i));
this.setFunctionModule(8, 7, getBit(data, 6));
this.setFunctionModule(8, 8, getBit(data, 7));
this.setFunctionModule(7, 8, getBit(data, 8));
this.setFunctionModule(8, i, getBit(bits, i));
this.setFunctionModule(8, 7, getBit(bits, 6));
this.setFunctionModule(8, 8, getBit(bits, 7));
this.setFunctionModule(7, 8, getBit(bits, 8));
for (let i = 9; i < 15; i++)
this.setFunctionModule(14 - i, 8, getBit(data, i));
this.setFunctionModule(14 - i, 8, getBit(bits, i));
// Draw second copy
for (let i = 0; i <= 7; i++)
this.setFunctionModule(this.size - 1 - i, 8, getBit(data, i));
this.setFunctionModule(this.size - 1 - i, 8, getBit(bits, i));
for (let i = 8; i < 15; i++)
this.setFunctionModule(8, this.size - 15 + i, getBit(data, i));
this.setFunctionModule(8, this.size - 15 + i, getBit(bits, i));
this.setFunctionModule(8, this.size - 8, true); // Always black
}

Loading…
Cancel
Save