Draws the given sequence of 8-bit codewords (data and error correction) onto the entire data area of this QR Code symbol. Function modules need to be marked off before this is called.
| 438 | // Draws the given sequence of 8-bit codewords (data and error correction) onto the entire |
| 439 | // data area of this QR Code symbol. Function modules need to be marked off before this is called. |
| 440 | static void drawCodewords(BitBucket *modules, BitBucket *isFunction, BitBucket *codewords) { |
| 441 | |
| 442 | uint32_t bitLength = codewords->bitOffsetOrWidth; |
| 443 | uint8_t *data = codewords->data; |
| 444 | |
| 445 | uint8_t size = modules->bitOffsetOrWidth; |
| 446 | |
| 447 | // Bit index into the data |
| 448 | uint32_t i = 0; |
| 449 | |
| 450 | // Do the funny zigzag scan |
| 451 | for (int16_t right = size - 1; right >= 1; right -= 2) { // Index of right column in each column pair |
| 452 | if (right == 6) { right = 5; } |
| 453 | |
| 454 | for (uint8_t vert = 0; vert < size; vert++) { // Vertical counter |
| 455 | for (int j = 0; j < 2; j++) { |
| 456 | uint8_t x = right - j; // Actual x coordinate |
| 457 | bool upwards = ((right & 2) == 0) ^ (x < 6); |
| 458 | uint8_t y = upwards ? size - 1 - vert : vert; // Actual y coordinate |
| 459 | if (!bb_getBit(isFunction, x, y) && i < bitLength) { |
| 460 | bb_setBit(modules, x, y, ((data[i >> 3] >> (7 - (i & 7))) & 1) != 0); |
| 461 | i++; |
| 462 | } |
| 463 | // If there are any remainder bits (0 to 7), they are already |
| 464 | // set to 0/false/white when the grid of modules was initialized |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | |
| 471 |