Draws two copies of the format bits (with its own error correction code) based on the given mask and error correction level. This always draws all modules of the format bits, unlike drawWhiteFunctionModules() which might skip black modules.
| 423 | // on the given mask and error correction level. This always draws all modules of |
| 424 | // the format bits, unlike drawWhiteFunctionModules() which might skip black modules. |
| 425 | static void drawFormatBits(enum qrcodegen_Ecc ecl, enum qrcodegen_Mask mask, uint8_t qrcode[]) { |
| 426 | // Calculate error correction code and pack bits |
| 427 | assert(0 <= (int)mask && (int)mask <= 7); |
| 428 | int data = -1; // Dummy value |
| 429 | switch (ecl) { |
| 430 | case qrcodegen_Ecc_LOW : data = 1; break; |
| 431 | case qrcodegen_Ecc_MEDIUM : data = 0; break; |
| 432 | case qrcodegen_Ecc_QUARTILE: data = 3; break; |
| 433 | case qrcodegen_Ecc_HIGH : data = 2; break; |
| 434 | default: assert(false); |
| 435 | } |
| 436 | data = data << 3 | (int)mask; // ecl-derived value is uint2, mask is uint3 |
| 437 | int rem = data; |
| 438 | for (int i = 0; i < 10; i++) |
| 439 | rem = (rem << 1) ^ ((rem >> 9) * 0x537); |
| 440 | data = data << 10 | rem; |
| 441 | data ^= 0x5412; // uint15 |
| 442 | assert(data >> 15 == 0); |
| 443 | |
| 444 | // Draw first copy |
| 445 | for (int i = 0; i <= 5; i++) |
| 446 | setModule(qrcode, 8, i, ((data >> i) & 1) != 0); |
| 447 | setModule(qrcode, 8, 7, ((data >> 6) & 1) != 0); |
| 448 | setModule(qrcode, 8, 8, ((data >> 7) & 1) != 0); |
| 449 | setModule(qrcode, 7, 8, ((data >> 8) & 1) != 0); |
| 450 | for (int i = 9; i < 15; i++) |
| 451 | setModule(qrcode, 14 - i, 8, ((data >> i) & 1) != 0); |
| 452 | |
| 453 | // Draw second copy |
| 454 | int qrsize = qrcodegen_getSize(qrcode); |
| 455 | for (int i = 0; i <= 7; i++) |
| 456 | setModule(qrcode, qrsize - 1 - i, 8, ((data >> i) & 1) != 0); |
| 457 | for (int i = 8; i < 15; i++) |
| 458 | setModule(qrcode, 8, qrsize - 15 + i, ((data >> i) & 1) != 0); |
| 459 | setModule(qrcode, 8, qrsize - 8, true); |
| 460 | } |
| 461 | |
| 462 | |
| 463 | // Calculates the positions of alignment patterns in ascending order for the given version number, |
no test coverage detected