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

Function drawCodewords

modules/data/qrcode/qrcodegen.c:496–519  ·  view source on GitHub ↗

Draws the raw codewords (including data and ECC) onto the given QR Code. This requires the initial state of the QR Code to be black at function modules and white at codeword modules (including unused remainder bits).

Source from the content-addressed store, hash-verified

494// Draws the raw codewords (including data and ECC) onto the given QR Code. This requires the initial state of
495// the QR Code to be black at function modules and white at codeword modules (including unused remainder bits).
496static void drawCodewords(const uint8_t data[], int dataLen, uint8_t qrcode[]) {
497 int qrsize = qrcodegen_getSize(qrcode);
498 int i = 0; // Bit index into the data
499 // Do the funny zigzag scan
500 for (int right = qrsize - 1; right >= 1; right -= 2) { // Index of right column in each column pair
501 if (right == 6)
502 right = 5;
503 for (int vert = 0; vert < qrsize; vert++) { // Vertical counter
504 for (int j = 0; j < 2; j++) {
505 int x = right - j; // Actual x coordinate
506 bool upward = ((right + 1) & 2) == 0;
507 int y = upward ? qrsize - 1 - vert : vert; // Actual y coordinate
508 if (!getModule(qrcode, x, y) && i < dataLen * 8) {
509 bool black = ((data[i >> 3] >> (7 - (i & 7))) & 1) != 0;
510 setModule(qrcode, x, y, black);
511 i++;
512 }
513 // If there are any remainder bits (0 to 7), they are already
514 // set to 0/false/white when the grid of modules was initialized
515 }
516 }
517 }
518 assert(i == dataLen * 8);
519}
520
521
522// XORs the data modules in this QR Code with the given mask pattern. Due to XOR's mathematical

Callers 1

Calls 4

qrcodegen_getSizeFunction · 0.85
getModuleFunction · 0.85
setModuleFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected