MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / drawWhiteFunctionModules

Function drawWhiteFunctionModules

modules/data/qrcode/qrcodegen.c:362–419  ·  view source on GitHub ↗

Draws white function modules and possibly some black modules onto the given QR Code, without changing non-function modules. This does not draw the format bits. This requires all function modules to be previously marked black (namely by initializeFunctionModules()), because this may skip redrawing black function modules.

Source from the content-addressed store, hash-verified

360// non-function modules. This does not draw the format bits. This requires all function modules to be previously
361// marked black (namely by initializeFunctionModules()), because this may skip redrawing black function modules.
362static void drawWhiteFunctionModules(uint8_t qrcode[], int version) {
363 // Draw horizontal and vertical timing patterns
364 int qrsize = qrcodegen_getSize(qrcode);
365 for (int i = 7; i < qrsize - 7; i += 2) {
366 setModule(qrcode, 6, i, false);
367 setModule(qrcode, i, 6, false);
368 }
369
370 // Draw 3 finder patterns (all corners except bottom right; overwrites some timing modules)
371 for (int i = -4; i <= 4; i++) {
372 for (int j = -4; j <= 4; j++) {
373 int dist = abs(i);
374 if (abs(j) > dist)
375 dist = abs(j);
376 if (dist == 2 || dist == 4) {
377 setModuleBounded(qrcode, 3 + j, 3 + i, false);
378 setModuleBounded(qrcode, qrsize - 4 + j, 3 + i, false);
379 setModuleBounded(qrcode, 3 + j, qrsize - 4 + i, false);
380 }
381 }
382 }
383
384 // Draw numerous alignment patterns
385 uint8_t alignPatPos[7] = {0};
386 int numAlign = getAlignmentPatternPositions(version, alignPatPos);
387 for (int i = 0; i < numAlign; i++) {
388 for (int j = 0; j < numAlign; j++) {
389 if ((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0))
390 continue; // Skip the three finder corners
391 else {
392 for (int k = -1; k <= 1; k++) {
393 for (int l = -1; l <= 1; l++)
394 setModule(qrcode, alignPatPos[i] + l, alignPatPos[j] + k, k == 0 && l == 0);
395 }
396 }
397 }
398 }
399
400 // Draw version blocks
401 if (version >= 7) {
402 // Calculate error correction code and pack bits
403 int rem = version; // version is uint6, in the range [7, 40]
404 for (int i = 0; i < 12; i++)
405 rem = (rem << 1) ^ ((rem >> 11) * 0x1F25);
406 long data = (long)version << 12 | rem; // uint18
407 assert(data >> 18 == 0);
408
409 // Draw two copies
410 for (int i = 0; i < 6; i++) {
411 for (int j = 0; j < 3; j++) {
412 int k = qrsize - 11 + j;
413 setModule(qrcode, k, i, (data & 1) != 0);
414 setModule(qrcode, i, k, (data & 1) != 0);
415 data >>= 1;
416 }
417 }
418 }
419}

Callers 1

Calls 5

qrcodegen_getSizeFunction · 0.85
setModuleFunction · 0.85
setModuleBoundedFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected