MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / applyMask

Function applyMask

Libraries/QRCode/src/qrcode.c:255–276  ·  view source on GitHub ↗

XORs the data modules in this QR Code with the given mask pattern. Due to XOR's mathematical properties, calling applyMask(m) twice with the same value is equivalent to no change at all. This means it is possible to apply a mask, undo it, and try another mask. Note that a final well-formed QR Code symbol needs exactly one mask applied (not zero, not two, etc.).

Source from the content-addressed store, hash-verified

253// This means it is possible to apply a mask, undo it, and try another mask. Note that a final
254// well-formed QR Code symbol needs exactly one mask applied (not zero, not two, etc.).
255static void applyMask(BitBucket *modules, BitBucket *isFunction, uint8_t mask) {
256 uint8_t size = modules->bitOffsetOrWidth;
257
258 for (uint8_t y = 0; y < size; y++) {
259 for (uint8_t x = 0; x < size; x++) {
260 if (bb_getBit(isFunction, x, y)) { continue; }
261
262 bool invert = 0;
263 switch (mask) {
264 case 0: invert = (x + y) % 2 == 0; break;
265 case 1: invert = y % 2 == 0; break;
266 case 2: invert = x % 3 == 0; break;
267 case 3: invert = (x + y) % 3 == 0; break;
268 case 4: invert = (x / 3 + y / 2) % 2 == 0; break;
269 case 5: invert = x * y % 2 + x * y % 3 == 0; break;
270 case 6: invert = (x * y % 2 + x * y % 3) % 2 == 0; break;
271 case 7: invert = ((x + y) % 2 + x * y % 3) % 2 == 0; break;
272 }
273 bb_invertBit(modules, x, y, invert);
274 }
275 }
276}
277
278static void setFunctionModule(BitBucket *modules, BitBucket *isFunction, uint8_t x, uint8_t y, bool on) {
279 bb_setBit(modules, x, y, on);

Callers 3

qrcode_initBytesFunction · 0.85
QrCodeMethod · 0.85

Calls 2

bb_getBitFunction · 0.85
bb_invertBitFunction · 0.85

Tested by 2

QrCodeMethod · 0.68