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

This commit is contained in:
Project Nayuki 2018-08-22 19:48:29 +00:00
parent ea29e58e9c
commit 23ae555dde
7 changed files with 63 additions and 70 deletions

View File

@ -437,25 +437,24 @@ static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uin
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(qrcode, 8, i, getBit(data, i)); setModule(qrcode, 8, i, getBit(bits, i));
setModule(qrcode, 8, 7, getBit(data, 6)); setModule(qrcode, 8, 7, getBit(bits, 6));
setModule(qrcode, 8, 8, getBit(data, 7)); setModule(qrcode, 8, 8, getBit(bits, 7));
setModule(qrcode, 7, 8, getBit(data, 8)); setModule(qrcode, 7, 8, getBit(bits, 8));
for (int i = 9; i < 15; i++) 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 // Draw second copy
int qrsize = qrcodegen_getSize(qrcode); int qrsize = qrcodegen_getSize(qrcode);
for (int i = 0; i <= 7; i++) 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++) 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 setModule(qrcode, 8, qrsize - 8, true); // Always black
} }

View File

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

View File

@ -351,24 +351,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++)
setFunctionModule(8, i, getBit(data, i)); setFunctionModule(8, i, getBit(bits, i));
setFunctionModule(8, 7, getBit(data, 6)); setFunctionModule(8, 7, getBit(bits, 6));
setFunctionModule(8, 8, getBit(data, 7)); setFunctionModule(8, 8, getBit(bits, 7));
setFunctionModule(7, 8, getBit(data, 8)); setFunctionModule(7, 8, getBit(bits, 8));
for (int i = 9; i < 15; i++) for (int i = 9; i < 15; i++)
setFunctionModule(14 - i, 8, getBit(data, i)); setFunctionModule(14 - i, 8, getBit(bits, i));
// Draw second copy // Draw second copy
for (int i = 0; i <= 7; i++) 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++) 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 setFunctionModule(8, size - 8, true); // Always black
} }

View File

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

View File

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

View File

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

View File

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