MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / drawFormatBits

Function drawFormatBits

Libraries/QRCode/src/qrcode.c:309–346  ·  view source on GitHub ↗

Draws two copies of the format bits (with its own error correction code) based on the given mask and this object's error correction level field.

Source from the content-addressed store, hash-verified

307// Draws two copies of the format bits (with its own error correction code)
308// based on the given mask and this object's error correction level field.
309static void drawFormatBits(BitBucket *modules, BitBucket *isFunction, uint8_t ecc, uint8_t mask) {
310
311 uint8_t size = modules->bitOffsetOrWidth;
312
313 // Calculate error correction code and pack bits
314 uint32_t data = ecc << 3 | mask; // errCorrLvl is uint2, mask is uint3
315 uint32_t rem = data;
316 for (int i = 0; i < 10; i++) {
317 rem = (rem << 1) ^ ((rem >> 9) * 0x537);
318 }
319
320 data = data << 10 | rem;
321 data ^= 0x5412; // uint15
322
323 // Draw first copy
324 for (uint8_t i = 0; i <= 5; i++) {
325 setFunctionModule(modules, isFunction, 8, i, ((data >> i) & 1) != 0);
326 }
327
328 setFunctionModule(modules, isFunction, 8, 7, ((data >> 6) & 1) != 0);
329 setFunctionModule(modules, isFunction, 8, 8, ((data >> 7) & 1) != 0);
330 setFunctionModule(modules, isFunction, 7, 8, ((data >> 8) & 1) != 0);
331
332 for (int8_t i = 9; i < 15; i++) {
333 setFunctionModule(modules, isFunction, 14 - i, 8, ((data >> i) & 1) != 0);
334 }
335
336 // Draw second copy
337 for (int8_t i = 0; i <= 7; i++) {
338 setFunctionModule(modules, isFunction, size - 1 - i, 8, ((data >> i) & 1) != 0);
339 }
340
341 for (int8_t i = 8; i < 15; i++) {
342 setFunctionModule(modules, isFunction, 8, size - 15 + i, ((data >> i) & 1) != 0);
343 }
344
345 setFunctionModule(modules, isFunction, 8, size - 8, true);
346}
347
348
349// Draws two copies of the version bits (with its own error correction code),

Callers 4

drawFunctionPatternsFunction · 0.85
qrcode_initBytesFunction · 0.85
drawFunctionPatternsMethod · 0.85

Calls 1

setFunctionModuleFunction · 0.85

Tested by 2

drawFunctionPatternsMethod · 0.68