Draws two copies of the version bits (with its own error correction code), based on this object's version field (which only has an effect for 7 <= version <= 40).
| 349 | // Draws two copies of the version bits (with its own error correction code), |
| 350 | // based on this object's version field (which only has an effect for 7 <= version <= 40). |
| 351 | static void drawVersion(BitBucket *modules, BitBucket *isFunction, uint8_t version) { |
| 352 | |
| 353 | int8_t size = modules->bitOffsetOrWidth; |
| 354 | |
| 355 | #if LOCK_VERSION != 0 && LOCK_VERSION < 7 |
| 356 | return; |
| 357 | |
| 358 | #else |
| 359 | if (version < 7) { return; } |
| 360 | |
| 361 | // Calculate error correction code and pack bits |
| 362 | uint32_t rem = version; // version is uint6, in the range [7, 40] |
| 363 | for (uint8_t i = 0; i < 12; i++) { |
| 364 | rem = (rem << 1) ^ ((rem >> 11) * 0x1F25); |
| 365 | } |
| 366 | |
| 367 | uint32_t data = version << 12 | rem; // uint18 |
| 368 | |
| 369 | // Draw two copies |
| 370 | for (uint8_t i = 0; i < 18; i++) { |
| 371 | bool bit = ((data >> i) & 1) != 0; |
| 372 | uint8_t a = size - 11 + i % 3, b = i / 3; |
| 373 | setFunctionModule(modules, isFunction, a, b, bit); |
| 374 | setFunctionModule(modules, isFunction, b, a, bit); |
| 375 | } |
| 376 | |
| 377 | #endif |
| 378 | } |
| 379 | |
| 380 | static void drawFunctionPatterns(BitBucket *modules, BitBucket *isFunction, uint8_t version, uint8_t ecc) { |
| 381 |