MCPcopy
hub / github.com/zpao/qrcode.react / drawCodewords

Method drawCodewords

src/third-party/qrcodegen/index.ts:391–414  ·  view source on GitHub ↗
(data: Readonly<Array<byte>>)

Source from the content-addressed store, hash-verified

389 // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire
390 // data area of this QR Code. Function modules need to be marked off before this is called.
391 private drawCodewords(data: Readonly<Array<byte>>): void {
392 if (data.length != Math.floor(QrCode.getNumRawDataModules(this.version) / 8))
393 throw new RangeError("Invalid argument");
394 let i: int = 0; // Bit index into the data
395 // Do the funny zigzag scan
396 for (let right = this.size - 1; right >= 1; right -= 2) { // Index of right column in each column pair
397 if (right == 6)
398 right = 5;
399 for (let vert = 0; vert < this.size; vert++) { // Vertical counter
400 for (let j = 0; j < 2; j++) {
401 const x: int = right - j; // Actual x coordinate
402 const upward: boolean = ((right + 1) & 2) == 0;
403 const y: int = upward ? this.size - 1 - vert : vert; // Actual y coordinate
404 if (!this.isFunction[y][x] && i < data.length * 8) {
405 this.modules[y][x] = getBit(data[i >>> 3], 7 - (i & 7));
406 i++;
407 }
408 // If this QR Code has any remainder bits (0 to 7), they were assigned as
409 // 0/false/light by the constructor and are left unchanged by this method
410 }
411 }
412 }
413 assert(i == data.length * 8);
414 }
415
416
417 // XORs the codeword modules in this QR Code with the given mask pattern.

Callers 1

constructorMethod · 0.95

Calls 3

getBitFunction · 0.85
assertFunction · 0.85
getNumRawDataModulesMethod · 0.80

Tested by

no test coverage detected