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

Function initializeFunctionModules

modules/data/qrcode/qrcodegen.c:324–356  ·  view source on GitHub ↗

Clears the given QR Code grid with white modules for the given version's size, then marks every function module as black.

Source from the content-addressed store, hash-verified

322// Clears the given QR Code grid with white modules for the given
323// version's size, then marks every function module as black.
324testable void initializeFunctionModules(int version, uint8_t qrcode[]) {
325 // Initialize QR Code
326 int qrsize = version * 4 + 17;
327 memset(qrcode, 0, ((qrsize * qrsize + 7) / 8 + 1) * sizeof(qrcode[0]));
328 qrcode[0] = (uint8_t)qrsize;
329
330 // Fill horizontal and vertical timing patterns
331 fillRectangle(6, 0, 1, qrsize, qrcode);
332 fillRectangle(0, 6, qrsize, 1, qrcode);
333
334 // Fill 3 finder patterns (all corners except bottom right) and format bits
335 fillRectangle(0, 0, 9, 9, qrcode);
336 fillRectangle(qrsize - 8, 0, 8, 9, qrcode);
337 fillRectangle(0, qrsize - 8, 9, 8, qrcode);
338
339 // Fill numerous alignment patterns
340 uint8_t alignPatPos[7] = {0};
341 int numAlign = getAlignmentPatternPositions(version, alignPatPos);
342 for (int i = 0; i < numAlign; i++) {
343 for (int j = 0; j < numAlign; j++) {
344 if ((i == 0 && j == 0) || (i == 0 && j == numAlign - 1) || (i == numAlign - 1 && j == 0))
345 continue; // Skip the three finder corners
346 else
347 fillRectangle(alignPatPos[i] - 2, alignPatPos[j] - 2, 5, 5, qrcode);
348 }
349 }
350
351 // Fill version blocks
352 if (version >= 7) {
353 fillRectangle(qrsize - 11, 0, 3, 6, qrcode);
354 fillRectangle(0, qrsize - 11, 6, 3, qrcode);
355 }
356}
357
358
359// Draws white function modules and possibly some black modules onto the given QR Code, without changing

Callers 1

Calls 2

fillRectangleFunction · 0.70

Tested by

no test coverage detected